@craft-native/ts-maps 0.0.91 → 0.0.94

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,60 @@
1
+ /**
2
+ * Thin Craft-specific wrapper around ts-maps' `saveOfflineRegion` that
3
+ * writes tile bytes to the app's sandboxed filesystem via the
4
+ * {@link createFilesystemBackend} adapter.
5
+ *
6
+ * Typical usage from a Craft app:
7
+ *
8
+ * ```ts
9
+ * import { saveOfflineRegionToFilesystem } from '@craft-native/ts-maps'
10
+ * import { app } from 'craft-native'
11
+ *
12
+ * await saveOfflineRegionToFilesystem({
13
+ * baseDir: `${await app.dataDir()}/tiles`,
14
+ * tileUrl: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
15
+ * bounds: mapViewBounds,
16
+ * zoomRange: [10, 14],
17
+ * })
18
+ * ```
19
+ *
20
+ * The download runs with bounded concurrency and respects `AbortSignal`,
21
+ * so a user canceling the region pre-cache tears the job down cleanly.
22
+ *
23
+ * @module @craft-native/ts-maps/offlineRegion
24
+ */
25
+ import type { OfflineRegionResult, TileCacheOptions } from 'ts-maps';
26
+ import { TileCache } from 'ts-maps';
27
+ export type OfflineBoundsLike = {
28
+ west: number;
29
+ south: number;
30
+ east: number;
31
+ north: number;
32
+ } | readonly [west: number, south: number, east: number, north: number];
33
+ export interface OfflineProgressEmitter {
34
+ fire: (type: string, data?: Record<string, unknown>) => unknown;
35
+ }
36
+ export interface FilesystemOfflineRegionOptions {
37
+ /** Sandbox directory for tile files. Created on first write. */
38
+ baseDir: string;
39
+ /** Tile URL template — `{z}/{x}/{y}` placeholders are substituted. */
40
+ tileUrl: string;
41
+ bounds: OfflineBoundsLike;
42
+ zoomRange: [minZ: number, maxZ: number];
43
+ concurrency?: number;
44
+ signal?: AbortSignal;
45
+ /** Optional overrides for the `TileCache` wrapping the filesystem backend. */
46
+ cacheOptions?: Omit<TileCacheOptions, 'backend'>;
47
+ }
48
+ /**
49
+ * Pre-download every tile inside `bounds` across `zoomRange` and persist
50
+ * it to disk under `baseDir`. Returns counts of saved / cached-already /
51
+ * failed tiles.
52
+ */
53
+ export declare function saveOfflineRegionToFilesystem(opts: FilesystemOfflineRegionOptions, emitter?: OfflineProgressEmitter): Promise<OfflineRegionResult>;
54
+ /**
55
+ * Build a standalone {@link TileCache} whose persistence layer is the
56
+ * Craft sandbox filesystem. Useful when a map instance needs to serve
57
+ * pre-saved tiles at runtime (not just pre-download them).
58
+ */
59
+ export declare function createFilesystemTileCache(baseDir: string, cacheOptions?: Omit<TileCacheOptions, 'backend'>): TileCache;
60
+ //# sourceMappingURL=offlineRegion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offlineRegion.d.ts","sourceRoot":"","sources":["../../../src/offlineRegion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAqB,SAAS,EAAE,MAAM,SAAS,CAAA;AAGtD,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC5D,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;AAEvE,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAA;CAChE;AAED,MAAM,WAAW,8BAA8B;IAC7C,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAA;IACf,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,iBAAiB,CAAA;IACzB,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IACvC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAA;CACjD;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,8BAA8B,EACpC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CAgB9B;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,GAC/C,SAAS,CAKX"}
@@ -0,0 +1,129 @@
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
+ * Matches `MapProvider` in `maps.zig`. String-literal union so JSON
11
+ * serialization emits the Zig enum tag name directly.
12
+ */
13
+ export type MapProvider = 'apple_maps' | 'google_maps' | 'mapbox' | 'openstreetmap' | 'here_maps' | 'ts_maps';
14
+ /** Matches `MapType` in `maps.zig`. */
15
+ export type MapType = 'standard' | 'satellite' | 'hybrid' | 'terrain' | 'muted_standard' | 'satellite_flyover' | 'hybrid_flyover';
16
+ /** Matches `UserTrackingMode` in `maps.zig`. */
17
+ export type UserTrackingMode = 'none' | 'follow' | 'follow_with_heading';
18
+ /** Matches `MarkerColor` in `maps.zig`. */
19
+ export type MarkerColor = 'red' | 'green' | 'blue' | 'yellow' | 'orange' | 'purple' | 'cyan' | 'magenta';
20
+ /** Matches `StrokePattern` in `maps.zig`. */
21
+ export type StrokePattern = 'solid' | 'dashed' | 'dotted' | 'dash_dot';
22
+ /** Matches `MapEvent` in `maps.zig`. */
23
+ export type MapEvent = 'region_changed' | 'region_will_change' | 'did_finish_loading' | 'did_fail_loading' | 'annotation_selected' | 'annotation_deselected' | 'annotation_drag_started' | 'annotation_dragged' | 'annotation_drag_ended' | 'user_location_updated' | 'camera_changed' | 'tap' | 'long_press' | 'poi_selected';
24
+ /** Matches `Coordinate` in `maps.zig`. */
25
+ export interface Coordinate {
26
+ latitude: number;
27
+ longitude: number;
28
+ }
29
+ /** Matches `CoordinateSpan` in `maps.zig`. */
30
+ export interface CoordinateSpan {
31
+ latitude_delta: number;
32
+ longitude_delta: number;
33
+ }
34
+ /** Matches `MapRegion` in `maps.zig`. */
35
+ export interface MapRegion {
36
+ center: Coordinate;
37
+ span: CoordinateSpan;
38
+ }
39
+ /** Matches `BoundingBox` in `maps.zig`. */
40
+ export interface BoundingBox {
41
+ south_west: Coordinate;
42
+ north_east: Coordinate;
43
+ }
44
+ /** Matches `MapCamera` in `maps.zig`. */
45
+ export interface MapCamera {
46
+ center: Coordinate;
47
+ zoom: number;
48
+ pitch: number;
49
+ heading: number;
50
+ }
51
+ /** Matches `MapMarker` in `maps.zig`. */
52
+ export interface MapMarker {
53
+ id: number;
54
+ coordinate: Coordinate;
55
+ title: string | null;
56
+ subtitle: string | null;
57
+ color: MarkerColor;
58
+ is_draggable: boolean;
59
+ is_selected: boolean;
60
+ custom_icon: string | null;
61
+ anchor_x: number;
62
+ anchor_y: number;
63
+ }
64
+ /** Matches `MapPolyline` in `maps.zig` (flattened: `coordinates` is a plain array). */
65
+ export interface MapPolyline {
66
+ id: number;
67
+ coordinates: Coordinate[];
68
+ stroke_color: MarkerColor;
69
+ stroke_width: number;
70
+ stroke_pattern: StrokePattern;
71
+ is_geodesic: boolean;
72
+ z_index: number;
73
+ }
74
+ /** Matches `MapPolygon` in `maps.zig`. */
75
+ export interface MapPolygon {
76
+ id: number;
77
+ exterior_ring: Coordinate[];
78
+ interior_rings: Coordinate[][];
79
+ fill_color: MarkerColor;
80
+ fill_opacity: number;
81
+ stroke_color: MarkerColor;
82
+ stroke_width: number;
83
+ z_index: number;
84
+ }
85
+ /** Matches `MapCircle` in `maps.zig`. */
86
+ export interface MapCircle {
87
+ id: number;
88
+ center: Coordinate;
89
+ radius_meters: number;
90
+ fill_color: MarkerColor;
91
+ fill_opacity: number;
92
+ stroke_color: MarkerColor;
93
+ stroke_width: number;
94
+ }
95
+ /** Matches `MapConfiguration` in `maps.zig`. */
96
+ export interface MapConfiguration {
97
+ provider: MapProvider;
98
+ map_type: MapType;
99
+ shows_user_location: boolean;
100
+ user_tracking_mode: UserTrackingMode;
101
+ shows_compass: boolean;
102
+ shows_scale: boolean;
103
+ shows_traffic: boolean;
104
+ shows_buildings: boolean;
105
+ is_rotate_enabled: boolean;
106
+ is_scroll_enabled: boolean;
107
+ is_zoom_enabled: boolean;
108
+ is_pitch_enabled: boolean;
109
+ min_zoom: number;
110
+ max_zoom: number;
111
+ }
112
+ /**
113
+ * Sensible defaults matching `MapConfiguration.defaults()` in `maps.zig`,
114
+ * but with the provider set to `ts_maps` — the whole point of this package.
115
+ */
116
+ export declare const defaultMapConfiguration: MapConfiguration;
117
+ /** Default camera — matches `MapCamera.init(Coordinate.zero)`. */
118
+ export declare const defaultMapCamera: MapCamera;
119
+ /**
120
+ * Hex string map for each `MarkerColor`, derived from `MarkerColor.toRGB()`
121
+ * in `maps.zig`. Used when passing stroke/fill colors to ts-maps.
122
+ */
123
+ export declare const markerColorHex: Record<MarkerColor, string>;
124
+ /**
125
+ * Dash pattern (in pixels) for each stroke pattern. Matches
126
+ * `StrokePattern.dashLengths()` in `maps.zig`.
127
+ */
128
+ export declare const strokePatternDashes: Record<StrokePattern, number[]>;
129
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAA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,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,WAAW,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,WAAW,CAAA;IACzB,YAAY,EAAE,MAAM,CAAA;CACrB;AAMD,gDAAgD;AAChD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,WAAW,CAAA;IACrB,QAAQ,EAAE,OAAO,CAAA;IACjB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,kBAAkB,EAAE,gBAAgB,CAAA;IACpC,aAAa,EAAE,OAAO,CAAA;IACtB,WAAW,EAAE,OAAO,CAAA;IACpB,aAAa,EAAE,OAAO,CAAA;IACtB,eAAe,EAAE,OAAO,CAAA;IACxB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,iBAAiB,EAAE,OAAO,CAAA;IAC1B,eAAe,EAAE,OAAO,CAAA;IACxB,gBAAgB,EAAE,OAAO,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,gBAerC,CAAA;AAED,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,SAK9B,CAAA;AAMD;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAStD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,EAAE,CAK/D,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,53 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // src/types.ts
10
+ var defaultMapConfiguration = {
11
+ provider: "ts_maps",
12
+ map_type: "standard",
13
+ shows_user_location: false,
14
+ user_tracking_mode: "none",
15
+ shows_compass: true,
16
+ shows_scale: true,
17
+ shows_traffic: false,
18
+ shows_buildings: true,
19
+ is_rotate_enabled: true,
20
+ is_scroll_enabled: true,
21
+ is_zoom_enabled: true,
22
+ is_pitch_enabled: true,
23
+ min_zoom: 0,
24
+ max_zoom: 22
25
+ };
26
+ var defaultMapCamera = {
27
+ center: { latitude: 0, longitude: 0 },
28
+ zoom: 15,
29
+ pitch: 0,
30
+ heading: 0
31
+ };
32
+ var markerColorHex = {
33
+ red: "#ff3b30",
34
+ green: "#34c759",
35
+ blue: "#007aff",
36
+ yellow: "#ffcc00",
37
+ orange: "#ff9500",
38
+ purple: "#af52de",
39
+ cyan: "#32ade6",
40
+ magenta: "#ff2d55"
41
+ };
42
+ var strokePatternDashes = {
43
+ solid: [],
44
+ dashed: [10, 5],
45
+ dotted: [2, 2],
46
+ dash_dot: [10, 5, 2, 5]
47
+ };
48
+ export {
49
+ strokePatternDashes,
50
+ markerColorHex,
51
+ defaultMapConfiguration,
52
+ defaultMapCamera
53
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@craft-native/ts-maps",
3
- "version": "0.0.91",
3
+ "version": "0.0.94",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Craft SDK bindings for the ts-maps interactive map runtime. Provides a cross-platform MapView component backed by the MapProvider.ts_maps variant in the Zig core.",
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- # MIT License
2
-
3
- Copyright (c) 2025 Stacks.js
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.