Skip to main content

ferro_json_ui/assets/
mod.rs

1//! Embedded static assets for ferro-json-ui.
2//!
3//! Served by the framework via the automatically-registered
4//! `GET /_ferro/ferro-base.css` route. Embedded at compile time —
5//! no runtime file I/O.
6
7pub(crate) mod quill;
8
9/// Pre-built Tailwind CSS covering every utility class emitted by
10/// ferro-json-ui components.
11///
12/// Regenerate with `scripts/gen-ferro-base-css.sh` after adding or
13/// modifying components that introduce new utility classes.
14pub const FERRO_BASE_CSS: &str = include_str!("../../assets/ferro-base.css");
15
16#[cfg(test)]
17mod tests {
18    use super::*;
19
20    #[test]
21    #[allow(clippy::const_is_empty)]
22    fn ferro_base_css_non_empty() {
23        assert!(!FERRO_BASE_CSS.is_empty(), "embedded CSS must not be empty");
24        // include_str! guarantees valid UTF-8 (compile error otherwise),
25        // so runtime validation is unnecessary. Smoke-check a class that
26        // every ferro-json-ui page relies on:
27        assert!(
28            FERRO_BASE_CSS.contains("flex"),
29            "expected `flex` utility in generated CSS"
30        );
31    }
32
33    #[test]
34    fn ferro_base_css_contains_motion_duration_fallback() {
35        // SC1: v1 themes that omit --motion-duration-fast resolve via the fallback.
36        assert!(
37            FERRO_BASE_CSS.contains("var(--motion-duration-fast,"),
38            "expected motion-duration-fast fallback in generated CSS; run scripts/gen-ferro-base-css.sh"
39        );
40        // The duration utilities must exist as class rules — a theme-layer
41        // variable emission alone satisfies the var() substring above without
42        // any consumable utility being generated.
43        for class in [".duration-fast{", ".duration-base{", ".duration-slow{"] {
44            assert!(
45                FERRO_BASE_CSS.contains(class),
46                "expected `{class}` utility rule in generated CSS; run scripts/gen-ferro-base-css.sh"
47            );
48        }
49        // SC3: reduced-motion collapse survives regeneration. The collapse
50        // declarations need !important — theme <style> tags are injected
51        // after this stylesheet and redeclare the tokens on :root at equal
52        // specificity, so normal declarations would lose on source order.
53        assert!(
54            FERRO_BASE_CSS.contains("prefers-reduced-motion"),
55            "expected prefers-reduced-motion block in generated CSS"
56        );
57        assert!(
58            FERRO_BASE_CSS.contains("--motion-duration-fast:.01ms!important"),
59            "expected !important on the reduced-motion collapse; run scripts/gen-ferro-base-css.sh"
60        );
61    }
62
63    #[test]
64    fn ferro_base_css_ring_falls_back_to_primary() {
65        // 23-slot v1 themes never define --color-ring; focus rings must
66        // resolve to the theme's primary color instead of an undefined var.
67        assert!(
68            FERRO_BASE_CSS.contains("var(--color-ring,var(--color-primary))"),
69            "expected --color-ring fallback to --color-primary in generated CSS; run scripts/gen-ferro-base-css.sh"
70        );
71    }
72}