@superrouteca/sindoor 0.0.0-stage → 0.1.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
+ Superroute SDK License
2
+
3
+ Copyright (c) 2026 Superroute Inc. All rights reserved, except as granted below.
4
+
5
+ 1. Permission is granted, free of charge, to any person obtaining a copy of this software and its documentation
6
+ (the "Software") to install, use, copy and distribute the Software, including as part of their own products and
7
+ services, to connect to Superroute services, on any other platform, and in their own commercial projects.
8
+
9
+ 2. The Software may not be sold on its own, whether alone or as the main part of a product whose value lies in the
10
+ Software rather than in the product built with it.
11
+
12
+ 3. The copyright notices, this license and the attribution of the Software to Superroute may not be removed or
13
+ changed, and must be kept in every copy or substantial portion of the Software that is distributed.
14
+
15
+ 4. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
16
+ THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
18
+ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ IN THE SOFTWARE.
20
+
21
+ 5. Use of Superroute services through the Software is governed by the terms of those services.
package/README.md CHANGED
@@ -1,3 +1,31 @@
1
- # Temporary Holding Version
1
+ # @superrouteca/sindoor
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
+ Indoor routes, tours and positioning that run on the device, and a ready navigation screen on an sMap map.
4
+
5
+ ```js
6
+ import { init, SindoorClient, SindoorSite, SindoorNavigator } from '@superrouteca/sindoor';
7
+ import * as sMap from '@superrouteca/smap';
8
+
9
+ await init();
10
+ const client = new SindoorClient({ key: 'smk_…' }); // your sMap map key
11
+ const site = await SindoorSite.load({ site: 'op-12-mall', client }); // downloaded once, then offline
12
+
13
+ const map = new sMap.Map({ container: 'map', key: 'smk_…' });
14
+ const nav = await SindoorNavigator.create(map, site, { panel: document.getElementById('steps') });
15
+
16
+ const locator = site.locator();
17
+ nav.showPosition(locator.observe({ t: Date.now(), kind: 'scan', ref: 'ABCD-EFGH' })); // a scanned position code
18
+ nav.navigateTo('fixture:checkout');
19
+ ```
20
+
21
+ - **Sites**: `SindoorSite.load` downloads a site's customer form with a map key, or its full form with a token your
22
+ server gets from `POST /v1/indoor/token` with its Open Platform key. Keep `site.download` to start offline later
23
+ with `SindoorSite.fromDownload`.
24
+ - **Routes**: `site.route(from, to)` — each end a ref (`door`, `fixture:12`, a position code), `{level, x, y}` in
25
+ millimetres or `{level, lng, lat}`; `site.tour({targets})` orders a list into the shortest walk.
26
+ - **Positioning**: `site.locator()` takes steps, headings, pressure, beacons, scans and GPS fixes and answers estimates
27
+ with `lng` / `lat`.
28
+ - **Navigation screen**: `SindoorNavigator` draws the site as sMap's indoor layer with a level switcher, the blue dot,
29
+ the route and a step list (`text` translates every line).
30
+
31
+ Licence: Superroute SDK License (see LICENSE).
package/package.json CHANGED
@@ -1,6 +1,23 @@
1
1
  {
2
2
  "name": "@superrouteca/sindoor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "sIndoor SDK: indoor routes, tours and positioning on the device, and a navigation screen on sMap",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "module": "src/index.js",
8
+ "types": "types/index.d.ts",
9
+ "exports": {
10
+ ".": { "types": "./types/index.d.ts", "import": "./src/index.js" },
11
+ "./wasm/sindoor_wasm_bg.wasm": "./wasm/sindoor_wasm_bg.wasm"
12
+ },
13
+ "files": ["src", "wasm", "types", "README.md", "LICENSE"],
14
+ "sideEffects": false,
15
+ "license": "SEE LICENSE IN LICENSE",
16
+ "author": "Superroute Inc.",
17
+ "homepage": "https://open.superroute.ca/developer",
18
+ "keywords": ["indoor", "navigation", "positioning", "wayfinding", "superroute", "smap"],
19
+ "peerDependencies": { "@superrouteca/smap": ">=1.5.12" },
20
+ "peerDependenciesMeta": { "@superrouteca/smap": { "optional": true } },
21
+ "scripts": { "test": "node --test test/*.test.mjs" },
22
+ "engines": { "node": ">=18" }
23
+ }
package/src/client.js ADDED
@@ -0,0 +1,74 @@
1
+ // The Open Platform's indoor routes (DESIGN.md Part 2h, "P6 interfaces"): a site's package for the device, its layer,
2
+ // public sites, and the server calls for those who prefer them to the device engine.
3
+ import { SindoorError } from './engine.js';
4
+
5
+ export const DEFAULT_BASE_URL = 'https://open.superroute.ca/v1/indoor';
6
+
7
+ export class SindoorClient {
8
+ /**
9
+ * @param {object} o
10
+ * @param {string} [o.key] an sMap map key (smk_…): the customer form of the account's own and public sites
11
+ * @param {string} [o.token] an sIndoor token (si1.…) the developer's server got from POST /v1/indoor/token: the full form
12
+ * @param {string} [o.apiKey] an Open Platform server key — only on a server, never in an app
13
+ * @param {string} [o.baseUrl]
14
+ * @param {Function} [o.fetch]
15
+ */
16
+ constructor(o = {}) {
17
+ this.key = o.key;
18
+ this.token = o.token;
19
+ this.apiKey = o.apiKey;
20
+ this.baseUrl = (o.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, '');
21
+ this.fetch = o.fetch || globalThis.fetch?.bind(globalThis);
22
+ if (!this.fetch) throw new SindoorError('no_fetch', 'no fetch available: pass options.fetch');
23
+ }
24
+
25
+ headers() {
26
+ const h = { Accept: 'application/json' };
27
+ const bearer = this.token || this.apiKey;
28
+ if (bearer) h.Authorization = `Bearer ${bearer}`;
29
+ if (this.key) h['X-SMap-Key'] = this.key;
30
+ return h;
31
+ }
32
+
33
+ url(path, query) {
34
+ const u = new URL(this.baseUrl + path);
35
+ if (this.key && !this.token) u.searchParams.set('key', this.key);
36
+ for (const [k, v] of Object.entries(query || {})) if (v !== undefined && v !== null) u.searchParams.set(k, String(v));
37
+ return u.toString();
38
+ }
39
+
40
+ async request(method, path, { query, body } = {}) {
41
+ const headers = this.headers();
42
+ if (body !== undefined) headers['Content-Type'] = 'application/json';
43
+ const r = await this.fetch(this.url(path, query), { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
44
+ let v = null;
45
+ try {
46
+ v = await r.json();
47
+ } catch {
48
+ v = null;
49
+ }
50
+ if (!r.ok) {
51
+ const e = v?.error || {};
52
+ throw new SindoorError(e.code || `http_${r.status}`, e.message || `HTTP ${r.status}`, e.refs || []);
53
+ }
54
+ return v;
55
+ }
56
+
57
+ /** `{site, package, overlay: {revision, overlay}, live}` — the form the credentials allow (customer by default). */
58
+ package(site, form = 'customer') {
59
+ return this.request('GET', `/sites/${encodeURIComponent(site)}/package`, { query: { form } });
60
+ }
61
+
62
+ layer(site) {
63
+ return this.request('GET', `/sites/${encodeURIComponent(site)}/layer`);
64
+ }
65
+
66
+ publicSites(bbox) {
67
+ return this.request('GET', '/public-sites', { query: { bbox: bbox.join(',') } });
68
+ }
69
+
70
+ /** Server side only (an Open Platform key): a short-lived token for the full form of a site. */
71
+ issueToken(site, { form = 'full', subject, ttlS } = {}) {
72
+ return this.request('POST', '/token', { body: { site, form, subject, ttl_s: ttlS } });
73
+ }
74
+ }
package/src/engine.js ADDED
@@ -0,0 +1,54 @@
1
+ // The engine: sIndoor's Rust core built for the browser and Node (wasm-bindgen --target web), loaded once.
2
+ import * as wasm from '../wasm/sindoor_wasm.js';
3
+
4
+ let ready = null;
5
+
6
+ /**
7
+ * Load the engine. In a browser it is fetched next to this module (or from `options.url`); in Node pass the bytes
8
+ * (`options.bytes`) or let it read the file. Resolves when ready; later calls return the same promise.
9
+ */
10
+ export function init(options = {}) {
11
+ if (ready) return ready;
12
+ ready = (async () => {
13
+ if (options.bytes) {
14
+ wasm.initSync({ module: options.bytes });
15
+ return wasm;
16
+ }
17
+ if (typeof process !== 'undefined' && process.versions?.node && !options.url) {
18
+ const fs = await import('node:fs');
19
+ const url = new URL('../wasm/sindoor_wasm_bg.wasm', import.meta.url);
20
+ wasm.initSync({ module: fs.readFileSync(url) });
21
+ return wasm;
22
+ }
23
+ await wasm.default(options.url ? { module_or_path: options.url } : undefined);
24
+ return wasm;
25
+ })();
26
+ return ready;
27
+ }
28
+
29
+ export function engine() {
30
+ if (!ready) throw new SindoorError('not_ready', 'call init() first');
31
+ return wasm;
32
+ }
33
+
34
+ export function engineVersion() {
35
+ return engine().sindoorVersion();
36
+ }
37
+
38
+ export class SindoorError extends Error {
39
+ constructor(code, message, refs = []) {
40
+ super(message || code);
41
+ this.name = 'SindoorError';
42
+ this.code = code;
43
+ this.refs = refs;
44
+ }
45
+ }
46
+
47
+ /** Parse an engine answer; `{error}` becomes a SindoorError. */
48
+ export function parse(json) {
49
+ const v = JSON.parse(json);
50
+ if (v && typeof v === 'object' && v.error && typeof v.error === 'object') {
51
+ throw new SindoorError(v.error.code || 'error', v.error.message || '', v.error.refs || []);
52
+ }
53
+ return v;
54
+ }
package/src/geo.js ADDED
@@ -0,0 +1,28 @@
1
+ // Level millimetres <-> longitude / latitude through a level's anchor: the formulas of sIndoor's
2
+ // sindoor_model::outdoor (level_to_geo / geo_to_level), so the SDK, sMap's indoor layer and the engine agree.
3
+
4
+ export function mmPerDegree(lat) {
5
+ const r = (lat * Math.PI) / 180;
6
+ const latM = 111132.92 - 559.82 * Math.cos(2 * r) + 1.175 * Math.cos(4 * r);
7
+ const lonM = 111412.84 * Math.cos(r) - 93.5 * Math.cos(3 * r);
8
+ return [latM * 1000, lonM * 1000];
9
+ }
10
+
11
+ /** A level point (mm, x east, y south) → [lng, lat]. */
12
+ export function levelToLngLat(anchor, x, y) {
13
+ const [kLat, kLon] = mmPerDegree(anchor.lat);
14
+ const rot = ((anchor.rotation_deg || 0) * Math.PI) / 180;
15
+ const s = Math.sin(rot), c = Math.cos(rot), k = anchor.scale ?? 1;
16
+ const xs = x * k, ys = y * k;
17
+ const e = xs * c - ys * s, south = xs * s + ys * c;
18
+ return [anchor.lon + e / kLon, anchor.lat - south / kLat];
19
+ }
20
+
21
+ /** [lng, lat] → a level point (mm). */
22
+ export function lngLatToLevel(anchor, lng, lat) {
23
+ const [kLat, kLon] = mmPerDegree(anchor.lat);
24
+ const e = (lng - anchor.lon) * kLon, south = -(lat - anchor.lat) * kLat;
25
+ const rot = ((anchor.rotation_deg || 0) * Math.PI) / 180;
26
+ const s = Math.sin(rot), c = Math.cos(rot), k = anchor.scale ?? 1;
27
+ return [(e * c + south * s) / k, (-e * s + south * c) / k];
28
+ }
package/src/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // sIndoor SDK for the web and Node (DESIGN.md Part 2h): the indoor engine on the device (routes, tours, positioning,
2
+ // offline once a site is downloaded), the Open Platform's indoor routes, and a navigation screen on sMap.
3
+ export { init, engineVersion, SindoorError } from './engine.js';
4
+ export { SindoorClient, DEFAULT_BASE_URL } from './client.js';
5
+ export { SindoorSite, SindoorLocator } from './site.js';
6
+ export { SindoorNavigator, DEFAULT_TEXT } from './navigator.js';
7
+ export { levelToLngLat, lngLatToLevel, mmPerDegree } from './geo.js';
8
+ export const VERSION = '0.1.0';
@@ -0,0 +1,172 @@
1
+ // The ready navigation screen (DESIGN.md Part 2h, IK5): a site drawn as sMap's indoor layer, a level switcher, the
2
+ // blue dot, the route line and the step list, on any sMap map (Web SDK `sMap.Map`, the contract's `addIndoor` API).
3
+ import { SindoorError } from './engine.js';
4
+
5
+ export const DEFAULT_TEXT = {
6
+ start: 'Start',
7
+ arrive: 'Arrive',
8
+ straight: 'Go straight',
9
+ slight_left: 'Bear left',
10
+ slight_right: 'Bear right',
11
+ left: 'Turn left',
12
+ right: 'Turn right',
13
+ sharp_left: 'Turn sharp left',
14
+ sharp_right: 'Turn sharp right',
15
+ u_turn: 'Turn around',
16
+ connector: 'Change level',
17
+ level: 'Level',
18
+ metres: '{n} m',
19
+ no_route: 'No walking route to this place.',
20
+ };
21
+
22
+ const fmt = (t, vars) => t.replace(/\{(\w+)\}/g, (_, k) => (vars[k] ?? ''));
23
+
24
+ export class SindoorNavigator {
25
+ /**
26
+ * @param {object} map an sMap map (the Web SDK's sMap.Map)
27
+ * @param {import('./site.js').SindoorSite} site
28
+ * @param {object} [o]
29
+ * @param {string} [o.id] the indoor layer's id on the map (default `sindoor`)
30
+ * @param {boolean|object} [o.control] the level switcher (default true)
31
+ * @param {HTMLElement} [o.panel] where the step list goes (none: no list)
32
+ * @param {object} [o.text] any DEFAULT_TEXT key, for translations
33
+ * @param {string} [o.profile] movement profile (default the site's pedestrian)
34
+ * @param {string} [o.role] `customer` (default), `staff`, `delivery`, `all`
35
+ * @param {boolean} [o.follow] keep the shown level on the walker's (default true)
36
+ * @param {object} [o.colors] {dot, accuracy, route}
37
+ */
38
+ constructor(map, site, o = {}) {
39
+ if (!map || typeof map.addIndoor !== 'function') throw new SindoorError('no_indoor_layer', 'this sMap map has no indoor layer (needs the sMap SDK with addIndoor)');
40
+ this.map = map;
41
+ this.site = site;
42
+ this.o = { id: 'sindoor', control: true, role: 'customer', follow: true, ...o };
43
+ this.text = { ...DEFAULT_TEXT, ...(o.text || {}) };
44
+ this.colors = { dot: '#1a73e8', accuracy: 'rgba(26,115,232,0.15)', route: '#1a73e8', ...(o.colors || {}) };
45
+ this.position = null;
46
+ this.routeResult = null;
47
+ this._routeLayers = [];
48
+ this._onLevel = (e) => {
49
+ if (e?.id === this.o.id) this._redrawDot();
50
+ };
51
+ /** Resolves once the map has the site (sMap's addIndoor waits for its data); `create()` waits for it. */
52
+ this.ready = Promise.resolve(map.addIndoor(this.o.id, { geojson: site.layer() }, { control: this.o.control, level: this.o.level })).then(() => this);
53
+ map.on?.('indoorlevelchange', this._onLevel);
54
+ }
55
+
56
+ /** A navigator once the map has drawn the site. */
57
+ static async create(map, site, o = {}) {
58
+ return new SindoorNavigator(map, site, o).ready;
59
+ }
60
+
61
+ get level() {
62
+ return this.map.getIndoorLevel(this.o.id);
63
+ }
64
+
65
+ setLevel(level) {
66
+ this.map.setIndoorLevel(this.o.id, level);
67
+ }
68
+
69
+ /** Show where the walker is: an estimate of a SindoorLocator (`{level, x, y, acc_mm}`, lng / lat added). */
70
+ showPosition(e) {
71
+ this.position = e || null;
72
+ if (e && this.o.follow && e.level !== this.level) this.setLevel(e.level);
73
+ this._redrawDot();
74
+ }
75
+
76
+ _redrawDot() {
77
+ const id = `${this.o.id}-me`;
78
+ try {
79
+ this.map.removeLayer(id);
80
+ } catch {
81
+ /* not there yet */
82
+ }
83
+ try {
84
+ this.map.removeLayer(`${id}-acc`);
85
+ } catch {
86
+ /* not there yet */
87
+ }
88
+ const e = this.position;
89
+ if (!e) return;
90
+ const [lng, lat] = this.site.toLngLat(e.level, e.x, e.y);
91
+ const indoor = { id: this.o.id, level: e.level };
92
+ if (this.map.addCircles && e.acc_mm) {
93
+ this.map.addCircles(`${id}-acc`, [{ lng, lat, radius: e.acc_mm / 1000 }], { color: this.colors.accuracy, indoor });
94
+ }
95
+ this.map.addPoints(id, [{ lng, lat }], { color: this.colors.dot, radius: 7, strokeColor: '#ffffff', strokeWidth: 2, indoor });
96
+ }
97
+
98
+ /** Walk to a target (a ref such as `fixture:12`, `{level, x, y}` or `{lng, lat, level}`) from the shown position (or
99
+ * `from`); draws the route and fills the step list. Resolves to the engine's route. */
100
+ navigateTo(target, { from } = {}) {
101
+ const start = from ?? (this.position ? { level: this.position.level, x: this.position.x, y: this.position.y } : null);
102
+ if (!start) throw new SindoorError('no_position', 'no position yet: pass from or call showPosition first');
103
+ let r;
104
+ try {
105
+ r = this.site.route(start, target, { role: this.o.role, profile: this.o.profile });
106
+ } catch (e) {
107
+ this.clearRoute();
108
+ this._panel([{ text: this.text.no_route }]);
109
+ throw e;
110
+ }
111
+ this.showRoute(r);
112
+ return r;
113
+ }
114
+
115
+ /** Draw an engine route (`{legs: [{level, polyline}], steps}`) and its steps. */
116
+ showRoute(r) {
117
+ this.clearRoute();
118
+ this.routeResult = r;
119
+ (r.legs || []).forEach((leg, i) => {
120
+ const id = `${this.o.id}-route-${i}`;
121
+ const coords = leg.polyline.map(([x, y]) => this.site.toLngLat(leg.level, x, y));
122
+ this.map.addLines(id, { type: 'Feature', geometry: { type: 'LineString', coordinates: coords }, properties: {} }, { color: this.colors.route, width: 5, indoor: { id: this.o.id, level: leg.level } });
123
+ this._routeLayers.push(id);
124
+ });
125
+ this._panel(this.steps(r));
126
+ }
127
+
128
+ /** The route's steps as text lines `[{kind, level, text, distance_mm}]` (also what the step list shows). */
129
+ steps(r = this.routeResult) {
130
+ return (r?.steps || []).map((s) => {
131
+ const what = this.text[s.kind] ?? s.kind;
132
+ const dist = s.distance_mm > 0 ? ' · ' + fmt(this.text.metres, { n: Math.round(s.distance_mm / 1000) }) : '';
133
+ return { kind: s.kind, level: s.level, distance_mm: s.distance_mm, text: `${what}${dist}` };
134
+ });
135
+ }
136
+
137
+ clearRoute() {
138
+ for (const id of this._routeLayers) {
139
+ try {
140
+ this.map.removeLayer(id);
141
+ } catch {
142
+ /* gone */
143
+ }
144
+ }
145
+ this._routeLayers = [];
146
+ this.routeResult = null;
147
+ this._panel([]);
148
+ }
149
+
150
+ _panel(lines) {
151
+ const p = this.o.panel;
152
+ if (!p || typeof document === 'undefined') return;
153
+ p.replaceChildren();
154
+ const ol = document.createElement('ol');
155
+ ol.className = 'sindoor-steps';
156
+ for (const l of lines) {
157
+ const li = document.createElement('li');
158
+ li.textContent = l.text;
159
+ if (l.level) li.dataset.level = l.level;
160
+ ol.appendChild(li);
161
+ }
162
+ p.appendChild(ol);
163
+ }
164
+
165
+ destroy() {
166
+ this.clearRoute();
167
+ this.position = null;
168
+ this._redrawDot();
169
+ this.map.off?.('indoorlevelchange', this._onLevel);
170
+ this.map.removeIndoor(this.o.id);
171
+ }
172
+ }
package/src/site.js ADDED
@@ -0,0 +1,141 @@
1
+ // A site on the device: downloaded once (or from a cache), compiled by the engine, routed and positioned offline.
2
+ import { engine, parse, SindoorError } from './engine.js';
3
+ import { levelToLngLat, lngLatToLevel } from './geo.js';
4
+
5
+ export class SindoorSite {
6
+ constructor(inner, download) {
7
+ this._inner = inner;
8
+ /** What was downloaded (`{site, package, overlay, live}`), for a cache: `SindoorSite.fromDownload(site.download)`. */
9
+ this.download = download;
10
+ this._layer = null;
11
+ }
12
+
13
+ /** Download a site's package through a SindoorClient and compile it here. */
14
+ static async load({ site, client, form = 'customer' }) {
15
+ if (!client) throw new SindoorError('no_client', 'pass a SindoorClient');
16
+ return SindoorSite.fromDownload(await client.package(site, form));
17
+ }
18
+
19
+ /** A site from a download kept earlier (offline). */
20
+ static fromDownload(d) {
21
+ if (!d || !d.package) throw new SindoorError('bad_download', 'expected {package, overlay, live}');
22
+ const w = engine();
23
+ const ov = d.overlay?.overlay ?? d.overlay ?? {};
24
+ const rev = d.overlay?.revision ?? 0;
25
+ let inner;
26
+ try {
27
+ inner = w.Site.fromPackageWithLive(JSON.stringify(d.package), JSON.stringify(ov), JSON.stringify(d.live || []), rev);
28
+ } catch (e) {
29
+ throw new SindoorError('invalid_site', String(e?.message || e));
30
+ }
31
+ return new SindoorSite(inner, d);
32
+ }
33
+
34
+ /** A site package with no overlay (e.g. a file the developer ships with the app). */
35
+ static fromPackage(pkg, overlay = {}, live = [], revision = 0) {
36
+ return SindoorSite.fromDownload({ package: pkg, overlay: { revision, overlay }, live });
37
+ }
38
+
39
+ get id() {
40
+ return this.download?.site ?? this.download?.package?.site?.id;
41
+ }
42
+
43
+ get version() {
44
+ return this._inner.version();
45
+ }
46
+
47
+ /** Walk from → to; each end a ref (`door`, `fixture:12`), `{level, x, y}` (mm) or `{lng, lat, level}`. */
48
+ route(from, to, options = {}) {
49
+ return parse(this._inner.routeJson(JSON.stringify({ from: this.toEngine(from), to: this.toEngine(to), ...options })));
50
+ }
51
+
52
+ /** A list of targets in the shortest order (IV13): `{targets, start?, end?}`. */
53
+ tour(request) {
54
+ return parse(this._inner.tourJson(JSON.stringify(request)));
55
+ }
56
+
57
+ /** From a parking point / delivery point (IV5). */
58
+ approach(request = {}) {
59
+ return parse(this._inner.approachJson(JSON.stringify(request)));
60
+ }
61
+
62
+ levels() {
63
+ return parse(this._inner.levelsJson()).levels;
64
+ }
65
+
66
+ /** The indoor layer's GeoJSON — what sMap's `addIndoor` draws. */
67
+ layer() {
68
+ if (!this._layer) this._layer = parse(this._inner.layerJson());
69
+ return this._layer;
70
+ }
71
+
72
+ anchor(level) {
73
+ const l = this.layer().levels.find((x) => x.id === level);
74
+ if (!l) throw new SindoorError('unknown_level', `no level ${level}`, [level]);
75
+ return l.anchor;
76
+ }
77
+
78
+ /** Level mm → [lng, lat]. */
79
+ toLngLat(level, x, y) {
80
+ return levelToLngLat(this.anchor(level), x, y);
81
+ }
82
+
83
+ /** [lng, lat] on a level → {level, x, y} mm. */
84
+ fromLngLat(level, lng, lat) {
85
+ const [x, y] = lngLatToLevel(this.anchor(level), lng, lat);
86
+ return { level, x: Math.round(x), y: Math.round(y) };
87
+ }
88
+
89
+ toEngine(p) {
90
+ if (p && typeof p === 'object' && 'lng' in p && 'lat' in p) {
91
+ return this.fromLngLat(p.level, p.lng, p.lat);
92
+ }
93
+ if (p && typeof p === 'object' && 'x' in p && 'y' in p) return { x: Math.round(p.x), y: Math.round(p.y), level: p.level };
94
+ return p;
95
+ }
96
+
97
+ /** A positioning filter running here (steps, heading, pressure, beacons, scans, GPS → estimates). */
98
+ locator(config = {}) {
99
+ return new SindoorLocator(this, config);
100
+ }
101
+
102
+ dispose() {
103
+ this._inner?.free();
104
+ this._inner = null;
105
+ }
106
+ }
107
+
108
+ export class SindoorLocator {
109
+ constructor(site, config) {
110
+ this.site = site;
111
+ this._inner = new (engine().Locator)(site._inner, JSON.stringify(config));
112
+ this.last = null;
113
+ }
114
+
115
+ /** One observation or a list (`{t, kind, …}` as the engine takes them) → the estimate `{x, y, level, acc_mm, at}`
116
+ * with `lng` / `lat` added, or null before the first fix. */
117
+ observe(obs) {
118
+ const e = parse(this._inner.observe(JSON.stringify(obs)));
119
+ if (e && e.level !== undefined) {
120
+ const [lng, lat] = this.site.toLngLat(e.level, e.x, e.y);
121
+ e.lng = lng;
122
+ e.lat = lat;
123
+ }
124
+ if (e) this.last = e;
125
+ return e;
126
+ }
127
+
128
+ /** `{step_scale, features}` — keep `step_scale` per person on the device and pass it back in the config. */
129
+ state() {
130
+ return parse(this._inner.state());
131
+ }
132
+
133
+ setCalibration(calibration) {
134
+ return parse(this._inner.setCalibration(JSON.stringify(calibration)));
135
+ }
136
+
137
+ dispose() {
138
+ this._inner?.free();
139
+ this._inner = null;
140
+ }
141
+ }