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

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 (75) hide show
  1. package/dist/dist.dev.js +137 -218
  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 +87 -62
  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 +67 -64
  27. package/dist/lib/utils/binary-writer.js +117 -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 +7 -2
  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-worker.js +4 -2
  43. package/dist/wkt-writer.js +19 -14
  44. package/dist/workers/wkb-worker.js +3 -1
  45. package/dist/workers/wkt-worker.js +3 -1
  46. package/package.json +11 -6
  47. package/src/lib/parse-wkb.ts +2 -2
  48. package/dist/hex-wkb-loader.js.map +0 -1
  49. package/dist/index.js.map +0 -1
  50. package/dist/lib/encode-twkb.js.map +0 -1
  51. package/dist/lib/encode-wkb.js.map +0 -1
  52. package/dist/lib/encode-wkt-crs.js.map +0 -1
  53. package/dist/lib/encode-wkt.js.map +0 -1
  54. package/dist/lib/parse-hex-wkb.js.map +0 -1
  55. package/dist/lib/parse-twkb.js.map +0 -1
  56. package/dist/lib/parse-wkb-header.js.map +0 -1
  57. package/dist/lib/parse-wkb.js.map +0 -1
  58. package/dist/lib/parse-wkt-crs.js.map +0 -1
  59. package/dist/lib/parse-wkt.js.map +0 -1
  60. package/dist/lib/utils/base64-encoder.js.map +0 -1
  61. package/dist/lib/utils/binary-reader.js.map +0 -1
  62. package/dist/lib/utils/binary-writer.js.map +0 -1
  63. package/dist/lib/utils/hex-encoder.js.map +0 -1
  64. package/dist/lib/utils/hex-transcoder.js.map +0 -1
  65. package/dist/lib/utils/version.js.map +0 -1
  66. package/dist/twkb-loader.js.map +0 -1
  67. package/dist/twkb-writer.js.map +0 -1
  68. package/dist/wkb-loader.js.map +0 -1
  69. package/dist/wkb-writer.js.map +0 -1
  70. package/dist/wkt-crs-loader.js.map +0 -1
  71. package/dist/wkt-crs-writer.js.map +0 -1
  72. package/dist/wkt-loader.js.map +0 -1
  73. package/dist/wkt-writer.js.map +0 -1
  74. package/dist/workers/wkb-worker.js.map +0 -1
  75. 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 Uint32Array(polygonIndices), size: 1 },
937
+ primitivePolygonIndices: { value: new Uint32Array(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,6 +983,8 @@ var __exports__ = (() => {
1019
983
  var LE = true;
1020
984
  var BE = false;
1021
985
  var BinaryWriter = class {
986
+ arrayBuffer;
987
+ dataView;
1022
988
  byteOffset = 0;
1023
989
  allowResize = false;
1024
990
  constructor(size, allowResize) {
@@ -1097,6 +1063,7 @@ var __exports__ = (() => {
1097
1063
  this.dataView.setFloat64(this.byteOffset, value, BE);
1098
1064
  this.byteOffset += 8;
1099
1065
  }
1066
+ /** A varint uses a variable number of bytes */
1100
1067
  writeVarInt(value) {
1101
1068
  let length = 1;
1102
1069
  while ((value & 4294967168) !== 0) {
@@ -1107,12 +1074,14 @@ var __exports__ = (() => {
1107
1074
  this.writeUInt8(value & 127);
1108
1075
  return length;
1109
1076
  }
1077
+ /** Append another ArrayBuffer to this ArrayBuffer */
1110
1078
  writeBuffer(arrayBuffer) {
1111
1079
  this._ensureSize(arrayBuffer.byteLength);
1112
1080
  const tempArray = new Uint8Array(this.arrayBuffer);
1113
1081
  tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);
1114
1082
  this.byteOffset += arrayBuffer.byteLength;
1115
1083
  }
1084
+ /** Resizes this.arrayBuffer if not enough space */
1116
1085
  _ensureSize(size) {
1117
1086
  if (this.arrayBuffer.byteLength < this.byteOffset + size) {
1118
1087
  if (this.allowResize) {
@@ -1128,16 +1097,6 @@ var __exports__ = (() => {
1128
1097
  };
1129
1098
 
1130
1099
  // 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
1100
  function encodeWKB(geometry, options = {}) {
1142
1101
  if (geometry.type === "Feature") {
1143
1102
  geometry = geometry.geometry;
@@ -1186,7 +1145,7 @@ var __exports__ = (() => {
1186
1145
  function encodePoint(coordinates, options) {
1187
1146
  const writer = new BinaryWriter(getPointSize(options));
1188
1147
  writer.writeInt8(1);
1189
- writeWkbType(writer, WKB.Point, options);
1148
+ writeWkbType(writer, 1 /* Point */, options);
1190
1149
  if (typeof coordinates[0] === "undefined" && typeof coordinates[1] === "undefined") {
1191
1150
  writer.writeDoubleLE(NaN);
1192
1151
  writer.writeDoubleLE(NaN);
@@ -1219,7 +1178,7 @@ var __exports__ = (() => {
1219
1178
  const size = getLineStringSize(coordinates, options);
1220
1179
  const writer = new BinaryWriter(size);
1221
1180
  writer.writeInt8(1);
1222
- writeWkbType(writer, WKB.LineString, options);
1181
+ writeWkbType(writer, 2 /* LineString */, options);
1223
1182
  writer.writeUInt32LE(coordinates.length);
1224
1183
  for (const coordinate of coordinates) {
1225
1184
  writeCoordinate(writer, coordinate, options);
@@ -1233,7 +1192,7 @@ var __exports__ = (() => {
1233
1192
  function encodePolygon(coordinates, options) {
1234
1193
  const writer = new BinaryWriter(getPolygonSize(coordinates, options));
1235
1194
  writer.writeInt8(1);
1236
- writeWkbType(writer, WKB.Polygon, options);
1195
+ writeWkbType(writer, 3 /* Polygon */, options);
1237
1196
  const [exteriorRing, ...interiorRings] = coordinates;
1238
1197
  if (exteriorRing.length > 0) {
1239
1198
  writer.writeUInt32LE(1 + interiorRings.length);
@@ -1268,7 +1227,7 @@ var __exports__ = (() => {
1268
1227
  const writer = new BinaryWriter(getMultiPointSize(multiPoint, options));
1269
1228
  const points = multiPoint.coordinates;
1270
1229
  writer.writeInt8(1);
1271
- writeWkbType(writer, WKB.MultiPoint, options);
1230
+ writeWkbType(writer, 4 /* MultiPoint */, options);
1272
1231
  writer.writeUInt32LE(points.length);
1273
1232
  for (const point of points) {
1274
1233
  const arrayBuffer = encodePoint(point, options);
@@ -1286,7 +1245,7 @@ var __exports__ = (() => {
1286
1245
  const writer = new BinaryWriter(getMultiLineStringSize(multiLineString, options));
1287
1246
  const lineStrings = multiLineString.coordinates;
1288
1247
  writer.writeInt8(1);
1289
- writeWkbType(writer, WKB.MultiLineString, options);
1248
+ writeWkbType(writer, 5 /* MultiLineString */, options);
1290
1249
  writer.writeUInt32LE(lineStrings.length);
1291
1250
  for (const lineString of lineStrings) {
1292
1251
  const encodedLineString = encodeLineString(lineString, options);
@@ -1306,7 +1265,7 @@ var __exports__ = (() => {
1306
1265
  const writer = new BinaryWriter(getMultiPolygonSize(multiPolygon, options));
1307
1266
  const polygons = multiPolygon.coordinates;
1308
1267
  writer.writeInt8(1);
1309
- writeWkbType(writer, WKB.MultiPolygon, options);
1268
+ writeWkbType(writer, 6 /* MultiPolygon */, options);
1310
1269
  writer.writeUInt32LE(polygons.length);
1311
1270
  for (const polygon of polygons) {
1312
1271
  const encodedPolygon = encodePolygon(polygon, options);
@@ -1325,7 +1284,7 @@ var __exports__ = (() => {
1325
1284
  function encodeGeometryCollection(collection, options) {
1326
1285
  const writer = new BinaryWriter(getGeometryCollectionSize(collection, options));
1327
1286
  writer.writeInt8(1);
1328
- writeWkbType(writer, WKB.GeometryCollection, options);
1287
+ writeWkbType(writer, 7 /* GeometryCollection */, options);
1329
1288
  writer.writeUInt32LE(collection.geometries.length);
1330
1289
  for (const geometry of collection.geometries) {
1331
1290
  const arrayBuffer = encodeWKB(geometry, options);
@@ -1341,11 +1300,7 @@ var __exports__ = (() => {
1341
1300
  return size;
1342
1301
  }
1343
1302
  function writeWkbType(writer, geometryType, options) {
1344
- const {
1345
- hasZ,
1346
- hasM,
1347
- srid
1348
- } = options;
1303
+ const { hasZ, hasM, srid } = options;
1349
1304
  let dimensionType = 0;
1350
1305
  if (!srid) {
1351
1306
  if (hasZ && hasM) {
@@ -1445,6 +1400,7 @@ var __exports__ = (() => {
1445
1400
  options: WKBLoader.options,
1446
1401
  text: true,
1447
1402
  testText: isHexWKB,
1403
+ // TODO - encoding here seems wasteful - extend hex transcoder?
1448
1404
  parse: async (arrayBuffer) => parseHexWKB(new TextDecoder().decode(arrayBuffer)),
1449
1405
  parseTextSync: parseHexWKB
1450
1406
  };
@@ -1468,6 +1424,10 @@ var __exports__ = (() => {
1468
1424
 
1469
1425
  // src/lib/utils/binary-reader.ts
1470
1426
  var BinaryReader = class {
1427
+ arrayBuffer;
1428
+ dataView;
1429
+ byteOffset;
1430
+ littleEndian;
1471
1431
  constructor(arrayBuffer, isBigEndian = false) {
1472
1432
  this.arrayBuffer = arrayBuffer;
1473
1433
  this.dataView = new DataView(arrayBuffer);
@@ -1599,19 +1559,19 @@ var __exports__ = (() => {
1599
1559
  }
1600
1560
  function parseGeometry2(binaryReader, context, geometryType) {
1601
1561
  switch (geometryType) {
1602
- case WKBGeometryType.Point:
1562
+ case 1 /* Point */:
1603
1563
  return parsePoint3(binaryReader, context);
1604
- case WKBGeometryType.LineString:
1564
+ case 2 /* LineString */:
1605
1565
  return parseLineString3(binaryReader, context);
1606
- case WKBGeometryType.Polygon:
1566
+ case 3 /* Polygon */:
1607
1567
  return parsePolygon3(binaryReader, context);
1608
- case WKBGeometryType.MultiPoint:
1568
+ case 4 /* MultiPoint */:
1609
1569
  return parseMultiPoint3(binaryReader, context);
1610
- case WKBGeometryType.MultiLineString:
1570
+ case 5 /* MultiLineString */:
1611
1571
  return parseMultiLineString3(binaryReader, context);
1612
- case WKBGeometryType.MultiPolygon:
1572
+ case 6 /* MultiPolygon */:
1613
1573
  return parseMultiPolygon3(binaryReader, context);
1614
- case WKBGeometryType.GeometryCollection:
1574
+ case 7 /* GeometryCollection */:
1615
1575
  return parseGeometryCollection2(binaryReader, context);
1616
1576
  default:
1617
1577
  throw new Error(`GeometryType ${geometryType} not supported`);
@@ -1619,22 +1579,13 @@ var __exports__ = (() => {
1619
1579
  }
1620
1580
  function parsePoint3(reader, context) {
1621
1581
  if (context.isEmpty) {
1622
- return {
1623
- type: "Point",
1624
- coordinates: []
1625
- };
1582
+ return { type: "Point", coordinates: [] };
1626
1583
  }
1627
- return {
1628
- type: "Point",
1629
- coordinates: readFirstPoint(reader, context)
1630
- };
1584
+ return { type: "Point", coordinates: readFirstPoint(reader, context) };
1631
1585
  }
1632
1586
  function parseLineString3(reader, context) {
1633
1587
  if (context.isEmpty) {
1634
- return {
1635
- type: "LineString",
1636
- coordinates: []
1637
- };
1588
+ return { type: "LineString", coordinates: [] };
1638
1589
  }
1639
1590
  const pointCount = reader.readVarInt();
1640
1591
  const previousPoint = makePreviousPoint(context);
@@ -1642,17 +1593,11 @@ var __exports__ = (() => {
1642
1593
  for (let i = 0; i < pointCount; i++) {
1643
1594
  points.push(parseNextPoint(reader, context, previousPoint));
1644
1595
  }
1645
- return {
1646
- type: "LineString",
1647
- coordinates: points
1648
- };
1596
+ return { type: "LineString", coordinates: points };
1649
1597
  }
1650
1598
  function parsePolygon3(reader, context) {
1651
1599
  if (context.isEmpty) {
1652
- return {
1653
- type: "Polygon",
1654
- coordinates: []
1655
- };
1600
+ return { type: "Polygon", coordinates: [] };
1656
1601
  }
1657
1602
  const ringCount = reader.readVarInt();
1658
1603
  const previousPoint = makePreviousPoint(context);
@@ -1670,17 +1615,11 @@ var __exports__ = (() => {
1670
1615
  }
1671
1616
  polygon.push(interiorRing);
1672
1617
  }
1673
- return {
1674
- type: "Polygon",
1675
- coordinates: polygon
1676
- };
1618
+ return { type: "Polygon", coordinates: polygon };
1677
1619
  }
1678
1620
  function parseMultiPoint3(reader, context) {
1679
1621
  if (context.isEmpty) {
1680
- return {
1681
- type: "MultiPoint",
1682
- coordinates: []
1683
- };
1622
+ return { type: "MultiPoint", coordinates: [] };
1684
1623
  }
1685
1624
  const previousPoint = makePreviousPoint(context);
1686
1625
  const pointCount = reader.readVarInt();
@@ -1688,17 +1627,11 @@ var __exports__ = (() => {
1688
1627
  for (let i = 0; i < pointCount; i++) {
1689
1628
  coordinates.push(parseNextPoint(reader, context, previousPoint));
1690
1629
  }
1691
- return {
1692
- type: "MultiPoint",
1693
- coordinates
1694
- };
1630
+ return { type: "MultiPoint", coordinates };
1695
1631
  }
1696
1632
  function parseMultiLineString3(reader, context) {
1697
1633
  if (context.isEmpty) {
1698
- return {
1699
- type: "MultiLineString",
1700
- coordinates: []
1701
- };
1634
+ return { type: "MultiLineString", coordinates: [] };
1702
1635
  }
1703
1636
  const previousPoint = makePreviousPoint(context);
1704
1637
  const lineStringCount = reader.readVarInt();
@@ -1711,17 +1644,11 @@ var __exports__ = (() => {
1711
1644
  }
1712
1645
  coordinates.push(lineString);
1713
1646
  }
1714
- return {
1715
- type: "MultiLineString",
1716
- coordinates
1717
- };
1647
+ return { type: "MultiLineString", coordinates };
1718
1648
  }
1719
1649
  function parseMultiPolygon3(reader, context) {
1720
1650
  if (context.isEmpty) {
1721
- return {
1722
- type: "MultiPolygon",
1723
- coordinates: []
1724
- };
1651
+ return { type: "MultiPolygon", coordinates: [] };
1725
1652
  }
1726
1653
  const previousPoint = makePreviousPoint(context);
1727
1654
  const polygonCount = reader.readVarInt();
@@ -1744,16 +1671,10 @@ var __exports__ = (() => {
1744
1671
  }
1745
1672
  polygons.push(polygon);
1746
1673
  }
1747
- return {
1748
- type: "MultiPolygon",
1749
- coordinates: polygons
1750
- };
1674
+ return { type: "MultiPolygon", coordinates: polygons };
1751
1675
  }
1752
1676
  function parseGeometryCollection2(reader, context) {
1753
- return {
1754
- type: "GeometryCollection",
1755
- geometries: []
1756
- };
1677
+ return { type: "GeometryCollection", geometries: [] };
1757
1678
  }
1758
1679
  function zigZagDecode(value) {
1759
1680
  return value >> 1 ^ -(value & 1);
@@ -1793,10 +1714,12 @@ var __exports__ = (() => {
1793
1714
  category: "geometry",
1794
1715
  extensions: ["twkb"],
1795
1716
  mimeTypes: [],
1717
+ // TODO can we define static, serializable tests, eg. some binary strings?
1796
1718
  tests: [isTWKB],
1797
1719
  options: {
1798
1720
  wkb: {
1799
1721
  shape: "binary-geometry"
1722
+ // 'geojson-geometry'
1800
1723
  }
1801
1724
  }
1802
1725
  };
@@ -1839,7 +1762,7 @@ var __exports__ = (() => {
1839
1762
  }
1840
1763
  function encodePoint2(writer, context, point) {
1841
1764
  const isEmpty = point.coordinates.length === 0 || point[0] === "undefined" || point[1] === "undefined";
1842
- writeTwkbHeader(writer, context, WKBGeometryType.Point, isEmpty);
1765
+ writeTwkbHeader(writer, context, 1 /* Point */, isEmpty);
1843
1766
  if (!isEmpty) {
1844
1767
  const previousPoint = [0, 0, 0, 0];
1845
1768
  writeTwkbPoint(writer, context, point.coordinates, previousPoint);
@@ -1848,7 +1771,7 @@ var __exports__ = (() => {
1848
1771
  function encodeLineString2(writer, context, lineString) {
1849
1772
  const points = lineString.coordinates;
1850
1773
  const isEmpty = points.length === 0;
1851
- writeTwkbHeader(writer, context, WKBGeometryType.LineString, isEmpty);
1774
+ writeTwkbHeader(writer, context, 2 /* LineString */, isEmpty);
1852
1775
  if (!isEmpty) {
1853
1776
  writer.writeVarInt(points.length);
1854
1777
  const previousPoint = [0, 0, 0, 0];
@@ -1861,7 +1784,7 @@ var __exports__ = (() => {
1861
1784
  function encodePolygon2(writer, context, polygon) {
1862
1785
  const polygonRings = polygon.coordinates;
1863
1786
  const isEmpty = polygonRings.length === 0;
1864
- writeTwkbHeader(writer, context, WKBGeometryType.Polygon, isEmpty);
1787
+ writeTwkbHeader(writer, context, 3 /* Polygon */, isEmpty);
1865
1788
  if (!isEmpty) {
1866
1789
  writer.writeVarInt(polygonRings.length);
1867
1790
  const previousPoint = [0, 0, 0, 0];
@@ -1877,7 +1800,7 @@ var __exports__ = (() => {
1877
1800
  function encodeMultiPoint2(writer, context, multiPoint) {
1878
1801
  const points = multiPoint.coordinates;
1879
1802
  const isEmpty = points.length === 0;
1880
- writeTwkbHeader(writer, context, WKBGeometryType.MultiPoint, isEmpty);
1803
+ writeTwkbHeader(writer, context, 4 /* MultiPoint */, isEmpty);
1881
1804
  if (!isEmpty) {
1882
1805
  writer.writeVarInt(points.length);
1883
1806
  const previousPoint = [0, 0, 0, 0];
@@ -1889,7 +1812,7 @@ var __exports__ = (() => {
1889
1812
  function encodeMultiLineString2(writer, context, multiLineStrings) {
1890
1813
  const lineStrings = multiLineStrings.coordinates;
1891
1814
  const isEmpty = lineStrings.length === 0;
1892
- writeTwkbHeader(writer, context, WKBGeometryType.MultiLineString, isEmpty);
1815
+ writeTwkbHeader(writer, context, 5 /* MultiLineString */, isEmpty);
1893
1816
  if (!isEmpty) {
1894
1817
  writer.writeVarInt(lineStrings.length);
1895
1818
  const previousPoint = [0, 0, 0, 0];
@@ -1903,11 +1826,9 @@ var __exports__ = (() => {
1903
1826
  return writer.arrayBuffer;
1904
1827
  }
1905
1828
  function encodeMultiPolygon2(writer, context, multiPolygon) {
1906
- const {
1907
- coordinates
1908
- } = multiPolygon;
1829
+ const { coordinates } = multiPolygon;
1909
1830
  const isEmpty = coordinates.length === 0;
1910
- writeTwkbHeader(writer, context, WKBGeometryType.MultiPolygon, isEmpty);
1831
+ writeTwkbHeader(writer, context, 6 /* MultiPolygon */, isEmpty);
1911
1832
  if (!isEmpty) {
1912
1833
  const polygons = coordinates;
1913
1834
  writer.writeVarInt(polygons.length);
@@ -1924,11 +1845,9 @@ var __exports__ = (() => {
1924
1845
  }
1925
1846
  }
1926
1847
  function encodeGeometryCollection2(writer, context, geometryCollection) {
1927
- const {
1928
- geometries
1929
- } = geometryCollection;
1848
+ const { geometries } = geometryCollection;
1930
1849
  const isEmpty = geometries.length === 0;
1931
- writeTwkbHeader(writer, context, WKBGeometryType.GeometryCollection, isEmpty);
1850
+ writeTwkbHeader(writer, context, 7 /* GeometryCollection */, isEmpty);
1932
1851
  if (geometries.length > 0) {
1933
1852
  writer.writeVarInt(geometries.length);
1934
1853
  for (const geometry of geometries) {
@@ -2001,7 +1920,7 @@ var __exports__ = (() => {
2001
1920
  }
2002
1921
  }
2003
1922
  };
2004
- return __toCommonJS(src_exports);
1923
+ return __toCommonJS(bundle_exports);
2005
1924
  })();
2006
1925
  return __exports__;
2007
1926
  });