@maplibre/mlt-wasm 0.1.41 → 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.
@@ -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
+ }