slint-mapping 0.1.0

Map framework for Slint — interactive map component with tile rendering, panning, zooming, and marker overlays.
Documentation
[package]
name = "slint-mapping"
version = "0.1.0"
edition = "2021"
rust-version = "1.74"
license = "MIT OR Apache-2.0"
description = "Map framework for Slint — interactive map component with tile rendering, panning, zooming, and marker overlays."
repository = "https://github.com/gregoryraymond/slint-mapping"
homepage = "https://gregoryraymond.github.io/slint-mapping/"
documentation = "https://docs.rs/slint-mapping"
readme = "README.md"
keywords = ["slint", "map", "tiles", "osm", "geo"]
categories = ["gui", "graphics", "rendering"]
# Stays false until you're actually ready to ship. `just publish-dry`
# temporarily flips it for the dry-run; the real `cargo publish` needs
# it set to `true` (or removed — `true` is the default).
publish = true

# Single-package workspace so the wasm-demo crate can live alongside
# the library and consume it via `path = ".."`. Root crate stays the
# library; sub-crates are demos / examples that aren't part of the
# published API.
[workspace]
members = ["wasm-demo", "crates/slint-android-gestures"]

[lib]
crate-type = ["rlib"]

[dependencies]
slint = { version = "1", default-features = false, features = [
    "compat-1-2",
    "std",
] }
# Synchronous HTTP client used by OsmTileSource + prefetch::region for
# fetching raster tiles. Gated behind the `http` feature so consumers
# who only want offline tile bundles don't pull rustls in.
ureq = { version = "2", default-features = false, features = ["tls"], optional = true }
# Off-thread PNG decoding. Used by OsmTileSource's worker so the UI
# thread never decodes — only wraps an already-decoded
# SharedPixelBuffer via slint::Image::from_rgba8. PNG-only for now to
# keep the dep small.
image = { version = "0.25", default-features = false, features = ["png"], optional = true }
# JSON deserialisation for OsrmRouter responses. Gated behind the
# `routing` feature so consumers who only want tile rendering don't
# pull serde derive machinery.
serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1", optional = true }

# wasm-only dependencies — pulled in by the `wasm` feature, which
# enables WasmOsmTileSource (browser-side OSM source). Kept under a
# target-cfg block so a `cargo check` on a native target with `wasm`
# in scope (e.g. cargo metadata in tooling) doesn't try to download
# them. The actual feature gate is in [features] below.
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true }
# web-sys with the exact API surface our fetch path needs. Replaces
# gloo-net 0.5 — the gloo wrapper was hitting the "FnOnce called
# more than once" + index-out-of-bounds cascade in `js-sys`'s
# JsFuture under Firefox (its Promise→then handler chain was
# triggering closure double-invocation). web-sys's fetch is the
# same Promise but with one less layer of indirection; less surface
# area for the bug to surface across.
web-sys = { version = "0.3", optional = true, features = [
    "Window",
    "XmlHttpRequest",
    "XmlHttpRequestEventTarget",
    "XmlHttpRequestResponseType",
] }
# Bounded LRU for the in-browser tile cache. Without it,
# WasmOsmTileSource's HashMap grows forever — each 256x256 RGBA tile
# is 256 KB, and a few minutes of panning leaks hundreds of MB and
# eventually freezes the tab. lru is a tiny dep (~6 KB compiled) with
# no transitive cost.
lru = { version = "0.16", optional = true }
# Lets us store a `!Send` closure (e.g. one that captures `Rc<…>`) in
# a struct that needs to satisfy `Send + Sync` for the TileSource
# trait. SendWrapper is safe on single-threaded wasm because every
# access happens on the same JS thread; it panics if dereferenced
# from anywhere else, which on wasm32-unknown-unknown can't happen.
send_wrapper = { version = "0.6", optional = true }

[build-dependencies]
slint-build = "1"

[dev-dependencies]
# Drives MapView from Rust tests without a real backend / event loop.
i-slint-backend-testing = "1"

[features]
# Pulls in Slint's default desktop backend + Skia renderer so the
# `viewer` example can open a real window. Off by default so consumers
# (e.g. an Android app) don't have winit forced on them.
viewer = ["slint/backend-default", "slint/renderer-skia"]
# Enables OsmTileSource + prefetch::region (HTTP fetching via ureq).
# Pulls `image` too because OsmTileSource decodes PNG bytes off the
# UI thread into a SharedPixelBuffer for non-blocking refreshes.
http = ["dep:ureq", "dep:image"]
# Enables OsrmRouter and the routing types. Shares ureq with the
# `http` feature but adds serde for parsing OSRM's GeoJSON responses;
# kept as a separate feature so a consumer that only wants tile
# rendering doesn't pull serde derive into their build.
routing = ["dep:ureq", "dep:serde", "dep:serde_json"]
# Enables WasmOsmTileSource — a browser-side OSM tile source that
# uses web-sys's XmlHttpRequest + a Closure::once_into_js callback
# instead of ureq + std::thread (or fetch + spawn_local, which an
# earlier iteration tried but hit a fatal JsFuture × winit-web
# closure-reentrancy bug — see crates/slint-mapping/src/sources/
# wasm_osm.rs for the post-mortem). Off by default; the mobile
# (Android) target never wants any of this. Mutually exclusive in
# practice with `http` (ureq doesn't compile to
# wasm32-unknown-unknown), but they don't conflict at the Cargo level
# — leaving both on a wasm build just brings in the dead native code
# in `osm.rs`.
#
# Every dependency this pulls is additionally gated by
# `[target.'cfg(target_arch = "wasm32")']` in this Cargo.toml, plus
# `#[cfg(all(feature = "wasm", target_arch = "wasm32"))]` on
# `src/sources/wasm_osm.rs`. Triple-gated: a native cargo build with
# `--features wasm` accidentally on still pulls zero wasm crates.
wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:web-sys", "dep:send_wrapper", "dep:image", "dep:lru"]

[[example]]
name = "viewer"
required-features = ["viewer"]

[[example]]
name = "map_page"
required-features = ["viewer"]

[[bin]]
name = "slint-mapping-prefetch"
path = "src/bin/prefetch.rs"
required-features = ["http"]