@yarrow-uz/rn-map-sdk 0.0.0-stage → 0.1.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.
@@ -0,0 +1,702 @@
1
+ import { CameraRef, CameraRef as CameraRef$1, MapProps, MapRef, MapRef as MapRef$1, OfflinePackStatus, PressEventWithFeatures } from "@maplibre/maplibre-react-native";
2
+ import { ReactNode, Ref } from "react";
3
+ import { NativeSyntheticEvent, ViewProps } from "react-native";
4
+ declare const YARROW_MAP_URL: string;
5
+ declare const YARROW_SEARCH_API_URL: string;
6
+ export declare function setYarrowApiKey(apiKey: string): void;
7
+ export declare function getYarrowApiKey(): string;
8
+ /**
9
+ * Appends the configured API key as the `api_key` query parameter. Returns the
10
+ * url unchanged when no key is configured yet or the url cannot be parsed.
11
+ */
12
+ export declare function addApiKeyToUrl(url: string): string;
13
+ export declare function trackDau(apiKey: string, sdkType?: string): void;
14
+ /**
15
+ * Public alias of `STORAGE_KEY` so platform SDKs can build storage adapters
16
+ * (e.g. React Native AsyncStorage bridges) without hard-coding the key.
17
+ */
18
+ export declare const USER_TOKEN_STORAGE_KEY = "yarrow:user_token";
19
+ /**
20
+ * Minimal persistence contract for the anonymous user token. The default
21
+ * resolution uses `localStorage` when available (guarded — this is the only
22
+ * file in core allowed to touch it); shells without a DOM (e.g. React Native)
23
+ * can inject their own storage via `setTokenStorage`.
24
+ */
25
+ interface TokenStorage {
26
+ getItem(key: string): string | null;
27
+ setItem(key: string, value: string): void;
28
+ }
29
+ export declare function setTokenStorage(storage: TokenStorage): void;
30
+ export declare function getOrCreateUserToken(): string;
31
+ type CacheConfig = {
32
+ enabled?: boolean;
33
+ lifespanDays?: number;
34
+ };
35
+ type NormalizedCacheConfig = {
36
+ enabled: boolean;
37
+ lifespanDays: number;
38
+ };
39
+ type CachedArrayBufferResponse = {
40
+ data: ArrayBuffer;
41
+ cacheControl: string | null;
42
+ expires: string | null;
43
+ contentType: string | null;
44
+ };
45
+ type RouteFeature = {
46
+ type: 'Feature';
47
+ geometry: {
48
+ type: 'LineString';
49
+ coordinates: [number, number][];
50
+ };
51
+ properties: {
52
+ duration: number;
53
+ distance: number;
54
+ [key: string]: unknown;
55
+ };
56
+ };
57
+ type SearchResult = {
58
+ id?: string | number;
59
+ latitude?: number;
60
+ longitude?: number;
61
+ icon_img?: string;
62
+ name?: string;
63
+ /** Backend category, e.g. `{ id: 789, name: "school" }`. The `name` field
64
+ * matches sprite names loaded into the map's icon registry at init, so
65
+ * it's used as a fallback icon source when `icon_img` is missing. */
66
+ category?: {
67
+ id?: number;
68
+ name?: string;
69
+ };
70
+ [key: string]: unknown;
71
+ };
72
+ export declare const DEFAULT_CACHE_LIFESPAN_DAYS = 30;
73
+ export declare const MILLISECONDS_PER_DAY: number;
74
+ export declare const TILE_CACHE_NAME = "yarrow-cache-v1-tile";
75
+ export declare const ICON_CACHE_NAME = "yarrow-cache-v1-icon";
76
+ export declare const CACHE_PROTOCOL = "yarrowcache";
77
+ export declare const CACHED_AT_HEADER = "x-yarrow-cached-at";
78
+ /**
79
+ * Structural subset of maplibre-gl's `RequestParameters` covering the fields
80
+ * used for the network fetch. Any real maplibre `RequestParameters` object is
81
+ * assignable to this type.
82
+ */
83
+ type RequestParametersLike = {
84
+ method?: string;
85
+ headers?: {
86
+ [key: string]: string;
87
+ };
88
+ body?: BodyInit | null;
89
+ credentials?: 'omit' | 'same-origin' | 'include';
90
+ };
91
+ export declare const hasCacheStorage: () => boolean;
92
+ export declare const fetchArrayBufferWithCache: (url: string, cacheName: string, lifespanMs: number, abortController: AbortController, requestParameters?: RequestParametersLike) => Promise<CachedArrayBufferResponse>;
93
+ /** Routing API endpoint used by `fetchRoutes()`. */
94
+ export declare const ROUTE_API_URL = "https://api.yarrow.uz/api/routing/route";
95
+ /**
96
+ * Turn modifier returned by the routing API for a direction step.
97
+ * Falls back to `string` for any value not enumerated here.
98
+ */
99
+ type RouteDirectionModifier = 'move' | 'left' | 'right' | 'slight left' | 'slight right' | 'sharp left' | 'sharp right' | 'straight' | 'uturn' | (string & {});
100
+ /**
101
+ * A single turn-by-turn step in a route's directions.
102
+ *
103
+ * `distance`/`duration` are omitted on terminal steps (e.g. the final
104
+ * "arrive" instruction), so they are optional. `to_street` is only present
105
+ * when the step transitions onto a named street.
106
+ */
107
+ type RouteDirection = {
108
+ instruction: string;
109
+ modifier?: RouteDirectionModifier;
110
+ modifier_key?: string;
111
+ to_street?: string;
112
+ distance?: number;
113
+ duration?: number;
114
+ [key: string]: unknown;
115
+ };
116
+ /** Platform-agnostic input for `fetchRoutes()` — the network half of
117
+ * `buildRoute()`. Rendering/callback options stay in the platform SDKs. */
118
+ type FetchRoutesInput = {
119
+ profile: string;
120
+ coordinates: [number, number][];
121
+ language?: string;
122
+ /** Cancels the routing request. */
123
+ signal?: AbortSignal;
124
+ };
125
+ export declare const transformRouteCoordinates: (features: RouteFeature[]) => RouteFeature[];
126
+ interface RoutesMeta {
127
+ profile: string;
128
+ totalRoutes: number;
129
+ bestRouteIndex: number;
130
+ duration: number;
131
+ distance: number;
132
+ }
133
+ interface FetchRoutesResult {
134
+ features: RouteFeature[];
135
+ directions: RouteDirection[][];
136
+ meta: RoutesMeta;
137
+ }
138
+ /**
139
+ * Network half of the routing flow: POSTs the route request to the Yarrow
140
+ * routing API, parses and normalizes the response (coordinate order fix
141
+ * included). Rendering, events and camera work stay in the platform SDKs —
142
+ * they consume the returned features/directions/meta verbatim.
143
+ *
144
+ * Early "no route" outcomes resolve to an empty result (never throw), exactly
145
+ * like the web SDK's historic `buildRoute()` behavior.
146
+ */
147
+ export declare function fetchRoutes(input: FetchRoutesInput): Promise<FetchRoutesResult>;
148
+ export declare const haversineDistance: (lat1: number, lon1: number, lat2: number, lon2: number) => number;
149
+ interface FetchSearchResultsInput {
150
+ lat: number;
151
+ lon: number;
152
+ page?: number;
153
+ pageSize?: number;
154
+ signal: AbortSignal;
155
+ }
156
+ /**
157
+ * Queries the Yarrow search API around a coordinate. Pure network + mapping —
158
+ * marker rendering stays in the platform SDKs.
159
+ */
160
+ export declare function fetchSearchResults(query: string, input: FetchSearchResultsInput): Promise<SearchResult[]>;
161
+ type YarrowStyleType = 'default' | 'satellite' | 'hybrid';
162
+ /**
163
+ * Validates a user-supplied style type, warning (and falling back to
164
+ * `"default"`) on anything unrecognized. Verbatim behavior of the web SDK's
165
+ * `changeStyles()` guard.
166
+ */
167
+ export declare function normalizeStyleType(styleType?: string): YarrowStyleType;
168
+ /**
169
+ * Style-fetch endpoint for a style type/theme combination, e.g.
170
+ * `/styles/satellite/?dark=true`. Verbatim behavior of the web SDK's
171
+ * `YarrowStylesManager.buildStyleEndpoint()`.
172
+ */
173
+ export declare function buildStyleEndpoint(styleType: YarrowStyleType, theme: 'light' | 'dark'): string;
174
+ /**
175
+ * Configuration for the React Native map — the `container`-free counterpart
176
+ * of the web SDK's `YarrowMapConfigOptions`. The native view is sized by the
177
+ * consuming component's layout, so there is no container to name.
178
+ */
179
+ type YarrowMapConfigOptions = {
180
+ /** Yarrow API key from the dashboard. Required. */
181
+ apiKey: string;
182
+ /** Initial map center as `[longitude, latitude]`, e.g. Tashkent. */
183
+ center: [number, number];
184
+ /** Initial zoom level. Default `10`. */
185
+ zoom?: number;
186
+ /** Minimum zoom level. Default `0`. */
187
+ minZoom?: number;
188
+ /** Maximum zoom level. Default `19`. */
189
+ maxZoom?: number;
190
+ /** Style theme. Default `"light"`. */
191
+ theme?: 'light' | 'dark';
192
+ /** Base style. Default `"default"` (street map). */
193
+ styleType?: YarrowStyleType;
194
+ };
195
+ type YarrowMapViewProps = YarrowMapConfigOptions & {
196
+ /** Called once the native map finished loading its style. */
197
+ onReady?: (map: MapRef$1) => void;
198
+ /** Called when the style fails to load. */
199
+ onLoadError?: (error: Error) => void;
200
+ /** Called when the user presses the map (bubbles up from pressable
201
+ * sources unless they call `event.stopPropagation()`). */
202
+ onPress?: MapProps['onPress'];
203
+ /** Forwarded to the inner camera — use it for `flyTo`/`fitBounds`/`zoomTo`.
204
+ * The outer component ref is the `MapRef` (getCenter, queryRenderedFeatures…). */
205
+ cameraRef?: Ref<CameraRef$1>;
206
+ /** Attribution button. Default `true`. */
207
+ attribution?: boolean;
208
+ /** MapLibre logo. Default `true`. */
209
+ logo?: boolean;
210
+ /** Compass ornament. Default `true`. */
211
+ compass?: boolean;
212
+ /** Fire-and-forget DAU ping when the style first loads. Default `true`. */
213
+ dauTracking?: boolean;
214
+ /** Style for the wrapping native view. Default `{ flex: 1 }`. */
215
+ style?: ViewProps['style'];
216
+ /** Sources/layers/markers rendered inside the map. */
217
+ children?: ReactNode;
218
+ };
219
+ /**
220
+ * React Native Yarrow map. Renders MapLibre Native with a Yarrow style URL
221
+ * (theme + styleType aware, API key attached) and a default camera.
222
+ *
223
+ * ```tsx
224
+ * const mapRef = useRef<MapRef>(null);
225
+ * <YarrowMapView
226
+ * apiKey="YOUR_API_KEY"
227
+ * center={[69.2401, 41.2995]} // Tashkent
228
+ * zoom={12}
229
+ * theme="dark"
230
+ * onReady={(map) => map.getCenter().then(console.log)}
231
+ * />
232
+ * ```
233
+ *
234
+ * Camera props (`center`, `zoom`) apply only on mount — recenter through
235
+ * `cameraRef` (`flyTo`, `jumpTo`, `fitBounds`). Theme and styleType changes
236
+ * hot-swap the style URL natively.
237
+ */
238
+ export declare const YarrowMapView: import("react").ForwardRefExoticComponent<YarrowMapConfigOptions & {
239
+ /** Called once the native map finished loading its style. */
240
+ onReady?: (map: MapRef$1) => void;
241
+ /** Called when the style fails to load. */
242
+ onLoadError?: (error: Error) => void;
243
+ /** Called when the user presses the map (bubbles up from pressable
244
+ * sources unless they call `event.stopPropagation()`). */
245
+ onPress?: MapProps['onPress'];
246
+ /** Forwarded to the inner camera — use it for `flyTo`/`fitBounds`/`zoomTo`.
247
+ * The outer component ref is the `MapRef` (getCenter, queryRenderedFeatures…). */
248
+ cameraRef?: Ref<CameraRef$1>;
249
+ /** Attribution button. Default `true`. */
250
+ attribution?: boolean;
251
+ /** MapLibre logo. Default `true`. */
252
+ logo?: boolean;
253
+ /** Compass ornament. Default `true`. */
254
+ compass?: boolean;
255
+ /** Fire-and-forget DAU ping when the style first loads. Default `true`. */
256
+ dauTracking?: boolean;
257
+ /** Style for the wrapping native view. Default `{ flex: 1 }`. */
258
+ style?: ViewProps['style'];
259
+ /** Sources/layers/markers rendered inside the map. */
260
+ children?: ReactNode;
261
+ } & import("react").RefAttributes<MapRef$1>>;
262
+ type RoutePressEvent = NativeSyntheticEvent<PressEventWithFeatures>;
263
+ /**
264
+ * Called when a rendered route is pressed, with the press event (carrying the
265
+ * GeoJSON feature) and the route's index in the `routes` array.
266
+ */
267
+ type RoutePressHandler = (event: RoutePressEvent, routeIndex: number) => void;
268
+ type RouteLayerProps = {
269
+ /** Route line features — feed with `useYarrowRouting().routes` or your own
270
+ * `fetchRoutes()` result. Best route renders bold; the rest as fainter,
271
+ * thinner alternatives. */
272
+ routes: RouteFeature[];
273
+ /** Index of the route to highlight. Default `0`. */
274
+ bestIndex?: number;
275
+ /** Best-route color. Default `#22c55e`. */
276
+ routeColor?: string;
277
+ /** Best-route line width. Default `5`. */
278
+ routeWidth?: number;
279
+ /** Best-route opacity. Default `1`. */
280
+ routeOpacity?: number;
281
+ /** Alternative-route color. Defaults to the shared palette by index. */
282
+ alternativeColor?: string;
283
+ /** Alternative-route line width. Default `2.5`. */
284
+ alternativeWidth?: number;
285
+ /** Alternative-route opacity. Default `0.5`. */
286
+ alternativeOpacity?: number;
287
+ /** Prefix for source/layer ids. Default `"yarrow-route"`. */
288
+ layerPrefix?: string;
289
+ /** Called when a rendered route line is pressed. */
290
+ onPressRoute?: RoutePressHandler;
291
+ };
292
+ /**
293
+ * Declarative route rendering: one GeoJSON source + line layer per route.
294
+ * Compose inside `<YarrowMapView>` and drive it with `useYarrowRouting()`:
295
+ *
296
+ * ```tsx
297
+ * const { routes } = useYarrowRouting();
298
+ * <YarrowMapView apiKey={KEY} center={[69.2401, 41.2995]}>
299
+ * <RouteLayer routes={routes} onPressRoute={…} />
300
+ * </YarrowMapView>
301
+ * ```
302
+ */
303
+ export declare const RouteLayer: import("react").MemoExoticComponent<({ routes, bestIndex, routeColor, routeWidth, routeOpacity, alternativeColor, alternativeWidth, alternativeOpacity, layerPrefix, onPressRoute }: RouteLayerProps) => import("react/jsx-runtime").JSX.Element[]>;
304
+ /**
305
+ * Validated, defaulted RN map configuration. Mirrors the web SDK's
306
+ * `YarrowMapConfig` minus the DOM container (the native view is sized by the
307
+ * consuming app's layout) and minus web-only rendering options (hover,
308
+ * clustering, controls, tile cache — none of which exist on native).
309
+ */
310
+ export declare class YarrowMapConfig {
311
+ readonly center: [number, number];
312
+ readonly zoom: number;
313
+ readonly minZoom: number;
314
+ readonly maxZoom: number;
315
+ theme: 'light' | 'dark';
316
+ styleType: YarrowStyleType;
317
+ apiKey: string;
318
+ constructor(config: YarrowMapConfigOptions);
319
+ }
320
+ /**
321
+ * Full style URL for MapLibre React Native's `mapStyle` prop, built from the
322
+ * platform-agnostic style endpoint plus the configured API key. The key comes
323
+ * from core's module state (`setYarrowApiKey`) — `YarrowMapView` calls it for
324
+ * you; standalone callers must set it first.
325
+ */
326
+ export declare function buildStyleUrl(styleType?: string, theme?: 'light' | 'dark'): string;
327
+ type UseYarrowSearchOptions = {
328
+ /** Latitude the search ranks results around. */
329
+ lat: number;
330
+ /** Longitude the search ranks results around. */
331
+ lon: number;
332
+ /** Result page. Default `1`. */
333
+ page?: number;
334
+ /** Results per page. Default `15`. */
335
+ pageSize?: number;
336
+ /** Debounce before querying, ms. Default `300`. */
337
+ debounceMs?: number;
338
+ /** Set `false` to pause querying — pending results clear while paused.
339
+ * Default `true`. */
340
+ enabled?: boolean;
341
+ };
342
+ type UseYarrowSearchResult = {
343
+ results: SearchResult[];
344
+ isLoading: boolean;
345
+ error: Error | null;
346
+ };
347
+ /**
348
+ * Debounced, abortable search against the Yarrow search API.
349
+ *
350
+ * Requires the API key to be configured (`YarrowMapView` does this on mount;
351
+ * otherwise call `setYarrowApiKey()` first).
352
+ *
353
+ * ```tsx
354
+ * const { results, isLoading } = useYarrowSearch(query, {
355
+ * lat: position?.lat ?? 41.2995,
356
+ * lon: position?.lng ?? 69.2401,
357
+ * });
358
+ * ```
359
+ */
360
+ export declare const useYarrowSearch: (query: string, options: UseYarrowSearchOptions) => UseYarrowSearchResult;
361
+ type UseYarrowRoutingOptions = {
362
+ /** Routing profile, e.g. `"driving"`, `"walking"`. Default `"driving"`. */
363
+ profile?: string;
364
+ /** Language for turn-by-turn directions. */
365
+ language?: string;
366
+ };
367
+ type BuildRouteInput = {
368
+ /** Waypoints as `[longitude, latitude][]` (minimum two). */
369
+ coordinates: [number, number][];
370
+ /** Overrides the hook-level profile for this request. */
371
+ profile?: string;
372
+ /** Overrides the hook-level language for this request. */
373
+ language?: string;
374
+ /** Cancels the request. */
375
+ signal?: AbortSignal;
376
+ };
377
+ type UseYarrowRoutingResult = {
378
+ /** Renderable route features — feed straight into `<RouteLayer routes={…}>`. */
379
+ routes: RouteFeature[];
380
+ /** Turn-by-turn directions per route. */
381
+ directions: RouteDirection[][];
382
+ /** Duration/distance/profile summary of the best route, when present. */
383
+ meta: RoutesMeta | null;
384
+ isLoading: boolean;
385
+ error: Error | null;
386
+ /** Fetches routes and stores them in state. Rejects on network failure —
387
+ * "no route found" resolves to an empty result instead. */
388
+ buildRoute: (input: BuildRouteInput) => Promise<FetchRoutesResult>;
389
+ /** Clears routes/directions/meta and any error. */
390
+ clearRoutes: () => void;
391
+ };
392
+ /**
393
+ * Headless routing state for the Yarrow routing API — pairs with
394
+ * `<RouteLayer>` for rendering.
395
+ *
396
+ * ```tsx
397
+ * const { routes, isLoading, buildRoute } = useYarrowRouting({ profile: 'driving' });
398
+ * <YarrowMapView apiKey={KEY} center={[69.2401, 41.2995]}>
399
+ * <RouteLayer routes={routes} />
400
+ * </YarrowMapView>
401
+ * ```
402
+ */
403
+ export declare const useYarrowRouting: (options?: UseYarrowRoutingOptions) => UseYarrowRoutingResult;
404
+ /** Download progress of an offline region (normalized native pack status). */
405
+ type OfflineRegionProgress = Omit<OfflinePackStatus, 'id'>;
406
+ /**
407
+ * Geographic bounds as `[west, south, east, north]` — the flat corner order
408
+ * MapLibre React Native's `LngLatBounds` uses.
409
+ */
410
+ type OfflineBounds = [west: number, south: number, east: number, north: number];
411
+ type OfflineRegionDownloadOptions = {
412
+ /**
413
+ * Unique region name. Re-downloading an existing name returns the stored
414
+ * pack instead of creating a duplicate; a different name is required per
415
+ * style combination.
416
+ */
417
+ name: string;
418
+ /** Region bounds as `[west, south, east, north]`. */
419
+ bounds: OfflineBounds;
420
+ /** Lowest zoom level to pack. Default `8`. */
421
+ minZoom?: number;
422
+ /** Highest zoom level to pack. Default `15`. */
423
+ maxZoom?: number;
424
+ /** Style the pack pins. Default `"default"`. Offline style swaps only
425
+ * work for styles that were packed. */
426
+ styleType?: YarrowStyleType;
427
+ /** Theme the pack pins. Default `"light"`. */
428
+ theme?: 'light' | 'dark';
429
+ /**
430
+ * Days after which `listRegions()` flags the region `isStale`. Unlike the
431
+ * web cache there is no native TTL — staleness is informational; refresh
432
+ * with `handle.invalidate()`. Default `null` (never stale).
433
+ */
434
+ maxAgeDays?: number | null;
435
+ /** Delete and re-download an existing region with this name. Default `false`. */
436
+ force?: boolean;
437
+ /** Extra app-specific data stored alongside the region metadata, readable
438
+ * back via `listRegions()` → `userMetadata`. JSON-serializable only —
439
+ * native stores metadata as a JSON string. */
440
+ metadata?: Record<string, unknown>;
441
+ /** Progress while the region downloads. */
442
+ onProgress?: (progress: OfflineRegionProgress) => void;
443
+ /** Download failure. Fatal for the region — call `handle.resume()` to retry. */
444
+ onError?: (error: YarrowOfflineError) => void;
445
+ };
446
+ type OfflineRegionErrorCode =
447
+ /** The name exists with different parameters than the stored pack. */
448
+ 'params-mismatch' |
449
+ /** The region is too large for the native offline system. */
450
+ 'region-too-large' |
451
+ /** The native tile-count limit was hit (see `setTileCountLimit`). */
452
+ 'tile-count-limit-exceeded' | 'network' | 'disk' |
453
+ /** A handle referenced a region that no longer exists. */
454
+ 'not-found' | 'unknown';
455
+ type YarrowOfflineError = Error & {
456
+ code: OfflineRegionErrorCode;
457
+ /** Native pack id, when the error is tied to a region. */
458
+ regionId?: string;
459
+ };
460
+ type OfflineRegionSummary = {
461
+ id: string;
462
+ name: string;
463
+ styleType: YarrowStyleType;
464
+ theme: 'light' | 'dark';
465
+ bounds: OfflineBounds;
466
+ minZoom: number;
467
+ maxZoom: number;
468
+ status: OfflineRegionProgress['state'];
469
+ /** Download percentage, 0–100. */
470
+ percentage: number;
471
+ /** Bytes of tiles stored so far. */
472
+ completedTileSize: number;
473
+ /** True when `maxAgeDays` has elapsed since `createdAt`. */
474
+ isStale: boolean;
475
+ /** Epoch ms when the region was created. */
476
+ createdAt: number;
477
+ /** The `metadata` the app passed to `downloadRegion`, if any. */
478
+ userMetadata?: Record<string, unknown>;
479
+ };
480
+ type OfflineRegionHandle = {
481
+ /** Native pack id (UUID). */
482
+ id: string;
483
+ name: string;
484
+ /**
485
+ * Resolves with the final progress on completion, rejects with a
486
+ * `YarrowOfflineError` on the first download failure. It stays rejected
487
+ * after that — retry with `resume()` and track recovery through
488
+ * `onProgress` / `refreshStatus()` instead of awaiting `done` again.
489
+ */
490
+ done: Promise<OfflineRegionProgress>;
491
+ /** Current status snapshot from the native layer. */
492
+ refreshStatus: () => Promise<OfflineRegionProgress>;
493
+ pause: () => Promise<void>;
494
+ resume: () => Promise<void>;
495
+ /** Revalidates stored tiles against the server and re-fetches changed
496
+ * ones — the cheap refresh path. */
497
+ invalidate: () => Promise<void>;
498
+ delete: () => Promise<void>;
499
+ };
500
+ type OfflineRegionEstimate = {
501
+ /** Unique `z/x/y` tiles across `[minZoom, maxZoom]`. Each style downloads
502
+ * one tile per source (≈12 vector sources, satellite adds a raster one),
503
+ * so network/storage cost scales with the style's source count too. */
504
+ tileCount: number;
505
+ /** Rough storage estimate: `tileCount × avgTileBytes`. */
506
+ estSizeBytes: number;
507
+ tilesPerLevel: Array<{
508
+ zoom: number;
509
+ tiles: number;
510
+ }>;
511
+ };
512
+ /** Default minimum zoom for offline regions. */
513
+ export declare const DEFAULT_OFFLINE_MIN_ZOOM = 8;
514
+ /** Default maximum zoom for offline regions. */
515
+ export declare const DEFAULT_OFFLINE_MAX_ZOOM = 15;
516
+ /** Schema version of the pack metadata this SDK writes. */
517
+ export declare const OFFLINE_METADATA_VERSION = 1;
518
+ /**
519
+ * Rough bytes per downloaded `z/x/y` tile, empirically measured from a
520
+ * Tashkent z14 tile: ≈64 KB × ~8 sources carrying data ≈ 0.5 MB. A region's
521
+ * true size depends on the style's source count and local data density —
522
+ * pass `avgTileBytes` for a tighter estimate.
523
+ */
524
+ export declare const AVG_TILE_BYTES = 500000;
525
+ type EstimateRegionInput = {
526
+ bounds: OfflineBounds;
527
+ minZoom: number;
528
+ maxZoom: number;
529
+ /** Bytes per `z/x/y` tile used for the size estimate. Default `500_000`. */
530
+ avgTileBytes?: number;
531
+ };
532
+ /**
533
+ * Estimates the download/storage cost of an offline region — pure tile math,
534
+ * no native calls. Tile counts are exact for the XYZ scheme; byte estimates
535
+ * are rough (see `AVG_TILE_BYTES`).
536
+ *
537
+ * ```ts
538
+ * const { tileCount, estSizeBytes } = estimateRegion({
539
+ * bounds: [69.15, 41.2, 69.4, 41.4], // Tashkent
540
+ * minZoom: 8,
541
+ * maxZoom: 15,
542
+ * });
543
+ * ```
544
+ */
545
+ export declare const estimateRegion: (input: EstimateRegionInput) => OfflineRegionEstimate;
546
+ type YarrowOfflineManagerOptions = {
547
+ /** Yarrow API key from the dashboard. Required. */
548
+ apiKey: string;
549
+ };
550
+ /**
551
+ * Offline region manager for React Native — a Yarrow-flavoured wrapper around
552
+ * MapLibre React Native's `OfflineManager`.
553
+ *
554
+ * The web SDK's `yarrowcache` protocol cannot exist on native (no
555
+ * `addProtocol`), so offline support here is region packs: pick a bounding
556
+ * box and zoom range, download it once, and the map renders from the native
557
+ * offline database with no network.
558
+ *
559
+ * ```ts
560
+ * const offline = new YarrowOfflineManager({ apiKey: 'YOUR_API_KEY' });
561
+ * const { tileCount, estSizeBytes } = offline.estimateRegion({
562
+ * bounds: [69.15, 41.2, 69.4, 41.4], // Tashkent
563
+ * minZoom: 8,
564
+ * maxZoom: 15,
565
+ * });
566
+ * const region = await offline.downloadRegion({
567
+ * name: 'tashkent-city',
568
+ * bounds: [69.15, 41.2, 69.4, 41.4],
569
+ * maxAgeDays: 30,
570
+ * onProgress: (p) => console.log(`${p.percentage}%`),
571
+ * });
572
+ * await region.done;
573
+ * ```
574
+ */
575
+ export declare class YarrowOfflineManager {
576
+ private readonly apiKey;
577
+ /**
578
+ * Downloads this session created, keyed by pack id. MLRN's listener maps
579
+ * are last-write-wins, so re-attaching listeners over a live download
580
+ * would strand the original handle — `reattachExisting` consults this map
581
+ * and reuses the original `done` instead.
582
+ */
583
+ private readonly activeDownloads;
584
+ constructor(options: YarrowOfflineManagerOptions);
585
+ /**
586
+ * Pure tile-math estimate of a region's download/storage cost — no native
587
+ * calls. See `estimateRegion` for the math and caveats.
588
+ */
589
+ estimateRegion(input: Parameters<typeof estimateRegion>[0]): OfflineRegionEstimate;
590
+ /**
591
+ * Starts (or resumes) a region download. Resolves with a handle once the
592
+ * pack is created and downloading — progress arrives via `options.onProgress`
593
+ * and `handle.done` settles with the outcome.
594
+ *
595
+ * Idempotent by `name`: an existing matching region is returned as-is
596
+ * (resumed when incomplete); a name reused with different parameters throws
597
+ * a `params-mismatch` error. Pass `force: true` to delete and re-download.
598
+ */
599
+ downloadRegion(options: OfflineRegionDownloadOptions): Promise<OfflineRegionHandle>;
600
+ /** Lists regions created through this SDK (native packs created directly
601
+ * against `OfflineManager` are not included), newest first. */
602
+ listRegions(): Promise<OfflineRegionSummary[]>;
603
+ /** Returns the handle for a region by name, or `null`. */
604
+ getRegion(name: string): Promise<OfflineRegionHandle | null>;
605
+ /** Ambient cache (seen-tiles LRU) max size in bytes. May erase resources
606
+ * when shrinking — call once at app startup. `0` disables the cache. */
607
+ setAmbientCacheSize(size: number): Promise<void>;
608
+ /** Revalidates ambient-cache tiles against the server — the recommended
609
+ * way to refresh cached data. */
610
+ invalidateAmbientCache(): Promise<void>;
611
+ /** Erases ambient-cache resources. Computationally expensive. */
612
+ clearAmbientCache(): Promise<void>;
613
+ /** Maximum number of tiles offline packs may store. Raise it when large
614
+ * regions fail with a `tile-count-limit-exceeded` error. */
615
+ setTileCountLimit(limit: number): void;
616
+ /** Download status event throttle in ms. Platform-defined default (300 ms
617
+ * today on both iOS and Android). Note errors bypass the throttle. */
618
+ setProgressEventThrottle(ms: number): void;
619
+ /** Deletes the offline database (ambient cache + packs), then
620
+ * reinitializes it. Destructive — and MLRN's JS pack cache only clears
621
+ * on app restart, so subsequent reads may hit stale ids (guarded as
622
+ * `not-found`). Prefer per-region `invalidate`/`delete`. */
623
+ resetDatabase(): Promise<void>;
624
+ private hydrate;
625
+ private findRegionPacks;
626
+ private findParamMismatches;
627
+ /** Attaches listeners to a pack that may have outlived the JS layer
628
+ * (created in a previous app session) and builds a fresh handle.
629
+ *
630
+ * Deliberately cautious: it never hijacks a download this session owns,
631
+ * never attaches listeners to packs that don't need them, and — on
632
+ * Android, where attaching an observer *activates* the region — never
633
+ * wakes a paused pack unless the caller explicitly asked for a download. */
634
+ private reattachExisting;
635
+ private toHandle;
636
+ private deletePack;
637
+ }
638
+ type UseYarrowOfflineRegionsOptions = {
639
+ /** Yarrow API key from the dashboard. Required. */
640
+ apiKey: string;
641
+ /** Poll interval while any region is downloading, ms. Default `1000`. */
642
+ pollMs?: number;
643
+ };
644
+ type UseYarrowOfflineRegionsResult = {
645
+ /** All regions created through the SDK, newest first. */
646
+ regions: OfflineRegionSummary[];
647
+ /** True during the initial `listRegions()` load. */
648
+ isLoading: boolean;
649
+ error: Error | null;
650
+ /** Re-reads regions from the native layer. */
651
+ refresh: () => Promise<void>;
652
+ /** Starts a region download (idempotent by `name` — see
653
+ * `YarrowOfflineManager.downloadRegion`). */
654
+ download: (options: OfflineRegionDownloadOptions) => Promise<OfflineRegionHandle>;
655
+ pause: (name: string) => Promise<void>;
656
+ resume: (name: string) => Promise<void>;
657
+ /** Revalidates stored tiles against the server — the cheap refresh path. */
658
+ invalidate: (name: string) => Promise<void>;
659
+ remove: (name: string) => Promise<void>;
660
+ };
661
+ /**
662
+ * Offline region state for settings/offline screens — pairs with
663
+ * `YarrowOfflineManager`. Polls the native layer while downloads run, so
664
+ * `regions` (and progress bars) stay current.
665
+ *
666
+ * ```tsx
667
+ * const { regions, download, remove } = useYarrowOfflineRegions({ apiKey });
668
+ * await download({ name: 'tashkent', bounds: [69.15, 41.2, 69.4, 41.4] });
669
+ * ```
670
+ */
671
+ export declare const useYarrowOfflineRegions: (options: UseYarrowOfflineRegionsOptions) => UseYarrowOfflineRegionsResult;
672
+ /**
673
+ * Minimal slice of `@react-native-async-storage/async-storage` the adapter
674
+ * needs. Accepting a structural type (instead of importing the module) keeps
675
+ * the async-storage peer dependency optional.
676
+ */
677
+ type AsyncStorageLike = {
678
+ getItem(key: string): Promise<string | null>;
679
+ setItem(key: string, value: string): Promise<void>;
680
+ };
681
+ /**
682
+ * Bridges the async AsyncStorage API onto core's synchronous TokenStorage
683
+ * contract: the existing token hydrates into memory once, reads are served
684
+ * synchronously from that cache, and writes mirror in-memory before flushing
685
+ * to AsyncStorage (fire-and-forget).
686
+ *
687
+ * If the initial read throws, the override is left unset entirely: core then
688
+ * degrades to ephemeral tokens *without persisting anything*, so a transient
689
+ * read failure can never overwrite the stored identity with a fresh token.
690
+ *
691
+ * Await this once during app startup, before the first map or tracking call
692
+ * (tokens generated before this resolves are ephemeral by design):
693
+ *
694
+ * ```ts
695
+ * import AsyncStorage from '@react-native-async-storage/async-storage';
696
+ * import { setAsyncStorageTokenStorage } from '@yarrow-uz/rn-map-sdk';
697
+ *
698
+ * await setAsyncStorageTokenStorage(AsyncStorage);
699
+ * ```
700
+ */
701
+ export declare function setAsyncStorageTokenStorage(storage: AsyncStorageLike): Promise<void>;
702
+ export { type AsyncStorageLike, type BuildRouteInput, type CacheConfig, type CachedArrayBufferResponse, type CameraRef, type FetchRoutesInput, type FetchRoutesResult, type MapRef, type NormalizedCacheConfig, type OfflineBounds, type OfflineRegionDownloadOptions, type OfflineRegionErrorCode, type OfflineRegionEstimate, type OfflineRegionHandle, type OfflineRegionProgress, type OfflineRegionSummary, type RouteDirection, type RouteDirectionModifier, type RouteFeature, type RouteLayerProps, type RoutesMeta, type SearchResult, type TokenStorage, type UseYarrowOfflineRegionsOptions, type UseYarrowOfflineRegionsResult, type UseYarrowRoutingOptions, type UseYarrowRoutingResult, type UseYarrowSearchOptions, type UseYarrowSearchResult, YARROW_MAP_URL, YARROW_SEARCH_API_URL, type YarrowMapConfigOptions, type YarrowMapViewProps, type YarrowOfflineError, type YarrowOfflineManagerOptions, type YarrowStyleType };