diff --git a/common/Cargo.lock b/common/Cargo.lock index 9e77d1fdd..c7a066f78 100644 --- a/common/Cargo.lock +++ b/common/Cargo.lock @@ -80,9 +80,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "approx" @@ -146,9 +146,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "basic-toml" @@ -197,9 +197,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "camino" @@ -235,9 +235,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.18" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "shlex", ] @@ -250,9 +250,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.17" +version = "4.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +checksum = "7be5744db7978a28d9df86a214130d106a89ce49644cbc4e3f0c22c3fba30615" dependencies = [ "clap_builder", "clap_derive", @@ -260,9 +260,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.17" +version = "4.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +checksum = "a5fbc17d3ef8278f55b282b2a2e75ae6f6c7d4bb70ed3d0382375104bfafdb4b" dependencies = [ "anstream", "anstyle", @@ -272,9 +272,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck", "proc-macro2", @@ -386,9 +386,10 @@ dependencies = [ "proptest", "rstest", "serde", - "serde-wasm-bindgen", + "serde-wasm-bindgen 0.6.5", "serde_json", "thiserror", + "tsify", "uniffi", "uuid", "wasm-bindgen", @@ -413,9 +414,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -428,9 +429,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -438,15 +439,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -455,15 +456,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -472,15 +473,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" @@ -490,9 +491,9 @@ checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -603,6 +604,12 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + [[package]] name = "heapless" version = "0.8.0" @@ -621,12 +628,12 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.15.0", ] [[package]] @@ -691,9 +698,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libm" @@ -773,9 +780,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "paste" @@ -785,9 +792,9 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pest" -version = "2.7.7" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219c0dcc30b6a27553f9cc242972b67f75b60eb0db71f0b5462f38b058c41546" +checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9" dependencies = [ "memchr", "thiserror", @@ -796,9 +803,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.7" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e1288dbd7786462961e69bfd4df7848c1e37e8b74303dbdab82c3a9cdd2809" +checksum = "4d3a6e3394ec80feb3b6393c725571754c6188490265c61aaf260810d6b95aa0" dependencies = [ "pest", "pest_generator", @@ -806,9 +813,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.7" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1381c29a877c6d34b8c176e734f35d7f7f5b3adaefe940cb4d1bb7af94678e2e" +checksum = "94429506bde1ca69d1b5601962c73f4172ab4726571a59ea95931218cb0e930e" dependencies = [ "pest", "pest_meta", @@ -819,9 +826,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.7.7" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0934d6907f148c22a3acbda520c7eed243ad7487a30f51f6ce52b58b7077a8a" +checksum = "ac8a071862e93690b6e34e9a5fb8e33ff3734473ac0245b27232222c4906a33f" dependencies = [ "once_cell", "pest", @@ -948,9 +955,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", @@ -960,9 +967,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -971,9 +978,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "relative-path" @@ -1096,6 +1103,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3b143e2833c57ab9ad3ea280d21fd34e285a42837aeb0ee301f4f41890fa00e" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde-wasm-bindgen" version = "0.6.5" @@ -1118,6 +1136,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_derive_internals" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e578a843d40b4189a4d66bba51d7684f57da5bd7c304c64e14bd63efbef49509" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_json" version = "1.0.128" @@ -1186,7 +1215,7 @@ version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f5ef1f863aca7d1d7dda7ccfc36a0a4279bd6d3c375176e5e0712e25cb4889" dependencies = [ - "hashbrown", + "hashbrown 0.14.5", "num-traits", "robust", "smallvec", @@ -1267,15 +1296,39 @@ checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "toml_datetime", "winnow", ] +[[package]] +name = "tsify" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6b26cf145f2f3b9ff84e182c448eaf05468e247f148cf3d2a7d67d78ff023a0" +dependencies = [ + "serde", + "serde-wasm-bindgen 0.5.0", + "tsify-macros", + "wasm-bindgen", +] + +[[package]] +name = "tsify-macros" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a94b0f0954b3e59bfc2c246b4c8574390d94a4ad4ad246aaf2fb07d7dfd3b47" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + [[package]] name = "typenum" version = "1.17.0" @@ -1284,9 +1337,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" [[package]] name = "unarray" @@ -1701,9 +1754,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] diff --git a/common/ferrostar/Cargo.toml b/common/ferrostar/Cargo.toml index ea3307797..23da5b711 100644 --- a/common/ferrostar/Cargo.toml +++ b/common/ferrostar/Cargo.toml @@ -40,6 +40,7 @@ getrandom = { version = "0.2.15", optional = true } wasm-bindgen = { version = "0.2.93", optional = true } web-time = { version = "1.1.0", features = ["serde"], optional = true } itertools = "0.13.0" +tsify = { version = "0.4.5", default-features = false, features = ["js"] } [build-dependencies] uniffi = { workspace = true, features = ["build"] } diff --git a/common/ferrostar/src/deviation_detection.rs b/common/ferrostar/src/deviation_detection.rs index d4a457a42..870cec8d4 100644 --- a/common/ferrostar/src/deviation_detection.rs +++ b/common/ferrostar/src/deviation_detection.rs @@ -20,6 +20,8 @@ use geo::Point; #[cfg(feature = "wasm-bindgen")] use serde::{Deserialize, Serialize}; +#[cfg(feature = "wasm-bindgen")] +use tsify::Tsify; #[cfg(test)] use { @@ -39,7 +41,8 @@ use web_time::SystemTime; /// Determines if the user has deviated from the expected route. #[derive(Clone)] #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] -#[cfg_attr(feature = "wasm-bindgen", derive(Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Deserialize, Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(from_wasm_abi))] pub enum RouteDeviationTracking { /// No checks will be done, and we assume the user is always following the route. None, @@ -111,7 +114,8 @@ impl RouteDeviationTracking { /// For example, we could conceivably add a "wrong way" status in the future. #[derive(Debug, Copy, Clone, PartialEq)] #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] -#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize, Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub enum RouteDeviation { /// The user is proceeding on course within the expected tolerances; everything is normal. NoDeviation, diff --git a/common/ferrostar/src/lib.rs b/common/ferrostar/src/lib.rs index 42fb2bc70..f6858bc3a 100644 --- a/common/ferrostar/src/lib.rs +++ b/common/ferrostar/src/lib.rs @@ -30,6 +30,7 @@ pub mod navigation_controller; pub mod routing_adapters; pub mod simulation; +#[cfg(feature = "uniffi")] use models::Route; #[cfg(feature = "uniffi")] use routing_adapters::{ diff --git a/common/ferrostar/src/models.rs b/common/ferrostar/src/models.rs index fa7ea635e..b8f065b05 100644 --- a/common/ferrostar/src/models.rs +++ b/common/ferrostar/src/models.rs @@ -21,6 +21,9 @@ use std::time::SystemTime; #[cfg(feature = "web-time")] use web_time::SystemTime; +#[cfg(feature = "wasm-bindgen")] +use tsify::Tsify; + use std::collections::HashMap; use uuid::Uuid; @@ -41,6 +44,8 @@ pub enum ModelError { #[derive(Clone, Copy, PartialEq, PartialOrd, Debug)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct GeographicCoordinate { /// The latitude (in degrees). pub lat: f64, @@ -95,6 +100,8 @@ impl From for Point { #[derive(Clone, Copy, PartialEq, PartialOrd, Debug)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct Waypoint { pub coordinate: GeographicCoordinate, pub kind: WaypointKind, @@ -104,6 +111,8 @@ pub struct Waypoint { #[derive(Clone, Copy, PartialEq, PartialOrd, Debug)] #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub enum WaypointKind { /// Starts or ends a leg of the trip. /// @@ -117,6 +126,8 @@ pub enum WaypointKind { #[derive(Clone, Copy, PartialEq, PartialOrd, Debug)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct BoundingBox { /// The southwest corner of the bounding box. pub sw: GeographicCoordinate, @@ -149,6 +160,8 @@ pub struct Heading { #[derive(Clone, Copy, PartialEq, PartialOrd, Debug)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct CourseOverGround { /// The direction in which the user's device is traveling, measured in clockwise degrees from /// true north (N = 0, E = 90, S = 180, W = 270). @@ -167,6 +180,8 @@ impl CourseOverGround { #[derive(Clone, Copy, PartialEq, PartialOrd, Debug)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct Speed { /// The user's speed in meters per second. pub value: f64, @@ -215,6 +230,8 @@ mod system_time_format { #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct UserLocation { pub coordinates: GeographicCoordinate, /// The estimated accuracy of the coordinate (in meters) @@ -239,6 +256,8 @@ impl From for Point { #[derive(Clone, Debug)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct Route { pub geometry: Vec, pub bbox: BoundingBox, @@ -270,6 +289,8 @@ fn get_route_polyline(route: &Route, precision: u32) -> Result, @@ -351,6 +372,8 @@ impl RouteStep { #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi))] pub struct SpokenInstruction { /// Plain-text instruction which can be synthesized with a TTS engine. pub text: String, @@ -367,6 +390,7 @@ pub struct SpokenInstruction { /// NOTE: While it is possible to deterministically create UUIDs, we do not do so at this time. /// This should be theoretically possible though if someone cares to write up a proposal and a PR. #[cfg_attr(test, serde(skip_serializing))] + #[cfg_attr(feature = "wasm-bindgen", tsify(type = "string"))] pub utterance_id: Uuid, } @@ -376,6 +400,8 @@ pub struct SpokenInstruction { #[derive(Deserialize, Debug, Copy, Clone, Eq, PartialEq)] #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] #[cfg_attr(any(test, feature = "wasm-bindgen"), derive(Serialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] #[serde(rename_all = "lowercase")] pub enum ManeuverType { Turn, @@ -407,6 +433,8 @@ pub enum ManeuverType { #[derive(Deserialize, Debug, Copy, Clone, Eq, PartialEq)] #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] #[cfg_attr(any(test, feature = "wasm-bindgen"), derive(Serialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] #[serde(rename_all = "lowercase")] pub enum ManeuverModifier { UTurn, @@ -428,6 +456,8 @@ pub enum ManeuverModifier { #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct VisualInstructionContent { /// The text to display. pub text: String, @@ -448,6 +478,8 @@ pub struct VisualInstructionContent { #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct VisualInstruction { /// The primary instruction content. /// diff --git a/common/ferrostar/src/navigation_controller/models.rs b/common/ferrostar/src/navigation_controller/models.rs index b43dda476..bae960262 100644 --- a/common/ferrostar/src/navigation_controller/models.rs +++ b/common/ferrostar/src/navigation_controller/models.rs @@ -7,12 +7,15 @@ use alloc::vec::Vec; use geo::LineString; #[cfg(feature = "wasm-bindgen")] use serde::{Deserialize, Serialize}; +#[cfg(feature = "wasm-bindgen")] +use tsify::Tsify; /// High-level state describing progress through a route. #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] -#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize, Tsify))] #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct TripProgress { /// The distance to the next maneuver, in meters. pub distance_to_next_maneuver: f64, @@ -31,7 +34,8 @@ pub struct TripProgress { /// and [`update_user_location`](super::NavigationController::update_user_location). #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] -#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize, Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub enum TripState { /// The navigation controller is idle and there is no active trip. Idle, @@ -90,7 +94,8 @@ pub enum StepAdvanceStatus { /// Controls filtering/post-processing of user course by the [`NavigationController`]. #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] -#[cfg_attr(feature = "wasm-bindgen", derive(Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Deserialize, Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(from_wasm_abi))] pub enum CourseFiltering { /// Snap the user's course to the current step's linestring using the next index in the step's geometry. /// @@ -105,7 +110,8 @@ pub enum CourseFiltering { /// and we should advance to the next step. #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] -#[cfg_attr(feature = "wasm-bindgen", derive(Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Deserialize, Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(from_wasm_abi))] pub enum StepAdvanceMode { /// Never advances to the next step automatically; /// requires calling [`NavigationController::advance_to_next_step`](super::NavigationController::advance_to_next_step). @@ -136,8 +142,9 @@ pub enum StepAdvanceMode { #[derive(Clone)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] -#[cfg_attr(feature = "wasm-bindgen", derive(Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Deserialize, Tsify))] #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "wasm-bindgen", tsify(from_wasm_abi))] pub struct NavigationControllerConfig { /// Configures when navigation advances to the next step in the route. pub step_advance: StepAdvanceMode, diff --git a/common/ferrostar/src/simulation.rs b/common/ferrostar/src/simulation.rs index 0e8fdc751..78f009a10 100644 --- a/common/ferrostar/src/simulation.rs +++ b/common/ferrostar/src/simulation.rs @@ -49,6 +49,9 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "wasm-bindgen")] use wasm_bindgen::{prelude::*, JsValue}; +#[cfg(feature = "wasm-bindgen")] +use tsify::Tsify; + #[cfg(all(feature = "std", not(feature = "web-time")))] use std::time::SystemTime; @@ -64,7 +67,8 @@ use alloc::{ #[derive(Debug)] #[cfg_attr(feature = "std", derive(thiserror::Error))] #[cfg_attr(feature = "uniffi", derive(uniffi::Error))] -#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize, Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub enum SimulationError { #[cfg_attr(feature = "std", error("Failed to parse polyline: {error}."))] /// Errors decoding the polyline string. @@ -78,6 +82,8 @@ pub enum SimulationError { #[derive(Clone, PartialEq)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", derive(Tsify))] +#[cfg_attr(feature = "wasm-bindgen", tsify(into_wasm_abi, from_wasm_abi))] pub struct LocationSimulationState { pub current_location: UserLocation, remaining_locations: Vec, diff --git a/web/src/ferrostar-map.ts b/web/src/ferrostar-map.ts index 63050cdd8..f26aa926a 100644 --- a/web/src/ferrostar-map.ts +++ b/web/src/ferrostar-map.ts @@ -7,7 +7,11 @@ import maplibregl, { Map } from "maplibre-gl"; import maplibreglStyles from "maplibre-gl/dist/maplibre-gl.css?inline"; -import {NavigationController, RouteAdapter} from "@stadiamaps/ferrostar"; +import { + NavigationController, + RouteAdapter, + TripState +} from "@stadiamaps/ferrostar"; import "./instructions-view"; import "./arrival-view"; import {SimulatedLocationProvider} from "./location"; @@ -47,9 +51,8 @@ export class FerrostarMap extends LitElement { @property({ type: Object, attribute: false }) options: object = {}; - // TODO: type @state() - protected _tripState: any = null; + protected _tripState: TripState | null = null; // Configures the control on first load. @property({ type: Function, attribute: false }) @@ -87,7 +90,7 @@ export class FerrostarMap extends LitElement { geolocateControl: GeolocateControl | null = null; navigationController: NavigationController | null = null; simulatedLocationMarker: maplibregl.Marker | null = null; - lastSpokenInstructionText: string | null = null; + lastSpokenUtteranceId: string | null = null; static styles = [ unsafeCSS(maplibreglStyles), @@ -236,7 +239,7 @@ export class FerrostarMap extends LitElement { return this.routeAdapter.parseResponse(responseData); } - // TODO: type + // TODO: types startNavigation(route: any, config: any) { this.locationProvider.start(); if (this.onNavigationStart && this.map) this.onNavigationStart(this.map); @@ -327,11 +330,12 @@ export class FerrostarMap extends LitElement { }); // Speak the next instruction if voice guidance is enabled - if (this.useVoiceGuidance) { - if (this._tripState.Navigating?.spokenInstruction && this._tripState.Navigating?.spokenInstruction.text !== this.lastSpokenInstructionText) { - this.lastSpokenInstructionText = this._tripState.Navigating?.spokenInstruction.text; + const tripState = this._tripState; + if (this.useVoiceGuidance && tripState != null && typeof tripState === 'object') { + if ("Navigating" in tripState && tripState.Navigating?.spokenInstruction && tripState.Navigating?.spokenInstruction.utteranceId !== this.lastSpokenUtteranceId) { + this.lastSpokenUtteranceId = tripState.Navigating?.spokenInstruction.utteranceId; window.speechSynthesis.cancel(); - window.speechSynthesis.speak(new SpeechSynthesisUtterance(this._tripState.Navigating?.spokenInstruction.text)); + window.speechSynthesis.speak(new SpeechSynthesisUtterance(tripState.Navigating?.spokenInstruction.text)); } } }