Skip to main content

ferro_json_ui/assets/
leaflet.rs

1//! Embedded Leaflet 1.9.4 assets.
2//!
3//! Served by the framework at `GET /_ferro/leaflet/*` so the Map plugin works
4//! offline and behind TLS-terminating proxies with no external CDN and no SRI
5//! integrity check to fail. Embedded at compile time — no runtime file I/O.
6//!
7//! Upstream: Leaflet 1.9.4, <https://leafletjs.com> — BSD-2-Clause,
8//! © 2010-2023 Volodymyr Agafonkin. License vendored alongside the assets at
9//! `ferro-json-ui/assets/leaflet/LICENSE`.
10
11/// Leaflet 1.9.4 JavaScript.
12pub const LEAFLET_JS: &str = include_str!("../../assets/leaflet/leaflet.js");
13
14/// Leaflet 1.9.4 CSS. References `images/*` (served alongside at
15/// `/_ferro/leaflet/images/…`), so default markers resolve without config.
16pub const LEAFLET_CSS: &str = include_str!("../../assets/leaflet/leaflet.css");
17
18/// Marker/layer images referenced by `leaflet.css`, keyed by filename.
19pub const LEAFLET_IMAGES: &[(&str, &[u8])] = &[
20    (
21        "layers.png",
22        include_bytes!("../../assets/leaflet/images/layers.png"),
23    ),
24    (
25        "layers-2x.png",
26        include_bytes!("../../assets/leaflet/images/layers-2x.png"),
27    ),
28    (
29        "marker-icon.png",
30        include_bytes!("../../assets/leaflet/images/marker-icon.png"),
31    ),
32    (
33        "marker-icon-2x.png",
34        include_bytes!("../../assets/leaflet/images/marker-icon-2x.png"),
35    ),
36    (
37        "marker-shadow.png",
38        include_bytes!("../../assets/leaflet/images/marker-shadow.png"),
39    ),
40];
41
42/// Look up an embedded Leaflet image by filename (e.g. `"marker-icon.png"`).
43pub fn leaflet_image(name: &str) -> Option<&'static [u8]> {
44    LEAFLET_IMAGES
45        .iter()
46        .find(|(n, _)| *n == name)
47        .map(|(_, b)| *b)
48}
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    #[allow(clippy::const_is_empty)]
56    fn embedded_leaflet_is_present() {
57        assert!(!LEAFLET_JS.is_empty(), "leaflet.js must be embedded");
58        assert!(
59            LEAFLET_CSS.contains(".leaflet-"),
60            "leaflet.css must be embedded"
61        );
62        assert!(LEAFLET_JS.contains("1.9.4"), "expected Leaflet 1.9.4");
63        assert_eq!(LEAFLET_IMAGES.len(), 5);
64        assert!(leaflet_image("marker-icon.png").is_some());
65        assert!(leaflet_image("nope.png").is_none());
66    }
67}