@remaply/maps 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +280 -2
  4. package/dist/client.d.ts +31 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +208 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/config.d.ts +62 -0
  9. package/dist/config.d.ts.map +1 -0
  10. package/dist/config.js +65 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/directions.d.ts +68 -0
  13. package/dist/directions.d.ts.map +1 -0
  14. package/dist/directions.js +114 -0
  15. package/dist/directions.js.map +1 -0
  16. package/dist/errors.d.ts +26 -0
  17. package/dist/errors.d.ts.map +1 -0
  18. package/dist/errors.js +85 -0
  19. package/dist/errors.js.map +1 -0
  20. package/dist/geo.d.ts +17 -0
  21. package/dist/geo.d.ts.map +1 -0
  22. package/dist/geo.js +43 -0
  23. package/dist/geo.js.map +1 -0
  24. package/dist/index.d.ts +23 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +25 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/map.d.ts +133 -0
  29. package/dist/map.d.ts.map +1 -0
  30. package/dist/map.js +369 -0
  31. package/dist/map.js.map +1 -0
  32. package/dist/routePreview.d.ts +84 -0
  33. package/dist/routePreview.d.ts.map +1 -0
  34. package/dist/routePreview.js +206 -0
  35. package/dist/routePreview.js.map +1 -0
  36. package/dist/search.d.ts +70 -0
  37. package/dist/search.d.ts.map +1 -0
  38. package/dist/search.js +60 -0
  39. package/dist/search.js.map +1 -0
  40. package/dist/security.d.ts +20 -0
  41. package/dist/security.d.ts.map +1 -0
  42. package/dist/security.js +53 -0
  43. package/dist/security.js.map +1 -0
  44. package/dist/stepPreview.d.ts +127 -0
  45. package/dist/stepPreview.d.ts.map +1 -0
  46. package/dist/stepPreview.js +317 -0
  47. package/dist/stepPreview.js.map +1 -0
  48. package/dist/stepPreviewPanel.d.ts +41 -0
  49. package/dist/stepPreviewPanel.d.ts.map +1 -0
  50. package/dist/stepPreviewPanel.js +153 -0
  51. package/dist/stepPreviewPanel.js.map +1 -0
  52. package/dist/style.d.ts +45 -0
  53. package/dist/style.d.ts.map +1 -0
  54. package/dist/style.js +173 -0
  55. package/dist/style.js.map +1 -0
  56. package/dist/version.d.ts +3 -0
  57. package/dist/version.d.ts.map +1 -0
  58. package/dist/version.js +5 -0
  59. package/dist/version.js.map +1 -0
  60. package/package.json +56 -4
@@ -0,0 +1,206 @@
1
+ // Copyright 2026 Remaply
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { boundsOf, unwrapLongitudes } from "./geo.js";
4
+ import { firstFont } from "./style.js";
5
+ /** The route colours, as in the Android and iOS SDKs: the chosen route blue, alternatives grey. */
6
+ export const ROUTE_COLORS = {
7
+ line: "#1A73E8",
8
+ casing: "#0B57D0",
9
+ alternativeLine: "#C5D2E6",
10
+ alternativeCasing: "#8F9DB3",
11
+ from: "#0B57D0",
12
+ to: "#D93025",
13
+ };
14
+ const SOURCE = "remaply-sdk-route-preview";
15
+ /** Layer ids, bottom to top. Routes go under the map's labels, the ends on top of everything. */
16
+ export const ROUTE_PREVIEW_LAYERS = {
17
+ casing: "remaply-sdk-route-casing",
18
+ line: "remaply-sdk-route-line",
19
+ links: "remaply-sdk-route-end-links",
20
+ ends: "remaply-sdk-route-ends",
21
+ labels: "remaply-sdk-route-end-labels",
22
+ };
23
+ const EMPTY = { routes: [] };
24
+ /**
25
+ * The route preview, as GeoJSON: each route (longitudes unwrapped across the antimeridian), the
26
+ * From and To points with their labels, and a dotted link from each to where the route line begins
27
+ * or ends (a router starts and ends on the nearest road, which can be a little way off).
28
+ * Exported for tests and for maps drawn another way.
29
+ */
30
+ export function routePreviewGeoJson(data) {
31
+ const features = [];
32
+ const lines = data.routes.filter((r) => r.points.length >= 2);
33
+ for (const r of lines) {
34
+ features.push({
35
+ type: "Feature",
36
+ geometry: { type: "LineString", coordinates: unwrapLongitudes(r.points).map((p) => [p.lon, p.lat]) },
37
+ properties: { kind: "route", id: r.id, active: r.active ?? false },
38
+ });
39
+ }
40
+ const main = lines.find((r) => r.active) ?? lines[0];
41
+ const ends = [
42
+ ["from", data.from, main?.points[0]],
43
+ ["to", data.to, main?.points[main.points.length - 1]],
44
+ ];
45
+ for (const [kind, end, onRoute] of ends) {
46
+ if (!end)
47
+ continue;
48
+ const at = [end.location.lon, end.location.lat];
49
+ if (onRoute) {
50
+ features.push({ type: "Feature", geometry: { type: "LineString", coordinates: [at, [onRoute.lon, onRoute.lat]] }, properties: { kind: "link" } });
51
+ }
52
+ features.push({
53
+ type: "Feature",
54
+ geometry: { type: "Point", coordinates: at },
55
+ properties: { kind, label: end.label ? `${kind === "from" ? "From" : "To"}: ${end.label}` : "" },
56
+ });
57
+ }
58
+ return { type: "FeatureCollection", features };
59
+ }
60
+ const isKind = (kind) => ["==", ["get", "kind"], kind];
61
+ /**
62
+ * Routes and their From and To on a MapLibre map showing the Remaply style (from `loadStyle`):
63
+ * the chosen route blue, alternatives grey, the ends labelled. Survives style changes.
64
+ * `RemaplyMap` uses it; use it directly on your own MapLibre map.
65
+ *
66
+ * ```ts
67
+ * const preview = new RoutePreview(map);
68
+ * const routes = await route([from, to], { alternatives: 2 });
69
+ * preview.set({
70
+ * routes: routes.map((r, i) => ({ id: `r${i}`, points: routePoints(r), active: i === 0 })),
71
+ * from: { location: from, label: "Your location" },
72
+ * to: { location: to, label: "CWM Hospital" },
73
+ * });
74
+ * preview.fit();
75
+ * ```
76
+ */
77
+ export class RoutePreview {
78
+ constructor(map) {
79
+ this.map = map;
80
+ this.data = EMPTY;
81
+ this.onStyleLoad = () => this.add();
82
+ map.on("style.load", this.onStyleLoad);
83
+ if (map.isStyleLoaded())
84
+ this.add();
85
+ }
86
+ /** Show these routes and ends (replacing what was shown). */
87
+ set(data) {
88
+ this.data = data;
89
+ const source = this.map.getSource(SOURCE);
90
+ if (source) {
91
+ source.setData(routePreviewGeoJson(data));
92
+ this.bringEndsToFront();
93
+ }
94
+ else {
95
+ this.add();
96
+ }
97
+ }
98
+ /** Remove the routes and ends from view. */
99
+ clear() {
100
+ this.set(EMPTY);
101
+ }
102
+ /** Fit the routes and ends on screen. [padding] in pixels, a number or per side. */
103
+ fit(padding = 64, maxZoom = 16) {
104
+ const ends = [this.data.from, this.data.to].filter((e) => !!e).map((e) => e.location);
105
+ const box = boundsOf([...this.data.routes.map((r) => r.points), ends].filter((l) => l.length > 0));
106
+ if (!box)
107
+ return;
108
+ const [west, south, east, north] = box;
109
+ this.map.fitBounds([[west, south], [east, north]], { padding, maxZoom, duration: 800 });
110
+ }
111
+ /** Remove the layers and stop following style changes. */
112
+ remove() {
113
+ this.map.off("style.load", this.onStyleLoad);
114
+ for (const id of Object.values(ROUTE_PREVIEW_LAYERS).reverse())
115
+ if (this.map.getLayer(id))
116
+ this.map.removeLayer(id);
117
+ if (this.map.getSource(SOURCE))
118
+ this.map.removeSource(SOURCE);
119
+ }
120
+ add() {
121
+ const map = this.map;
122
+ if (!map.isStyleLoaded() || map.getSource(SOURCE))
123
+ return;
124
+ const style = map.getStyle();
125
+ const font = firstFont(style);
126
+ // Routes under the first label layer, so road names stay readable over them.
127
+ const firstSymbol = style.layers?.find((l) => l.type === "symbol")?.id;
128
+ map.addSource(SOURCE, { type: "geojson", data: routePreviewGeoJson(this.data) });
129
+ const active = ["get", "active"];
130
+ const lineLayout = { "line-cap": "round", "line-join": "round", "line-sort-key": ["case", active, 1, 0] };
131
+ map.addLayer({
132
+ id: ROUTE_PREVIEW_LAYERS.casing,
133
+ type: "line",
134
+ source: SOURCE,
135
+ filter: isKind("route"),
136
+ layout: lineLayout,
137
+ paint: {
138
+ "line-color": ["case", active, ROUTE_COLORS.casing, ROUTE_COLORS.alternativeCasing],
139
+ "line-width": ["interpolate", ["linear"], ["zoom"], 8, 5, 12, 8, 16, 14],
140
+ },
141
+ }, firstSymbol);
142
+ map.addLayer({
143
+ id: ROUTE_PREVIEW_LAYERS.line,
144
+ type: "line",
145
+ source: SOURCE,
146
+ filter: isKind("route"),
147
+ layout: lineLayout,
148
+ paint: {
149
+ "line-color": ["case", active, ROUTE_COLORS.line, ROUTE_COLORS.alternativeLine],
150
+ "line-width": ["interpolate", ["linear"], ["zoom"], 8, 3, 12, 5.5, 16, 10],
151
+ },
152
+ }, firstSymbol);
153
+ map.addLayer({
154
+ id: ROUTE_PREVIEW_LAYERS.links,
155
+ type: "line",
156
+ source: SOURCE,
157
+ filter: isKind("link"),
158
+ layout: { "line-cap": "round" },
159
+ paint: { "line-color": ROUTE_COLORS.casing, "line-width": 3, "line-dasharray": [0.1, 2], "line-opacity": 0.8 },
160
+ });
161
+ const isTo = isKind("to");
162
+ map.addLayer({
163
+ id: ROUTE_PREVIEW_LAYERS.ends,
164
+ type: "circle",
165
+ source: SOURCE,
166
+ filter: ["any", isKind("from"), isTo],
167
+ paint: {
168
+ "circle-radius": ["case", isTo, 8, 7],
169
+ "circle-color": ["case", isTo, ROUTE_COLORS.to, "#FFFFFF"],
170
+ "circle-stroke-width": 3,
171
+ "circle-stroke-color": ["case", isTo, "#FFFFFF", ROUTE_COLORS.from],
172
+ },
173
+ });
174
+ if (font) {
175
+ map.addLayer({
176
+ id: ROUTE_PREVIEW_LAYERS.labels,
177
+ type: "symbol",
178
+ source: SOURCE,
179
+ filter: ["all", ["any", isKind("from"), isTo], ["!=", ["get", "label"], ""]],
180
+ layout: {
181
+ "text-field": ["get", "label"],
182
+ "text-font": [font],
183
+ "text-size": 13,
184
+ "text-anchor": "bottom",
185
+ "text-offset": [0, -1],
186
+ "text-max-width": 14,
187
+ "text-allow-overlap": true,
188
+ "text-ignore-placement": true,
189
+ },
190
+ paint: {
191
+ "text-color": ["case", isTo, "#B3261E", ROUTE_COLORS.casing],
192
+ "text-halo-color": "#FFFFFF",
193
+ "text-halo-width": 2,
194
+ },
195
+ });
196
+ }
197
+ }
198
+ /** Keep the ends above layers added after the preview (an app's own pins), so they're never hidden. */
199
+ bringEndsToFront() {
200
+ for (const id of [ROUTE_PREVIEW_LAYERS.links, ROUTE_PREVIEW_LAYERS.ends, ROUTE_PREVIEW_LAYERS.labels]) {
201
+ if (this.map.getLayer(id))
202
+ this.map.moveLayer(id);
203
+ }
204
+ }
205
+ }
206
+ //# sourceMappingURL=routePreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routePreview.js","sourceRoot":"","sources":["../src/routePreview.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,sCAAsC;AAGtC,OAAO,EAAE,QAAQ,EAAe,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAwBvC,mGAAmG;AACnG,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,SAAS;IAC1B,iBAAiB,EAAE,SAAS;IAC5B,IAAI,EAAE,SAAS;IACf,EAAE,EAAE,SAAS;CACL,CAAC;AAEX,MAAM,MAAM,GAAG,2BAA2B,CAAC;AAC3C,iGAAiG;AACjG,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,0BAA0B;IAClC,IAAI,EAAE,wBAAwB;IAC9B,KAAK,EAAE,6BAA6B;IACpC,IAAI,EAAE,wBAAwB;IAC9B,MAAM,EAAE,8BAA8B;CAC9B,CAAC;AAEX,MAAM,KAAK,GAAqB,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAsB;IACxD,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,CAA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vB,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBACtB,gBAAgB,EAAE,EAAE;oBACpB,oBAAoB,EAAE,IAAI;oBAC1B,uBAAuB,EAAE,IAAI;iBAC9B;gBACD,KAAK,EAAE;oBACL,YAAY,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,CAAC,MAAM,CAAC;oBAC5D,iBAAiB,EAAE,SAAS;oBAC5B,iBAAiB,EAAE,CAAC;iBACrB;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,uGAAuG;IACvG,gBAAgB;QACd,KAAK,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,oBAAoB,CAAC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;YACtG,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAAE,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,70 @@
1
+ import type { LatLon } from "./geo.js";
2
+ export interface Address {
3
+ road_name?: string | null;
4
+ building_number?: string | null;
5
+ settlement?: string | null;
6
+ province?: string | null;
7
+ country_code?: string | null;
8
+ country?: string | null;
9
+ }
10
+ export interface Place {
11
+ id: string;
12
+ name: string;
13
+ /** `poi`, `building`, `administrative_area`... A string so that new values do not break your code. */
14
+ type: string;
15
+ category: string;
16
+ categories: string[];
17
+ address: Address;
18
+ virtual_address_code?: string | null;
19
+ location: LatLon;
20
+ /** Metres from the point the search was biased to; null when none was sent. */
21
+ distance_m?: number | null;
22
+ is_verified: boolean;
23
+ phone?: string | null;
24
+ website?: string | null;
25
+ brand?: string | null;
26
+ }
27
+ export interface SearchOptions {
28
+ /** Nearest to this point first, e.g. the map centre. */
29
+ near?: LatLon;
30
+ /** At most this many results. Default 10. */
31
+ limit?: number;
32
+ /** Cancel the request, e.g. when the user types again. */
33
+ signal?: AbortSignal;
34
+ }
35
+ export interface NearbyOptions {
36
+ /** Overture category codes, which also match their children (`restaurant`, `atm`...). Empty: any place. */
37
+ categories?: readonly string[];
38
+ /** Search radius in metres, at most 5000. Default 5000. */
39
+ radiusM?: number;
40
+ /** At most this many results, at most 20. Default 20. */
41
+ limit?: number;
42
+ signal?: AbortSignal;
43
+ }
44
+ /** A category for "search nearby". */
45
+ export interface NearbyCategory {
46
+ id: string;
47
+ label: string;
48
+ categories: readonly string[];
49
+ }
50
+ /** The categories the Remaply apps offer for "search nearby". */
51
+ export declare const NEARBY_CATEGORIES: readonly NearbyCategory[];
52
+ /** Limits of /v1/reverse. */
53
+ export declare const NEARBY_RADIUS_M = 5000;
54
+ export declare const NEARBY_LIMIT = 20;
55
+ /**
56
+ * Places and addresses matching [query], nearest to `near` first when given. The key needs the
57
+ * `search` scope.
58
+ *
59
+ * ```ts
60
+ * const places = await search("hospital", { near: { lat: -18.1416, lon: 178.4419 } });
61
+ * ```
62
+ */
63
+ export declare function search(query: string, options?: SearchOptions): Promise<Place[]>;
64
+ /** Places nearest to a point, nearest first. The key needs the `geocode` scope. */
65
+ export declare function nearby(near: LatLon, options?: NearbyOptions): Promise<Place[]>;
66
+ /** `12 Victoria Parade, Suva, Fiji`. */
67
+ export declare function formatAddress(place: Pick<Place, "address">): string;
68
+ /** `fast_food` → `Fast food`. */
69
+ export declare function formatCategory(category: string): string;
70
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKvC,MAAM,WAAW,OAAO;IACtB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,C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,CAAC;CAC/B;AAED,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,EAAE,SAAS,cAAc,EAQtD,CAAC;AAEF,6BAA6B;AAC7B,eAAO,MAAM,eAAe,OAAO,CAAC;AACpC,eAAO,MAAM,YAAY,KAAK,CAAC;AAoB/B;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAQzF;AAED,mFAAmF;AACnF,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAQxF;AAED,wCAAwC;AACxC,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,MAAM,CAMnE;AAED,iCAAiC;AACjC,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGvD"}
package/dist/search.js ADDED
@@ -0,0 +1,60 @@
1
+ // Copyright 2026 Remaply
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { apiGet } from "./client.js";
4
+ /** The categories the Remaply apps offer for "search nearby". */
5
+ export const NEARBY_CATEGORIES = [
6
+ { id: "restaurant", label: "Restaurants", categories: ["restaurant"] },
7
+ { id: "cafe", label: "Cafes", categories: ["cafe"] },
8
+ { id: "hotel", label: "Hotels", categories: ["hotel"] },
9
+ { id: "atm", label: "ATMs", categories: ["atm"] },
10
+ { id: "gas_station", label: "Gas stations", categories: ["gas_station"] },
11
+ { id: "pharmacy", label: "Pharmacies", categories: ["pharmacy"] },
12
+ { id: "hospital", label: "Health", categories: ["hospital"] },
13
+ ];
14
+ /** Limits of /v1/reverse. */
15
+ export const NEARBY_RADIUS_M = 5000;
16
+ export const NEARBY_LIMIT = 20;
17
+ /** Fills in what the API may leave out, so `Place` fields are always there. */
18
+ function normalize(raw) {
19
+ return {
20
+ ...raw,
21
+ type: raw.type ?? "",
22
+ category: raw.category ?? "",
23
+ categories: raw.categories ?? [],
24
+ address: raw.address ?? {},
25
+ is_verified: raw.is_verified ?? false,
26
+ };
27
+ }
28
+ /**
29
+ * Places and addresses matching [query], nearest to `near` first when given. The key needs the
30
+ * `search` scope.
31
+ *
32
+ * ```ts
33
+ * const places = await search("hospital", { near: { lat: -18.1416, lon: 178.4419 } });
34
+ * ```
35
+ */
36
+ export async function search(query, options = {}) {
37
+ const { near, limit = 10, signal } = options;
38
+ const body = await apiGet("/v1/search", { q: query.trim(), lat: near?.lat, lon: near?.lon, limit }, signal);
39
+ return body.results.map(normalize);
40
+ }
41
+ /** Places nearest to a point, nearest first. The key needs the `geocode` scope. */
42
+ export async function nearby(near, options = {}) {
43
+ const { categories = [], radiusM = NEARBY_RADIUS_M, limit = NEARBY_LIMIT, signal } = options;
44
+ const body = await apiGet("/v1/reverse", { lat: near.lat, lon: near.lon, category: categories, radius_m: radiusM, limit }, signal);
45
+ return body.results.map(normalize);
46
+ }
47
+ /** `12 Victoria Parade, Suva, Fiji`. */
48
+ export function formatAddress(place) {
49
+ const a = place.address;
50
+ const street = [a.building_number, a.road_name].filter((s) => !!s && s.trim() !== "").join(" ");
51
+ // Many records have no settlement yet; province is the fallback.
52
+ const area = a.settlement ?? a.province;
53
+ return [street, area, a.country ?? a.country_code].filter((s) => !!s && s.trim() !== "").join(", ");
54
+ }
55
+ /** `fast_food` → `Fast food`. */
56
+ export function formatCategory(category) {
57
+ const text = category.replace(/_/g, " ");
58
+ return text.charAt(0).toUpperCase() + text.slice(1);
59
+ }
60
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.js","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,sCAAsC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA2DrC,iEAAiE;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAA8B;IAC1D,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AC,CAAC,UAAU,IAAI,CAAC,CAAC,QAAQ,CAAC;IACxC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnH,CAAC;AAED,iCAAiC;AACjC,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,20 @@
1
+ /** Prefix of secret keys. They must never reach a browser, so the SDK never sends them. */
2
+ export declare const SECRET_KEY_PREFIX = "rmp_sk_";
3
+ /**
4
+ * Largest response the SDK reads, in bytes. Styles, TileJSON and search or route answers are far
5
+ * smaller; the cap keeps a broken or hostile `mapStyleUrl` from exhausting memory.
6
+ */
7
+ export declare const MAX_RESPONSE_BYTES: number;
8
+ export declare function isSecretKey(key: string): boolean;
9
+ /**
10
+ * [baseUrl] trimmed and without a trailing slash, when it is an `https://` URL (or `http://` on a
11
+ * local host). Throws otherwise: over plain HTTP the API key would travel in clear text.
12
+ */
13
+ export declare function validatedApiBaseUrl(baseUrl: string): string;
14
+ /**
15
+ * True when [url] is on the same origin as [apiBaseUrl] (scheme, host and port), the only requests
16
+ * that get the API key. Comparing the host alone would also send the key to `http://` or another
17
+ * port of the same host. An `http://` origin only counts on a local host.
18
+ */
19
+ export declare function isSameApiOrigin(apiBaseUrl: string, url: string): boolean;
20
+ //# sourceMappingURL=security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAGA,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAkB,CAAC;AAKlD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAUD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAY3D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAOxE"}
@@ -0,0 +1,53 @@
1
+ // Copyright 2026 Remaply
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /** Prefix of secret keys. They must never reach a browser, so the SDK never sends them. */
4
+ export const SECRET_KEY_PREFIX = "rmp_sk_";
5
+ /**
6
+ * Largest response the SDK reads, in bytes. Styles, TileJSON and search or route answers are far
7
+ * smaller; the cap keeps a broken or hostile `mapStyleUrl` from exhausting memory.
8
+ */
9
+ export const MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
10
+ /** Hosts where an `http://` API is allowed, for an API running on the developer's machine. */
11
+ const LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
12
+ export function isSecretKey(key) {
13
+ return key.startsWith(SECRET_KEY_PREFIX);
14
+ }
15
+ function parse(url) {
16
+ try {
17
+ return new URL(url);
18
+ }
19
+ catch {
20
+ return null;
21
+ }
22
+ }
23
+ /**
24
+ * [baseUrl] trimmed and without a trailing slash, when it is an `https://` URL (or `http://` on a
25
+ * local host). Throws otherwise: over plain HTTP the API key would travel in clear text.
26
+ */
27
+ export function validatedApiBaseUrl(baseUrl) {
28
+ const trimmed = baseUrl.trim().replace(/\/+$/, "");
29
+ const url = parse(trimmed);
30
+ const host = url?.hostname.toLowerCase() ?? "";
31
+ const ok = url !== null &&
32
+ host !== "" &&
33
+ (url.protocol === "https:" || (url.protocol === "http:" && LOCAL_HOSTS.has(host)));
34
+ if (!ok) {
35
+ throw new Error(`Remaply apiBaseUrl must be an https:// URL (http:// only for localhost), not "${trimmed}".`);
36
+ }
37
+ return trimmed;
38
+ }
39
+ /**
40
+ * True when [url] is on the same origin as [apiBaseUrl] (scheme, host and port), the only requests
41
+ * that get the API key. Comparing the host alone would also send the key to `http://` or another
42
+ * port of the same host. An `http://` origin only counts on a local host.
43
+ */
44
+ export function isSameApiOrigin(apiBaseUrl, url) {
45
+ const api = parse(apiBaseUrl);
46
+ const target = parse(url);
47
+ if (!api || !target || api.hostname === "")
48
+ return false;
49
+ const secure = api.protocol === "https:" || LOCAL_HOSTS.has(api.hostname.toLowerCase());
50
+ // URL.origin normalises case and default ports (https://x:443 is https://x).
51
+ return secure && api.origin === target.origin;
52
+ }
53
+ //# sourceMappingURL=security.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.js","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,sCAAsC;AAEtC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,8FAA8F;AAC9F,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AAEjE,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,GAAG,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,KAAK,CAAC,GAAW;IACxB,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,MAAM,IAAI,GAAG,GAAG,EAAE,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC;IAC/C,MAAM,EAAE,GACN,GAAG,KAAK,IAAI;QACZ,IAAI,KAAK,EAAE;QACX,CAAC,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACrF,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,KAAK,CAAC,iFAAiF,OAAO,IAAI,CAAC,CAAC;IAChH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,UAAkB,EAAE,GAAW;IAC7D,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IAC9B,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,QAAQ,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IACzD,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IACxF,6EAA6E;IAC7E,OAAO,MAAM,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC;AAChD,CAAC"}
@@ -0,0 +1,127 @@
1
+ import type { Map as MaplibreMap, PaddingOptions } from "maplibre-gl";
2
+ import { type Maneuver, type Route, type RouteStep } from "./directions.js";
3
+ import { type LatLon } from "./geo.js";
4
+ import { type StepPreviewTheme } from "./stepPreviewPanel.js";
5
+ /** Close-in zoom on a turn, as in the Android and iOS route planner Preview. */
6
+ export declare const STEP_PREVIEW_ZOOM = 16.5;
7
+ /** Camera tilt on a turn, in degrees, as in the apps. A crossing is shown flat. */
8
+ export declare const STEP_PREVIEW_PITCH = 45;
9
+ /** One turn of a route, ready to show while stepping through it. */
10
+ export interface PreviewStep {
11
+ /** The step as `route()` returned it. */
12
+ step: RouteStep;
13
+ /** The kind of turn, for its icon. */
14
+ maneuver: Maneuver;
15
+ /** "Turn right onto Milverton Road". */
16
+ instruction: string;
17
+ /** How far the step runs ("400 m", shown as "for 400 m"); null when it has no length, such as the arrival. */
18
+ distance: string | null;
19
+ /** Where the turn is. */
20
+ location: LatLon;
21
+ /** The direction of travel out of the turn (into it, for an arrival), degrees clockwise from north. Null when unknown. */
22
+ bearing: number | null;
23
+ /**
24
+ * For a crossing (a ferry): its two ends, framed together instead of a close-in view, because a
25
+ * 10 km and a 100 km crossing need very different zooms. Empty for a turn.
26
+ */
27
+ frame: LatLon[];
28
+ }
29
+ /** Initial great-circle bearing from [a] to [b], degrees clockwise from north, 0–360. */
30
+ export declare function bearingBetween(a: LatLon, b: LatLon): number;
31
+ /**
32
+ * The direction of travel at point [index] of [line]: towards the point about 25 m further on, or,
33
+ * at the end of the line, from the point about 25 m before. Null for a line of one point.
34
+ */
35
+ export declare function bearingAlong(line: readonly LatLon[], index: number): number | null;
36
+ /**
37
+ * The steps of [route] to step through, in order: each with its instruction, icon, length,
38
+ * where it is and the direction of travel there. On a route with stops, a leg's departure
39
+ * from a stop is left out: the arrival at that stop already shows it.
40
+ */
41
+ export declare function previewSteps(route: Pick<Route, "geometry" | "legs">): PreviewStep[];
42
+ /** Where the stepper is. */
43
+ export interface StepPreviewState {
44
+ /** The step shown, from 0. */
45
+ index: number;
46
+ /** How many steps there are. */
47
+ count: number;
48
+ step: PreviewStep;
49
+ isFirst: boolean;
50
+ isLast: boolean;
51
+ }
52
+ export interface StepPreviewOptions {
53
+ /** Close-in zoom on a turn. Default 16.5. */
54
+ zoom?: number;
55
+ /** Camera tilt on a turn, degrees. Default 45. */
56
+ pitch?: number;
57
+ /**
58
+ * Space kept clear of the camera's target, in pixels: the turn is centred in what is left.
59
+ * Default: room for the built-in panel at the bottom when it is shown.
60
+ */
61
+ padding?: number | Partial<PaddingOptions>;
62
+ /** Show the built-in panel (PREVIEW, the turn, `n / total`, Back, Next, Exit preview) on the map. Default true. */
63
+ panel?: boolean;
64
+ /** Panel colours: `auto` follows the system's light or dark setting. Default `auto`. */
65
+ theme?: StepPreviewTheme;
66
+ /** Left and Right arrow keys go back and forward, Escape exits. Default true. */
67
+ keyboard?: boolean;
68
+ /** Called on every step shown, and with null when the preview ends. */
69
+ onChange?: (state: StepPreviewState | null) => void;
70
+ }
71
+ /** The layer marking the turn being shown. */
72
+ export declare const STEP_PREVIEW_LAYER = "remaply-sdk-step-preview-turn";
73
+ /**
74
+ * Step through a route's turns before setting off, as the apps' route planner Preview does: each
75
+ * Next or Back moves the camera to that turn, tilted and facing the way you will travel, marks the
76
+ * turn on the route, and shows it in a panel. This is a preview only: it does not follow your
77
+ * location, speak, or re-route.
78
+ *
79
+ * ```ts
80
+ * const steps = new StepPreview(map.maplibre); // or any MapLibre map
81
+ * const [best] = await route([from, to]);
82
+ * steps.start(best); // the first step; Next, Back and Exit preview in the panel
83
+ * steps.next(); // or drive it yourself
84
+ * steps.exit(); // back to where the camera was
85
+ * ```
86
+ *
87
+ * Use `panel: false` to draw your own panel from `onChange`.
88
+ */
89
+ export declare class StepPreview {
90
+ private readonly map;
91
+ private steps;
92
+ private index;
93
+ private saved;
94
+ private panel;
95
+ private listening;
96
+ private readonly options;
97
+ private readonly onStyleLoad;
98
+ private readonly onKey;
99
+ constructor(map: MaplibreMap, options?: StepPreviewOptions);
100
+ /** Whether a route is being stepped through. */
101
+ get active(): boolean;
102
+ /** The step shown and where it is in the route; null when not previewing. */
103
+ get state(): StepPreviewState | null;
104
+ /**
105
+ * Start stepping through [route] (from `route()`) at step [at], default the first. Returns false,
106
+ * and does nothing, for a route without steps. Starting again replaces the route but keeps the
107
+ * camera to go back to on exit.
108
+ */
109
+ start(route: Pick<Route, "geometry" | "legs">, at?: number): boolean;
110
+ /** Show step [index] (clamped to the route's steps). */
111
+ goTo(index: number): void;
112
+ /** The next step; nothing on the last. */
113
+ next(): void;
114
+ /** The step before; nothing on the first. */
115
+ back(): void;
116
+ /** Stop previewing: the panel and the turn's mark go, and the camera goes back to where it was. */
117
+ exit(): void;
118
+ /** Exit, remove the layer and stop following style changes. */
119
+ remove(): void;
120
+ private padding;
121
+ private moveCamera;
122
+ private mark;
123
+ private setData;
124
+ private addLayer;
125
+ private handleKey;
126
+ }
127
+ //# sourceMappingURL=stepPreview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stepPreview.d.ts","sourceRoot":"","sources":["../src/stepPreview.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAmC,GAAG,IAAI,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACvG,OAAO,EAA2C,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACrH,OAAO,EAAuB,KAAK,MAAM,EAAoB,MAAM,UAAU,CAAC;AAE9E,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,gFAAgF;AAChF,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,mFAAmF;AACnF,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAIrC,oEAAoE;AACpE,MAAM,WAAW,WAAW;IAC1B,yCAAyC;IACzC,IAAI,EAAE,SAAS,CAAC;IAChB,sCAAsC;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,8GAA8G;IAC9G,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB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