@math.gl/dggs 5.0.0-alpha.2

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 (113) hide show
  1. package/LICENSE +140 -0
  2. package/README.md +7 -0
  3. package/dist/a5-decoder.d.ts +15 -0
  4. package/dist/a5-decoder.d.ts.map +1 -0
  5. package/dist/a5-decoder.js +36 -0
  6. package/dist/a5-decoder.js.map +1 -0
  7. package/dist/a5.cjs +77 -0
  8. package/dist/a5.cjs.map +6 -0
  9. package/dist/a5.d.ts +2 -0
  10. package/dist/a5.d.ts.map +1 -0
  11. package/dist/a5.js +5 -0
  12. package/dist/a5.js.map +1 -0
  13. package/dist/converters/s2-to-obb-points.d.ts +15 -0
  14. package/dist/converters/s2-to-obb-points.d.ts.map +1 -0
  15. package/dist/converters/s2-to-obb-points.js +60 -0
  16. package/dist/converters/s2-to-obb-points.js.map +1 -0
  17. package/dist/converters/s2-to-region.d.ts +6 -0
  18. package/dist/converters/s2-to-region.d.ts.map +1 -0
  19. package/dist/converters/s2-to-region.js +27 -0
  20. package/dist/converters/s2-to-region.js.map +1 -0
  21. package/dist/dggs-decoder.d.ts +37 -0
  22. package/dist/dggs-decoder.d.ts.map +1 -0
  23. package/dist/dggs-decoder.js +28 -0
  24. package/dist/dggs-decoder.js.map +1 -0
  25. package/dist/geohash-decoder.d.ts +17 -0
  26. package/dist/geohash-decoder.d.ts.map +1 -0
  27. package/dist/geohash-decoder.js +88 -0
  28. package/dist/geohash-decoder.js.map +1 -0
  29. package/dist/geohash.cjs +108 -0
  30. package/dist/geohash.cjs.map +6 -0
  31. package/dist/geohash.d.ts +2 -0
  32. package/dist/geohash.d.ts.map +1 -0
  33. package/dist/geohash.js +5 -0
  34. package/dist/geohash.js.map +1 -0
  35. package/dist/h3-decoder.d.ts +15 -0
  36. package/dist/h3-decoder.d.ts.map +1 -0
  37. package/dist/h3-decoder.js +46 -0
  38. package/dist/h3-decoder.js.map +1 -0
  39. package/dist/h3.cjs +87 -0
  40. package/dist/h3.cjs.map +6 -0
  41. package/dist/h3.d.ts +2 -0
  42. package/dist/h3.d.ts.map +1 -0
  43. package/dist/h3.js +5 -0
  44. package/dist/h3.js.map +1 -0
  45. package/dist/index.cjs +615 -0
  46. package/dist/index.cjs.map +6 -0
  47. package/dist/index.d.ts +24 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +52 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/plus-code-decoder.d.ts +16 -0
  52. package/dist/plus-code-decoder.d.ts.map +1 -0
  53. package/dist/plus-code-decoder.js +50 -0
  54. package/dist/plus-code-decoder.js.map +1 -0
  55. package/dist/plus-code.cjs +88 -0
  56. package/dist/plus-code.cjs.map +6 -0
  57. package/dist/plus-code.d.ts +2 -0
  58. package/dist/plus-code.d.ts.map +1 -0
  59. package/dist/plus-code.js +5 -0
  60. package/dist/plus-code.js.map +1 -0
  61. package/dist/quadkey-decoder.d.ts +14 -0
  62. package/dist/quadkey-decoder.d.ts.map +1 -0
  63. package/dist/quadkey-decoder.js +86 -0
  64. package/dist/quadkey-decoder.js.map +1 -0
  65. package/dist/quadkey.cjs +106 -0
  66. package/dist/quadkey.cjs.map +6 -0
  67. package/dist/quadkey.d.ts +2 -0
  68. package/dist/quadkey.d.ts.map +1 -0
  69. package/dist/quadkey.js +5 -0
  70. package/dist/quadkey.js.map +1 -0
  71. package/dist/s2-decoder.d.ts +26 -0
  72. package/dist/s2-decoder.d.ts.map +1 -0
  73. package/dist/s2-decoder.js +76 -0
  74. package/dist/s2-decoder.js.map +1 -0
  75. package/dist/s2-geometry/s2-geometry.d.ts +13 -0
  76. package/dist/s2-geometry/s2-geometry.d.ts.map +1 -0
  77. package/dist/s2-geometry/s2-geometry.js +126 -0
  78. package/dist/s2-geometry/s2-geometry.js.map +1 -0
  79. package/dist/s2-geometry/s2-to-boundary.d.ts +14 -0
  80. package/dist/s2-geometry/s2-to-boundary.d.ts.map +1 -0
  81. package/dist/s2-geometry/s2-to-boundary.js +60 -0
  82. package/dist/s2-geometry/s2-to-boundary.js.map +1 -0
  83. package/dist/s2-geometry/s2-token.d.ts +13 -0
  84. package/dist/s2-geometry/s2-token.d.ts.map +1 -0
  85. package/dist/s2-geometry/s2-token.js +61 -0
  86. package/dist/s2-geometry/s2-token.js.map +1 -0
  87. package/dist/s2.cjs +278 -0
  88. package/dist/s2.cjs.map +6 -0
  89. package/dist/s2.d.ts +3 -0
  90. package/dist/s2.d.ts.map +1 -0
  91. package/dist/s2.js +6 -0
  92. package/dist/s2.js.map +1 -0
  93. package/package.json +80 -0
  94. package/src/a5-decoder.ts +42 -0
  95. package/src/a5.ts +5 -0
  96. package/src/converters/s2-to-obb-points.ts +78 -0
  97. package/src/converters/s2-to-region.ts +30 -0
  98. package/src/dggs-decoder.ts +71 -0
  99. package/src/geohash-decoder.ts +99 -0
  100. package/src/geohash.ts +5 -0
  101. package/src/h3-decoder.ts +53 -0
  102. package/src/h3.ts +5 -0
  103. package/src/index.ts +61 -0
  104. package/src/open-location-code.d.ts +19 -0
  105. package/src/plus-code-decoder.ts +56 -0
  106. package/src/plus-code.ts +5 -0
  107. package/src/quadkey-decoder.ts +98 -0
  108. package/src/quadkey.ts +5 -0
  109. package/src/s2-decoder.ts +87 -0
  110. package/src/s2-geometry/s2-geometry.ts +166 -0
  111. package/src/s2-geometry/s2-to-boundary.ts +76 -0
  112. package/src/s2-geometry/s2-token.ts +70 -0
  113. package/src/s2.ts +6 -0
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { A5Decoder } from "./a5-decoder.js";
5
+ import { GeohashDecoder } from "./geohash-decoder.js";
6
+ import { H3Decoder } from "./h3-decoder.js";
7
+ import { PlusCodeDecoder } from "./plus-code-decoder.js";
8
+ import { QuadkeyDecoder } from "./quadkey-decoder.js";
9
+ import { S2Decoder } from "./s2-decoder.js";
10
+ export { A5Decoder };
11
+ export { GeohashDecoder };
12
+ export { H3Decoder };
13
+ export { PlusCodeDecoder };
14
+ export { QuadkeyDecoder, quadkeyToWorldBounds } from "./quadkey-decoder.js";
15
+ export { S2Decoder };
16
+ export { getS2ChildIndex } from "./s2-geometry/s2-token.js";
17
+ /** Lightweight decoders bundled with this module. */
18
+ export const DGGS_DECODERS = [
19
+ A5Decoder,
20
+ GeohashDecoder,
21
+ H3Decoder,
22
+ PlusCodeDecoder,
23
+ QuadkeyDecoder,
24
+ S2Decoder
25
+ ];
26
+ /**
27
+ * Finds a conventional DGGS cell column by name.
28
+ *
29
+ * Returns `null` when there is no match or when columns from more than one
30
+ * decoder match. Callers should ask the user to choose in the ambiguous case.
31
+ */
32
+ export function findDGGSCellColumn(columnNames, decoders = DGGS_DECODERS) {
33
+ const actualNames = new Map();
34
+ for (const columnName of columnNames) {
35
+ actualNames.set(columnName.toLowerCase(), columnName);
36
+ }
37
+ let match = null;
38
+ for (const decoder of decoders) {
39
+ for (const candidate of decoder.cellColumnNames) {
40
+ const columnName = actualNames.get(candidate.toLowerCase());
41
+ if (!columnName) {
42
+ continue;
43
+ }
44
+ if (match && (match.decoder !== decoder || match.columnName !== columnName)) {
45
+ return null;
46
+ }
47
+ match = { columnName, decoder };
48
+ }
49
+ }
50
+ return match;
51
+ }
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,SAAS,EAAC,wBAAqB;AACvC,OAAO,EAAC,cAAc,EAAC,6BAA0B;AACjD,OAAO,EAAC,SAAS,EAAC,wBAAqB;AACvC,OAAO,EAAC,eAAe,EAAC,+BAA4B;AACpD,OAAO,EAAC,cAAc,EAAC,6BAA0B;AACjD,OAAO,EAAC,SAAS,EAAC,wBAAqB;AAGvC,OAAO,EAAC,SAAS,EAAC,CAAC;AACn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2
+ import { type DGGSCell } from "./dggs-decoder.js";
3
+ /**
4
+ * Lightweight geometry decoder for full Google Plus Codes (Open Location Codes).
5
+ * Short codes require a reference location and are intentionally unsupported.
6
+ */
7
+ export declare const PlusCodeDecoder: {
8
+ readonly name: "plus-code";
9
+ readonly hasNumericRepresentation: false;
10
+ readonly cellColumnNames: readonly ["plusCode", "plus_code", "openLocationCode", "open_location_code", "olc"];
11
+ readonly cellToLngLat: (cell: DGGSCell) => [number, number];
12
+ readonly cellToBoundary: (cell: DGGSCell) => [number, number][];
13
+ readonly cellToBoundaryFlat: (cell: DGGSCell) => number[];
14
+ readonly cellToBounds: (cell: DGGSCell) => Bounds2D;
15
+ };
16
+ //# sourceMappingURL=plus-code-decoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plus-code-decoder.d.ts","sourceRoot":"","sources":["../src/plus-code-decoder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,KAAK,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,KAAK,QAAQ,EAAqC,0BAAuB;AAIjF;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;kCAIL,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC;oCACzB,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;wCACzB,QAAQ,KAAG,MAAM,EAAE;kCAIzB,QAAQ,KAAG,QAAQ;CAOV,CAAC"}
@@ -0,0 +1,50 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import OpenLocationCodePackage from 'open-location-code';
5
+ import { getDGGSCellToken } from "./dggs-decoder.js";
6
+ const openLocationCode = new OpenLocationCodePackage.OpenLocationCode();
7
+ /**
8
+ * Lightweight geometry decoder for full Google Plus Codes (Open Location Codes).
9
+ * Short codes require a reference location and are intentionally unsupported.
10
+ */
11
+ export const PlusCodeDecoder = {
12
+ name: 'plus-code',
13
+ hasNumericRepresentation: false,
14
+ cellColumnNames: ['plusCode', 'plus_code', 'openLocationCode', 'open_location_code', 'olc'],
15
+ cellToLngLat: (cell) => getPlusCodeLngLat(cell),
16
+ cellToBoundary: (cell) => getPlusCodeBoundary(decodePlusCode(cell)),
17
+ cellToBoundaryFlat: (cell) => {
18
+ const area = decodePlusCode(cell);
19
+ return getPlusCodeBoundary(area).flat();
20
+ },
21
+ cellToBounds: (cell) => {
22
+ const area = decodePlusCode(cell);
23
+ return [
24
+ [area.longitudeLo, area.latitudeLo],
25
+ [area.longitudeHi, area.latitudeHi]
26
+ ];
27
+ }
28
+ };
29
+ function getPlusCodeLngLat(cell) {
30
+ const area = decodePlusCode(cell);
31
+ return [area.longitudeCenter, area.latitudeCenter];
32
+ }
33
+ function decodePlusCode(cell) {
34
+ const code = getDGGSCellToken(cell, 'Plus Code');
35
+ if (!openLocationCode.isFull(code)) {
36
+ throw new Error(`Plus Code decoder requires a full code: ${code}`);
37
+ }
38
+ return openLocationCode.decode(code);
39
+ }
40
+ function getPlusCodeBoundary(area) {
41
+ const { longitudeLo: west, latitudeLo: south, longitudeHi: east, latitudeHi: north } = area;
42
+ return [
43
+ [east, north],
44
+ [east, south],
45
+ [west, south],
46
+ [west, north],
47
+ [east, north]
48
+ ];
49
+ }
50
+ //# sourceMappingURL=plus-code-decoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plus-code-decoder.js","sourceRoot":"","sources":["../src/plus-code-decoder.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,uBAAoD,MAAM,oBAAoB,CAAC;AAEtF,OAAO,EAAkC,gBAAgB,EAAC,0BAAuB;AAEjF,MAAM,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,gBAAgB,EAAE,CAAC;AAExE;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,WAAW;IACjB,wBAAwB,EAAE,KAAK;IAC/B,eAAe,EAAE,C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AE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAC,GAAG,IAAI,CAAC;IAC1F,OAAO;QACL,CAAC,IAAI,EAAE,KAAK,CAAC;QACb,CAAC,IAAI,EAAE,KAAK,CAAC;QACb,CAAC,IAAI,EAAE,KAAK,CAAC;QACb,CAAC,IAAI,EAAE,KAAK,CAAC;QACb,CAAC,IAAI,EAAE,KAAK,CAAC;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,88 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // dist/plus-code.js
30
+ var plus_code_exports = {};
31
+ __export(plus_code_exports, {
32
+ PlusCodeDecoder: () => PlusCodeDecoder
33
+ });
34
+ module.exports = __toCommonJS(plus_code_exports);
35
+
36
+ // dist/plus-code-decoder.js
37
+ var import_open_location_code = __toESM(require("open-location-code"), 1);
38
+
39
+ // dist/dggs-decoder.js
40
+ function getDGGSCellToken(cell, gridName) {
41
+ if (typeof cell !== "string") {
42
+ throw new Error(`${gridName} cell identifiers must be strings`);
43
+ }
44
+ return cell;
45
+ }
46
+
47
+ // dist/plus-code-decoder.js
48
+ var openLocationCode = new import_open_location_code.default.OpenLocationCode();
49
+ var PlusCodeDecoder = {
50
+ name: "plus-code",
51
+ hasNumericRepresentation: false,
52
+ cellColumnNames: ["plusCode", "plus_code", "openLocationCode", "open_location_code", "olc"],
53
+ cellToLngLat: (cell) => getPlusCodeLngLat(cell),
54
+ cellToBoundary: (cell) => getPlusCodeBoundary(decodePlusCode(cell)),
55
+ cellToBoundaryFlat: (cell) => {
56
+ const area = decodePlusCode(cell);
57
+ return getPlusCodeBoundary(area).flat();
58
+ },
59
+ cellToBounds: (cell) => {
60
+ const area = decodePlusCode(cell);
61
+ return [
62
+ [area.longitudeLo, area.latitudeLo],
63
+ [area.longitudeHi, area.latitudeHi]
64
+ ];
65
+ }
66
+ };
67
+ function getPlusCodeLngLat(cell) {
68
+ const area = decodePlusCode(cell);
69
+ return [area.longitudeCenter, area.latitudeCenter];
70
+ }
71
+ function decodePlusCode(cell) {
72
+ const code = getDGGSCellToken(cell, "Plus Code");
73
+ if (!openLocationCode.isFull(code)) {
74
+ throw new Error(`Plus Code decoder requires a full code: ${code}`);
75
+ }
76
+ return openLocationCode.decode(code);
77
+ }
78
+ function getPlusCodeBoundary(area) {
79
+ const { longitudeLo: west, latitudeLo: south, longitudeHi: east, latitudeHi: north } = area;
80
+ return [
81
+ [east, north],
82
+ [east, south],
83
+ [west, south],
84
+ [west, north],
85
+ [east, north]
86
+ ];
87
+ }
88
+ //# sourceMappingURL=plus-code.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources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KAAK;IACZ,CAAC,MAAM,KAAK;IACZ,CAAC,MAAM,KAAK;IACZ,CAAC,MAAM,KAAK;;AAEhB;",
5
+ "names": ["OpenLocationCodePackage"]
6
+ }
@@ -0,0 +1,2 @@
1
+ export { PlusCodeDecoder } from "./plus-code-decoder.js";
2
+ //# sourceMappingURL=plus-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plus-code.d.ts","sourceRoot":"","sources":["../src/plus-code.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,eAAe,EAAC,+BAA4B"}
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export { PlusCodeDecoder } from "./plus-code-decoder.js";
5
+ //# sourceMappingURL=plus-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plus-code.js","sourceRoot":"","sources":["../src/plus-code.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,eAAe,EAAC,+BAA4B"}
@@ -0,0 +1,14 @@
1
+ import { type Bounds2D } from '@math.gl/types';
2
+ import { type DGGSCell } from "./dggs-decoder.js";
3
+ /** Decoder for the quadkey DGGS */
4
+ export declare const QuadkeyDecoder: {
5
+ readonly name: "quadkey";
6
+ readonly hasNumericRepresentation: false;
7
+ readonly cellColumnNames: readonly ["quadkey", "quadkeyId", "quadkey_id"];
8
+ readonly cellToLngLat: (cell: DGGSCell) => [number, number];
9
+ readonly cellToBoundary: (cell: DGGSCell) => [number, number][];
10
+ readonly cellToBoundaryFlat: (cell: DGGSCell) => number[];
11
+ readonly cellToBounds: (cell: DGGSCell) => Bounds2D;
12
+ };
13
+ export declare function quadkeyToWorldBounds(quadkey: string): [[number, number], [number, number]];
14
+ //# sourceMappingURL=quadkey-decoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quadkey-decoder.d.ts","sourceRoot":"","sources":["../src/quadkey-decoder.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,KAAK,QAAQ,EAAqC,0BAAuB;AAIjF,mCAAmC;AACnC,eAAO,MAAM,cAAc;;;;kCAIJ,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC;oCAEzB,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;wCAEzB,QAAQ,KAAG,MAAM,EAAE;kCAEzB,QAAQ,KAAG,QAAQ;CACV,CAAC;AAuCjC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAgB1F"}
@@ -0,0 +1,86 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { getDGGSCellToken } from "./dggs-decoder.js";
5
+ const TILE_SIZE = 512;
6
+ /** Decoder for the quadkey DGGS */
7
+ export const QuadkeyDecoder = {
8
+ name: 'quadkey',
9
+ hasNumericRepresentation: false,
10
+ cellColumnNames: ['quadkey', 'quadkeyId', 'quadkey_id'],
11
+ cellToLngLat: (cell) => getQuadkeyLngLat(getDGGSCellToken(cell, 'Quadkey')),
12
+ cellToBoundary: (cell) => getQuadkeyBoundary(getDGGSCellToken(cell, 'Quadkey')),
13
+ cellToBoundaryFlat: (cell) => getQuadkeyBoundaryFlat(getDGGSCellToken(cell, 'Quadkey')),
14
+ cellToBounds: (cell) => getQuadkeyBounds(getDGGSCellToken(cell, 'Quadkey'))
15
+ };
16
+ function getQuadkeyLngLat(quadkey) {
17
+ const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
18
+ const [w, n] = worldToLngLat(topLeft);
19
+ const [e, s] = worldToLngLat(bottomRight);
20
+ return [(e + w) / 2, (s + n) / 2];
21
+ }
22
+ function getQuadkeyBoundary(quadkey) {
23
+ const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
24
+ const [w, n] = worldToLngLat(topLeft);
25
+ const [e, s] = worldToLngLat(bottomRight);
26
+ return [
27
+ [e, n],
28
+ [e, s],
29
+ [w, s],
30
+ [w, n],
31
+ [e, n]
32
+ ];
33
+ }
34
+ function getQuadkeyBoundaryFlat(quadkey) {
35
+ const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
36
+ const [w, n] = worldToLngLat(topLeft);
37
+ const [e, s] = worldToLngLat(bottomRight);
38
+ return [e, n, e, s, w, s, w, n, e, n];
39
+ }
40
+ function getQuadkeyBounds(quadkey) {
41
+ const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
42
+ const [w, n] = worldToLngLat(topLeft);
43
+ const [e, s] = worldToLngLat(bottomRight);
44
+ return [
45
+ [w, s],
46
+ [e, n]
47
+ ];
48
+ }
49
+ export function quadkeyToWorldBounds(quadkey) {
50
+ let x = 0;
51
+ let y = 0;
52
+ let mask = 1 << quadkey.length;
53
+ const scale = mask / TILE_SIZE;
54
+ for (let i = 0; i < quadkey.length; i++) {
55
+ mask >>= 1;
56
+ const q = parseInt(quadkey[i], 10);
57
+ if (q % 2)
58
+ x |= mask;
59
+ if (q > 1)
60
+ y |= mask;
61
+ }
62
+ return [
63
+ [x / scale, TILE_SIZE - y / scale],
64
+ [(x + 0.99) / scale, TILE_SIZE - (y + 0.99) / scale]
65
+ ];
66
+ }
67
+ // CONSTANTS
68
+ const PI = Math.PI;
69
+ const PI_4 = PI / 4;
70
+ const RADIANS_TO_DEGREES = 180 / PI;
71
+ /**
72
+ * Unproject world point [x,y] on map onto {lat, lon} on sphere
73
+ *
74
+ * @param xy - array with [x,y] members
75
+ * representing point on projected map plane
76
+ * @return - array with [x,y] of point on sphere.
77
+ * Has toArray method if you need a GeoJSON Array.
78
+ * Per cartographic tradition, lat and lon are specified as degrees.
79
+ */
80
+ function worldToLngLat(xy) {
81
+ const [x, y] = xy;
82
+ const lambda2 = (x / TILE_SIZE) * (2 * PI) - PI;
83
+ const phi2 = 2 * (Math.atan(Math.exp((y / TILE_SIZE) * (2 * PI) - PI)) - PI_4);
84
+ return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];
85
+ }
86
+ //# sourceMappingURL=quadkey-decoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quadkey-decoder.js","sourceRoot":"","sources":["../src/quadkey-decoder.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAkC,gBAAgB,EAAC,0BAAuB;AAEjF,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,mCAAmC;AACnC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,SAAS;IACf,wBAAwB,EAAE,KAAK;IAC/B,eAAe,EAAE,CAAC,SAAS,EAAE,WAAW,EAAE,YAAY,CAAC;IACvD,YAAY,EAAE,CAAC,IAAc,EAAoB,EAAE,CACjD,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACrD,cAAc,EAAE,CAAC,IAAc,EAAsB,EAAE,CACrD,kBAAkB,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACvD,kBAAkB,EAAE,CAAC,IAAc,EAAY,EAAE,CAC/C,sBAAsB,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC3D,YAAY,EAAE,CAAC,IAAc,EAAY,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;CACjE,CAAC;AAEjC,SAAS,gBAAgB,CAAC,OAAe;IACvC,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC7D,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,MAA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AAS,aAAa,CAAC,EAAY;IACjC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC;IAClB,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;IAChD,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC/E,OAAO,CAAC,OAAO,GAAG,kBAAkB,EAAE,IAAI,GAAG,kBAAkB,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,106 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/quadkey.js
20
+ var quadkey_exports = {};
21
+ __export(quadkey_exports, {
22
+ QuadkeyDecoder: () => QuadkeyDecoder,
23
+ quadkeyToWorldBounds: () => quadkeyToWorldBounds
24
+ });
25
+ module.exports = __toCommonJS(quadkey_exports);
26
+
27
+ // dist/dggs-decoder.js
28
+ function getDGGSCellToken(cell, gridName) {
29
+ if (typeof cell !== "string") {
30
+ throw new Error(`${gridName} cell identifiers must be strings`);
31
+ }
32
+ return cell;
33
+ }
34
+
35
+ // dist/quadkey-decoder.js
36
+ var TILE_SIZE = 512;
37
+ var QuadkeyDecoder = {
38
+ name: "quadkey",
39
+ hasNumericRepresentation: false,
40
+ cellColumnNames: ["quadkey", "quadkeyId", "quadkey_id"],
41
+ cellToLngLat: (cell) => getQuadkeyLngLat(getDGGSCellToken(cell, "Quadkey")),
42
+ cellToBoundary: (cell) => getQuadkeyBoundary(getDGGSCellToken(cell, "Quadkey")),
43
+ cellToBoundaryFlat: (cell) => getQuadkeyBoundaryFlat(getDGGSCellToken(cell, "Quadkey")),
44
+ cellToBounds: (cell) => getQuadkeyBounds(getDGGSCellToken(cell, "Quadkey"))
45
+ };
46
+ function getQuadkeyLngLat(quadkey) {
47
+ const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
48
+ const [w, n] = worldToLngLat(topLeft);
49
+ const [e, s] = worldToLngLat(bottomRight);
50
+ return [(e + w) / 2, (s + n) / 2];
51
+ }
52
+ function getQuadkeyBoundary(quadkey) {
53
+ const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
54
+ const [w, n] = worldToLngLat(topLeft);
55
+ const [e, s] = worldToLngLat(bottomRight);
56
+ return [
57
+ [e, n],
58
+ [e, s],
59
+ [w, s],
60
+ [w, n],
61
+ [e, n]
62
+ ];
63
+ }
64
+ function getQuadkeyBoundaryFlat(quadkey) {
65
+ const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
66
+ const [w, n] = worldToLngLat(topLeft);
67
+ const [e, s] = worldToLngLat(bottomRight);
68
+ return [e, n, e, s, w, s, w, n, e, n];
69
+ }
70
+ function getQuadkeyBounds(quadkey) {
71
+ const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
72
+ const [w, n] = worldToLngLat(topLeft);
73
+ const [e, s] = worldToLngLat(bottomRight);
74
+ return [
75
+ [w, s],
76
+ [e, n]
77
+ ];
78
+ }
79
+ function quadkeyToWorldBounds(quadkey) {
80
+ let x = 0;
81
+ let y = 0;
82
+ let mask = 1 << quadkey.length;
83
+ const scale = mask / TILE_SIZE;
84
+ for (let i = 0; i < quadkey.length; i++) {
85
+ mask >>= 1;
86
+ const q = parseInt(quadkey[i], 10);
87
+ if (q % 2)
88
+ x |= mask;
89
+ if (q > 1)
90
+ y |= mask;
91
+ }
92
+ return [
93
+ [x / scale, TILE_SIZE - y / scale],
94
+ [(x + 0.99) / scale, TILE_SIZE - (y + 0.99) / scale]
95
+ ];
96
+ }
97
+ var PI = Math.PI;
98
+ var PI_4 = PI / 4;
99
+ var RADIANS_TO_DEGREES = 180 / PI;
100
+ function worldToLngLat(xy) {
101
+ const [x, y] = xy;
102
+ const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
103
+ const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
104
+ return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];
105
+ }
106
+ //# sourceMappingURL=quadkey.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/quadkey.ts", "../src/dggs-decoder.ts", "../src/quadkey-decoder.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;AC6CM,SAAU,iBAAiB,MAAgB,UAAgB;AAC/D,MAAI,OAAO,SAAS,UAAU;AAC5B,UAAM,IAAI,MAAM,GAAG,QAAQ,mCAAmC;EAChE;AACA,SAAO;AACT;;;AC3CA,IAAM,YAAY;AAGX,IAAM,iBAAiB;EAC5B,MAAM;EACN,0BAA0B;EAC1B,iBAAiB,CAAC,WAAW,aAAa,YAAY;EACtD,cAAc,CAAC,SACb,iBAAiB,iBAAiB,MAAM,SAAS,CAAC;EACpD,gBAAgB,CAAC,SACf,mBAAmB,iBAAiB,MAAM,SAAS,CAAC;EACtD,oBAAoB,CAAC,SACnB,uBAAuB,iBAAiB,MAA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O;AAErB,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,aAAS;AACT,UAAM,IAAI,SAAS,QAAQ,CAAC,GAAG,EAAE;AACjC,QAAI,IAAI;AAAG,WAAK;AAChB,QAAI,IAAI;AAAG,WAAK;EAClB;AACA,SAAO;IACL,CAAC,IAAI,OAAO,YAAY,IAAI,KAAK;IACjC,EAAE,IAAI,QAAQ,OAAO,aAAa,IAAI,QAAQ,KAAK;;AAEvD;AAGA,IAAM,KAAK,KAAK;AAChB,IAAM,OAAO,KAAK;AAClB,IAAM,qBAAqB,MAAM;AAWjC,SAAS,cAAc,IAAY;AACjC,QAAM,CAAC,GAAG,CAAC,IAAI;AACf,QAAM,UAAW,IAAI,aAAc,IAAI,MAAM;AAC7C,QAAM,OAAO,KAAK,KAAK,KAAK,KAAK,IAAK,IAAI,aAAc,IAAI,MAAM,EAAE,CAAC,IAAI;AACzE,SAAO,CAAC,UAAU,oBAAoB,OAAO,kBAAkB;AACjE;",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ export { QuadkeyDecoder, quadkeyToWorldBounds } from "./quadkey-decoder.js";
2
+ //# sourceMappingURL=quadkey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quadkey.d.ts","sourceRoot":"","sources":["../src/quadkey.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,cAAc,EAAE,oBAAoB,EAAC,6BAA0B"}
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export { QuadkeyDecoder, quadkeyToWorldBounds } from "./quadkey-decoder.js";
5
+ //# sourceMappingURL=quadkey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quadkey.js","sourceRoot":"","sources":["../src/quadkey.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,cAAc,EAAE,oBAAoB,EAAC,6BAA0B"}
@@ -0,0 +1,26 @@
1
+ import { type Bounds2D } from '@math.gl/types';
2
+ import { type DGGSCell } from "./dggs-decoder.js";
3
+ /** Decoder for the S2 DGGS */
4
+ export declare const S2Decoder: {
5
+ readonly name: "s2";
6
+ readonly hasNumericRepresentation: true;
7
+ readonly cellColumnNames: readonly ["s2", "s2Token", "s2_token", "s2Cell", "s2_cell", "s2CellId", "s2_cell_id"];
8
+ readonly tokenToCell: (s2Token: string) => bigint;
9
+ readonly cellToToken: (cell: DGGSCell) => string;
10
+ readonly cellToLngLat: (cell: DGGSCell) => [number, number];
11
+ readonly cellToBoundary: (cell: DGGSCell) => [number, number][];
12
+ readonly cellToBoundaryFlat: (cell: DGGSCell) => number[];
13
+ readonly cellToBounds: (cell: DGGSCell) => Bounds2D;
14
+ };
15
+ /**
16
+ * Retrieve S2 geometry center
17
+ */
18
+ export declare function getS2LngLat(cell: DGGSCell): [number, number];
19
+ /**
20
+ * Get a polygon with corner coordinates for an s2 cell
21
+ * @param - This can be an S2 key or token
22
+ * @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
23
+ * - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
24
+ */
25
+ export declare function getS2BoundaryFlat(cell: DGGSCell): number[];
26
+ //# sourceMappingURL=s2-decoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s2-decoder.d.ts","sourceRoot":"","sources":["../src/s2-decoder.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,KAAK,QAAQ,EAAmB,0BAAuB;AAM/D,8BAA8B;AAC9B,eAAO,MAAM,SAAS;;;;oCAIG,MAAM,KAAG,MAAM;iCAClB,QAAQ,KAAG,MAAM;kCAEhB,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC;oCACzB,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;wCACzB,QAAQ,KAAG,MAAM,EAAE;kCACzB,QAAQ,KAAG,QAAQ;CACV,CAAC;AAEjC;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAU5D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,CAK1D"}
@@ -0,0 +1,76 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { getS2IndexFromToken, getS2TokenFromIndex } from "./s2-geometry/s2-token.js";
5
+ import { getS2GeoBounds } from "./s2-geometry/s2-to-boundary.js";
6
+ import { getS2Cell, IJToST, STToUV, FaceUVToXYZ, XYZToLngLat } from "./s2-geometry/s2-geometry.js";
7
+ /** Decoder for the S2 DGGS */
8
+ export const S2Decoder = {
9
+ name: 's2',
10
+ hasNumericRepresentation: true,
11
+ cellColumnNames: ['s2', 's2Token', 's2_token', 's2Cell', 's2_cell', 's2CellId', 's2_cell_id'],
12
+ tokenToCell: (s2Token) => getS2IndexFromToken(s2Token),
13
+ cellToToken: (cell) => typeof cell === 'string' ? cell : getS2TokenFromIndex(cell),
14
+ cellToLngLat: (cell) => getS2LngLat(cell),
15
+ cellToBoundary: (cell) => getS2Boundary(cell),
16
+ cellToBoundaryFlat: (cell) => getS2BoundaryFlat(cell),
17
+ cellToBounds: (cell) => getS2Bounds(cell)
18
+ };
19
+ /**
20
+ * Retrieve S2 geometry center
21
+ */
22
+ export function getS2LngLat(cell) {
23
+ const s2Index = getS2CellIndex(cell);
24
+ const s2Cell = getS2Cell(s2Index);
25
+ const st = IJToST(s2Cell.ij, s2Cell.level, [0.5, 0.5]);
26
+ const uv = STToUV(st);
27
+ const xyz = FaceUVToXYZ(s2Cell.face, uv);
28
+ const lngLat = XYZToLngLat(xyz);
29
+ return lngLat;
30
+ }
31
+ /**
32
+ * Get a polygon with corner coordinates for an s2 cell
33
+ * @param - This can be an S2 key or token
34
+ * @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
35
+ * - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
36
+ */
37
+ export function getS2BoundaryFlat(cell) {
38
+ const s2Index = getS2CellIndex(cell);
39
+ const float64Array = getS2GeoBounds(s2Index);
40
+ // TODO - inefficient
41
+ return Array.from(float64Array);
42
+ }
43
+ function getS2Boundary(cell) {
44
+ const flatBoundary = getS2BoundaryFlat(cell);
45
+ const boundary = [];
46
+ for (let i = 0; i < flatBoundary.length; i += 2) {
47
+ boundary.push([flatBoundary[i], flatBoundary[i + 1]]);
48
+ }
49
+ return boundary;
50
+ }
51
+ function getS2Bounds(cell) {
52
+ const flatBoundary = getS2Boundary(cell);
53
+ // We know that we have at least one point, no Infinity will be returned.
54
+ let xmin = Infinity;
55
+ let ymin = Infinity;
56
+ let xmax = -Infinity;
57
+ let ymax = -Infinity;
58
+ for (const [x, y] of flatBoundary) {
59
+ if (x < xmin)
60
+ xmin = x;
61
+ if (x > xmax)
62
+ xmax = x;
63
+ if (y < ymin)
64
+ ymin = y;
65
+ if (y > ymax)
66
+ ymax = y;
67
+ }
68
+ return [
69
+ [xmin, ymin],
70
+ [xmax, ymax]
71
+ ];
72
+ }
73
+ function getS2CellIndex(cell) {
74
+ return typeof cell === 'bigint' ? cell : getS2IndexFromToken(cell);
75
+ }
76
+ //# sourceMappingURL=s2-decoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s2-decoder.js","sourceRoot":"","sources":["../src/s2-decoder.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAKpC,OAAO,EAAC,mBAAmB,EAAE,mBAAmB,EAAC,kCAA+B;AAChF,OAAO,EAAC,cAAc,EAAC,wCAAqC;AAC5D,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAC,qCAAkC;AAE9F,8BAA8B;AAC9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AED,OAAO;QACL,CAAC,IAAI,EAAE,IAAI,CAAC;QACZ,CAAC,IAAI,EAAE,IAAI,CAAC;KACb,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,IAAc;IACpC,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,13 @@
1
+ export type S2Cell = {
2
+ face: number;
3
+ ij: [number, number];
4
+ level: number;
5
+ };
6
+ export declare function getS2Cell(s2Index: bigint): S2Cell;
7
+ export declare function fromHilbertQuadKey(hilbertQuadkey: string): S2Cell;
8
+ export declare function toHilbertQuadkey(id: bigint): string;
9
+ export declare function IJToST(ij: [number, number], order: number, offsets: [number, number]): [number, number];
10
+ export declare function STToUV(st: [number, number]): [number, number];
11
+ export declare function FaceUVToXYZ(face: number, [u, v]: [number, number]): [number, number, number];
12
+ export declare function XYZToLngLat([x, y, z]: [number, number, number]): [number, number];
13
+ //# sourceMappingURL=s2-geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s2-geometry.d.ts","sourceRoot":"","sources":["../../src/s2-geometry/s2-geometry.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIjD;AAcD,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAqCjE;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CA6BnD;AAED,wBAAgB,MAAM,CACpB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GACxB,CAAC,MAAM,EAAE,MAAM,CAAC,CAIlB;AASD,wBAAgB,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAE7D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAiB5F;AAED,wBAAgB,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAKjF"}