@osm-editor-kit/osm-route-snapper 0.1.0-alpha.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/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # `@osm-editor-kit/osm-route-snapper`
2
+
3
+ **Status:** First npm **alpha** (`0.1.0-alpha.0`). Publish with `bun run packages:release -- --publish-only` after `npm login`.
4
+
5
+ ## What it does
6
+
7
+ Bridge between merged session `ParsedOsmData` (`@osm-editor-kit/osm-data`) and the [route-snapper](https://github.com/a-b-street/route-snapper) routing graph:
8
+
9
+ - Build route-snapper **bincode graph bytes** from Overpass/session coverage via vendored `osm-to-route-snapper` WASM
10
+ - Serialize parsed OSM to minimal OSM XML for graph conversion
11
+ - Extract **routing-network GeoJSON** (intersection-split edges) from graph bytes
12
+ - GeoJSON LineStrings for session highway ways and a **coverage graph signature** for cache keys
13
+ - TanStack Query factory that rebuilds the graph when Overpass coverage grows
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import {
19
+ buildRouteSnapperGraphBytes,
20
+ createRouteSnapperGraphApi,
21
+ parsedOsmWaysToFeatureCollection,
22
+ routingNetworkGeoJsonFromBytes,
23
+ } from '@osm-editor-kit/osm-route-snapper'
24
+ ```
25
+
26
+ **Direct graph build** — pass merged `ParsedOsmData`; returns `Uint8Array` bincode or `null` when there are no ways:
27
+
28
+ ```ts
29
+ const graphBytes = await buildRouteSnapperGraphBytes(parsedOsm)
30
+ const routingNetwork = graphBytes
31
+ ? await routingNetworkGeoJsonFromBytes(graphBytes)
32
+ : null
33
+ ```
34
+
35
+ **React + TanStack Query** — `createRouteSnapperGraphApi` wires coverage growth to automatic full rebuilds (WASM has no incremental API):
36
+
37
+ ```ts
38
+ const { useRouteSnapperGraphQuery } = createRouteSnapperGraphApi({
39
+ getGraphKey: () => ['route-snapper-graph'],
40
+ useCoverageGraph: () => useSessionParsedOsm(),
41
+ })
42
+ ```
43
+
44
+ **Usage notes**
45
+
46
+ - Graph conversion uses vendored `osm-to-route-snapper` WASM; routing-network GeoJSON uses the peer **`route-snapper`** package (`^0.4.9`) — install both in the app.
47
+ - Peer deps: `react`, `@tanstack/react-query`, `route-snapper`.
@@ -0,0 +1,7 @@
1
+ import type { ParsedOsmData } from '@osm-editor-kit/osm-data';
2
+ /**
3
+ * Convert merged session OSM coverage into route-snapper bincode graph bytes.
4
+ * Uses prebuilt osm-to-route-snapper WASM (no Rust fork) — full rebuild from the
5
+ * current ParsedOsmData whenever coverage grows (WASM has no incremental merge API).
6
+ */
7
+ export declare function buildRouteSnapperGraphBytes(data: ParsedOsmData): Promise<Uint8Array<ArrayBufferLike> | null>;
@@ -0,0 +1,25 @@
1
+ import type { ParsedOsmData } from '@osm-editor-kit/osm-data';
2
+ import type { FeatureCollection, LineString } from 'geojson';
3
+ export type RouteSnapperGraphData = {
4
+ graphBytes: Uint8Array | null;
5
+ wayCount: number;
6
+ edgeCount: number;
7
+ overpassWays: FeatureCollection<LineString>;
8
+ routingNetwork: FeatureCollection<LineString>;
9
+ lastError: string | null;
10
+ };
11
+ export declare function emptyRouteSnapperGraphData(): RouteSnapperGraphData;
12
+ export type CreateRouteSnapperGraphApiOptions = {
13
+ /** Query key prefix; coverage signature is appended automatically. */
14
+ getGraphKey: () => readonly unknown[];
15
+ /** Latest merged Overpass session graph (grows incrementally). */
16
+ useCoverageGraph: () => ParsedOsmData;
17
+ };
18
+ /**
19
+ * TanStack Query API that rebuilds the route-snapper graph whenever the
20
+ * Overpass coverage graph grows. Full rebuild (WASM has no incremental API).
21
+ */
22
+ export declare function createRouteSnapperGraphApi({ getGraphKey, useCoverageGraph, }: CreateRouteSnapperGraphApiOptions): {
23
+ emptyData: typeof emptyRouteSnapperGraphData;
24
+ createUseQuery: () => () => import("@tanstack/react-query").UseQueryResult<NoInfer<RouteSnapperGraphData>, Error>;
25
+ };
@@ -0,0 +1,5 @@
1
+ export { buildRouteSnapperGraphBytes } from './build-graph';
2
+ export { createRouteSnapperGraphApi, emptyRouteSnapperGraphData, type CreateRouteSnapperGraphApiOptions, type RouteSnapperGraphData, } from './create-route-snapper-graph-api';
3
+ export { parsedOsmToXml } from './parsed-osm-to-xml';
4
+ export { countRoutingNetworkEdges, emptyLineCollection, routingNetworkGeoJsonFromBytes, } from './routing-network-geojson';
5
+ export { countRoadWays, coverageGraphSignature, parsedOsmWaysToFeatureCollection, } from './ways-geojson';
package/dist/index.js ADDED
@@ -0,0 +1,215 @@
1
+ import initOsmToRouteSnapper, { convert } from '../vendor/osm-to-route-snapper/osm_to_route_snapper.js';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import initRouteSnapper, { JsRouteSnapper } from 'route-snapper';
4
+
5
+ // src/parsed-osm-to-xml.ts
6
+ function escapeXml(value) {
7
+ return value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("'", "&apos;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
8
+ }
9
+ function renderTags(tags) {
10
+ return Object.entries(tags).map(([key, value]) => `<tag k="${escapeXml(key)}" v="${escapeXml(value)}"/>`).join("");
11
+ }
12
+ function renderNode(node) {
13
+ return `<node id="${node.id}" lat="${node.lat}" lon="${node.lon}" version="${node.version}" changeset="${node.changeset}"/>`;
14
+ }
15
+ function renderWay(way) {
16
+ const nds = way.nodes.map((nodeId) => `<nd ref="${nodeId}"/>`).join("");
17
+ return `<way id="${way.id}" version="${way.version}" changeset="${way.changeset}">${nds}${renderTags(way.tags)}</way>`;
18
+ }
19
+ function parsedOsmToXml(data) {
20
+ const nodeIds = /* @__PURE__ */ new Set();
21
+ for (const way of Object.values(data.ways)) {
22
+ for (const nodeId of way.nodes) {
23
+ nodeIds.add(nodeId);
24
+ }
25
+ }
26
+ const nodes = [...nodeIds].map((nodeId) => {
27
+ const node = data.nodes[nodeId];
28
+ if (node) return renderNode(node);
29
+ const coords = data.nodeCoords[nodeId];
30
+ if (!coords) return null;
31
+ return `<node id="${nodeId}" lat="${coords[0]}" lon="${coords[1]}" version="1" changeset="0"/>`;
32
+ }).filter((line) => line != null).join("");
33
+ const ways = Object.values(data.ways).map(renderWay).join("");
34
+ return `<?xml version="1.0" encoding="UTF-8"?><osm version="0.6" generator="osm-route-snapper">${nodes}${ways}</osm>`;
35
+ }
36
+ var initPromise;
37
+ async function ensureOsmToRouteSnapperReady() {
38
+ if (!initPromise) {
39
+ initPromise = initOsmToRouteSnapper().then(() => void 0);
40
+ }
41
+ await initPromise;
42
+ }
43
+ function coverageBoundaryGeoJson(data) {
44
+ let west = Infinity;
45
+ let south = Infinity;
46
+ let east = -Infinity;
47
+ let north = -Infinity;
48
+ for (const coords of Object.values(data.nodeCoords)) {
49
+ const [lat, lon] = coords;
50
+ west = Math.min(west, lon);
51
+ east = Math.max(east, lon);
52
+ south = Math.min(south, lat);
53
+ north = Math.max(north, lat);
54
+ }
55
+ if (!Number.isFinite(west)) {
56
+ west = 13.2;
57
+ east = 13.6;
58
+ south = 52.4;
59
+ north = 52.6;
60
+ }
61
+ const pad = 2e-3;
62
+ west -= pad;
63
+ east += pad;
64
+ south -= pad;
65
+ north += pad;
66
+ return JSON.stringify({
67
+ type: "Polygon",
68
+ coordinates: [
69
+ [
70
+ [west, south],
71
+ [east, south],
72
+ [east, north],
73
+ [west, north],
74
+ [west, south]
75
+ ]
76
+ ]
77
+ });
78
+ }
79
+ async function buildRouteSnapperGraphBytes(data) {
80
+ const wayCount = Object.keys(data.ways).length;
81
+ if (wayCount === 0) return null;
82
+ await ensureOsmToRouteSnapperReady();
83
+ const xml = parsedOsmToXml(data);
84
+ const input = new TextEncoder().encode(xml);
85
+ return convert(input, coverageBoundaryGeoJson(data));
86
+ }
87
+ var routeSnapperInitPromise;
88
+ async function ensureRouteSnapperReady() {
89
+ if (!routeSnapperInitPromise) {
90
+ routeSnapperInitPromise = initRouteSnapper().then(() => void 0);
91
+ }
92
+ await routeSnapperInitPromise;
93
+ }
94
+ function emptyLineCollection() {
95
+ return { type: "FeatureCollection", features: [] };
96
+ }
97
+ async function routingNetworkGeoJsonFromBytes(graphBytes) {
98
+ await ensureRouteSnapperReady();
99
+ const snapper = new JsRouteSnapper(graphBytes);
100
+ try {
101
+ const parsed = JSON.parse(snapper.debugRenderGraph());
102
+ const features = parsed.features.filter(
103
+ (feature) => feature.geometry?.type === "LineString"
104
+ );
105
+ return { type: "FeatureCollection", features };
106
+ } finally {
107
+ snapper.free();
108
+ }
109
+ }
110
+ function countRoutingNetworkEdges(collection) {
111
+ return collection.features.length;
112
+ }
113
+
114
+ // src/ways-geojson.ts
115
+ function wayLineString(wayId, nodeIds, nodeCoords) {
116
+ const coordinates = [];
117
+ for (const nodeId of nodeIds) {
118
+ const coords = nodeCoords[nodeId];
119
+ if (!coords) continue;
120
+ coordinates.push([coords[1], coords[0]]);
121
+ }
122
+ if (coordinates.length < 2) return null;
123
+ return {
124
+ type: "Feature",
125
+ properties: { osm_way_id: wayId },
126
+ geometry: { type: "LineString", coordinates }
127
+ };
128
+ }
129
+ function parsedOsmWaysToFeatureCollection(data) {
130
+ const features = [];
131
+ for (const way of Object.values(data.ways)) {
132
+ const feature = wayLineString(way.id, way.nodes, data.nodeCoords);
133
+ if (feature) features.push(feature);
134
+ }
135
+ return { type: "FeatureCollection", features };
136
+ }
137
+ function countRoadWays(data) {
138
+ return Object.keys(data.ways).length;
139
+ }
140
+ function coverageGraphSignature(data) {
141
+ return [
142
+ Object.keys(data.ways).length,
143
+ Object.keys(data.nodes).length,
144
+ Object.keys(data.nodeCoords).length
145
+ ].join(":");
146
+ }
147
+
148
+ // src/create-route-snapper-graph-api.ts
149
+ function emptyRouteSnapperGraphData() {
150
+ return {
151
+ graphBytes: null,
152
+ wayCount: 0,
153
+ edgeCount: 0,
154
+ overpassWays: emptyLineCollection(),
155
+ routingNetwork: emptyLineCollection(),
156
+ lastError: null
157
+ };
158
+ }
159
+ function createRouteSnapperGraphApi({
160
+ getGraphKey,
161
+ useCoverageGraph
162
+ }) {
163
+ function createUseQuery() {
164
+ return function useRouteSnapperGraphQuery() {
165
+ const graph = useCoverageGraph();
166
+ const signature = coverageGraphSignature(graph);
167
+ return useQuery({
168
+ queryKey: [...getGraphKey(), signature],
169
+ queryFn: async () => {
170
+ const wayCount = countRoadWays(graph);
171
+ if (wayCount === 0) return emptyRouteSnapperGraphData();
172
+ const overpassWays = parsedOsmWaysToFeatureCollection(graph);
173
+ try {
174
+ const graphBytes = await buildRouteSnapperGraphBytes(graph);
175
+ if (!graphBytes) {
176
+ return {
177
+ ...emptyRouteSnapperGraphData(),
178
+ wayCount,
179
+ overpassWays
180
+ };
181
+ }
182
+ const routingNetwork = await routingNetworkGeoJsonFromBytes(graphBytes);
183
+ return {
184
+ graphBytes,
185
+ wayCount,
186
+ edgeCount: countRoutingNetworkEdges(routingNetwork),
187
+ overpassWays,
188
+ routingNetwork,
189
+ lastError: null
190
+ };
191
+ } catch (error) {
192
+ const message = error instanceof Error ? error.message : "Graph build failed";
193
+ console.error("route-snapper graph build failed", error);
194
+ return {
195
+ graphBytes: null,
196
+ wayCount,
197
+ edgeCount: 0,
198
+ overpassWays,
199
+ routingNetwork: emptyLineCollection(),
200
+ lastError: message
201
+ };
202
+ }
203
+ },
204
+ staleTime: Number.POSITIVE_INFINITY,
205
+ enabled: countRoadWays(graph) > 0
206
+ });
207
+ };
208
+ }
209
+ return {
210
+ emptyData: emptyRouteSnapperGraphData,
211
+ createUseQuery
212
+ };
213
+ }
214
+
215
+ export { buildRouteSnapperGraphBytes, countRoadWays, countRoutingNetworkEdges, coverageGraphSignature, createRouteSnapperGraphApi, emptyLineCollection, emptyRouteSnapperGraphData, parsedOsmToXml, parsedOsmWaysToFeatureCollection, routingNetworkGeoJsonFromBytes };
@@ -0,0 +1,3 @@
1
+ import type { ParsedOsmData } from '@osm-editor-kit/osm-data';
2
+ /** Minimal OSM XML for osm-to-route-snapper (highway ways + referenced nodes). */
3
+ export declare function parsedOsmToXml(data: ParsedOsmData): string;
@@ -0,0 +1,6 @@
1
+ import type { FeatureCollection, LineString } from 'geojson';
2
+ declare function emptyLineCollection(): FeatureCollection<LineString>;
3
+ /** LineStrings for edges in the Rust/WASM route-snapper graph (split at intersections). */
4
+ export declare function routingNetworkGeoJsonFromBytes(graphBytes: Uint8Array): Promise<FeatureCollection<LineString>>;
5
+ export declare function countRoutingNetworkEdges(collection: FeatureCollection<LineString>): number;
6
+ export { emptyLineCollection };
@@ -0,0 +1,7 @@
1
+ import type { ParsedOsmData } from '@osm-editor-kit/osm-data';
2
+ import type { FeatureCollection, LineString } from 'geojson';
3
+ /** GeoJSON LineStrings for ways in the Overpass / session OSM cache. */
4
+ export declare function parsedOsmWaysToFeatureCollection(data: ParsedOsmData): FeatureCollection<LineString>;
5
+ export declare function countRoadWays(data: ParsedOsmData): number;
6
+ /** Stable signature so graph queries rebuild when coverage grows. */
7
+ export declare function coverageGraphSignature(data: ParsedOsmData): string;
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@osm-editor-kit/osm-route-snapper",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "Build route-snapper graph bytes and routing-network GeoJSON from parsed OSM coverage (WASM).",
5
+ "license": "MIT",
6
+ "author": "Tobias Jordans",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/osmberlin/street-space-editor.git",
10
+ "directory": "packages/osm-route-snapper"
11
+ },
12
+ "type": "module",
13
+ "sideEffects": false,
14
+ "files": [
15
+ "dist",
16
+ "vendor"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ },
23
+ "./package.json": "./package.json"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "tag": "alpha"
28
+ },
29
+ "scripts": {
30
+ "build": "tsup && rm -f .tsbuildinfo && tsc -p tsconfig.build.json",
31
+ "type-check": "tsc --noEmit",
32
+ "test-run": "bun test src/test",
33
+ "prepublishOnly": "bun run build && bun ../../scripts/package-exports-for-publish.ts",
34
+ "postpublish": "bun ../../scripts/package-exports-restore.ts",
35
+ "prepack": "bun ../../scripts/package-exports-for-publish.ts",
36
+ "postpack": "bun ../../scripts/package-exports-restore.ts"
37
+ },
38
+ "dependencies": {
39
+ "@osm-editor-kit/osm-data": "workspace:*"
40
+ },
41
+ "devDependencies": {
42
+ "@types/geojson": "^7946.0.16",
43
+ "@types/react": "^19.1.10",
44
+ "bun-types": "^1.2.20",
45
+ "react": "^19.1.1",
46
+ "route-snapper": "0.4.9",
47
+ "tsup": "^8.5.1",
48
+ "typescript": "^7.0.0"
49
+ },
50
+ "peerDependencies": {
51
+ "@tanstack/react-query": "^5.85.5",
52
+ "react": "^19.0.0",
53
+ "route-snapper": "^0.4.9"
54
+ },
55
+ "publishExports": {
56
+ ".": {
57
+ "types": "./dist/index.d.ts",
58
+ "import": "./dist/index.js"
59
+ },
60
+ "./package.json": "./package.json"
61
+ }
62
+ }
@@ -0,0 +1,42 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export function convert(input_bytes: Uint8Array, boundary_geojson: string): Uint8Array
4
+
5
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module
6
+
7
+ export interface InitOutput {
8
+ readonly memory: WebAssembly.Memory
9
+ readonly convert: (a: number, b: number, c: number, d: number) => [number, number, number, number]
10
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void
11
+ readonly __wbindgen_malloc: (a: number, b: number) => number
12
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number
13
+ readonly __wbindgen_export_3: WebAssembly.Table
14
+ readonly __externref_table_dealloc: (a: number) => void
15
+ readonly __wbindgen_start: () => void
16
+ }
17
+
18
+ export type SyncInitInput = BufferSource | WebAssembly.Module
19
+ /**
20
+ * Instantiates the given `module`, which can either be bytes or
21
+ * a precompiled `WebAssembly.Module`.
22
+ *
23
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
24
+ *
25
+ * @returns {InitOutput}
26
+ */
27
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput
28
+
29
+ /**
30
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
31
+ * for everything else, calls `WebAssembly.instantiate` directly.
32
+ *
33
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
34
+ *
35
+ * @returns {Promise<InitOutput>}
36
+ */
37
+ export default function __wbg_init(
38
+ module_or_path?:
39
+ | { module_or_path: InitInput | Promise<InitInput> }
40
+ | InitInput
41
+ | Promise<InitInput>,
42
+ ): Promise<InitOutput>
@@ -0,0 +1,305 @@
1
+ let wasm
2
+
3
+ const cachedTextDecoder =
4
+ typeof TextDecoder !== 'undefined'
5
+ ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true })
6
+ : {
7
+ decode: () => {
8
+ throw Error('TextDecoder not available')
9
+ },
10
+ }
11
+
12
+ if (typeof TextDecoder !== 'undefined') {
13
+ cachedTextDecoder.decode()
14
+ }
15
+
16
+ let cachedUint8ArrayMemory0 = null
17
+
18
+ function getUint8ArrayMemory0() {
19
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
20
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer)
21
+ }
22
+ return cachedUint8ArrayMemory0
23
+ }
24
+
25
+ function getStringFromWasm0(ptr, len) {
26
+ ptr = ptr >>> 0
27
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len))
28
+ }
29
+
30
+ let WASM_VECTOR_LEN = 0
31
+
32
+ const cachedTextEncoder =
33
+ typeof TextEncoder !== 'undefined'
34
+ ? new TextEncoder('utf-8')
35
+ : {
36
+ encode: () => {
37
+ throw Error('TextEncoder not available')
38
+ },
39
+ }
40
+
41
+ const encodeString =
42
+ typeof cachedTextEncoder.encodeInto === 'function'
43
+ ? function (arg, view) {
44
+ return cachedTextEncoder.encodeInto(arg, view)
45
+ }
46
+ : function (arg, view) {
47
+ const buf = cachedTextEncoder.encode(arg)
48
+ view.set(buf)
49
+ return {
50
+ read: arg.length,
51
+ written: buf.length,
52
+ }
53
+ }
54
+
55
+ function passStringToWasm0(arg, malloc, realloc) {
56
+ if (realloc === undefined) {
57
+ const buf = cachedTextEncoder.encode(arg)
58
+ const ptr = malloc(buf.length, 1) >>> 0
59
+ getUint8ArrayMemory0()
60
+ .subarray(ptr, ptr + buf.length)
61
+ .set(buf)
62
+ WASM_VECTOR_LEN = buf.length
63
+ return ptr
64
+ }
65
+
66
+ let len = arg.length
67
+ let ptr = malloc(len, 1) >>> 0
68
+
69
+ const mem = getUint8ArrayMemory0()
70
+
71
+ let offset = 0
72
+
73
+ for (; offset < len; offset++) {
74
+ const code = arg.charCodeAt(offset)
75
+ if (code > 0x7f) break
76
+ mem[ptr + offset] = code
77
+ }
78
+
79
+ if (offset !== len) {
80
+ if (offset !== 0) {
81
+ arg = arg.slice(offset)
82
+ }
83
+ ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0
84
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len)
85
+ const ret = encodeString(arg, view)
86
+
87
+ offset += ret.written
88
+ ptr = realloc(ptr, len, offset, 1) >>> 0
89
+ }
90
+
91
+ WASM_VECTOR_LEN = offset
92
+ return ptr
93
+ }
94
+
95
+ let cachedDataViewMemory0 = null
96
+
97
+ function getDataViewMemory0() {
98
+ if (
99
+ cachedDataViewMemory0 === null ||
100
+ cachedDataViewMemory0.buffer.detached === true ||
101
+ (cachedDataViewMemory0.buffer.detached === undefined &&
102
+ cachedDataViewMemory0.buffer !== wasm.memory.buffer)
103
+ ) {
104
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer)
105
+ }
106
+ return cachedDataViewMemory0
107
+ }
108
+
109
+ function passArray8ToWasm0(arg, malloc) {
110
+ const ptr = malloc(arg.length * 1, 1) >>> 0
111
+ getUint8ArrayMemory0().set(arg, ptr / 1)
112
+ WASM_VECTOR_LEN = arg.length
113
+ return ptr
114
+ }
115
+
116
+ function takeFromExternrefTable0(idx) {
117
+ const value = wasm.__wbindgen_export_3.get(idx)
118
+ wasm.__externref_table_dealloc(idx)
119
+ return value
120
+ }
121
+
122
+ function getArrayU8FromWasm0(ptr, len) {
123
+ ptr = ptr >>> 0
124
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len)
125
+ }
126
+ /**
127
+ * @param {Uint8Array} input_bytes
128
+ * @param {string} boundary_geojson
129
+ * @returns {Uint8Array}
130
+ */
131
+ export function convert(input_bytes, boundary_geojson) {
132
+ const ptr0 = passArray8ToWasm0(input_bytes, wasm.__wbindgen_malloc)
133
+ const len0 = WASM_VECTOR_LEN
134
+ const ptr1 = passStringToWasm0(boundary_geojson, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc)
135
+ const len1 = WASM_VECTOR_LEN
136
+ const ret = wasm.convert(ptr0, len0, ptr1, len1)
137
+ if (ret[3]) {
138
+ throw takeFromExternrefTable0(ret[2])
139
+ }
140
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice()
141
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1)
142
+ return v3
143
+ }
144
+
145
+ async function __wbg_load(module, imports) {
146
+ if (typeof Response === 'function' && module instanceof Response) {
147
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
148
+ try {
149
+ return await WebAssembly.instantiateStreaming(module, imports)
150
+ } catch (e) {
151
+ if (module.headers.get('Content-Type') != 'application/wasm') {
152
+ console.warn(
153
+ '`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n',
154
+ e,
155
+ )
156
+ } else {
157
+ throw e
158
+ }
159
+ }
160
+ }
161
+
162
+ const bytes = await module.arrayBuffer()
163
+ return await WebAssembly.instantiate(bytes, imports)
164
+ } else {
165
+ const instance = await WebAssembly.instantiate(module, imports)
166
+
167
+ if (instance instanceof WebAssembly.Instance) {
168
+ return { instance, module }
169
+ } else {
170
+ return instance
171
+ }
172
+ }
173
+ }
174
+
175
+ function __wbg_get_imports() {
176
+ const imports = {}
177
+ imports.wbg = {}
178
+ imports.wbg.__wbg_debug_dd7b0d8e36e37544 = function (arg0) {
179
+ console.debug(arg0)
180
+ }
181
+ imports.wbg.__wbg_error_0aa52a01e6e7818f = function (arg0) {
182
+ console.error(arg0)
183
+ }
184
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function (arg0, arg1) {
185
+ let deferred0_0
186
+ let deferred0_1
187
+ try {
188
+ deferred0_0 = arg0
189
+ deferred0_1 = arg1
190
+ console.error(getStringFromWasm0(arg0, arg1))
191
+ } finally {
192
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1)
193
+ }
194
+ }
195
+ imports.wbg.__wbg_info_82e75a55937c8734 = function (arg0) {
196
+ console.info(arg0)
197
+ }
198
+ imports.wbg.__wbg_log_42eff0132cf97143 = function (arg0) {
199
+ console.log(arg0)
200
+ }
201
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function () {
202
+ const ret = new Error()
203
+ return ret
204
+ }
205
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function (arg0, arg1) {
206
+ const ret = arg1.stack
207
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc)
208
+ const len1 = WASM_VECTOR_LEN
209
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true)
210
+ getDataViewMemory0().setInt32(arg0 + 0, ptr1, true)
211
+ }
212
+ imports.wbg.__wbg_warn_daee763c4ce7051e = function (arg0) {
213
+ console.warn(arg0)
214
+ }
215
+ imports.wbg.__wbindgen_init_externref_table = function () {
216
+ const table = wasm.__wbindgen_export_3
217
+ const offset = table.grow(4)
218
+ table.set(0, undefined)
219
+ table.set(offset + 0, undefined)
220
+ table.set(offset + 1, null)
221
+ table.set(offset + 2, true)
222
+ table.set(offset + 3, false)
223
+ }
224
+ imports.wbg.__wbindgen_string_new = function (arg0, arg1) {
225
+ const ret = getStringFromWasm0(arg0, arg1)
226
+ return ret
227
+ }
228
+ imports.wbg.__wbindgen_throw = function (arg0, arg1) {
229
+ throw new Error(getStringFromWasm0(arg0, arg1))
230
+ }
231
+
232
+ return imports
233
+ }
234
+
235
+ function __wbg_init_memory(_imports, _memory) {}
236
+
237
+ function __wbg_finalize_init(instance, module) {
238
+ wasm = instance.exports
239
+ __wbg_init.__wbindgen_wasm_module = module
240
+ cachedDataViewMemory0 = null
241
+ cachedUint8ArrayMemory0 = null
242
+
243
+ wasm.__wbindgen_start()
244
+ return wasm
245
+ }
246
+
247
+ function initSync(module) {
248
+ if (wasm !== undefined) return wasm
249
+
250
+ if (typeof module !== 'undefined') {
251
+ if (Object.getPrototypeOf(module) === Object.prototype) {
252
+ ;({ module } = module)
253
+ } else {
254
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
255
+ }
256
+ }
257
+
258
+ const imports = __wbg_get_imports()
259
+
260
+ __wbg_init_memory(imports)
261
+
262
+ if (!(module instanceof WebAssembly.Module)) {
263
+ module = new WebAssembly.Module(module)
264
+ }
265
+
266
+ const instance = new WebAssembly.Instance(module, imports)
267
+
268
+ return __wbg_finalize_init(instance, module)
269
+ }
270
+
271
+ async function __wbg_init(module_or_path) {
272
+ if (wasm !== undefined) return wasm
273
+
274
+ if (typeof module_or_path !== 'undefined') {
275
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
276
+ ;({ module_or_path } = module_or_path)
277
+ } else {
278
+ console.warn(
279
+ 'using deprecated parameters for the initialization function; pass a single object instead',
280
+ )
281
+ }
282
+ }
283
+
284
+ if (typeof module_or_path === 'undefined') {
285
+ module_or_path = new URL('osm_to_route_snapper_bg.wasm', import.meta.url)
286
+ }
287
+ const imports = __wbg_get_imports()
288
+
289
+ if (
290
+ typeof module_or_path === 'string' ||
291
+ (typeof Request === 'function' && module_or_path instanceof Request) ||
292
+ (typeof URL === 'function' && module_or_path instanceof URL)
293
+ ) {
294
+ module_or_path = fetch(module_or_path)
295
+ }
296
+
297
+ __wbg_init_memory(imports)
298
+
299
+ const { instance, module } = await __wbg_load(await module_or_path, imports)
300
+
301
+ return __wbg_finalize_init(instance, module)
302
+ }
303
+
304
+ export { initSync }
305
+ export default __wbg_init