@craft-native/ts-maps 0.0.37

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/src/types.ts ADDED
@@ -0,0 +1,237 @@
1
+ /**
2
+ * TypeScript mirrors of the Craft Zig map types defined in
3
+ * `packages/zig/src/maps.zig`. Field names match the Zig struct field names
4
+ * exactly so a straight `JSON.stringify` round-trips cleanly across the
5
+ * bridge without a renaming layer.
6
+ *
7
+ * @module @craft-native/ts-maps/types
8
+ */
9
+
10
+ // ---------------------------------------------------------------------------
11
+ // Providers & map types
12
+ // ---------------------------------------------------------------------------
13
+
14
+ /**
15
+ * Matches `MapProvider` in `maps.zig`. String-literal union so JSON
16
+ * serialization emits the Zig enum tag name directly.
17
+ */
18
+ export type MapProvider =
19
+ | 'apple_maps'
20
+ | 'google_maps'
21
+ | 'mapbox'
22
+ | 'openstreetmap'
23
+ | 'here_maps'
24
+ | 'ts_maps'
25
+
26
+ /** Matches `MapType` in `maps.zig`. */
27
+ export type MapType =
28
+ | 'standard'
29
+ | 'satellite'
30
+ | 'hybrid'
31
+ | 'terrain'
32
+ | 'muted_standard'
33
+ | 'satellite_flyover'
34
+ | 'hybrid_flyover'
35
+
36
+ /** Matches `UserTrackingMode` in `maps.zig`. */
37
+ export type UserTrackingMode = 'none' | 'follow' | 'follow_with_heading'
38
+
39
+ /** Matches `MarkerColor` in `maps.zig`. */
40
+ export type MarkerColor =
41
+ | 'red'
42
+ | 'green'
43
+ | 'blue'
44
+ | 'yellow'
45
+ | 'orange'
46
+ | 'purple'
47
+ | 'cyan'
48
+ | 'magenta'
49
+
50
+ /** Matches `StrokePattern` in `maps.zig`. */
51
+ export type StrokePattern = 'solid' | 'dashed' | 'dotted' | 'dash_dot'
52
+
53
+ /** Matches `MapEvent` in `maps.zig`. */
54
+ export type MapEvent =
55
+ | 'region_changed'
56
+ | 'region_will_change'
57
+ | 'did_finish_loading'
58
+ | 'did_fail_loading'
59
+ | 'annotation_selected'
60
+ | 'annotation_deselected'
61
+ | 'annotation_drag_started'
62
+ | 'annotation_dragged'
63
+ | 'annotation_drag_ended'
64
+ | 'user_location_updated'
65
+ | 'camera_changed'
66
+ | 'tap'
67
+ | 'long_press'
68
+ | 'poi_selected'
69
+
70
+ // ---------------------------------------------------------------------------
71
+ // Geographic primitives
72
+ // ---------------------------------------------------------------------------
73
+
74
+ /** Matches `Coordinate` in `maps.zig`. */
75
+ export interface Coordinate {
76
+ latitude: number
77
+ longitude: number
78
+ }
79
+
80
+ /** Matches `CoordinateSpan` in `maps.zig`. */
81
+ export interface CoordinateSpan {
82
+ latitude_delta: number
83
+ longitude_delta: number
84
+ }
85
+
86
+ /** Matches `MapRegion` in `maps.zig`. */
87
+ export interface MapRegion {
88
+ center: Coordinate
89
+ span: CoordinateSpan
90
+ }
91
+
92
+ /** Matches `BoundingBox` in `maps.zig`. */
93
+ export interface BoundingBox {
94
+ south_west: Coordinate
95
+ north_east: Coordinate
96
+ }
97
+
98
+ /** Matches `MapCamera` in `maps.zig`. */
99
+ export interface MapCamera {
100
+ center: Coordinate
101
+ zoom: number
102
+ pitch: number
103
+ heading: number
104
+ }
105
+
106
+ // ---------------------------------------------------------------------------
107
+ // Overlays
108
+ // ---------------------------------------------------------------------------
109
+
110
+ /** Matches `MapMarker` in `maps.zig`. */
111
+ export interface MapMarker {
112
+ id: number
113
+ coordinate: Coordinate
114
+ title: string | null
115
+ subtitle: string | null
116
+ color: MarkerColor
117
+ is_draggable: boolean
118
+ is_selected: boolean
119
+ custom_icon: string | null
120
+ anchor_x: number
121
+ anchor_y: number
122
+ }
123
+
124
+ /** Matches `MapPolyline` in `maps.zig` (flattened: `coordinates` is a plain array). */
125
+ export interface MapPolyline {
126
+ id: number
127
+ coordinates: Coordinate[]
128
+ stroke_color: MarkerColor
129
+ stroke_width: number
130
+ stroke_pattern: StrokePattern
131
+ is_geodesic: boolean
132
+ z_index: number
133
+ }
134
+
135
+ /** Matches `MapPolygon` in `maps.zig`. */
136
+ export interface MapPolygon {
137
+ id: number
138
+ exterior_ring: Coordinate[]
139
+ interior_rings: Coordinate[][]
140
+ fill_color: MarkerColor
141
+ fill_opacity: number
142
+ stroke_color: MarkerColor
143
+ stroke_width: number
144
+ z_index: number
145
+ }
146
+
147
+ /** Matches `MapCircle` in `maps.zig`. */
148
+ export interface MapCircle {
149
+ id: number
150
+ center: Coordinate
151
+ radius_meters: number
152
+ fill_color: MarkerColor
153
+ fill_opacity: number
154
+ stroke_color: MarkerColor
155
+ stroke_width: number
156
+ }
157
+
158
+ // ---------------------------------------------------------------------------
159
+ // Configuration
160
+ // ---------------------------------------------------------------------------
161
+
162
+ /** Matches `MapConfiguration` in `maps.zig`. */
163
+ export interface MapConfiguration {
164
+ provider: MapProvider
165
+ map_type: MapType
166
+ shows_user_location: boolean
167
+ user_tracking_mode: UserTrackingMode
168
+ shows_compass: boolean
169
+ shows_scale: boolean
170
+ shows_traffic: boolean
171
+ shows_buildings: boolean
172
+ is_rotate_enabled: boolean
173
+ is_scroll_enabled: boolean
174
+ is_zoom_enabled: boolean
175
+ is_pitch_enabled: boolean
176
+ min_zoom: number
177
+ max_zoom: number
178
+ }
179
+
180
+ /**
181
+ * Sensible defaults matching `MapConfiguration.defaults()` in `maps.zig`,
182
+ * but with the provider set to `ts_maps` — the whole point of this package.
183
+ */
184
+ export const defaultMapConfiguration: MapConfiguration = {
185
+ provider: 'ts_maps',
186
+ map_type: 'standard',
187
+ shows_user_location: false,
188
+ user_tracking_mode: 'none',
189
+ shows_compass: true,
190
+ shows_scale: true,
191
+ shows_traffic: false,
192
+ shows_buildings: true,
193
+ is_rotate_enabled: true,
194
+ is_scroll_enabled: true,
195
+ is_zoom_enabled: true,
196
+ is_pitch_enabled: true,
197
+ min_zoom: 0,
198
+ max_zoom: 22,
199
+ }
200
+
201
+ /** Default camera — matches `MapCamera.init(Coordinate.zero)`. */
202
+ export const defaultMapCamera: MapCamera = {
203
+ center: { latitude: 0, longitude: 0 },
204
+ zoom: 15,
205
+ pitch: 0,
206
+ heading: 0,
207
+ }
208
+
209
+ // ---------------------------------------------------------------------------
210
+ // Hex colors
211
+ // ---------------------------------------------------------------------------
212
+
213
+ /**
214
+ * Hex string map for each `MarkerColor`, derived from `MarkerColor.toRGB()`
215
+ * in `maps.zig`. Used when passing stroke/fill colors to ts-maps.
216
+ */
217
+ export const markerColorHex: Record<MarkerColor, string> = {
218
+ red: '#ff3b30',
219
+ green: '#34c759',
220
+ blue: '#007aff',
221
+ yellow: '#ffcc00',
222
+ orange: '#ff9500',
223
+ purple: '#af52de',
224
+ cyan: '#32ade6',
225
+ magenta: '#ff2d55',
226
+ }
227
+
228
+ /**
229
+ * Dash pattern (in pixels) for each stroke pattern. Matches
230
+ * `StrokePattern.dashLengths()` in `maps.zig`.
231
+ */
232
+ export const strokePatternDashes: Record<StrokePattern, number[]> = {
233
+ solid: [],
234
+ dashed: [10, 5],
235
+ dotted: [2, 2],
236
+ dash_dot: [10, 5, 2, 5],
237
+ }