Files
gpx.studio/wasm/src/ts.rs
T
vcoppeandvcoppe 8fe7d8d64d Migration to new Rust-based engine (#401)
* wasm first steps

* parsing start

* parsing continued

* progress

* progress

* progress

* progress

* progress

* progress

* progress

* progress

* fixes

* reorganize

* change type

* fix

* progress

* refactoring

* progress

* progress

* progress

* keep style info

* progress

* progress

* remove (copy) in name

* progress

* merge methods into 1

* splice

* progress

* progress

* progress

* cleaning

* progress

* progress

* progress

* visibility

* progress

* progress

* progress

* progress

* progress

* fixes

* progress

* fix markers

* fix

* progress

* progress

* progress

* progress

* progress

* progress

* small fix

* use engine info

* fix popups

* small fix

* progress

* progress

* progress

* clean tool

* handle self closing elements

* reduce data exchanges across boundary

* copy on wasm side to avoid any data corruption

* speed fix

* routing

* refactoring

* reverse

* reverse

* crop

* split

* merge

* progress

* time tool

* fix bounds for waypoints

* reduce

* fix reactivity

* handle corrupt time data

* export

* progress

* remove gpx js package

* remove todo

* update readme

* cleaning

* progress

* fix link fields

* remove unused fields

* refactoring and tests

* import and export of routes, ref #192

* per-chunk categories storage

* cross-tab sync

* outdated state

* refactoring

* reorder methods

* refactoring

* fix

* improve flow

* renaming

* progress

* progress

* fix

* progress

* per file history

* keep original flag

* use history variant

* fix

* progress

* file explorer

* progress

* fix

* sticky folders

* improved sticky folders

* fix sortable

* fix sortable

* fix

* fix tab size

* no file delete on desktop

* fix routing on other file

* fix sorting

* remember language

* open links in browser

* commit missing changes

* avoid selecting on resize

* clarify filename

* explorer actions

* fix folder styling

* drop anywhere in folder

* cleaning

* fixes

* remove focus-ring

* full screen

* small fix

* consistent highlight color

* improved preview

* performance improvements

* sparser data transfers

* sparser data transfers

* show popup once data is loaded

* fix routing control size

* fix

* sparse desktop build

* remove custom ign styles

* use new endpoint for openhikingmap

* strip native menu

* reorder context menu items

* route full support

* route - track conversion

* create route file action

* route export, filter out anchors at high zoom level

* clarify name handling

* move hide & center to view

* routes continued

* update docs

* fix power format, closes #378

* lint fixes

* fix display of additional data with gaps, closes #361

* fix linting issues

* fix import modules

* fix multidrag

* change base to resolve

* fix type errors

* fix layer typings

* fix last type error

* each keys

* improve typings

* deploy to cloudflare

---------

Co-authored-by: vcoppe <vcoppe@hexaly.com>
2026-10-31 18:08:22 +01:00

216 lines
7.0 KiB
Rust

//! The TypeScript types of the JS objects, which the functions declare in their signatures.
use wasm_bindgen::prelude::*;
#[wasm_bindgen(typescript_custom_section)]
const ROUTE_TS: &str = r#"
/**
* An OSM attribute of the new trackpoints of a route, as the intervals of trackpoints that share
* a value: `starts[i]` is the index of the first trackpoint of the interval `i`, and `values[i]`
* its value, 0 when unknown, else 1 + the index of its name in `names`.
*/
export interface RouteCategory {
starts: Uint32Array;
values: Uint8Array;
names: string[];
}
/** The attributes of the new trackpoints of a route. The ones that are missing are unknown. */
export interface RouteAttributes {
surface?: RouteCategory;
highway?: RouteCategory;
sacScale?: RouteCategory;
mtbScale?: RouteCategory;
}
"#;
#[wasm_bindgen(typescript_custom_section)]
const FILE_STRUCTURE_TS: &str = r#"
export type Selection =
| { type: 'empty' }
| { type: 'file'; fileIds: string[] }
| { type: 'route'; fileId: string; routeIds: string[] }
| { type: 'track'; fileId: string; trackIds: string[] }
| { type: 'segment'; fileId: string; trackId: string; segmentIds: string[] }
| { type: 'waypoints'; fileId: string }
| { type: 'waypoint'; fileId: string; waypointIds: string[] };
/**
* Where moved elements go: a list of the file tree and the position in it, counted among the
* elements of the list that are not moved. Routes and tracks keep their kind: moved among the
* other kind, routes go after the routes, tracks before the tracks.
*/
export type MoveTarget =
| { type: 'files'; index: number }
| { type: 'routes'; fileId: string; index: number }
| { type: 'tracks'; fileId: string; index: number }
| { type: 'segments'; fileId: string; trackId: string; index: number }
| { type: 'waypoints'; fileId: string; index: number };
/** All the data of a waypoint. The fields it does not have are absent. */
export interface WaypointDetails {
id: string;
lng: number;
lat: number;
ele: number;
/** ms since epoch */
time?: number;
name?: string;
desc?: string;
cmt?: string;
/** The links of the waypoint, absent when it has none. */
links?: { href: string; text?: string }[];
sym?: string;
}
/** The position, elevation and time of a trackpoint. */
export interface TrackpointDetails {
lng: number;
lat: number;
ele: number;
/** ms since epoch */
time?: number;
}
/**
* A trackpoint of the selection: what the statistics buffers do not hold for each trackpoint.
* Absent fields are unknown.
*/
export interface SelectionPoint {
/** Slope (%) at the trackpoint. */
slope?: number;
/** ms since epoch */
time?: number;
/** Slope (%) and length (km) of the smoothed elevation segment of the trackpoint. */
slopeSegmentSlope?: number;
slopeSegmentDistance?: number;
surface?: string;
highway?: string;
sacScale?: string;
mtbScale?: string;
}
/** What was copied or cut, to be pasted: the kind of the elements and their ids. */
export interface Clipboard {
type: 'files' | 'routes' | 'tracks' | 'segments' | 'waypoints';
ids: string[];
cut: boolean;
}
/** What changed in the files, the selection and the clipboard. */
export interface FilesUpdate {
orderChanged: boolean;
selectionChanged: boolean;
clipboardChanged: boolean;
/** Files to read the structure of. */
added: string[];
/** Files whose structure changed: reread it. */
modified: string[];
/** Files that do not exist anymore: drop their structure. */
removed: string[];
}
/**
* What a call that edits the files or changes the selection did. `changed` is whether anything
* did; `error` tells why not (nothing to do, invalid data, or what is wrong with the arguments).
* Apply the update to what is kept of the files before the next call.
*/
export interface Outcome extends FilesUpdate {
changed: boolean;
error?: string;
}
/** What opening the storage found. */
export interface StorageOpened {
/** The settings, as JSON strings by key. */
settings: Record<string, string>;
/** The files that were restored are the added ones. */
outcome: Outcome;
}
export interface FileStructure {
id: string;
name: string;
desc?: string;
/** The routes come before the tracks, in the file and in the statistics. */
routes: RouteNode[];
tracks: TrackNode[];
waypoints: WaypointNode[];
/** Changes when the waypoints of the file change: refetch their coordinates. */
waypointsRev: string;
}
/**
* Global statistics of a file, of the selection, or of a part of it. The optional fields are
* absent when there is no data for them (no timestamps...).
*/
export interface GlobalStatistics {
/** km */
totalDistance: number;
movingDistance?: number;
/** seconds */
totalTime?: number;
movingTime?: number;
elevationGain: number;
elevationLoss: number;
/** ms since epoch */
startTime?: number;
endTime?: number;
/** km/h */
totalSpeed?: number;
movingSpeed?: number;
/** Absent when there are no trackpoints. */
bounds?: { west: number; south: number; east: number; north: number };
}
/** The name, description and style of a route or a track. */
export interface PathInfo {
name?: string;
desc?: string;
/** Style, only present when the file defines it. */
color?: string;
opacity?: number;
width?: number;
}
/** A route: like a track, with a single segment. */
export interface RouteNode extends PathInfo {
id: string;
segment: SegmentNode;
}
export interface TrackNode extends PathInfo {
id: string;
segments: SegmentNode[];
}
export interface SegmentNode {
id: string;
/** Changes when the trackpoints of the segment change: refetch their coordinates. */
rev: string;
/** Number of trackpoints. */
length: number;
}
export interface WaypointNode {
id: string;
name?: string;
sym?: string;
}
"#;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "Selection")]
pub type Selection;
#[wasm_bindgen(typescript_type = "WaypointDetails | undefined")]
pub type WaypointDetails;
#[wasm_bindgen(typescript_type = "TrackpointDetails | undefined")]
pub type TrackpointDetails;
#[wasm_bindgen(typescript_type = "SelectionPoint | undefined")]
pub type SelectionPoint;
#[wasm_bindgen(typescript_type = "MoveTarget")]
pub type MoveTarget;
#[wasm_bindgen(typescript_type = "RouteAttributes")]
pub type RouteAttributes;
#[wasm_bindgen(typescript_type = "Clipboard | undefined")]
pub type Clipboard;
#[wasm_bindgen(typescript_type = "Outcome")]
pub type Outcome;
#[wasm_bindgen(typescript_type = "StorageOpened")]
pub type StorageOpened;
#[wasm_bindgen(typescript_type = "FileStructure | undefined")]
pub type FileStructure;
#[wasm_bindgen(typescript_type = "GlobalStatistics | undefined")]
pub type GlobalStatistics;
#[wasm_bindgen(typescript_type = "string[]")]
pub type FileOrder;
#[wasm_bindgen(typescript_type = "string[]")]
pub type StringList;
}