@craft-native/ts-maps 0.0.92 → 0.0.95
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/FilesystemTileBackend.d.ts +47 -0
- package/dist/FilesystemTileBackend.d.ts.map +1 -0
- package/dist/MapView.d.ts +91 -0
- package/dist/MapView.d.ts.map +1 -0
- package/dist/adapters.d.ts +60 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +18451 -0
- package/dist/bridge-protocol.d.ts +100 -0
- package/dist/bridge-protocol.d.ts.map +1 -0
- package/dist/bridge-protocol.js +17 -0
- package/dist/capabilities.d.ts +44 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20190 -0
- package/dist/offlineRegion.d.ts +60 -0
- package/dist/offlineRegion.d.ts.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +53 -0
- package/package.json +1 -1
- package/LICENSE.md +0 -21
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filesystem-backed tile persistence for `ts-maps` `TileCache`.
|
|
3
|
+
*
|
|
4
|
+
* Wraps Craft's `fs` bridge (which transparently falls back to `node:fs`
|
|
5
|
+
* when running outside a Craft WebView) so that tile bytes for an
|
|
6
|
+
* offline region are written to an app-sandboxed directory rather than
|
|
7
|
+
* IndexedDB. Returned objects plug straight into `TileCache` via its
|
|
8
|
+
* `backend` option.
|
|
9
|
+
*
|
|
10
|
+
* Each cached tile is serialised as a single `.tsm` file containing:
|
|
11
|
+
*
|
|
12
|
+
* magic 4 bytes "TSMT"
|
|
13
|
+
* version 1 byte 0x01
|
|
14
|
+
* keyLen 4 bytes little-endian uint32
|
|
15
|
+
* mimeLen 4 bytes little-endian uint32
|
|
16
|
+
* reservedLen 4 bytes little-endian uint32 (0)
|
|
17
|
+
* addedAt 8 bytes little-endian float64 (ms epoch)
|
|
18
|
+
* reserved 8 bytes little-endian float64 (0)
|
|
19
|
+
* dataLen 4 bytes little-endian uint32
|
|
20
|
+
* key keyLen bytes UTF-8
|
|
21
|
+
* mime mimeLen bytes UTF-8
|
|
22
|
+
* data dataLen bytes payload
|
|
23
|
+
*
|
|
24
|
+
* Filenames are `<hash>.tsm` where `<hash>` is a 64-bit FNV-1a of the
|
|
25
|
+
* URL (two 32-bit passes with different seeds) rendered in base36. That
|
|
26
|
+
* keeps filenames short, URL-safe, and collision-resistant enough for
|
|
27
|
+
* the tile counts an offline region realistically produces.
|
|
28
|
+
*
|
|
29
|
+
* @module @craft-native/ts-maps/FilesystemTileBackend
|
|
30
|
+
*/
|
|
31
|
+
import type { TileCacheBackend } from 'ts-maps';
|
|
32
|
+
export interface FilesystemBackendOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Directory where tile files are stored. Created on first write if it
|
|
35
|
+
* doesn't exist. On Craft apps this is typically something like
|
|
36
|
+
* `app.dataDir + '/tiles'` — the caller resolves the platform-specific
|
|
37
|
+
* path and passes it in.
|
|
38
|
+
*/
|
|
39
|
+
baseDir: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Construct a {@link TileCacheBackend} that persists tiles under `baseDir`.
|
|
43
|
+
* Pass the returned object to `new TileCache({ backend })` (or to the
|
|
44
|
+
* cache used by `saveOfflineRegion`).
|
|
45
|
+
*/
|
|
46
|
+
export declare function createFilesystemBackend(opts: FilesystemBackendOptions): TileCacheBackend;
|
|
47
|
+
//# sourceMappingURL=FilesystemTileBackend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FilesystemTileBackend.d.ts","sourceRoot":"","sources":["../../../src/FilesystemTileBackend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAQ,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAMrD,MAAM,WAAW,wBAAwB;IACvC;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAA;CAChB;AAMD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,wBAAwB,GAAG,gBAAgB,CA+FxF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `MapView` — Craft-native interactive map component backed by the
|
|
3
|
+
* ts-maps runtime. Instances are WebView-hosted; in native Craft apps
|
|
4
|
+
* the Zig core drives them via the `ts_maps` bridge namespace.
|
|
5
|
+
*
|
|
6
|
+
* @module @craft-native/ts-maps/MapView
|
|
7
|
+
*/
|
|
8
|
+
import type { TsMap } from 'ts-maps';
|
|
9
|
+
import type { Coordinate, MapCamera, MapCircle, MapConfiguration, MapMarker, MapPolygon, MapPolyline, MapRegion } from './types.js';
|
|
10
|
+
/** Subset of Craft's `ComponentProps` duplicated here to keep runtime deps minimal. */
|
|
11
|
+
export interface ComponentProps {
|
|
12
|
+
/** Explicit component id — auto-generated if omitted. */
|
|
13
|
+
id?: string;
|
|
14
|
+
/** CSS class applied to the container `<div>`. */
|
|
15
|
+
className?: string;
|
|
16
|
+
/** Inline styles applied to the container. */
|
|
17
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
18
|
+
/** Hidden state. */
|
|
19
|
+
hidden?: boolean;
|
|
20
|
+
/** Accessible tooltip. */
|
|
21
|
+
tooltip?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Props accepted by {@link createMapView}. */
|
|
24
|
+
export interface MapViewProps extends ComponentProps {
|
|
25
|
+
/** Map configuration; defaults to {@link defaultMapConfiguration}. */
|
|
26
|
+
configuration?: MapConfiguration;
|
|
27
|
+
/** Initial camera position; defaults to {@link defaultMapCamera}. */
|
|
28
|
+
initialCamera?: MapCamera;
|
|
29
|
+
/** Markers to render on first mount. */
|
|
30
|
+
markers?: MapMarker[];
|
|
31
|
+
/** Polylines to render on first mount. */
|
|
32
|
+
polylines?: MapPolyline[];
|
|
33
|
+
/** Polygons to render on first mount. */
|
|
34
|
+
polygons?: MapPolygon[];
|
|
35
|
+
/** Circles to render on first mount. */
|
|
36
|
+
circles?: MapCircle[];
|
|
37
|
+
/** Optional tile URL template. Defaults to OSM. */
|
|
38
|
+
tileUrl?: string;
|
|
39
|
+
/** Optional tile attribution string. */
|
|
40
|
+
tileAttribution?: string;
|
|
41
|
+
/** Called when the user taps the map background. */
|
|
42
|
+
onTap?: (coordinate: Coordinate) => void;
|
|
43
|
+
/** Called when a marker is tapped. */
|
|
44
|
+
onMarkerTap?: (markerId: number, coordinate: Coordinate) => void;
|
|
45
|
+
/** Called when the visible region changes (after the user pans/zooms). */
|
|
46
|
+
onRegionChanged?: (region: MapRegion) => void;
|
|
47
|
+
/** Called when the camera changes (zoom / bearing / pitch). */
|
|
48
|
+
onCameraChanged?: (camera: MapCamera) => void;
|
|
49
|
+
}
|
|
50
|
+
/** Instance returned by {@link createMapView}. */
|
|
51
|
+
export interface MapViewInstance {
|
|
52
|
+
/** Unique id — also used as the bridge component id. */
|
|
53
|
+
id: string;
|
|
54
|
+
/** DOM container hosting the ts-maps canvas. */
|
|
55
|
+
container: HTMLDivElement;
|
|
56
|
+
/** Underlying ts-maps instance. */
|
|
57
|
+
map: TsMap;
|
|
58
|
+
/** Current configuration. */
|
|
59
|
+
configuration: MapConfiguration;
|
|
60
|
+
/** Move the camera. */
|
|
61
|
+
setCamera: (camera: MapCamera, animated?: boolean) => void;
|
|
62
|
+
/** Fit the viewport to a region. */
|
|
63
|
+
setRegion: (region: MapRegion, animated?: boolean) => void;
|
|
64
|
+
/** Add a marker; returns its id. */
|
|
65
|
+
addMarker: (marker: MapMarker) => number;
|
|
66
|
+
/** Remove a marker by id. */
|
|
67
|
+
removeMarker: (id: number) => boolean;
|
|
68
|
+
/** Add a polyline; returns its id. */
|
|
69
|
+
addPolyline: (polyline: MapPolyline) => number;
|
|
70
|
+
/** Add a polygon; returns its id. */
|
|
71
|
+
addPolygon: (polygon: MapPolygon) => number;
|
|
72
|
+
/** Add a circle; returns its id. */
|
|
73
|
+
addCircle: (circle: MapCircle) => number;
|
|
74
|
+
/** Fit the map to all currently-rendered markers. */
|
|
75
|
+
fitToMarkers: (paddingPercent?: number) => void;
|
|
76
|
+
/** Select a marker by id. */
|
|
77
|
+
selectMarker: (id: number) => void;
|
|
78
|
+
/** Deselect all markers. */
|
|
79
|
+
deselectAll: () => void;
|
|
80
|
+
/** Update the configuration. */
|
|
81
|
+
setConfiguration: (configuration: MapConfiguration) => void;
|
|
82
|
+
/** Detach event listeners and remove the map from the DOM. */
|
|
83
|
+
destroy: () => void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create a `MapView`. The returned {@link MapViewInstance} owns a DOM
|
|
87
|
+
* container — append it to the page yourself; this factory never mounts it
|
|
88
|
+
* for you so consumers stay in control of layout.
|
|
89
|
+
*/
|
|
90
|
+
export declare function createMapView(props?: MapViewProps): MapViewInstance;
|
|
91
|
+
//# sourceMappingURL=MapView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapView.d.ts","sourceRoot":"","sources":["../../../src/MapView.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAiBpC,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,WAAW,EACX,SAAS,EACV,MAAM,YAAY,CAAA;AAgBnB,uFAAuF;AACvF,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAA;IACpC,oBAAoB;IACpB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,0BAA0B;IAC1B,OAAO,CAAC,EAAE,MAA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E,SAAS,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAC1D,oCAAoC;IACpC,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,MAAM,CAAA;IACxC,6BAA6B;IAC7B,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAA;IACrC,sCAAsC;IACtC,WAAW,EAAE,CAAC,QAAQ,EAAE,WAAW,KAAK,MAAM,CAAA;IAC9C,qCAAqC;IACrC,UAAU,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,MAAM,CAAA;IAC3C,oCAAoC;IACpC,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,MAAM,CAAA;IACxC,qDAAqD;IACrD,YAAY,EAAE,CAAC,cAAc,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/C,6BAA6B;IAC7B,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,4BAA4B;IAC5B,WAAW,EAAE,MAAM,IAAI,CAAA;IACvB,gCAAgC;IAChC,gBAAgB,EAAE,CAAC,aAAa,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAC3D,8DAA8D;IAC9D,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AA2BD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,GAAE,YAAiB,GAAG,eAAe,CAsQvE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure conversion functions between Craft's Zig-mirrored map types and
|
|
3
|
+
* the runtime objects used by the ts-maps library. These are deliberately
|
|
4
|
+
* side-effect-free so they can be unit-tested without a DOM.
|
|
5
|
+
*
|
|
6
|
+
* @module @craft-native/ts-maps/adapters
|
|
7
|
+
*/
|
|
8
|
+
import { Circle, Marker, Polygon, Polyline } from 'ts-maps';
|
|
9
|
+
import { LatLng, LatLngBounds } from 'ts-maps';
|
|
10
|
+
import type { BoundingBox, Coordinate, MapCamera, MapCircle, MapMarker, MapPolygon, MapPolyline, MapRegion } from './types.js';
|
|
11
|
+
/** Convert a Craft `Coordinate` to a ts-maps `LatLng`. */
|
|
12
|
+
export declare function craftCoordToLatLng(coord: Coordinate): LatLng;
|
|
13
|
+
/** Convert a ts-maps `LatLng` back to a Craft `Coordinate`. */
|
|
14
|
+
export declare function latLngToCraftCoord(ll: LatLng): Coordinate;
|
|
15
|
+
/** Convert a Craft `MapRegion` (center + span) to a ts-maps `LatLngBounds`. */
|
|
16
|
+
export declare function craftRegionToBounds(region: MapRegion): LatLngBounds;
|
|
17
|
+
/** Convert a Craft `BoundingBox` to a ts-maps `LatLngBounds`. */
|
|
18
|
+
export declare function craftBoundingBoxToBounds(box: BoundingBox): LatLngBounds;
|
|
19
|
+
/**
|
|
20
|
+
* Convert a ts-maps `LatLngBounds` back to a Craft `MapRegion`. Useful when
|
|
21
|
+
* translating `moveend` events into `regionChanged` bridge events.
|
|
22
|
+
*/
|
|
23
|
+
export declare function boundsToCraftRegion(bounds: LatLngBounds): MapRegion;
|
|
24
|
+
/**
|
|
25
|
+
* ts-maps `setView()` / `easeTo()` option shape. Pulled out so the MapView
|
|
26
|
+
* wrapper and consumers can pass the exact object through without guessing
|
|
27
|
+
* field names.
|
|
28
|
+
*/
|
|
29
|
+
export interface TsMapsCameraOptions {
|
|
30
|
+
center: LatLng;
|
|
31
|
+
zoom: number;
|
|
32
|
+
bearing: number;
|
|
33
|
+
pitch: number;
|
|
34
|
+
}
|
|
35
|
+
/** Convert a Craft `MapCamera` to a ts-maps-style camera options object. */
|
|
36
|
+
export declare function craftCameraToOptions(cam: MapCamera): TsMapsCameraOptions;
|
|
37
|
+
/**
|
|
38
|
+
* Alias matching the name requested in the SDK spec. Kept distinct from
|
|
39
|
+
* `craftCameraToOptions` in case the upstream runtime ever needs a
|
|
40
|
+
* different shape for `cameraTo…` vs `…ToOptions`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function cameraToCamera(cam: MapCamera): TsMapsCameraOptions;
|
|
43
|
+
/**
|
|
44
|
+
* Convert a Craft `MapMarker` to a ts-maps `Marker`. The returned marker
|
|
45
|
+
* has not yet been added to a map — the caller is responsible for calling
|
|
46
|
+
* `marker.addTo(map)`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function craftMarkerToMarker(m: MapMarker): Marker;
|
|
49
|
+
/** Convert a Craft `MapPolyline` to a ts-maps `Polyline`. */
|
|
50
|
+
export declare function craftPolylineToPolyline(pl: MapPolyline): Polyline;
|
|
51
|
+
/** Convert a Craft `MapPolygon` to a ts-maps `Polygon`. */
|
|
52
|
+
export declare function craftPolygonToPolygon(pg: MapPolygon): Polygon;
|
|
53
|
+
/** Convert a Craft `MapCircle` to a ts-maps `Circle`. */
|
|
54
|
+
export declare function craftCircleToCircle(c: MapCircle): Circle;
|
|
55
|
+
/**
|
|
56
|
+
* Build a Craft `MapRegion` from the bounds of an array of coordinates.
|
|
57
|
+
* Mirrors `BoundingBox.fromCoordinates(...).toRegion()` in `maps.zig`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function regionFromBounds(coords: Coordinate[]): MapRegion | null;
|
|
60
|
+
//# sourceMappingURL=adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../../../src/adapters.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,UAAU,EACV,WAAW,EACX,SAAS,EACV,MAAM,YAAY,CAAA;AAOnB,0DAA0D;AAC1D,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE5D;AAED,+DAA+D;AAC/D,wBAAgB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