@mapslibvn/react-native 0.4.0 → 0.5.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.
package/dist/index.d.ts CHANGED
@@ -1,225 +1,36 @@
1
1
  import * as react from 'react';
2
2
  import { RefObject, ReactNode, ReactElement } from 'react';
3
+ import { b as SessionEvents, T as TravelMode, c as NavigationSession, d as NavigationSessionStartOptions, e as NavigationProgress, f as NavigationStatus, M as MapsLibVNClient, D as DirectionsResponse, g as Theme, L as Lang, P as PoiSource, N as NavigationSessionOptions, h as PoiFeature, i as AutocompleteItem, G as GeoFix, j as PositionSource } from './session-B7Fu_s_b.js';
4
+ export { k as Announcement, A as AudioSession, B as BackgroundUnavailable, l as DirectionsLang, m as DirectionsOptions, K as KeepAwake, n as MISSING_SOURCE_MESSAGE, o as ManeuverKind, p as NAVIGATION_THRESHOLDS, q as NavigationEvents, r as NavigationThresholds, s as Place, t as PositionError, R as Route, u as RouteLeg, v as RouteProvider, w as RouteStep, S as SessionPositionSource, a as Speaker, x as createClient, y as createNavigationSession, z as createNavigator, C as decodePolyline6, E as formatDistance, F as formatDistanceShort, H as simulateFixes } from './session-B7Fu_s_b.js';
3
5
  import { StyleProp, ViewStyle } from 'react-native';
4
- import { MapRef, CameraRef, Anchor } from '@maplibre/maplibre-react-native';
6
+ import { ViewPadding, MapRef, CameraRef, Anchor } from '@maplibre/maplibre-react-native';
5
7
 
6
- /**
7
- * Nguồn POI profile archive (spec 07/09 mục 4). Đây là nguồn sự thật duy nhất cho API, SDK và
8
- * pipeline: thêm profile mới = thêm một dòng vào POI_SOURCE_PROFILES + một lần export-tiles.
9
- */
10
- declare const POI_SOURCES: readonly ["osm", "overture", "fsq"];
11
- type PoiSource = (typeof POI_SOURCES)[number];
12
-
13
- /** Kiểu dữ liệu Places API (spec 6.1) dùng chung cho Worker và SDK. */
14
- interface PlaceCategory {
15
- code: string;
16
- group: string;
17
- name_vi: string;
18
- name_en: string;
19
- }
20
- interface PlaceAddress {
21
- housenumber?: string;
22
- street?: string;
23
- ward?: string;
24
- province?: string;
25
- text?: string;
26
- }
27
- interface Place {
28
- id: string;
29
- name: string;
30
- category: PlaceCategory | null;
31
- lat: number;
32
- lng: number;
33
- address: PlaceAddress;
34
- contact?: Record<string, unknown> | null;
35
- hours?: unknown;
36
- quality_score: number | null;
37
- status: 'active' | 'closed' | 'pending' | 'rejected';
38
- updated_at: string;
39
- }
40
- interface PlaceSource {
41
- source: 'osm' | 'overture' | 'fsq';
42
- source_id: string;
43
- role: 'primary' | 'secondary';
44
- }
45
- interface PlaceDetails extends Place {
46
- sources: PlaceSource[];
47
- attribution: {
48
- text: string;
49
- html: string;
50
- };
51
- }
52
- type GeocodePrecision = 'rooftop' | 'alley' | 'interpolated' | 'street' | 'ward' | 'district' | 'province';
53
- type AutocompleteType = 'poi' | 'street' | 'address' | 'area';
54
- interface AutocompleteItem {
55
- type: AutocompleteType;
56
- id?: string;
57
- name: string;
58
- secondary: string;
59
- lat: number;
60
- lng: number;
61
- precision?: GeocodePrecision;
62
- score: number;
63
- bbox?: [number, number, number, number];
64
- /** Tên thay thế (OSM `alt_name`/`old_name`) đã khớp truy vấn, ví dụ "Công Lý" (spec 6.3). */
65
- matched_alt?: string;
66
- }
67
- interface GeocodeMatched {
68
- housenumber?: string;
69
- street?: string;
70
- ward?: string;
71
- province?: string;
72
- former?: {
73
- ward?: string;
74
- district?: string;
75
- province?: string;
76
- };
77
- }
78
- interface GeocodeItem {
79
- lat: number;
80
- lng: number;
81
- precision: GeocodePrecision;
82
- confidence: number;
83
- matched: GeocodeMatched;
84
- display_name: string;
85
- bbox?: [number, number, number, number];
86
- }
87
- interface ReverseAddress {
88
- approx_housenumber?: string;
89
- street?: string;
90
- ward?: string;
91
- province?: string;
92
- display_name: string;
93
- }
94
- interface ReverseResponse {
95
- address: ReverseAddress;
96
- nearest_poi: Place | null;
97
- }
98
- type EditKind = 'create' | 'update' | 'close' | 'reopen' | 'report';
99
- /** Trường được phép sửa/khai khi đóng góp (spec 6.1 + 6.5). */
100
- interface EditChanges {
101
- name?: string;
102
- lat?: number;
103
- lng?: number;
104
- category?: string;
105
- housenumber?: string;
106
- street?: string;
107
- ward?: string;
108
- province?: string;
109
- address_text?: string;
110
- contact?: {
111
- phone?: string[];
112
- website?: string[];
113
- facebook?: string;
114
- };
115
- /** Chuỗi opening_hours OSM hoặc {osm: chuỗi}. */
116
- hours?: string | {
117
- osm: string;
118
- };
119
- }
120
- interface SuggestEditRequest {
121
- /** Bắt buộc trừ kind='create'. */
122
- poi_id?: string;
123
- kind: EditKind;
124
- changes?: EditChanges;
125
- photo_url?: string;
126
- note?: string;
127
- /** Chuỗi ổn định theo người dùng cuối do app nhúng cấp — server chỉ lưu bản băm. */
128
- end_user_token: string;
129
- }
130
- interface SuggestEditResponse {
131
- edit_id: number;
132
- status: 'pending' | 'auto_approved';
133
- /** POI đích; với kind='create' là id POI mới (pending cho tới khi được duyệt). */
134
- poi_id: string | null;
135
- }
136
- /** POI đọc từ tile lớp `poi` khi người dùng bấm — SDK web và React Native dùng chung. */
137
- interface PoiFeature {
138
- id: string;
139
- name: string;
140
- category: string;
141
- group: string;
142
- lngLat: [number, number];
143
- }
144
-
145
- type Theme = 'light' | 'dark';
146
- interface ClientOptions {
147
- /** Khoá API dạng mlv_live_… */
148
- apiKey: string;
149
- /** Gốc API, ví dụ https://maps-api.example.com */
150
- baseUrl: string;
151
- /** Cho phép tiêm fetch cho test hoặc môi trường không có global fetch. */
152
- fetch?: typeof globalThis.fetch;
153
- /**
154
- * Header thêm cho mọi request, ví dụ `X-Bundle-Id` cho khoá `mobile` (spec 6.4).
155
- * Không ghi đè được `X-Api-Key`.
156
- */
157
- headers?: Record<string, string>;
158
- /**
159
- * Tập nguồn POI cho bản đồ và Places API (spec 07/09). Mặc định cả ba nguồn.
160
- * Áp cho autocomplete/search/nearby/reverse và `styleUrl`; `getPlace`/`geocode` không lọc.
161
- */
162
- poiSources?: readonly PoiSource[];
163
- }
164
- interface AttributionResponse {
165
- text: string;
166
- html: string;
167
- links: {
168
- text: string;
169
- href: string;
170
- license?: string;
171
- }[];
8
+ interface FollowOptions {
9
+ /** Mặc định theo phương tiện: walk 17, motorbike 16,5, car 15,5. */
10
+ zoom?: number;
11
+ /** Mặc định 45. */
12
+ pitch?: number;
13
+ padding?: ViewPadding;
14
+ }
15
+ declare const FOLLOW_ZOOM: Readonly<Record<TravelMode, number>>;
16
+ declare const FOLLOW_PITCH = 45;
17
+ interface BindingEvents extends SessionEvents {
18
+ followChange: boolean;
19
+ }
20
+ /** Thứ lộ ra qua `useMap().navigation` — uỷ quyền sang phiên, thêm bám camera của map này. */
21
+ interface MapNavigationBinding {
22
+ /** Phiên qua prop `navigation`, không thì phiên mặc định của map (tạo lười). */
23
+ readonly session: NavigationSession;
24
+ readonly following: boolean;
25
+ recenter(): void;
26
+ start(opts: NavigationSessionStartOptions): Promise<void>;
27
+ stop(): Promise<void>;
28
+ reroute(): Promise<void>;
29
+ readonly state: NavigationProgress | null;
30
+ readonly status: NavigationStatus;
31
+ on<K extends keyof BindingEvents>(event: K, handler: (e: BindingEvents[K]) => void): void;
32
+ off<K extends keyof BindingEvents>(event: K, handler: (e: BindingEvents[K]) => void): void;
172
33
  }
173
- declare function createClient(options: ClientOptions): {
174
- baseUrl: string;
175
- attribution: () => Promise<AttributionResponse>;
176
- styleUrl: (theme: Theme) => string;
177
- autocomplete: (q: string, opts?: {
178
- near?: [number, number];
179
- limit?: number;
180
- types?: AutocompleteType[];
181
- }) => Promise<{
182
- items: AutocompleteItem[];
183
- }>;
184
- search: (q: string, opts?: {
185
- category?: string;
186
- near?: [number, number];
187
- radius?: number;
188
- bbox?: [number, number, number, number];
189
- limit?: number;
190
- offset?: number;
191
- }) => Promise<{
192
- items: Place[];
193
- total: number;
194
- }>;
195
- nearby: (opts: {
196
- lat: number;
197
- lng: number;
198
- radius?: number;
199
- category?: string;
200
- limit?: number;
201
- }) => Promise<{
202
- items: Place[];
203
- }>;
204
- getPlace: (id: string) => Promise<PlaceDetails>;
205
- geocode: (q: string, opts?: {
206
- near?: [number, number];
207
- limit?: number;
208
- }) => Promise<{
209
- items: GeocodeItem[];
210
- }>;
211
- reverse: (lat: number, lng: number) => Promise<ReverseResponse>;
212
- /** Gửi đóng góp/sửa POI (spec 6.1). Khoá phải có scope edits:write. */
213
- suggestEdit: (edit: SuggestEditRequest) => Promise<SuggestEditResponse>;
214
- };
215
- type MapsLibVNClient = ReturnType<typeof createClient>;
216
-
217
- /**
218
- * Biến đổi style JSON thuần (không cần Map đang chạy) — dùng cho React Native, nơi wrapper
219
- * không có API đổi layout property của lớp có sẵn. Web dùng `applyLanguage` lúc chạy nhưng
220
- * chia sẻ `nameExpression`/`isNameLabelLayer` từ đây.
221
- */
222
- type Lang = 'vi' | 'en';
223
34
 
224
35
  /** Tay cầm map — tương ứng `MapsLibVNMap` của web: `native` thay `gl`. */
225
36
  interface MapHandle {
@@ -232,6 +43,38 @@ interface MapHandle {
232
43
  fitBounds(bbox: [number, number, number, number], padding?: number): void;
233
44
  /** [west, south, east, north] */
234
45
  getBounds(): Promise<[number, number, number, number]>;
46
+ /** Vẽ tuyến không cần phiên (xem trước, app khách). Phiên gắn vào sẽ ghi đè. */
47
+ routes: {
48
+ show(response: DirectionsResponse, opts?: {
49
+ active?: number;
50
+ }): void;
51
+ setActive(index: number): void;
52
+ clear(): void;
53
+ };
54
+ /** Dẫn đường của map này: phiên qua prop `navigation`, không thì phiên mặc định tạo lười. */
55
+ navigation: MapNavigationBinding;
56
+ }
57
+
58
+ declare const ROUTE_SOURCE_ID = "mapslibvn-route";
59
+ declare const ROUTE_LAYER_IDS: {
60
+ readonly alt: "mapslibvn-route-alt";
61
+ readonly casing: "mapslibvn-route-casing";
62
+ readonly line: "mapslibvn-route-line";
63
+ readonly traveled: "mapslibvn-route-traveled";
64
+ readonly puck: "mapslibvn-route-puck";
65
+ };
66
+ declare const ROUTE_COLOR = "#2458a6";
67
+ declare const ALT_ROUTE_COLOR = "#9ca8ba";
68
+ declare const DESTINATION_COLOR = "#d92d20";
69
+ interface RouteStyle {
70
+ /** Tuyến chính và phần đã đi — mặc định #2458a6. */
71
+ color?: string;
72
+ /** Tuyến thay thế — mặc định #9ca8ba. */
73
+ altColor?: string;
74
+ /** Viền tuyến chính — mặc định trắng. */
75
+ casingColor?: string;
76
+ /** Độ mờ phần đã đi — mặc định 0,35. */
77
+ traveledOpacity?: number;
235
78
  }
236
79
 
237
80
  declare const DEFAULT_CENTER: [number, number];
@@ -256,13 +99,26 @@ interface MapsLibVNMapProps {
256
99
  bundleId?: string;
257
100
  /** Style của khung View bọc ngoài */
258
101
  containerStyle?: StyleProp<ViewStyle>;
102
+ /** Phiên dẫn đường gắn vào map để vẽ tuyến, puck, camera bám; bỏ prop → gỡ và xoá tuyến. */
103
+ navigation?: NavigationSession;
104
+ /** Tuỳ chọn cho phiên mặc định (khi không truyền `navigation`); cần ít nhất `source`. */
105
+ sessionOptions?: Omit<NavigationSessionOptions, 'provider'>;
106
+ /** Camera bám vị trí khi dẫn đường — mặc định true (zoom theo phương tiện, pitch 45). */
107
+ follow?: boolean | FollowOptions;
108
+ /** Vẽ mũi tên vị trí — mặc định true; false để app tự vẽ từ `progress.snapped`. */
109
+ puck?: boolean;
110
+ routeStyle?: RouteStyle;
111
+ /** Chèn tuyến dưới lớp này; mặc định lớp symbol đầu tiên của theme; null = trên cùng. */
112
+ routeBeforeLayerId?: string | null;
113
+ /** Bấm tuyến thay thế. */
114
+ onRouteClick?: (index: number) => void;
259
115
  onLoad?: (map: MapHandle) => void;
260
116
  onPoiClick?: (poi: PoiFeature) => void;
261
117
  onError?: (error: Error) => void;
262
118
  testID?: string;
263
119
  children?: ReactNode;
264
120
  }
265
- declare function MapsLibVNMap({ apiKey, apiBase, style, center, zoom, lang, poiLayer, poiSources, compactAttribution, bundleId, containerStyle, onLoad, onPoiClick, onError, testID, children, }: MapsLibVNMapProps): react.JSX.Element;
121
+ declare function MapsLibVNMap({ apiKey, apiBase, style, center, zoom, lang, poiLayer, poiSources, compactAttribution, bundleId, containerStyle, navigation, sessionOptions, follow, puck, routeStyle, routeBeforeLayerId, onRouteClick, onLoad, onPoiClick, onError, testID, children, }: MapsLibVNMapProps): react.JSX.Element;
266
122
  /** Map hiện hành — chỉ dùng bên trong <MapsLibVNMap>. */
267
123
  declare function useMap(): MapHandle;
268
124
 
@@ -297,7 +153,32 @@ interface UsePlacesResult {
297
153
  /** Autocomplete kiểu SWR: giữ items cũ khi tải và bỏ qua response của query đã huỷ. */
298
154
  declare function usePlaces(query: string, options?: UsePlacesOptions): UsePlacesResult;
299
155
 
156
+ interface UseNavigationResult {
157
+ status: NavigationStatus;
158
+ progress: NavigationProgress | null;
159
+ /** Camera của map trong context đang bám; luôn false khi hook nhận `session` tường minh. */
160
+ following: boolean;
161
+ start(opts: NavigationSessionStartOptions): Promise<void>;
162
+ stop(): Promise<void>;
163
+ reroute(): Promise<void>;
164
+ /** Bật lại bám camera của map trong context; no-op khi không có map. */
165
+ recenter(): void;
166
+ }
167
+ /**
168
+ * Không tham số → dùng `useMap().navigation` (phải nằm trong `<MapsLibVNMap>`).
169
+ * Có `session` → dùng được ở bất kỳ đâu (banner ngoài map, màn hình khác).
170
+ */
171
+ declare function useNavigation(session?: NavigationSession): UseNavigationResult;
172
+
300
173
  /** Dòng gọn khi `compactAttribution`; bấm vào mở hộp thoại native với đủ nguồn. */
301
174
  declare const COMPACT_ATTRIBUTION = "\u00A9 MapsLibVN \u00B7 \u00A9 OpenStreetMap contributors";
302
175
 
303
- export { type AutocompleteItem, COMPACT_ATTRIBUTION, DEFAULT_CENTER, DEFAULT_MARKER_COLOR, DEFAULT_ZOOM, type Lang, type MapHandle, type MapsLibVNClient, MapsLibVNMap, type MapsLibVNMapProps, Marker, type MarkerProps, type Place, type PoiFeature, type PoiSource, type Theme, type UsePlacesOptions, type UsePlacesResult, useMap, usePlaces };
176
+ /**
177
+ * Phát lại chuỗi fix (ví dụ từ `simulateFixes`) theo chênh timestamp chia `rate`; `rate: 0` phát
178
+ * hết trong một tick. Copy từ `@mapslibvn/web` — core không có timer nên không đặt ở đó.
179
+ */
180
+ declare function playbackSource(fixes: readonly GeoFix[], options?: {
181
+ rate?: number;
182
+ }): PositionSource;
183
+
184
+ export { ALT_ROUTE_COLOR, AutocompleteItem, type BindingEvents, COMPACT_ATTRIBUTION, DEFAULT_CENTER, DEFAULT_MARKER_COLOR, DEFAULT_ZOOM, DESTINATION_COLOR, DirectionsResponse, FOLLOW_PITCH, FOLLOW_ZOOM, type FollowOptions, GeoFix, Lang, type MapHandle, type MapNavigationBinding, MapsLibVNClient, MapsLibVNMap, type MapsLibVNMapProps, Marker, type MarkerProps, NavigationProgress, NavigationSession, NavigationSessionOptions, NavigationSessionStartOptions, NavigationStatus, PoiFeature, PoiSource, PositionSource, ROUTE_COLOR, ROUTE_LAYER_IDS, ROUTE_SOURCE_ID, type RouteStyle, SessionEvents, Theme, TravelMode, type UseNavigationResult, type UsePlacesOptions, type UsePlacesResult, playbackSource, useMap, useNavigation, usePlaces };