@loaders.gl/wkt 4.2.0-alpha.4 → 4.2.0-alpha.5

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.
Files changed (73) hide show
  1. package/dist/dist.dev.js +133 -220
  2. package/dist/dist.min.js +10 -0
  3. package/dist/hex-wkb-loader.d.ts +1 -1
  4. package/dist/hex-wkb-loader.d.ts.map +1 -1
  5. package/dist/hex-wkb-loader.js +44 -28
  6. package/dist/index.cjs +77 -58
  7. package/dist/index.cjs.map +7 -0
  8. package/dist/index.d.ts +14 -14
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +4 -1
  11. package/dist/lib/encode-twkb.js +158 -143
  12. package/dist/lib/encode-wkb.js +247 -211
  13. package/dist/lib/encode-wkt-crs.d.ts +1 -1
  14. package/dist/lib/encode-wkt-crs.d.ts.map +1 -1
  15. package/dist/lib/encode-wkt-crs.js +32 -18
  16. package/dist/lib/encode-wkt.js +35 -27
  17. package/dist/lib/parse-hex-wkb.js +1 -2
  18. package/dist/lib/parse-twkb.js +215 -218
  19. package/dist/lib/parse-wkb-header.js +124 -95
  20. package/dist/lib/parse-wkb.d.ts +1 -1
  21. package/dist/lib/parse-wkb.d.ts.map +1 -1
  22. package/dist/lib/parse-wkb.js +210 -235
  23. package/dist/lib/parse-wkt-crs.js +110 -86
  24. package/dist/lib/parse-wkt.js +251 -185
  25. package/dist/lib/utils/base64-encoder.js +151 -5
  26. package/dist/lib/utils/binary-reader.js +63 -64
  27. package/dist/lib/utils/binary-writer.js +115 -109
  28. package/dist/lib/utils/hex-encoder.js +46 -32
  29. package/dist/lib/utils/hex-transcoder.js +40 -24
  30. package/dist/lib/utils/version.js +6 -1
  31. package/dist/twkb-loader.js +26 -17
  32. package/dist/twkb-writer.js +18 -13
  33. package/dist/wkb-loader.js +26 -17
  34. package/dist/wkb-writer.js +22 -17
  35. package/dist/wkt-crs-loader.d.ts +1 -1
  36. package/dist/wkt-crs-loader.d.ts.map +1 -1
  37. package/dist/wkt-crs-loader.js +22 -15
  38. package/dist/wkt-crs-writer.d.ts +2 -2
  39. package/dist/wkt-crs-writer.d.ts.map +1 -1
  40. package/dist/wkt-crs-writer.js +23 -15
  41. package/dist/wkt-loader.js +28 -20
  42. package/dist/wkt-writer.js +19 -14
  43. package/dist/workers/wkb-worker.js +3 -1
  44. package/dist/workers/wkt-worker.js +3 -1
  45. package/package.json +10 -6
  46. package/dist/hex-wkb-loader.js.map +0 -1
  47. package/dist/index.js.map +0 -1
  48. package/dist/lib/encode-twkb.js.map +0 -1
  49. package/dist/lib/encode-wkb.js.map +0 -1
  50. package/dist/lib/encode-wkt-crs.js.map +0 -1
  51. package/dist/lib/encode-wkt.js.map +0 -1
  52. package/dist/lib/parse-hex-wkb.js.map +0 -1
  53. package/dist/lib/parse-twkb.js.map +0 -1
  54. package/dist/lib/parse-wkb-header.js.map +0 -1
  55. package/dist/lib/parse-wkb.js.map +0 -1
  56. package/dist/lib/parse-wkt-crs.js.map +0 -1
  57. package/dist/lib/parse-wkt.js.map +0 -1
  58. package/dist/lib/utils/base64-encoder.js.map +0 -1
  59. package/dist/lib/utils/binary-reader.js.map +0 -1
  60. package/dist/lib/utils/binary-writer.js.map +0 -1
  61. package/dist/lib/utils/hex-encoder.js.map +0 -1
  62. package/dist/lib/utils/hex-transcoder.js.map +0 -1
  63. package/dist/lib/utils/version.js.map +0 -1
  64. package/dist/twkb-loader.js.map +0 -1
  65. package/dist/twkb-writer.js.map +0 -1
  66. package/dist/wkb-loader.js.map +0 -1
  67. package/dist/wkb-writer.js.map +0 -1
  68. package/dist/wkt-crs-loader.js.map +0 -1
  69. package/dist/wkt-crs-writer.js.map +0 -1
  70. package/dist/wkt-loader.js.map +0 -1
  71. package/dist/wkt-writer.js.map +0 -1
  72. package/dist/workers/wkb-worker.js.map +0 -1
  73. package/dist/workers/wkt-worker.js.map +0 -1
package/dist/dist.dev.js CHANGED
@@ -2,14 +2,19 @@
2
2
  if (typeof exports === 'object' && typeof module === 'object')
3
3
  module.exports = factory();
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
- else if (typeof exports === 'object') exports['loader'] = factory();
6
- else root['loader'] = factory();})(globalThis, function () {
5
+ else if (typeof exports === 'object') exports['loaders'] = factory();
6
+ else root['loaders'] = factory();})(globalThis, function () {
7
7
  "use strict";
8
8
  var __exports__ = (() => {
9
+ var __create = Object.create;
9
10
  var __defProp = Object.defineProperty;
10
11
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __getProtoOf = Object.getPrototypeOf;
12
14
  var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __commonJS = (cb, mod) => function __require() {
16
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
+ };
13
18
  var __export = (target, all) => {
14
19
  for (var name in all)
15
20
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -22,11 +27,27 @@ var __exports__ = (() => {
22
27
  }
23
28
  return to;
24
29
  };
30
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
+ // If the importer is in node compatibility mode or this is not an ESM
33
+ // file that has been converted to a CommonJS file using a Babel-
34
+ // compatible transform (i.e. "__esModule" has not been set), then set
35
+ // "default" to the CommonJS "module.exports" for node compatibility.
36
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
+ mod
38
+ ));
25
39
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
40
 
27
- // src/index.ts
28
- var src_exports = {};
29
- __export(src_exports, {
41
+ // external-global-plugin:@loaders.gl/core
42
+ var require_core = __commonJS({
43
+ "external-global-plugin:@loaders.gl/core"(exports, module) {
44
+ module.exports = globalThis.loaders;
45
+ }
46
+ });
47
+
48
+ // bundle.ts
49
+ var bundle_exports = {};
50
+ __export(bundle_exports, {
30
51
  HexWKBLoader: () => HexWKBLoader,
31
52
  TWKBLoader: () => TWKBLoader,
32
53
  TWKBWriter: () => TWKBWriter,
@@ -45,9 +66,10 @@ var __exports__ = (() => {
45
66
  isWKT: () => isWKT,
46
67
  parseWKBHeader: () => parseWKBHeader
47
68
  });
69
+ __reExport(bundle_exports, __toESM(require_core(), 1));
48
70
 
49
71
  // src/lib/utils/version.ts
50
- var VERSION = true ? "4.2.0-alpha.4" : "latest";
72
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
51
73
 
52
74
  // src/lib/parse-wkt-crs.ts
53
75
  function parseWKTCRS(wkt, options) {
@@ -197,6 +219,7 @@ var __exports__ = (() => {
197
219
  worker: true,
198
220
  extensions: [],
199
221
  mimeTypes: ["text/plain"],
222
+ // category: 'json',
200
223
  text: true,
201
224
  options: {
202
225
  "wkt-crs": {}
@@ -209,7 +232,16 @@ var __exports__ = (() => {
209
232
  // src/lib/parse-wkt.ts
210
233
  var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
211
234
  var tuples = new RegExp("^" + numberRegexp.source + "(\\s" + numberRegexp.source + "){1,}");
212
- var WKT_MAGIC_STRINGS = ["POINT(", "LINESTRING(", "POLYGON(", "MULTIPOINT(", "MULTILINESTRING(", "MULTIPOLYGON(", "GEOMETRYCOLLECTION("];
235
+ var WKT_MAGIC_STRINGS = [
236
+ "POINT(",
237
+ "LINESTRING(",
238
+ "POLYGON(",
239
+ "MULTIPOINT(",
240
+ "MULTILINESTRING(",
241
+ "MULTIPOLYGON(",
242
+ "GEOMETRYCOLLECTION("
243
+ // We only support this "geojson" subset of the OGC simple features standard
244
+ ];
213
245
  function isWKT(input) {
214
246
  return WKT_MAGIC_STRINGS.some((magicString) => input.startsWith(magicString));
215
247
  }
@@ -220,11 +252,7 @@ var __exports__ = (() => {
220
252
  const parts = input.split(";");
221
253
  let _ = parts.pop();
222
254
  const srid = (parts.shift() || "").split("=").pop();
223
- const state = {
224
- parts,
225
- _,
226
- i: 0
227
- };
255
+ const state = { parts, _, i: 0 };
228
256
  const geometry = parseGeometry(state);
229
257
  return options?.wkt?.crs ? addCRS(geometry, srid) : geometry;
230
258
  }
@@ -311,7 +339,9 @@ var __exports__ = (() => {
311
339
  }
312
340
  white(state);
313
341
  return {
342
+ // @ts-ignore
314
343
  type: "MultiLineString",
344
+ // @ts-expect-error
315
345
  coordinates: c
316
346
  };
317
347
  }
@@ -325,7 +355,9 @@ var __exports__ = (() => {
325
355
  return null;
326
356
  }
327
357
  return {
358
+ // @ts-ignore
328
359
  type: "Polygon",
360
+ // @ts-expect-error
329
361
  coordinates: c
330
362
  };
331
363
  }
@@ -340,6 +372,7 @@ var __exports__ = (() => {
340
372
  }
341
373
  return {
342
374
  type: "MultiPolygon",
375
+ // @ts-expect-error
343
376
  coordinates: c
344
377
  };
345
378
  }
@@ -537,11 +570,11 @@ var __exports__ = (() => {
537
570
  }
538
571
  }
539
572
  function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
540
- const {
541
- positions
542
- } = data;
573
+ const { positions } = data;
543
574
  const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
544
- const primitivePolygonIndices = data.primitivePolygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
575
+ const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(
576
+ (x) => x >= startIndex && x <= endIndex
577
+ );
545
578
  const multi = polygonIndices.length > 2;
546
579
  if (!multi) {
547
580
  const coordinates2 = [];
@@ -551,62 +584,44 @@ var __exports__ = (() => {
551
584
  const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
552
585
  coordinates2.push(ringCoordinates);
553
586
  }
554
- return {
555
- type: "Polygon",
556
- coordinates: coordinates2
557
- };
587
+ return { type: "Polygon", coordinates: coordinates2 };
558
588
  }
559
589
  const coordinates = [];
560
590
  for (let i = 0; i < polygonIndices.length - 1; i++) {
561
591
  const startPolygonIndex = polygonIndices[i];
562
592
  const endPolygonIndex = polygonIndices[i + 1];
563
- const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
593
+ const polygonCoordinates = polygonToGeoJson(
594
+ data,
595
+ startPolygonIndex,
596
+ endPolygonIndex
597
+ ).coordinates;
564
598
  coordinates.push(polygonCoordinates);
565
599
  }
566
- return {
567
- type: "MultiPolygon",
568
- coordinates
569
- };
600
+ return { type: "MultiPolygon", coordinates };
570
601
  }
571
602
  function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
572
- const {
573
- positions
574
- } = data;
603
+ const { positions } = data;
575
604
  const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
576
605
  const multi = pathIndices.length > 2;
577
606
  if (!multi) {
578
607
  const coordinates2 = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
579
- return {
580
- type: "LineString",
581
- coordinates: coordinates2
582
- };
608
+ return { type: "LineString", coordinates: coordinates2 };
583
609
  }
584
610
  const coordinates = [];
585
611
  for (let i = 0; i < pathIndices.length - 1; i++) {
586
612
  const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
587
613
  coordinates.push(ringCoordinates);
588
614
  }
589
- return {
590
- type: "MultiLineString",
591
- coordinates
592
- };
615
+ return { type: "MultiLineString", coordinates };
593
616
  }
594
617
  function pointToGeoJson(data, startIndex, endIndex) {
595
- const {
596
- positions
597
- } = data;
618
+ const { positions } = data;
598
619
  const coordinates = ringToGeoJson(positions, startIndex, endIndex);
599
620
  const multi = coordinates.length > 1;
600
621
  if (multi) {
601
- return {
602
- type: "MultiPoint",
603
- coordinates
604
- };
622
+ return { type: "MultiPoint", coordinates };
605
623
  }
606
- return {
607
- type: "Point",
608
- coordinates: coordinates[0]
609
- };
624
+ return { type: "Point", coordinates: coordinates[0] };
610
625
  }
611
626
  function ringToGeoJson(positions, startIndex, endIndex) {
612
627
  startIndex = startIndex || 0;
@@ -627,16 +642,6 @@ var __exports__ = (() => {
627
642
  var EWKB_FLAG_M = 1073741824;
628
643
  var EWKB_FLAG_SRID = 536870912;
629
644
  var MAX_SRID = 1e4;
630
- var WKBGeometryType = function(WKBGeometryType2) {
631
- WKBGeometryType2[WKBGeometryType2["Point"] = 1] = "Point";
632
- WKBGeometryType2[WKBGeometryType2["LineString"] = 2] = "LineString";
633
- WKBGeometryType2[WKBGeometryType2["Polygon"] = 3] = "Polygon";
634
- WKBGeometryType2[WKBGeometryType2["MultiPoint"] = 4] = "MultiPoint";
635
- WKBGeometryType2[WKBGeometryType2["MultiLineString"] = 5] = "MultiLineString";
636
- WKBGeometryType2[WKBGeometryType2["MultiPolygon"] = 6] = "MultiPolygon";
637
- WKBGeometryType2[WKBGeometryType2["GeometryCollection"] = 7] = "GeometryCollection";
638
- return WKBGeometryType2;
639
- }({});
640
645
  function isWKB(arrayBuffer) {
641
646
  const dataView = new DataView(arrayBuffer);
642
647
  let byteOffset = 0;
@@ -747,31 +752,27 @@ var __exports__ = (() => {
747
752
  function parseWKBToBinary(arrayBuffer, options) {
748
753
  const dataView = new DataView(arrayBuffer);
749
754
  const wkbHeader = parseWKBHeader(dataView);
750
- const {
751
- geometryType,
752
- dimensions,
753
- littleEndian
754
- } = wkbHeader;
755
+ const { geometryType, dimensions, littleEndian } = wkbHeader;
755
756
  const offset = wkbHeader.byteOffset;
756
757
  switch (geometryType) {
757
- case WKBGeometryType.Point:
758
+ case 1 /* Point */:
758
759
  const point = parsePoint2(dataView, offset, dimensions, littleEndian);
759
760
  return point.geometry;
760
- case WKBGeometryType.LineString:
761
+ case 2 /* LineString */:
761
762
  const line = parseLineString2(dataView, offset, dimensions, littleEndian);
762
763
  return line.geometry;
763
- case WKBGeometryType.Polygon:
764
+ case 3 /* Polygon */:
764
765
  const polygon = parsePolygon2(dataView, offset, dimensions, littleEndian);
765
766
  return polygon.geometry;
766
- case WKBGeometryType.MultiPoint:
767
+ case 4 /* MultiPoint */:
767
768
  const multiPoint = parseMultiPoint2(dataView, offset, dimensions, littleEndian);
768
769
  multiPoint.type = "Point";
769
770
  return multiPoint;
770
- case WKBGeometryType.MultiLineString:
771
+ case 5 /* MultiLineString */:
771
772
  const multiLine = parseMultiLineString2(dataView, offset, dimensions, littleEndian);
772
773
  multiLine.type = "LineString";
773
774
  return multiLine;
774
- case WKBGeometryType.MultiPolygon:
775
+ case 6 /* MultiPolygon */:
775
776
  const multiPolygon = parseMultiPolygon2(dataView, offset, dimensions, littleEndian);
776
777
  multiPolygon.type = "Polygon";
777
778
  return multiPolygon;
@@ -786,13 +787,7 @@ var __exports__ = (() => {
786
787
  offset += 8;
787
788
  }
788
789
  return {
789
- geometry: {
790
- type: "Point",
791
- positions: {
792
- value: positions,
793
- size: dimension
794
- }
795
- },
790
+ geometry: { type: "Point", positions: { value: positions, size: dimension } },
796
791
  offset
797
792
  };
798
793
  }
@@ -811,14 +806,8 @@ var __exports__ = (() => {
811
806
  return {
812
807
  geometry: {
813
808
  type: "LineString",
814
- positions: {
815
- value: positions,
816
- size: dimension
817
- },
818
- pathIndices: {
819
- value: new Uint16Array(pathIndices),
820
- size: 1
821
- }
809
+ positions: { value: positions, size: dimension },
810
+ pathIndices: { value: new Uint16Array(pathIndices), size: 1 }
822
811
  },
823
812
  offset
824
813
  };
@@ -830,9 +819,7 @@ var __exports__ = (() => {
830
819
  const rings = [];
831
820
  for (let i = 0; i < nRings; i++) {
832
821
  const parsed = parseLineString2(dataView, offset, dimension, littleEndian);
833
- const {
834
- positions
835
- } = parsed.geometry;
822
+ const { positions } = parsed.geometry;
836
823
  offset = parsed.offset;
837
824
  rings.push(positions.value);
838
825
  }
@@ -846,18 +833,12 @@ var __exports__ = (() => {
846
833
  return {
847
834
  geometry: {
848
835
  type: "Polygon",
849
- positions: {
850
- value: concatenatedPositions,
851
- size: dimension
852
- },
836
+ positions: { value: concatenatedPositions, size: dimension },
853
837
  polygonIndices: {
854
838
  value: new Uint16Array(polygonIndices),
855
839
  size: 1
856
840
  },
857
- primitivePolygonIndices: {
858
- value: new Uint16Array(primitivePolygonIndices),
859
- size: 1
860
- }
841
+ primitivePolygonIndices: { value: new Uint16Array(primitivePolygonIndices), size: 1 }
861
842
  },
862
843
  offset
863
844
  };
@@ -918,10 +899,7 @@ var __exports__ = (() => {
918
899
  const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
919
900
  return {
920
901
  type: "Point",
921
- positions: {
922
- value: concatenatedPositions,
923
- size: dimension
924
- }
902
+ positions: { value: concatenatedPositions, size: dimension }
925
903
  };
926
904
  }
927
905
  function concatenateBinaryLineGeometries(binaryLineGeometries, dimension) {
@@ -931,24 +909,15 @@ var __exports__ = (() => {
931
909
  pathIndices.unshift(0);
932
910
  return {
933
911
  type: "LineString",
934
- positions: {
935
- value: concatenatedPositions,
936
- size: dimension
937
- },
938
- pathIndices: {
939
- value: new Uint16Array(pathIndices),
940
- size: 1
941
- }
912
+ positions: { value: concatenatedPositions, size: dimension },
913
+ pathIndices: { value: new Uint16Array(pathIndices), size: 1 }
942
914
  };
943
915
  }
944
916
  function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension) {
945
917
  const polygons = [];
946
918
  const primitivePolygons = [];
947
919
  for (const binaryPolygon of binaryPolygonGeometries) {
948
- const {
949
- positions,
950
- primitivePolygonIndices: primitivePolygonIndices2
951
- } = binaryPolygon;
920
+ const { positions, primitivePolygonIndices: primitivePolygonIndices2 } = binaryPolygon;
952
921
  polygons.push(positions.value);
953
922
  primitivePolygons.push(primitivePolygonIndices2.value);
954
923
  }
@@ -957,22 +926,15 @@ var __exports__ = (() => {
957
926
  polygonIndices.unshift(0);
958
927
  const primitivePolygonIndices = [0];
959
928
  for (const primitivePolygon of primitivePolygons) {
960
- primitivePolygonIndices.push(...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1]));
929
+ primitivePolygonIndices.push(
930
+ ...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1])
931
+ );
961
932
  }
962
933
  return {
963
934
  type: "Polygon",
964
- positions: {
965
- value: concatenatedPositions,
966
- size: dimension
967
- },
968
- polygonIndices: {
969
- value: new Uint16Array(polygonIndices),
970
- size: 1
971
- },
972
- primitivePolygonIndices: {
973
- value: new Uint16Array(primitivePolygonIndices),
974
- size: 1
975
- }
935
+ positions: { value: concatenatedPositions, size: dimension },
936
+ polygonIndices: { value: new Uint16Array(polygonIndices), size: 1 },
937
+ primitivePolygonIndices: { value: new Uint16Array(primitivePolygonIndices), size: 1 }
976
938
  };
977
939
  }
978
940
  function concatTypedArrays(arrays) {
@@ -1002,10 +964,12 @@ var __exports__ = (() => {
1002
964
  category: "geometry",
1003
965
  extensions: ["wkb"],
1004
966
  mimeTypes: [],
967
+ // TODO can we define static, serializable tests, eg. some binary strings?
1005
968
  tests: [isWKB],
1006
969
  options: {
1007
970
  wkb: {
1008
971
  shape: "binary-geometry"
972
+ // 'geojson-geometry'
1009
973
  }
1010
974
  }
1011
975
  };
@@ -1019,9 +983,9 @@ var __exports__ = (() => {
1019
983
  var LE = true;
1020
984
  var BE = false;
1021
985
  var BinaryWriter = class {
1022
- byteOffset = 0;
1023
- allowResize = false;
1024
986
  constructor(size, allowResize) {
987
+ this.byteOffset = 0;
988
+ this.allowResize = false;
1025
989
  this.arrayBuffer = new ArrayBuffer(size);
1026
990
  this.dataView = new DataView(this.arrayBuffer);
1027
991
  this.byteOffset = 0;
@@ -1097,6 +1061,7 @@ var __exports__ = (() => {
1097
1061
  this.dataView.setFloat64(this.byteOffset, value, BE);
1098
1062
  this.byteOffset += 8;
1099
1063
  }
1064
+ /** A varint uses a variable number of bytes */
1100
1065
  writeVarInt(value) {
1101
1066
  let length = 1;
1102
1067
  while ((value & 4294967168) !== 0) {
@@ -1107,12 +1072,14 @@ var __exports__ = (() => {
1107
1072
  this.writeUInt8(value & 127);
1108
1073
  return length;
1109
1074
  }
1075
+ /** Append another ArrayBuffer to this ArrayBuffer */
1110
1076
  writeBuffer(arrayBuffer) {
1111
1077
  this._ensureSize(arrayBuffer.byteLength);
1112
1078
  const tempArray = new Uint8Array(this.arrayBuffer);
1113
1079
  tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);
1114
1080
  this.byteOffset += arrayBuffer.byteLength;
1115
1081
  }
1082
+ /** Resizes this.arrayBuffer if not enough space */
1116
1083
  _ensureSize(size) {
1117
1084
  if (this.arrayBuffer.byteLength < this.byteOffset + size) {
1118
1085
  if (this.allowResize) {
@@ -1128,16 +1095,6 @@ var __exports__ = (() => {
1128
1095
  };
1129
1096
 
1130
1097
  // src/lib/encode-wkb.ts
1131
- var WKB = function(WKB2) {
1132
- WKB2[WKB2["Point"] = 1] = "Point";
1133
- WKB2[WKB2["LineString"] = 2] = "LineString";
1134
- WKB2[WKB2["Polygon"] = 3] = "Polygon";
1135
- WKB2[WKB2["MultiPoint"] = 4] = "MultiPoint";
1136
- WKB2[WKB2["MultiLineString"] = 5] = "MultiLineString";
1137
- WKB2[WKB2["MultiPolygon"] = 6] = "MultiPolygon";
1138
- WKB2[WKB2["GeometryCollection"] = 7] = "GeometryCollection";
1139
- return WKB2;
1140
- }({});
1141
1098
  function encodeWKB(geometry, options = {}) {
1142
1099
  if (geometry.type === "Feature") {
1143
1100
  geometry = geometry.geometry;
@@ -1186,7 +1143,7 @@ var __exports__ = (() => {
1186
1143
  function encodePoint(coordinates, options) {
1187
1144
  const writer = new BinaryWriter(getPointSize(options));
1188
1145
  writer.writeInt8(1);
1189
- writeWkbType(writer, WKB.Point, options);
1146
+ writeWkbType(writer, 1 /* Point */, options);
1190
1147
  if (typeof coordinates[0] === "undefined" && typeof coordinates[1] === "undefined") {
1191
1148
  writer.writeDoubleLE(NaN);
1192
1149
  writer.writeDoubleLE(NaN);
@@ -1219,7 +1176,7 @@ var __exports__ = (() => {
1219
1176
  const size = getLineStringSize(coordinates, options);
1220
1177
  const writer = new BinaryWriter(size);
1221
1178
  writer.writeInt8(1);
1222
- writeWkbType(writer, WKB.LineString, options);
1179
+ writeWkbType(writer, 2 /* LineString */, options);
1223
1180
  writer.writeUInt32LE(coordinates.length);
1224
1181
  for (const coordinate of coordinates) {
1225
1182
  writeCoordinate(writer, coordinate, options);
@@ -1233,7 +1190,7 @@ var __exports__ = (() => {
1233
1190
  function encodePolygon(coordinates, options) {
1234
1191
  const writer = new BinaryWriter(getPolygonSize(coordinates, options));
1235
1192
  writer.writeInt8(1);
1236
- writeWkbType(writer, WKB.Polygon, options);
1193
+ writeWkbType(writer, 3 /* Polygon */, options);
1237
1194
  const [exteriorRing, ...interiorRings] = coordinates;
1238
1195
  if (exteriorRing.length > 0) {
1239
1196
  writer.writeUInt32LE(1 + interiorRings.length);
@@ -1268,7 +1225,7 @@ var __exports__ = (() => {
1268
1225
  const writer = new BinaryWriter(getMultiPointSize(multiPoint, options));
1269
1226
  const points = multiPoint.coordinates;
1270
1227
  writer.writeInt8(1);
1271
- writeWkbType(writer, WKB.MultiPoint, options);
1228
+ writeWkbType(writer, 4 /* MultiPoint */, options);
1272
1229
  writer.writeUInt32LE(points.length);
1273
1230
  for (const point of points) {
1274
1231
  const arrayBuffer = encodePoint(point, options);
@@ -1286,7 +1243,7 @@ var __exports__ = (() => {
1286
1243
  const writer = new BinaryWriter(getMultiLineStringSize(multiLineString, options));
1287
1244
  const lineStrings = multiLineString.coordinates;
1288
1245
  writer.writeInt8(1);
1289
- writeWkbType(writer, WKB.MultiLineString, options);
1246
+ writeWkbType(writer, 5 /* MultiLineString */, options);
1290
1247
  writer.writeUInt32LE(lineStrings.length);
1291
1248
  for (const lineString of lineStrings) {
1292
1249
  const encodedLineString = encodeLineString(lineString, options);
@@ -1306,7 +1263,7 @@ var __exports__ = (() => {
1306
1263
  const writer = new BinaryWriter(getMultiPolygonSize(multiPolygon, options));
1307
1264
  const polygons = multiPolygon.coordinates;
1308
1265
  writer.writeInt8(1);
1309
- writeWkbType(writer, WKB.MultiPolygon, options);
1266
+ writeWkbType(writer, 6 /* MultiPolygon */, options);
1310
1267
  writer.writeUInt32LE(polygons.length);
1311
1268
  for (const polygon of polygons) {
1312
1269
  const encodedPolygon = encodePolygon(polygon, options);
@@ -1325,7 +1282,7 @@ var __exports__ = (() => {
1325
1282
  function encodeGeometryCollection(collection, options) {
1326
1283
  const writer = new BinaryWriter(getGeometryCollectionSize(collection, options));
1327
1284
  writer.writeInt8(1);
1328
- writeWkbType(writer, WKB.GeometryCollection, options);
1285
+ writeWkbType(writer, 7 /* GeometryCollection */, options);
1329
1286
  writer.writeUInt32LE(collection.geometries.length);
1330
1287
  for (const geometry of collection.geometries) {
1331
1288
  const arrayBuffer = encodeWKB(geometry, options);
@@ -1341,11 +1298,7 @@ var __exports__ = (() => {
1341
1298
  return size;
1342
1299
  }
1343
1300
  function writeWkbType(writer, geometryType, options) {
1344
- const {
1345
- hasZ,
1346
- hasM,
1347
- srid
1348
- } = options;
1301
+ const { hasZ, hasM, srid } = options;
1349
1302
  let dimensionType = 0;
1350
1303
  if (!srid) {
1351
1304
  if (hasZ && hasM) {
@@ -1445,6 +1398,7 @@ var __exports__ = (() => {
1445
1398
  options: WKBLoader.options,
1446
1399
  text: true,
1447
1400
  testText: isHexWKB,
1401
+ // TODO - encoding here seems wasteful - extend hex transcoder?
1448
1402
  parse: async (arrayBuffer) => parseHexWKB(new TextDecoder().decode(arrayBuffer)),
1449
1403
  parseTextSync: parseHexWKB
1450
1404
  };
@@ -1599,19 +1553,19 @@ var __exports__ = (() => {
1599
1553
  }
1600
1554
  function parseGeometry2(binaryReader, context, geometryType) {
1601
1555
  switch (geometryType) {
1602
- case WKBGeometryType.Point:
1556
+ case 1 /* Point */:
1603
1557
  return parsePoint3(binaryReader, context);
1604
- case WKBGeometryType.LineString:
1558
+ case 2 /* LineString */:
1605
1559
  return parseLineString3(binaryReader, context);
1606
- case WKBGeometryType.Polygon:
1560
+ case 3 /* Polygon */:
1607
1561
  return parsePolygon3(binaryReader, context);
1608
- case WKBGeometryType.MultiPoint:
1562
+ case 4 /* MultiPoint */:
1609
1563
  return parseMultiPoint3(binaryReader, context);
1610
- case WKBGeometryType.MultiLineString:
1564
+ case 5 /* MultiLineString */:
1611
1565
  return parseMultiLineString3(binaryReader, context);
1612
- case WKBGeometryType.MultiPolygon:
1566
+ case 6 /* MultiPolygon */:
1613
1567
  return parseMultiPolygon3(binaryReader, context);
1614
- case WKBGeometryType.GeometryCollection:
1568
+ case 7 /* GeometryCollection */:
1615
1569
  return parseGeometryCollection2(binaryReader, context);
1616
1570
  default:
1617
1571
  throw new Error(`GeometryType ${geometryType} not supported`);
@@ -1619,22 +1573,13 @@ var __exports__ = (() => {
1619
1573
  }
1620
1574
  function parsePoint3(reader, context) {
1621
1575
  if (context.isEmpty) {
1622
- return {
1623
- type: "Point",
1624
- coordinates: []
1625
- };
1576
+ return { type: "Point", coordinates: [] };
1626
1577
  }
1627
- return {
1628
- type: "Point",
1629
- coordinates: readFirstPoint(reader, context)
1630
- };
1578
+ return { type: "Point", coordinates: readFirstPoint(reader, context) };
1631
1579
  }
1632
1580
  function parseLineString3(reader, context) {
1633
1581
  if (context.isEmpty) {
1634
- return {
1635
- type: "LineString",
1636
- coordinates: []
1637
- };
1582
+ return { type: "LineString", coordinates: [] };
1638
1583
  }
1639
1584
  const pointCount = reader.readVarInt();
1640
1585
  const previousPoint = makePreviousPoint(context);
@@ -1642,17 +1587,11 @@ var __exports__ = (() => {
1642
1587
  for (let i = 0; i < pointCount; i++) {
1643
1588
  points.push(parseNextPoint(reader, context, previousPoint));
1644
1589
  }
1645
- return {
1646
- type: "LineString",
1647
- coordinates: points
1648
- };
1590
+ return { type: "LineString", coordinates: points };
1649
1591
  }
1650
1592
  function parsePolygon3(reader, context) {
1651
1593
  if (context.isEmpty) {
1652
- return {
1653
- type: "Polygon",
1654
- coordinates: []
1655
- };
1594
+ return { type: "Polygon", coordinates: [] };
1656
1595
  }
1657
1596
  const ringCount = reader.readVarInt();
1658
1597
  const previousPoint = makePreviousPoint(context);
@@ -1670,17 +1609,11 @@ var __exports__ = (() => {
1670
1609
  }
1671
1610
  polygon.push(interiorRing);
1672
1611
  }
1673
- return {
1674
- type: "Polygon",
1675
- coordinates: polygon
1676
- };
1612
+ return { type: "Polygon", coordinates: polygon };
1677
1613
  }
1678
1614
  function parseMultiPoint3(reader, context) {
1679
1615
  if (context.isEmpty) {
1680
- return {
1681
- type: "MultiPoint",
1682
- coordinates: []
1683
- };
1616
+ return { type: "MultiPoint", coordinates: [] };
1684
1617
  }
1685
1618
  const previousPoint = makePreviousPoint(context);
1686
1619
  const pointCount = reader.readVarInt();
@@ -1688,17 +1621,11 @@ var __exports__ = (() => {
1688
1621
  for (let i = 0; i < pointCount; i++) {
1689
1622
  coordinates.push(parseNextPoint(reader, context, previousPoint));
1690
1623
  }
1691
- return {
1692
- type: "MultiPoint",
1693
- coordinates
1694
- };
1624
+ return { type: "MultiPoint", coordinates };
1695
1625
  }
1696
1626
  function parseMultiLineString3(reader, context) {
1697
1627
  if (context.isEmpty) {
1698
- return {
1699
- type: "MultiLineString",
1700
- coordinates: []
1701
- };
1628
+ return { type: "MultiLineString", coordinates: [] };
1702
1629
  }
1703
1630
  const previousPoint = makePreviousPoint(context);
1704
1631
  const lineStringCount = reader.readVarInt();
@@ -1711,17 +1638,11 @@ var __exports__ = (() => {
1711
1638
  }
1712
1639
  coordinates.push(lineString);
1713
1640
  }
1714
- return {
1715
- type: "MultiLineString",
1716
- coordinates
1717
- };
1641
+ return { type: "MultiLineString", coordinates };
1718
1642
  }
1719
1643
  function parseMultiPolygon3(reader, context) {
1720
1644
  if (context.isEmpty) {
1721
- return {
1722
- type: "MultiPolygon",
1723
- coordinates: []
1724
- };
1645
+ return { type: "MultiPolygon", coordinates: [] };
1725
1646
  }
1726
1647
  const previousPoint = makePreviousPoint(context);
1727
1648
  const polygonCount = reader.readVarInt();
@@ -1744,16 +1665,10 @@ var __exports__ = (() => {
1744
1665
  }
1745
1666
  polygons.push(polygon);
1746
1667
  }
1747
- return {
1748
- type: "MultiPolygon",
1749
- coordinates: polygons
1750
- };
1668
+ return { type: "MultiPolygon", coordinates: polygons };
1751
1669
  }
1752
1670
  function parseGeometryCollection2(reader, context) {
1753
- return {
1754
- type: "GeometryCollection",
1755
- geometries: []
1756
- };
1671
+ return { type: "GeometryCollection", geometries: [] };
1757
1672
  }
1758
1673
  function zigZagDecode(value) {
1759
1674
  return value >> 1 ^ -(value & 1);
@@ -1793,10 +1708,12 @@ var __exports__ = (() => {
1793
1708
  category: "geometry",
1794
1709
  extensions: ["twkb"],
1795
1710
  mimeTypes: [],
1711
+ // TODO can we define static, serializable tests, eg. some binary strings?
1796
1712
  tests: [isTWKB],
1797
1713
  options: {
1798
1714
  wkb: {
1799
1715
  shape: "binary-geometry"
1716
+ // 'geojson-geometry'
1800
1717
  }
1801
1718
  }
1802
1719
  };
@@ -1839,7 +1756,7 @@ var __exports__ = (() => {
1839
1756
  }
1840
1757
  function encodePoint2(writer, context, point) {
1841
1758
  const isEmpty = point.coordinates.length === 0 || point[0] === "undefined" || point[1] === "undefined";
1842
- writeTwkbHeader(writer, context, WKBGeometryType.Point, isEmpty);
1759
+ writeTwkbHeader(writer, context, 1 /* Point */, isEmpty);
1843
1760
  if (!isEmpty) {
1844
1761
  const previousPoint = [0, 0, 0, 0];
1845
1762
  writeTwkbPoint(writer, context, point.coordinates, previousPoint);
@@ -1848,7 +1765,7 @@ var __exports__ = (() => {
1848
1765
  function encodeLineString2(writer, context, lineString) {
1849
1766
  const points = lineString.coordinates;
1850
1767
  const isEmpty = points.length === 0;
1851
- writeTwkbHeader(writer, context, WKBGeometryType.LineString, isEmpty);
1768
+ writeTwkbHeader(writer, context, 2 /* LineString */, isEmpty);
1852
1769
  if (!isEmpty) {
1853
1770
  writer.writeVarInt(points.length);
1854
1771
  const previousPoint = [0, 0, 0, 0];
@@ -1861,7 +1778,7 @@ var __exports__ = (() => {
1861
1778
  function encodePolygon2(writer, context, polygon) {
1862
1779
  const polygonRings = polygon.coordinates;
1863
1780
  const isEmpty = polygonRings.length === 0;
1864
- writeTwkbHeader(writer, context, WKBGeometryType.Polygon, isEmpty);
1781
+ writeTwkbHeader(writer, context, 3 /* Polygon */, isEmpty);
1865
1782
  if (!isEmpty) {
1866
1783
  writer.writeVarInt(polygonRings.length);
1867
1784
  const previousPoint = [0, 0, 0, 0];
@@ -1877,7 +1794,7 @@ var __exports__ = (() => {
1877
1794
  function encodeMultiPoint2(writer, context, multiPoint) {
1878
1795
  const points = multiPoint.coordinates;
1879
1796
  const isEmpty = points.length === 0;
1880
- writeTwkbHeader(writer, context, WKBGeometryType.MultiPoint, isEmpty);
1797
+ writeTwkbHeader(writer, context, 4 /* MultiPoint */, isEmpty);
1881
1798
  if (!isEmpty) {
1882
1799
  writer.writeVarInt(points.length);
1883
1800
  const previousPoint = [0, 0, 0, 0];
@@ -1889,7 +1806,7 @@ var __exports__ = (() => {
1889
1806
  function encodeMultiLineString2(writer, context, multiLineStrings) {
1890
1807
  const lineStrings = multiLineStrings.coordinates;
1891
1808
  const isEmpty = lineStrings.length === 0;
1892
- writeTwkbHeader(writer, context, WKBGeometryType.MultiLineString, isEmpty);
1809
+ writeTwkbHeader(writer, context, 5 /* MultiLineString */, isEmpty);
1893
1810
  if (!isEmpty) {
1894
1811
  writer.writeVarInt(lineStrings.length);
1895
1812
  const previousPoint = [0, 0, 0, 0];
@@ -1903,11 +1820,9 @@ var __exports__ = (() => {
1903
1820
  return writer.arrayBuffer;
1904
1821
  }
1905
1822
  function encodeMultiPolygon2(writer, context, multiPolygon) {
1906
- const {
1907
- coordinates
1908
- } = multiPolygon;
1823
+ const { coordinates } = multiPolygon;
1909
1824
  const isEmpty = coordinates.length === 0;
1910
- writeTwkbHeader(writer, context, WKBGeometryType.MultiPolygon, isEmpty);
1825
+ writeTwkbHeader(writer, context, 6 /* MultiPolygon */, isEmpty);
1911
1826
  if (!isEmpty) {
1912
1827
  const polygons = coordinates;
1913
1828
  writer.writeVarInt(polygons.length);
@@ -1924,11 +1839,9 @@ var __exports__ = (() => {
1924
1839
  }
1925
1840
  }
1926
1841
  function encodeGeometryCollection2(writer, context, geometryCollection) {
1927
- const {
1928
- geometries
1929
- } = geometryCollection;
1842
+ const { geometries } = geometryCollection;
1930
1843
  const isEmpty = geometries.length === 0;
1931
- writeTwkbHeader(writer, context, WKBGeometryType.GeometryCollection, isEmpty);
1844
+ writeTwkbHeader(writer, context, 7 /* GeometryCollection */, isEmpty);
1932
1845
  if (geometries.length > 0) {
1933
1846
  writer.writeVarInt(geometries.length);
1934
1847
  for (const geometry of geometries) {
@@ -2001,7 +1914,7 @@ var __exports__ = (() => {
2001
1914
  }
2002
1915
  }
2003
1916
  };
2004
- return __toCommonJS(src_exports);
1917
+ return __toCommonJS(bundle_exports);
2005
1918
  })();
2006
1919
  return __exports__;
2007
1920
  });