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