@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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Locate2u
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,148 @@
1
- # Temporary Holding Version
1
+ # @locate2u/mesh-map
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Put a map on a page.** The map control for the [Locate2u Mesh](https://locate2u.com) platform — Locate2u serves its own map imagery from OpenStreetMap data, and this draws it.
4
+
5
+ ```bash
6
+ npm install @locate2u/mesh-map
7
+ ```
8
+
9
+ > 🚧 **Beta.** Published under the `beta` tag while the interface settles. Pin an exact version until this reaches 1.0.
10
+
11
+ ## The smallest thing that works
12
+
13
+ ```html
14
+ <script type="module">
15
+ import '@locate2u/mesh-map/element';
16
+ </script>
17
+
18
+ <mesh-map
19
+ tiles-base-url="https://tiles-api.mesh.locate2u.app"
20
+ map-key="mk_live_your_key"
21
+ center="153.0251,-27.4698"
22
+ zoom="14"
23
+ style="display:block; height:400px"
24
+ ></mesh-map>
25
+ ```
26
+
27
+ That is the whole integration. It works in React, Vue, Angular, Svelte and a plain HTML file, because it is a custom element rather than a framework component.
28
+
29
+ ⚠️ **Give it a height.** The element has none of its own, and a map in a zero-pixel box looks like a page that failed to load while reporting nothing.
30
+
31
+ ## Or in code
32
+
33
+ ```js
34
+ import { MeshMap } from '@locate2u/mesh-map';
35
+
36
+ const map = await MeshMap.create({
37
+ container: 'map',
38
+ tilesBaseUrl: 'https://tiles-api.mesh.locate2u.app',
39
+ mapKey: 'mk_live_your_key',
40
+ center: [153.0251, -27.4698],
41
+ zoom: 14,
42
+ theme: 'light',
43
+ onError: (e) => console.warn(e.code, e.message),
44
+ });
45
+
46
+ // Anything this control does not wrap, reach through to MapLibre for:
47
+ map.map.addSource('my-route', { type: 'geojson', data: myLineString });
48
+ ```
49
+
50
+ ## Themes
51
+
52
+ Five, painted by the service: `light` and `white` for daylight, `dark` and `black` for night, and `grayscale` for when your own data has to be the thing that stands out.
53
+
54
+ ```js
55
+ await map.setTheme('dark');
56
+ ```
57
+
58
+ Switching costs one small document and **no new tile requests** — the squares, fonts and icons are shared between themes.
59
+
60
+ ### Day and night, automatically
61
+
62
+ ```js
63
+ MeshMap.create({ ..., autoTheme: { day: 'light', night: 'black' } });
64
+ ```
65
+
66
+ ⚠️ **It switches at civil twilight, not at sunset.** Sunset leaves a driver on a bright white screen through the whole of dusk and then flips to night while it is still light outside. The threshold is the sun six degrees below the horizon — roughly when you would turn headlights on.
67
+
68
+ ## Credentials
69
+
70
+ A **map key** is safe in front-end code: it is origin-locked, issued per tenant, and revocable.
71
+
72
+ ```js
73
+ MeshMap.create({ ..., mapKey: 'mk_live_...' });
74
+ ```
75
+
76
+ A **map token** is short-lived — four hours by default — and is minted by *your* backend:
77
+
78
+ ```js
79
+ MeshMap.create({
80
+ ...,
81
+ getMapToken: async () => {
82
+ const r = await fetch('/api/my-backend/map-token');
83
+ return r.json(); // { token, expiresAt }
84
+ },
85
+ });
86
+ ```
87
+
88
+ 🔴 **Never mint a map token in the browser.** Minting needs a Mesh bearer token, and a bearer token in front-end code is a credential leak.
89
+
90
+ This package refreshes a token at 80% of its life, so a map does not go blank part-way through a shift. That is most of the reason to use it rather than forty lines of your own.
91
+
92
+ ## Knowing why a map is blank
93
+
94
+ 🔴 **Almost every map failure answers HTTP 200.** A grey rectangle looks identical to an empty ocean, the page does not crash, and the console stays quiet. So this control always reports a cause:
95
+
96
+ ```js
97
+ onError: (e) => {
98
+ // e.code is one of:
99
+ // credential_rejected the key or token was refused
100
+ // module_not_enabled valid credential, Maps module not on for this tenant
101
+ // no_map_data nothing published for this environment
102
+ // discovery_failed could not ask the service what it serves
103
+ // tile_unreadable a square arrived and could not be parsed
104
+ // quota_exceeded over the allowance for this period
105
+ // token_refresh_failed the map will go dark when the current token expires
106
+ // e.fatal says whether the map is still usable.
107
+ }
108
+ ```
109
+
110
+ Credentials are stripped from every error before it reaches you.
111
+
112
+ With the custom element, the same thing arrives as a DOM event:
113
+
114
+ ```js
115
+ document.addEventListener('mesh-map-error', (e) => console.warn(e.detail.code));
116
+ ```
117
+
118
+ ## Options
119
+
120
+ | Option | Attribute | Default | |
121
+ |---|---|---|---|
122
+ | `tilesBaseUrl` | `tiles-base-url` | — | Tiles service origin, **no path** |
123
+ | `mapKey` | `map-key` | — | Or use `getMapToken` |
124
+ | `getMapToken` | — | — | Mint a short-lived token from your backend |
125
+ | `center` | `center` | `0,0` | `[lng, lat]` in code; `"lng,lat"` as an attribute |
126
+ | `zoom` / `pitch` / `bearing` | same | `11` / `0` / `0` | |
127
+ | `theme` | `theme` | `light` | One of the five |
128
+ | `autoTheme` | `auto-theme` | off | Day/night at civil twilight |
129
+ | `pois` | `pois` | `true` | Shop and café labels |
130
+ | `buildings3d` | `buildings-3d` | `false` | Needs tilt and zoom 14+ |
131
+ | `region` | `region` | first published | Pin to a named region |
132
+ | `onError` | — | logs | Strongly recommended |
133
+
134
+ ## What this package does not do
135
+
136
+ It knows nothing about stops, runs, drivers or any other Mesh resource, and it never fetches one. **Hand it geometry and it draws it.**
137
+
138
+ That boundary is deliberate: Locate2u Mesh is a platform rather than a product, and a control that fetched your runs for you would be shipping product. Recipes for drawing Mesh data on this map live in the Mesh developer documentation, where you copy them and own them.
139
+
140
+ ## Attribution
141
+
142
+ The map is OpenStreetMap data under the Open Database Licence, and the credit is a **licence condition** that has to reach the person looking at the map. This control enables MapLibre's attribution control and gives you no way to switch it off. It may be collapsed behind the small information icon, which is the default here.
143
+
144
+ See [THIRD-PARTY-NOTICES.md](./THIRD-PARTY-NOTICES.md).
145
+
146
+ ## Licence
147
+
148
+ MIT. Built and maintained by [Locate2u](https://locate2u.com).
@@ -0,0 +1,61 @@
1
+ # Third-party notices
2
+
3
+ What this package depends on, what those dependencies are licensed under, and
4
+ what we owe each of them.
5
+
6
+ ⚠️ **Permissive is not obligation-free.** BSD-2-Clause, BSD-3-Clause, MIT and
7
+ ISC all require the copyright notice and licence text to be retained in
8
+ redistributions. Where a consumer installs a dependency transitively through
9
+ npm it arrives with its own `LICENSE` file and the obligation is discharged by
10
+ the registry. **If a build ever bundles or vendors one of these into our own
11
+ artifact, its notice must ship inside that artifact** — which is why this file
12
+ exists from the first commit rather than from the day someone remembers.
13
+
14
+ ## Direct dependency
15
+
16
+ | Package | Licence | Why we depend on it |
17
+ |---|---|---|
18
+ | [`maplibre-gl`](https://github.com/maplibre/maplibre-gl-js) | BSD-3-Clause | Renders the map. ⚠️ **MapLibre, never Mapbox GL JS v2 or later** — the latter requires a billed Mapbox account even when pointed at our own tiles, which would defeat the entire point of self-hosting the map. Pinned by `loc-mesh/design` ADR 0039. |
19
+
20
+ ## Transitive dependencies
21
+
22
+ Audited 2026-10-16 across the whole declared tree of `maplibre-gl` 6.x. **No
23
+ copyleft or share-alike licence appears anywhere** — no GPL, LGPL, AGPL, MPL or
24
+ SSPL.
25
+
26
+ | Licence | Packages |
27
+ |---|---|
28
+ | ISC | `earcut`, `kdbush`, `potpack`, `tinyqueue`, `quickselect`, `@maplibre/geojson-vt`, `@mapbox/point-geometry`, `@maplibre/maplibre-gl-style-spec` |
29
+ | MIT | `bidi-js`, `gl-matrix`, `murmurhash-js`, `@types/geojson`, `@maplibre/vt-pbf` |
30
+ | BSD-3-Clause | `maplibre-gl`, `pbf`, `@mapbox/vector-tile` |
31
+ | BSD-2-Clause | `@mapbox/tiny-sdf`, `@mapbox/unitbezier` |
32
+ | MIT OR Apache-2.0 | `@maplibre/mlt` |
33
+
34
+ ## Map data
35
+
36
+ The map itself is **OpenStreetMap** data, served by Locate2u Mesh under the
37
+ [Open Database Licence](https://opendatacommons.org/licenses/odbl/).
38
+
39
+ 🔴 **The credit is a licence condition, not a courtesy, and it must reach the
40
+ person looking at the map.** This package therefore enables MapLibre's
41
+ attribution control and does not expose a way to switch it off. It may be
42
+ collapsed behind the small information icon — the OpenStreetMap Foundation's
43
+ guidelines permit that, provided it stays reachable — which is why compact mode
44
+ is the default presentation rather than a hidden one.
45
+
46
+ ## Cartography
47
+
48
+ The map's styling comes from
49
+ [`@protomaps/basemaps`](https://github.com/protomaps/basemaps) (BSD-3-Clause).
50
+ It is **not** a dependency of this package: the style document is built and
51
+ served by the Mesh tiles service, so this package receives finished cartography
52
+ over HTTP rather than generating it. OpenMapTiles was rejected for the role
53
+ because its CC-BY terms would force a second visible credit line
54
+ (`loc-mesh/design` ADR 0037).
55
+
56
+ ## Adding a dependency
57
+
58
+ A new runtime dependency is added **together with its licence, verified from
59
+ the registry rather than assumed, in the same change**. A dependency whose
60
+ licence is copyleft, share-alike, source-available or unstated is refused until
61
+ the owner rules on it. Pinned by `loc-mesh/design` ADR 0059 §5.
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Getting a credential onto every request the map library makes.
3
+ *
4
+ * 🔴 A MAP LIBRARY FETCHES ITS OWN TILES, AND YOU CANNOT GIVE THOSE REQUESTS A
5
+ * HEADER. It reads a style document and then generates hundreds of requests for
6
+ * squares, fonts and icons on its own. There is no interception point where an
7
+ * `Authorization` header can be attached, which is why the credential travels
8
+ * in the URL and why every consumer that wires this by hand writes the same
9
+ * `transformRequest` hook.
10
+ *
11
+ * 🔴 AND A MAP TOKEN EXPIRES WHILE SOMEONE IS LOOKING AT THE MAP. Tokens are
12
+ * short-lived by design — four hours by default. Nothing in a naive integration
13
+ * refreshes them, so a driver's map goes blank part-way through a shift, with
14
+ * no error anyone sees and no action that brings it back except reloading the
15
+ * page. Handling that is not a nicety; it is most of the reason to use a
16
+ * package instead of forty lines of your own.
17
+ */
18
+ import { type MeshMapError } from './errors.js';
19
+ export interface MintedToken {
20
+ token: string;
21
+ /** ISO 8601. Used to schedule the refresh; a missing value is treated as one hour. */
22
+ expiresAt?: string;
23
+ }
24
+ export type TokenMinter = () => Promise<MintedToken>;
25
+ /**
26
+ * Holds whichever credential the caller supplied and keeps it current.
27
+ *
28
+ * A map key never changes and needs none of this. A minted token does, and the
29
+ * two are deliberately the same interface to the rest of the package so nothing
30
+ * downstream has to care which it was given.
31
+ */
32
+ export declare class Credential {
33
+ private readonly minter;
34
+ private readonly onError;
35
+ private value;
36
+ private timer;
37
+ private stopped;
38
+ private constructor();
39
+ static fromKey(key: string, onError: (e: MeshMapError) => void): Credential;
40
+ static fromMinter(minter: TokenMinter, onError: (e: MeshMapError) => void): Promise<Credential>;
41
+ /** The current credential. Read fresh on every request, never captured. */
42
+ get current(): string;
43
+ /** Stop refreshing. Call when the map is destroyed, or the timer outlives the page's need for it. */
44
+ dispose(): void;
45
+ private schedule;
46
+ private refresh;
47
+ }
48
+ /**
49
+ * The hook that puts the credential on every generated request.
50
+ *
51
+ * ⚠️ Only on requests to the tiles service. A `transformRequest` that appends a
52
+ * credential to every URL the library touches would leak it to any third-party
53
+ * source a caller adds later.
54
+ */
55
+ export declare function transformRequest(origin: string, credential: () => string): (url: string) => {
56
+ url: string;
57
+ };
58
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;AASrD;;;;;;GAMG;AACH,qBAAa,UAAU;IAOnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAP1B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,KAAK,CAA4C;IACzD,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO;IAQP,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,IAAI,GAAG,UAAU;WAI9D,UAAU,CACrB,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,IAAI,GACjC,OAAO,CAAC,UAAU,CAAC;IAOtB,2EAA2E;IAC3E,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,qGAAqG;IACrG,OAAO,IAAI,IAAI;IAMf,OAAO,CAAC,QAAQ;YASF,OAAO;CAqBtB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,MAAM,IAC/D,KAAK,MAAM,KAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAWtC"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Getting a credential onto every request the map library makes.
3
+ *
4
+ * 🔴 A MAP LIBRARY FETCHES ITS OWN TILES, AND YOU CANNOT GIVE THOSE REQUESTS A
5
+ * HEADER. It reads a style document and then generates hundreds of requests for
6
+ * squares, fonts and icons on its own. There is no interception point where an
7
+ * `Authorization` header can be attached, which is why the credential travels
8
+ * in the URL and why every consumer that wires this by hand writes the same
9
+ * `transformRequest` hook.
10
+ *
11
+ * 🔴 AND A MAP TOKEN EXPIRES WHILE SOMEONE IS LOOKING AT THE MAP. Tokens are
12
+ * short-lived by design — four hours by default. Nothing in a naive integration
13
+ * refreshes them, so a driver's map goes blank part-way through a shift, with
14
+ * no error anyone sees and no action that brings it back except reloading the
15
+ * page. Handling that is not a nicety; it is most of the reason to use a
16
+ * package instead of forty lines of your own.
17
+ */
18
+ import { classify } from './errors.js';
19
+ /** Refresh at 80% of the token's life — early enough to absorb a slow mint. */
20
+ const REFRESH_AT = 0.8;
21
+ /** Never schedule further out than this, so a wrong clock cannot park a refresh for a week. */
22
+ const MAX_DELAY_MS = 60 * 60 * 1000;
23
+ /** Nor sooner than this, so a bad `expiresAt` cannot spin. */
24
+ const MIN_DELAY_MS = 30 * 1000;
25
+ /**
26
+ * Holds whichever credential the caller supplied and keeps it current.
27
+ *
28
+ * A map key never changes and needs none of this. A minted token does, and the
29
+ * two are deliberately the same interface to the rest of the package so nothing
30
+ * downstream has to care which it was given.
31
+ */
32
+ export class Credential {
33
+ minter;
34
+ onError;
35
+ value;
36
+ timer;
37
+ stopped = false;
38
+ constructor(value, minter, onError) {
39
+ this.minter = minter;
40
+ this.onError = onError;
41
+ this.value = value;
42
+ }
43
+ static fromKey(key, onError) {
44
+ return new Credential(key, undefined, onError);
45
+ }
46
+ static async fromMinter(minter, onError) {
47
+ const first = await minter();
48
+ const c = new Credential(first.token, minter, onError);
49
+ c.schedule(first.expiresAt);
50
+ return c;
51
+ }
52
+ /** The current credential. Read fresh on every request, never captured. */
53
+ get current() {
54
+ return this.value;
55
+ }
56
+ /** Stop refreshing. Call when the map is destroyed, or the timer outlives the page's need for it. */
57
+ dispose() {
58
+ this.stopped = true;
59
+ if (this.timer)
60
+ clearTimeout(this.timer);
61
+ this.timer = undefined;
62
+ }
63
+ schedule(expiresAt) {
64
+ if (!this.minter || this.stopped)
65
+ return;
66
+ const expiry = expiresAt ? Date.parse(expiresAt) : Number.NaN;
67
+ const lifetime = Number.isFinite(expiry) ? expiry - Date.now() : 60 * 60 * 1000;
68
+ const delay = Math.min(MAX_DELAY_MS, Math.max(MIN_DELAY_MS, lifetime * REFRESH_AT));
69
+ this.timer = setTimeout(() => void this.refresh(), delay);
70
+ }
71
+ async refresh() {
72
+ if (this.stopped || !this.minter)
73
+ return;
74
+ try {
75
+ const next = await this.minter();
76
+ this.value = next.token;
77
+ this.schedule(next.expiresAt);
78
+ }
79
+ catch (raw) {
80
+ // ⚠️ Report, then try again rather than giving up. The current token is
81
+ // usually still valid for a while — this is a warning that the map will
82
+ // go dark later, which is a far more useful thing to say now than after.
83
+ this.onError({
84
+ ...classify(raw),
85
+ code: 'token_refresh_failed',
86
+ message: 'Could not mint a new map token. The map keeps working until the current one expires, ' +
87
+ 'and then stops drawing.',
88
+ fatal: false,
89
+ });
90
+ this.timer = setTimeout(() => void this.refresh(), MIN_DELAY_MS);
91
+ }
92
+ }
93
+ }
94
+ /**
95
+ * The hook that puts the credential on every generated request.
96
+ *
97
+ * ⚠️ Only on requests to the tiles service. A `transformRequest` that appends a
98
+ * credential to every URL the library touches would leak it to any third-party
99
+ * source a caller adds later.
100
+ */
101
+ export function transformRequest(origin, credential) {
102
+ return (url) => {
103
+ if (!url.startsWith(origin))
104
+ return { url };
105
+ const u = new URL(url);
106
+ // The style document already carries the credential on everything it
107
+ // references; only add one where it is genuinely absent, so a rotated token
108
+ // in a freshly fetched style is not overwritten by a stale closure.
109
+ if (!u.searchParams.has('key') && !u.searchParams.has('token')) {
110
+ u.searchParams.set('key', credential());
111
+ }
112
+ return { url: u.toString() };
113
+ };
114
+ }
115
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAU1D,+EAA+E;AAC/E,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,+FAA+F;AAC/F,MAAM,YAAY,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACpC,8DAA8D;AAC9D,MAAM,YAAY,GAAG,EAAE,GAAG,IAAI,CAAC;AAE/B;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IAOF;IACA;IAPX,KAAK,CAAS;IACd,KAAK,CAA4C;IACjD,OAAO,GAAG,KAAK,CAAC;IAExB,YACE,KAAa,EACI,MAA+B,EAC/B,OAAkC;QADlC,WAAM,GAAN,MAAM,CAAyB;QAC/B,YAAO,GAAP,OAAO,CAA2B;QAEnD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,GAAW,EAAE,OAAkC;QAC5D,OAAO,IAAI,UAAU,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,UAAU,CACrB,MAAmB,EACnB,OAAkC;QAElC,MAAM,KAAK,GAAG,MAAM,MAAM,EAAE,CAAC;QAC7B,MAAM,CAAC,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACvD,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC5B,OAAO,CAAC,CAAC;IACX,CAAC;IAED,2EAA2E;IAC3E,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,qGAAqG;IACrG,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AAO,CAAC;gBACX,GAAG,QAAQ,CAAC,GAAG,CAAC;gBAChB,IAAI,EAAE,sBAAsB;gBAC5B,OAAO,EACL,uFAAuF;oBACvF,yBAAyB;gBAC3B,KAAK,EAAE,KAAK;aACb,CAAC,CAAC;YACH,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc,EAAE,UAAwB;IACvE,OAAO,CAAC,GAAW,EAAmB,EAAE;QACtC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,OAAO,EAAE,GAAG,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,qEAAqE;QACrE,4EAA4E;QAC5E,oEAAoE;QACpE,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/D,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Finding out what this environment can actually serve.
3
+ *
4
+ * 🔴 WHY THIS IS NOT A CONSTANT. Every map address is
5
+ * `/v1/<region>/<version>/…`, and both segments come from whatever the map
6
+ * pipeline last published. They cannot be guessed, they differ per
7
+ * environment, and they change when a new build lands.
8
+ *
9
+ * ⚠️ AND THE SERVICE'S CONTRACT DOES NOT DESCRIBE THE SHAPE OF THE ANSWER. The
10
+ * OpenAPI document types `GET /api` as a bare `object`, while its prose insists
11
+ * the fields in it are unguessable. An application built against Mesh on
12
+ * 2026-10-16 responded to that, entirely reasonably, by shipping a forty-line
13
+ * recursive crawler that walked four levels deep looking for any key matching
14
+ * /region/i with five fallback field names. Doing that once, here, is the
15
+ * difference between this package existing and not.
16
+ */
17
+ export interface Published {
18
+ region: string;
19
+ /** The explicit build version, never the word "current" — see `pin`. */
20
+ version: string;
21
+ /** Themes this service says it can paint, straight from the service. */
22
+ themes: string[];
23
+ }
24
+ /**
25
+ * Ask the service what it has, and pin to it.
26
+ *
27
+ * 🔴 PINNING IS THE POINT, NOT AN OPTIMISATION. Asking for `current` on every
28
+ * request means that when a new build publishes underneath a live page, the
29
+ * style a browser already holds stops matching the squares it is still
30
+ * fetching. Resolve `current` ONCE, keep the explicit version for the life of
31
+ * the session, and the map a user is looking at stays internally consistent
32
+ * however many builds land while they look at it.
33
+ */
34
+ export declare function discover(baseUrl: string, opts?: {
35
+ region?: string;
36
+ fetchImpl?: typeof fetch;
37
+ }): Promise<Published>;
38
+ //# sourceMappingURL=discovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAOD;;;;;;;;;GASG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,MAAM,EACf,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;CAAO,GACvD,OAAO,CAAC,SAAS,CAAC,CAsDpB"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Finding out what this environment can actually serve.
3
+ *
4
+ * 🔴 WHY THIS IS NOT A CONSTANT. Every map address is
5
+ * `/v1/<region>/<version>/…`, and both segments come from whatever the map
6
+ * pipeline last published. They cannot be guessed, they differ per
7
+ * environment, and they change when a new build lands.
8
+ *
9
+ * ⚠️ AND THE SERVICE'S CONTRACT DOES NOT DESCRIBE THE SHAPE OF THE ANSWER. The
10
+ * OpenAPI document types `GET /api` as a bare `object`, while its prose insists
11
+ * the fields in it are unguessable. An application built against Mesh on
12
+ * 2026-10-16 responded to that, entirely reasonably, by shipping a forty-line
13
+ * recursive crawler that walked four levels deep looking for any key matching
14
+ * /region/i with five fallback field names. Doing that once, here, is the
15
+ * difference between this package existing and not.
16
+ */
17
+ import { classify } from './errors.js';
18
+ /**
19
+ * Ask the service what it has, and pin to it.
20
+ *
21
+ * 🔴 PINNING IS THE POINT, NOT AN OPTIMISATION. Asking for `current` on every
22
+ * request means that when a new build publishes underneath a live page, the
23
+ * style a browser already holds stops matching the squares it is still
24
+ * fetching. Resolve `current` ONCE, keep the explicit version for the life of
25
+ * the session, and the map a user is looking at stays internally consistent
26
+ * however many builds land while they look at it.
27
+ */
28
+ export async function discover(baseUrl, opts = {}) {
29
+ const doFetch = opts.fetchImpl ?? fetch;
30
+ let body;
31
+ try {
32
+ const res = await doFetch(`${baseUrl.replace(/\/$/, '')}/api`, {
33
+ headers: { accept: 'application/json' },
34
+ });
35
+ if (!res.ok) {
36
+ throw Object.assign(new Error(`the tiles service answered ${res.status}`), {
37
+ status: res.status,
38
+ });
39
+ }
40
+ body = (await res.json());
41
+ }
42
+ catch (raw) {
43
+ const err = {
44
+ ...classify(raw),
45
+ code: 'discovery_failed',
46
+ message: `Could not ask ${baseUrl} what map data it has. Check the base URL — it should be the ` +
47
+ `tiles service origin, with no path.`,
48
+ fatal: true,
49
+ };
50
+ throw err;
51
+ }
52
+ const rows = Array.isArray(body.regions) ? body.regions : [];
53
+ const wanted = opts.region
54
+ ? rows.find((r) => String(r.region) === opts.region)
55
+ : rows[0];
56
+ if (!wanted || typeof wanted.region !== 'string' || typeof wanted.currentVersion !== 'string') {
57
+ const available = rows.map((r) => String(r.region)).filter(Boolean);
58
+ const err = {
59
+ code: 'no_map_data',
60
+ message: opts.region
61
+ ? `This environment does not serve the region "${opts.region}". It serves: ` +
62
+ `${available.join(', ') || 'nothing yet'}.`
63
+ : 'This environment has no published map data yet, so there is no region to draw.',
64
+ fatal: true,
65
+ };
66
+ throw err;
67
+ }
68
+ // Themes are read rather than hard-coded: the service is the only thing that
69
+ // knows which it can actually paint, and a list baked in here would be a
70
+ // second source of truth that goes stale on their next release.
71
+ const themes = body.themes?.available;
72
+ return {
73
+ region: wanted.region,
74
+ version: wanted.currentVersion,
75
+ themes: Array.isArray(themes) ? themes.map(String) : [],
76
+ };
77
+ }
78
+ //# sourceMappingURL=discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAe1D;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,OAAe,EACf,OAAsD,EAAE;IAExD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC;IACxC,IAAI,IAA6B,CAAC;IAElC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,EAAE;YAC7D,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;SACxC,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE;gBACzE,MAAM,EAAE,GAAG,CAAC,MAAM;aACnB,CAAC,CAAC;QACL,CAAC;QACD,I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,CAAC;QACF,MAAM,GAAG,CAAC;IACZ,CAAC;IAED,6EAA6E;IAC7E,yEAAyE;IACzE,gEAAgE;IAChE,MAAM,MAAM,GAAI,IAAI,CAAC,MAA8C,EAAE,SAAS,CAAC;IAE/E,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO,EAAE,MAAM,CAAC,cAAc;QAC9B,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;KACxD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `<mesh-map>` — the same control as a custom element.
3
+ *
4
+ * ⚠️ A CUSTOM ELEMENT RATHER THAN A REACT COMPONENT, DELIBERATELY. Custom
5
+ * elements work unchanged in React, Vue, Angular, Svelte and a plain HTML file.
6
+ * A React component would have been the easier thing to write and would have
7
+ * made every other framework a second-class citizen — which is the wrong bet
8
+ * for a platform whose customers we have never met.
9
+ *
10
+ * Importing this module registers the element. That is a side effect, declared
11
+ * as one in package.json so a bundler does not tree-shake it away.
12
+ */
13
+ import { MeshMap } from './map.js';
14
+ export declare class MeshMapElement extends HTMLElement {
15
+ /** The control, once it has finished starting. Null before that and after disconnect. */
16
+ controller: MeshMap | null;
17
+ private starting;
18
+ static get observedAttributes(): string[];
19
+ connectedCallback(): void;
20
+ disconnectedCallback(): void;
21
+ attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
22
+ private start;
23
+ /** Resolves once the map has started, so tests and callers can await it. */
24
+ whenReady(): Promise<void>;
25
+ }
26
+ //# sourceMappingURL=element.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAuB,MAAM,UAAU,CAAC;AAKxD,qBAAa,cAAe,SAAQ,WAAW;IAC7C,yFAAyF;IACzF,UAAU,EAAE,OAAO,GAAG,IAAI,CAAQ;IAClC,OAAO,CAAC,QAAQ,CAA8B;IAE9C,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAExC;IAED,iBAAiB,IAAI,IAAI;IAOzB,oBAAoB,IAAI,IAAI;IAK5B,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;YAIzE,KAAK;IAqCnB,4EAA4E;IAC5E,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAG3B"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `<mesh-map>` — the same control as a custom element.
3
+ *
4
+ * ⚠️ A CUSTOM ELEMENT RATHER THAN A REACT COMPONENT, DELIBERATELY. Custom
5
+ * elements work unchanged in React, Vue, Angular, Svelte and a plain HTML file.
6
+ * A React component would have been the easier thing to write and would have
7
+ * made every other framework a second-class citizen — which is the wrong bet
8
+ * for a platform whose customers we have never met.
9
+ *
10
+ * Importing this module registers the element. That is a side effect, declared
11
+ * as one in package.json so a bundler does not tree-shake it away.
12
+ */
13
+ import { MeshMap } from './map.js';
14
+ const NUMBER_ATTRS = ['zoom', 'pitch', 'bearing'];
15
+ export class MeshMapElement extends HTMLElement {
16
+ /** The control, once it has finished starting. Null before that and after disconnect. */
17
+ controller = null;
18
+ starting = null;
19
+ static get observedAttributes() {
20
+ return ['theme'];
21
+ }
22
+ connectedCallback() {
23
+ // The element has no height of its own; without this the map renders into a
24
+ // zero-pixel box and the page looks empty with nothing reporting a problem.
25
+ if (!this.style.display)
26
+ this.style.display = 'block';
27
+ this.starting = this.start();
28
+ }
29
+ disconnectedCallback() {
30
+ this.controller?.destroy();
31
+ this.controller = null;
32
+ }
33
+ attributeChangedCallback(name, _old, value) {
34
+ if (name === 'theme' && value && this.controller)
35
+ void this.controller.setTheme(value);
36
+ }
37
+ async start() {
38
+ const attr = (n) => this.getAttribute(n) ?? undefined;
39
+ const centre = attr('center')?.split(',').map(Number);
40
+ const options = {
41
+ container: this,
42
+ tilesBaseUrl: attr('tiles-base-url') ?? '',
43
+ mapKey: attr('map-key'),
44
+ theme: attr('theme'),
45
+ autoTheme: this.hasAttribute('auto-theme'),
46
+ pois: attr('pois') !== 'false',
47
+ buildings3d: attr('buildings-3d') === 'true',
48
+ region: attr('region'),
49
+ onError: (error) => {
50
+ // Reported as a DOM event as well as the callback, because an element
51
+ // used declaratively has nowhere to put a callback.
52
+ this.dispatchEvent(new CustomEvent('mesh-map-error', { detail: error, bubbles: true }));
53
+ if (error.fatal)
54
+ console.error(`[mesh-map] ${error.code}: ${error.message}`);
55
+ },
56
+ };
57
+ if (centre?.length === 2 && centre.every((n) => Number.isFinite(n))) {
58
+ options.center = [centre[0], centre[1]];
59
+ }
60
+ for (const n of NUMBER_ATTRS) {
61
+ const v = Number(attr(n));
62
+ if (Number.isFinite(v) && attr(n) !== undefined)
63
+ options[n] = v;
64
+ }
65
+ try {
66
+ this.controller = await MeshMap.create(options);
67
+ this.dispatchEvent(new CustomEvent('mesh-map-ready', { detail: this.controller, bubbles: true }));
68
+ }
69
+ catch {
70
+ // MeshMap.create already reported through onError above; swallowing here
71
+ // keeps an unhandled rejection out of the host application's console.
72
+ }
73
+ }
74
+ /** Resolves once the map has started, so tests and callers can await it. */
75
+ whenReady() {
76
+ return this.starting ?? Promise.resolve();
77
+ }
78
+ }
79
+ if (typeof customElements !== 'undefined' && !customElements.get('mesh-map')) {
80
+ customElements.define('mesh-map', MeshMapElement);
81
+ }
82
+ //# sourceMappingURL=element.js.map