@maplibre/mlt-wasm 0.1.44 → 0.1.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maplibre/mlt-wasm",
3
- "version": "0.1.44",
3
+ "version": "0.1.45",
4
4
  "description": "WebAssembly-backed MapLibre Tile (MLT) decoder",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "gis"
28
28
  ],
29
29
  "scripts": {
30
- "build:wasm": "RUSTFLAGS=\"-Zunstable-options -Cpanic=immediate-abort -Ctarget-feature=+simd128\" CARGO_UNSTABLE_BUILD_STD=std,panic_abort RUSTUP_TOOLCHAIN=nightly wasm-pack build --target bundler --weak-refs --out-dir pkg",
30
+ "build:wasm": "RUSTFLAGS=\"-Zunstable-options -Cpanic=immediate-abort -Ctarget-feature=+simd128\" CARGO_UNSTABLE_BUILD_STD=std,panic_abort RUSTUP_TOOLCHAIN=nightly wasm-pack build --target bundler --weak-refs --out-dir pkg && rm -f pkg/.gitignore",
31
31
  "build:wasm-coverage": "CARGO_INCREMENTAL=0 RUSTFLAGS=\"-Cinstrument-coverage -Cdebuginfo=0 -Zno-profiler-runtime --emit=llvm-ir -Ccodegen-units=1\" RUSTUP_TOOLCHAIN=nightly wasm-pack build --dev --target bundler --weak-refs --out-dir pkg -- --features coverage",
32
32
  "build:wasm-gz": "gzip --best --no-name pkg/mlt_wasm_bg.wasm --keep --force && du -sh pkg/*.wasm*",
33
33
  "build:ts": "tsc",
package/pkg/README.md ADDED
@@ -0,0 +1,234 @@
1
+ # mlt-wasm
2
+
3
+ WebAssembly bindings for the [MapLibre Tile (MLT)](https://github.com/maplibre/maplibre-tile-spec) decoder.
4
+
5
+ Compiles `mlt-core` to WASM via [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) and ships a TypeScript wrapper exposing a `VectorTileLike` API.
6
+
7
+ ## Layout
8
+
9
+ ```
10
+ mlt-wasm/
11
+ ├── src/lib.rs # wasm-bindgen bindings
12
+ ├── js/
13
+ │ ├── index.ts # package entry point
14
+ │ ├── wasm.ts # the one module that imports pkg/
15
+ │ ├── annotate.ts # annotated-dump wire contract
16
+ │ ├── columns.ts # typed-array layers, as decoded
17
+ │ └── vectorTile.ts # VectorTileLike wrapper over columns.ts
18
+ ├── pkg/ # wasm-pack output (gitignored)
19
+ ├── dist/ # tsc output (gitignored)
20
+ ├── Cargo.toml
21
+ ├── package.json
22
+ └── tsconfig.json
23
+ ```
24
+
25
+ ## Build
26
+
27
+ Requires [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) and Node.js.
28
+
29
+ ```sh
30
+ npm run build
31
+ ```
32
+
33
+ This runs `wasm-pack build --target bundler --out-dir pkg` followed by `tsc`. Both steps are also available individually:
34
+
35
+ ```sh
36
+ npm run build:wasm
37
+ npm run build:ts
38
+ ```
39
+
40
+ The `unstable-v2` feature is on by default, so v2 layers decode. Building with
41
+ `--no-default-features` skips them.
42
+
43
+ ## Usage
44
+
45
+ ```ts
46
+ import { decodeTile } from '@maplibre/mlt-wasm';
47
+
48
+ const data = new Uint8Array(await fetch(tileUrl).then(r => r.arrayBuffer()));
49
+ const tile = decodeTile(data);
50
+
51
+ for (const [name, layer] of Object.entries(tile.layers)) {
52
+ for (let i = 0; i < layer.length; i++) {
53
+ const feature = layer.feature(i);
54
+ console.log(feature.type); // 1 | 2 | 3
55
+ console.log(feature.id); // number | undefined
56
+ console.log(feature.properties); // read from the decoded columns
57
+ console.log(feature.loadGeometry()); // Point[][]
58
+ }
59
+ }
60
+ ```
61
+
62
+ ### Columns
63
+
64
+ `decodeTileColumns` hands each layer over as the typed arrays it decodes to, for consumers that
65
+ build their own buffers, such as a renderer. Nothing per feature crosses the WASM boundary.
66
+
67
+ ```ts
68
+ import { columnValue, decodeTileColumns } from '@maplibre/mlt-wasm';
69
+
70
+ for (const layer of decodeTileColumns(data).layers) {
71
+ const { dimension, vertices, zStep } = layer.geometry;
72
+ // vertices: Int32Array of (x, y) pairs, or (x, y, z) triples when dimension is 3
73
+ // geometryOffsets, partOffsets, ringOffsets: cumulative offsets, left out when not needed
74
+ // triangleOffsets, indexBuffer: present on tessellated layers
75
+ for (const column of layer.properties) {
76
+ // column.values has one slot per feature; a slot without a value holds 0 or ""
77
+ for (let f = 0; f < layer.featureCount; f++) {
78
+ const value = columnValue(column, f); // undefined when feature f has no value
79
+ }
80
+ }
81
+ // v2 vertex-scoped (m-value) and nested columns are not passed on
82
+ }
83
+ ```
84
+
85
+ `decodeTileColumns(data, { layers: ['roads', 'water'] })` decodes only the layers with those names,
86
+ every one that has it, since layer names need not be unique. The other layers are skipped undecoded.
87
+
88
+ Each column is `{ name, type, values, present? }`. `present` is a bitmap with one bit per
89
+ feature, LSB-first, left out when every feature has a value. `bool` comes as `0`/`1`, and
90
+ 64-bit integers, ids included, as `Float64Array`, so values above `Number.MAX_SAFE_INTEGER`
91
+ lose precision.
92
+
93
+ A 3D layer's `zStep` is the power of ten of its z grid's step in metres; `toElevation(z, zStep)`
94
+ converts one z to metres, exactly as `mlt-core` does.
95
+
96
+ ### Features
97
+
98
+ `featureGeometry(layer, i)` reads feature `i` of a column layer without knowing the offset levels.
99
+ Its points, lines and polygon rings are views of the layer's vertices, still in tile coordinates,
100
+ and a polygon's rings come ready for earcut. A `TessPolygonsWithOutlines` layer's triangles come per
101
+ feature, counted from the feature's own vertices. A `TessPolygons` layer stores triangles without
102
+ outlines, so `featureGeometry` rejects it; its `indexBuffer` and `triangleOffsets` are the triangles.
103
+
104
+ ```ts
105
+ import { featureGeometry } from '@maplibre/mlt-wasm';
106
+
107
+ const g = featureGeometry(layer, i);
108
+ if (g.kind === 'polygon') {
109
+ for (const { vertices, holeIndices } of g.polygons) {
110
+ const triangles = earcut(vertices, holeIndices, layer.geometry.dimension);
111
+ }
112
+ }
113
+ ```
114
+
115
+ #### Building GPU buffers
116
+
117
+ `layer.geometry.vertices` can be uploaded as the vertex buffer as it is: `dimension` integers per
118
+ vertex, read as `ivec2` or `ivec3` in the shader. What a renderer adds next to it depends on whether
119
+ its shapes need tessellation on the CPU.
120
+
121
+ Shapes drawn as they are, such as points and lines (thick lines can be extruded in the vertex
122
+ shader), need to know where each line starts, to break lines apart, and which feature it belongs to,
123
+ to style or pick it. `geometryStarts(layer.geometry)` gives both for the whole layer, from the tile's
124
+ own offset levels: where each feature's geometries start, where each geometry's vertices start and, in
125
+ a layer with polygons, where each polygon's rings and each ring's vertices start. The tile stores
126
+ these as counts per level, not per vertex, and the arrays are their running totals. Each has one
127
+ entry more than it has items, and stored offset columns come back as they are. They are resolved once
128
+ per layer and every call returns the same arrays, so don't modify them.
129
+
130
+ In a layer of one geometry kind they are what a renderer takes for a batch, such as deck.gl's binary
131
+ `PathLayer` for lines:
132
+
133
+ ```ts
134
+ import { geometryStarts } from '@maplibre/mlt-wasm';
135
+
136
+ const { featureGeometries, geometryVertices, ringVertices } = geometryStarts(layer.geometry);
137
+ // Lines: line g is vertices geometryVertices[g] .. geometryVertices[g + 1], and feature f's lines
138
+ // are featureGeometries[f] .. featureGeometries[f + 1].
139
+ new PathLayer({
140
+ data: {
141
+ length: geometryVertices.length - 1,
142
+ startIndices: geometryVertices,
143
+ attributes: { getPath: { value: layer.geometry.vertices, size: layer.geometry.dimension } },
144
+ },
145
+ _pathType: 'open',
146
+ });
147
+ // Polygons: geometryVertices starts each polygon, ringVertices each ring (outlines without the
148
+ // closing vertex).
149
+ ```
150
+
151
+ A shader that extrudes lines itself reads one vertex at a time, so it needs the line as a vertex
152
+ attribute instead. That is one fill per line from the same starts, done by the renderer for the id it
153
+ uploads:
154
+
155
+ ```ts
156
+ // A segment is drawn only if both ends are the same line.
157
+ const lineOfVertex = new Uint32Array(geometryVertices[geometryVertices.length - 1]);
158
+ for (let g = 0; g + 1 < geometryVertices.length; g++) {
159
+ lineOfVertex.fill(g, geometryVertices[g], geometryVertices[g + 1]);
160
+ }
161
+ ```
162
+
163
+ A geometry is a point, a line or a polygon, and every kind shares one sequence in feature order, so in
164
+ a layer mixing kinds, `layer.geometry.types` tells which features are which. A `TessPolygons` layer has
165
+ no runs of vertices, only triangles, so `geometryStarts` rejects it.
166
+
167
+ On a 1.3 MB tile of 1,333 line features and 524,482 vertices, `geometryStarts` takes about 0.006 ms
168
+ and the fill above about 0.2 ms, against about 3.8 ms for `decodeTileColumns` (Node, one machine).
169
+
170
+ Shapes that need tessellation on the CPU work one polygon or line at a time:
171
+
172
+ - A tessellation that only adds triangles keeps the vertex buffer: earcut's indices are counted from a
173
+ polygon's view in `featureGeometry`, which comes with its hole indices, so adding its `firstVertex`
174
+ makes them an index buffer over `vertices`. A tessellated layer's triangles are that already.
175
+ - A tessellation that creates vertices, such as ribbons with joins built on the CPU or extruded walls,
176
+ reads each line or ring between its starts, writes a buffer of its own, and tags its output with the
177
+ line or feature it came from.
178
+
179
+ ### 3D
180
+
181
+ `decodeTile3D` reads a tile whose every layer has z coordinates. Its features have the same
182
+ `loadGeometry()` and `loadPolygons()`, with every vertex an `[x, y, z]` array, so the rest of the
183
+ code can assume 3D. It throws when any layer has no z coordinates, for which `decodeTile` reads the
184
+ tile in 2D, and when any layer uses the `TessPolygons` or `TessPolygonsWithOutlines` geometry
185
+ layout. `decodeTileColumns` reads every layout, in 2D and 3D.
186
+
187
+ Like `x` and `y`, `z` is the stored integer: it lies on the layer's `zStep` grid, and
188
+ `toElevation(z, layer.zStep)` gives its elevation in metres.
189
+
190
+ ```ts
191
+ import { decodeTile3D } from '@maplibre/mlt-wasm';
192
+
193
+ const tile = decodeTile3D(data);
194
+ for (const [name, layer] of Object.entries(tile.layers)) {
195
+ for (let i = 0; i < layer.length; i++) {
196
+ const feature = layer.feature(i);
197
+ // exterior ring, then holes; each ring is closed (its first vertex is repeated at the end)
198
+ const polygons = feature.loadPolygons(); // [x, y, z][][][]
199
+ }
200
+ }
201
+ ```
202
+
203
+ ## Annotate
204
+
205
+ `annotateTile` walks a tile into the regions an annotated hexdump is made of: every byte beside
206
+ the meaning of the field that owns it. The crate is built with `unstable-v2`, so v1 and v2 tiles
207
+ both annotate.
208
+
209
+ ```ts
210
+ import { annotateTile } from '@maplibre/mlt-wasm';
211
+
212
+ const tile = annotateTile(data);
213
+ const { bufLen, regions } = tile.tree(); // the whole tile
214
+
215
+ for (const [i, region] of regions.entries()) {
216
+ console.log(region.offset, region.len, region.label, region.value);
217
+ if (region.blob) {
218
+ console.log(tile.decodeBlob(i, 64)); // decoded values, capped
219
+ }
220
+ }
221
+
222
+ console.log(tile.error); // null, or what stopped the walk
223
+ tile.free();
224
+ ```
225
+
226
+ `tree(layerIndex)` narrows to one top-level layer, but `decodeBlob` keeps counting the regions of
227
+ the whole tile.
228
+
229
+ A handle, not a document: the tile bytes stay on the WASM side, `tree()` crosses once per layer
230
+ and is memoized, and payload values are decoded one blob at a time with a cap the caller picks.
231
+
232
+ A malformed tile never throws. The walk hands back the regions it reached, `error` carries the
233
+ failure, and a final `<unannotated>` leaf covers the bytes it never got to, so the leaves still
234
+ partition the buffer.
@@ -0,0 +1,63 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * A tile annotated as far as the walk got, plus the error that stopped it.
6
+ *
7
+ * The handle keeps the tile bytes and the region list on the WASM side.
8
+ * JS pulls the region list across once per layer and asks for decoded payloads one blob at a
9
+ * time, so a tile with tens of thousands of regions costs one conversion rather than one per
10
+ * value.
11
+ */
12
+ export class AnnotatedTile {
13
+ private constructor();
14
+ free(): void;
15
+ [Symbol.dispose](): void;
16
+ /**
17
+ * Decode the payload of the data blob at `region_index`, keeping at most `max_values` values.
18
+ *
19
+ * `max_values` of `0` keeps all of them, and a bytes payload ignores the cap.
20
+ * The index counts the regions of the whole tile, never those of a filtered [`Self::tree`].
21
+ */
22
+ decodeBlob(region_index: number, max_values: number): any;
23
+ /**
24
+ * The regions of the whole tile, or of one top-level layer, memoized per argument.
25
+ *
26
+ * A tree costs a real conversion, so this is a method rather than a getter.
27
+ */
28
+ tree(layer?: number | null): any;
29
+ /**
30
+ * The walker failure that stopped the annotation, or `null`.
31
+ *
32
+ * When set, the tree ends in an `<unannotated>` leaf covering the bytes the walk never
33
+ * reached.
34
+ */
35
+ readonly error: any;
36
+ }
37
+
38
+ /**
39
+ * Annotate a raw MLT tile blob, region by region.
40
+ *
41
+ * Never throws for a malformed tile: the walk hands back what it annotated and
42
+ * [`AnnotatedTile::error`] carries the failure.
43
+ */
44
+ export function annotateTile(data: Uint8Array): AnnotatedTile;
45
+
46
+ /**
47
+ * Decode the layers of `data` into their columns, in wire order: every layer, or with
48
+ * `names`, only those with one of these names. A layer left out is never decoded.
49
+ *
50
+ * v2 layers are skipped unless the crate is built with the `unstable-v2` feature.
51
+ */
52
+ export function decodeTileColumns(data: Uint8Array, names?: string[] | null): Array<any>;
53
+
54
+ /**
55
+ * Decode a raw MLT tile blob into `GeoJSON`, as the serialized text.
56
+ *
57
+ * Every feature carries `_layer` and `_extent`, and a v2 tile's vertex-scoped columns ride
58
+ * along as `m:`-prefixed arrays, one value per vertex.
59
+ *
60
+ * Text rather than a `JsValue`: building the object graph across the boundary costs a
61
+ * crossing per value, where one string plus `JSON.parse` is a single copy.
62
+ */
63
+ export function tileGeoJson(data: Uint8Array): string;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./mlt_wasm.d.ts" */
2
+ import * as wasm from "./mlt_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./mlt_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ AnnotatedTile, annotateTile, decodeTileColumns, tileGeoJson
9
+ } from "./mlt_wasm_bg.js";
@@ -0,0 +1,456 @@
1
+ /**
2
+ * A tile annotated as far as the walk got, plus the error that stopped it.
3
+ *
4
+ * The handle keeps the tile bytes and the region list on the WASM side.
5
+ * JS pulls the region list across once per layer and asks for decoded payloads one blob at a
6
+ * time, so a tile with tens of thousands of regions costs one conversion rather than one per
7
+ * value.
8
+ */
9
+ export class AnnotatedTile {
10
+ static __wrap(ptr) {
11
+ const obj = Object.create(AnnotatedTile.prototype);
12
+ obj.__wbg_ptr = ptr;
13
+ AnnotatedTileFinalization.register(obj, obj.__wbg_ptr, obj);
14
+ return obj;
15
+ }
16
+ __destroy_into_raw() {
17
+ const ptr = this.__wbg_ptr;
18
+ this.__wbg_ptr = 0;
19
+ AnnotatedTileFinalization.unregister(this);
20
+ return ptr;
21
+ }
22
+ free() {
23
+ const ptr = this.__destroy_into_raw();
24
+ wasm.__wbg_annotatedtile_free(ptr, 0);
25
+ }
26
+ /**
27
+ * Decode the payload of the data blob at `region_index`, keeping at most `max_values` values.
28
+ *
29
+ * `max_values` of `0` keeps all of them, and a bytes payload ignores the cap.
30
+ * The index counts the regions of the whole tile, never those of a filtered [`Self::tree`].
31
+ * @param {number} region_index
32
+ * @param {number} max_values
33
+ * @returns {any}
34
+ */
35
+ decodeBlob(region_index, max_values) {
36
+ const ret = wasm.annotatedtile_decodeBlob(this.__wbg_ptr, region_index, max_values);
37
+ if (ret[2]) {
38
+ throw takeFromExternrefTable0(ret[1]);
39
+ }
40
+ return takeFromExternrefTable0(ret[0]);
41
+ }
42
+ /**
43
+ * The walker failure that stopped the annotation, or `null`.
44
+ *
45
+ * When set, the tree ends in an `<unannotated>` leaf covering the bytes the walk never
46
+ * reached.
47
+ * @returns {any}
48
+ */
49
+ get error() {
50
+ const ret = wasm.annotatedtile_error(this.__wbg_ptr);
51
+ return ret;
52
+ }
53
+ /**
54
+ * The regions of the whole tile, or of one top-level layer, memoized per argument.
55
+ *
56
+ * A tree costs a real conversion, so this is a method rather than a getter.
57
+ * @param {number | null} [layer]
58
+ * @returns {any}
59
+ */
60
+ tree(layer) {
61
+ const ret = wasm.annotatedtile_tree(this.__wbg_ptr, isLikeNone(layer) ? Number.MAX_SAFE_INTEGER : (layer) >>> 0);
62
+ if (ret[2]) {
63
+ throw takeFromExternrefTable0(ret[1]);
64
+ }
65
+ return takeFromExternrefTable0(ret[0]);
66
+ }
67
+ }
68
+ if (Symbol.dispose) AnnotatedTile.prototype[Symbol.dispose] = AnnotatedTile.prototype.free;
69
+
70
+ /**
71
+ * Annotate a raw MLT tile blob, region by region.
72
+ *
73
+ * Never throws for a malformed tile: the walk hands back what it annotated and
74
+ * [`AnnotatedTile::error`] carries the failure.
75
+ * @param {Uint8Array} data
76
+ * @returns {AnnotatedTile}
77
+ */
78
+ export function annotateTile(data) {
79
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
80
+ const len0 = WASM_VECTOR_LEN;
81
+ const ret = wasm.annotateTile(ptr0, len0);
82
+ return AnnotatedTile.__wrap(ret);
83
+ }
84
+
85
+ /**
86
+ * Decode the layers of `data` into their columns, in wire order: every layer, or with
87
+ * `names`, only those with one of these names. A layer left out is never decoded.
88
+ *
89
+ * v2 layers are skipped unless the crate is built with the `unstable-v2` feature.
90
+ * @param {Uint8Array} data
91
+ * @param {string[] | null} [names]
92
+ * @returns {Array<any>}
93
+ */
94
+ export function decodeTileColumns(data, names) {
95
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
96
+ const len0 = WASM_VECTOR_LEN;
97
+ var ptr1 = isLikeNone(names) ? 0 : passArrayJsValueToWasm0(names, wasm.__wbindgen_malloc);
98
+ var len1 = WASM_VECTOR_LEN;
99
+ const ret = wasm.decodeTileColumns(ptr0, len0, ptr1, len1);
100
+ if (ret[2]) {
101
+ throw takeFromExternrefTable0(ret[1]);
102
+ }
103
+ return takeFromExternrefTable0(ret[0]);
104
+ }
105
+
106
+ /**
107
+ * Decode a raw MLT tile blob into `GeoJSON`, as the serialized text.
108
+ *
109
+ * Every feature carries `_layer` and `_extent`, and a v2 tile's vertex-scoped columns ride
110
+ * along as `m:`-prefixed arrays, one value per vertex.
111
+ *
112
+ * Text rather than a `JsValue`: building the object graph across the boundary costs a
113
+ * crossing per value, where one string plus `JSON.parse` is a single copy.
114
+ * @param {Uint8Array} data
115
+ * @returns {string}
116
+ */
117
+ export function tileGeoJson(data) {
118
+ let deferred3_0;
119
+ let deferred3_1;
120
+ try {
121
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
122
+ const len0 = WASM_VECTOR_LEN;
123
+ const ret = wasm.tileGeoJson(ptr0, len0);
124
+ var ptr2 = ret[0];
125
+ var len2 = ret[1];
126
+ if (ret[3]) {
127
+ ptr2 = 0; len2 = 0;
128
+ throw takeFromExternrefTable0(ret[2]);
129
+ }
130
+ deferred3_0 = ptr2;
131
+ deferred3_1 = len2;
132
+ return getStringFromWasm0(ptr2, len2);
133
+ } finally {
134
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
135
+ }
136
+ }
137
+ export function __wbg_Error_30c8987f7c2ed4e2(arg0, arg1) {
138
+ const ret = Error(getStringFromWasm0(arg0, arg1));
139
+ return ret;
140
+ }
141
+ export function __wbg_String_8564e559799eccda(arg0, arg1) {
142
+ const ret = String(arg1);
143
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
144
+ const len1 = WASM_VECTOR_LEN;
145
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
146
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
147
+ }
148
+ export function __wbg___wbindgen_is_string_90b56bc79aad6f6c(arg0) {
149
+ const ret = typeof(arg0) === 'string';
150
+ return ret;
151
+ }
152
+ export function __wbg___wbindgen_string_get_0380ccaa2f57f0d9(arg0, arg1) {
153
+ const obj = arg1;
154
+ const ret = typeof(obj) === 'string' ? obj : undefined;
155
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
156
+ var len1 = WASM_VECTOR_LEN;
157
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
158
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
159
+ }
160
+ export function __wbg___wbindgen_throw_41e9ee4f547fc59a(arg0, arg1) {
161
+ throw new Error(getStringFromWasm0(arg0, arg1));
162
+ }
163
+ export function __wbg_new_28744009d011f847() {
164
+ const ret = new Map();
165
+ return ret;
166
+ }
167
+ export function __wbg_new_617a8cdb8bb1130e() {
168
+ const ret = new Object();
169
+ return ret;
170
+ }
171
+ export function __wbg_new_ee2291f50781bf1d() {
172
+ const ret = new Array();
173
+ return ret;
174
+ }
175
+ export function __wbg_new_from_slice_36f6b4e63daa7f59(arg0, arg1) {
176
+ const ret = new Int8Array(getArrayI8FromWasm0(arg0, arg1));
177
+ return ret;
178
+ }
179
+ export function __wbg_new_from_slice_37a3c3a194266cb8(arg0, arg1) {
180
+ const ret = new Uint32Array(getArrayU32FromWasm0(arg0, arg1));
181
+ return ret;
182
+ }
183
+ export function __wbg_new_from_slice_911f717853b222c7(arg0, arg1) {
184
+ const ret = new Int32Array(getArrayI32FromWasm0(arg0, arg1));
185
+ return ret;
186
+ }
187
+ export function __wbg_new_from_slice_9a868026ffa4208a(arg0, arg1) {
188
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
189
+ return ret;
190
+ }
191
+ export function __wbg_new_from_slice_ca6ad97db1f4779a(arg0, arg1) {
192
+ const ret = new Float32Array(getArrayF32FromWasm0(arg0, arg1));
193
+ return ret;
194
+ }
195
+ export function __wbg_new_from_slice_f545fd22ddc142b8(arg0, arg1) {
196
+ const ret = new Float64Array(getArrayF64FromWasm0(arg0, arg1));
197
+ return ret;
198
+ }
199
+ export function __wbg_new_with_length_469fcc27bd71672e(arg0) {
200
+ const ret = new Array(arg0 >>> 0);
201
+ return ret;
202
+ }
203
+ export function __wbg_push_2baf45db356cf468(arg0, arg1) {
204
+ const ret = arg0.push(arg1);
205
+ return ret;
206
+ }
207
+ export function __wbg_set_145a351398b48c65() { return handleError(function (arg0, arg1, arg2) {
208
+ const ret = Reflect.set(arg0, arg1, arg2);
209
+ return ret;
210
+ }, arguments); }
211
+ export function __wbg_set_6ae97e73113c4f0b(arg0, arg1, arg2) {
212
+ const ret = arg0.set(arg1, arg2);
213
+ return ret;
214
+ }
215
+ export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
216
+ arg0[arg1] = arg2;
217
+ }
218
+ export function __wbg_set_bea140a88be9b277(arg0, arg1, arg2) {
219
+ arg0[arg1 >>> 0] = arg2;
220
+ }
221
+ export function __wbindgen_generic_0000000000000001(arg0) {
222
+ // Cast intrinsic for `F64 -> Externref`.
223
+ const ret = arg0;
224
+ return ret;
225
+ }
226
+ export function __wbindgen_generic_0000000000000002(arg0, arg1) {
227
+ // Cast intrinsic for `I128 -> Externref`.
228
+ const ret = (BigInt.asUintN(64, arg0) | (arg1 << BigInt(64)));
229
+ return ret;
230
+ }
231
+ export function __wbindgen_generic_0000000000000003(arg0) {
232
+ // Cast intrinsic for `I64 -> Externref`.
233
+ const ret = arg0;
234
+ return ret;
235
+ }
236
+ export function __wbindgen_generic_0000000000000004(arg0, arg1) {
237
+ // Cast intrinsic for `Ref(String) -> Externref`.
238
+ const ret = getStringFromWasm0(arg0, arg1);
239
+ return ret;
240
+ }
241
+ export function __wbindgen_init_externref_table() {
242
+ const table = wasm.__wbindgen_externrefs;
243
+ const offset = table.grow(4);
244
+ table.set(0, undefined);
245
+ table.set(offset + 0, undefined);
246
+ table.set(offset + 1, null);
247
+ table.set(offset + 2, true);
248
+ table.set(offset + 3, false);
249
+ }
250
+ const AnnotatedTileFinalization = (typeof FinalizationRegistry === 'undefined')
251
+ ? { register: () => {}, unregister: () => {} }
252
+ : new FinalizationRegistry(ptr => wasm.__wbg_annotatedtile_free(ptr, 1));
253
+
254
+ function addToExternrefTable0(obj) {
255
+ const idx = wasm.__externref_table_alloc();
256
+ wasm.__wbindgen_externrefs.set(idx, obj);
257
+ return idx;
258
+ }
259
+
260
+ function getArrayF32FromWasm0(ptr, len) {
261
+ ptr = ptr >>> 0;
262
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
263
+ }
264
+
265
+ function getArrayF64FromWasm0(ptr, len) {
266
+ ptr = ptr >>> 0;
267
+ return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
268
+ }
269
+
270
+ function getArrayI32FromWasm0(ptr, len) {
271
+ ptr = ptr >>> 0;
272
+ return getInt32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
273
+ }
274
+
275
+ function getArrayI8FromWasm0(ptr, len) {
276
+ ptr = ptr >>> 0;
277
+ return getInt8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
278
+ }
279
+
280
+ function getArrayU32FromWasm0(ptr, len) {
281
+ ptr = ptr >>> 0;
282
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
283
+ }
284
+
285
+ function getArrayU8FromWasm0(ptr, len) {
286
+ ptr = ptr >>> 0;
287
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
288
+ }
289
+
290
+ let cachedDataViewMemory0 = null;
291
+ function getDataViewMemory0() {
292
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
293
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
294
+ }
295
+ return cachedDataViewMemory0;
296
+ }
297
+
298
+ let cachedFloat32ArrayMemory0 = null;
299
+ function getFloat32ArrayMemory0() {
300
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
301
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
302
+ }
303
+ return cachedFloat32ArrayMemory0;
304
+ }
305
+
306
+ let cachedFloat64ArrayMemory0 = null;
307
+ function getFloat64ArrayMemory0() {
308
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
309
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
310
+ }
311
+ return cachedFloat64ArrayMemory0;
312
+ }
313
+
314
+ let cachedInt32ArrayMemory0 = null;
315
+ function getInt32ArrayMemory0() {
316
+ if (cachedInt32ArrayMemory0 === null || cachedInt32ArrayMemory0.byteLength === 0) {
317
+ cachedInt32ArrayMemory0 = new Int32Array(wasm.memory.buffer);
318
+ }
319
+ return cachedInt32ArrayMemory0;
320
+ }
321
+
322
+ let cachedInt8ArrayMemory0 = null;
323
+ function getInt8ArrayMemory0() {
324
+ if (cachedInt8ArrayMemory0 === null || cachedInt8ArrayMemory0.byteLength === 0) {
325
+ cachedInt8ArrayMemory0 = new Int8Array(wasm.memory.buffer);
326
+ }
327
+ return cachedInt8ArrayMemory0;
328
+ }
329
+
330
+ function getStringFromWasm0(ptr, len) {
331
+ return decodeText(ptr >>> 0, len);
332
+ }
333
+
334
+ let cachedUint32ArrayMemory0 = null;
335
+ function getUint32ArrayMemory0() {
336
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
337
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
338
+ }
339
+ return cachedUint32ArrayMemory0;
340
+ }
341
+
342
+ let cachedUint8ArrayMemory0 = null;
343
+ function getUint8ArrayMemory0() {
344
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
345
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
346
+ }
347
+ return cachedUint8ArrayMemory0;
348
+ }
349
+
350
+ function handleError(f, args) {
351
+ try {
352
+ return f.apply(this, args);
353
+ } catch (e) {
354
+ const idx = addToExternrefTable0(e);
355
+ wasm.__wbindgen_exn_store(idx);
356
+ }
357
+ }
358
+
359
+ function isLikeNone(x) {
360
+ return x === undefined || x === null;
361
+ }
362
+
363
+ function passArray8ToWasm0(arg, malloc) {
364
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
365
+ getUint8ArrayMemory0().set(arg, ptr / 1);
366
+ WASM_VECTOR_LEN = arg.length;
367
+ return ptr;
368
+ }
369
+
370
+ function passArrayJsValueToWasm0(array, malloc) {
371
+ const ptr = malloc(array.length * 4, 4) >>> 0;
372
+ for (let i = 0; i < array.length; i++) {
373
+ const add = addToExternrefTable0(array[i]);
374
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
375
+ }
376
+ WASM_VECTOR_LEN = array.length;
377
+ return ptr;
378
+ }
379
+
380
+ function passStringToWasm0(arg, malloc, realloc) {
381
+ if (realloc === undefined) {
382
+ const buf = cachedTextEncoder.encode(arg);
383
+ const ptr = malloc(buf.length, 1) >>> 0;
384
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
385
+ WASM_VECTOR_LEN = buf.length;
386
+ return ptr;
387
+ }
388
+
389
+ let len = arg.length;
390
+ let ptr = malloc(len, 1) >>> 0;
391
+
392
+ const mem = getUint8ArrayMemory0();
393
+
394
+ let offset = 0;
395
+
396
+ for (; offset < len; offset++) {
397
+ const code = arg.charCodeAt(offset);
398
+ if (code > 0x7F) break;
399
+ mem[ptr + offset] = code;
400
+ }
401
+ if (offset !== len) {
402
+ if (offset !== 0) {
403
+ arg = arg.slice(offset);
404
+ }
405
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
406
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
407
+ const ret = cachedTextEncoder.encodeInto(arg, view);
408
+
409
+ offset += ret.written;
410
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
411
+ }
412
+
413
+ WASM_VECTOR_LEN = offset;
414
+ return ptr;
415
+ }
416
+
417
+ function takeFromExternrefTable0(idx) {
418
+ const value = wasm.__wbindgen_externrefs.get(idx);
419
+ wasm.__externref_table_dealloc(idx);
420
+ return value;
421
+ }
422
+
423
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
424
+ cachedTextDecoder.decode();
425
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
426
+ let numBytesDecoded = 0;
427
+ function decodeText(ptr, len) {
428
+ numBytesDecoded += len;
429
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
430
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
431
+ cachedTextDecoder.decode();
432
+ numBytesDecoded = len;
433
+ }
434
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
435
+ }
436
+
437
+ const cachedTextEncoder = new TextEncoder();
438
+
439
+ if (!('encodeInto' in cachedTextEncoder)) {
440
+ cachedTextEncoder.encodeInto = function (arg, view) {
441
+ const buf = cachedTextEncoder.encode(arg);
442
+ view.set(buf);
443
+ return {
444
+ read: arg.length,
445
+ written: buf.length
446
+ };
447
+ };
448
+ }
449
+
450
+ let WASM_VECTOR_LEN = 0;
451
+
452
+
453
+ let wasm;
454
+ export function __wbg_set_wasm(val) {
455
+ wasm = val;
456
+ }
Binary file
@@ -0,0 +1,18 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_annotatedtile_free: (a: number, b: number) => void;
5
+ export const annotateTile: (a: number, b: number) => number;
6
+ export const annotatedtile_decodeBlob: (a: number, b: number, c: number) => [number, number, number];
7
+ export const annotatedtile_error: (a: number) => any;
8
+ export const annotatedtile_tree: (a: number, b: number) => [number, number, number];
9
+ export const decodeTileColumns: (a: number, b: number, c: number, d: number) => [number, number, number];
10
+ export const tileGeoJson: (a: number, b: number) => [number, number, number, number];
11
+ export const __wbindgen_malloc: (a: number, b: number) => number;
12
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
13
+ export const __wbindgen_exn_store: (a: number) => void;
14
+ export const __externref_table_alloc: () => number;
15
+ export const __wbindgen_externrefs: WebAssembly.Table;
16
+ export const __externref_table_dealloc: (a: number) => void;
17
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
18
+ export const __wbindgen_start: () => void;
Binary file
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "mlt-wasm",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Maplibre Contributors"
6
+ ],
7
+ "description": "WebAssembly bindings for the MapLibre Tile (MLT) format",
8
+ "version": "0.1.45",
9
+ "license": "MIT OR Apache-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/maplibre/maplibre-tile-spec"
13
+ },
14
+ "files": [
15
+ "mlt_wasm_bg.wasm",
16
+ "mlt_wasm.js",
17
+ "mlt_wasm_bg.js",
18
+ "mlt_wasm.d.ts"
19
+ ],
20
+ "main": "mlt_wasm.js",
21
+ "homepage": "https://maplibre.org",
22
+ "types": "mlt_wasm.d.ts",
23
+ "sideEffects": [
24
+ "./mlt_wasm.js",
25
+ "./snippets/*"
26
+ ],
27
+ "keywords": [
28
+ "maplibre",
29
+ "tile",
30
+ "mlt",
31
+ "mvt",
32
+ "map"
33
+ ]
34
+ }