@carto/api-client 0.5.0-alpha.1 → 0.5.0-alpha.11

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 (127) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/api-client.cjs +3163 -3206
  3. package/build/api-client.cjs.map +1 -1
  4. package/build/api-client.d.cts +1389 -0
  5. package/build/api-client.d.ts +1389 -0
  6. package/build/api-client.js +3674 -0
  7. package/build/api-client.js.map +1 -0
  8. package/build/worker.d.ts +2 -0
  9. package/build/worker.js +1949 -0
  10. package/build/worker.js.map +1 -0
  11. package/package.json +60 -45
  12. package/src/api/carto-api-error.ts +1 -1
  13. package/src/api/query.ts +5 -5
  14. package/src/api/request-with-parameters.ts +6 -6
  15. package/src/client.ts +3 -3
  16. package/src/constants-internal.ts +5 -11
  17. package/src/constants.ts +6 -6
  18. package/src/deck/get-data-filter-extension-props.ts +146 -0
  19. package/src/deck/index.ts +1 -0
  20. package/src/filters/Filter.ts +18 -8
  21. package/src/filters/FilterTypes.ts +2 -2
  22. package/src/filters/geosjonFeatures.ts +2 -2
  23. package/src/filters/tileFeatures.ts +12 -17
  24. package/src/filters.ts +4 -4
  25. package/src/geo.ts +12 -14
  26. package/src/global.d.ts +3 -8
  27. package/src/index.ts +3 -0
  28. package/src/models/common.ts +11 -9
  29. package/src/models/model.ts +3 -4
  30. package/src/operations/aggregation.ts +5 -5
  31. package/src/operations/applySorting.ts +4 -4
  32. package/src/operations/groupBy.ts +4 -4
  33. package/src/operations/groupByDate.ts +1 -1
  34. package/src/operations/histogram.ts +4 -4
  35. package/src/operations/scatterPlot.ts +4 -4
  36. package/src/sources/base-source.ts +8 -8
  37. package/src/sources/boundary-query-source.ts +2 -2
  38. package/src/sources/boundary-table-source.ts +2 -2
  39. package/src/sources/h3-query-source.ts +7 -5
  40. package/src/sources/h3-table-source.ts +7 -5
  41. package/src/sources/h3-tileset-source.ts +4 -4
  42. package/src/sources/index.ts +26 -26
  43. package/src/sources/quadbin-query-source.ts +7 -5
  44. package/src/sources/quadbin-table-source.ts +7 -5
  45. package/src/sources/quadbin-tileset-source.ts +4 -4
  46. package/src/sources/raster-source.ts +2 -2
  47. package/src/sources/types.ts +9 -3
  48. package/src/sources/vector-query-source.ts +2 -3
  49. package/src/sources/vector-table-source.ts +2 -3
  50. package/src/sources/vector-tileset-source.ts +5 -5
  51. package/src/spatial-index.ts +12 -10
  52. package/src/types-internal.ts +5 -5
  53. package/src/types.ts +15 -15
  54. package/src/utils/makeIntervalComplete.ts +1 -1
  55. package/src/utils.ts +3 -3
  56. package/src/widget-sources/index.ts +1 -0
  57. package/src/widget-sources/types.ts +6 -4
  58. package/src/widget-sources/widget-query-source.ts +6 -2
  59. package/src/widget-sources/widget-remote-source.ts +67 -26
  60. package/src/widget-sources/widget-source.ts +10 -25
  61. package/src/widget-sources/widget-table-source.ts +6 -2
  62. package/src/widget-sources/widget-tileset-source-impl.ts +417 -0
  63. package/src/widget-sources/widget-tileset-source.ts +200 -299
  64. package/src/workers/constants.ts +13 -0
  65. package/src/workers/types.ts +19 -0
  66. package/src/workers/widget-tileset-worker.ts +40 -0
  67. package/build/api/carto-api-error.d.ts +0 -26
  68. package/build/api/endpoints.d.ts +0 -24
  69. package/build/api/index.d.ts +0 -5
  70. package/build/api/query.d.ts +0 -3
  71. package/build/api/request-with-parameters.d.ts +0 -10
  72. package/build/api-client.modern.js +0 -3574
  73. package/build/api-client.modern.js.map +0 -1
  74. package/build/client.d.ts +0 -14
  75. package/build/constants-internal.d.ts +0 -26
  76. package/build/constants.d.ts +0 -53
  77. package/build/filters/Filter.d.ts +0 -13
  78. package/build/filters/FilterTypes.d.ts +0 -3
  79. package/build/filters/geosjonFeatures.d.ts +0 -8
  80. package/build/filters/index.d.ts +0 -6
  81. package/build/filters/tileFeatures.d.ts +0 -20
  82. package/build/filters/tileFeaturesGeometries.d.ts +0 -13
  83. package/build/filters/tileFeaturesSpatialIndex.d.ts +0 -10
  84. package/build/filters.d.ts +0 -39
  85. package/build/geo.d.ts +0 -19
  86. package/build/index.d.ts +0 -14
  87. package/build/models/common.d.ts +0 -27
  88. package/build/models/index.d.ts +0 -3
  89. package/build/models/model.d.ts +0 -37
  90. package/build/operations/aggregation.d.ts +0 -8
  91. package/build/operations/applySorting.d.ts +0 -20
  92. package/build/operations/groupBy.d.ts +0 -15
  93. package/build/operations/groupByDate.d.ts +0 -11
  94. package/build/operations/histogram.d.ts +0 -13
  95. package/build/operations/index.d.ts +0 -6
  96. package/build/operations/scatterPlot.d.ts +0 -14
  97. package/build/sources/base-source.d.ts +0 -4
  98. package/build/sources/boundary-query-source.d.ts +0 -10
  99. package/build/sources/boundary-table-source.d.ts +0 -8
  100. package/build/sources/h3-query-source.d.ts +0 -5
  101. package/build/sources/h3-table-source.d.ts +0 -5
  102. package/build/sources/h3-tileset-source.d.ts +0 -5
  103. package/build/sources/index.d.ts +0 -26
  104. package/build/sources/quadbin-query-source.d.ts +0 -5
  105. package/build/sources/quadbin-table-source.d.ts +0 -5
  106. package/build/sources/quadbin-tileset-source.d.ts +0 -5
  107. package/build/sources/raster-source.d.ts +0 -4
  108. package/build/sources/types.d.ts +0 -366
  109. package/build/sources/vector-query-source.d.ts +0 -5
  110. package/build/sources/vector-table-source.d.ts +0 -5
  111. package/build/sources/vector-tileset-source.d.ts +0 -5
  112. package/build/spatial-index.d.ts +0 -8
  113. package/build/types-internal.d.ts +0 -56
  114. package/build/types.d.ts +0 -140
  115. package/build/utils/dateUtils.d.ts +0 -10
  116. package/build/utils/getTileFormat.d.ts +0 -3
  117. package/build/utils/makeIntervalComplete.d.ts +0 -2
  118. package/build/utils/transformTileCoordsToWGS84.d.ts +0 -8
  119. package/build/utils/transformToTileCoords.d.ts +0 -9
  120. package/build/utils.d.ts +0 -32
  121. package/build/widget-sources/index.d.ts +0 -5
  122. package/build/widget-sources/types.d.ts +0 -158
  123. package/build/widget-sources/widget-query-source.d.ts +0 -33
  124. package/build/widget-sources/widget-remote-source.d.ts +0 -18
  125. package/build/widget-sources/widget-source.d.ts +0 -74
  126. package/build/widget-sources/widget-table-source.d.ts +0 -33
  127. package/build/widget-sources/widget-tileset-source.d.ts +0 -76
@@ -0,0 +1,1949 @@
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __commonJS = (cb, mod2) => function __require() {
9
+ return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
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 = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __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 || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
25
+ mod2
26
+ ));
27
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
28
+
29
+ // node_modules/tilebelt/index.js
30
+ var require_tilebelt = __commonJS({
31
+ "node_modules/tilebelt/index.js"(exports, module) {
32
+ "use strict";
33
+ var d2r = Math.PI / 180;
34
+ var r2d = 180 / Math.PI;
35
+ function tileToBBOX(tile) {
36
+ var e = tile2lon(tile[0] + 1, tile[2]);
37
+ var w = tile2lon(tile[0], tile[2]);
38
+ var s = tile2lat(tile[1] + 1, tile[2]);
39
+ var n = tile2lat(tile[1], tile[2]);
40
+ return [w, s, e, n];
41
+ }
42
+ function tileToGeoJSON(tile) {
43
+ var bbox = tileToBBOX(tile);
44
+ var poly = {
45
+ type: "Polygon",
46
+ coordinates: [
47
+ [
48
+ [bbox[0], bbox[1]],
49
+ [bbox[0], bbox[3]],
50
+ [bbox[2], bbox[3]],
51
+ [bbox[2], bbox[1]],
52
+ [bbox[0], bbox[1]]
53
+ ]
54
+ ]
55
+ };
56
+ return poly;
57
+ }
58
+ function tile2lon(x, z) {
59
+ return x / Math.pow(2, z) * 360 - 180;
60
+ }
61
+ function tile2lat(y, z) {
62
+ var n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
63
+ return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
64
+ }
65
+ function pointToTile(lon, lat, z) {
66
+ var tile = pointToTileFraction(lon, lat, z);
67
+ tile[0] = Math.floor(tile[0]);
68
+ tile[1] = Math.floor(tile[1]);
69
+ return tile;
70
+ }
71
+ function getChildren(tile) {
72
+ return [
73
+ [tile[0] * 2, tile[1] * 2, tile[2] + 1],
74
+ [tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],
75
+ [tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],
76
+ [tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1]
77
+ ];
78
+ }
79
+ function getParent(tile) {
80
+ if (tile[0] % 2 === 0 && tile[1] % 2 === 0) {
81
+ return [tile[0] / 2, tile[1] / 2, tile[2] - 1];
82
+ } else if (tile[0] % 2 === 0 && !tile[1] % 2 === 0) {
83
+ return [tile[0] / 2, (tile[1] - 1) / 2, tile[2] - 1];
84
+ } else if (!tile[0] % 2 === 0 && tile[1] % 2 === 0) {
85
+ return [(tile[0] - 1) / 2, tile[1] / 2, tile[2] - 1];
86
+ } else {
87
+ return [(tile[0] - 1) / 2, (tile[1] - 1) / 2, tile[2] - 1];
88
+ }
89
+ }
90
+ function getSiblings(tile) {
91
+ return getChildren(getParent(tile));
92
+ }
93
+ function hasSiblings(tile, tiles2) {
94
+ var siblings = getSiblings(tile);
95
+ for (var i = 0; i < siblings.length; i++) {
96
+ if (!hasTile(tiles2, siblings[i])) return false;
97
+ }
98
+ return true;
99
+ }
100
+ function hasTile(tiles2, tile) {
101
+ for (var i = 0; i < tiles2.length; i++) {
102
+ if (tilesEqual(tiles2[i], tile)) return true;
103
+ }
104
+ return false;
105
+ }
106
+ function tilesEqual(tile1, tile2) {
107
+ return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2];
108
+ }
109
+ function tileToQuadkey(tile) {
110
+ var index = "";
111
+ for (var z = tile[2]; z > 0; z--) {
112
+ var b = 0;
113
+ var mask = 1 << z - 1;
114
+ if ((tile[0] & mask) !== 0) b++;
115
+ if ((tile[1] & mask) !== 0) b += 2;
116
+ index += b.toString();
117
+ }
118
+ return index;
119
+ }
120
+ function quadkeyToTile(quadkey) {
121
+ var x = 0;
122
+ var y = 0;
123
+ var z = quadkey.length;
124
+ for (var i = z; i > 0; i--) {
125
+ var mask = 1 << i - 1;
126
+ switch (quadkey[z - i]) {
127
+ case "0":
128
+ break;
129
+ case "1":
130
+ x |= mask;
131
+ break;
132
+ case "2":
133
+ y |= mask;
134
+ break;
135
+ case "3":
136
+ x |= mask;
137
+ y |= mask;
138
+ break;
139
+ }
140
+ }
141
+ return [x, y, z];
142
+ }
143
+ function bboxToTile(bboxCoords) {
144
+ var min2 = pointToTile(bboxCoords[0], bboxCoords[1], 32);
145
+ var max2 = pointToTile(bboxCoords[2], bboxCoords[3], 32);
146
+ var bbox = [min2[0], min2[1], max2[0], max2[1]];
147
+ var z = getBboxZoom(bbox);
148
+ if (z === 0) return [0, 0, 0];
149
+ var x = bbox[0] >>> 32 - z;
150
+ var y = bbox[1] >>> 32 - z;
151
+ return [x, y, z];
152
+ }
153
+ function getBboxZoom(bbox) {
154
+ var MAX_ZOOM = 28;
155
+ for (var z = 0; z < MAX_ZOOM; z++) {
156
+ var mask = 1 << 32 - (z + 1);
157
+ if ((bbox[0] & mask) != (bbox[2] & mask) || (bbox[1] & mask) != (bbox[3] & mask)) {
158
+ return z;
159
+ }
160
+ }
161
+ return MAX_ZOOM;
162
+ }
163
+ function pointToTileFraction(lon, lat, z) {
164
+ var sin2 = Math.sin(lat * d2r), z2 = Math.pow(2, z), x = z2 * (lon / 360 + 0.5), y = z2 * (0.5 - 0.25 * Math.log((1 + sin2) / (1 - sin2)) / Math.PI);
165
+ return [x, y, z];
166
+ }
167
+ module.exports = {
168
+ tileToGeoJSON,
169
+ tileToBBOX,
170
+ getChildren,
171
+ getParent,
172
+ getSiblings,
173
+ hasTile,
174
+ hasSiblings,
175
+ tilesEqual,
176
+ tileToQuadkey,
177
+ quadkeyToTile,
178
+ pointToTile,
179
+ bboxToTile,
180
+ pointToTileFraction
181
+ };
182
+ }
183
+ });
184
+
185
+ // node_modules/@mapbox/tile-cover/index.js
186
+ var require_tile_cover = __commonJS({
187
+ "node_modules/@mapbox/tile-cover/index.js"(exports) {
188
+ "use strict";
189
+ var tilebelt = require_tilebelt();
190
+ exports.geojson = function(geom, limits) {
191
+ return {
192
+ type: "FeatureCollection",
193
+ features: getTiles(geom, limits).map(tileToFeature)
194
+ };
195
+ };
196
+ function tileToFeature(t) {
197
+ return {
198
+ type: "Feature",
199
+ geometry: tilebelt.tileToGeoJSON(t),
200
+ properties: {}
201
+ };
202
+ }
203
+ exports.tiles = getTiles;
204
+ exports.indexes = function(geom, limits) {
205
+ return getTiles(geom, limits).map(tilebelt.tileToQuadkey);
206
+ };
207
+ function getTiles(geom, limits) {
208
+ var i, tile, coords = geom.coordinates, maxZoom = limits.max_zoom, tileHash = {}, tiles2 = [];
209
+ if (geom.type === "Point") {
210
+ return [tilebelt.pointToTile(coords[0], coords[1], maxZoom)];
211
+ } else if (geom.type === "MultiPoint") {
212
+ for (i = 0; i < coords.length; i++) {
213
+ tile = tilebelt.pointToTile(coords[i][0], coords[i][1], maxZoom);
214
+ tileHash[toID(tile[0], tile[1], tile[2])] = true;
215
+ }
216
+ } else if (geom.type === "LineString") {
217
+ lineCover(tileHash, coords, maxZoom);
218
+ } else if (geom.type === "MultiLineString") {
219
+ for (i = 0; i < coords.length; i++) {
220
+ lineCover(tileHash, coords[i], maxZoom);
221
+ }
222
+ } else if (geom.type === "Polygon") {
223
+ polygonCover(tileHash, tiles2, coords, maxZoom);
224
+ } else if (geom.type === "MultiPolygon") {
225
+ for (i = 0; i < coords.length; i++) {
226
+ polygonCover(tileHash, tiles2, coords[i], maxZoom);
227
+ }
228
+ } else {
229
+ throw new Error("Geometry type not implemented");
230
+ }
231
+ if (limits.min_zoom !== maxZoom) {
232
+ var len = tiles2.length;
233
+ appendHashTiles(tileHash, tiles2);
234
+ for (i = 0; i < len; i++) {
235
+ var t = tiles2[i];
236
+ tileHash[toID(t[0], t[1], t[2])] = true;
237
+ }
238
+ return mergeTiles(tileHash, tiles2, limits);
239
+ }
240
+ appendHashTiles(tileHash, tiles2);
241
+ return tiles2;
242
+ }
243
+ function mergeTiles(tileHash, tiles2, limits) {
244
+ var mergedTiles = [];
245
+ for (var z = limits.max_zoom; z > limits.min_zoom; z--) {
246
+ var parentTileHash = {};
247
+ var parentTiles = [];
248
+ for (var i = 0; i < tiles2.length; i++) {
249
+ var t = tiles2[i];
250
+ if (t[0] % 2 === 0 && t[1] % 2 === 0) {
251
+ var id2 = toID(t[0] + 1, t[1], z), id3 = toID(t[0], t[1] + 1, z), id4 = toID(t[0] + 1, t[1] + 1, z);
252
+ if (tileHash[id2] && tileHash[id3] && tileHash[id4]) {
253
+ tileHash[toID(t[0], t[1], t[2])] = false;
254
+ tileHash[id2] = false;
255
+ tileHash[id3] = false;
256
+ tileHash[id4] = false;
257
+ var parentTile = [t[0] / 2, t[1] / 2, z - 1];
258
+ if (z - 1 === limits.min_zoom) mergedTiles.push(parentTile);
259
+ else {
260
+ parentTileHash[toID(t[0] / 2, t[1] / 2, z - 1)] = true;
261
+ parentTiles.push(parentTile);
262
+ }
263
+ }
264
+ }
265
+ }
266
+ for (i = 0; i < tiles2.length; i++) {
267
+ t = tiles2[i];
268
+ if (tileHash[toID(t[0], t[1], t[2])]) mergedTiles.push(t);
269
+ }
270
+ tileHash = parentTileHash;
271
+ tiles2 = parentTiles;
272
+ }
273
+ return mergedTiles;
274
+ }
275
+ function polygonCover(tileHash, tileArray, geom, zoom) {
276
+ var intersections = [];
277
+ for (var i = 0; i < geom.length; i++) {
278
+ var ring = [];
279
+ lineCover(tileHash, geom[i], zoom, ring);
280
+ for (var j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
281
+ var m = (j + 1) % len;
282
+ var y = ring[j][1];
283
+ if ((y > ring[k][1] || y > ring[m][1]) && // not local minimum
284
+ (y < ring[k][1] || y < ring[m][1]) && // not local maximum
285
+ y !== ring[m][1]) intersections.push(ring[j]);
286
+ }
287
+ }
288
+ intersections.sort(compareTiles);
289
+ for (i = 0; i < intersections.length; i += 2) {
290
+ y = intersections[i][1];
291
+ for (var x = intersections[i][0] + 1; x < intersections[i + 1][0]; x++) {
292
+ var id = toID(x, y, zoom);
293
+ if (!tileHash[id]) {
294
+ tileArray.push([x, y, zoom]);
295
+ }
296
+ }
297
+ }
298
+ }
299
+ function compareTiles(a, b) {
300
+ return a[1] - b[1] || a[0] - b[0];
301
+ }
302
+ function lineCover(tileHash, coords, maxZoom, ring) {
303
+ var prevX, prevY;
304
+ for (var i = 0; i < coords.length - 1; i++) {
305
+ var start = tilebelt.pointToTileFraction(coords[i][0], coords[i][1], maxZoom), stop = tilebelt.pointToTileFraction(coords[i + 1][0], coords[i + 1][1], maxZoom), x0 = start[0], y0 = start[1], x1 = stop[0], y1 = stop[1], dx = x1 - x0, dy = y1 - y0;
306
+ if (dy === 0 && dx === 0) continue;
307
+ var sx = dx > 0 ? 1 : -1, sy = dy > 0 ? 1 : -1, x = Math.floor(x0), y = Math.floor(y0), tMaxX = dx === 0 ? Infinity : Math.abs(((dx > 0 ? 1 : 0) + x - x0) / dx), tMaxY = dy === 0 ? Infinity : Math.abs(((dy > 0 ? 1 : 0) + y - y0) / dy), tdx = Math.abs(sx / dx), tdy = Math.abs(sy / dy);
308
+ if (x !== prevX || y !== prevY) {
309
+ tileHash[toID(x, y, maxZoom)] = true;
310
+ if (ring && y !== prevY) ring.push([x, y]);
311
+ prevX = x;
312
+ prevY = y;
313
+ }
314
+ while (tMaxX < 1 || tMaxY < 1) {
315
+ if (tMaxX < tMaxY) {
316
+ tMaxX += tdx;
317
+ x += sx;
318
+ } else {
319
+ tMaxY += tdy;
320
+ y += sy;
321
+ }
322
+ tileHash[toID(x, y, maxZoom)] = true;
323
+ if (ring && y !== prevY) ring.push([x, y]);
324
+ prevX = x;
325
+ prevY = y;
326
+ }
327
+ }
328
+ if (ring && y === ring[0][1]) ring.pop();
329
+ }
330
+ function appendHashTiles(hash, tiles2) {
331
+ var keys = Object.keys(hash);
332
+ for (var i = 0; i < keys.length; i++) {
333
+ tiles2.push(fromID(+keys[i]));
334
+ }
335
+ }
336
+ function toID(x, y, z) {
337
+ var dim = 2 * (1 << z);
338
+ return (dim * y + x) * 32 + z;
339
+ }
340
+ function fromID(id) {
341
+ var z = id % 32, dim = 2 * (1 << z), xy = (id - z) / 32, x = xy % dim, y = (xy - x) / dim % dim;
342
+ return [x, y, z];
343
+ }
344
+ }
345
+ });
346
+
347
+ // node_modules/thenby/thenBy.module.js
348
+ var require_thenBy_module = __commonJS({
349
+ "node_modules/thenby/thenBy.module.js"(exports, module) {
350
+ "use strict";
351
+ module.exports = function() {
352
+ function identity(v) {
353
+ return v;
354
+ }
355
+ function ignoreCase(v) {
356
+ return typeof v === "string" ? v.toLowerCase() : v;
357
+ }
358
+ function makeCompareFunction(f, opt) {
359
+ opt = typeof opt === "object" ? opt : { direction: opt };
360
+ if (typeof f != "function") {
361
+ var prop = f;
362
+ f = function(v1) {
363
+ return !!v1[prop] ? v1[prop] : "";
364
+ };
365
+ }
366
+ if (f.length === 1) {
367
+ var uf = f;
368
+ var preprocess = opt.ignoreCase ? ignoreCase : identity;
369
+ var cmp = opt.cmp || function(v1, v2) {
370
+ return v1 < v2 ? -1 : v1 > v2 ? 1 : 0;
371
+ };
372
+ f = function(v1, v2) {
373
+ return cmp(preprocess(uf(v1)), preprocess(uf(v2)));
374
+ };
375
+ }
376
+ const descTokens = { "-1": "", desc: "" };
377
+ if (opt.direction in descTokens) return function(v1, v2) {
378
+ return -f(v1, v2);
379
+ };
380
+ return f;
381
+ }
382
+ function tb(func, opt) {
383
+ var x = typeof this == "function" && !this.firstBy ? this : false;
384
+ var y = makeCompareFunction(func, opt);
385
+ var f = x ? function(a, b) {
386
+ return x(a, b) || y(a, b);
387
+ } : y;
388
+ f.thenBy = tb;
389
+ return f;
390
+ }
391
+ tb.firstBy = tb;
392
+ return tb;
393
+ }();
394
+ }
395
+ });
396
+
397
+ // src/constants.ts
398
+ var FilterType = /* @__PURE__ */ ((FilterType2) => {
399
+ FilterType2["IN"] = "in";
400
+ FilterType2["BETWEEN"] = "between";
401
+ FilterType2["CLOSED_OPEN"] = "closed_open";
402
+ FilterType2["TIME"] = "time";
403
+ FilterType2["STRING_SEARCH"] = "stringSearch";
404
+ return FilterType2;
405
+ })(FilterType || {});
406
+ var DEFAULT_API_BASE_URL = "https://gcp-us-east1.api.carto.com";
407
+
408
+ // src/utils.ts
409
+ var FILTER_TYPES = new Set(Object.values(FilterType));
410
+ var isFilterType = (type) => FILTER_TYPES.has(type);
411
+ function getApplicableFilters(owner, filters) {
412
+ if (!filters) return {};
413
+ const applicableFilters = {};
414
+ for (const column in filters) {
415
+ for (const type in filters[column]) {
416
+ if (!isFilterType(type)) continue;
417
+ const filter = filters[column][type];
418
+ const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
419
+ if (filter && isApplicable) {
420
+ applicableFilters[column] || (applicableFilters[column] = {});
421
+ applicableFilters[column][type] = filter;
422
+ }
423
+ }
424
+ }
425
+ return applicableFilters;
426
+ }
427
+ function assert(condition, message) {
428
+ if (!condition) {
429
+ throw new Error(message);
430
+ }
431
+ }
432
+ var _InvalidColumnError = class _InvalidColumnError extends Error {
433
+ constructor(message) {
434
+ super(`${_InvalidColumnError.NAME}: ${message}`);
435
+ this.name = _InvalidColumnError.NAME;
436
+ }
437
+ static is(error) {
438
+ return error instanceof _InvalidColumnError || error.message?.includes(_InvalidColumnError.NAME);
439
+ }
440
+ };
441
+ __publicField(_InvalidColumnError, "NAME", "InvalidColumnError");
442
+ var InvalidColumnError = _InvalidColumnError;
443
+
444
+ // src/utils/makeIntervalComplete.ts
445
+ function makeIntervalComplete(intervals) {
446
+ return intervals.map((val) => {
447
+ if (val[0] === void 0 || val[0] === null) {
448
+ return [Number.MIN_SAFE_INTEGER, val[1]];
449
+ }
450
+ if (val[1] === void 0 || val[1] === null) {
451
+ return [val[0], Number.MAX_SAFE_INTEGER];
452
+ }
453
+ return val;
454
+ });
455
+ }
456
+
457
+ // src/filters/FilterTypes.ts
458
+ var filterFunctions = {
459
+ ["in" /* IN */]: filterIn,
460
+ ["between" /* BETWEEN */]: filterBetween,
461
+ ["time" /* TIME */]: filterTime,
462
+ ["closed_open" /* CLOSED_OPEN */]: filterClosedOpen,
463
+ ["stringSearch" /* STRING_SEARCH */]: filterStringSearch
464
+ };
465
+ function filterIn(filterValues, featureValue) {
466
+ return filterValues.includes(featureValue);
467
+ }
468
+ function filterBetween(filterValues, featureValue) {
469
+ const checkRange = (range) => {
470
+ const [lowerBound, upperBound] = range;
471
+ return featureValue >= lowerBound && featureValue <= upperBound;
472
+ };
473
+ return makeIntervalComplete(filterValues).some(
474
+ checkRange
475
+ );
476
+ }
477
+ function filterTime(filterValues, featureValue) {
478
+ const featureValueAsTimestamp = new Date(featureValue).getTime();
479
+ if (isFinite(featureValueAsTimestamp)) {
480
+ return filterBetween(filterValues, featureValueAsTimestamp);
481
+ } else {
482
+ throw new Error(`Column used to filter by time isn't well formatted.`);
483
+ }
484
+ }
485
+ function filterClosedOpen(filterValues, featureValue) {
486
+ const checkRange = (range) => {
487
+ const [lowerBound, upperBound] = range;
488
+ return featureValue >= lowerBound && featureValue < upperBound;
489
+ };
490
+ return makeIntervalComplete(filterValues).some(
491
+ checkRange
492
+ );
493
+ }
494
+ function filterStringSearch(filterValues, featureValue, params = {}) {
495
+ const normalizedFeatureValue = normalize(featureValue, params);
496
+ const stringRegExp = params.useRegExp ? filterValues : filterValues.map((filterValue) => {
497
+ let stringRegExp2 = escapeRegExp(normalize(filterValue, params));
498
+ if (params.mustStart) stringRegExp2 = `^${stringRegExp2}`;
499
+ if (params.mustEnd) stringRegExp2 = `${stringRegExp2}$`;
500
+ return stringRegExp2;
501
+ });
502
+ const regex = new RegExp(
503
+ stringRegExp.join("|"),
504
+ params.caseSensitive ? "g" : "gi"
505
+ );
506
+ return !!normalizedFeatureValue.match(regex);
507
+ }
508
+ var specialCharRegExp = /[.*+?^${}()|[\]\\]/g;
509
+ var normalizeRegExp = /\p{Diacritic}/gu;
510
+ function escapeRegExp(value) {
511
+ return value.replace(specialCharRegExp, "\\$&");
512
+ }
513
+ function normalize(data, params) {
514
+ let normalizedData = String(data);
515
+ if (!params.keepSpecialCharacters)
516
+ normalizedData = normalizedData.normalize("NFD").replace(normalizeRegExp, "");
517
+ return normalizedData;
518
+ }
519
+
520
+ // src/filters/Filter.ts
521
+ var LOGICAL_OPERATOR_METHODS = {
522
+ and: "every",
523
+ or: "some"
524
+ };
525
+ function passesFilter(columns, filters, feature, filtersLogicalOperator) {
526
+ const method = LOGICAL_OPERATOR_METHODS[filtersLogicalOperator];
527
+ return columns[method]((column) => {
528
+ const columnFilters = filters[column];
529
+ const columnFilterTypes = Object.keys(columnFilters);
530
+ if (!feature || feature[column] === null || feature[column] === void 0) {
531
+ return false;
532
+ }
533
+ return columnFilterTypes.every((filter) => {
534
+ const filterFunction = filterFunctions[filter];
535
+ if (!filterFunction) {
536
+ throw new Error(`"${filter}" filter is not implemented.`);
537
+ }
538
+ return filterFunction(
539
+ columnFilters[filter].values,
540
+ feature[column],
541
+ columnFilters[filter].params
542
+ );
543
+ });
544
+ });
545
+ }
546
+ function _buildFeatureFilter({
547
+ filters = {},
548
+ type = "boolean",
549
+ filtersLogicalOperator = "and"
550
+ }) {
551
+ const columns = Object.keys(filters);
552
+ if (!columns.length) {
553
+ return () => type === "number" ? 1 : true;
554
+ }
555
+ return (feature) => {
556
+ const f = feature.properties || feature;
557
+ const featurePassesFilter = passesFilter(
558
+ columns,
559
+ filters,
560
+ f,
561
+ filtersLogicalOperator
562
+ );
563
+ return type === "number" ? Number(featurePassesFilter) : featurePassesFilter;
564
+ };
565
+ }
566
+ function applyFilters(features, filters, filtersLogicalOperator) {
567
+ return Object.keys(filters).length ? features.filter(_buildFeatureFilter({ filters, filtersLogicalOperator })) : features;
568
+ }
569
+
570
+ // src/filters/geosjonFeatures.ts
571
+ import intersects from "@turf/boolean-intersects";
572
+ function geojsonFeatures({
573
+ geojson,
574
+ spatialFilter,
575
+ uniqueIdProperty
576
+ }) {
577
+ let uniqueIdx = 0;
578
+ const map = /* @__PURE__ */ new Map();
579
+ if (!spatialFilter) {
580
+ return [];
581
+ }
582
+ for (const feature of geojson.features) {
583
+ const uniqueId = uniqueIdProperty ? feature.properties[uniqueIdProperty] : ++uniqueIdx;
584
+ if (!map.has(uniqueId) && intersects(spatialFilter, feature)) {
585
+ map.set(uniqueId, feature.properties);
586
+ }
587
+ }
588
+ return Array.from(map.values());
589
+ }
590
+
591
+ // src/filters/tileFeaturesGeometries.ts
592
+ import bboxPolygon from "@turf/bbox-polygon";
593
+ import intersects2 from "@turf/boolean-intersects";
594
+ import booleanWithin from "@turf/boolean-within";
595
+ import intersect from "@turf/intersect";
596
+
597
+ // node_modules/@math.gl/core/dist/lib/common.js
598
+ var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
599
+ var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
600
+ var DEFAULT_CONFIG = {
601
+ EPSILON: 1e-12,
602
+ debug: false,
603
+ precision: 4,
604
+ printTypes: false,
605
+ printDegrees: false,
606
+ printRowMajor: true,
607
+ _cartographicRadians: false
608
+ };
609
+ globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
610
+ var config = globalThis.mathgl.config;
611
+ function isArray(value) {
612
+ return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
613
+ }
614
+ function lerp(a, b, t) {
615
+ if (isArray(a)) {
616
+ return a.map((ai, i) => lerp(ai, b[i], t));
617
+ }
618
+ return t * b + (1 - t) * a;
619
+ }
620
+
621
+ // node_modules/@math.gl/web-mercator/dist/assert.js
622
+ function assert2(condition, message) {
623
+ if (!condition) {
624
+ throw new Error(message || "@math.gl/web-mercator: assertion failed.");
625
+ }
626
+ }
627
+
628
+ // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
629
+ var PI = Math.PI;
630
+ var PI_4 = PI / 4;
631
+ var DEGREES_TO_RADIANS2 = PI / 180;
632
+ var RADIANS_TO_DEGREES2 = 180 / PI;
633
+ var TILE_SIZE = 512;
634
+ function lngLatToWorld(lngLat) {
635
+ const [lng, lat] = lngLat;
636
+ assert2(Number.isFinite(lng));
637
+ assert2(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
638
+ const lambda2 = lng * DEGREES_TO_RADIANS2;
639
+ const phi2 = lat * DEGREES_TO_RADIANS2;
640
+ const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
641
+ const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
642
+ return [x, y];
643
+ }
644
+ function worldToLngLat(xy) {
645
+ const [x, y] = xy;
646
+ const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
647
+ const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
648
+ return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
649
+ }
650
+
651
+ // node_modules/@math.gl/web-mercator/dist/get-bounds.js
652
+ var DEGREES_TO_RADIANS3 = Math.PI / 180;
653
+
654
+ // src/utils/transformToTileCoords.ts
655
+ var TRANSFORM_FN = {
656
+ Point: transformPoint,
657
+ MultiPoint: transformMultiPoint,
658
+ LineString: transformLineString,
659
+ MultiLineString: transformMultiLineString,
660
+ Polygon: transformPolygon,
661
+ MultiPolygon: transformMultiPolygon
662
+ };
663
+ function transformToTileCoords(geometry, bbox) {
664
+ const [west, south, east, north] = bbox;
665
+ const nw = projectFlat([west, north]);
666
+ const se = projectFlat([east, south]);
667
+ const projectedBbox = [nw, se];
668
+ if (geometry.type === "GeometryCollection") {
669
+ throw new Error("Unsupported geometry type GeometryCollection");
670
+ }
671
+ const transformFn = TRANSFORM_FN[geometry.type];
672
+ const coordinates = transformFn(geometry.coordinates, projectedBbox);
673
+ return { ...geometry, coordinates };
674
+ }
675
+ function transformPoint([pointX, pointY], [nw, se]) {
676
+ const x = inverseLerp(nw[0], se[0], pointX);
677
+ const y = inverseLerp(nw[1], se[1], pointY);
678
+ return [x, y];
679
+ }
680
+ function getPoints(geometry, bbox) {
681
+ return geometry.map((g) => transformPoint(projectFlat(g), bbox));
682
+ }
683
+ function transformMultiPoint(multiPoint, bbox) {
684
+ return getPoints(multiPoint, bbox);
685
+ }
686
+ function transformLineString(line, bbox) {
687
+ return getPoints(line, bbox);
688
+ }
689
+ function transformMultiLineString(multiLineString, bbox) {
690
+ return multiLineString.map(
691
+ (lineString) => transformLineString(lineString, bbox)
692
+ );
693
+ }
694
+ function transformPolygon(polygon, bbox) {
695
+ return polygon.map((polygonRing) => getPoints(polygonRing, bbox));
696
+ }
697
+ function transformMultiPolygon(multiPolygon, bbox) {
698
+ return multiPolygon.map((polygon) => transformPolygon(polygon, bbox));
699
+ }
700
+ function projectFlat(xyz) {
701
+ return lngLatToWorld(xyz);
702
+ }
703
+ function inverseLerp(a, b, x) {
704
+ return (x - a) / (b - a);
705
+ }
706
+
707
+ // src/utils/transformTileCoordsToWGS84.ts
708
+ var TRANSFORM_FN2 = {
709
+ Point: transformPoint2,
710
+ MultiPoint: transformMultiPoint2,
711
+ LineString: transformLineString2,
712
+ MultiLineString: transformMultiLineString2,
713
+ Polygon: transformPolygon2,
714
+ MultiPolygon: transformMultiPolygon2
715
+ };
716
+ function transformTileCoordsToWGS84(geometry, bbox) {
717
+ const [west, south, east, north] = bbox;
718
+ const nw = lngLatToWorld([west, north]);
719
+ const se = lngLatToWorld([east, south]);
720
+ const projectedBbox = [nw, se];
721
+ if (geometry.type === "GeometryCollection") {
722
+ throw new Error("Unsupported geometry type GeometryCollection");
723
+ }
724
+ const transformFn = TRANSFORM_FN2[geometry.type];
725
+ const coordinates = transformFn(geometry.coordinates, projectedBbox);
726
+ return { ...geometry, coordinates };
727
+ }
728
+ function transformPoint2([pointX, pointY], [nw, se]) {
729
+ const x = lerp(nw[0], se[0], pointX);
730
+ const y = lerp(nw[1], se[1], pointY);
731
+ return worldToLngLat([x, y]);
732
+ }
733
+ function getPoints2(geometry, bbox) {
734
+ return geometry.map((g) => transformPoint2(g, bbox));
735
+ }
736
+ function transformMultiPoint2(multiPoint, bbox) {
737
+ return getPoints2(multiPoint, bbox);
738
+ }
739
+ function transformLineString2(line, bbox) {
740
+ return getPoints2(line, bbox);
741
+ }
742
+ function transformMultiLineString2(multiLineString, bbox) {
743
+ return multiLineString.map(
744
+ (lineString) => transformLineString2(lineString, bbox)
745
+ );
746
+ }
747
+ function transformPolygon2(polygon, bbox) {
748
+ return polygon.map((polygonRing) => getPoints2(polygonRing, bbox));
749
+ }
750
+ function transformMultiPolygon2(multiPolygon, bbox) {
751
+ return multiPolygon.map((polygon) => transformPolygon2(polygon, bbox));
752
+ }
753
+
754
+ // src/filters/tileFeaturesGeometries.ts
755
+ import { featureCollection } from "@turf/helpers";
756
+ var FEATURE_GEOM_PROPERTY = "__geomValue";
757
+ function tileFeaturesGeometries({
758
+ tiles: tiles2,
759
+ tileFormat,
760
+ spatialFilter,
761
+ uniqueIdProperty,
762
+ options
763
+ }) {
764
+ const map = /* @__PURE__ */ new Map();
765
+ for (const tile of tiles2) {
766
+ if (tile.isVisible === false || !tile.data) {
767
+ continue;
768
+ }
769
+ const bbox = [
770
+ tile.bbox.west,
771
+ tile.bbox.south,
772
+ tile.bbox.east,
773
+ tile.bbox.north
774
+ ];
775
+ const bboxToGeom = bboxPolygon(bbox);
776
+ const tileIsFullyVisible = booleanWithin(bboxToGeom, spatialFilter);
777
+ const spatialFilterFeature = {
778
+ type: "Feature",
779
+ geometry: spatialFilter,
780
+ properties: {}
781
+ };
782
+ const clippedGeometryToIntersect = intersect(
783
+ featureCollection([bboxToGeom, spatialFilterFeature])
784
+ );
785
+ if (!clippedGeometryToIntersect) {
786
+ continue;
787
+ }
788
+ const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox) : clippedGeometryToIntersect.geometry;
789
+ createIndicesForPoints(tile.data.points);
790
+ calculateFeatures({
791
+ map,
792
+ tileIsFullyVisible,
793
+ geometryIntersection: transformedGeometryToIntersect,
794
+ data: tile.data.points,
795
+ type: "Point",
796
+ bbox,
797
+ tileFormat,
798
+ uniqueIdProperty,
799
+ options
800
+ });
801
+ calculateFeatures({
802
+ map,
803
+ tileIsFullyVisible,
804
+ geometryIntersection: transformedGeometryToIntersect,
805
+ data: tile.data.lines,
806
+ type: "LineString",
807
+ bbox,
808
+ tileFormat,
809
+ uniqueIdProperty,
810
+ options
811
+ });
812
+ calculateFeatures({
813
+ map,
814
+ tileIsFullyVisible,
815
+ geometryIntersection: transformedGeometryToIntersect,
816
+ data: tile.data.polygons,
817
+ type: "Polygon",
818
+ bbox,
819
+ tileFormat,
820
+ uniqueIdProperty,
821
+ options
822
+ });
823
+ }
824
+ return Array.from(map.values());
825
+ }
826
+ function processTileFeatureProperties({
827
+ map,
828
+ data,
829
+ startIndex,
830
+ endIndex,
831
+ type,
832
+ bbox,
833
+ tileFormat,
834
+ uniqueIdProperty,
835
+ storeGeometry,
836
+ geometryIntersection
837
+ }) {
838
+ const tileProps = getPropertiesFromTile(data, startIndex);
839
+ const uniquePropertyValue = getUniquePropertyValue(
840
+ tileProps,
841
+ uniqueIdProperty,
842
+ map
843
+ );
844
+ if (!uniquePropertyValue || map.has(uniquePropertyValue)) {
845
+ return;
846
+ }
847
+ let geometry = null;
848
+ if (storeGeometry || geometryIntersection) {
849
+ const { positions } = data;
850
+ const ringCoordinates = getRingCoordinatesFor(
851
+ startIndex,
852
+ endIndex,
853
+ positions
854
+ );
855
+ geometry = getFeatureByType(ringCoordinates, type);
856
+ }
857
+ if (geometry && geometryIntersection && !intersects2(geometry, geometryIntersection)) {
858
+ return;
859
+ }
860
+ const properties = parseProperties(tileProps);
861
+ if (storeGeometry && geometry) {
862
+ properties[FEATURE_GEOM_PROPERTY] = tileFormat === "mvt" /* MVT */ ? transformTileCoordsToWGS84(geometry, bbox) : geometry;
863
+ }
864
+ map.set(uniquePropertyValue, properties);
865
+ }
866
+ function addIntersectedFeaturesInTile({
867
+ map,
868
+ data,
869
+ geometryIntersection,
870
+ type,
871
+ bbox,
872
+ tileFormat,
873
+ uniqueIdProperty,
874
+ options
875
+ }) {
876
+ const indices = getIndices(data);
877
+ const storeGeometry = options?.storeGeometry || false;
878
+ for (let i = 0; i < indices.length - 1; i++) {
879
+ const startIndex = indices[i];
880
+ const endIndex = indices[i + 1];
881
+ processTileFeatureProperties({
882
+ map,
883
+ data,
884
+ startIndex,
885
+ endIndex,
886
+ type,
887
+ bbox,
888
+ tileFormat,
889
+ uniqueIdProperty,
890
+ storeGeometry,
891
+ geometryIntersection
892
+ });
893
+ }
894
+ }
895
+ function getIndices(data) {
896
+ let indices;
897
+ switch (data.type) {
898
+ case "Point":
899
+ indices = data.pointIndices;
900
+ break;
901
+ case "LineString":
902
+ indices = data.pathIndices;
903
+ break;
904
+ case "Polygon":
905
+ indices = data.primitivePolygonIndices;
906
+ break;
907
+ default:
908
+ throw new Error(`Unexpected type, "${data.type}"`);
909
+ }
910
+ return indices.value;
911
+ }
912
+ function getFeatureId(data, startIndex) {
913
+ return data.featureIds.value[startIndex];
914
+ }
915
+ function getPropertiesFromTile(data, startIndex) {
916
+ const featureId = getFeatureId(data, startIndex);
917
+ const { properties, numericProps, fields } = data;
918
+ const result = {
919
+ uniqueId: fields?.[featureId]?.id,
920
+ properties: properties[featureId],
921
+ numericProps: {}
922
+ };
923
+ for (const key in numericProps) {
924
+ result.numericProps[key] = numericProps[key].value[startIndex];
925
+ }
926
+ return result;
927
+ }
928
+ function parseProperties(tileProps) {
929
+ const { properties, numericProps } = tileProps;
930
+ return Object.assign({}, properties, numericProps);
931
+ }
932
+ function getUniquePropertyValue(tileProps, uniqueIdProperty, map) {
933
+ if (uniqueIdProperty) {
934
+ return getValueFromTileProps(tileProps, uniqueIdProperty);
935
+ }
936
+ if (tileProps.uniqueId) {
937
+ return tileProps.uniqueId;
938
+ }
939
+ const artificialId = map.size + 1;
940
+ return getValueFromTileProps(tileProps, "cartodb_id") || getValueFromTileProps(tileProps, "geoid") || artificialId;
941
+ }
942
+ function getValueFromTileProps(tileProps, propertyName) {
943
+ const { properties, numericProps } = tileProps;
944
+ return numericProps[propertyName] || properties[propertyName];
945
+ }
946
+ function getFeatureByType(coordinates, type) {
947
+ switch (type) {
948
+ case "Polygon":
949
+ return { type: "Polygon", coordinates: [coordinates] };
950
+ case "LineString":
951
+ return { type: "LineString", coordinates };
952
+ case "Point":
953
+ return { type: "Point", coordinates: coordinates[0] };
954
+ default:
955
+ throw new Error("Invalid geometry type");
956
+ }
957
+ }
958
+ function getRingCoordinatesFor(startIndex, endIndex, positions) {
959
+ const ringCoordinates = [];
960
+ for (let j = startIndex; j < endIndex; j++) {
961
+ ringCoordinates.push(
962
+ Array.from(
963
+ positions.value.subarray(j * positions.size, (j + 1) * positions.size)
964
+ )
965
+ );
966
+ }
967
+ return ringCoordinates;
968
+ }
969
+ function calculateFeatures({
970
+ map,
971
+ tileIsFullyVisible,
972
+ geometryIntersection,
973
+ data,
974
+ type,
975
+ bbox,
976
+ tileFormat,
977
+ uniqueIdProperty,
978
+ options
979
+ }) {
980
+ if (!data?.properties.length) {
981
+ return;
982
+ }
983
+ if (tileIsFullyVisible) {
984
+ addAllFeaturesInTile({
985
+ map,
986
+ data,
987
+ type,
988
+ bbox,
989
+ tileFormat,
990
+ uniqueIdProperty,
991
+ options
992
+ });
993
+ } else {
994
+ addIntersectedFeaturesInTile({
995
+ map,
996
+ data,
997
+ geometryIntersection,
998
+ type,
999
+ bbox,
1000
+ tileFormat,
1001
+ uniqueIdProperty,
1002
+ options
1003
+ });
1004
+ }
1005
+ }
1006
+ function addAllFeaturesInTile({
1007
+ map,
1008
+ data,
1009
+ type,
1010
+ bbox,
1011
+ tileFormat,
1012
+ uniqueIdProperty,
1013
+ options
1014
+ }) {
1015
+ const indices = getIndices(data);
1016
+ const storeGeometry = options?.storeGeometry || false;
1017
+ for (let i = 0; i < indices.length - 1; i++) {
1018
+ const startIndex = indices[i];
1019
+ const endIndex = indices[i + 1];
1020
+ processTileFeatureProperties({
1021
+ map,
1022
+ data,
1023
+ startIndex,
1024
+ endIndex,
1025
+ type,
1026
+ bbox,
1027
+ tileFormat,
1028
+ uniqueIdProperty,
1029
+ storeGeometry
1030
+ });
1031
+ }
1032
+ }
1033
+ function createIndicesForPoints(data) {
1034
+ const featureIds = data.featureIds.value;
1035
+ const lastFeatureId = featureIds[featureIds.length - 1];
1036
+ const PointIndicesArray = featureIds.constructor;
1037
+ const pointIndices = {
1038
+ value: new PointIndicesArray(featureIds.length + 1),
1039
+ size: 1
1040
+ };
1041
+ pointIndices.value.set(featureIds);
1042
+ pointIndices.value.set([lastFeatureId + 1], featureIds.length);
1043
+ data.pointIndices = pointIndices;
1044
+ }
1045
+
1046
+ // node_modules/quadbin/dist/esm/index.js
1047
+ var import_tile_cover = __toESM(require_tile_cover(), 1);
1048
+ var B = [
1049
+ 0x5555555555555555n,
1050
+ 0x3333333333333333n,
1051
+ 0x0f0f0f0f0f0f0f0fn,
1052
+ 0x00ff00ff00ff00ffn,
1053
+ 0x0000ffff0000ffffn,
1054
+ 0x00000000ffffffffn
1055
+ ];
1056
+ var S = [0n, 1n, 2n, 4n, 8n, 16n];
1057
+ function tileToCell(tile) {
1058
+ if (tile.z < 0 || tile.z > 26) {
1059
+ throw new Error("Wrong zoom");
1060
+ }
1061
+ const z = BigInt(tile.z);
1062
+ let x = BigInt(tile.x) << 32n - z;
1063
+ let y = BigInt(tile.y) << 32n - z;
1064
+ for (let i = 0; i < 5; i++) {
1065
+ const s = S[5 - i];
1066
+ const b = B[4 - i];
1067
+ x = (x | x << s) & b;
1068
+ y = (y | y << s) & b;
1069
+ }
1070
+ const quadbin = 0x4000000000000000n | 1n << 59n | // | (mode << 59) | (mode_dep << 57)
1071
+ z << 52n | (x | y << 1n) >> 12n | 0xfffffffffffffn >> z * 2n;
1072
+ return quadbin;
1073
+ }
1074
+ function getResolution(quadbin) {
1075
+ return quadbin >> 52n & 0x1fn;
1076
+ }
1077
+ function geometryToCells(geometry, resolution) {
1078
+ const zoom = Number(resolution);
1079
+ return (0, import_tile_cover.tiles)(geometry, {
1080
+ min_zoom: zoom,
1081
+ max_zoom: zoom
1082
+ }).map(([x, y, z]) => tileToCell({ x, y, z }));
1083
+ }
1084
+
1085
+ // src/filters/tileFeaturesSpatialIndex.ts
1086
+ import bboxClip from "@turf/bbox-clip";
1087
+ import { getResolution as h3GetResolution, polygonToCells } from "h3-js";
1088
+ function tileFeaturesSpatialIndex({
1089
+ tiles: tiles2,
1090
+ spatialFilter,
1091
+ spatialDataColumn,
1092
+ spatialDataType
1093
+ }) {
1094
+ const map = /* @__PURE__ */ new Map();
1095
+ const spatialIndex = getSpatialIndex(spatialDataType);
1096
+ const resolution = getResolution2(tiles2, spatialIndex);
1097
+ const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
1098
+ if (!resolution) {
1099
+ return [];
1100
+ }
1101
+ const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
1102
+ if (!cells?.length) {
1103
+ return [];
1104
+ }
1105
+ const cellsSet = new Set(cells);
1106
+ for (const tile of tiles2) {
1107
+ if (tile.isVisible === false || !tile.data) {
1108
+ continue;
1109
+ }
1110
+ tile.data.forEach((d) => {
1111
+ if (cellsSet.has(d.id)) {
1112
+ map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
1113
+ }
1114
+ });
1115
+ }
1116
+ return Array.from(map.values());
1117
+ }
1118
+ function getResolution2(tiles2, spatialIndex) {
1119
+ const data = tiles2.find((tile) => tile.data?.length)?.data;
1120
+ if (!data) {
1121
+ return;
1122
+ }
1123
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
1124
+ return Number(getResolution(data[0].id));
1125
+ }
1126
+ if (spatialIndex === "h3" /* H3 */) {
1127
+ return h3GetResolution(data[0].id);
1128
+ }
1129
+ }
1130
+ var bboxWest = [-180, -90, 0, 90];
1131
+ var bboxEast = [0, -90, 180, 90];
1132
+ function getCellsCoverGeometry(geometry, spatialIndex, resolution) {
1133
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
1134
+ return geometryToCells(geometry, resolution);
1135
+ }
1136
+ if (spatialIndex === "h3" /* H3 */) {
1137
+ return polygonToCells(
1138
+ bboxClip(geometry, bboxWest).geometry.coordinates,
1139
+ resolution,
1140
+ true
1141
+ ).concat(
1142
+ polygonToCells(
1143
+ bboxClip(geometry, bboxEast).geometry.coordinates,
1144
+ resolution,
1145
+ true
1146
+ )
1147
+ );
1148
+ }
1149
+ }
1150
+ function getSpatialIndex(spatialDataType) {
1151
+ switch (spatialDataType) {
1152
+ case "h3":
1153
+ return "h3" /* H3 */;
1154
+ case "quadbin":
1155
+ return "quadbin" /* QUADBIN */;
1156
+ default:
1157
+ throw new Error("Unexpected spatial data type");
1158
+ }
1159
+ }
1160
+
1161
+ // src/constants-internal.ts
1162
+ var DEFAULT_GEO_COLUMN = "geom";
1163
+ var DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
1164
+ var DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
1165
+
1166
+ // src/filters/tileFeatures.ts
1167
+ function tileFeatures({
1168
+ tiles: tiles2,
1169
+ spatialFilter,
1170
+ uniqueIdProperty,
1171
+ tileFormat,
1172
+ spatialDataColumn = DEFAULT_GEO_COLUMN,
1173
+ spatialDataType,
1174
+ options = {}
1175
+ }) {
1176
+ if (spatialDataType !== "geo") {
1177
+ return tileFeaturesSpatialIndex({
1178
+ tiles: tiles2,
1179
+ spatialFilter,
1180
+ spatialDataColumn,
1181
+ spatialDataType
1182
+ });
1183
+ }
1184
+ return tileFeaturesGeometries({
1185
+ tiles: tiles2,
1186
+ tileFormat,
1187
+ spatialFilter,
1188
+ uniqueIdProperty,
1189
+ options
1190
+ });
1191
+ }
1192
+
1193
+ // src/operations/aggregation.ts
1194
+ var aggregationFunctions = {
1195
+ count: (values) => values.length,
1196
+ min: (...args) => applyAggregationFunction(min, ...args),
1197
+ max: (...args) => applyAggregationFunction(max, ...args),
1198
+ sum: (...args) => applyAggregationFunction(sum, ...args),
1199
+ avg: (...args) => applyAggregationFunction(avg, ...args)
1200
+ };
1201
+ function aggregate(feature, keys, operation) {
1202
+ if (!keys?.length) {
1203
+ throw new Error("Cannot aggregate a feature without having keys");
1204
+ } else if (keys.length === 1) {
1205
+ const value = feature[keys[0]];
1206
+ return isPotentiallyValidNumber(value) ? Number(value) : value;
1207
+ }
1208
+ const aggregationFn = aggregationFunctions[operation];
1209
+ if (!aggregationFn) {
1210
+ throw new Error(`${operation} isn't a valid aggregation function`);
1211
+ }
1212
+ return aggregationFn(
1213
+ keys.map((column) => {
1214
+ const value = feature[column];
1215
+ return isPotentiallyValidNumber(value) ? Number(value) : value;
1216
+ })
1217
+ );
1218
+ }
1219
+ function isPotentiallyValidNumber(value) {
1220
+ return typeof value === "string" && value.trim().length > 0;
1221
+ }
1222
+ var applyAggregationFunction = (aggFn, values, keys, operation) => {
1223
+ const normalizedKeys = normalizeKeys(keys);
1224
+ const elements = (normalizedKeys?.length || 0) <= 1 ? filterFalsyElements(values, normalizedKeys || []) : values;
1225
+ return aggFn(elements, keys, operation);
1226
+ };
1227
+ function filterFalsyElements(values, keys) {
1228
+ const filterFn = (value) => value !== null && value !== void 0;
1229
+ if (!keys?.length) {
1230
+ return values.filter(filterFn);
1231
+ }
1232
+ return values.filter((v) => filterFn(v[keys[0]]));
1233
+ }
1234
+ function avg(values, keys, joinOperation) {
1235
+ return sum(values, keys, joinOperation) / (values.length || 1);
1236
+ }
1237
+ function sum(values, keys, joinOperation) {
1238
+ const normalizedKeys = normalizeKeys(keys);
1239
+ if (normalizedKeys) {
1240
+ return values.reduce(
1241
+ (a, b) => a + aggregate(b, normalizedKeys, joinOperation),
1242
+ 0
1243
+ );
1244
+ }
1245
+ return values.reduce((a, b) => a + b, 0);
1246
+ }
1247
+ function min(values, keys, joinOperation) {
1248
+ const normalizedKeys = normalizeKeys(keys);
1249
+ if (normalizedKeys) {
1250
+ return values.reduce(
1251
+ (a, b) => Math.min(a, aggregate(b, normalizedKeys, joinOperation)),
1252
+ Infinity
1253
+ );
1254
+ }
1255
+ return Math.min(...values);
1256
+ }
1257
+ function max(values, keys, joinOperation) {
1258
+ const normalizedKeys = normalizeKeys(keys);
1259
+ if (normalizedKeys) {
1260
+ return values.reduce(
1261
+ (a, b) => Math.max(a, aggregate(b, normalizedKeys, joinOperation)),
1262
+ -Infinity
1263
+ );
1264
+ }
1265
+ return Math.max(...values);
1266
+ }
1267
+ function normalizeKeys(keys) {
1268
+ return Array.isArray(keys) ? keys : typeof keys === "string" ? [keys] : void 0;
1269
+ }
1270
+
1271
+ // src/operations/applySorting.ts
1272
+ var import_thenby = __toESM(require_thenBy_module(), 1);
1273
+ function applySorting(features, {
1274
+ sortBy,
1275
+ sortByDirection = "asc",
1276
+ sortByColumnType = "string"
1277
+ } = {}) {
1278
+ if (sortBy === void 0) {
1279
+ return features;
1280
+ }
1281
+ const isValidSortBy = Array.isArray(sortBy) && sortBy.length || // sortBy can be an array of columns
1282
+ typeof sortBy === "string";
1283
+ if (!isValidSortBy) {
1284
+ throw new Error("Sorting options are bad formatted");
1285
+ }
1286
+ const sortFn = createSortFn({
1287
+ sortBy,
1288
+ sortByDirection,
1289
+ sortByColumnType: sortByColumnType || "string"
1290
+ });
1291
+ return features.sort(sortFn);
1292
+ }
1293
+ function createSortFn({
1294
+ sortBy,
1295
+ sortByDirection,
1296
+ sortByColumnType
1297
+ }) {
1298
+ const [firstSortOption, ...othersSortOptions] = normalizeSortByOptions({
1299
+ sortBy,
1300
+ sortByDirection,
1301
+ sortByColumnType
1302
+ });
1303
+ let sortFn = (0, import_thenby.firstBy)(...firstSortOption);
1304
+ for (const sortOptions of othersSortOptions) {
1305
+ sortFn = sortFn.thenBy(...sortOptions);
1306
+ }
1307
+ return sortFn;
1308
+ }
1309
+ function normalizeSortByOptions({
1310
+ sortBy,
1311
+ sortByDirection,
1312
+ sortByColumnType
1313
+ }) {
1314
+ const numberFormat = sortByColumnType === "number" && {
1315
+ cmp: (a, b) => a - b
1316
+ };
1317
+ if (!Array.isArray(sortBy)) {
1318
+ sortBy = [sortBy];
1319
+ }
1320
+ return sortBy.map((sortByEl) => {
1321
+ if (typeof sortByEl === "string") {
1322
+ return [sortByEl, { direction: sortByDirection, ...numberFormat }];
1323
+ }
1324
+ if (Array.isArray(sortByEl)) {
1325
+ if (sortByEl[1] === void 0) {
1326
+ return [sortByEl, { direction: sortByDirection, ...numberFormat }];
1327
+ }
1328
+ if (typeof sortByEl[1] === "object") {
1329
+ const othersSortOptions = numberFormat ? { ...numberFormat, ...sortByEl[1] } : sortByEl[1];
1330
+ return [
1331
+ sortByEl[0],
1332
+ { direction: sortByDirection, ...othersSortOptions }
1333
+ ];
1334
+ }
1335
+ }
1336
+ return sortByEl;
1337
+ });
1338
+ }
1339
+
1340
+ // src/operations/groupBy.ts
1341
+ function groupValuesByColumn({
1342
+ data,
1343
+ valuesColumns,
1344
+ joinOperation,
1345
+ keysColumn,
1346
+ operation
1347
+ }) {
1348
+ if (Array.isArray(data) && data.length === 0) {
1349
+ return null;
1350
+ }
1351
+ const groups = data.reduce((accumulator, item) => {
1352
+ const group = item[keysColumn];
1353
+ const values = accumulator.get(group) || [];
1354
+ accumulator.set(group, values);
1355
+ const aggregatedValue = aggregate(item, valuesColumns, joinOperation);
1356
+ const isValid = (operation === "count" ? true : aggregatedValue !== null) && aggregatedValue !== void 0;
1357
+ if (isValid) {
1358
+ values.push(aggregatedValue);
1359
+ accumulator.set(group, values);
1360
+ }
1361
+ return accumulator;
1362
+ }, /* @__PURE__ */ new Map());
1363
+ const targetOperation = aggregationFunctions[operation];
1364
+ if (targetOperation) {
1365
+ return Array.from(groups).map(([name, value]) => ({
1366
+ name,
1367
+ value: targetOperation(value)
1368
+ }));
1369
+ }
1370
+ return [];
1371
+ }
1372
+
1373
+ // src/utils/dateUtils.ts
1374
+ function getUTCMonday(date) {
1375
+ const dateCp = new Date(date);
1376
+ const day = dateCp.getUTCDay();
1377
+ const diff = dateCp.getUTCDate() - day + (day ? 1 : -6);
1378
+ dateCp.setUTCDate(diff);
1379
+ return Date.UTC(
1380
+ dateCp.getUTCFullYear(),
1381
+ dateCp.getUTCMonth(),
1382
+ dateCp.getUTCDate()
1383
+ );
1384
+ }
1385
+
1386
+ // src/operations/groupByDate.ts
1387
+ var GROUP_KEY_FN_MAPPING = {
1388
+ year: (date) => Date.UTC(date.getUTCFullYear()),
1389
+ month: (date) => Date.UTC(date.getUTCFullYear(), date.getUTCMonth()),
1390
+ week: (date) => getUTCMonday(date),
1391
+ day: (date) => Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()),
1392
+ hour: (date) => Date.UTC(
1393
+ date.getUTCFullYear(),
1394
+ date.getUTCMonth(),
1395
+ date.getUTCDate(),
1396
+ date.getUTCHours()
1397
+ ),
1398
+ minute: (date) => Date.UTC(
1399
+ date.getUTCFullYear(),
1400
+ date.getUTCMonth(),
1401
+ date.getUTCDate(),
1402
+ date.getUTCHours(),
1403
+ date.getUTCMinutes()
1404
+ ),
1405
+ second: (date) => Date.UTC(
1406
+ date.getUTCFullYear(),
1407
+ date.getUTCMonth(),
1408
+ date.getUTCDate(),
1409
+ date.getUTCHours(),
1410
+ date.getUTCMinutes(),
1411
+ date.getUTCSeconds()
1412
+ )
1413
+ };
1414
+ function groupValuesByDateColumn({
1415
+ data,
1416
+ valuesColumns,
1417
+ joinOperation,
1418
+ keysColumn,
1419
+ groupType,
1420
+ operation
1421
+ }) {
1422
+ if (Array.isArray(data) && data.length === 0) {
1423
+ return null;
1424
+ }
1425
+ const groupKeyFn = GROUP_KEY_FN_MAPPING[groupType];
1426
+ if (!groupKeyFn) {
1427
+ return null;
1428
+ }
1429
+ const groups = data.reduce((acc, item) => {
1430
+ const value = item[keysColumn];
1431
+ const formattedValue = new Date(value);
1432
+ const groupKey = groupKeyFn(formattedValue);
1433
+ if (!isNaN(groupKey)) {
1434
+ let groupedValues = acc.get(groupKey);
1435
+ if (!groupedValues) {
1436
+ groupedValues = [];
1437
+ acc.set(groupKey, groupedValues);
1438
+ }
1439
+ const aggregatedValue = aggregate(item, valuesColumns, joinOperation);
1440
+ const isValid = aggregatedValue !== null && aggregatedValue !== void 0;
1441
+ if (isValid) {
1442
+ groupedValues.push(aggregatedValue);
1443
+ acc.set(groupKey, groupedValues);
1444
+ }
1445
+ }
1446
+ return acc;
1447
+ }, /* @__PURE__ */ new Map());
1448
+ const targetOperation = aggregationFunctions[operation];
1449
+ return [...groups.entries()].map(([name, value]) => ({
1450
+ name,
1451
+ value: targetOperation(value)
1452
+ })).sort((a, b) => a.name - b.name);
1453
+ }
1454
+
1455
+ // src/operations/histogram.ts
1456
+ function histogram({
1457
+ data,
1458
+ valuesColumns,
1459
+ joinOperation,
1460
+ ticks,
1461
+ operation
1462
+ }) {
1463
+ if (Array.isArray(data) && data.length === 0) {
1464
+ return [];
1465
+ }
1466
+ const binsContainer = [Number.MIN_SAFE_INTEGER, ...ticks].map(
1467
+ (tick, index, arr) => ({
1468
+ bin: index,
1469
+ start: tick,
1470
+ end: index === arr.length - 1 ? Number.MAX_SAFE_INTEGER : arr[index + 1],
1471
+ values: []
1472
+ })
1473
+ );
1474
+ data.forEach((feature) => {
1475
+ const featureValue = aggregate(
1476
+ feature,
1477
+ valuesColumns,
1478
+ joinOperation
1479
+ );
1480
+ const isValid = featureValue !== null && featureValue !== void 0;
1481
+ if (!isValid) {
1482
+ return;
1483
+ }
1484
+ const binContainer = binsContainer.find(
1485
+ (bin) => bin.start <= featureValue && bin.end > featureValue
1486
+ );
1487
+ if (!binContainer) {
1488
+ return;
1489
+ }
1490
+ binContainer.values.push(featureValue);
1491
+ });
1492
+ const targetOperation = aggregationFunctions[operation];
1493
+ const transformedBins = binsContainer.map(
1494
+ (binContainer) => binContainer.values
1495
+ );
1496
+ return transformedBins.map(
1497
+ (values) => values.length ? targetOperation(values) : 0
1498
+ );
1499
+ }
1500
+
1501
+ // src/operations/scatterPlot.ts
1502
+ function scatterPlot({
1503
+ data,
1504
+ xAxisColumns,
1505
+ xAxisJoinOperation,
1506
+ yAxisColumns,
1507
+ yAxisJoinOperation
1508
+ }) {
1509
+ return data.reduce(
1510
+ (acc, feature) => {
1511
+ const xValue = aggregate(
1512
+ feature,
1513
+ xAxisColumns,
1514
+ xAxisJoinOperation
1515
+ );
1516
+ const xIsValid = xValue !== null && xValue !== void 0;
1517
+ const yValue = aggregate(
1518
+ feature,
1519
+ yAxisColumns,
1520
+ yAxisJoinOperation
1521
+ );
1522
+ const yIsValid = yValue !== null && yValue !== void 0;
1523
+ if (xIsValid && yIsValid) {
1524
+ acc.push([xValue, yValue]);
1525
+ }
1526
+ return acc;
1527
+ },
1528
+ []
1529
+ );
1530
+ }
1531
+
1532
+ // src/client.ts
1533
+ var client = "deck-gl-carto";
1534
+ function getClient() {
1535
+ return client;
1536
+ }
1537
+
1538
+ // src/spatial-index.ts
1539
+ var DEFAULT_TILE_SIZE = 512;
1540
+ var QUADBIN_ZOOM_MAX_OFFSET = 4;
1541
+ function getSpatialFiltersResolution(source2, viewState) {
1542
+ const dataResolution = source2.dataResolution ?? Number.MAX_VALUE;
1543
+ const aggregationResLevel = source2.aggregationResLevel ?? (source2.spatialDataType === "h3" ? DEFAULT_AGGREGATION_RES_LEVEL_H3 : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN);
1544
+ const aggregationResLevelOffset = Math.max(
1545
+ 0,
1546
+ Math.floor(aggregationResLevel)
1547
+ );
1548
+ const currentZoomInt = Math.ceil(viewState.zoom);
1549
+ if (source2.spatialDataType === "h3") {
1550
+ const tileSize = DEFAULT_TILE_SIZE;
1551
+ const maxResolutionForZoom = maxH3SpatialFiltersResolutions.find(
1552
+ ([zoom]) => zoom === currentZoomInt
1553
+ )?.[1] ?? Math.max(0, currentZoomInt - 3);
1554
+ const maxSpatialFiltersResolution = maxResolutionForZoom ? Math.min(dataResolution, maxResolutionForZoom) : dataResolution;
1555
+ const hexagonResolution = _getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
1556
+ return Math.min(hexagonResolution, maxSpatialFiltersResolution);
1557
+ }
1558
+ if (source2.spatialDataType === "quadbin") {
1559
+ const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
1560
+ const maxSpatialFiltersResolution = Math.min(
1561
+ dataResolution,
1562
+ maxResolutionForZoom
1563
+ );
1564
+ const quadsResolution = Math.floor(viewState.zoom) + aggregationResLevelOffset;
1565
+ return Math.min(quadsResolution, maxSpatialFiltersResolution);
1566
+ }
1567
+ return void 0;
1568
+ }
1569
+ var maxH3SpatialFiltersResolutions = [
1570
+ [20, 14],
1571
+ [19, 13],
1572
+ [18, 12],
1573
+ [17, 11],
1574
+ [16, 10],
1575
+ [15, 9],
1576
+ [14, 8],
1577
+ [13, 7],
1578
+ [12, 7],
1579
+ [11, 7],
1580
+ [10, 6],
1581
+ [9, 6],
1582
+ [8, 5],
1583
+ [7, 4],
1584
+ [6, 4],
1585
+ [5, 3],
1586
+ [4, 2],
1587
+ [3, 1],
1588
+ [2, 1],
1589
+ [1, 0]
1590
+ ];
1591
+ var BIAS = 2;
1592
+ function _getHexagonResolution(viewport, tileSize) {
1593
+ const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
1594
+ const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
1595
+ const latitudeScaleFactor = Math.log(
1596
+ 1 / Math.cos(Math.PI * viewport.latitude / 180)
1597
+ );
1598
+ return Math.max(
1599
+ 0,
1600
+ Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)
1601
+ );
1602
+ }
1603
+
1604
+ // src/widget-sources/widget-source.ts
1605
+ var _WidgetSource = class _WidgetSource {
1606
+ constructor(props) {
1607
+ __publicField(this, "props");
1608
+ this.props = { ..._WidgetSource.defaultProps, ...props };
1609
+ }
1610
+ /**
1611
+ * Destroys the widget source and releases allocated resources.
1612
+ *
1613
+ * For remote sources (tables, queries) this has no effect, but for local
1614
+ * sources (tilesets, rasters) these resources will affect performance
1615
+ * and stability if many (10+) sources are created and not released.
1616
+ */
1617
+ destroy() {
1618
+ }
1619
+ _getSpatialFiltersResolution(source2, spatialFilter, referenceViewState) {
1620
+ if (!spatialFilter || source2.spatialDataType === "geo") {
1621
+ return;
1622
+ }
1623
+ if (!referenceViewState) {
1624
+ throw new Error(
1625
+ 'Missing required option, "spatialIndexReferenceViewState".'
1626
+ );
1627
+ }
1628
+ return getSpatialFiltersResolution(source2, referenceViewState);
1629
+ }
1630
+ };
1631
+ __publicField(_WidgetSource, "defaultProps", {
1632
+ apiVersion: "v3" /* V3 */,
1633
+ apiBaseUrl: DEFAULT_API_BASE_URL,
1634
+ clientId: getClient(),
1635
+ filters: {},
1636
+ filtersLogicalOperator: "and"
1637
+ });
1638
+ var WidgetSource = _WidgetSource;
1639
+
1640
+ // src/widget-sources/widget-tileset-source-impl.ts
1641
+ import { booleanEqual } from "@turf/boolean-equal";
1642
+ var WidgetTilesetSourceImpl = class extends WidgetSource {
1643
+ constructor() {
1644
+ super(...arguments);
1645
+ __publicField(this, "_tiles", []);
1646
+ __publicField(this, "_features", []);
1647
+ __publicField(this, "_tileFeatureExtractOptions", {});
1648
+ __publicField(this, "_tileFeatureExtractPreviousInputs", {});
1649
+ }
1650
+ /**
1651
+ * Loads features as a list of tiles (typically provided by deck.gl).
1652
+ * After tiles are loaded, {@link extractTileFeatures} must be called
1653
+ * before computing statistics on the tiles.
1654
+ */
1655
+ loadTiles(tiles2) {
1656
+ this._tiles = tiles2;
1657
+ this._features.length = 0;
1658
+ }
1659
+ /** Configures options used to extract features from tiles. */
1660
+ setTileFeatureExtractOptions(options) {
1661
+ this._tileFeatureExtractOptions = options;
1662
+ this._features.length = 0;
1663
+ }
1664
+ _extractTileFeatures(spatialFilter) {
1665
+ const prevInputs = this._tileFeatureExtractPreviousInputs;
1666
+ if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
1667
+ return;
1668
+ }
1669
+ this._features = tileFeatures({
1670
+ tiles: this._tiles,
1671
+ tileFormat: this.props.tileFormat,
1672
+ ...this._tileFeatureExtractOptions,
1673
+ spatialFilter,
1674
+ spatialDataColumn: this.props.spatialDataColumn,
1675
+ spatialDataType: this.props.spatialDataType
1676
+ });
1677
+ prevInputs.spatialFilter = spatialFilter;
1678
+ }
1679
+ /**
1680
+ * Loads features as GeoJSON (used for testing).
1681
+ * @experimental
1682
+ * @internal Not for public use. Spatial filters in other method calls will be ignored.
1683
+ */
1684
+ loadGeoJSON({
1685
+ geojson,
1686
+ spatialFilter
1687
+ }) {
1688
+ this._features = geojsonFeatures({
1689
+ geojson,
1690
+ spatialFilter,
1691
+ ...this._tileFeatureExtractOptions
1692
+ });
1693
+ this._tileFeatureExtractPreviousInputs.spatialFilter = spatialFilter;
1694
+ }
1695
+ async getFeatures() {
1696
+ throw new Error("getFeatures not supported for tilesets");
1697
+ }
1698
+ async getFormula({
1699
+ column = "*",
1700
+ operation = "count",
1701
+ joinOperation,
1702
+ filters,
1703
+ filterOwner,
1704
+ spatialFilter
1705
+ }) {
1706
+ if (operation === "custom") {
1707
+ throw new Error("Custom aggregation not supported for tilesets");
1708
+ }
1709
+ if (column && column !== "*" || operation !== "count") {
1710
+ assertColumn(this._features, column);
1711
+ }
1712
+ const filteredFeatures = this._getFilteredFeatures(
1713
+ spatialFilter,
1714
+ filters,
1715
+ filterOwner
1716
+ );
1717
+ if (filteredFeatures.length === 0 && operation !== "count") {
1718
+ return { value: null };
1719
+ }
1720
+ const targetOperation = aggregationFunctions[operation];
1721
+ return {
1722
+ value: targetOperation(filteredFeatures, column, joinOperation)
1723
+ };
1724
+ }
1725
+ async getHistogram({
1726
+ operation = "count",
1727
+ ticks,
1728
+ column,
1729
+ joinOperation,
1730
+ filters,
1731
+ filterOwner,
1732
+ spatialFilter
1733
+ }) {
1734
+ const filteredFeatures = this._getFilteredFeatures(
1735
+ spatialFilter,
1736
+ filters,
1737
+ filterOwner
1738
+ );
1739
+ if (!this._features.length) {
1740
+ return [];
1741
+ }
1742
+ assertColumn(this._features, column);
1743
+ return histogram({
1744
+ data: filteredFeatures,
1745
+ valuesColumns: normalizeColumns(column),
1746
+ joinOperation,
1747
+ ticks,
1748
+ operation
1749
+ });
1750
+ }
1751
+ async getCategories({
1752
+ column,
1753
+ operation = "count",
1754
+ operationColumn,
1755
+ joinOperation,
1756
+ filters,
1757
+ filterOwner,
1758
+ spatialFilter
1759
+ }) {
1760
+ const filteredFeatures = this._getFilteredFeatures(
1761
+ spatialFilter,
1762
+ filters,
1763
+ filterOwner
1764
+ );
1765
+ if (!filteredFeatures.length) {
1766
+ return [];
1767
+ }
1768
+ assertColumn(this._features, column, operationColumn);
1769
+ const groups = groupValuesByColumn({
1770
+ data: filteredFeatures,
1771
+ valuesColumns: normalizeColumns(operationColumn || column),
1772
+ joinOperation,
1773
+ keysColumn: column,
1774
+ operation
1775
+ });
1776
+ return groups || [];
1777
+ }
1778
+ async getScatter({
1779
+ xAxisColumn,
1780
+ yAxisColumn,
1781
+ xAxisJoinOperation,
1782
+ yAxisJoinOperation,
1783
+ filters,
1784
+ filterOwner,
1785
+ spatialFilter
1786
+ }) {
1787
+ const filteredFeatures = this._getFilteredFeatures(
1788
+ spatialFilter,
1789
+ filters,
1790
+ filterOwner
1791
+ );
1792
+ if (!filteredFeatures.length) {
1793
+ return [];
1794
+ }
1795
+ assertColumn(this._features, xAxisColumn, yAxisColumn);
1796
+ return scatterPlot({
1797
+ data: filteredFeatures,
1798
+ xAxisColumns: normalizeColumns(xAxisColumn),
1799
+ xAxisJoinOperation,
1800
+ yAxisColumns: normalizeColumns(yAxisColumn),
1801
+ yAxisJoinOperation
1802
+ });
1803
+ }
1804
+ async getTable({
1805
+ columns,
1806
+ searchFilterColumn,
1807
+ searchFilterText,
1808
+ sortBy,
1809
+ sortDirection,
1810
+ sortByColumnType,
1811
+ offset = 0,
1812
+ limit = 10,
1813
+ filters,
1814
+ filterOwner,
1815
+ spatialFilter
1816
+ }) {
1817
+ let filteredFeatures = this._getFilteredFeatures(
1818
+ spatialFilter,
1819
+ filters,
1820
+ filterOwner
1821
+ );
1822
+ if (!filteredFeatures.length) {
1823
+ return { rows: [], totalCount: 0 };
1824
+ }
1825
+ if (searchFilterColumn && searchFilterText) {
1826
+ filteredFeatures = filteredFeatures.filter(
1827
+ (row) => row[searchFilterColumn] && String(row[searchFilterColumn]).toLowerCase().includes(String(searchFilterText).toLowerCase())
1828
+ );
1829
+ }
1830
+ let rows = applySorting(filteredFeatures, {
1831
+ sortBy,
1832
+ sortByDirection: sortDirection,
1833
+ sortByColumnType
1834
+ });
1835
+ const totalCount = rows.length;
1836
+ rows = rows.slice(
1837
+ Math.min(offset, totalCount),
1838
+ Math.min(offset + limit, totalCount)
1839
+ );
1840
+ rows = rows.map((srcRow) => {
1841
+ const dstRow = {};
1842
+ for (const column of columns) {
1843
+ dstRow[column] = srcRow[column];
1844
+ }
1845
+ return dstRow;
1846
+ });
1847
+ return { rows, totalCount };
1848
+ }
1849
+ async getTimeSeries({
1850
+ column,
1851
+ stepSize,
1852
+ operation,
1853
+ operationColumn,
1854
+ joinOperation,
1855
+ filters,
1856
+ filterOwner,
1857
+ spatialFilter
1858
+ }) {
1859
+ const filteredFeatures = this._getFilteredFeatures(
1860
+ spatialFilter,
1861
+ filters,
1862
+ filterOwner
1863
+ );
1864
+ if (!filteredFeatures.length) {
1865
+ return { rows: [] };
1866
+ }
1867
+ assertColumn(this._features, column, operationColumn);
1868
+ const rows = groupValuesByDateColumn({
1869
+ data: filteredFeatures,
1870
+ valuesColumns: normalizeColumns(operationColumn || column),
1871
+ keysColumn: column,
1872
+ groupType: stepSize,
1873
+ operation,
1874
+ joinOperation
1875
+ }) || [];
1876
+ return { rows };
1877
+ }
1878
+ async getRange({
1879
+ column,
1880
+ filters,
1881
+ filterOwner,
1882
+ spatialFilter
1883
+ }) {
1884
+ assertColumn(this._features, column);
1885
+ const filteredFeatures = this._getFilteredFeatures(
1886
+ spatialFilter,
1887
+ filters,
1888
+ filterOwner
1889
+ );
1890
+ if (!this._features.length) {
1891
+ return null;
1892
+ }
1893
+ return {
1894
+ min: aggregationFunctions.min(filteredFeatures, column),
1895
+ max: aggregationFunctions.max(filteredFeatures, column)
1896
+ };
1897
+ }
1898
+ /****************************************************************************
1899
+ * INTERNAL
1900
+ */
1901
+ _getFilteredFeatures(spatialFilter, filters, filterOwner) {
1902
+ assert(spatialFilter, "spatialFilter required for tilesets");
1903
+ this._extractTileFeatures(spatialFilter);
1904
+ return applyFilters(
1905
+ this._features,
1906
+ getApplicableFilters(filterOwner, filters || this.props.filters),
1907
+ this.props.filtersLogicalOperator || "and"
1908
+ );
1909
+ }
1910
+ };
1911
+ function assertColumn(features, ...columnArgs) {
1912
+ const columns = Array.from(new Set(columnArgs.map(normalizeColumns).flat()));
1913
+ const featureKeys = Object.keys(features[0]);
1914
+ const invalidColumns = columns.filter(
1915
+ (column) => !featureKeys.includes(column)
1916
+ );
1917
+ if (invalidColumns.length) {
1918
+ throw new InvalidColumnError(
1919
+ `Missing column(s): ${invalidColumns.join(", ")}`
1920
+ );
1921
+ }
1922
+ }
1923
+ function normalizeColumns(columns) {
1924
+ return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
1925
+ }
1926
+
1927
+ // src/workers/widget-tileset-worker.ts
1928
+ var source;
1929
+ addEventListener("message", (e) => {
1930
+ const { method, params, requestId } = e.data;
1931
+ if (method === "init" /* INIT */) {
1932
+ source = new WidgetTilesetSourceImpl({
1933
+ ...params[0],
1934
+ widgetWorker: false
1935
+ });
1936
+ return;
1937
+ }
1938
+ if (!source) {
1939
+ const error = `Cannot execute "${method}" on uninitialized source.`;
1940
+ postMessage({ ok: false, error, requestId });
1941
+ return;
1942
+ }
1943
+ Promise.resolve(source[method](...params)).then((result) => {
1944
+ postMessage({ ok: true, result, requestId });
1945
+ }).catch((error) => {
1946
+ postMessage({ ok: false, error, requestId });
1947
+ });
1948
+ });
1949
+ //# sourceMappingURL=worker.js.map