@kepler.gl/table 3.3.0-alpha.2 → 3.3.0-alpha.21

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 (121) hide show
  1. package/dist/cjs/dataset-ops/aggregations.js +133 -0
  2. package/dist/cjs/dataset-ops/aggregations.js.map +1 -0
  3. package/dist/cjs/dataset-ops/column-edit.js +472 -0
  4. package/dist/cjs/dataset-ops/column-edit.js.map +1 -0
  5. package/dist/cjs/dataset-ops/geometry.js +237 -0
  6. package/dist/cjs/dataset-ops/geometry.js.map +1 -0
  7. package/dist/cjs/dataset-ops/group-by.js +139 -0
  8. package/dist/cjs/dataset-ops/group-by.js.map +1 -0
  9. package/dist/cjs/dataset-ops/index.js +135 -0
  10. package/dist/cjs/dataset-ops/index.js.map +1 -0
  11. package/dist/cjs/dataset-ops/join.js +213 -0
  12. package/dist/cjs/dataset-ops/join.js.map +1 -0
  13. package/dist/cjs/dataset-ops/normalize-bigint-columns.js +58 -0
  14. package/dist/cjs/dataset-ops/normalize-bigint-columns.js.map +1 -0
  15. package/dist/cjs/dataset-ops/proto-dataset.js +71 -0
  16. package/dist/cjs/dataset-ops/proto-dataset.js.map +1 -0
  17. package/dist/cjs/dataset-ops/spatial-join.js +340 -0
  18. package/dist/cjs/dataset-ops/spatial-join.js.map +1 -0
  19. package/dist/cjs/dataset-ops/suitability.js +200 -0
  20. package/dist/cjs/dataset-ops/suitability.js.map +1 -0
  21. package/dist/cjs/dataset-ops/table-helpers.js +48 -0
  22. package/dist/cjs/dataset-ops/table-helpers.js.map +1 -0
  23. package/dist/cjs/dataset-ops/types.js +81 -0
  24. package/dist/cjs/dataset-ops/types.js.map +1 -0
  25. package/dist/cjs/dataset-utils.js +466 -0
  26. package/dist/cjs/dataset-utils.js.map +1 -0
  27. package/dist/cjs/gpu-filter-utils.js +368 -0
  28. package/dist/cjs/gpu-filter-utils.js.map +1 -0
  29. package/dist/cjs/index.js +243 -0
  30. package/dist/cjs/index.js.map +1 -0
  31. package/dist/cjs/kepler-table.js +1044 -0
  32. package/dist/cjs/kepler-table.js.map +1 -0
  33. package/dist/cjs/tileset/raster-tile-utils.js +76 -0
  34. package/dist/cjs/tileset/raster-tile-utils.js.map +1 -0
  35. package/dist/cjs/tileset/tileset-utils.js +83 -0
  36. package/dist/cjs/tileset/tileset-utils.js.map +1 -0
  37. package/dist/cjs/tileset/vector-tile-utils.js +757 -0
  38. package/dist/cjs/tileset/vector-tile-utils.js.map +1 -0
  39. package/dist/cjs/tileset/wms-utils.js +236 -0
  40. package/dist/cjs/tileset/wms-utils.js.map +1 -0
  41. package/dist/cjs/tileset/zarr-axis.js +178 -0
  42. package/dist/cjs/tileset/zarr-axis.js.map +1 -0
  43. package/dist/cjs/tileset/zarr-runtime.js +29 -0
  44. package/dist/cjs/tileset/zarr-runtime.js.map +1 -0
  45. package/dist/cjs/tileset/zarr-utils.js +2168 -0
  46. package/dist/cjs/tileset/zarr-utils.js.map +1 -0
  47. package/dist/dataset-ops/aggregations.d.ts +17 -0
  48. package/dist/dataset-ops/column-edit.d.ts +48 -0
  49. package/dist/dataset-ops/geometry.d.ts +13 -0
  50. package/dist/dataset-ops/group-by.d.ts +3 -0
  51. package/dist/dataset-ops/index.d.ts +12 -0
  52. package/dist/dataset-ops/join.d.ts +3 -0
  53. package/dist/dataset-ops/normalize-bigint-columns.d.ts +7 -0
  54. package/dist/dataset-ops/proto-dataset.d.ts +20 -0
  55. package/dist/dataset-ops/spatial-join.d.ts +17 -0
  56. package/dist/dataset-ops/suitability.d.ts +15 -0
  57. package/dist/dataset-ops/table-helpers.d.ts +12 -0
  58. package/dist/dataset-ops/types.d.ts +164 -0
  59. package/dist/dataset-utils.d.ts +2 -2
  60. package/dist/esm/dataset-ops/aggregations.js +120 -0
  61. package/dist/esm/dataset-ops/aggregations.js.map +1 -0
  62. package/dist/esm/dataset-ops/column-edit.js +460 -0
  63. package/dist/esm/dataset-ops/column-edit.js.map +1 -0
  64. package/dist/esm/dataset-ops/geometry.js +225 -0
  65. package/dist/esm/dataset-ops/geometry.js.map +1 -0
  66. package/dist/esm/dataset-ops/group-by.js +134 -0
  67. package/dist/esm/dataset-ops/group-by.js.map +1 -0
  68. package/dist/esm/dataset-ops/index.js +24 -0
  69. package/dist/esm/dataset-ops/index.js.map +1 -0
  70. package/dist/esm/dataset-ops/join.js +208 -0
  71. package/dist/esm/dataset-ops/join.js.map +1 -0
  72. package/dist/esm/dataset-ops/normalize-bigint-columns.js +51 -0
  73. package/dist/esm/dataset-ops/normalize-bigint-columns.js.map +1 -0
  74. package/dist/esm/dataset-ops/proto-dataset.js +62 -0
  75. package/dist/esm/dataset-ops/proto-dataset.js.map +1 -0
  76. package/dist/esm/dataset-ops/spatial-join.js +332 -0
  77. package/dist/esm/dataset-ops/spatial-join.js.map +1 -0
  78. package/dist/esm/dataset-ops/suitability.js +191 -0
  79. package/dist/esm/dataset-ops/suitability.js.map +1 -0
  80. package/dist/esm/dataset-ops/table-helpers.js +38 -0
  81. package/dist/esm/dataset-ops/table-helpers.js.map +1 -0
  82. package/dist/esm/dataset-ops/types.js +74 -0
  83. package/dist/esm/dataset-ops/types.js.map +1 -0
  84. package/dist/esm/dataset-utils.js +460 -0
  85. package/dist/esm/dataset-utils.js.map +1 -0
  86. package/dist/esm/gpu-filter-utils.js +357 -0
  87. package/dist/esm/gpu-filter-utils.js.map +1 -0
  88. package/dist/esm/index.js +18 -0
  89. package/dist/esm/index.js.map +1 -0
  90. package/dist/esm/kepler-table.js +1031 -0
  91. package/dist/esm/kepler-table.js.map +1 -0
  92. package/dist/esm/tileset/raster-tile-utils.js +69 -0
  93. package/dist/esm/tileset/raster-tile-utils.js.map +1 -0
  94. package/dist/esm/tileset/tileset-utils.js +79 -0
  95. package/dist/esm/tileset/tileset-utils.js.map +1 -0
  96. package/dist/esm/tileset/vector-tile-utils.js +747 -0
  97. package/dist/esm/tileset/vector-tile-utils.js.map +1 -0
  98. package/dist/esm/tileset/wms-utils.js +224 -0
  99. package/dist/esm/tileset/wms-utils.js.map +1 -0
  100. package/dist/esm/tileset/zarr-axis.js +167 -0
  101. package/dist/esm/tileset/zarr-axis.js.map +1 -0
  102. package/dist/esm/tileset/zarr-runtime.js +22 -0
  103. package/dist/esm/tileset/zarr-runtime.js.map +1 -0
  104. package/dist/esm/tileset/zarr-utils.js +2144 -0
  105. package/dist/esm/tileset/zarr-utils.js.map +1 -0
  106. package/dist/gpu-filter-utils.d.ts +4 -0
  107. package/dist/index.d.ts +7 -1
  108. package/dist/kepler-table.d.ts +56 -5
  109. package/dist/tileset/wms-utils.d.ts +40 -0
  110. package/dist/tileset/zarr-axis.d.ts +23 -0
  111. package/dist/tileset/zarr-runtime.d.ts +4 -0
  112. package/dist/tileset/zarr-utils.d.ts +200 -0
  113. package/package.json +36 -19
  114. package/dist/dataset-utils.js +0 -440
  115. package/dist/gpu-filter-utils.js +0 -254
  116. package/dist/index.js +0 -127
  117. package/dist/kepler-table.js +0 -648
  118. package/dist/tileset/raster-tile-utils.js +0 -76
  119. package/dist/tileset/tileset-utils.js +0 -73
  120. package/dist/tileset/vector-tile-utils.js +0 -741
  121. package/dist/tileset/vector-tile-utils.spec.js +0 -303
@@ -0,0 +1,2144 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
5
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
10
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
+ // SPDX-License-Identifier: MIT
13
+ // Copyright contributors to the kepler.gl project
14
+
15
+ import { loadZarrRuntime } from './zarr-runtime';
16
+
17
+ /** Dimension names treated as time when the store does not advertise CF units. */
18
+ var TIME_DIMENSION_NAMES = new Set(['time', 't', 'valid_time', 'datetime', 'date']);
19
+
20
+ /** CF calendars with a fixed-length day that map cleanly onto epoch milliseconds. */
21
+ var SUPPORTED_CALENDARS = new Set(['standard', 'gregorian', 'proleptic_gregorian', 'julian']);
22
+
23
+ /** Milliseconds per CF time unit. Months and years are omitted: they are not fixed length. */
24
+ var CF_UNIT_MS = {
25
+ microsecond: 0.001,
26
+ microseconds: 0.001,
27
+ microsec: 0.001,
28
+ us: 0.001,
29
+ millisecond: 1,
30
+ milliseconds: 1,
31
+ millisec: 1,
32
+ msec: 1,
33
+ ms: 1,
34
+ second: 1000,
35
+ seconds: 1000,
36
+ sec: 1000,
37
+ secs: 1000,
38
+ s: 1000,
39
+ minute: 60000,
40
+ minutes: 60000,
41
+ min: 60000,
42
+ mins: 60000,
43
+ hour: 3600000,
44
+ hours: 3600000,
45
+ hr: 3600000,
46
+ hrs: 3600000,
47
+ h: 3600000,
48
+ day: 86400000,
49
+ days: 86400000,
50
+ d: 86400000,
51
+ week: 604800000,
52
+ weeks: 604800000
53
+ };
54
+
55
+ /** Guard against walking an unbounded hierarchy when a store lists thousands of nodes. */
56
+ var MAX_VARIABLE_CANDIDATES = 200;
57
+
58
+ /**
59
+ * Axis labels `@developmentseed/geozarr` accepts for the spatial dimensions.
60
+ * Anything else cannot be rendered, so it is not worth deriving metadata for.
61
+ */
62
+ var Y_AXIS_LABELS = new Set(['y', 'latitude', 'lat']);
63
+ var X_AXIS_LABELS = new Set(['x', 'longitude', 'lon']);
64
+
65
+ /** Variable names conventionally holding the CF grid mapping when none is named. */
66
+ var GRID_MAPPING_FALLBACK_NAMES = ['spatial_ref', 'crs', 'transverse_mercator', 'projection'];
67
+
68
+ /** Coordinate arrays longer than this are not worth materializing for a time slider. */
69
+ var MAX_COORDINATE_LENGTH = 20000;
70
+
71
+ /**
72
+ * Node kinds by normalized path, built from the store's consolidated metadata.
73
+ *
74
+ * Zarr over plain HTTP has no directory listing, so without this every guess at
75
+ * a coordinate or grid-mapping path costs a round trip that usually 404s. When
76
+ * the store publishes a listing we consult it instead of probing. Null means
77
+ * the store has no consolidated metadata and probing is the only option.
78
+ */
79
+
80
+ function normalizePath(path) {
81
+ return path.replace(/^\/+/, '').replace(/\/+$/, '');
82
+ }
83
+ function buildStoreIndex(store) {
84
+ if (typeof store.contents !== 'function') {
85
+ return null;
86
+ }
87
+ var index = new Map();
88
+ var _iterator = _createForOfIteratorHelper(store.contents()),
89
+ _step;
90
+ try {
91
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
92
+ var entry = _step.value;
93
+ index.set(normalizePath(entry.path), entry.kind);
94
+ }
95
+ } catch (err) {
96
+ _iterator.e(err);
97
+ } finally {
98
+ _iterator.f();
99
+ }
100
+ return index;
101
+ }
102
+
103
+ /** True when the path is known to be absent, so opening it would only 404. */
104
+ function isKnownMissing(index, path, kind) {
105
+ if (!index) {
106
+ return false;
107
+ }
108
+ var found = index.get(normalizePath(path));
109
+ return kind ? found !== kind : found === undefined;
110
+ }
111
+
112
+ /**
113
+ * Parse a CF `units` string of the form `"<unit> since <timestamp>"`.
114
+ *
115
+ * Returns null for units that are not fixed-length (months, years) or for a
116
+ * timestamp the runtime cannot parse, so callers can fall back to treating the
117
+ * dimension as non-temporal instead of producing nonsense dates.
118
+ */
119
+ export function parseCfTimeUnits(units) {
120
+ if (typeof units !== 'string') {
121
+ return null;
122
+ }
123
+ var match = units.trim().match(/^([a-zA-Z]+)\s+since\s+(.+)$/);
124
+ if (!match) {
125
+ return null;
126
+ }
127
+ var stepMs = CF_UNIT_MS[match[1].toLowerCase()];
128
+ if (!stepMs) {
129
+ return null;
130
+ }
131
+ var originMs = parseCfTimeOrigin(match[2]);
132
+ if (originMs === null) {
133
+ return null;
134
+ }
135
+ return {
136
+ stepMs: stepMs,
137
+ originMs: originMs
138
+ };
139
+ }
140
+
141
+ /**
142
+ * CF reference dates come in many shapes: `1970-01-01`, `1970-1-1 0:0:0`,
143
+ * `2020-01-01T00:00:00Z`, sometimes with a trailing offset. Normalize to
144
+ * something `Date.parse` accepts and default to UTC when no zone is given.
145
+ */
146
+ function parseCfTimeOrigin(origin) {
147
+ var trimmed = origin.trim();
148
+ var match = trimmed.match(/^(\d{1,4})-(\d{1,2})-(\d{1,2})(?:[T ](\d{1,2}):(\d{1,2})(?::(\d{1,2}(?:\.\d+)?))?)?\s*(Z|UTC|GMT|[+-]\d{1,2}:?\d{0,2})?$/i);
149
+ if (!match) {
150
+ return null;
151
+ }
152
+ var _match = _slicedToArray(match, 8),
153
+ year = _match[1],
154
+ month = _match[2],
155
+ day = _match[3],
156
+ _match$ = _match[4],
157
+ hour = _match$ === void 0 ? '0' : _match$,
158
+ _match$2 = _match[5],
159
+ minute = _match$2 === void 0 ? '0' : _match$2,
160
+ _match$3 = _match[6],
161
+ second = _match$3 === void 0 ? '0' : _match$3,
162
+ zone = _match[7];
163
+ var seconds = Number.parseFloat(second);
164
+ var base = Date.UTC(Number(year), Number(month) - 1, Number(day), Number(hour), Number(minute), Math.trunc(seconds), Math.round(seconds % 1 * 1000));
165
+ if (!Number.isFinite(base)) {
166
+ return null;
167
+ }
168
+ // Date.UTC maps years 0-99 into the 1900s, which is wrong for CF epochs like `0001-01-01`.
169
+ var utc = Number(year) < 100 ? adjustLowYear(base, Number(year)) : base;
170
+ return utc - parseUtcOffsetMs(zone);
171
+ }
172
+ function adjustLowYear(base, year) {
173
+ var date = new Date(base);
174
+ date.setUTCFullYear(year);
175
+ return date.getTime();
176
+ }
177
+ function parseUtcOffsetMs(zone) {
178
+ if (!zone || /^(Z|UTC|GMT)$/i.test(zone)) {
179
+ return 0;
180
+ }
181
+ var match = zone.match(/^([+-])(\d{1,2}):?(\d{0,2})$/);
182
+ if (!match) {
183
+ return 0;
184
+ }
185
+ var sign = match[1] === '-' ? -1 : 1;
186
+ var hours = Number(match[2]);
187
+ var minutes = match[3] ? Number(match[3]) : 0;
188
+ return sign * (hours * 3600000 + minutes * 60000);
189
+ }
190
+
191
+ /**
192
+ * Decode CF-encoded time coordinates into epoch milliseconds.
193
+ *
194
+ * Returns null when the units are missing, not fixed-length, or the calendar is
195
+ * one of the synthetic CF calendars (`360_day`, `noleap`, ...) that cannot be
196
+ * represented on a real timeline.
197
+ */
198
+ export function decodeCfTime(values, units, calendar) {
199
+ if (!values || values.length === 0) {
200
+ return null;
201
+ }
202
+ if (typeof calendar === 'string' && !SUPPORTED_CALENDARS.has(calendar.toLowerCase())) {
203
+ return null;
204
+ }
205
+ var parsed = parseCfTimeUnits(units);
206
+ if (!parsed) {
207
+ return null;
208
+ }
209
+ var decoded = [];
210
+ for (var i = 0; i < values.length; i++) {
211
+ var raw = Number(values[i]);
212
+ if (!Number.isFinite(raw)) {
213
+ return null;
214
+ }
215
+ decoded.push(parsed.originMs + raw * parsed.stepMs);
216
+ }
217
+ return decoded;
218
+ }
219
+
220
+ /**
221
+ * Animation domain for a decoded time dimension, or null when the dimension
222
+ * carries fewer than two usable timestamps.
223
+ */
224
+ export function getZarrTimeDomain(dimension) {
225
+ var values = dimension === null || dimension === void 0 ? void 0 : dimension.values;
226
+ if (!values || values.length < 2) {
227
+ return null;
228
+ }
229
+ var timeSteps = _toConsumableArray(new Set(values)).filter(function (value) {
230
+ return typeof value === 'number' && Number.isFinite(value);
231
+ }).sort(function (a, b) {
232
+ return a - b;
233
+ });
234
+ if (timeSteps.length < 2) {
235
+ return null;
236
+ }
237
+ return {
238
+ domain: [timeSteps[0], timeSteps[timeSteps.length - 1]],
239
+ timeSteps: timeSteps
240
+ };
241
+ }
242
+
243
+ /** Find a variable by path, falling back to the dataset's active variable. */
244
+ export function getZarrVariable(metadata, variablePath) {
245
+ var _variables$find;
246
+ var variables = metadata === null || metadata === void 0 ? void 0 : metadata.variables;
247
+ if (!variables || variables.length === 0) {
248
+ return undefined;
249
+ }
250
+ var path = variablePath !== null && variablePath !== void 0 ? variablePath : metadata === null || metadata === void 0 ? void 0 : metadata.variable;
251
+ return (_variables$find = variables.find(function (variable) {
252
+ return variable.path === path;
253
+ })) !== null && _variables$find !== void 0 ? _variables$find : variables[0];
254
+ }
255
+
256
+ /**
257
+ * Switch the active variable of an already-fetched dataset metadata. Pure, so
258
+ * the layer can react to the variable dropdown without refetching the store.
259
+ */
260
+ export function selectZarrVariable(metadata, variablePath) {
261
+ var _variable$spatialMeta;
262
+ var variable = getZarrVariable(metadata, variablePath);
263
+ if (!variable) {
264
+ return metadata;
265
+ }
266
+ return _objectSpread(_objectSpread(_objectSpread({}, metadata), (_variable$spatialMeta = variable.spatialMetadata) !== null && _variable$spatialMeta !== void 0 ? _variable$spatialMeta : variable.path === metadata.variable ? {} : {
267
+ crs: undefined,
268
+ axes: [],
269
+ xAxisIndex: -1,
270
+ yAxisIndex: -1,
271
+ levels: [],
272
+ webMercatorPyramid: false
273
+ }), {}, {
274
+ variable: variable.path,
275
+ nonSpatialDims: variable.nonSpatialDims,
276
+ timeDimension: variable.timeDimension,
277
+ dataRange: variable.dataRange,
278
+ nodataValue: variable.nodataValue
279
+ });
280
+ }
281
+ function throwIfAborted(signal) {
282
+ if (signal !== null && signal !== void 0 && signal.aborted) {
283
+ var _signal$reason;
284
+ throw (_signal$reason = signal.reason) !== null && _signal$reason !== void 0 ? _signal$reason : new DOMException('The operation was aborted.', 'AbortError');
285
+ }
286
+ }
287
+ var storeCache = new Map();
288
+ function createMetadataFetch(signal, onProgress) {
289
+ var loadedBytes = 0;
290
+ var lastUpdate = 0;
291
+ var waitingForHeaders = 0;
292
+ var active = new Set();
293
+ var report = function report() {
294
+ var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
295
+ if (signal !== null && signal !== void 0 && signal.aborted || !force && Date.now() - lastUpdate < 200) return;
296
+ lastUpdate = Date.now();
297
+ var downloads = _toConsumableArray(active);
298
+ var totalBytes = !waitingForHeaders && downloads.length && downloads.every(function (download) {
299
+ return download.total !== undefined;
300
+ }) ? loadedBytes + downloads.reduce(function (sum, download) {
301
+ var _download$total;
302
+ return sum + ((_download$total = download.total) !== null && _download$total !== void 0 ? _download$total : 0) - download.loaded;
303
+ }, 0) : undefined;
304
+ onProgress({
305
+ phase: downloads.length ? 'downloading' : waitingForHeaders ? 'connecting' : 'processing',
306
+ loadedBytes: loadedBytes,
307
+ totalBytes: totalBytes
308
+ });
309
+ };
310
+ return /*#__PURE__*/function () {
311
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(request, init) {
312
+ var response, length, encoding, download, reader, abort, finish, body;
313
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
314
+ while (1) switch (_context2.prev = _context2.next) {
315
+ case 0:
316
+ throwIfAborted(signal);
317
+ waitingForHeaders++;
318
+ report(true);
319
+ _context2.prev = 3;
320
+ _context2.next = 6;
321
+ return fetch(request, _objectSpread(_objectSpread({}, init), {}, {
322
+ signal: signal
323
+ }));
324
+ case 6:
325
+ response = _context2.sent;
326
+ _context2.next = 14;
327
+ break;
328
+ case 9:
329
+ _context2.prev = 9;
330
+ _context2.t0 = _context2["catch"](3);
331
+ waitingForHeaders--;
332
+ report(true);
333
+ throw _context2.t0;
334
+ case 14:
335
+ waitingForHeaders--;
336
+ throwIfAborted(signal);
337
+ if (!(!response.ok || !response.body)) {
338
+ _context2.next = 19;
339
+ break;
340
+ }
341
+ report(true);
342
+ return _context2.abrupt("return", response);
343
+ case 19:
344
+ // Fetch streams contain decoded bytes. An encoded Content-Length cannot
345
+ // be compared to them, and some servers do not expose a length at all.
346
+ length = Number(response.headers.get('content-length'));
347
+ encoding = response.headers.get('content-encoding');
348
+ download = {
349
+ loaded: 0,
350
+ total: (!encoding || encoding === 'identity') && Number.isFinite(length) && length > 0 ? length : undefined
351
+ };
352
+ active.add(download);
353
+ report(true);
354
+ reader = response.body.getReader();
355
+ abort = function abort() {
356
+ void reader.cancel(signal === null || signal === void 0 ? void 0 : signal.reason)["catch"](function () {
357
+ return undefined;
358
+ });
359
+ };
360
+ signal === null || signal === void 0 || signal.addEventListener('abort', abort, {
361
+ once: true
362
+ });
363
+ finish = function finish() {
364
+ active["delete"](download);
365
+ signal === null || signal === void 0 || signal.removeEventListener('abort', abort);
366
+ };
367
+ body = new ReadableStream({
368
+ pull: function pull(controller) {
369
+ return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
370
+ var _yield$reader$read, done, value;
371
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
372
+ while (1) switch (_context.prev = _context.next) {
373
+ case 0:
374
+ _context.prev = 0;
375
+ throwIfAborted(signal);
376
+ _context.next = 4;
377
+ return reader.read();
378
+ case 4:
379
+ _yield$reader$read = _context.sent;
380
+ done = _yield$reader$read.done;
381
+ value = _yield$reader$read.value;
382
+ throwIfAborted(signal);
383
+ if (!done) {
384
+ _context.next = 14;
385
+ break;
386
+ }
387
+ finish();
388
+ reader.releaseLock();
389
+ report(true);
390
+ controller.close();
391
+ return _context.abrupt("return");
392
+ case 14:
393
+ download.loaded += value.byteLength;
394
+ loadedBytes += value.byteLength;
395
+ // A proxy may hide Content-Encoding while exposing the encoded size.
396
+ if (download.total !== undefined && download.loaded > download.total) {
397
+ download.total = undefined;
398
+ }
399
+ report();
400
+ controller.enqueue(value);
401
+ _context.next = 27;
402
+ break;
403
+ case 21:
404
+ _context.prev = 21;
405
+ _context.t0 = _context["catch"](0);
406
+ finish();
407
+ _context.next = 26;
408
+ return reader.cancel(_context.t0)["catch"](function () {
409
+ return undefined;
410
+ });
411
+ case 26:
412
+ controller.error(_context.t0);
413
+ case 27:
414
+ case "end":
415
+ return _context.stop();
416
+ }
417
+ }, _callee, null, [[0, 21]]);
418
+ }))();
419
+ },
420
+ cancel: function cancel(reason) {
421
+ finish();
422
+ return reader.cancel(reason);
423
+ }
424
+ });
425
+ return _context2.abrupt("return", new Response(body, {
426
+ status: response.status,
427
+ statusText: response.statusText,
428
+ headers: response.headers
429
+ }));
430
+ case 30:
431
+ case "end":
432
+ return _context2.stop();
433
+ }
434
+ }, _callee2, null, [[3, 9]]);
435
+ }));
436
+ return function (_x, _x2) {
437
+ return _ref.apply(this, arguments);
438
+ };
439
+ }();
440
+ }
441
+ function withDetectedZarrMetadata(_x3) {
442
+ return _withDetectedZarrMetadata.apply(this, arguments);
443
+ }
444
+ /**
445
+ * Open a Zarr store, preferring consolidated metadata so variable discovery
446
+ * costs one request instead of one per node. Memoized per URL because the
447
+ * dataset refresh and the layer open the same store. Cancellable metadata
448
+ * previews use their own store so aborting a preview cannot affect a layer.
449
+ */
450
+ function _withDetectedZarrMetadata() {
451
+ _withDetectedZarrMetadata = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(store) {
452
+ var _yield$loadZarrRuntim2, zarr, _iterator9, _step9, format, consolidated;
453
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
454
+ while (1) switch (_context4.prev = _context4.next) {
455
+ case 0:
456
+ _context4.next = 2;
457
+ return loadZarrRuntime();
458
+ case 2:
459
+ _yield$loadZarrRuntim2 = _context4.sent;
460
+ zarr = _yield$loadZarrRuntim2.zarr;
461
+ _iterator9 = _createForOfIteratorHelper(['v2', 'v3']);
462
+ _context4.prev = 5;
463
+ _iterator9.s();
464
+ case 7:
465
+ if ((_step9 = _iterator9.n()).done) {
466
+ _context4.next = 20;
467
+ break;
468
+ }
469
+ format = _step9.value;
470
+ _context4.next = 11;
471
+ return zarr.withMaybeConsolidatedMetadata(store, {
472
+ format: format
473
+ });
474
+ case 11:
475
+ consolidated = _context4.sent;
476
+ if (!(consolidated === store)) {
477
+ _context4.next = 14;
478
+ break;
479
+ }
480
+ return _context4.abrupt("continue", 18);
481
+ case 14:
482
+ if (!(format === 'v3')) {
483
+ _context4.next = 17;
484
+ break;
485
+ }
486
+ _context4.next = 17;
487
+ return zarr.open.v3(consolidated, {
488
+ kind: 'group'
489
+ });
490
+ case 17:
491
+ return _context4.abrupt("return", consolidated);
492
+ case 18:
493
+ _context4.next = 7;
494
+ break;
495
+ case 20:
496
+ _context4.next = 25;
497
+ break;
498
+ case 22:
499
+ _context4.prev = 22;
500
+ _context4.t0 = _context4["catch"](5);
501
+ _iterator9.e(_context4.t0);
502
+ case 25:
503
+ _context4.prev = 25;
504
+ _iterator9.f();
505
+ return _context4.finish(25);
506
+ case 28:
507
+ return _context4.abrupt("return", store);
508
+ case 29:
509
+ case "end":
510
+ return _context4.stop();
511
+ }
512
+ }, _callee4, null, [[5, 22, 25, 28]]);
513
+ }));
514
+ return _withDetectedZarrMetadata.apply(this, arguments);
515
+ }
516
+ export function openZarrStore(url) {
517
+ var existing = storeCache.get(url);
518
+ if (existing) {
519
+ return existing;
520
+ }
521
+ var opening = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
522
+ var _yield$loadZarrRuntim, zarr, store;
523
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
524
+ while (1) switch (_context3.prev = _context3.next) {
525
+ case 0:
526
+ _context3.next = 2;
527
+ return loadZarrRuntime();
528
+ case 2:
529
+ _yield$loadZarrRuntim = _context3.sent;
530
+ zarr = _yield$loadZarrRuntim.zarr;
531
+ store = new zarr.FetchStore(url);
532
+ return _context3.abrupt("return", withDetectedZarrMetadata(store));
533
+ case 6:
534
+ case "end":
535
+ return _context3.stop();
536
+ }
537
+ }, _callee3);
538
+ }))()["catch"](function (error) {
539
+ storeCache["delete"](url);
540
+ throw error;
541
+ });
542
+ storeCache.set(url, opening);
543
+ return opening;
544
+ }
545
+
546
+ /**
547
+ * Open the node that backs a variable: a multiscale group, or the array itself
548
+ * for a single-resolution dataset. This is what `ZarrLayer` takes as its `node`
549
+ * prop, already resolved so the layer does not need a `variable` path.
550
+ */
551
+ export function openZarrNode(_x4, _x5) {
552
+ return _openZarrNode.apply(this, arguments);
553
+ }
554
+
555
+ /** Drop a cached store so a refresh re-reads the consolidated metadata. */
556
+ function _openZarrNode() {
557
+ _openZarrNode = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(url, variablePath) {
558
+ var store, _yield$loadZarrRuntim3, zarr;
559
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
560
+ while (1) switch (_context5.prev = _context5.next) {
561
+ case 0:
562
+ _context5.next = 2;
563
+ return openZarrStore(url);
564
+ case 2:
565
+ store = _context5.sent;
566
+ _context5.next = 5;
567
+ return loadZarrRuntime();
568
+ case 5:
569
+ _yield$loadZarrRuntim3 = _context5.sent;
570
+ zarr = _yield$loadZarrRuntim3.zarr;
571
+ return _context5.abrupt("return", zarr.open(new zarr.Location(store, toAbsolutePath(variablePath !== null && variablePath !== void 0 ? variablePath : ''))));
572
+ case 8:
573
+ case "end":
574
+ return _context5.stop();
575
+ }
576
+ }, _callee5);
577
+ }));
578
+ return _openZarrNode.apply(this, arguments);
579
+ }
580
+ export function clearZarrStoreCache(url) {
581
+ if (url === undefined) {
582
+ storeCache.clear();
583
+ } else {
584
+ storeCache["delete"](url);
585
+ }
586
+ }
587
+ function toAbsolutePath(path) {
588
+ var trimmed = path.replace(/^\/+/, '').replace(/\/+$/, '');
589
+ return trimmed ? "/".concat(trimmed) : '/';
590
+ }
591
+ function getAttrs(node) {
592
+ var _node$attrs;
593
+ return (_node$attrs = node.attrs) !== null && _node$attrs !== void 0 ? _node$attrs : {};
594
+ }
595
+ function readNumber(attrs, keys) {
596
+ var _iterator2 = _createForOfIteratorHelper(keys),
597
+ _step2;
598
+ try {
599
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
600
+ var key = _step2.value;
601
+ var value = attrs[key];
602
+ if (typeof value === 'number' && Number.isFinite(value)) {
603
+ return value;
604
+ }
605
+ if (typeof value === 'bigint') {
606
+ return Number(value);
607
+ }
608
+ }
609
+ } catch (err) {
610
+ _iterator2.e(err);
611
+ } finally {
612
+ _iterator2.f();
613
+ }
614
+ return undefined;
615
+ }
616
+ function readString(attrs, keys) {
617
+ var _iterator3 = _createForOfIteratorHelper(keys),
618
+ _step3;
619
+ try {
620
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
621
+ var key = _step3.value;
622
+ var value = attrs[key];
623
+ if (typeof value === 'string' && value) {
624
+ return value;
625
+ }
626
+ }
627
+ } catch (err) {
628
+ _iterator3.e(err);
629
+ } finally {
630
+ _iterator3.f();
631
+ }
632
+ return undefined;
633
+ }
634
+ function readDataRange(attrs) {
635
+ var _attrs$actual_range;
636
+ var range = (_attrs$actual_range = attrs.actual_range) !== null && _attrs$actual_range !== void 0 ? _attrs$actual_range : attrs.valid_range;
637
+ if (Array.isArray(range) && range.length === 2) {
638
+ var _range$map = range.map(Number),
639
+ _range$map2 = _slicedToArray(_range$map, 2),
640
+ _min = _range$map2[0],
641
+ _max = _range$map2[1];
642
+ if (Number.isFinite(_min) && Number.isFinite(_max) && _min < _max) {
643
+ return [_min, _max];
644
+ }
645
+ }
646
+ var min = readNumber(attrs, ['valid_min', 'vmin', 'min', 'minimum']);
647
+ var max = readNumber(attrs, ['valid_max', 'vmax', 'max', 'maximum']);
648
+ if (min !== undefined && max !== undefined && min < max) {
649
+ return [min, max];
650
+ }
651
+ return undefined;
652
+ }
653
+
654
+ /**
655
+ * Dimension names for a zarr array. Zarr v3 stores them in `dimension_names`;
656
+ * xarray-written v2 stores put them in the `_ARRAY_DIMENSIONS` attribute.
657
+ */
658
+ export function getZarrDimensionNames(arr) {
659
+ var fromMetadata = arr.dimensionNames;
660
+ if (fromMetadata && fromMetadata.length === arr.shape.length) {
661
+ var named = fromMetadata.filter(function (name) {
662
+ return Boolean(name);
663
+ });
664
+ if (named.length === fromMetadata.length) {
665
+ return named;
666
+ }
667
+ }
668
+ var fromAttrs = getAttrs(arr)._ARRAY_DIMENSIONS;
669
+ if (Array.isArray(fromAttrs) && fromAttrs.length === arr.shape.length) {
670
+ var _named = fromAttrs.filter(function (name) {
671
+ return typeof name === 'string' && !!name;
672
+ });
673
+ if (_named.length === fromAttrs.length) {
674
+ return _named;
675
+ }
676
+ }
677
+ return null;
678
+ }
679
+
680
+ /**
681
+ * Candidate locations for a coordinate array. Coordinates usually sit next to
682
+ * the variable, but xarray and the GeoZarr examples also hoist shared
683
+ * coordinates to the store root.
684
+ */
685
+ function coordinateCandidates(variablePath, name) {
686
+ var parent = variablePath.split('/').slice(0, -1).join('/');
687
+ return [toAbsolutePath("".concat(variablePath, "/").concat(name)), toAbsolutePath("".concat(parent, "/").concat(name)), toAbsolutePath(name)];
688
+ }
689
+
690
+ /**
691
+ * Resolve a coordinate array to a concrete path using the store listing, with
692
+ * no network access. Returns null when the store has no listing (the caller
693
+ * must probe) or when no candidate exists.
694
+ */
695
+ export function resolveCoordinatePath(index, variablePath, name) {
696
+ if (!index) {
697
+ return null;
698
+ }
699
+ var _iterator4 = _createForOfIteratorHelper(new Set(coordinateCandidates(variablePath, name))),
700
+ _step4;
701
+ try {
702
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
703
+ var path = _step4.value;
704
+ if (index.get(normalizePath(path)) === 'array') {
705
+ return path;
706
+ }
707
+ }
708
+ } catch (err) {
709
+ _iterator4.e(err);
710
+ } finally {
711
+ _iterator4.f();
712
+ }
713
+ return null;
714
+ }
715
+
716
+ /** Open a 1-D coordinate array for `name`, or null when there is not one. */
717
+ function openCoordinateArray(_x6, _x7, _x8, _x9, _x0) {
718
+ return _openCoordinateArray.apply(this, arguments);
719
+ }
720
+ /**
721
+ * GDAL writes its six-element `GeoTransform` as a space-separated string in
722
+ * `[c, a, b, f, d, e]` order. `@developmentseed/affine` wants `[a, b, c, d, e, f]`.
723
+ */
724
+ function _openCoordinateArray() {
725
+ _openCoordinateArray = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(store, index, variablePath, name, size) {
726
+ var _yield$loadZarrRuntim4, zarr, _iterator0, _step0, path, arr;
727
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
728
+ while (1) switch (_context6.prev = _context6.next) {
729
+ case 0:
730
+ _context6.next = 2;
731
+ return loadZarrRuntime();
732
+ case 2:
733
+ _yield$loadZarrRuntim4 = _context6.sent;
734
+ zarr = _yield$loadZarrRuntim4.zarr;
735
+ _iterator0 = _createForOfIteratorHelper(new Set(coordinateCandidates(variablePath, name)));
736
+ _context6.prev = 5;
737
+ _iterator0.s();
738
+ case 7:
739
+ if ((_step0 = _iterator0.n()).done) {
740
+ _context6.next = 25;
741
+ break;
742
+ }
743
+ path = _step0.value;
744
+ if (!isKnownMissing(index, path, 'array')) {
745
+ _context6.next = 11;
746
+ break;
747
+ }
748
+ return _context6.abrupt("continue", 23);
749
+ case 11:
750
+ _context6.prev = 11;
751
+ _context6.next = 14;
752
+ return zarr.open(new zarr.Location(store, path), {
753
+ kind: 'array'
754
+ });
755
+ case 14:
756
+ arr = _context6.sent;
757
+ if (!(arr.shape.length !== 1 || size !== undefined && arr.shape[0] !== size)) {
758
+ _context6.next = 17;
759
+ break;
760
+ }
761
+ return _context6.abrupt("continue", 23);
762
+ case 17:
763
+ return _context6.abrupt("return", arr);
764
+ case 20:
765
+ _context6.prev = 20;
766
+ _context6.t0 = _context6["catch"](11);
767
+ throwIfAborted(store.signal);
768
+ // Not every dimension has a coordinate array; try the next candidate.
769
+ case 23:
770
+ _context6.next = 7;
771
+ break;
772
+ case 25:
773
+ _context6.next = 30;
774
+ break;
775
+ case 27:
776
+ _context6.prev = 27;
777
+ _context6.t1 = _context6["catch"](5);
778
+ _iterator0.e(_context6.t1);
779
+ case 30:
780
+ _context6.prev = 30;
781
+ _iterator0.f();
782
+ return _context6.finish(30);
783
+ case 33:
784
+ return _context6.abrupt("return", null);
785
+ case 34:
786
+ case "end":
787
+ return _context6.stop();
788
+ }
789
+ }, _callee6, null, [[5, 27, 30, 33], [11, 20]]);
790
+ }));
791
+ return _openCoordinateArray.apply(this, arguments);
792
+ }
793
+ export function parseGdalGeoTransform(value) {
794
+ var parts = typeof value === 'string' ? value.trim().split(/\s+/).map(Number) : Array.isArray(value) ? value.map(Number) : null;
795
+ if (!parts || parts.length !== 6 || !parts.every(Number.isFinite)) {
796
+ return null;
797
+ }
798
+ var _parts = _slicedToArray(parts, 6),
799
+ c = _parts[0],
800
+ a = _parts[1],
801
+ b = _parts[2],
802
+ f = _parts[3],
803
+ d = _parts[4],
804
+ e = _parts[5];
805
+ return [a, b, c, d, e, f];
806
+ }
807
+ /**
808
+ * Read the CF grid-mapping variable, which is where GDAL-written stores keep
809
+ * the CRS (`crs_wkt` / `spatial_ref`) and the affine (`GeoTransform`).
810
+ */
811
+ function readGridMapping(_x1, _x10, _x11, _x12) {
812
+ return _readGridMapping.apply(this, arguments);
813
+ }
814
+ /**
815
+ * Derive the affine from 1-D coordinate arrays, which is how most CF stores
816
+ * describe a regular grid. Coordinate values are cell centers, so the origin is
817
+ * stepped back by half a cell to reach the outer edge the affine expects.
818
+ *
819
+ * Returns null for irregular spacing, which an affine cannot represent.
820
+ */
821
+ function _readGridMapping() {
822
+ _readGridMapping = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(store, index, variablePath, arrayAttrs) {
823
+ var _yield$loadZarrRuntim5, zarr, named, names, parent, _iterator1, _step1, name, _iterator10, _step10, _attrs$GeoTransform, base, path, attrs, node, wkt2, epsg, crs, transform;
824
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
825
+ while (1) switch (_context7.prev = _context7.next) {
826
+ case 0:
827
+ _context7.next = 2;
828
+ return loadZarrRuntime();
829
+ case 2:
830
+ _yield$loadZarrRuntim5 = _context7.sent;
831
+ zarr = _yield$loadZarrRuntim5.zarr;
832
+ named = readString(arrayAttrs, ['grid_mapping']);
833
+ names = named ? [named].concat(GRID_MAPPING_FALLBACK_NAMES) : GRID_MAPPING_FALLBACK_NAMES;
834
+ parent = variablePath.split('/').slice(0, -1).join('/');
835
+ _iterator1 = _createForOfIteratorHelper(new Set(names));
836
+ _context7.prev = 8;
837
+ _iterator1.s();
838
+ case 10:
839
+ if ((_step1 = _iterator1.n()).done) {
840
+ _context7.next = 50;
841
+ break;
842
+ }
843
+ name = _step1.value;
844
+ _iterator10 = _createForOfIteratorHelper(new Set([variablePath, parent, '']));
845
+ _context7.prev = 13;
846
+ _iterator10.s();
847
+ case 15:
848
+ if ((_step10 = _iterator10.n()).done) {
849
+ _context7.next = 40;
850
+ break;
851
+ }
852
+ base = _step10.value;
853
+ path = toAbsolutePath("".concat(base, "/").concat(name));
854
+ if (!isKnownMissing(index, path)) {
855
+ _context7.next = 20;
856
+ break;
857
+ }
858
+ return _context7.abrupt("continue", 38);
859
+ case 20:
860
+ attrs = void 0;
861
+ _context7.prev = 21;
862
+ _context7.next = 24;
863
+ return zarr.open(new zarr.Location(store, path));
864
+ case 24:
865
+ node = _context7.sent;
866
+ attrs = getAttrs(node);
867
+ _context7.next = 32;
868
+ break;
869
+ case 28:
870
+ _context7.prev = 28;
871
+ _context7.t0 = _context7["catch"](21);
872
+ throwIfAborted(store.signal);
873
+ return _context7.abrupt("continue", 38);
874
+ case 32:
875
+ wkt2 = readString(attrs, ['crs_wkt', 'spatial_ref', 'esri_pe_string']);
876
+ epsg = readNumber(attrs, ['epsg_code', 'EPSG_code']);
877
+ crs = epsg ? {
878
+ 'proj:code': "EPSG:".concat(epsg)
879
+ } : wkt2 ? {
880
+ 'proj:wkt2': wkt2
881
+ } : undefined;
882
+ transform = parseGdalGeoTransform((_attrs$GeoTransform = attrs.GeoTransform) !== null && _attrs$GeoTransform !== void 0 ? _attrs$GeoTransform : attrs.geotransform);
883
+ if (!(crs || transform)) {
884
+ _context7.next = 38;
885
+ break;
886
+ }
887
+ return _context7.abrupt("return", {
888
+ crs: crs,
889
+ transform: transform !== null && transform !== void 0 ? transform : undefined
890
+ });
891
+ case 38:
892
+ _context7.next = 15;
893
+ break;
894
+ case 40:
895
+ _context7.next = 45;
896
+ break;
897
+ case 42:
898
+ _context7.prev = 42;
899
+ _context7.t1 = _context7["catch"](13);
900
+ _iterator10.e(_context7.t1);
901
+ case 45:
902
+ _context7.prev = 45;
903
+ _iterator10.f();
904
+ return _context7.finish(45);
905
+ case 48:
906
+ _context7.next = 10;
907
+ break;
908
+ case 50:
909
+ _context7.next = 55;
910
+ break;
911
+ case 52:
912
+ _context7.prev = 52;
913
+ _context7.t2 = _context7["catch"](8);
914
+ _iterator1.e(_context7.t2);
915
+ case 55:
916
+ _context7.prev = 55;
917
+ _iterator1.f();
918
+ return _context7.finish(55);
919
+ case 58:
920
+ return _context7.abrupt("return", null);
921
+ case 59:
922
+ case "end":
923
+ return _context7.stop();
924
+ }
925
+ }, _callee7, null, [[8, 52, 55, 58], [13, 42, 45, 48], [21, 28]]);
926
+ }));
927
+ return _readGridMapping.apply(this, arguments);
928
+ }
929
+ function deriveAffineFromCoordinates(_x13, _x14, _x15, _x16, _x17, _x18, _x19, _x20) {
930
+ return _deriveAffineFromCoordinates.apply(this, arguments);
931
+ }
932
+ function _deriveAffineFromCoordinates() {
933
+ _deriveAffineFromCoordinates = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(store, index, variablePath, yName, xName, height, width, cache) {
934
+ var _yield$Promise$all, _yield$Promise$all2, yArr, xArr, _yield$Promise$all3, _yield$Promise$all4, yStats, xStats;
935
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
936
+ while (1) switch (_context8.prev = _context8.next) {
937
+ case 0:
938
+ _context8.next = 2;
939
+ return Promise.all([openCoordinateArray(store, index, variablePath, yName, height), openCoordinateArray(store, index, variablePath, xName, width)]);
940
+ case 2:
941
+ _yield$Promise$all = _context8.sent;
942
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
943
+ yArr = _yield$Promise$all2[0];
944
+ xArr = _yield$Promise$all2[1];
945
+ if (!(!yArr || !xArr)) {
946
+ _context8.next = 8;
947
+ break;
948
+ }
949
+ return _context8.abrupt("return", null);
950
+ case 8:
951
+ _context8.next = 10;
952
+ return Promise.all([readAxisSpacing(yArr, cache), readAxisSpacing(xArr, cache)]);
953
+ case 10:
954
+ _yield$Promise$all3 = _context8.sent;
955
+ _yield$Promise$all4 = _slicedToArray(_yield$Promise$all3, 2);
956
+ yStats = _yield$Promise$all4[0];
957
+ xStats = _yield$Promise$all4[1];
958
+ if (!(!yStats || !xStats)) {
959
+ _context8.next = 16;
960
+ break;
961
+ }
962
+ return _context8.abrupt("return", null);
963
+ case 16:
964
+ return _context8.abrupt("return", affineFromCellCenters(xStats, yStats));
965
+ case 17:
966
+ case "end":
967
+ return _context8.stop();
968
+ }
969
+ }, _callee8);
970
+ }));
971
+ return _deriveAffineFromCoordinates.apply(this, arguments);
972
+ }
973
+ /**
974
+ * Build an affine from the spacing of two cell-center axes. The affine maps the
975
+ * outer edge of the first cell, so each origin is stepped back by half a cell.
976
+ */
977
+ export function affineFromCellCenters(x, y) {
978
+ return [x.step, 0, x.first - x.step / 2, 0, y.step, y.first - y.step / 2];
979
+ }
980
+
981
+ /**
982
+ * Derive a constant step from a cell-center coordinate array, rejecting any grid
983
+ * the affine would misrepresent. Every coordinate is checked rather than just
984
+ * the last, because an axis that drifts in the middle yet lands on the expected
985
+ * endpoint would otherwise yield a silently wrong georeference.
986
+ */
987
+ export function axisSpacingFromValues(raw) {
988
+ if (raw.length < 2) {
989
+ return null;
990
+ }
991
+ var first = Number(raw[0]);
992
+ var last = Number(raw[raw.length - 1]);
993
+ // Average over the whole axis so rounding the first two float32 coordinates
994
+ // does not accumulate into a large positional error at the far end.
995
+ var step = (last - first) / (raw.length - 1);
996
+ if (!Number.isFinite(first) || !Number.isFinite(step) || step === 0) {
997
+ return null;
998
+ }
999
+ // Allow coordinate rounding and affine arithmetic, not a fraction of a cell.
1000
+ var precision = raw instanceof Float32Array ? Math.pow(2, -23) : Number.EPSILON;
1001
+ var tolerance = Math.max(Math.abs(first), Math.abs(last), Math.abs(step)) * precision * 2;
1002
+ var previous = first;
1003
+ for (var i = 1; i < raw.length; i++) {
1004
+ var value = Number(raw[i]);
1005
+ if (!Number.isFinite(value) || (step > 0 ? value <= previous : value >= previous) || Math.abs(value - (first + step * i)) > tolerance) {
1006
+ return null;
1007
+ }
1008
+ previous = value;
1009
+ }
1010
+ return {
1011
+ first: first,
1012
+ step: step
1013
+ };
1014
+ }
1015
+ function readAxisSpacing(_x21, _x22) {
1016
+ return _readAxisSpacing.apply(this, arguments);
1017
+ }
1018
+ /**
1019
+ * Synthesize GeoZarr-convention attributes for a store that does not declare
1020
+ * them, using the CF/GDAL metadata that real-world Zarr publishers actually
1021
+ * write: a grid-mapping variable and/or 1-D coordinate arrays.
1022
+ *
1023
+ * `ZarrLayer` re-parses whatever is passed as its `metadata` prop, so the
1024
+ * result is attributes rather than a parsed descriptor.
1025
+ */
1026
+ function _readAxisSpacing() {
1027
+ _readAxisSpacing = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0(arr, cache) {
1028
+ var pending;
1029
+ return _regeneratorRuntime.wrap(function _callee0$(_context0) {
1030
+ while (1) switch (_context0.prev = _context0.next) {
1031
+ case 0:
1032
+ if (!(arr.shape[0] < 2 || arr.shape[0] > MAX_COORDINATE_LENGTH)) {
1033
+ _context0.next = 2;
1034
+ break;
1035
+ }
1036
+ return _context0.abrupt("return", null);
1037
+ case 2:
1038
+ pending = cache.spatialAxes.get(arr.path);
1039
+ if (!pending) {
1040
+ pending = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
1041
+ var _yield$loadZarrRuntim6, zarr, chunk;
1042
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
1043
+ while (1) switch (_context9.prev = _context9.next) {
1044
+ case 0:
1045
+ _context9.next = 2;
1046
+ return loadZarrRuntime();
1047
+ case 2:
1048
+ _yield$loadZarrRuntim6 = _context9.sent;
1049
+ zarr = _yield$loadZarrRuntim6.zarr;
1050
+ _context9.next = 6;
1051
+ return zarr.get(arr, null);
1052
+ case 6:
1053
+ chunk = _context9.sent;
1054
+ return _context9.abrupt("return", axisSpacingFromValues(chunk.data));
1055
+ case 8:
1056
+ case "end":
1057
+ return _context9.stop();
1058
+ }
1059
+ }, _callee9);
1060
+ }))();
1061
+ cache.spatialAxes.set(arr.path, pending);
1062
+ }
1063
+ return _context0.abrupt("return", pending);
1064
+ case 5:
1065
+ case "end":
1066
+ return _context0.stop();
1067
+ }
1068
+ }, _callee0);
1069
+ }));
1070
+ return _readAxisSpacing.apply(this, arguments);
1071
+ }
1072
+ function deriveGeoZarrAttrs(_x23, _x24, _x25, _x26, _x27, _x28) {
1073
+ return _deriveGeoZarrAttrs.apply(this, arguments);
1074
+ }
1075
+ /**
1076
+ * Level paths of an OME-NGFF style `multiscales` attribute, finest first.
1077
+ *
1078
+ * `ndpyramid` and `xarray-multiscale` write a pyramid this way: a list of
1079
+ * multiscale descriptors, each holding a `datasets` array of child paths. The
1080
+ * zarr-conventions form the GeoZarr parser reads is instead an object with a
1081
+ * `layout`, so the two have to be told apart and the OME form rewritten.
1082
+ */
1083
+ function _deriveGeoZarrAttrs() {
1084
+ _deriveGeoZarrAttrs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1(store, index, variablePath, arr, dimensionNames, cache) {
1085
+ var _gridMapping$transfor, _gridMapping$crs;
1086
+ var yName, xName, height, width, gridMapping, transform, isGeographic, crs;
1087
+ return _regeneratorRuntime.wrap(function _callee1$(_context1) {
1088
+ while (1) switch (_context1.prev = _context1.next) {
1089
+ case 0:
1090
+ if (!(dimensionNames.length < 2)) {
1091
+ _context1.next = 2;
1092
+ break;
1093
+ }
1094
+ return _context1.abrupt("return", null);
1095
+ case 2:
1096
+ yName = dimensionNames[dimensionNames.length - 2];
1097
+ xName = dimensionNames[dimensionNames.length - 1]; // The renderer requires the spatial dims last, in [y, x] order, and labeled
1098
+ // with names the GeoZarr parser recognizes.
1099
+ if (!(!Y_AXIS_LABELS.has(yName.toLowerCase()) || !X_AXIS_LABELS.has(xName.toLowerCase()))) {
1100
+ _context1.next = 6;
1101
+ break;
1102
+ }
1103
+ return _context1.abrupt("return", null);
1104
+ case 6:
1105
+ height = arr.shape[arr.shape.length - 2];
1106
+ width = arr.shape[arr.shape.length - 1];
1107
+ _context1.next = 10;
1108
+ return readGridMapping(store, index, variablePath, getAttrs(arr));
1109
+ case 10:
1110
+ gridMapping = _context1.sent;
1111
+ if (!((_gridMapping$transfor = gridMapping === null || gridMapping === void 0 ? void 0 : gridMapping.transform) !== null && _gridMapping$transfor !== void 0)) {
1112
+ _context1.next = 15;
1113
+ break;
1114
+ }
1115
+ _context1.t0 = _gridMapping$transfor;
1116
+ _context1.next = 18;
1117
+ break;
1118
+ case 15:
1119
+ _context1.next = 17;
1120
+ return deriveAffineFromCoordinates(store, index, variablePath, yName, xName, height, width, cache);
1121
+ case 17:
1122
+ _context1.t0 = _context1.sent;
1123
+ case 18:
1124
+ transform = _context1.t0;
1125
+ if (transform) {
1126
+ _context1.next = 21;
1127
+ break;
1128
+ }
1129
+ return _context1.abrupt("return", null);
1130
+ case 21:
1131
+ // Lat/lon axis names imply geographic coordinates when nothing declares a CRS.
1132
+ isGeographic = yName.toLowerCase() !== 'y' && xName.toLowerCase() !== 'x';
1133
+ crs = (_gridMapping$crs = gridMapping === null || gridMapping === void 0 ? void 0 : gridMapping.crs) !== null && _gridMapping$crs !== void 0 ? _gridMapping$crs : isGeographic ? {
1134
+ 'proj:code': 'EPSG:4326'
1135
+ } : null;
1136
+ if (crs) {
1137
+ _context1.next = 25;
1138
+ break;
1139
+ }
1140
+ return _context1.abrupt("return", null);
1141
+ case 25:
1142
+ return _context1.abrupt("return", _objectSpread({
1143
+ 'spatial:dimensions': [yName, xName],
1144
+ 'spatial:transform': transform,
1145
+ 'spatial:shape': [height, width]
1146
+ }, crs));
1147
+ case 26:
1148
+ case "end":
1149
+ return _context1.stop();
1150
+ }
1151
+ }, _callee1);
1152
+ }));
1153
+ return _deriveGeoZarrAttrs.apply(this, arguments);
1154
+ }
1155
+ export function parseOmeMultiscaleLevels(attrs) {
1156
+ var raw = attrs.multiscales;
1157
+ var entry = Array.isArray(raw) ? raw[0] : raw;
1158
+ if (!entry || _typeof(entry) !== 'object') {
1159
+ return null;
1160
+ }
1161
+ var datasets = entry.datasets;
1162
+ if (!Array.isArray(datasets) || datasets.length === 0) {
1163
+ return null;
1164
+ }
1165
+ var paths = [];
1166
+ var _iterator5 = _createForOfIteratorHelper(datasets),
1167
+ _step5;
1168
+ try {
1169
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1170
+ var dataset = _step5.value;
1171
+ var path = dataset === null || dataset === void 0 ? void 0 : dataset.path;
1172
+ if (typeof path !== 'string' || !normalizePath(path)) {
1173
+ return null;
1174
+ }
1175
+ paths.push(normalizePath(path));
1176
+ }
1177
+ } catch (err) {
1178
+ _iterator5.e(err);
1179
+ } finally {
1180
+ _iterator5.f();
1181
+ }
1182
+ return paths;
1183
+ }
1184
+
1185
+ /**
1186
+ * Whether `multiscales` describes a web-mercator tile pyramid.
1187
+ *
1188
+ * This is what `ndpyramid`'s `pyramid_reproject` writes and what CarbonPlan
1189
+ * publishes: every level is reprojected to EPSG:3857 and covers the whole world
1190
+ * in `pixels_per_tile * 2 ** level` pixels. Knowing that lets the renderer tie
1191
+ * the level it draws to the map zoom, which is how such a pyramid is meant to
1192
+ * be read.
1193
+ */
1194
+ export function isWebMercatorPyramid(attrs) {
1195
+ var raw = attrs === null || attrs === void 0 ? void 0 : attrs.multiscales;
1196
+ var entry = Array.isArray(raw) ? raw[0] : raw;
1197
+ var datasets = entry === null || entry === void 0 ? void 0 : entry.datasets;
1198
+ if (!Array.isArray(datasets) || datasets.length < 2) {
1199
+ return false;
1200
+ }
1201
+ return datasets.every(function (dataset) {
1202
+ var _ref3 = dataset !== null && dataset !== void 0 ? dataset : {},
1203
+ crs = _ref3.crs,
1204
+ pixelsPerTile = _ref3.pixels_per_tile;
1205
+ return crs === 'EPSG:3857' && typeof pixelsPerTile === 'number' && pixelsPerTile > 0;
1206
+ });
1207
+ }
1208
+
1209
+ /**
1210
+ * Order pyramid levels finest first, which is what the renderer expects.
1211
+ *
1212
+ * OME-NGFF asks for that order in the declaration, but a web-mercator pyramid —
1213
+ * what `ndpyramid`'s `pyramid_reproject` writes, and what CarbonPlan publishes —
1214
+ * numbers its levels by zoom, so `0` is the coarsest. Sorting by resolution
1215
+ * rather than trusting the declared order reads either convention right.
1216
+ */
1217
+ export function orderLevelsFinestFirst(levels) {
1218
+ return _toConsumableArray(levels).sort(function (a, b) {
1219
+ return b.shape[0] * b.shape[1] - a.shape[0] * a.shape[1];
1220
+ });
1221
+ }
1222
+
1223
+ /**
1224
+ * Names of the data arrays a pyramid level holds.
1225
+ *
1226
+ * An OME-NGFF level path points straight at the array, so there is nothing to
1227
+ * name and the result is a single empty string. `ndpyramid` instead writes an
1228
+ * xarray dataset per level, so the level is a group and each array inside it is
1229
+ * a separate variable sharing the same pyramid.
1230
+ */
1231
+ export function multiscaleVariableNames(index, levelPath) {
1232
+ if (!index) {
1233
+ return [];
1234
+ }
1235
+ var normalized = normalizePath(levelPath);
1236
+ if (index.get(normalized) === 'array') {
1237
+ return [''];
1238
+ }
1239
+ var prefix = "".concat(normalized, "/");
1240
+ var names = [];
1241
+ var _iterator6 = _createForOfIteratorHelper(index),
1242
+ _step6;
1243
+ try {
1244
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1245
+ var _step6$value = _slicedToArray(_step6.value, 2),
1246
+ path = _step6$value[0],
1247
+ kind = _step6$value[1];
1248
+ if (kind !== 'array' || !path.startsWith(prefix)) {
1249
+ continue;
1250
+ }
1251
+ var rest = path.slice(prefix.length);
1252
+ if (!rest.includes('/')) {
1253
+ names.push(rest);
1254
+ }
1255
+ }
1256
+ } catch (err) {
1257
+ _iterator6.e(err);
1258
+ } finally {
1259
+ _iterator6.f();
1260
+ }
1261
+ return names;
1262
+ }
1263
+
1264
+ /**
1265
+ * Rewrite per-level grids into the `multiscales.layout` the GeoZarr parser
1266
+ * reads. Levels stay finest-first, which is the order it expects.
1267
+ */
1268
+ export function buildMultiscaleAttrs(base, levels) {
1269
+ // The finest grid stays at the top level as well, because the convention
1270
+ // allows per-level values to be omitted and falls back to it.
1271
+ return _objectSpread(_objectSpread({}, base), {}, {
1272
+ multiscales: {
1273
+ layout: levels.map(function (level) {
1274
+ return {
1275
+ asset: level.asset,
1276
+ 'spatial:transform': level.transform,
1277
+ 'spatial:shape': level.shape
1278
+ };
1279
+ })
1280
+ }
1281
+ });
1282
+ }
1283
+ /** Decode coordinates without losing categorical labels or duration/calendar metadata. */
1284
+ export function decodeZarrCoordinate(name, size, raw, attrs) {
1285
+ var units = readString(attrs, ['units']);
1286
+ var calendar = readString(attrs, ['calendar']);
1287
+ var standardName = readString(attrs, ['standard_name']);
1288
+ var source = Array.from(raw);
1289
+ var values = source.map(function (value) {
1290
+ return typeof value === 'bigint' ? Number.isSafeInteger(Number(value)) ? Number(value) : String(value) : value;
1291
+ });
1292
+ var dimension = {
1293
+ name: name,
1294
+ size: size,
1295
+ units: units,
1296
+ calendar: calendar,
1297
+ standardName: standardName
1298
+ };
1299
+ if (!values.every(function (v) {
1300
+ return ['number', 'string', 'boolean'].includes(_typeof(v));
1301
+ })) {
1302
+ return {
1303
+ dimension: dimension,
1304
+ isCfTime: false
1305
+ };
1306
+ }
1307
+ var numeric = values.every(function (v) {
1308
+ return typeof v === 'number';
1309
+ });
1310
+ var decoded = source.every(function (v) {
1311
+ return typeof v === 'number' || typeof v === 'bigint';
1312
+ }) ? decodeCfTime(source, units, calendar) : null;
1313
+ return {
1314
+ dimension: _objectSpread(_objectSpread(_objectSpread({}, dimension), {}, {
1315
+ values: decoded !== null && decoded !== void 0 ? decoded : values
1316
+ }, decoded ? {
1317
+ rawValues: values
1318
+ } : {}), {}, {
1319
+ kind: decoded ? 'time' : !numeric || standardName === 'realization' ? 'category' : standardName === 'forecast_period' || String(attrs.dtype).startsWith('timedelta') ? 'duration' : 'number'
1320
+ }),
1321
+ isCfTime: Boolean(decoded)
1322
+ };
1323
+ }
1324
+
1325
+ /**
1326
+ * Coordinate arrays are shared across the variables of a store, and a time axis
1327
+ * can run to thousands of values. Read each one once per metadata fetch.
1328
+ */
1329
+
1330
+ function readCoordinateDimension(store, index, variablePath, name, size, cache) {
1331
+ var resolved = resolveCoordinatePath(index, variablePath, name);
1332
+ if (index && !resolved) {
1333
+ // The listing says this dimension has no coordinate array; do not probe.
1334
+ return Promise.resolve({
1335
+ dimension: {
1336
+ name: name,
1337
+ size: size
1338
+ },
1339
+ isCfTime: false
1340
+ });
1341
+ }
1342
+ var key = "".concat(resolved !== null && resolved !== void 0 ? resolved : variablePath, "|").concat(name, "|").concat(size);
1343
+ var cached = cache.dimensions.get(key);
1344
+ if (cached) {
1345
+ return cached;
1346
+ }
1347
+ var pending = loadCoordinateDimension(store, index, variablePath, name, size);
1348
+ cache.dimensions.set(key, pending);
1349
+ return pending;
1350
+ }
1351
+ function loadCoordinateDimension(_x29, _x30, _x31, _x32, _x33) {
1352
+ return _loadCoordinateDimension.apply(this, arguments);
1353
+ }
1354
+ /**
1355
+ * A dimension decoded through CF units is temporal regardless of its name.
1356
+ * Otherwise fall back to the conventional time dimension names.
1357
+ */
1358
+ function _loadCoordinateDimension() {
1359
+ _loadCoordinateDimension = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10(store, index, variablePath, name, size) {
1360
+ var dimension, arr, _yield$loadZarrRuntim7, zarr, chunk;
1361
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
1362
+ while (1) switch (_context10.prev = _context10.next) {
1363
+ case 0:
1364
+ dimension = {
1365
+ name: name,
1366
+ size: size
1367
+ };
1368
+ if (!(size > MAX_COORDINATE_LENGTH)) {
1369
+ _context10.next = 3;
1370
+ break;
1371
+ }
1372
+ return _context10.abrupt("return", {
1373
+ dimension: dimension,
1374
+ isCfTime: false
1375
+ });
1376
+ case 3:
1377
+ _context10.next = 5;
1378
+ return openCoordinateArray(store, index, variablePath, name, size);
1379
+ case 5:
1380
+ arr = _context10.sent;
1381
+ if (arr) {
1382
+ _context10.next = 8;
1383
+ break;
1384
+ }
1385
+ return _context10.abrupt("return", {
1386
+ dimension: dimension,
1387
+ isCfTime: false
1388
+ });
1389
+ case 8:
1390
+ _context10.prev = 8;
1391
+ _context10.next = 11;
1392
+ return loadZarrRuntime();
1393
+ case 11:
1394
+ _yield$loadZarrRuntim7 = _context10.sent;
1395
+ zarr = _yield$loadZarrRuntim7.zarr;
1396
+ _context10.next = 15;
1397
+ return zarr.get(arr, null);
1398
+ case 15:
1399
+ chunk = _context10.sent;
1400
+ return _context10.abrupt("return", decodeZarrCoordinate(name, size, chunk.data, getAttrs(arr)));
1401
+ case 19:
1402
+ _context10.prev = 19;
1403
+ _context10.t0 = _context10["catch"](8);
1404
+ throwIfAborted(store.signal);
1405
+ return _context10.abrupt("return", {
1406
+ dimension: dimension,
1407
+ isCfTime: false
1408
+ });
1409
+ case 23:
1410
+ case "end":
1411
+ return _context10.stop();
1412
+ }
1413
+ }, _callee10, null, [[8, 19]]);
1414
+ }));
1415
+ return _loadCoordinateDimension.apply(this, arguments);
1416
+ }
1417
+ function isTimeDimension(dimension, decodedFromCf) {
1418
+ if (!dimension.values || dimension.values.length < 2) {
1419
+ return false;
1420
+ }
1421
+ // Unsupported calendars/units must not be mistaken for epoch milliseconds.
1422
+ return decodedFromCf || !dimension.units && dimension.kind !== 'category' && TIME_DIMENSION_NAMES.has(dimension.name.toLowerCase());
1423
+ }
1424
+ function buildVariableInfo(_x34, _x35, _x36, _x37, _x38) {
1425
+ return _buildVariableInfo.apply(this, arguments);
1426
+ }
1427
+ /**
1428
+ * Build one variable per data array of an OME-NGFF style pyramid.
1429
+ *
1430
+ * Each level holds the same arrays at a lower resolution, so a variable's
1431
+ * identity is the group plus the array name while the node handed to the
1432
+ * renderer is the group itself. A level whose grid cannot be derived ends the
1433
+ * pyramid rather than discarding it, leaving the finer levels usable.
1434
+ */
1435
+ function _buildVariableInfo() {
1436
+ _buildVariableInfo = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11(store, index, path, geoAttrs, cache) {
1437
+ var _options$nodePath, _options$preopened, _options$webMercatorP, _readDataRange, _readNumber;
1438
+ var options,
1439
+ _yield$loadZarrRuntim8,
1440
+ zarr,
1441
+ parseGeoZarrMetadata,
1442
+ geo,
1443
+ spatialDims,
1444
+ nodePath,
1445
+ basePath,
1446
+ finest,
1447
+ arrayPath,
1448
+ arr,
1449
+ dimensionNames,
1450
+ nonSpatialDims,
1451
+ timeDimension,
1452
+ i,
1453
+ _name,
1454
+ _yield$readCoordinate,
1455
+ dimension,
1456
+ isCfTime,
1457
+ arrayAttrs,
1458
+ fillValue,
1459
+ name,
1460
+ _args11 = arguments;
1461
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
1462
+ while (1) switch (_context11.prev = _context11.next) {
1463
+ case 0:
1464
+ options = _args11.length > 5 && _args11[5] !== undefined ? _args11[5] : {};
1465
+ _context11.next = 3;
1466
+ return loadZarrRuntime();
1467
+ case 3:
1468
+ _yield$loadZarrRuntim8 = _context11.sent;
1469
+ zarr = _yield$loadZarrRuntim8.zarr;
1470
+ parseGeoZarrMetadata = _yield$loadZarrRuntim8.parseGeoZarrMetadata;
1471
+ geo = parseGeoZarrMetadata(geoAttrs);
1472
+ spatialDims = [geo.axes[geo.yAxisIndex], geo.axes[geo.xAxisIndex]];
1473
+ nodePath = (_options$nodePath = options.nodePath) !== null && _options$nodePath !== void 0 ? _options$nodePath : path;
1474
+ basePath = toAbsolutePath(nodePath);
1475
+ finest = geo.levels[0];
1476
+ arrayPath = !finest || finest.path === '.' ? basePath : toAbsolutePath("".concat(nodePath, "/").concat(finest.path));
1477
+ if (!((_options$preopened = options.preopened) !== null && _options$preopened !== void 0)) {
1478
+ _context11.next = 16;
1479
+ break;
1480
+ }
1481
+ _context11.t0 = _options$preopened;
1482
+ _context11.next = 19;
1483
+ break;
1484
+ case 16:
1485
+ _context11.next = 18;
1486
+ return zarr.open(new zarr.Location(store, arrayPath), {
1487
+ kind: 'array'
1488
+ });
1489
+ case 18:
1490
+ _context11.t0 = _context11.sent;
1491
+ case 19:
1492
+ arr = _context11.t0;
1493
+ dimensionNames = getZarrDimensionNames(arr);
1494
+ if (dimensionNames) {
1495
+ _context11.next = 23;
1496
+ break;
1497
+ }
1498
+ throw new Error("Zarr array \"".concat(arrayPath, "\" does not name every dimension. ") + 'Rendering requires zarr v3 `dimension_names` or an `_ARRAY_DIMENSIONS` attribute.');
1499
+ case 23:
1500
+ nonSpatialDims = [];
1501
+ i = 0;
1502
+ case 25:
1503
+ if (!(i < dimensionNames.length)) {
1504
+ _context11.next = 39;
1505
+ break;
1506
+ }
1507
+ _name = dimensionNames[i];
1508
+ if (!spatialDims.includes(_name)) {
1509
+ _context11.next = 29;
1510
+ break;
1511
+ }
1512
+ return _context11.abrupt("continue", 36);
1513
+ case 29:
1514
+ _context11.next = 31;
1515
+ return readCoordinateDimension(store, index, arrayPath, _name, arr.shape[i], cache);
1516
+ case 31:
1517
+ _yield$readCoordinate = _context11.sent;
1518
+ dimension = _yield$readCoordinate.dimension;
1519
+ isCfTime = _yield$readCoordinate.isCfTime;
1520
+ nonSpatialDims.push(dimension);
1521
+ if (!timeDimension && isTimeDimension(dimension, isCfTime)) {
1522
+ timeDimension = dimension;
1523
+ }
1524
+ case 36:
1525
+ i++;
1526
+ _context11.next = 25;
1527
+ break;
1528
+ case 39:
1529
+ arrayAttrs = getAttrs(arr);
1530
+ fillValue = arr.fillValue;
1531
+ name = path.split('/').filter(Boolean).pop() || path || 'data';
1532
+ return _context11.abrupt("return", _objectSpread(_objectSpread({
1533
+ path: path
1534
+ }, options.nodePath !== undefined && {
1535
+ nodePath: options.nodePath
1536
+ }), {}, {
1537
+ name: name,
1538
+ // Qualified later, once every sibling variable is known.
1539
+ displayName: name,
1540
+ geoAttrs: geoAttrs,
1541
+ spatialMetadata: {
1542
+ crs: geo.crs,
1543
+ axes: geo.axes,
1544
+ xAxisIndex: geo.xAxisIndex,
1545
+ yAxisIndex: geo.yAxisIndex,
1546
+ levels: geo.levels.map(function (level) {
1547
+ return {
1548
+ path: level.path,
1549
+ shape: [level.arrayHeight, level.arrayWidth],
1550
+ chunks: arr.chunks.slice(-2)
1551
+ };
1552
+ }),
1553
+ webMercatorPyramid: (_options$webMercatorP = options.webMercatorPyramid) !== null && _options$webMercatorP !== void 0 ? _options$webMercatorP : false
1554
+ },
1555
+ shape: _toConsumableArray(arr.shape),
1556
+ chunks: _toConsumableArray(arr.chunks),
1557
+ dtype: String(arr.dtype),
1558
+ nonSpatialDims: nonSpatialDims,
1559
+ timeDimension: timeDimension,
1560
+ dataRange: (_readDataRange = readDataRange(arrayAttrs)) !== null && _readDataRange !== void 0 ? _readDataRange : readDataRange(geoAttrs),
1561
+ nodataValue: (_readNumber = readNumber(arrayAttrs, ['_FillValue', 'missing_value', 'nodata'])) !== null && _readNumber !== void 0 ? _readNumber : readNumber({
1562
+ fillValue: fillValue
1563
+ }, ['fillValue'])
1564
+ }));
1565
+ case 43:
1566
+ case "end":
1567
+ return _context11.stop();
1568
+ }
1569
+ }, _callee11);
1570
+ }));
1571
+ return _buildVariableInfo.apply(this, arguments);
1572
+ }
1573
+ function buildPyramidVariables(_x39, _x40, _x41, _x42, _x43, _x44) {
1574
+ return _buildPyramidVariables.apply(this, arguments);
1575
+ }
1576
+ function _buildPyramidVariables() {
1577
+ _buildPyramidVariables = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12(store, index, groupPath, levelPaths, cache, webMercatorPyramid) {
1578
+ var _yield$loadZarrRuntim9, zarr, base, resolve, names, variables, _iterator11, _step11, _loop2;
1579
+ return _regeneratorRuntime.wrap(function _callee12$(_context13) {
1580
+ while (1) switch (_context13.prev = _context13.next) {
1581
+ case 0:
1582
+ _context13.next = 2;
1583
+ return loadZarrRuntime();
1584
+ case 2:
1585
+ _yield$loadZarrRuntim9 = _context13.sent;
1586
+ zarr = _yield$loadZarrRuntim9.zarr;
1587
+ base = normalizePath(groupPath);
1588
+ resolve = function resolve(rest) {
1589
+ return base ? "".concat(base, "/").concat(rest) : rest;
1590
+ };
1591
+ names = multiscaleVariableNames(index, resolve(levelPaths[0]));
1592
+ variables = [];
1593
+ _iterator11 = _createForOfIteratorHelper(names.slice(0, MAX_VARIABLE_CANDIDATES));
1594
+ _context13.prev = 9;
1595
+ _loop2 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop2() {
1596
+ var name, asset, collected, _iterator12, _step12, level, levelPath, arr, dimensionNames, attrs, ordered, finest, variable;
1597
+ return _regeneratorRuntime.wrap(function _loop2$(_context12) {
1598
+ while (1) switch (_context12.prev = _context12.next) {
1599
+ case 0:
1600
+ name = _step11.value;
1601
+ asset = function asset(level) {
1602
+ return name ? "".concat(level, "/").concat(name) : level;
1603
+ };
1604
+ collected = [];
1605
+ _iterator12 = _createForOfIteratorHelper(levelPaths);
1606
+ _context12.prev = 4;
1607
+ _iterator12.s();
1608
+ case 6:
1609
+ if ((_step12 = _iterator12.n()).done) {
1610
+ _context12.next = 36;
1611
+ break;
1612
+ }
1613
+ level = _step12.value;
1614
+ levelPath = resolve(asset(level));
1615
+ if (!isKnownMissing(index, levelPath, 'array')) {
1616
+ _context12.next = 11;
1617
+ break;
1618
+ }
1619
+ return _context12.abrupt("break", 36);
1620
+ case 11:
1621
+ arr = void 0;
1622
+ _context12.prev = 12;
1623
+ _context12.next = 15;
1624
+ return zarr.open(new zarr.Location(store, toAbsolutePath(levelPath)), {
1625
+ kind: 'array'
1626
+ });
1627
+ case 15:
1628
+ arr = _context12.sent;
1629
+ _context12.next = 22;
1630
+ break;
1631
+ case 18:
1632
+ _context12.prev = 18;
1633
+ _context12.t0 = _context12["catch"](12);
1634
+ throwIfAborted(store.signal);
1635
+ return _context12.abrupt("break", 36);
1636
+ case 22:
1637
+ dimensionNames = getZarrDimensionNames(arr);
1638
+ if (!dimensionNames) {
1639
+ _context12.next = 29;
1640
+ break;
1641
+ }
1642
+ _context12.next = 26;
1643
+ return deriveGeoZarrAttrs(store, index, levelPath, arr, dimensionNames, cache);
1644
+ case 26:
1645
+ _context12.t1 = _context12.sent;
1646
+ _context12.next = 30;
1647
+ break;
1648
+ case 29:
1649
+ _context12.t1 = null;
1650
+ case 30:
1651
+ attrs = _context12.t1;
1652
+ if (attrs) {
1653
+ _context12.next = 33;
1654
+ break;
1655
+ }
1656
+ return _context12.abrupt("break", 36);
1657
+ case 33:
1658
+ collected.push({
1659
+ asset: asset(level),
1660
+ transform: attrs['spatial:transform'],
1661
+ shape: attrs['spatial:shape'],
1662
+ arr: arr,
1663
+ attrs: attrs
1664
+ });
1665
+ case 34:
1666
+ _context12.next = 6;
1667
+ break;
1668
+ case 36:
1669
+ _context12.next = 41;
1670
+ break;
1671
+ case 38:
1672
+ _context12.prev = 38;
1673
+ _context12.t2 = _context12["catch"](4);
1674
+ _iterator12.e(_context12.t2);
1675
+ case 41:
1676
+ _context12.prev = 41;
1677
+ _iterator12.f();
1678
+ return _context12.finish(41);
1679
+ case 44:
1680
+ if (collected.length) {
1681
+ _context12.next = 46;
1682
+ break;
1683
+ }
1684
+ return _context12.abrupt("return", 1);
1685
+ case 46:
1686
+ ordered = orderLevelsFinestFirst(collected);
1687
+ finest = ordered[0];
1688
+ _context12.next = 50;
1689
+ return buildVariableInfo(store, index, name ? resolve(name) : base, buildMultiscaleAttrs(finest.attrs, ordered.map(function (_ref5) {
1690
+ var a = _ref5.asset,
1691
+ transform = _ref5.transform,
1692
+ shape = _ref5.shape;
1693
+ return {
1694
+ asset: a,
1695
+ transform: transform,
1696
+ shape: shape
1697
+ };
1698
+ })), cache, {
1699
+ preopened: finest.arr,
1700
+ nodePath: base,
1701
+ webMercatorPyramid: webMercatorPyramid
1702
+ });
1703
+ case 50:
1704
+ variable = _context12.sent;
1705
+ if (variable) {
1706
+ variables.push(variable);
1707
+ }
1708
+ case 52:
1709
+ case "end":
1710
+ return _context12.stop();
1711
+ }
1712
+ }, _loop2, null, [[4, 38, 41, 44], [12, 18]]);
1713
+ });
1714
+ _iterator11.s();
1715
+ case 12:
1716
+ if ((_step11 = _iterator11.n()).done) {
1717
+ _context13.next = 18;
1718
+ break;
1719
+ }
1720
+ return _context13.delegateYield(_loop2(), "t0", 14);
1721
+ case 14:
1722
+ if (!_context13.t0) {
1723
+ _context13.next = 16;
1724
+ break;
1725
+ }
1726
+ return _context13.abrupt("continue", 16);
1727
+ case 16:
1728
+ _context13.next = 12;
1729
+ break;
1730
+ case 18:
1731
+ _context13.next = 23;
1732
+ break;
1733
+ case 20:
1734
+ _context13.prev = 20;
1735
+ _context13.t1 = _context13["catch"](9);
1736
+ _iterator11.e(_context13.t1);
1737
+ case 23:
1738
+ _context13.prev = 23;
1739
+ _iterator11.f();
1740
+ return _context13.finish(23);
1741
+ case 26:
1742
+ return _context13.abrupt("return", variables);
1743
+ case 27:
1744
+ case "end":
1745
+ return _context13.stop();
1746
+ }
1747
+ }, _callee12, null, [[9, 20, 23, 26]]);
1748
+ }));
1749
+ return _buildPyramidVariables.apply(this, arguments);
1750
+ }
1751
+ function pathSuffix(path, depth) {
1752
+ return path.split('/').filter(Boolean).slice(-depth).join('/');
1753
+ }
1754
+
1755
+ /**
1756
+ * Stores often repeat a variable across scenario groups, e.g. `FUTUR/evap_total`
1757
+ * and `HISTO/evap_total`. Listing those by array name alone shows the same label
1758
+ * several times, so prepend the fewest leading path segments that tell them
1759
+ * apart. Names that are already unique are left alone.
1760
+ */
1761
+ export function assignVariableDisplayNames(variables) {
1762
+ var byName = new Map();
1763
+ var _iterator7 = _createForOfIteratorHelper(variables),
1764
+ _step7;
1765
+ try {
1766
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1767
+ var variable = _step7.value;
1768
+ var group = byName.get(variable.name);
1769
+ if (group) {
1770
+ group.push(variable);
1771
+ } else {
1772
+ byName.set(variable.name, [variable]);
1773
+ }
1774
+ }
1775
+ } catch (err) {
1776
+ _iterator7.e(err);
1777
+ } finally {
1778
+ _iterator7.f();
1779
+ }
1780
+ var labels = new Map();
1781
+ var _iterator8 = _createForOfIteratorHelper(byName.values()),
1782
+ _step8;
1783
+ try {
1784
+ var _loop = function _loop() {
1785
+ var group = _step8.value;
1786
+ if (group.length < 2) {
1787
+ return 1; // continue
1788
+ }
1789
+ var maxDepth = Math.max.apply(Math, _toConsumableArray(group.map(function (variable) {
1790
+ return variable.path.split('/').filter(Boolean).length;
1791
+ })));
1792
+ var depth = 2;
1793
+ var candidates = group.map(function (variable) {
1794
+ return pathSuffix(variable.path, depth);
1795
+ });
1796
+ while (new Set(candidates).size < group.length && depth < maxDepth) {
1797
+ depth += 1;
1798
+ candidates = group.map(function (variable) {
1799
+ return pathSuffix(variable.path, depth);
1800
+ });
1801
+ }
1802
+ group.forEach(function (variable, i) {
1803
+ return labels.set(variable, candidates[i] || variable.name);
1804
+ });
1805
+ };
1806
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1807
+ if (_loop()) continue;
1808
+ }
1809
+ } catch (err) {
1810
+ _iterator8.e(err);
1811
+ } finally {
1812
+ _iterator8.f();
1813
+ }
1814
+ return variables.map(function (variable) {
1815
+ var label = labels.get(variable);
1816
+ return label ? _objectSpread(_objectSpread({}, variable), {}, {
1817
+ displayName: label
1818
+ }) : variable;
1819
+ });
1820
+ }
1821
+
1822
+ /**
1823
+ * Prefix matching everything below a matched node, so its resolution levels are
1824
+ * not offered as variables of their own. When the root matched, every remaining
1825
+ * path is one of its children.
1826
+ */
1827
+ export function childPrefix(path) {
1828
+ var normalized = normalizePath(path);
1829
+ return normalized ? "".concat(normalized, "/") : '';
1830
+ }
1831
+ function listCandidatePaths(_x45) {
1832
+ return _listCandidatePaths.apply(this, arguments);
1833
+ }
1834
+ /**
1835
+ * Discover every renderable variable in a store.
1836
+ *
1837
+ * Nodes that declare the GeoZarr `spatial` and `geo-proj` conventions are used
1838
+ * as-is. Very little published data does yet, so an array that does not declare
1839
+ * them is still accepted when its CF/GDAL metadata is enough to derive the same
1840
+ * information. Children of a matched node are skipped so resolution levels are
1841
+ * not offered as separate variables.
1842
+ */
1843
+ function _listCandidatePaths() {
1844
+ _listCandidatePaths = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee13(store) {
1845
+ var contents, paths;
1846
+ return _regeneratorRuntime.wrap(function _callee13$(_context14) {
1847
+ while (1) switch (_context14.prev = _context14.next) {
1848
+ case 0:
1849
+ if (!(typeof store.contents !== 'function')) {
1850
+ _context14.next = 2;
1851
+ break;
1852
+ }
1853
+ return _context14.abrupt("return", ['']);
1854
+ case 2:
1855
+ contents = store.contents();
1856
+ paths = contents.filter(function (entry) {
1857
+ return entry.kind === 'group' || entry.kind === 'array';
1858
+ }).map(function (entry) {
1859
+ return entry.path.replace(/^\/+/, '');
1860
+ })
1861
+ // Shallow nodes first so a multiscale parent is matched before its levels.
1862
+ .sort(function (a, b) {
1863
+ return a.split('/').length - b.split('/').length || a.localeCompare(b);
1864
+ });
1865
+ return _context14.abrupt("return", paths.length ? paths : ['']);
1866
+ case 5:
1867
+ case "end":
1868
+ return _context14.stop();
1869
+ }
1870
+ }, _callee13);
1871
+ }));
1872
+ return _listCandidatePaths.apply(this, arguments);
1873
+ }
1874
+ export function getZarrMetadata(_x46) {
1875
+ return _getZarrMetadata.apply(this, arguments);
1876
+ }
1877
+ function _getZarrMetadata() {
1878
+ _getZarrMetadata = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee14(url) {
1879
+ var _labeled$find;
1880
+ var options,
1881
+ signal,
1882
+ onProgress,
1883
+ _yield$loadZarrRuntim0,
1884
+ zarr,
1885
+ parseGeoZarrMetadata,
1886
+ store,
1887
+ index,
1888
+ paths,
1889
+ variables,
1890
+ coordinateCache,
1891
+ matchedPrefixes,
1892
+ errors,
1893
+ _iterator13,
1894
+ _step13,
1895
+ _loop3,
1896
+ _ret,
1897
+ labeled,
1898
+ active,
1899
+ _args16 = arguments;
1900
+ return _regeneratorRuntime.wrap(function _callee14$(_context16) {
1901
+ while (1) switch (_context16.prev = _context16.next) {
1902
+ case 0:
1903
+ options = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : {};
1904
+ signal = options.signal, onProgress = options.onProgress;
1905
+ throwIfAborted(signal);
1906
+ onProgress === null || onProgress === void 0 || onProgress({
1907
+ phase: 'connecting',
1908
+ loadedBytes: 0
1909
+ });
1910
+ _context16.next = 6;
1911
+ return loadZarrRuntime();
1912
+ case 6:
1913
+ _yield$loadZarrRuntim0 = _context16.sent;
1914
+ zarr = _yield$loadZarrRuntim0.zarr;
1915
+ parseGeoZarrMetadata = _yield$loadZarrRuntim0.parseGeoZarrMetadata;
1916
+ throwIfAborted(signal);
1917
+ // Keep the signal out of the shared cache. All reads, including coordinate
1918
+ // chunks and range requests, go through this request-scoped fetch function.
1919
+ if (!(signal || onProgress)) {
1920
+ _context16.next = 19;
1921
+ break;
1922
+ }
1923
+ _context16.t1 = Object;
1924
+ _context16.next = 14;
1925
+ return withDetectedZarrMetadata(new zarr.FetchStore(url, {
1926
+ fetch: onProgress ? createMetadataFetch(signal, onProgress) : function (request) {
1927
+ return fetch(request, {
1928
+ signal: signal
1929
+ });
1930
+ }
1931
+ }));
1932
+ case 14:
1933
+ _context16.t2 = _context16.sent;
1934
+ _context16.t3 = {
1935
+ signal: signal
1936
+ };
1937
+ _context16.t0 = _context16.t1.assign.call(_context16.t1, _context16.t2, _context16.t3);
1938
+ _context16.next = 22;
1939
+ break;
1940
+ case 19:
1941
+ _context16.next = 21;
1942
+ return openZarrStore(url);
1943
+ case 21:
1944
+ _context16.t0 = _context16.sent;
1945
+ case 22:
1946
+ store = _context16.t0;
1947
+ throwIfAborted(signal);
1948
+ index = buildStoreIndex(store);
1949
+ _context16.next = 27;
1950
+ return listCandidatePaths(store);
1951
+ case 27:
1952
+ paths = _context16.sent;
1953
+ variables = [];
1954
+ coordinateCache = {
1955
+ dimensions: new Map(),
1956
+ spatialAxes: new Map()
1957
+ };
1958
+ matchedPrefixes = [];
1959
+ errors = [];
1960
+ _iterator13 = _createForOfIteratorHelper(paths.slice(0, MAX_VARIABLE_CANDIDATES));
1961
+ _context16.prev = 33;
1962
+ _loop3 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop3() {
1963
+ var path, node, declared, levelPaths, pyramid, geoAttrs, preopened, arr, dimensionNames, variable;
1964
+ return _regeneratorRuntime.wrap(function _loop3$(_context15) {
1965
+ while (1) switch (_context15.prev = _context15.next) {
1966
+ case 0:
1967
+ path = _step13.value;
1968
+ throwIfAborted(signal);
1969
+ if (!matchedPrefixes.some(function (prefix) {
1970
+ return path.startsWith(prefix);
1971
+ })) {
1972
+ _context15.next = 4;
1973
+ break;
1974
+ }
1975
+ return _context15.abrupt("return", 0);
1976
+ case 4:
1977
+ _context15.prev = 4;
1978
+ _context15.next = 7;
1979
+ return zarr.open(new zarr.Location(store, toAbsolutePath(path)), {
1980
+ kind: index === null || index === void 0 ? void 0 : index.get(normalizePath(path))
1981
+ });
1982
+ case 7:
1983
+ node = _context15.sent;
1984
+ _context15.next = 14;
1985
+ break;
1986
+ case 10:
1987
+ _context15.prev = 10;
1988
+ _context15.t0 = _context15["catch"](4);
1989
+ throwIfAborted(signal);
1990
+ return _context15.abrupt("return", 0);
1991
+ case 14:
1992
+ declared = getAttrs(node); // A pyramid written in the OME-NGFF style has to be rewritten before the
1993
+ // GeoZarr parser can read it, and yields one variable per array in a level.
1994
+ levelPaths = 'shape' in node ? null : parseOmeMultiscaleLevels(declared);
1995
+ if (!levelPaths) {
1996
+ _context15.next = 31;
1997
+ break;
1998
+ }
1999
+ _context15.prev = 17;
2000
+ _context15.next = 20;
2001
+ return buildPyramidVariables(store, index, path, levelPaths, coordinateCache, isWebMercatorPyramid(declared));
2002
+ case 20:
2003
+ pyramid = _context15.sent;
2004
+ if (!pyramid.length) {
2005
+ _context15.next = 25;
2006
+ break;
2007
+ }
2008
+ variables.push.apply(variables, _toConsumableArray(pyramid));
2009
+ matchedPrefixes.push(childPrefix(path));
2010
+ return _context15.abrupt("return", 0);
2011
+ case 25:
2012
+ _context15.next = 31;
2013
+ break;
2014
+ case 27:
2015
+ _context15.prev = 27;
2016
+ _context15.t1 = _context15["catch"](17);
2017
+ throwIfAborted(signal);
2018
+ errors.push(_context15.t1 instanceof Error ? _context15.t1.message : String(_context15.t1));
2019
+ case 31:
2020
+ geoAttrs = null;
2021
+ _context15.prev = 32;
2022
+ parseGeoZarrMetadata(declared);
2023
+ geoAttrs = declared;
2024
+ _context15.next = 51;
2025
+ break;
2026
+ case 37:
2027
+ _context15.prev = 37;
2028
+ _context15.t2 = _context15["catch"](32);
2029
+ if (!('shape' in node)) {
2030
+ _context15.next = 51;
2031
+ break;
2032
+ }
2033
+ arr = node;
2034
+ dimensionNames = getZarrDimensionNames(arr);
2035
+ if (!dimensionNames) {
2036
+ _context15.next = 48;
2037
+ break;
2038
+ }
2039
+ _context15.next = 45;
2040
+ return deriveGeoZarrAttrs(store, index, path, arr, dimensionNames, coordinateCache);
2041
+ case 45:
2042
+ _context15.t3 = _context15.sent;
2043
+ _context15.next = 49;
2044
+ break;
2045
+ case 48:
2046
+ _context15.t3 = null;
2047
+ case 49:
2048
+ geoAttrs = _context15.t3;
2049
+ preopened = arr;
2050
+ case 51:
2051
+ if (geoAttrs) {
2052
+ _context15.next = 53;
2053
+ break;
2054
+ }
2055
+ return _context15.abrupt("return", 0);
2056
+ case 53:
2057
+ _context15.prev = 53;
2058
+ _context15.next = 56;
2059
+ return buildVariableInfo(store, index, path, geoAttrs, coordinateCache, {
2060
+ preopened: preopened
2061
+ });
2062
+ case 56:
2063
+ variable = _context15.sent;
2064
+ if (variable) {
2065
+ variables.push(variable);
2066
+ matchedPrefixes.push(childPrefix(path));
2067
+ }
2068
+ _context15.next = 64;
2069
+ break;
2070
+ case 60:
2071
+ _context15.prev = 60;
2072
+ _context15.t4 = _context15["catch"](53);
2073
+ throwIfAborted(signal);
2074
+ errors.push(_context15.t4 instanceof Error ? _context15.t4.message : String(_context15.t4));
2075
+ case 64:
2076
+ case "end":
2077
+ return _context15.stop();
2078
+ }
2079
+ }, _loop3, null, [[4, 10], [17, 27], [32, 37], [53, 60]]);
2080
+ });
2081
+ _iterator13.s();
2082
+ case 36:
2083
+ if ((_step13 = _iterator13.n()).done) {
2084
+ _context16.next = 43;
2085
+ break;
2086
+ }
2087
+ return _context16.delegateYield(_loop3(), "t4", 38);
2088
+ case 38:
2089
+ _ret = _context16.t4;
2090
+ if (!(_ret === 0)) {
2091
+ _context16.next = 41;
2092
+ break;
2093
+ }
2094
+ return _context16.abrupt("continue", 41);
2095
+ case 41:
2096
+ _context16.next = 36;
2097
+ break;
2098
+ case 43:
2099
+ _context16.next = 48;
2100
+ break;
2101
+ case 45:
2102
+ _context16.prev = 45;
2103
+ _context16.t5 = _context16["catch"](33);
2104
+ _iterator13.e(_context16.t5);
2105
+ case 48:
2106
+ _context16.prev = 48;
2107
+ _iterator13.f();
2108
+ return _context16.finish(48);
2109
+ case 51:
2110
+ throwIfAborted(signal);
2111
+ if (!(variables.length === 0)) {
2112
+ _context16.next = 56;
2113
+ break;
2114
+ }
2115
+ if (!errors.length) {
2116
+ _context16.next = 55;
2117
+ break;
2118
+ }
2119
+ throw new Error(errors[0]);
2120
+ case 55:
2121
+ throw new Error(index ? 'No renderable variables found. The store must either declare the GeoZarr `spatial` ' + 'and `geo-proj` conventions, or expose a data array whose last two dimensions are ' + 'named y/x (or lat/lon) with coordinate arrays or a CF grid mapping.' : 'This store has no consolidated metadata, so its variables cannot be listed. Point ' + 'the URL directly at a data array, or use a store written with consolidated metadata.');
2122
+ case 56:
2123
+ labeled = assignVariableDisplayNames(variables);
2124
+ active = (_labeled$find = labeled.find(function (variable) {
2125
+ return variable.path === options.variable;
2126
+ })) !== null && _labeled$find !== void 0 ? _labeled$find : labeled[0];
2127
+ return _context16.abrupt("return", selectZarrVariable({
2128
+ url: url,
2129
+ axes: [],
2130
+ xAxisIndex: -1,
2131
+ yAxisIndex: -1,
2132
+ levels: [],
2133
+ variables: labeled,
2134
+ nonSpatialDims: []
2135
+ }, active.path));
2136
+ case 59:
2137
+ case "end":
2138
+ return _context16.stop();
2139
+ }
2140
+ }, _callee14, null, [[33, 45, 48, 51]]);
2141
+ }));
2142
+ return _getZarrMetadata.apply(this, arguments);
2143
+ }
2144
+ //# sourceMappingURL=zarr-utils.js.map