@chrtco/sdk 0.4.1 → 0.6.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/CHANGELOG.md +51 -0
- package/README.md +69 -0
- package/dist/atlas/browser.cjs +3186 -0
- package/dist/atlas/browser.cjs.map +1 -0
- package/dist/atlas/browser.d.cts +33 -0
- package/dist/atlas/browser.d.ts +33 -0
- package/dist/atlas/browser.js +3156 -0
- package/dist/atlas/browser.js.map +1 -0
- package/dist/fs-adapter-D5iwdb1Q.d.cts +33 -0
- package/dist/fs-adapter-D5iwdb1Q.d.ts +33 -0
- package/dist/index.cjs +7830 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +964 -1
- package/dist/index.d.ts +964 -1
- package/dist/index.js +7763 -1
- package/dist/index.js.map +1 -1
- package/dist/node/index.cjs +90 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +5 -0
- package/dist/node/index.d.ts +5 -0
- package/dist/node/index.js +66 -0
- package/dist/node/index.js.map +1 -0
- package/dist/s52-colors-CdVzqt2K.d.cts +17 -0
- package/dist/s52-colors-CdVzqt2K.d.ts +17 -0
- package/package.json +31 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,112 @@
|
|
|
1
|
+
import { F as FileSystemAdapter } from './fs-adapter-D5iwdb1Q.cjs';
|
|
2
|
+
import { C as ColorTableName } from './s52-colors-CdVzqt2K.cjs';
|
|
3
|
+
export { S as S52_COLORS, a as S52_DAY, b as S52_DUSK, c as S52_NIGHT, g as getColorTable, r as resolveColor } from './s52-colors-CdVzqt2K.cjs';
|
|
4
|
+
import maplibregl from 'maplibre-gl';
|
|
5
|
+
import { ExpressionSpecification } from '@maplibre/maplibre-gl-style-spec';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pure helper: take an online MapLibre style and rewrite the named region's
|
|
9
|
+
* vector source to point at a local MBTiles file. Layers, paint, layout,
|
|
10
|
+
* glyphs, and sprite are untouched.
|
|
11
|
+
*
|
|
12
|
+
* This is the JS counterpart of the offline-worker's server-side rewriter
|
|
13
|
+
* (see `cloudflare/offline-worker/src/common.ts:rewriteStyleSources`).
|
|
14
|
+
* Customers can either:
|
|
15
|
+
*
|
|
16
|
+
* 1. Fetch a pre-baked offline style from the worker via
|
|
17
|
+
* `chrt.offline.fetchStyle(region, opts)` — recommended for native
|
|
18
|
+
* MapLibre clients (iOS/Android/desktop) that don't have the JS atlas
|
|
19
|
+
* available.
|
|
20
|
+
*
|
|
21
|
+
* 2. Generate the online style themselves (e.g. via the React app's
|
|
22
|
+
* `src/lib/atlas/style-generator.ts`) and call `buildOfflineStyle()`
|
|
23
|
+
* locally — recommended for JS/web SDK consumers who already use the
|
|
24
|
+
* atlas at runtime.
|
|
25
|
+
*
|
|
26
|
+
* Both paths produce equivalent output.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* MapLibre style specification (subset). Matches the JSON shape MapLibre GL
|
|
30
|
+
* JS, MapLibre Native iOS/Android, and the MapLibre style spec all consume.
|
|
31
|
+
* Customers who want full TypeScript style typing should reference
|
|
32
|
+
* `@maplibre/maplibre-gl-style-spec.StyleSpecification` directly.
|
|
33
|
+
*/
|
|
34
|
+
interface MapLibreStyle {
|
|
35
|
+
version: number;
|
|
36
|
+
name?: string;
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
sources: Record<string, MapLibreSource | unknown>;
|
|
39
|
+
sprite?: string;
|
|
40
|
+
glyphs?: string;
|
|
41
|
+
layers: unknown[];
|
|
42
|
+
}
|
|
43
|
+
interface MapLibreSource {
|
|
44
|
+
type: string;
|
|
45
|
+
tiles?: string[];
|
|
46
|
+
url?: string;
|
|
47
|
+
minzoom?: number;
|
|
48
|
+
maxzoom?: number;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
/** Target platform — drives the URL scheme used in the rewritten source. */
|
|
52
|
+
type OfflineStylePlatform = "ios" | "android" | "desktop";
|
|
53
|
+
interface BuildOfflineStyleOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Target platform. iOS + Android use the `mbtiles://` scheme MapLibre Native
|
|
56
|
+
* understands; desktop uses `file://`. Default: `"ios"`.
|
|
57
|
+
*/
|
|
58
|
+
platform?: OfflineStylePlatform;
|
|
59
|
+
/**
|
|
60
|
+
* Name of the source to rewrite. If omitted, defaults to the only vector
|
|
61
|
+
* source in the input style. Throws `OfflineStyleError` if there are zero
|
|
62
|
+
* or more than one vector sources and `sourceName` isn't provided.
|
|
63
|
+
*/
|
|
64
|
+
sourceName?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Thrown when `buildOfflineStyle` can't determine which source to swap or
|
|
68
|
+
* the named source isn't present in the input style.
|
|
69
|
+
*/
|
|
70
|
+
declare class OfflineStyleError extends Error {
|
|
71
|
+
readonly code: string;
|
|
72
|
+
constructor(message: string, code: string);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns a deep-copy of `onlineStyle` with the named (or auto-detected)
|
|
76
|
+
* vector source rewritten to point at `mbtilesPath`. Other sources, layers,
|
|
77
|
+
* paint, layout, glyphs, and sprite pass through unmodified.
|
|
78
|
+
*
|
|
79
|
+
* URL scheme:
|
|
80
|
+
*
|
|
81
|
+
* platform="ios" → `mbtiles://<mbtilesPath>` MLN Native iOS
|
|
82
|
+
* platform="android" → `mbtiles://<mbtilesPath>` MLN Native Android
|
|
83
|
+
* platform="desktop" → `file://<mbtilesPath>` MLN GL native (Win/Mac/Linux)
|
|
84
|
+
*
|
|
85
|
+
* The `mbtilesPath` is intentionally treated as opaque text. Most native MLN
|
|
86
|
+
* bindings accept the bare scheme + filename and resolve against an
|
|
87
|
+
* app-defined root (typically the app's Documents directory). Pass an
|
|
88
|
+
* absolute path on desktop, or a relative filename on iOS/Android.
|
|
89
|
+
*
|
|
90
|
+
* @param onlineStyle The base MapLibre style. Not mutated.
|
|
91
|
+
* @param mbtilesPath Local-file path component (e.g. `"NOAA_ENC.mbtiles"`).
|
|
92
|
+
* @param opts Platform + optional explicit `sourceName`.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* import { buildOfflineStyle } from "@chrtco/sdk";
|
|
96
|
+
*
|
|
97
|
+
* // Online style obtained however you like — generated client-side or
|
|
98
|
+
* // fetched from a server.
|
|
99
|
+
* const onlineStyle = generateStyle("DAY", { region: "NOAA_ENC" });
|
|
100
|
+
*
|
|
101
|
+
* const offlineStyle = buildOfflineStyle(
|
|
102
|
+
* onlineStyle,
|
|
103
|
+
* "NOAA_ENC.mbtiles",
|
|
104
|
+
* { platform: "ios" },
|
|
105
|
+
* );
|
|
106
|
+
* // → hand `offlineStyle` to MapLibre.
|
|
107
|
+
*/
|
|
108
|
+
declare function buildOfflineStyle(onlineStyle: MapLibreStyle, mbtilesPath: string, opts?: BuildOfflineStyleOptions): MapLibreStyle;
|
|
109
|
+
|
|
1
110
|
interface GeoJsonGeometry {
|
|
2
111
|
type: string;
|
|
3
112
|
coordinates: unknown;
|
|
@@ -68,6 +177,48 @@ interface CellsResponse {
|
|
|
68
177
|
limit: number;
|
|
69
178
|
offset: number;
|
|
70
179
|
}
|
|
180
|
+
interface RouteQueryOptions {
|
|
181
|
+
/** Array of [longitude, latitude] waypoints forming the route */
|
|
182
|
+
route: [number, number][];
|
|
183
|
+
/** Buffer distance in metres (default 1000, max 50000) */
|
|
184
|
+
buffer?: number;
|
|
185
|
+
/** Filter by chart source, e.g. "NOAA" */
|
|
186
|
+
source?: string;
|
|
187
|
+
/** Filter by scale band, e.g. "4" */
|
|
188
|
+
scaleBand?: string;
|
|
189
|
+
/** Max cells to return (default 100) */
|
|
190
|
+
limit?: number;
|
|
191
|
+
/** AbortSignal to cancel the request */
|
|
192
|
+
signal?: AbortSignal;
|
|
193
|
+
}
|
|
194
|
+
interface RouteQueryResponse {
|
|
195
|
+
cells: CellDetail[];
|
|
196
|
+
query: {
|
|
197
|
+
buffer_m: number;
|
|
198
|
+
cell_count: number;
|
|
199
|
+
};
|
|
200
|
+
total_count: number;
|
|
201
|
+
}
|
|
202
|
+
interface RouteFeatureQueryOptions {
|
|
203
|
+
/** Array of [longitude, latitude] waypoints forming the route */
|
|
204
|
+
route: [number, number][];
|
|
205
|
+
/** Buffer distance in metres (default 1000, max 50000) */
|
|
206
|
+
buffer?: number;
|
|
207
|
+
/** Comma-separated layer codes to filter */
|
|
208
|
+
layer?: string;
|
|
209
|
+
/** Max features to return (default 100) */
|
|
210
|
+
limit?: number;
|
|
211
|
+
/** Pagination offset */
|
|
212
|
+
offset?: number;
|
|
213
|
+
/** AbortSignal to cancel the request */
|
|
214
|
+
signal?: AbortSignal;
|
|
215
|
+
}
|
|
216
|
+
interface RouteFeatureQueryResponse extends FeatureCollection {
|
|
217
|
+
query: {
|
|
218
|
+
buffer_m: number;
|
|
219
|
+
route_length_m?: number;
|
|
220
|
+
};
|
|
221
|
+
}
|
|
71
222
|
interface CoverageSource {
|
|
72
223
|
/** Chart source ID, e.g. "NOAA" */
|
|
73
224
|
source: string;
|
|
@@ -117,6 +268,119 @@ interface ChrtConfig {
|
|
|
117
268
|
baseUrl?: string;
|
|
118
269
|
/** Max retries on 5xx/network errors (default 2) */
|
|
119
270
|
retries?: number;
|
|
271
|
+
/**
|
|
272
|
+
* Stable per-install device identifier. Required to call `chrt.offline.*`.
|
|
273
|
+
* Generate once at first launch (e.g. UUIDv4), persist, reuse forever.
|
|
274
|
+
* Echoed into the offline JWT + heartbeat for device-level correlation.
|
|
275
|
+
*/
|
|
276
|
+
deviceId?: string;
|
|
277
|
+
/**
|
|
278
|
+
* Absolute path to a JSON file where the SDK tracks local offline state
|
|
279
|
+
* (which regions are downloaded, their sizes and hashes, the storage
|
|
280
|
+
* budget). Optional — if unset, `setStorageBudget` throws and
|
|
281
|
+
* budget enforcement in `download` is skipped. No hidden state otherwise.
|
|
282
|
+
*/
|
|
283
|
+
manifestPath?: string;
|
|
284
|
+
}
|
|
285
|
+
interface OfflineRegionSummary {
|
|
286
|
+
region: string;
|
|
287
|
+
build_id: string;
|
|
288
|
+
build_tag: string;
|
|
289
|
+
total_bytes: number;
|
|
290
|
+
issued_at: number | null;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Response shape from `GET /v1/offline/bundles/{region}`.
|
|
294
|
+
*
|
|
295
|
+
* Designed against the post-groups-collapse single-URL shape. A parallel task
|
|
296
|
+
* is migrating the offline-worker from `groups[]` → one URL per region; this
|
|
297
|
+
* SDK expects that migration to land before end-to-end integration.
|
|
298
|
+
*/
|
|
299
|
+
interface OfflineBundleResponse {
|
|
300
|
+
region: string;
|
|
301
|
+
build_id: string;
|
|
302
|
+
build_tag: string;
|
|
303
|
+
signed_url: string;
|
|
304
|
+
expires_at: number;
|
|
305
|
+
bytes: number;
|
|
306
|
+
sha256: string;
|
|
307
|
+
offline_until: number;
|
|
308
|
+
heartbeat_after: number;
|
|
309
|
+
server_time: number;
|
|
310
|
+
}
|
|
311
|
+
interface OfflineDownloadProgress {
|
|
312
|
+
bytesDownloaded: number;
|
|
313
|
+
bytesTotal: number;
|
|
314
|
+
fraction: number;
|
|
315
|
+
}
|
|
316
|
+
interface OfflineDownloadOptions {
|
|
317
|
+
/** Final destination path for the downloaded MBTiles. SDK writes to `<path>.partial` first, then renames. */
|
|
318
|
+
path: string;
|
|
319
|
+
/** FileSystem adapter (e.g. `nodeFileSystemAdapter()` from `@chrtco/sdk/node`). */
|
|
320
|
+
fs: FileSystemAdapter;
|
|
321
|
+
/**
|
|
322
|
+
* Progress callback. Throttled to max(1 MB, 1%) boundaries. Always fires
|
|
323
|
+
* once at 0 bytes and once at completion regardless of threshold.
|
|
324
|
+
*/
|
|
325
|
+
onProgress?: (p: OfflineDownloadProgress) => void;
|
|
326
|
+
/** AbortSignal — on abort, any bytes written persist as `<path>.partial` for resume. */
|
|
327
|
+
signal?: AbortSignal;
|
|
328
|
+
}
|
|
329
|
+
interface OfflineDownloadResult {
|
|
330
|
+
path: string;
|
|
331
|
+
bytes: number;
|
|
332
|
+
sha256: string;
|
|
333
|
+
build_id: string;
|
|
334
|
+
build_tag: string;
|
|
335
|
+
/** True if this call finished an in-flight download rather than starting fresh. */
|
|
336
|
+
resumed: boolean;
|
|
337
|
+
}
|
|
338
|
+
interface OfflineRemoveOptions {
|
|
339
|
+
path: string;
|
|
340
|
+
fs: FileSystemAdapter;
|
|
341
|
+
}
|
|
342
|
+
interface OfflineHeartbeatOptions {
|
|
343
|
+
/** Regions currently downloaded. If omitted, derived from manifest (requires `fs`). */
|
|
344
|
+
regions?: string[];
|
|
345
|
+
/** Total bytes on device. If omitted, derived from manifest (requires `fs`). */
|
|
346
|
+
total_bytes?: number;
|
|
347
|
+
/** FileSystem adapter. Required iff `regions`/`total_bytes` are omitted and manifestPath is set. */
|
|
348
|
+
fs?: FileSystemAdapter;
|
|
349
|
+
sdk_version?: string;
|
|
350
|
+
platform?: string;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Options for `chrt.offline.fetchStyle()` — fetch a pre-baked offline style
|
|
354
|
+
* from `GET /v1/offline/styles/{region}`.
|
|
355
|
+
*/
|
|
356
|
+
interface OfflineFetchStyleOptions {
|
|
357
|
+
/** S-52 colour palette. Default: `"DAY"`. */
|
|
358
|
+
palette?: "DAY" | "DUSK" | "NIGHT";
|
|
359
|
+
/**
|
|
360
|
+
* URL scheme baked into the source. Default: `"mbtiles"` (iOS/Android via
|
|
361
|
+
* MLN Native). Use `"file"` for desktop (Win/macOS/Linux).
|
|
362
|
+
*/
|
|
363
|
+
protocol?: "mbtiles" | "file";
|
|
364
|
+
/** AbortSignal to cancel the request. */
|
|
365
|
+
signal?: AbortSignal;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Response shape from `GET /v1/offline/styles/{region}`. The `style` field is
|
|
369
|
+
* a MapLibre style spec ready to hand to MLN; the surrounding metadata mirrors
|
|
370
|
+
* the bundle response so callers can refresh `offline_until` from the same
|
|
371
|
+
* call without a separate heartbeat.
|
|
372
|
+
*/
|
|
373
|
+
interface OfflineStyleResponse {
|
|
374
|
+
region: string;
|
|
375
|
+
palette: "DAY" | "DUSK" | "NIGHT";
|
|
376
|
+
protocol: "mbtiles" | "file";
|
|
377
|
+
build_id: string;
|
|
378
|
+
build_tag: string;
|
|
379
|
+
/** Full MapLibre style JSON. Pass directly to `Map({ style: ... })`. */
|
|
380
|
+
style: MapLibreStyle;
|
|
381
|
+
offline_until: number;
|
|
382
|
+
heartbeat_after: number;
|
|
383
|
+
server_time: number;
|
|
120
384
|
}
|
|
121
385
|
|
|
122
386
|
declare class ChrtError extends Error {
|
|
@@ -133,6 +397,27 @@ declare class HttpClient {
|
|
|
133
397
|
getBaseUrl(): string;
|
|
134
398
|
getApiKey(): string;
|
|
135
399
|
request<T>(path: string, params?: Record<string, string | number | undefined>, signal?: AbortSignal): Promise<T>;
|
|
400
|
+
/**
|
|
401
|
+
* Typed wrapper for non-GET JSON requests. Returns the parsed body and HTTP
|
|
402
|
+
* status together so callers (e.g. offline endpoints) can map error bodies
|
|
403
|
+
* to typed errors without throwing at the HTTP layer. Auth defaults to
|
|
404
|
+
* `x-api-key` header; pass `bearerToken` to swap to `Authorization: Bearer`.
|
|
405
|
+
* No retry — the offline flow owns its own retry logic.
|
|
406
|
+
*/
|
|
407
|
+
postJson<T>(path: string, body: unknown, opts?: {
|
|
408
|
+
bearerToken?: string;
|
|
409
|
+
signal?: AbortSignal;
|
|
410
|
+
}): Promise<{
|
|
411
|
+
ok: boolean;
|
|
412
|
+
status: number;
|
|
413
|
+
body: T | null;
|
|
414
|
+
}>;
|
|
415
|
+
/** GET with Bearer auth (for offline-worker endpoints that require a JWT). */
|
|
416
|
+
getJsonWithBearer<T>(path: string, bearerToken: string, signal?: AbortSignal): Promise<{
|
|
417
|
+
ok: boolean;
|
|
418
|
+
status: number;
|
|
419
|
+
body: T | null;
|
|
420
|
+
}>;
|
|
136
421
|
}
|
|
137
422
|
|
|
138
423
|
declare class TilesEndpoint {
|
|
@@ -162,6 +447,100 @@ declare class CoverageEndpoint {
|
|
|
162
447
|
list(options?: CoverageOptions): Promise<CoverageResponse>;
|
|
163
448
|
}
|
|
164
449
|
|
|
450
|
+
/**
|
|
451
|
+
* Fresh-token shape from POST `/v1/mint/offline-token` (proxied to Supabase
|
|
452
|
+
* `mint-offline-token`). Mirrors docs/api/tile-jwt-claims.md §4.
|
|
453
|
+
*/
|
|
454
|
+
interface MintedOfflineToken {
|
|
455
|
+
token: string;
|
|
456
|
+
expiresAt: number;
|
|
457
|
+
kid: string;
|
|
458
|
+
offlineUntil: number;
|
|
459
|
+
/** Per-region build_tag map returned by the mint function. */
|
|
460
|
+
buildTags: Record<string, string>;
|
|
461
|
+
gracePeriodDays: number;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Cache + single-flight mint for offline JWTs.
|
|
465
|
+
*
|
|
466
|
+
* - Keyed by `(deviceId, sorted-regions)` so a token scoped to one region
|
|
467
|
+
* doesn't accidentally get reused for a broader request.
|
|
468
|
+
* - Refreshes 30s before `exp`.
|
|
469
|
+
* - While a mint is in flight, concurrent callers share the same promise.
|
|
470
|
+
*/
|
|
471
|
+
declare class OfflineTokenManager {
|
|
472
|
+
private readonly http;
|
|
473
|
+
private readonly cache;
|
|
474
|
+
private readonly pending;
|
|
475
|
+
constructor(http: HttpClient);
|
|
476
|
+
/**
|
|
477
|
+
* Get a fresh-enough token for the caller's device + requested regions.
|
|
478
|
+
* If `regions` is omitted, the mint function defaults to the key's full
|
|
479
|
+
* `allowed_sources`.
|
|
480
|
+
*/
|
|
481
|
+
getToken(deviceId: string, regions?: string[]): Promise<MintedOfflineToken>;
|
|
482
|
+
/** Force-evict the cached token for a (deviceId, regions) pair. Used after a 401. */
|
|
483
|
+
invalidate(deviceId: string, regions?: string[]): void;
|
|
484
|
+
private cacheKey;
|
|
485
|
+
private mintFresh;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
declare class OfflineEndpoint {
|
|
489
|
+
private readonly http;
|
|
490
|
+
private readonly deviceId;
|
|
491
|
+
private readonly manifestPath;
|
|
492
|
+
readonly tokenManager: OfflineTokenManager;
|
|
493
|
+
constructor(http: HttpClient, deviceId: string | undefined, manifestPath: string | undefined);
|
|
494
|
+
/** List regions downloadable under the caller's API key. */
|
|
495
|
+
list(): Promise<OfflineRegionSummary[]>;
|
|
496
|
+
/**
|
|
497
|
+
* Download an MBTiles bundle for `region` to `opts.path`. Resumable via a
|
|
498
|
+
* `<path>.partial` sidecar on interrupt. SHA-256 verified before rename.
|
|
499
|
+
*/
|
|
500
|
+
download(region: string, opts: OfflineDownloadOptions): Promise<OfflineDownloadResult>;
|
|
501
|
+
/** Delete local file and, if manifest is configured, drop its row + heartbeat. */
|
|
502
|
+
remove(region: string, opts: OfflineRemoveOptions): Promise<void>;
|
|
503
|
+
/**
|
|
504
|
+
* Pure helper — rewrites the named (or auto-detected) vector source in
|
|
505
|
+
* `onlineStyle` to point at a local MBTiles file. Layers/paint/glyphs
|
|
506
|
+
* untouched. Use when you already have an online style (e.g. generated
|
|
507
|
+
* client-side via the React app's atlas) and want the offline variant.
|
|
508
|
+
*
|
|
509
|
+
* Equivalent to importing `buildOfflineStyle` directly — exposed on the
|
|
510
|
+
* endpoint for discoverability.
|
|
511
|
+
*/
|
|
512
|
+
style(onlineStyle: MapLibreStyle, mbtilesPath: string, opts?: BuildOfflineStyleOptions): MapLibreStyle;
|
|
513
|
+
/**
|
|
514
|
+
* Fetch a pre-baked offline style for `region` from
|
|
515
|
+
* `GET /v1/offline/styles/{region}`. The worker's response already has the
|
|
516
|
+
* source rewritten to `mbtiles://` (default) or `file://`, so the returned
|
|
517
|
+
* `style` is ready to hand directly to MapLibre.
|
|
518
|
+
*
|
|
519
|
+
* Recommended for native MLN clients (iOS/Android/desktop) that don't have
|
|
520
|
+
* the JS atlas available. JS/web SDK consumers can equivalently generate
|
|
521
|
+
* the online style themselves and call `chrt.offline.style(...)`.
|
|
522
|
+
*/
|
|
523
|
+
fetchStyle(region: string, opts?: OfflineFetchStyleOptions): Promise<OfflineStyleResponse>;
|
|
524
|
+
/**
|
|
525
|
+
* Set the local storage budget in bytes. Requires `manifestPath`. Enforced
|
|
526
|
+
* at the start of each `download()`. A budget smaller than current usage
|
|
527
|
+
* does not auto-prune; it only refuses new downloads until the customer
|
|
528
|
+
* calls `remove()`.
|
|
529
|
+
*/
|
|
530
|
+
setStorageBudget(bytes: number, fs: FileSystemAdapter): Promise<void>;
|
|
531
|
+
/**
|
|
532
|
+
* Send a heartbeat. If `opts.regions` / `opts.total_bytes` are omitted and
|
|
533
|
+
* a manifest is configured, values are derived from it. v1 is manual-call
|
|
534
|
+
* only; auto-scheduling is a follow-up phase.
|
|
535
|
+
*/
|
|
536
|
+
heartbeat(opts?: OfflineHeartbeatOptions): Promise<void>;
|
|
537
|
+
private requireDeviceId;
|
|
538
|
+
private requireToken;
|
|
539
|
+
private fetchBundle;
|
|
540
|
+
private downloadInternal;
|
|
541
|
+
private persistManifestEntry;
|
|
542
|
+
}
|
|
543
|
+
|
|
165
544
|
/**
|
|
166
545
|
* Generic async auto-pagination generator.
|
|
167
546
|
*
|
|
@@ -241,6 +620,584 @@ type WebhookEventType = WebhookEvent["type"];
|
|
|
241
620
|
*/
|
|
242
621
|
declare function parseWebhook(body: unknown): WebhookEvent;
|
|
243
622
|
|
|
623
|
+
/**
|
|
624
|
+
* Typed errors surfaced by `chrt.offline.*`.
|
|
625
|
+
*
|
|
626
|
+
* Callers switch on `.code` — never parse `.message`. `.status` is set only
|
|
627
|
+
* when the error originated from an HTTP response. `.detail` carries
|
|
628
|
+
* machine-readable context for programmatic handling (byte math for budget
|
|
629
|
+
* violations, `resumable: true` for interrupts, etc.).
|
|
630
|
+
*/
|
|
631
|
+
type OfflineErrorCode = "budget_exceeded" | "coverage_denied" | "quota_exceeded" | "download_corrupt" | "network_interrupted" | "partial_file_invalid" | "invalid_api_key" | "region_not_available" | "offline_not_enabled" | "missing_device_id" | "missing_manifest_path" | "sha_missing" | "unexpected_response";
|
|
632
|
+
declare class OfflineError extends Error {
|
|
633
|
+
readonly code: OfflineErrorCode;
|
|
634
|
+
readonly status?: number;
|
|
635
|
+
readonly detail?: Record<string, unknown>;
|
|
636
|
+
constructor(code: OfflineErrorCode, message: string, status?: number, detail?: Record<string, unknown>);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/** S-52 display categories – controls default visibility */
|
|
640
|
+
type DisplayCategory = "BASE" | "STANDARD" | "OTHER" | "MARINERS" | "META";
|
|
641
|
+
/** Mapbox GL layer type we'll use for this entry */
|
|
642
|
+
type GeomType = "fill" | "line" | "circle" | "symbol";
|
|
643
|
+
/** Nautical groupings (loosely follows Chart No. 1 sections) */
|
|
644
|
+
type NauticalCategory = "Depths" | "Land" | "Navigation Aids" | "Hazards" | "Regulated Areas" | "Infrastructure" | "Meta";
|
|
645
|
+
/** Paint properties – a subset we actually use */
|
|
646
|
+
interface AtlasStyle {
|
|
647
|
+
type: GeomType;
|
|
648
|
+
paint: Record<string, unknown>;
|
|
649
|
+
layout?: Record<string, unknown>;
|
|
650
|
+
/** Nautical symbol ID for symbol-type layers */
|
|
651
|
+
iconImage?: string;
|
|
652
|
+
}
|
|
653
|
+
/** One row in the S-52 lookup table */
|
|
654
|
+
interface LookupEntry {
|
|
655
|
+
/** S-57 object class acronym */
|
|
656
|
+
objectClass: string;
|
|
657
|
+
/** Human-readable name */
|
|
658
|
+
name: string;
|
|
659
|
+
/** Chart No. 1 section */
|
|
660
|
+
category: NauticalCategory;
|
|
661
|
+
/** S-52 display category */
|
|
662
|
+
displayCategory: DisplayCategory;
|
|
663
|
+
/** Default style using S-52 color tokens (resolved later) */
|
|
664
|
+
style: AtlasStyle;
|
|
665
|
+
/** Whether conditional symbology may override the style */
|
|
666
|
+
hasConditional?: boolean;
|
|
667
|
+
/** Attributes that affect styling */
|
|
668
|
+
conditionalAttributes?: string[];
|
|
669
|
+
/** INT1 / Chart No. 1 reference (e.g. "Q130.1") */
|
|
670
|
+
int1Ref?: string;
|
|
671
|
+
/** S-52 viewing group number */
|
|
672
|
+
viewingGroup?: number;
|
|
673
|
+
/** Minimum compilation scale for display (SCAMIN) */
|
|
674
|
+
scamin?: number;
|
|
675
|
+
}
|
|
676
|
+
/** Resolved style ready for Mapbox GL (tokens → hex) */
|
|
677
|
+
interface ResolvedStyle {
|
|
678
|
+
type: GeomType;
|
|
679
|
+
paint: Record<string, unknown>;
|
|
680
|
+
layout?: Record<string, unknown>;
|
|
681
|
+
minzoom?: number;
|
|
682
|
+
maxzoom?: number;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* S-52 lookup table covering all S-57 object classes found in NOAA ENCs.
|
|
687
|
+
* Colours reference S-52 tokens (resolved at render time).
|
|
688
|
+
* INT1 references per NOAA Chart No. 1 (Ed 13).
|
|
689
|
+
*/
|
|
690
|
+
declare const S52_LOOKUP: Record<string, LookupEntry>;
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* S-52 draw order: layers listed bottom → top.
|
|
694
|
+
* Layers not in this list are inserted before point features.
|
|
695
|
+
*/
|
|
696
|
+
declare const S52_DRAW_ORDER: string[];
|
|
697
|
+
/** Get numeric draw priority for a layer (lower = drawn first / below) */
|
|
698
|
+
declare function getDrawPriority(layerName: string): number;
|
|
699
|
+
|
|
700
|
+
/** S-52 display modes */
|
|
701
|
+
type DisplayMode = "BASE" | "STANDARD" | "ALL";
|
|
702
|
+
/** Check if a layer's display category is visible in the given mode */
|
|
703
|
+
declare function isVisibleInMode(displayCategory: DisplayCategory, mode: DisplayMode): boolean;
|
|
704
|
+
/**
|
|
705
|
+
* Convert S-52 SCAMIN (scale minimum) to Mapbox GL minzoom.
|
|
706
|
+
*/
|
|
707
|
+
declare function scaminToMinZoom(scamin?: number): number | undefined;
|
|
708
|
+
declare function getCollisionSettings(viewingGroup?: number): {
|
|
709
|
+
iconAllowOverlap: boolean;
|
|
710
|
+
iconOptional: boolean;
|
|
711
|
+
symbolSortKey?: number;
|
|
712
|
+
};
|
|
713
|
+
/**
|
|
714
|
+
* Get the resolved Mapbox GL style for a given S-57 layer.
|
|
715
|
+
*/
|
|
716
|
+
declare function resolveStyle(layerName: string, geomKind?: GeomType, ct?: ColorTableName): ResolvedStyle;
|
|
717
|
+
declare function getLookupEntry(layerName: string): LookupEntry;
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* S-52 Conditional Symbology Procedures.
|
|
721
|
+
* Each function takes feature properties and returns paint overrides (hex colours).
|
|
722
|
+
* All expression builders accept an optional colorTable parameter.
|
|
723
|
+
*/
|
|
724
|
+
declare function depareColor(props: Record<string, unknown>, ct?: ColorTableName): string;
|
|
725
|
+
declare function depareFillExpression(ct?: ColorTableName): unknown[];
|
|
726
|
+
declare function lightColor(props: Record<string, unknown>, ct?: ColorTableName): string;
|
|
727
|
+
declare function lightFillExpression(ct?: ColorTableName): unknown[];
|
|
728
|
+
declare function lateralColor(props: Record<string, unknown>, ct?: ColorTableName): string;
|
|
729
|
+
declare function lateralFillExpression(ct?: ColorTableName): unknown[];
|
|
730
|
+
declare function hazardColor(props: Record<string, unknown>, ct?: ColorTableName): string;
|
|
731
|
+
declare function hazardFillExpression(ct?: ColorTableName): unknown[];
|
|
732
|
+
declare function daymarkColor(props: Record<string, unknown>, ct?: ColorTableName): string;
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Label configurations for S-57 layers.
|
|
736
|
+
* Defines which layers get text labels and how to extract label text.
|
|
737
|
+
*/
|
|
738
|
+
|
|
739
|
+
interface LabelLayerConfig {
|
|
740
|
+
/** Mapbox source layer type */
|
|
741
|
+
type: "symbol";
|
|
742
|
+
/** Text field expression or string */
|
|
743
|
+
textField: ExpressionSpecification | string;
|
|
744
|
+
/** Text size in pixels */
|
|
745
|
+
textSize: number | ExpressionSpecification;
|
|
746
|
+
/** Text color */
|
|
747
|
+
textColor: string;
|
|
748
|
+
/** Halo color for contrast */
|
|
749
|
+
textHaloColor: string;
|
|
750
|
+
/** Halo width */
|
|
751
|
+
textHaloWidth: number;
|
|
752
|
+
/** Text offset [x, y] in ems */
|
|
753
|
+
textOffset: [number, number];
|
|
754
|
+
/** Font stack */
|
|
755
|
+
textFont?: string[];
|
|
756
|
+
/** Additional layout properties */
|
|
757
|
+
layout?: Record<string, unknown>;
|
|
758
|
+
/** Minimum zoom level for this label */
|
|
759
|
+
minzoom?: number;
|
|
760
|
+
}
|
|
761
|
+
/** Get label config for a given S-57 layer, or null if no labels */
|
|
762
|
+
declare function getLabelConfig(layerName: string): LabelLayerConfig | null;
|
|
763
|
+
/**
|
|
764
|
+
* Build a Mapbox symbol layer spec from a label config.
|
|
765
|
+
*/
|
|
766
|
+
declare function buildLabelLayer(layerId: string, sourceId: string, config: LabelLayerConfig, visible: boolean, overrides?: {
|
|
767
|
+
textScale?: number;
|
|
768
|
+
minzoom?: number | null;
|
|
769
|
+
allowOverlap?: boolean;
|
|
770
|
+
}): maplibregl.LayerSpecification;
|
|
771
|
+
/**
|
|
772
|
+
* Pre-process SOUNDG GeoJSON to extract Z coordinates as `depth` properties.
|
|
773
|
+
* Soundings are MultiPoint with Z values in geometry.coordinates[][2].
|
|
774
|
+
* This explodes MultiPoints into individual Points with a `depth` property.
|
|
775
|
+
*/
|
|
776
|
+
declare function preprocessSoundings(fc: GeoJSON.FeatureCollection): GeoJSON.FeatureCollection;
|
|
777
|
+
/**
|
|
778
|
+
* Pre-process LIGHTS GeoJSON to derive compact light characteristic labels.
|
|
779
|
+
* Adds `_lightLabel` property (e.g., "Fl R 4s").
|
|
780
|
+
*/
|
|
781
|
+
declare function preprocessLights(fc: GeoJSON.FeatureCollection): GeoJSON.FeatureCollection;
|
|
782
|
+
/** List of layers that have labels */
|
|
783
|
+
declare const LABELED_LAYERS: Set<string>;
|
|
784
|
+
/**
|
|
785
|
+
* Pre-process buoy/beacon GeoJSON to derive concise mariner-style labels.
|
|
786
|
+
* Adds `_navAidLabel` property (e.g., 'R "8"', 'G "5"').
|
|
787
|
+
*/
|
|
788
|
+
declare function preprocessNavAids(fc: GeoJSON.FeatureCollection): GeoJSON.FeatureCollection;
|
|
789
|
+
/** Check if a layer name needs nav aid preprocessing */
|
|
790
|
+
declare function isNavAidLayer(layerName: string): boolean;
|
|
791
|
+
/**
|
|
792
|
+
* Pre-process water body polygon GeoJSON into centroid points for label placement.
|
|
793
|
+
* Computes a simple average-coordinate centroid for each polygon feature that has OBJNAM.
|
|
794
|
+
*/
|
|
795
|
+
declare function preprocessWaterBodies(fc: GeoJSON.FeatureCollection): GeoJSON.FeatureCollection;
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Spatial grid-based feature decimation for performance at low zoom levels.
|
|
799
|
+
* Thins dense GeoJSON feature sets by keeping only one representative
|
|
800
|
+
* feature per grid cell per layer.
|
|
801
|
+
*/
|
|
802
|
+
interface DecimationOptions {
|
|
803
|
+
/** Grid resolution (cells per axis). Default 80. */
|
|
804
|
+
gridSize?: number;
|
|
805
|
+
/** Zoom level below which decimation kicks in. Default 12. */
|
|
806
|
+
zoomThreshold?: number;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Zoom-adaptive grid resolution for decimation.
|
|
810
|
+
*/
|
|
811
|
+
declare function getGridSizeForZoom(zoom: number): number;
|
|
812
|
+
/**
|
|
813
|
+
* Decimate a GeoJSON FeatureCollection using spatial grid thinning.
|
|
814
|
+
* Only runs when zoom < zoomThreshold. Returns the original FC otherwise.
|
|
815
|
+
*
|
|
816
|
+
* @param fc - Input FeatureCollection
|
|
817
|
+
* @param layerName - S-57 layer name (affects priority logic)
|
|
818
|
+
* @param currentZoom - Current map zoom level
|
|
819
|
+
* @param bounds - Current viewport bounds
|
|
820
|
+
* @param opts - Decimation options
|
|
821
|
+
*/
|
|
822
|
+
declare function decimateFeatures(fc: GeoJSON.FeatureCollection, layerName: string, currentZoom: number, bounds: {
|
|
823
|
+
west: number;
|
|
824
|
+
south: number;
|
|
825
|
+
east: number;
|
|
826
|
+
north: number;
|
|
827
|
+
}, opts?: DecimationOptions): GeoJSON.FeatureCollection;
|
|
828
|
+
/**
|
|
829
|
+
* Get the max number of cells to load based on zoom level.
|
|
830
|
+
*/
|
|
831
|
+
declare function getMaxCellsForZoom(zoom: number): number;
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* IHO S-52 / NOAA Chart No. 1 / INT1 nautical symbol SVGs.
|
|
835
|
+
*
|
|
836
|
+
* Complete symbology suite following:
|
|
837
|
+
* - IHO S-52 Presentation Library (Ed 4.0)
|
|
838
|
+
* - IALA Maritime Buoyage System R1001 (Region B for US waters)
|
|
839
|
+
* - NOAA Chart No. 1 (Ed 13) / INT1
|
|
840
|
+
*
|
|
841
|
+
* Buoy shape terminology (US / Chart No. 1):
|
|
842
|
+
* - CAN (Q20): Flat-top cylindrical buoy — Port mark in IALA-B (red)
|
|
843
|
+
* - NUN (Q21): Conical/pointed-top buoy — Starboard mark in IALA-B (green)
|
|
844
|
+
* - PILLAR: Tall narrow buoy — used for cardinal, isolated danger, etc.
|
|
845
|
+
* - SPAR: Tall thin pole buoy
|
|
846
|
+
* - SPHERICAL: Round buoy — safe water marks
|
|
847
|
+
* - BARREL: Barrel/tun shaped buoy
|
|
848
|
+
* - SUPER: Large navigation buoy / LANBY
|
|
849
|
+
*
|
|
850
|
+
* Cardinal mark topmark orientations (IALA):
|
|
851
|
+
* - North: both cones point UP ▲▲
|
|
852
|
+
* - South: both cones point DOWN ▼▼
|
|
853
|
+
* - East: cones base-to-base (diamond) ◆
|
|
854
|
+
* - West: cones point-to-point (hourglass) ⊗
|
|
855
|
+
*
|
|
856
|
+
* Each symbol is a compact SVG at 32×32 for Mapbox GL `map.addImage()`.
|
|
857
|
+
*/
|
|
858
|
+
/** Color used in the SVG with its S-52 token name, hex, and usage */
|
|
859
|
+
interface SymbolColor {
|
|
860
|
+
token: string;
|
|
861
|
+
hex: string;
|
|
862
|
+
usage: string;
|
|
863
|
+
}
|
|
864
|
+
/** Line style used in the SVG */
|
|
865
|
+
interface SymbolLineStyle {
|
|
866
|
+
element: string;
|
|
867
|
+
width: number;
|
|
868
|
+
pattern?: string;
|
|
869
|
+
color: string;
|
|
870
|
+
}
|
|
871
|
+
/** Fill element used in the SVG */
|
|
872
|
+
interface SymbolFillElement {
|
|
873
|
+
element: string;
|
|
874
|
+
color: string;
|
|
875
|
+
opacity?: number;
|
|
876
|
+
}
|
|
877
|
+
interface NauticalSymbol {
|
|
878
|
+
id: string;
|
|
879
|
+
label: string;
|
|
880
|
+
/** INT1 / Chart No. 1 reference */
|
|
881
|
+
int1Ref: string;
|
|
882
|
+
/** Chart No. 1 section letter */
|
|
883
|
+
section: string;
|
|
884
|
+
getSvg: () => string;
|
|
885
|
+
/** Generate SVG with theme-specific colors (for bridge icons etc.) */
|
|
886
|
+
getThemedSvg?: (chblk: string, movable: string) => string;
|
|
887
|
+
/** What this symbol represents on a chart */
|
|
888
|
+
description?: string;
|
|
889
|
+
/** S-52 Presentation Library symbol name */
|
|
890
|
+
s52PlRef?: string;
|
|
891
|
+
/** Grouping key for family clustering */
|
|
892
|
+
group?: string;
|
|
893
|
+
/** IDs of related variant symbols */
|
|
894
|
+
variants?: string[];
|
|
895
|
+
/** S-57 attribute that selects this variant */
|
|
896
|
+
attributeKey?: string;
|
|
897
|
+
/** Value of that attribute for this variant */
|
|
898
|
+
attributeValue?: number;
|
|
899
|
+
/** Example label strings seen on charts */
|
|
900
|
+
labelExamples?: string[];
|
|
901
|
+
/** What the color represents */
|
|
902
|
+
colorMeaning?: string;
|
|
903
|
+
/** Colors used in the SVG */
|
|
904
|
+
colors?: SymbolColor[];
|
|
905
|
+
/** Line/stroke styles used in the SVG */
|
|
906
|
+
lineStyles?: SymbolLineStyle[];
|
|
907
|
+
/** Fill regions in the SVG */
|
|
908
|
+
fillElements?: SymbolFillElement[];
|
|
909
|
+
/** Expanded navigational usage context (2-4 sentences) */
|
|
910
|
+
usageContext?: string;
|
|
911
|
+
/** Render size for documentation */
|
|
912
|
+
renderSize?: string;
|
|
913
|
+
}
|
|
914
|
+
/** A logical grouping of related symbols */
|
|
915
|
+
interface SymbolGroup {
|
|
916
|
+
id: string;
|
|
917
|
+
label: string;
|
|
918
|
+
section: string;
|
|
919
|
+
description: string;
|
|
920
|
+
symbolIds: string[];
|
|
921
|
+
}
|
|
922
|
+
/** Chart No. 1 section metadata */
|
|
923
|
+
interface ChartSection {
|
|
924
|
+
id: string;
|
|
925
|
+
label: string;
|
|
926
|
+
description: string;
|
|
927
|
+
}
|
|
928
|
+
declare const NAUTICAL_SYMBOLS: NauticalSymbol[];
|
|
929
|
+
/** S-57 object class → default symbol ID mapping.
|
|
930
|
+
* Values are S-52 PL symbol names (matching SVG filenames in s52/point/).
|
|
931
|
+
* Conditional expressions in getIconExpression() override these for classes
|
|
932
|
+
* with attribute-dependent variants.
|
|
933
|
+
*/
|
|
934
|
+
declare const SYMBOL_MAP: Record<string, string>;
|
|
935
|
+
/** Get the Mapbox icon-image expression for data-driven symbol selection.
|
|
936
|
+
* Returns S-52 PL symbol names that correspond to SVG files in s52/point/.
|
|
937
|
+
*/
|
|
938
|
+
declare function getIconExpression(layerName: string): string | unknown[];
|
|
939
|
+
/**
|
|
940
|
+
* Browser-only image loaders (`loadSymbolImages`, `loadThemedBridgeImages`)
|
|
941
|
+
* live in `./symbols-browser.ts` (sub-export `@chrtco/sdk/atlas/browser`) —
|
|
942
|
+
* they require a DOM (use `new Image()` + `map.addImage()`).
|
|
943
|
+
*/
|
|
944
|
+
/** Get inline SVG string for a symbol by ID (for the Atlas legend) */
|
|
945
|
+
declare function getSymbolSvgString(symbolId: string): string | null;
|
|
946
|
+
declare const CHART_SECTIONS: ChartSection[];
|
|
947
|
+
declare const SYMBOL_GROUPS: SymbolGroup[];
|
|
948
|
+
/** Generate a single SVG sprite sheet containing all symbols as <symbol> elements */
|
|
949
|
+
declare function generateSpriteSheet(): string;
|
|
950
|
+
/** Generate a JSON manifest mapping symbol IDs to metadata */
|
|
951
|
+
declare function generateSpriteManifest(): Record<string, {
|
|
952
|
+
label: string;
|
|
953
|
+
int1Ref: string;
|
|
954
|
+
section: string;
|
|
955
|
+
group?: string;
|
|
956
|
+
s52PlRef?: string;
|
|
957
|
+
description?: string;
|
|
958
|
+
attributeKey?: string;
|
|
959
|
+
attributeValue?: number;
|
|
960
|
+
}>;
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* IHO S-101 ENC Product Specification — Feature Catalogue
|
|
964
|
+
*
|
|
965
|
+
* S-101 replaces S-57 as the data model for Electronic Navigational Charts.
|
|
966
|
+
* This catalogue maps S-101 feature classes to:
|
|
967
|
+
* - S-57 equivalents (where they exist)
|
|
968
|
+
* - Chart No. 1 sections (same organizational structure)
|
|
969
|
+
* - Portrayal catalogue references (S-100 Portrayal Model)
|
|
970
|
+
*
|
|
971
|
+
* Key S-101 changes from S-57:
|
|
972
|
+
* - CamelCase feature class names (DepthArea vs DEPARE)
|
|
973
|
+
* - Complex/structured attributes (nested objects vs flat)
|
|
974
|
+
* - New feature types for AIS, quality, under-keel clearance
|
|
975
|
+
* - Removed/merged features for simplification
|
|
976
|
+
*
|
|
977
|
+
* Reference: IHO S-101 Product Specification (Ed 1.1.0)
|
|
978
|
+
* IHO S-100 Universal Hydrographic Data Model
|
|
979
|
+
*/
|
|
980
|
+
interface S101Feature {
|
|
981
|
+
/** S-101 camelCase feature class name */
|
|
982
|
+
featureClass: string;
|
|
983
|
+
/** Human-readable name */
|
|
984
|
+
name: string;
|
|
985
|
+
/** S-57 6-char equivalent acronym, if any */
|
|
986
|
+
s57Equivalent?: string;
|
|
987
|
+
/** Chart No. 1 section letter */
|
|
988
|
+
section: string;
|
|
989
|
+
/** Group key for clustering */
|
|
990
|
+
group: string;
|
|
991
|
+
/** Feature category */
|
|
992
|
+
category: "geo" | "meta" | "info";
|
|
993
|
+
/** Description of the feature */
|
|
994
|
+
description: string;
|
|
995
|
+
/** S-100 Portrayal Catalogue reference */
|
|
996
|
+
portrayalRef?: string;
|
|
997
|
+
/** True if this feature has no S-57 equivalent */
|
|
998
|
+
isNewInS101: boolean;
|
|
999
|
+
/** Key attributes specific to this feature */
|
|
1000
|
+
attributes?: string[];
|
|
1001
|
+
}
|
|
1002
|
+
declare const S101_FEATURES: S101Feature[];
|
|
1003
|
+
declare const S101_CHART_SECTIONS: {
|
|
1004
|
+
id: string;
|
|
1005
|
+
label: string;
|
|
1006
|
+
description: string;
|
|
1007
|
+
}[];
|
|
1008
|
+
declare const S101_SYMBOL_GROUPS: {
|
|
1009
|
+
id: string;
|
|
1010
|
+
label: string;
|
|
1011
|
+
section: string;
|
|
1012
|
+
description: string;
|
|
1013
|
+
}[];
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* S-101 Portrayal Catalogue — New Symbol SVGs
|
|
1017
|
+
*
|
|
1018
|
+
* These symbols represent features introduced in S-101 that have no
|
|
1019
|
+
* direct S-57/S-52 equivalent. The existing S-52 symbols are reused
|
|
1020
|
+
* where S-101 retains visual continuity with the S-57 portrayal.
|
|
1021
|
+
*
|
|
1022
|
+
* Reference: IHO S-101 Portrayal Catalogue (Ed 1.1.0)
|
|
1023
|
+
*/
|
|
1024
|
+
|
|
1025
|
+
declare const S101_NEW_SYMBOLS: NauticalSymbol[];
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* S-52 SVG Loader — pure (DOM-free) string operations over the inlined S-52
|
|
1029
|
+
* SVG catalogue in `s52-svgs-generated.ts`. SVG files use S-52 color token
|
|
1030
|
+
* names (e.g., CHBLK, LITRD) as fill/stroke values; `applyColorTheme` swaps
|
|
1031
|
+
* those tokens for hex from the active palette.
|
|
1032
|
+
*
|
|
1033
|
+
* Browser-only image loaders live in `./s52-svg-loader-browser.ts` (sub-export
|
|
1034
|
+
* `@chrtco/sdk/atlas/browser`) — they use `new Image()` and require a DOM.
|
|
1035
|
+
*/
|
|
1036
|
+
|
|
1037
|
+
/**
|
|
1038
|
+
* Get raw SVG string for an S-52 symbol by name (e.g., "BOYCAN01").
|
|
1039
|
+
* Returns null if the symbol is not found.
|
|
1040
|
+
*/
|
|
1041
|
+
declare function getS52SvgString(symbolName: string): string | null;
|
|
1042
|
+
/**
|
|
1043
|
+
* Get an S-52 SVG string with color tokens resolved to hex values
|
|
1044
|
+
* from the specified color table.
|
|
1045
|
+
*/
|
|
1046
|
+
declare function getThemedS52Svg(symbolName: string, colorTable?: ColorTableName): string | null;
|
|
1047
|
+
/**
|
|
1048
|
+
* Replace S-52 color token names in an SVG string with hex colors
|
|
1049
|
+
* from the active color table.
|
|
1050
|
+
*
|
|
1051
|
+
* Matches tokens in fill="TOKEN" and stroke="TOKEN" attribute values.
|
|
1052
|
+
*/
|
|
1053
|
+
declare function applyColorTheme(svgString: string, colorTable?: ColorTableName): string;
|
|
1054
|
+
/** Get a list of all available S-52 point symbol names. */
|
|
1055
|
+
declare function getAvailablePointSymbols(): string[];
|
|
1056
|
+
/** Get a list of all available S-52 pattern names. */
|
|
1057
|
+
declare function getAvailablePatterns(): string[];
|
|
1058
|
+
/** Get a list of all available S-52 line symbol names. */
|
|
1059
|
+
declare function getAvailableLineSymbols(): string[];
|
|
1060
|
+
/** Stats for debugging */
|
|
1061
|
+
declare function getS52SymbolStats(): {
|
|
1062
|
+
pointCount: number;
|
|
1063
|
+
patternCount: number;
|
|
1064
|
+
lineCount: number;
|
|
1065
|
+
totalCount: number;
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* Zoom range of CHRT tile builds — kept in lockstep with the baremetal
|
|
1070
|
+
* tippecanoe invocation (tools/chrt-baremetal/server/src/tilebuild/per-layer-zoom.ts).
|
|
1071
|
+
*
|
|
1072
|
+
* Per-S-57-class minzoom/maxzoom narrowing is handled inside the MVT at
|
|
1073
|
+
* tile-build time via per-feature `tippecanoe.minzoom/maxzoom`; these two
|
|
1074
|
+
* constants are the outer envelope the MapLibre source declares, so the
|
|
1075
|
+
* client doesn't request tiles outside what the pmtiles can actually serve.
|
|
1076
|
+
*/
|
|
1077
|
+
declare const BUILD_MINZOOM = 3;
|
|
1078
|
+
declare const BUILD_MAXZOOM = 14;
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* Post-consolidation (2026-04): one consolidated PMTiles per region, all
|
|
1082
|
+
* S-57 classes as distinct MVT layers inside. The MapLibre style emits one
|
|
1083
|
+
* vector source (id = region) and N paint layers that reference it via
|
|
1084
|
+
* `source-layer` = S-57 class name.
|
|
1085
|
+
*
|
|
1086
|
+
* `buildSources()` returns either the legacy Mapbox MTS shape (preserved for
|
|
1087
|
+
* demos / external style export — see generateStyle comments) or the PMTiles
|
|
1088
|
+
* shape pointing at a single tile URL per region.
|
|
1089
|
+
*/
|
|
1090
|
+
/** Vector source emitted for the legacy Mapbox MTS path. */
|
|
1091
|
+
interface MapboxVectorSource {
|
|
1092
|
+
type: "vector";
|
|
1093
|
+
url: string;
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Vector source emitted for the tiles.chrt.co PMTiles path. Uses an explicit
|
|
1097
|
+
* `tiles` array (not a TileJSON `url`) because the tile-worker serves raw MVT
|
|
1098
|
+
* bytes without a TileJSON descriptor.
|
|
1099
|
+
*/
|
|
1100
|
+
interface PmtilesVectorSource {
|
|
1101
|
+
type: "vector";
|
|
1102
|
+
tiles: string[];
|
|
1103
|
+
minzoom: number;
|
|
1104
|
+
maxzoom: number;
|
|
1105
|
+
}
|
|
1106
|
+
type VectorSourceSpec = MapboxVectorSource | PmtilesVectorSource;
|
|
1107
|
+
type SourceMode = "mapbox" | "pmtiles";
|
|
1108
|
+
/**
|
|
1109
|
+
* Default tile-worker origin for PMTiles mode. Callers should pass
|
|
1110
|
+
* `tileBaseUrl` explicitly via `BuildSourcesOptions` to override (e.g. the
|
|
1111
|
+
* React app reads `import.meta.env.VITE_TILE_WORKER_BASE`; the offline-worker
|
|
1112
|
+
* reads `env.TILE_BASE_URL`). This constant is the prod fallback only.
|
|
1113
|
+
*/
|
|
1114
|
+
declare const DEFAULT_TILE_BASE_URL = "https://tiles.chrt.co";
|
|
1115
|
+
/** Canonical source id used in `generateStyle()` — matches the region name
|
|
1116
|
+
* of the one consolidated PMTiles served by the tile-worker for this region. */
|
|
1117
|
+
declare const DEFAULT_REGION = "NOAA_ENC";
|
|
1118
|
+
interface BuildSourcesOptions {
|
|
1119
|
+
/** Which tile path to emit. Default: "pmtiles" (the supported path post-Mapbox). */
|
|
1120
|
+
mode?: SourceMode;
|
|
1121
|
+
/** Chart region. Default: "NOAA_ENC". */
|
|
1122
|
+
region?: string;
|
|
1123
|
+
/**
|
|
1124
|
+
* Reserved for future cache-busting on KV-pointer flips. Currently unused;
|
|
1125
|
+
* build pinning rides in the JWT, not the URL.
|
|
1126
|
+
*/
|
|
1127
|
+
buildTag?: string;
|
|
1128
|
+
/** Override tile-worker origin (e.g. staging). Default: DEFAULT_TILE_BASE_URL. */
|
|
1129
|
+
tileBaseUrl?: string;
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Build the "sources" block for a CHRT style.
|
|
1133
|
+
*
|
|
1134
|
+
* - `mode: "mapbox"`: one mapbox:// url (kept for external style export only).
|
|
1135
|
+
* - `mode: "pmtiles"` (default): one vector tile endpoint for the region,
|
|
1136
|
+
* routed by the Worker to the one consolidated PMTiles:
|
|
1137
|
+
* `${tileBaseUrl}/v1/tiles/{region}/{z}/{x}/{y}.mvt`
|
|
1138
|
+
*/
|
|
1139
|
+
declare function buildSources(opts?: BuildSourcesOptions): Record<string, VectorSourceSpec>;
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* Builds Mapbox GL Style layer specs from S-52 lookup entries.
|
|
1143
|
+
* Wraps the existing atlas resolveStyle() and adds source/source-layer/filter.
|
|
1144
|
+
*/
|
|
1145
|
+
|
|
1146
|
+
interface StyleLayer {
|
|
1147
|
+
id: string;
|
|
1148
|
+
type: string;
|
|
1149
|
+
source: string;
|
|
1150
|
+
"source-layer": string;
|
|
1151
|
+
filter?: unknown[];
|
|
1152
|
+
paint: Record<string, unknown>;
|
|
1153
|
+
layout?: Record<string, unknown>;
|
|
1154
|
+
minzoom?: number;
|
|
1155
|
+
maxzoom?: number;
|
|
1156
|
+
metadata?: Record<string, unknown>;
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Build all Mapbox GL layers for a given S-57 object class.
|
|
1160
|
+
* Returns multiple layers (fill, outline, symbol, label, etc.).
|
|
1161
|
+
*
|
|
1162
|
+
* Post-consolidation: all S-57 classes live as MVT layers inside one
|
|
1163
|
+
* consolidated PMTiles per region; `source` is always the region name.
|
|
1164
|
+
*/
|
|
1165
|
+
declare function buildLayersForClass(objectClass: string, ct: ColorTableName, sourceId?: string): StyleLayer[];
|
|
1166
|
+
/**
|
|
1167
|
+
* Get the full ordered list of object classes for style generation.
|
|
1168
|
+
* Uses S52_DRAW_ORDER as base, then adds any missing classes from the
|
|
1169
|
+
* S-52 lookup table so a newly-ingested class automatically gets styled
|
|
1170
|
+
* without touching this file.
|
|
1171
|
+
*/
|
|
1172
|
+
declare function getOrderedClasses(): string[];
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* Generates a complete Mapbox GL Style Specification v8 JSON
|
|
1176
|
+
* from the S-52 atlas definitions.
|
|
1177
|
+
*/
|
|
1178
|
+
|
|
1179
|
+
interface MapboxStyle {
|
|
1180
|
+
version: 8;
|
|
1181
|
+
name: string;
|
|
1182
|
+
metadata: Record<string, unknown>;
|
|
1183
|
+
sources: Record<string, unknown>;
|
|
1184
|
+
sprite?: string;
|
|
1185
|
+
glyphs: string;
|
|
1186
|
+
layers: StyleLayer[];
|
|
1187
|
+
}
|
|
1188
|
+
declare function generateStyle(palette?: ColorTableName, opts?: BuildSourcesOptions): MapboxStyle;
|
|
1189
|
+
declare function generateStyleJSON(palette?: ColorTableName, opts?: BuildSourcesOptions): string;
|
|
1190
|
+
/** Get summary stats about the generated style */
|
|
1191
|
+
declare function getStyleStats(style: MapboxStyle): {
|
|
1192
|
+
totalLayers: number;
|
|
1193
|
+
fillLayers: number;
|
|
1194
|
+
lineLayers: number;
|
|
1195
|
+
symbolLayers: number;
|
|
1196
|
+
circleLayers: number;
|
|
1197
|
+
sources: number;
|
|
1198
|
+
objectClasses: Set<string>;
|
|
1199
|
+
};
|
|
1200
|
+
|
|
244
1201
|
declare class Chrt {
|
|
245
1202
|
/** Tile endpoints — styleUrl, tileUrl, groups */
|
|
246
1203
|
readonly tiles: TilesEndpoint;
|
|
@@ -248,6 +1205,12 @@ declare class Chrt {
|
|
|
248
1205
|
readonly cells: CellsEndpoint;
|
|
249
1206
|
/** Coverage data — list available chart sources */
|
|
250
1207
|
readonly coverage: CoverageEndpoint;
|
|
1208
|
+
/**
|
|
1209
|
+
* CHRToffline — download MBTiles bundles for offline use.
|
|
1210
|
+
* Requires `deviceId` in config. Manifest-based budget enforcement
|
|
1211
|
+
* requires `manifestPath`.
|
|
1212
|
+
*/
|
|
1213
|
+
readonly offline: OfflineEndpoint;
|
|
251
1214
|
private featuresEp;
|
|
252
1215
|
private queryEp;
|
|
253
1216
|
private http;
|
|
@@ -293,4 +1256,4 @@ declare class Chrt {
|
|
|
293
1256
|
transformRequest(): (url: string) => TransformRequest | undefined;
|
|
294
1257
|
}
|
|
295
1258
|
|
|
296
|
-
export { type CellDeletedEvent, type CellDetail, type CellEventData, type CellNewEvent, type CellUpdatedData, type CellUpdatedEvent, type CellsOptions, type CellsResponse, Chrt, type ChrtConfig, ChrtError, type CoverageOptions, type CoverageResponse, type CoverageSource, type FeatureCollection, type FeaturesOptions, type GeoJsonFeature, type GeoJsonGeometry, type QueryOptions, type TileGroup, type TileGroupsResponse, type TransformRequest, type WebhookEvent, type WebhookEventType, type WebhookPayload, paginate, parseWebhook };
|
|
1259
|
+
export { type AtlasStyle, BUILD_MAXZOOM, BUILD_MINZOOM, type BuildOfflineStyleOptions, type BuildSourcesOptions, CHART_SECTIONS, type CellDeletedEvent, type CellDetail, type CellEventData, type CellNewEvent, type CellUpdatedData, type CellUpdatedEvent, type CellsOptions, type CellsResponse, type ChartSection, Chrt, type ChrtConfig, ChrtError, ColorTableName, type CoverageOptions, type CoverageResponse, type CoverageSource, DEFAULT_REGION, DEFAULT_TILE_BASE_URL, type DisplayCategory, type DisplayMode, type FeatureCollection, type FeaturesOptions, FileSystemAdapter, type GeoJsonFeature, type GeoJsonGeometry, type GeomType, LABELED_LAYERS, type LabelLayerConfig, type LookupEntry, type MapLibreStyle, type MapboxStyle, type MapboxVectorSource, NAUTICAL_SYMBOLS, type NauticalCategory, type NauticalSymbol, type OfflineBundleResponse, type OfflineDownloadOptions, type OfflineDownloadProgress, type OfflineDownloadResult, OfflineError, type OfflineErrorCode, type OfflineFetchStyleOptions, type OfflineHeartbeatOptions, type OfflineRegionSummary, type OfflineRemoveOptions, OfflineStyleError, type OfflineStylePlatform, type OfflineStyleResponse, type PmtilesVectorSource, type QueryOptions, type ResolvedStyle, type RouteFeatureQueryOptions, type RouteFeatureQueryResponse, type RouteQueryOptions, type RouteQueryResponse, type S101Feature, S101_CHART_SECTIONS, S101_FEATURES, S101_NEW_SYMBOLS, S101_SYMBOL_GROUPS, S52_DRAW_ORDER, S52_LOOKUP, SYMBOL_GROUPS, SYMBOL_MAP, type SourceMode, type StyleLayer, type SymbolGroup, type TileGroup, type TileGroupsResponse, type TransformRequest, type VectorSourceSpec, type WebhookEvent, type WebhookEventType, type WebhookPayload, applyColorTheme, buildLabelLayer, buildLayersForClass, buildOfflineStyle, buildSources, daymarkColor, decimateFeatures, depareColor, depareFillExpression, generateSpriteManifest, generateSpriteSheet, generateStyle, generateStyleJSON, getAvailableLineSymbols, getAvailablePatterns, getAvailablePointSymbols, getCollisionSettings, getDrawPriority, getGridSizeForZoom, getIconExpression, getLabelConfig, getLookupEntry, getMaxCellsForZoom, getOrderedClasses, getS52SvgString, getS52SymbolStats, getStyleStats, getSymbolSvgString, getThemedS52Svg, hazardColor, hazardFillExpression, isNavAidLayer, isVisibleInMode, lateralColor, lateralFillExpression, lightColor, lightFillExpression, paginate, parseWebhook, preprocessLights, preprocessNavAids, preprocessSoundings, preprocessWaterBodies, resolveStyle, scaminToMinZoom };
|