@locate2u/mesh-map 0.0.0-stage → 0.1.0-beta.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.js","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAuB,MAAM,UAAU,CAAC;AAGxD,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AAE3D,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC7C,yFAAyF;IACzF,UAAU,GAAmB,IAAI,CAAC;IAC1B,QAAQ,GAAyB,IAAI,CAAC;IAE9C,MAAM,KAAK,kBAAkB;QAC3B,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IAED,iBAAiB;QACf,4EAA4E;QAC5E,4EAA4E;QAC5E,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO;YAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;QACtD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED,oBAAoB;QAClB,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,wBAAwB,CAAC,IAAY,EAAE,IAAmB,EAAE,KAAoB;QAC9E,IAAI,IAAI,KAAK,OAAO,IAAI,KAAK,IAAI,IAAI,CAAC,UAAU;YAAE,KAAK,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAc,CAAC,CAAC;IAClG,CAAC;IAEO,KAAK,CAAC,KAAK;QACjB,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC;QAC9D,MAAM,MAAM,G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AC,CAAC,CAAC,CAAC;YAC1B,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS;gBAAG,OAA8C,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC1G,CAAC;QAED,IAAI,CAAC;YACH,IAAI,CAAC,UAAU,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAChD,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACpG,CAAC;QAAC,MAAM,CAAC;YACP,yEAAyE;YACzE,sEAAsE;QACxE,CAAC;IACH,CAAC;IAED,4EAA4E;IAC5E,SAAS;QACP,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAC5C,CAAC;CACF;AAED,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;IAC7E,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Why the map is not drawing.
3
+ *
4
+ * 🔴 THE FAILURE THIS FILE EXISTS FOR. On 2026-10-16 an application built
5
+ * against Mesh showed a blank grey rectangle and the status line
6
+ * "Loaded from Mesh". Every tile request had returned **200**, with the right
7
+ * content type and a plausible number of bytes, and the map library had refused
8
+ * every one of them. The application's error handler surfaced only failures
9
+ * carrying an HTTP status, and a tile that cannot be parsed has none.
10
+ *
11
+ * That is the shape of almost every map failure: the page does not crash, the
12
+ * console stays quiet, and a grey rectangle is indistinguishable from an empty
13
+ * ocean. So this control reports a cause, every time, with a code worth keying
14
+ * on and a sentence worth showing a user.
15
+ */
16
+ export type MeshMapErrorCode =
17
+ /** The map key or token was refused. Usually wrong key, wrong environment, or an origin the key is not allowed on. */
18
+ 'credential_rejected'
19
+ /** Authenticated, but the tenant does not have the Maps module enabled. */
20
+ | 'module_not_enabled'
21
+ /** The environment has no published map data at all, so no region can be served. */
22
+ | 'no_map_data'
23
+ /** The service could not be asked what it can serve. Usually a wrong base URL or a network failure. */
24
+ | 'discovery_failed'
25
+ /** A square arrived and could not be read. Answers 200; draws nothing. */
26
+ | 'tile_unreadable'
27
+ /** The tenant is over its allowance for this period. */
28
+ | 'quota_exceeded'
29
+ /** Minting a short-lived map token failed, so the map cannot keep refreshing. */
30
+ | 'token_refresh_failed'
31
+ /** Anything else, with the original attached. */
32
+ | 'unknown';
33
+ export interface MeshMapError {
34
+ code: MeshMapErrorCode;
35
+ /** One sentence, written to be shown to a developer, not parsed. */
36
+ message: string;
37
+ /** HTTP status where there was one. A parse failure has none — that is the point. */
38
+ status?: number;
39
+ /** The request that failed, with any credential removed. */
40
+ url?: string;
41
+ /** Whether the map is still usable. A single bad square is not an outage. */
42
+ fatal: boolean;
43
+ cause?: unknown;
44
+ }
45
+ /** Never put a credential in an error, a log line or an event. */
46
+ export declare function redact(url: string): string;
47
+ /**
48
+ * Turn whatever the map library threw into something with a cause.
49
+ *
50
+ * ⚠️ The ordering matters. A tile parse failure carries no status, so checking
51
+ * status first and giving up classifies the most confusing failure mode as
52
+ * "unknown" — which is where this started.
53
+ */
54
+ export declare function classify(raw: unknown): MeshMapError;
55
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,MAAM,gBAAgB;AAC1B,sHAAsH;AACpH,qBAAqB;AACvB,2EAA2E;GACzE,oBAAoB;AACtB,oFAAoF;GAClF,aAAa;AACf,uGAAuG;GACrG,kBAAkB;AACpB,0EAA0E;GACxE,iBAAiB;AACnB,wDAAwD;GACtD,gBAAgB;AAClB,iFAAiF;GAC/E,sBAAsB;AACxB,iDAAiD;GAC/C,SAAS,CAAC;AAEd,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,gBAAgB,CAAC;IACvB,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CA4DnD"}
package/dist/errors.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Why the map is not drawing.
3
+ *
4
+ * 🔴 THE FAILURE THIS FILE EXISTS FOR. On 2026-10-16 an application built
5
+ * against Mesh showed a blank grey rectangle and the status line
6
+ * "Loaded from Mesh". Every tile request had returned **200**, with the right
7
+ * content type and a plausible number of bytes, and the map library had refused
8
+ * every one of them. The application's error handler surfaced only failures
9
+ * carrying an HTTP status, and a tile that cannot be parsed has none.
10
+ *
11
+ * That is the shape of almost every map failure: the page does not crash, the
12
+ * console stays quiet, and a grey rectangle is indistinguishable from an empty
13
+ * ocean. So this control reports a cause, every time, with a code worth keying
14
+ * on and a sentence worth showing a user.
15
+ */
16
+ /** Never put a credential in an error, a log line or an event. */
17
+ export function redact(url) {
18
+ try {
19
+ const u = new URL(url);
20
+ for (const p of ['key', 'token', 'access_token'])
21
+ if (u.searchParams.has(p))
22
+ u.searchParams.set(p, '…');
23
+ return u.toString();
24
+ }
25
+ catch {
26
+ return url;
27
+ }
28
+ }
29
+ /**
30
+ * Turn whatever the map library threw into something with a cause.
31
+ *
32
+ * ⚠️ The ordering matters. A tile parse failure carries no status, so checking
33
+ * status first and giving up classifies the most confusing failure mode as
34
+ * "unknown" — which is where this started.
35
+ */
36
+ export function classify(raw) {
37
+ const err = raw;
38
+ const message = String(err?.message ?? raw ?? 'the map failed for a reason it did not state');
39
+ const status = typeof err?.status === 'number' ? err.status : undefined;
40
+ const url = err?.url ? redact(err.url) : undefined;
41
+ if (/unable to parse the tile|unimplemented type|not a gzip|invalid/i.test(message) && !status) {
42
+ return {
43
+ code: 'tile_unreadable',
44
+ message: 'A map square arrived but could not be read, so nothing from it is drawn. The request ' +
45
+ 'succeeded — this is a problem with the bytes, not the connection.',
46
+ url,
47
+ fatal: false,
48
+ cause: raw,
49
+ };
50
+ }
51
+ if (status === 401 || status === 403) {
52
+ // 403 with a module code is a different fix from a bad key: one is a
53
+ // support conversation about entitlement, the other is a typo.
54
+ const moduleGated = /module/i.test(message);
55
+ return {
56
+ code: moduleGated ? 'module_not_enabled' : 'credential_rejected',
57
+ message: moduleGated
58
+ ? 'The credential is valid but this tenant does not have the Maps module enabled.'
59
+ : 'The map key or token was refused. Check the key, the environment it belongs to, and ' +
60
+ 'whether this page\'s origin is one the key allows.',
61
+ status,
62
+ url,
63
+ fatal: true,
64
+ cause: raw,
65
+ };
66
+ }
67
+ if (status === 429) {
68
+ return {
69
+ code: 'quota_exceeded',
70
+ message: 'This tenant is over its map allowance for the current period.',
71
+ status,
72
+ url,
73
+ fatal: false,
74
+ cause: raw,
75
+ };
76
+ }
77
+ if (status === 503) {
78
+ return {
79
+ code: 'no_map_data',
80
+ message: 'The service is reachable but has no map data published for this environment, so there ' +
81
+ 'is nothing to draw.',
82
+ status,
83
+ url,
84
+ fatal: true,
85
+ cause: raw,
86
+ };
87
+ }
88
+ return { code: 'unknown', message, status, url, fatal: false, cause: raw };
89
+ }
90
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GA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AC/D,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO;YACL,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,qBAAqB;YAChE,OAAO,EAAE,WAAW;gBAClB,CAAC,CAAC,gFAAgF;gBAClF,CAAC,CAAC,sFAAsF;oBACtF,oDAAoD;YACxD,MAAM;YACN,GAAG;YACH,KAAK,EAAE,IAAI;YACX,KAAK,EAAE,GAAG;SACX,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,+DAA+D;YACxE,MAAM;YACN,GAAG;YACH,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,GAAG;SACX,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,OAAO;YACL,IAAI,EAAE,aAAa;YACnB,OAAO,EACL,wFAAwF;gBACxF,qBAAqB;YACvB,MAAM;YACN,GAAG;YACH,KAAK,EAAE,IAAI;YACX,KAAK,EAAE,GAAG;SACX,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @locate2u/mesh-map — the Locate2u Mesh map control.
3
+ *
4
+ * Two ways in. `MeshMap.create()` for application code that wants the object,
5
+ * and `<mesh-map>` for markup — import `@locate2u/mesh-map/element` to register
6
+ * it.
7
+ *
8
+ * ⚠️ This package draws maps. It knows nothing about stops, runs or drivers and
9
+ * never fetches one: hand it geometry and it renders it. That boundary is set
10
+ * by design ADR 0059 §4 and is not an oversight.
11
+ */
12
+ export { MeshMap, type MeshMapOptions } from './map.js';
13
+ export { discover, type Published } from './discovery.js';
14
+ export { Credential, type TokenMinter, type MintedToken } from './credentials.js';
15
+ export { classify, redact, type MeshMapError, type MeshMapErrorCode, } from './errors.js';
16
+ export { solarElevation, isNight, themeFor, DAY_THEMES, NIGHT_THEMES, type Theme, } from './theme.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EACL,QAAQ,EACR,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,OAAO,EACP,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,KAAK,KAAK,GACX,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @locate2u/mesh-map — the Locate2u Mesh map control.
3
+ *
4
+ * Two ways in. `MeshMap.create()` for application code that wants the object,
5
+ * and `<mesh-map>` for markup — import `@locate2u/mesh-map/element` to register
6
+ * it.
7
+ *
8
+ * ⚠️ This package draws maps. It knows nothing about stops, runs or drivers and
9
+ * never fetches one: hand it geometry and it renders it. That boundary is set
10
+ * by design ADR 0059 §4 and is not an oversight.
11
+ */
12
+ export { MeshMap } from './map.js';
13
+ export { discover } from './discovery.js';
14
+ export { Credential } from './credentials.js';
15
+ export { classify, redact, } from './errors.js';
16
+ export { solarElevation, isNight, themeFor, DAY_THEMES, NIGHT_THEMES, } from './theme.js';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAuB,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAkB,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAsC,MAAM,kBAAkB,CAAC;AAClF,OAAO,EACL,QAAQ,EACR,MAAM,GAGP,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,OAAO,EACP,QAAQ,EACR,UAAU,EACV,YAAY,GAEb,MAAM,YAAY,CAAC"}
package/dist/map.d.ts ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The map control.
3
+ *
4
+ * What this exists to stop every customer re-deriving, measured from a real
5
+ * application built against Mesh on 2026-10-16 with no help:
6
+ *
7
+ * - that region and version are unguessable and come from `GET /api`
8
+ * - that the credential has to be threaded into generated sub-requests
9
+ * - that the library must be MapLibre and not Mapbox GL JS, for licence
10
+ * reasons rather than taste
11
+ * - that a session should pin the version it discovered
12
+ * - that a short-lived token has to be refreshed before it expires
13
+ * - that a blank map needs to say WHY, because every failure here answers 200
14
+ *
15
+ * ⚠️ WHAT IT DELIBERATELY DOES NOT DO. It knows nothing about stops, runs,
16
+ * drivers or any other Mesh resource, and it never fetches one. It draws what
17
+ * it is handed. A control that fetched your runs for you would be a product
18
+ * surface rather than a platform one — design ADR 0059 §4 and `scope.md`.
19
+ */
20
+ import { Map as MapLibreMap } from 'maplibre-gl';
21
+ /** The style document shape, taken from the library rather than named separately. */
22
+ type StyleSpecification = ReturnType<MapLibreMap['getStyle']>;
23
+ import { type TokenMinter } from './credentials.js';
24
+ import { type Published } from './discovery.js';
25
+ import { type MeshMapError } from './errors.js';
26
+ import { type Theme } from './theme.js';
27
+ export interface MeshMapOptions {
28
+ /** The element to draw in, or its id. */
29
+ container: HTMLElement | string;
30
+ /** Origin of the Mesh tiles service, e.g. https://tiles-api.mesh.locate2u.app — no path. */
31
+ tilesBaseUrl: string;
32
+ /** A Mesh map key. Safe in front-end code: origin-locked, per tenant, revocable. */
33
+ mapKey?: string;
34
+ /**
35
+ * Or a function that mints a short-lived map token from YOUR backend.
36
+ * ⚠️ Never mint one in the browser — that needs a Mesh bearer token, and a
37
+ * bearer token in front-end code is a credential leak.
38
+ */
39
+ getMapToken?: TokenMinter;
40
+ /** Starting view. */
41
+ center?: [number, number];
42
+ zoom?: number;
43
+ pitch?: number;
44
+ bearing?: number;
45
+ /** One of the five the service paints. Unknown values fall back to `light`. */
46
+ theme?: Theme;
47
+ /**
48
+ * Switch between a day and a night theme at civil twilight, for the map's
49
+ * current centre. Off by default — a map that changes colour unasked is a
50
+ * surprise.
51
+ */
52
+ autoTheme?: boolean | {
53
+ day: Theme;
54
+ night: Theme;
55
+ };
56
+ /** Shop and café labels. On by default. */
57
+ pois?: boolean;
58
+ /** Extruded buildings. Needs tilt and zoom 14+ to show anything. */
59
+ buildings3d?: boolean;
60
+ /** Pin to a particular published region instead of the first one offered. */
61
+ region?: string;
62
+ /** Told why the map is not drawing. Strongly recommended — see `errors.ts`. */
63
+ onError?: (error: MeshMapError) => void;
64
+ }
65
+ export declare class MeshMap {
66
+ /** The MapLibre map, for anything this control does not wrap. */
67
+ readonly map: MapLibreMap;
68
+ /** What the service said it had when this session started. */
69
+ readonly published: Published;
70
+ private readonly credential;
71
+ private readonly origin;
72
+ private readonly onError;
73
+ private readonly options;
74
+ private theme;
75
+ private autoThemeTimer;
76
+ private disposed;
77
+ private constructor();
78
+ /**
79
+ * Create a map. Asynchronous because it asks the service what it can serve
80
+ * before drawing anything — see `discovery.ts` for why that is not optional.
81
+ */
82
+ static create(options: MeshMapOptions): Promise<MeshMap>;
83
+ /** Paint a different theme. Keeps the view, the pinned version and your own layers. */
84
+ setTheme(theme: Theme): Promise<void>;
85
+ /** The theme currently painted. */
86
+ get currentTheme(): Theme;
87
+ /**
88
+ * The style document as the service built it, for callers that want to read
89
+ * `metadata` or insert their own layers at a particular point.
90
+ */
91
+ get style(): StyleSpecification;
92
+ /** Stop timers and release the map. Safe to call twice. */
93
+ destroy(): void;
94
+ private startAutoTheme;
95
+ }
96
+ export {};
97
+ //# sourceMappingURL=map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAEjD,qFAAqF;AACrF,KAAK,kBAAkB,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;AAC9D,OAAO,EAAgC,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAY,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,SAAS,EAAE,WAAW,GAAG,MAAM,CAAC;IAChC,4FAA4F;IAC5F,YAAY,EAAE,MAAM,CAAC;IAErB,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B,qBAAqB;IACrB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG;QAAE,GAAG,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC;IAEnD,2CAA2C;IAC3C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,oEAAoE;IACpE,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;CACzC;AAID,qBAAa,OAAO;IAClB,iEAAiE;IACjE,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAE9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO;IAkBP;;;OAGG;WACU,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IAyD9D,uFAAuF;IACjF,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3C,mCAAmC;IACnC,IAAI,YAAY,IAAI,KAAK,CAExB;IAED;;;OAGG;IACH,IAAI,KAAK,IAAI,kBAAkB,CAE9B;IAED,2DAA2D;IAC3D,OAAO,IAAI,IAAI;IAQf,OAAO,CAAC,cAAc;CAUvB"}
package/dist/map.js ADDED
@@ -0,0 +1,167 @@
1
+ /**
2
+ * The map control.
3
+ *
4
+ * What this exists to stop every customer re-deriving, measured from a real
5
+ * application built against Mesh on 2026-10-16 with no help:
6
+ *
7
+ * - that region and version are unguessable and come from `GET /api`
8
+ * - that the credential has to be threaded into generated sub-requests
9
+ * - that the library must be MapLibre and not Mapbox GL JS, for licence
10
+ * reasons rather than taste
11
+ * - that a session should pin the version it discovered
12
+ * - that a short-lived token has to be refreshed before it expires
13
+ * - that a blank map needs to say WHY, because every failure here answers 200
14
+ *
15
+ * ⚠️ WHAT IT DELIBERATELY DOES NOT DO. It knows nothing about stops, runs,
16
+ * drivers or any other Mesh resource, and it never fetches one. It draws what
17
+ * it is handed. A control that fetched your runs for you would be a product
18
+ * surface rather than a platform one — design ADR 0059 §4 and `scope.md`.
19
+ */
20
+ // ⚠️ Named imports, not a default. MapLibre dropped its default export in v6;
21
+ // `import maplibregl from "maplibre-gl"` compiles under older typings and is
22
+ // undefined at runtime, which fails as "maplibregl.Map is not a constructor"
23
+ // at the one moment you are trying to draw a map.
24
+ import { Map as MapLibreMap } from 'maplibre-gl';
25
+ import { Credential, transformRequest } from './credentials.js';
26
+ import { discover } from './discovery.js';
27
+ import { classify } from './errors.js';
28
+ import { themeFor } from './theme.js';
29
+ const DEFAULT_PAIR = { day: 'light', night: 'dark' };
30
+ export class MeshMap {
31
+ /** The MapLibre map, for anything this control does not wrap. */
32
+ map;
33
+ /** What the service said it had when this session started. */
34
+ published;
35
+ credential;
36
+ origin;
37
+ onError;
38
+ options;
39
+ theme;
40
+ autoThemeTimer;
41
+ disposed = false;
42
+ constructor(args) {
43
+ this.map = args.map;
44
+ this.published = args.published;
45
+ this.credential = args.credential;
46
+ this.origin = args.origin;
47
+ this.theme = args.theme;
48
+ this.options = args.options;
49
+ this.onError = args.onError;
50
+ }
51
+ /**
52
+ * Create a map. Asynchronous because it asks the service what it can serve
53
+ * before drawing anything — see `discovery.ts` for why that is not optional.
54
+ */
55
+ static async create(options) {
56
+ const onError = options.onError ?? ((e) => console.error(`[mesh-map] ${e.code}: ${e.message}`));
57
+ if (!options.mapKey && !options.getMapToken) {
58
+ const e = {
59
+ code: 'credential_rejected',
60
+ message: 'A map key or a getMapToken function is required. Mesh maps are metered per tenant, so ' +
61
+ 'there is no anonymous mode.',
62
+ fatal: true,
63
+ };
64
+ onError(e);
65
+ throw e;
66
+ }
67
+ const baseUrl = options.tilesBaseUrl.replace(/\/$/, '');
68
+ const origin = new URL(baseUrl).origin;
69
+ const published = await discover(baseUrl, { region: options.region });
70
+ const credential = options.mapKey
71
+ ? Credential.fromKey(options.mapKey, onError)
72
+ : await Credential.fromMinter(options.getMapToken, onError);
73
+ const centre = options.center ?? [0, 0];
74
+ const pair = resolvePair(options.autoTheme);
75
+ const theme = options.autoTheme && pair
76
+ ? themeFor(new Date(), centre[1], centre[0], pair)
77
+ : (options.theme ?? 'light');
78
+ const map = new MapLibreMap({
79
+ container: options.container,
80
+ style: styleUrl(baseUrl, published, theme, options),
81
+ center: centre,
82
+ zoom: options.zoom ?? 11,
83
+ pitch: options.pitch ?? 0,
84
+ bearing: options.bearing ?? 0,
85
+ // 🔴 NOT CONFIGURABLE, AND THAT IS THE POINT. The OpenStreetMap credit is
86
+ // a licence obligation that has to reach the person looking at the map.
87
+ // Putting it here rather than in each application is what stops it being
88
+ // lost by somebody who never knew it was required. Compact is permitted:
89
+ // the OSMF guidelines allow it behind an information icon.
90
+ attributionControl: { compact: true },
91
+ transformRequest: transformRequest(origin, () => credential.current),
92
+ });
93
+ const self = new MeshMap({ map, published, credential, origin, theme, options, onError });
94
+ // ⚠️ The handler that would have turned 2026-10-16's blank grey rectangle
95
+ // into one sentence. MapLibre reports tile parse failures on this event and
96
+ // nowhere else, and only if something is listening.
97
+ map.on('error', (e) => self.onError(classify(e?.error ?? e)));
98
+ if (options.autoTheme && pair)
99
+ self.startAutoTheme(pair);
100
+ return self;
101
+ }
102
+ /** Paint a different theme. Keeps the view, the pinned version and your own layers. */
103
+ async setTheme(theme) {
104
+ if (this.disposed || theme === this.theme)
105
+ return;
106
+ this.theme = theme;
107
+ const url = styleUrl(this.options.tilesBaseUrl.replace(/\/$/, ''), this.published, theme, this.options);
108
+ // `diff: false` because the two documents share no layer ids worth
109
+ // reconciling; a full swap is both faster and more predictable.
110
+ this.map.setStyle(url, { diff: false });
111
+ await new Promise((resolve) => this.map.once('styledata', () => resolve()));
112
+ }
113
+ /** The theme currently painted. */
114
+ get currentTheme() {
115
+ return this.theme;
116
+ }
117
+ /**
118
+ * The style document as the service built it, for callers that want to read
119
+ * `metadata` or insert their own layers at a particular point.
120
+ */
121
+ get style() {
122
+ return this.map.getStyle();
123
+ }
124
+ /** Stop timers and release the map. Safe to call twice. */
125
+ destroy() {
126
+ if (this.disposed)
127
+ return;
128
+ this.disposed = true;
129
+ if (this.autoThemeTimer)
130
+ clearInterval(this.autoThemeTimer);
131
+ this.credential.dispose();
132
+ this.map.remove();
133
+ }
134
+ startAutoTheme(pair) {
135
+ // Every five minutes is far more often than needed to land the switch
136
+ // within a few minutes of civil twilight, and costs nothing.
137
+ this.autoThemeTimer = setInterval(() => {
138
+ if (this.disposed)
139
+ return;
140
+ const c = this.map.getCenter();
141
+ const want = themeFor(new Date(), c.lat, c.lng, pair);
142
+ if (want !== this.theme)
143
+ void this.setTheme(want);
144
+ }, 5 * 60 * 1000);
145
+ }
146
+ }
147
+ function resolvePair(auto) {
148
+ if (!auto)
149
+ return undefined;
150
+ return auto === true ? DEFAULT_PAIR : auto;
151
+ }
152
+ /**
153
+ * 🔴 THE EXPLICIT VERSION, NEVER THE WORD "current". Resolving `current` on
154
+ * every style request means a build publishing underneath a live page leaves
155
+ * the browser holding a style that no longer matches the squares it is
156
+ * fetching. `discover` resolved it once; everything after uses what it found.
157
+ */
158
+ function styleUrl(baseUrl, published, theme, options) {
159
+ const u = new URL(`${baseUrl}/v1/${encodeURIComponent(published.region)}/${encodeURIComponent(published.version)}/style.json`);
160
+ u.searchParams.set('flavour', theme);
161
+ if (options.pois === false)
162
+ u.searchParams.set('pois', 'false');
163
+ if (options.buildings3d === true)
164
+ u.searchParams.set('buildings3d', 'true');
165
+ return u.toString();
166
+ }
167
+ //# sourceMappingURL=map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.js","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings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AAM,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACtD,IAAI,IAAI,KAAK,IAAI,CAAC,KAAK;gBAAE,KAAK,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACpB,CAAC;CACF;AAED,SAAS,WAAW,CAAC,IAAiC;IACpD,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,SAAS,QAAQ,CACf,OAAe,EACf,SAAoB,EACpB,KAAY,EACZ,OAAuB;IAEvB,MAAM,CAAC,GAAG,IAAI,GAAG,CACf,GAAG,OAAO,OAAO,kBAAkB,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,kBAAkB,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,CAC5G,CAAC;IACF,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK;QAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChE,IAAI,OAAO,CAAC,WAAW,KAAK,IAAI;QAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAC5E,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Which theme to paint, and when to change it.
3
+ *
4
+ * The Mesh tiles service paints five: two for daylight, two for night, and one
5
+ * neutral for when the application's own data has to be the thing that stands
6
+ * out. They are requested per style document; the squares, fonts and icons are
7
+ * shared between them, so switching costs one small document and no new tile
8
+ * requests.
9
+ */
10
+ export type Theme = 'light' | 'white' | 'grayscale' | 'dark' | 'black';
11
+ export declare const DAY_THEMES: readonly Theme[];
12
+ export declare const NIGHT_THEMES: readonly Theme[];
13
+ /**
14
+ * The sun's elevation above the horizon, in degrees.
15
+ *
16
+ * ⚠️ Deliberately a small approximation rather than a dependency. It is
17
+ * accurate to well under a degree, which decides the switch within a couple of
18
+ * minutes of the exact moment — and nobody can perceive the difference, whereas
19
+ * every consumer can perceive an extra package in their bundle.
20
+ */
21
+ export declare function solarElevation(when: Date, latitude: number, longitude: number): number;
22
+ /** True when it is dark enough at this place and time to want a night theme. */
23
+ export declare function isNight(when: Date, latitude: number, longitude: number): boolean;
24
+ /**
25
+ * The theme to use right now, given the pair the caller wants to alternate
26
+ * between. Keeping both in the caller's hands matters: "dark" and "black" are
27
+ * genuinely different choices, and so are "light" and "white".
28
+ */
29
+ export declare function themeFor(when: Date, latitude: number, longitude: number, pair: {
30
+ day: Theme;
31
+ night: Theme;
32
+ }): Theme;
33
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAEvE,eAAO,MAAM,UAAU,EAAE,SAAS,KAAK,EAAuB,CAAC;AAC/D,eAAO,MAAM,YAAY,EAAE,SAAS,KAAK,EAAsB,CAAC;AAWhE;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CA2BtF;AAED,gFAAgF;AAChF,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAEhF;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GACjC,KAAK,CAEP"}
package/dist/theme.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Which theme to paint, and when to change it.
3
+ *
4
+ * The Mesh tiles service paints five: two for daylight, two for night, and one
5
+ * neutral for when the application's own data has to be the thing that stands
6
+ * out. They are requested per style document; the squares, fonts and icons are
7
+ * shared between them, so switching costs one small document and no new tile
8
+ * requests.
9
+ */
10
+ export const DAY_THEMES = ['light', 'white'];
11
+ export const NIGHT_THEMES = ['dark', 'black'];
12
+ /**
13
+ * 🔴 THE SWITCH POINT IS NOT SUNSET, AND GETTING THIS WRONG IS WORSE THAN NOT
14
+ * DOING IT AT ALL. Switching at sunset leaves someone on a bright white screen
15
+ * through the whole of dusk and then flips to night while it is still light
16
+ * outside. The usable threshold is **civil twilight** — the sun six degrees
17
+ * below the horizon — which is roughly when you would turn headlights on.
18
+ */
19
+ const CIVIL_TWILIGHT_DEGREES = -6;
20
+ /**
21
+ * The sun's elevation above the horizon, in degrees.
22
+ *
23
+ * ⚠️ Deliberately a small approximation rather than a dependency. It is
24
+ * accurate to well under a degree, which decides the switch within a couple of
25
+ * minutes of the exact moment — and nobody can perceive the difference, whereas
26
+ * every consumer can perceive an extra package in their bundle.
27
+ */
28
+ export function solarElevation(when, latitude, longitude) {
29
+ const rad = Math.PI / 180;
30
+ const dayMs = 86_400_000;
31
+ // Days since the J2000.0 epoch.
32
+ const d = when.getTime() / dayMs - 10957.5;
33
+ const meanAnomaly = (357.5291 + 0.98560028 * d) * rad;
34
+ const eclipticLongitude = (280.459 + 0.98564736 * d) * rad +
35
+ (1.915 * Math.sin(meanAnomaly) + 0.02 * Math.sin(2 * meanAnomaly)) * rad;
36
+ const obliquity = (23.439 - 0.00000036 * d) * rad;
37
+ const declination = Math.asin(Math.sin(obliquity) * Math.sin(eclipticLongitude));
38
+ const rightAscension = Math.atan2(Math.cos(obliquity) * Math.sin(eclipticLongitude), Math.cos(eclipticLongitude));
39
+ const greenwichSiderealTime = (280.16 + 360.9856235 * d) * rad;
40
+ const hourAngle = greenwichSiderealTime + longitude * rad - rightAscension;
41
+ const lat = latitude * rad;
42
+ const sinElevation = Math.sin(lat) * Math.sin(declination) +
43
+ Math.cos(lat) * Math.cos(declination) * Math.cos(hourAngle);
44
+ return Math.asin(Math.max(-1, Math.min(1, sinElevation))) / rad;
45
+ }
46
+ /** True when it is dark enough at this place and time to want a night theme. */
47
+ export function isNight(when, latitude, longitude) {
48
+ return solarElevation(when, latitude, longitude) < CIVIL_TWILIGHT_DEGREES;
49
+ }
50
+ /**
51
+ * The theme to use right now, given the pair the caller wants to alternate
52
+ * between. Keeping both in the caller's hands matters: "dark" and "black" are
53
+ * genuinely different choices, and so are "light" and "white".
54
+ */
55
+ export function themeFor(when, latitude, longitude, pair) {
56
+ return isNight(when, latitude, longitude) ? pair.night : pair.day;
57
+ }
58
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,CAAC,MAAM,UAAU,GAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/D,MAAM,CAAC,MAAM,YAAY,GAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhE;;;;;;GAMG;AACH,MAAM,sBAAsB,GAAG,CAAC,CAAC,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,IAAU,EAAE,QAAgB,EAAE,SAAiB;IAC5E,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC;IAC1B,MAAM,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AAC,WAAW,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAE9D,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAClE,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,OAAO,CAAC,IAAU,EAAE,QAAgB,EAAE,SAAiB;IACrE,OAAO,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG,sBAAsB,CAAC;AAC5E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CACtB,IAAU,EACV,QAAgB,EAChB,SAAiB,EACjB,IAAkC;IAElC,OAAO,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;AACpE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@locate2u/mesh-map",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-beta.0",
4
+ "description": "The Locate2u Mesh map control. Put a map on a page with your Mesh map key — themes, credentials, attribution and error reporting handled.",
5
+ "keywords": ["locate2u", "mesh", "map", "maplibre", "openstreetmap", "logistics", "delivery", "web-component"],
6
+ "homepage": "https://github.com/loc-mesh/sdk-map/tree/main/packages/web#readme",
7
+ "bugs": { "url": "https://github.com/loc-mesh/sdk-map/issues" },
8
+ "repository": { "type": "git", "url": "git+https://github.com/loc-mesh/sdk-map.git", "directory": "packages/web" },
9
+ "license": "MIT",
10
+ "author": "Locate2u <engineering@locate2u.com> (https://locate2u.com)",
11
+ "publisher": "Locate2u",
12
+ "type": "module",
13
+ "main": "./dist/index.js",
14
+ "module": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
18
+ "./element": { "types": "./dist/element.d.ts", "import": "./dist/element.js" }
19
+ },
20
+ "files": ["dist", "README.md", "LICENSE", "THIRD-PARTY-NOTICES.md"],
21
+ "sideEffects": ["./dist/element.js"],
22
+ "engines": { "node": ">=20" },
23
+ "scripts": {
24
+ "build": "tsc -p tsconfig.build.json",
25
+ "typecheck": "tsc -p tsconfig.json --noEmit",
26
+ "test": "vitest run",
27
+ "prepack": "npm run build",
28
+ "verify-publish": "npm pack --dry-run && npm publish --dry-run --tag beta"
29
+ },
30
+ "dependencies": {
31
+ "maplibre-gl": "^6.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^20.14.10",
35
+ "typescript": "^5.5.3",
36
+ "vitest": "^2.1.8"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "provenance": false,
41
+ "tag": "beta"
42
+ }
43
+ }