@loaders.gl/netcdf 4.2.0-alpha.3 → 4.2.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.dev.js CHANGED
@@ -2,14 +2,19 @@
2
2
  if (typeof exports === 'object' && typeof module === 'object')
3
3
  module.exports = factory();
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
- else if (typeof exports === 'object') exports['loader'] = factory();
6
- else root['loader'] = factory();})(globalThis, function () {
5
+ else if (typeof exports === 'object') exports['loaders'] = factory();
6
+ else root['loaders'] = factory();})(globalThis, function () {
7
7
  "use strict";
8
8
  var __exports__ = (() => {
9
+ var __create = Object.create;
9
10
  var __defProp = Object.defineProperty;
10
11
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __getProtoOf = Object.getPrototypeOf;
12
14
  var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __commonJS = (cb, mod) => function __require() {
16
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
+ };
13
18
  var __export = (target, all) => {
14
19
  for (var name in all)
15
20
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -22,21 +27,46 @@ var __exports__ = (() => {
22
27
  }
23
28
  return to;
24
29
  };
30
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
+ // If the importer is in node compatibility mode or this is not an ESM
33
+ // file that has been converted to a CommonJS file using a Babel-
34
+ // compatible transform (i.e. "__esModule" has not been set), then set
35
+ // "default" to the CommonJS "module.exports" for node compatibility.
36
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
+ mod
38
+ ));
25
39
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
40
 
27
- // src/index.ts
28
- var src_exports = {};
29
- __export(src_exports, {
41
+ // external-global-plugin:@loaders.gl/core
42
+ var require_core = __commonJS({
43
+ "external-global-plugin:@loaders.gl/core"(exports, module) {
44
+ module.exports = globalThis.loaders;
45
+ }
46
+ });
47
+
48
+ // bundle.ts
49
+ var bundle_exports = {};
50
+ __export(bundle_exports, {
30
51
  NetCDFLoader: () => NetCDFLoader,
31
52
  NetCDFReader: () => NetCDFReader
32
53
  });
54
+ __reExport(bundle_exports, __toESM(require_core(), 1));
33
55
 
34
56
  // src/iobuffer/iobuffer.ts
35
57
  var DEFAULT_BYTE_LENGTH = 1024 * 8;
36
58
  var IOBuffer = class {
37
- textDecoder = new TextDecoder();
38
- textEncoder = new TextEncoder();
59
+ /**
60
+ * @param data - The data to construct the IOBuffer with.
61
+ * If data is a number, it will be the new buffer's length<br>
62
+ * If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br>
63
+ * If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,
64
+ * or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.
65
+ * @param options
66
+ */
39
67
  constructor(data = DEFAULT_BYTE_LENGTH, options = {}) {
68
+ this.textDecoder = new TextDecoder();
69
+ this.textEncoder = new TextEncoder();
40
70
  let dataIsGiven = false;
41
71
  if (typeof data === "number") {
42
72
  data = new ArrayBuffer(data);
@@ -68,43 +98,89 @@ var __exports__ = (() => {
68
98
  this._mark = 0;
69
99
  this._marks = [];
70
100
  }
101
+ /**
102
+ * Checks if the memory allocated to the buffer is sufficient to store more
103
+ * bytes after the offset.
104
+ * @param byteLength - The needed memory in bytes.
105
+ * @returns `true` if there is sufficient space and `false` otherwise.
106
+ */
71
107
  available(byteLength = 1) {
72
108
  return this.offset + byteLength <= this.length;
73
109
  }
110
+ /**
111
+ * Check if little-endian mode is used for reading and writing multi-byte
112
+ * values.
113
+ * @returns `true` if little-endian mode is used, `false` otherwise.
114
+ */
74
115
  isLittleEndian() {
75
116
  return this.littleEndian;
76
117
  }
118
+ /**
119
+ * Set little-endian mode for reading and writing multi-byte values.
120
+ */
77
121
  setLittleEndian() {
78
122
  this.littleEndian = true;
79
123
  return this;
80
124
  }
125
+ /**
126
+ * Check if big-endian mode is used for reading and writing multi-byte values.
127
+ * @returns `true` if big-endian mode is used, `false` otherwise.
128
+ */
81
129
  isBigEndian() {
82
130
  return !this.littleEndian;
83
131
  }
132
+ /**
133
+ * Switches to big-endian mode for reading and writing multi-byte values.
134
+ */
84
135
  setBigEndian() {
85
136
  this.littleEndian = false;
86
137
  return this;
87
138
  }
139
+ /**
140
+ * Move the pointer n bytes forward.
141
+ * @param n - Number of bytes to skip.
142
+ */
88
143
  skip(n = 1) {
89
144
  this.offset += n;
90
145
  return this;
91
146
  }
147
+ /**
148
+ * Move the pointer to the given offset.
149
+ * @param offset
150
+ */
92
151
  seek(offset) {
93
152
  this.offset = offset;
94
153
  return this;
95
154
  }
155
+ /**
156
+ * Store the current pointer offset.
157
+ * @see {@link IOBuffer#reset}
158
+ */
96
159
  mark() {
97
160
  this._mark = this.offset;
98
161
  return this;
99
162
  }
163
+ /**
164
+ * Move the pointer back to the last pointer offset set by mark.
165
+ * @see {@link IOBuffer#mark}
166
+ */
100
167
  reset() {
101
168
  this.offset = this._mark;
102
169
  return this;
103
170
  }
171
+ /**
172
+ * Push the current pointer offset to the mark stack.
173
+ * @see {@link IOBuffer#popMark}
174
+ */
104
175
  pushMark() {
105
176
  this._marks.push(this.offset);
106
177
  return this;
107
178
  }
179
+ /**
180
+ * Pop the last pointer offset from the mark stack, and set the current
181
+ * pointer offset to the popped value.
182
+ * @see {@link IOBuffer#pushMark}
183
+ */
108
184
  popMark() {
109
185
  const offset = this._marks.pop();
110
186
  if (offset === void 0) {
@@ -113,10 +189,20 @@ var __exports__ = (() => {
113
189
  this.seek(offset);
114
190
  return this;
115
191
  }
192
+ /**
193
+ * Move the pointer offset back to 0.
194
+ */
116
195
  rewind() {
117
196
  this.offset = 0;
118
197
  return this;
119
198
  }
199
+ /**
200
+ * Make sure the buffer has sufficient memory to write a given byteLength at
201
+ * the current pointer offset.
202
+ * If the buffer's memory is insufficient, this method will create a new
203
+ * buffer (a copy) with a length that is twice (byteLength + current offset).
204
+ * @param byteLength
205
+ */
120
206
  ensureAvailable(byteLength = 1) {
121
207
  if (!this.available(byteLength)) {
122
208
  const lengthNeeded = this.offset + byteLength;
@@ -129,18 +215,34 @@ var __exports__ = (() => {
129
215
  }
130
216
  return this;
131
217
  }
218
+ /**
219
+ * Read a byte and return false if the byte's value is 0, or true otherwise.
220
+ * Moves pointer forward by one byte.
221
+ */
132
222
  readBoolean() {
133
223
  return this.readUint8() !== 0;
134
224
  }
225
+ /**
226
+ * Read a signed 8-bit integer and move pointer forward by 1 byte.
227
+ */
135
228
  readInt8() {
136
229
  return this._data.getInt8(this.offset++);
137
230
  }
231
+ /**
232
+ * Read an unsigned 8-bit integer and move pointer forward by 1 byte.
233
+ */
138
234
  readUint8() {
139
235
  return this._data.getUint8(this.offset++);
140
236
  }
237
+ /**
238
+ * Alias for {@link IOBuffer#readUint8}.
239
+ */
141
240
  readByte() {
142
241
  return this.readUint8();
143
242
  }
243
+ /**
244
+ * Read `n` bytes and move pointer forward by `n` bytes.
245
+ */
144
246
  readBytes(n = 1) {
145
247
  const bytes = new Uint8Array(n);
146
248
  for (let i = 0; i < n; i++) {
@@ -148,39 +250,63 @@ var __exports__ = (() => {
148
250
  }
149
251
  return bytes;
150
252
  }
253
+ /**
254
+ * Read a 16-bit signed integer and move pointer forward by 2 bytes.
255
+ */
151
256
  readInt16() {
152
257
  const value = this._data.getInt16(this.offset, this.littleEndian);
153
258
  this.offset += 2;
154
259
  return value;
155
260
  }
261
+ /**
262
+ * Read a 16-bit unsigned integer and move pointer forward by 2 bytes.
263
+ */
156
264
  readUint16() {
157
265
  const value = this._data.getUint16(this.offset, this.littleEndian);
158
266
  this.offset += 2;
159
267
  return value;
160
268
  }
269
+ /**
270
+ * Read a 32-bit signed integer and move pointer forward by 4 bytes.
271
+ */
161
272
  readInt32() {
162
273
  const value = this._data.getInt32(this.offset, this.littleEndian);
163
274
  this.offset += 4;
164
275
  return value;
165
276
  }
277
+ /**
278
+ * Read a 32-bit unsigned integer and move pointer forward by 4 bytes.
279
+ */
166
280
  readUint32() {
167
281
  const value = this._data.getUint32(this.offset, this.littleEndian);
168
282
  this.offset += 4;
169
283
  return value;
170
284
  }
285
+ /**
286
+ * Read a 32-bit floating number and move pointer forward by 4 bytes.
287
+ */
171
288
  readFloat32() {
172
289
  const value = this._data.getFloat32(this.offset, this.littleEndian);
173
290
  this.offset += 4;
174
291
  return value;
175
292
  }
293
+ /**
294
+ * Read a 64-bit floating number and move pointer forward by 8 bytes.
295
+ */
176
296
  readFloat64() {
177
297
  const value = this._data.getFloat64(this.offset, this.littleEndian);
178
298
  this.offset += 8;
179
299
  return value;
180
300
  }
301
+ /**
302
+ * Read a 1-byte ASCII character and move pointer forward by 1 byte.
303
+ */
181
304
  readChar() {
182
305
  return String.fromCharCode(this.readInt8());
183
306
  }
307
+ /**
308
+ * Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.
309
+ */
184
310
  readChars(n = 1) {
185
311
  let result = "";
186
312
  for (let i = 0; i < n; i++) {
@@ -188,28 +314,50 @@ var __exports__ = (() => {
188
314
  }
189
315
  return result;
190
316
  }
317
+ /**
318
+ * Read the next `n` bytes, return a UTF-8 decoded string and move pointer
319
+ * forward by `n` bytes.
320
+ */
191
321
  readUtf8(n = 1) {
192
322
  return this.textDecoder.decode(this.readBytes(n));
193
323
  }
324
+ /**
325
+ * Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer
326
+ * forward by 1 byte.
327
+ */
194
328
  writeBoolean(value) {
195
329
  this.writeUint8(value ? 255 : 0);
196
330
  return this;
197
331
  }
332
+ /**
333
+ * Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.
334
+ */
198
335
  writeInt8(value) {
199
336
  this.ensureAvailable(1);
200
337
  this._data.setInt8(this.offset++, value);
201
338
  this._updateLastWrittenByte();
202
339
  return this;
203
340
  }
341
+ /**
342
+ * Write `value` as an 8-bit unsigned integer and move pointer forward by 1
343
+ * byte.
344
+ */
204
345
  writeUint8(value) {
205
346
  this.ensureAvailable(1);
206
347
  this._data.setUint8(this.offset++, value);
207
348
  this._updateLastWrittenByte();
208
349
  return this;
209
350
  }
351
+ /**
352
+ * An alias for {@link IOBuffer#writeUint8}.
353
+ */
210
354
  writeByte(value) {
211
355
  return this.writeUint8(value);
212
356
  }
357
+ /**
358
+ * Write all elements of `bytes` as uint8 values and move pointer forward by
359
+ * `bytes.length` bytes.
360
+ */
213
361
  writeBytes(bytes) {
214
362
  this.ensureAvailable(bytes.length);
215
363
  for (let i = 0; i < bytes.length; i++) {
@@ -218,6 +366,10 @@ var __exports__ = (() => {
218
366
  this._updateLastWrittenByte();
219
367
  return this;
220
368
  }
369
+ /**
370
+ * Write `value` as a 16-bit signed integer and move pointer forward by 2
371
+ * bytes.
372
+ */
221
373
  writeInt16(value) {
222
374
  this.ensureAvailable(2);
223
375
  this._data.setInt16(this.offset, value, this.littleEndian);
@@ -225,6 +377,10 @@ var __exports__ = (() => {
225
377
  this._updateLastWrittenByte();
226
378
  return this;
227
379
  }
380
+ /**
381
+ * Write `value` as a 16-bit unsigned integer and move pointer forward by 2
382
+ * bytes.
383
+ */
228
384
  writeUint16(value) {
229
385
  this.ensureAvailable(2);
230
386
  this._data.setUint16(this.offset, value, this.littleEndian);
@@ -232,6 +388,10 @@ var __exports__ = (() => {
232
388
  this._updateLastWrittenByte();
233
389
  return this;
234
390
  }
391
+ /**
392
+ * Write `value` as a 32-bit signed integer and move pointer forward by 4
393
+ * bytes.
394
+ */
235
395
  writeInt32(value) {
236
396
  this.ensureAvailable(4);
237
397
  this._data.setInt32(this.offset, value, this.littleEndian);
@@ -239,6 +399,10 @@ var __exports__ = (() => {
239
399
  this._updateLastWrittenByte();
240
400
  return this;
241
401
  }
402
+ /**
403
+ * Write `value` as a 32-bit unsigned integer and move pointer forward by 4
404
+ * bytes.
405
+ */
242
406
  writeUint32(value) {
243
407
  this.ensureAvailable(4);
244
408
  this._data.setUint32(this.offset, value, this.littleEndian);
@@ -246,6 +410,10 @@ var __exports__ = (() => {
246
410
  this._updateLastWrittenByte();
247
411
  return this;
248
412
  }
413
+ /**
414
+ * Write `value` as a 32-bit floating number and move pointer forward by 4
415
+ * bytes.
416
+ */
249
417
  writeFloat32(value) {
250
418
  this.ensureAvailable(4);
251
419
  this._data.setFloat32(this.offset, value, this.littleEndian);
@@ -253,6 +421,10 @@ var __exports__ = (() => {
253
421
  this._updateLastWrittenByte();
254
422
  return this;
255
423
  }
424
+ /**
425
+ * Write `value` as a 64-bit floating number and move pointer forward by 8
426
+ * bytes.
427
+ */
256
428
  writeFloat64(value) {
257
429
  this.ensureAvailable(8);
258
430
  this._data.setFloat64(this.offset, value, this.littleEndian);
@@ -260,22 +432,43 @@ var __exports__ = (() => {
260
432
  this._updateLastWrittenByte();
261
433
  return this;
262
434
  }
435
+ /**
436
+ * Write the charCode of `str`'s first character as an 8-bit unsigned integer
437
+ * and move pointer forward by 1 byte.
438
+ */
263
439
  writeChar(str) {
264
440
  return this.writeUint8(str.charCodeAt(0));
265
441
  }
442
+ /**
443
+ * Write the charCodes of all `str`'s characters as 8-bit unsigned integers
444
+ * and move pointer forward by `str.length` bytes.
445
+ */
266
446
  writeChars(str) {
267
447
  for (let i = 0; i < str.length; i++) {
268
448
  this.writeUint8(str.charCodeAt(i));
269
449
  }
270
450
  return this;
271
451
  }
452
+ /**
453
+ * UTF-8 encode and write `str` to the current pointer offset and move pointer
454
+ * forward according to the encoded length.
455
+ */
272
456
  writeUtf8(str) {
273
457
  const bytes = this.textEncoder.encode(str);
274
458
  return this.writeBytes(bytes);
275
459
  }
460
+ /**
461
+ * Export a Uint8Array view of the internal buffer.
462
+ * The view starts at the byte offset and its length
463
+ * is calculated to stop at the last written byte or the original length.
464
+ */
276
465
  toArray() {
277
466
  return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
278
467
  }
468
+ /**
469
+ * Update the last written byte offset
470
+ * @private
471
+ */
279
472
  _updateLastWrittenByte() {
280
473
  if (this.offset > this.lastWrittenByte) {
281
474
  this.lastWrittenByte = this.offset;
@@ -397,7 +590,9 @@ var __exports__ = (() => {
397
590
  recordDimension: {
398
591
  length: recordDimensionLength,
399
592
  id: dimList.recordId,
593
+ // id of the unlimited dimension
400
594
  name: dimList.recordName,
595
+ // name of the unlimited dimension
401
596
  recordStep: variableList.recordStep
402
597
  },
403
598
  dimensions: dimList.dimensions,
@@ -582,46 +777,89 @@ var __exports__ = (() => {
582
777
  this.header = readNetCDFHeader(buffer, version);
583
778
  this.buffer = buffer;
584
779
  }
780
+ /**
781
+ * @return {string} - Version for the NetCDF format
782
+ */
585
783
  get version() {
586
784
  if (this.header.version === 1) {
587
785
  return "classic format";
588
786
  }
589
787
  return "64-bit offset format";
590
788
  }
789
+ /**
790
+ * Get metadata for the record dimension
791
+ */
591
792
  get recordDimension() {
592
793
  return this.header.recordDimension;
593
794
  }
795
+ /**
796
+ * Get list of dimensions (each with `name` and `size`)
797
+ */
594
798
  get dimensions() {
595
799
  return this.header.dimensions;
596
800
  }
801
+ /**
802
+ * Get list of global attributes with:
803
+ * * `name`: String with the name of the attribute
804
+ * * `type`: String with the type of the attribute
805
+ * * `value`: A number or string with the value of the attribute
806
+ */
597
807
  get attributes() {
598
808
  return this.header.attributes;
599
809
  }
810
+ /**
811
+ * Get list of variables
812
+ */
600
813
  get variables() {
601
814
  return this.header.variables;
602
815
  }
816
+ /**
817
+ * Check if an attribute exists
818
+ * @param attributeName - Name of the attribute to find
819
+ * @return
820
+ */
603
821
  attributeExists(attributeName) {
604
822
  const attribute = this.attributes.find((val) => val.name === attributeName);
605
823
  return attribute !== void 0;
606
824
  }
825
+ /**
826
+ * Returns the value of an attribute
827
+ * @param attributeName
828
+ * @return Value of the attributeName or null
829
+ */
607
830
  getAttribute(attributeName) {
608
831
  const attribute = this.attributes.find((val) => val.name === attributeName);
609
832
  if (attribute)
610
833
  return attribute.value;
611
834
  return null;
612
835
  }
836
+ /**
837
+ * Check if a dataVariable exists
838
+ * @param variableName - Name of the variable to find
839
+ * @return
840
+ */
613
841
  dataVariableExists(variableName) {
614
842
  const variable = this.header.variables.find(function(val) {
615
843
  return val.name === variableName;
616
844
  });
617
845
  return variable !== void 0;
618
846
  }
847
+ /**
848
+ * Returns the value of a variable as a string
849
+ * @param variableName
850
+ * @return Value of the variable as a string or null
851
+ */
619
852
  getDataVariableAsString(variableName) {
620
853
  const variable = this.getDataVariable(variableName);
621
854
  if (variable)
622
855
  return variable.join("");
623
856
  return null;
624
857
  }
858
+ /**
859
+ * Retrieves the data for a given variable
860
+ * @param variableName - Name of the variable to search or variable object
861
+ * @return List with the variable values
862
+ */
625
863
  getDataVariable(variableName) {
626
864
  let variable;
627
865
  if (typeof variableName === "string") {
@@ -669,14 +907,18 @@ var __exports__ = (() => {
669
907
  };
670
908
 
671
909
  // src/netcdf-loader.ts
672
- var VERSION = true ? "4.2.0-alpha.3" : "latest";
910
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
673
911
  var NetCDFWorkerLoader = {
674
912
  name: "NetCDF",
675
913
  id: "mvt",
676
914
  module: "mvt",
677
915
  version: VERSION,
678
916
  extensions: ["cdf", "nc"],
679
- mimeTypes: ["application/netcdf", "application/x-netcdf"],
917
+ mimeTypes: [
918
+ "application/netcdf",
919
+ "application/x-netcdf"
920
+ // 'application/octet-stream'
921
+ ],
680
922
  category: "image",
681
923
  options: {
682
924
  netcdf: {
@@ -702,7 +944,7 @@ var __exports__ = (() => {
702
944
  data: variables
703
945
  };
704
946
  }
705
- return __toCommonJS(src_exports);
947
+ return __toCommonJS(bundle_exports);
706
948
  })();
707
949
  return __exports__;
708
950
  });
@@ -0,0 +1,10 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if (typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if (typeof define === 'function' && define.amd) define([], factory);
5
+ else if (typeof exports === 'object') exports['loaders'] = factory();
6
+ else root['loaders'] = factory();})(globalThis, function () {
7
+ "use strict";var __exports__=(()=>{var H=Object.create;var g=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var M=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),G=(e,t)=>{for(var r in t)g(e,r,{get:t[r],enumerable:!0})},y=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of $(t))!z.call(e,n)&&n!==r&&g(e,n,{get:()=>t[n],enumerable:!(i=V(t,n))||i.enumerable});return e},E=(e,t,r)=>(y(e,t,"default"),r&&y(r,t,"default")),J=(e,t,r)=>(r=e!=null?H(Y(e)):{},y(t||!e||!e.__esModule?g(r,"default",{value:e,enumerable:!0}):r,e)),j=e=>y(g({},"__esModule",{value:!0}),e);var F=M((st,T)=>{T.exports=globalThis.loaders});var p={};G(p,{NetCDFLoader:()=>k,NetCDFReader:()=>u});E(p,J(F(),1));var f=class{constructor(t=8192,r={}){this.textDecoder=new TextDecoder,this.textEncoder=new TextEncoder;let i=!1;typeof t=="number"?t=new ArrayBuffer(t):(i=!0,this.lastWrittenByte=t.byteLength);let n=r.offset?r.offset>>>0:0,a=t.byteLength-n,o=n;(ArrayBuffer.isView(t)||t instanceof f)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+n),t=t.buffer),i?this.lastWrittenByte=a:this.lastWrittenByte=0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}available(t=1){return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t=1){return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){let t=this._marks.pop();if(t===void 0)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t=1){if(!this.available(t)){let i=(this.offset+t)*2,n=new Uint8Array(i);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=this.byteLength=i,this._data=new DataView(this.buffer)}return this}readBoolean(){return this.readUint8()!==0}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t=1){let r=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=this.readByte();return r}readInt16(){let t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){let t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){let t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){let t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){let t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){let t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t=1){let r="";for(let i=0;i<t;i++)r+=this.readChar();return r}readUtf8(t=1){return this.textDecoder.decode(this.readBytes(t))}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let r=0;r<t.length;r++)this._data.setUint8(this.offset++,t[r]);return this._updateLastWrittenByte(),this}writeInt16(t){return this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(t){return this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(t){return this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(t){return this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(t){return this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(t){return this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(t){return this.writeUint8(t.charCodeAt(0))}writeChars(t){for(let r=0;r<t.length;r++)this.writeUint8(t.charCodeAt(r));return this}writeUtf8(t){let r=this.textEncoder.encode(t);return this.writeBytes(r)}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this.lastWrittenByte)}_updateLastWrittenByte(){this.offset>this.lastWrittenByte&&(this.lastWrittenByte=this.offset)}};var s={BYTE:1,CHAR:2,SHORT:3,INT:4,FLOAT:5,DOUBLE:6};function c(e,t,r){switch(t){case s.BYTE:return e.readBytes(r);case s.CHAR:return P(e.readChars(r));case s.SHORT:return b(r,e.readInt16.bind(e));case s.INT:return b(r,e.readInt32.bind(e));case s.FLOAT:return b(r,e.readFloat32.bind(e));case s.DOUBLE:return b(r,e.readFloat64.bind(e));default:throw new Error(`NetCDF: non valid type ${t}`)}}function N(e){switch(Number(e)){case s.BYTE:return"byte";case s.CHAR:return"char";case s.SHORT:return"short";case s.INT:return"int";case s.FLOAT:return"float";case s.DOUBLE:return"double";default:return"undefined"}}function L(e){switch(Number(e)){case s.BYTE:return 1;case s.CHAR:return 1;case s.SHORT:return 2;case s.INT:return 4;case s.FLOAT:return 4;case s.DOUBLE:return 8;default:return-1}}function D(e){switch(String(e)){case"byte":return s.BYTE;case"char":return s.CHAR;case"short":return s.SHORT;case"int":return s.INT;case"float":return s.FLOAT;case"double":return s.DOUBLE;default:return-1}}function b(e,t){if(e!==1){let r=new Array(e);for(let i=0;i<e;i++)r[i]=t();return r}return t()}function P(e){return e.charCodeAt(e.length-1)===0?e.substring(0,e.length-1):e}var l=0,Z=10,q=11,K=12,Q=0;function I(e,t){let r=e.readUint32(),i=X(e),n=x(e),a=tt(e,i.recordId,t);return{version:t,recordDimension:{length:r,id:i.recordId,name:i.recordName,recordStep:a.recordStep},dimensions:i.dimensions,variables:a.variables,attributes:n}}function X(e){let t=e.readUint32();if(t===l){if(e.readUint32()!==l)throw new Error("NetCDF: wrong empty tag for list of dimensions");return{recordId:0,recordName:"",dimensions:[]}}if(t!==Z)throw new Error("NetCDF: wrong tag for list of dimensions");let r=e.readUint32(),i=new Array(r),n,a;for(let o=0;o<r;o++){let h=B(e),d=e.readUint32();d===Q&&(n=o,a=h),i[o]={name:h,size:d}}return{dimensions:i,recordId:n,recordName:a}}function x(e){let t=e.readUint32();if(t===l){if(e.readUint32()!==l)throw new Error("NetCDF: wrong empty tag for list of attributes");return[]}if(t!==K)throw new Error("NetCDF: wrong tag for list of attributes");let r=e.readUint32(),i=new Array(r);for(let n=0;n<r;n++){let a=B(e),o=e.readUint32();if(o<1||o>6)throw new Error(`NetCDF: non valid type ${o}`);let h=e.readUint32(),d=c(e,o,h);O(e),i[n]={name:a,type:N(o),value:d}}return i}function tt(e,t,r){let i=e.readUint32(),n=0;if(i===l){if(e.readUint32()!==l)throw new Error("NetCDF: wrong empty tag for list of variables");return{recordStep:n,variables:[]}}if(i!==q)throw new Error("NetCDF: wrong tag for list of variables");let a=e.readUint32(),o=new Array(a);for(let h=0;h<a;h++){let d=B(e),m=e.readUint32(),U=new Array(m);for(let A=0;A<m;A++)U[A]=e.readUint32();let W=x(e),w=e.readUint32();if(w<1&&w>6)throw new Error(`NetCDF: non valid type ${w}`);let C=e.readUint32(),v=e.readUint32();if(r===2){if(v>0)throw new Error("NetCDF: offsets larger than 4GB not supported");v=e.readUint32()}let _=!1;typeof t<"u"&&U[0]===t&&(n+=C,_=!0),o[h]={name:d,dimensions:U,attributes:W,type:N(w),size:C,offset:v,record:_}}return{variables:o,recordStep:n}}function B(e){let t=e.readUint32(),r=e.readChars(t);return O(e),r}function O(e){e.offset%4!==0&&e.skip(4-e.offset%4)}function S(e,t){let r=D(t.type),i=t.size/L(r),n=new Array(i);for(let a=0;a<i;a++)n[a]=c(e,r,1);return n}function R(e,t,r){let i=D(t.type),n=t.size?t.size/L(i):1,a=r.length,o=new Array(a),h=r.recordStep;for(let d=0;d<a;d++){let m=e.offset;o[d]=c(e,i,n),e.seek(m+h)}return o}var u=class{constructor(t){let r=new f(t);r.setBigEndian();let i=r.readChars(3);if(i!=="CDF")throw new Error(`NetCDF: file should start with 'CDF', found ${i}`);let n=r.readByte();if(n>2)throw new Error(`NetCDF: unsupported version ${n}`);this.header=I(r,n),this.buffer=r}get version(){return this.header.version===1?"classic format":"64-bit offset format"}get recordDimension(){return this.header.recordDimension}get dimensions(){return this.header.dimensions}get attributes(){return this.header.attributes}get variables(){return this.header.variables}attributeExists(t){return this.attributes.find(i=>i.name===t)!==void 0}getAttribute(t){let r=this.attributes.find(i=>i.name===t);return r?r.value:null}dataVariableExists(t){return this.header.variables.find(function(i){return i.name===t})!==void 0}getDataVariableAsString(t){let r=this.getDataVariable(t);return r?r.join(""):null}getDataVariable(t){let r;if(typeof t=="string"?r=this.header.variables.find(function(i){return i.name===t}):r=t,r===void 0)throw new Error(`NetCDF: variable not found: ${t}`);return this.buffer.seek(r.offset),r.record?R(this.buffer,r,this.header.recordDimension):S(this.buffer,r)}toString(){let t=[];t.push("DIMENSIONS");for(let i of this.dimensions)t.push(` ${i.name.padEnd(30)} = size: ${i.size}`);t.push(""),t.push("GLOBAL ATTRIBUTES");for(let i of this.attributes)t.push(` ${i.name.padEnd(30)} = ${i.value}`);let r=JSON.parse(JSON.stringify(this.variables));t.push(""),t.push("VARIABLES:");for(let i of r){i.value=this.getDataVariable(i);let n=JSON.stringify(i.value);n.length>50&&(n=n.substring(0,50)),isNaN(i.value.length)||(n+=` (length: ${i.value.length})`),t.push(` ${i.name.padEnd(30)} = ${n}`)}return t.join(`
8
+ `)}};var et="4.2.0-alpha.4",rt={name:"NetCDF",id:"mvt",module:"mvt",version:et,extensions:["cdf","nc"],mimeTypes:["application/netcdf","application/x-netcdf"],category:"image",options:{netcdf:{loadVariables:!1}}},k={...rt,parse:async(e,t)=>it(e,t),binary:!0};function it(e,t){let r=new u(e),i={};if(t?.netcdf?.loadData)for(let n of r.variables)i[n.name]=r.getDataVariable(n);return{loaderData:r.header,data:i}}return j(p);})();
9
+ return __exports__;
10
+ });
package/dist/index.cjs CHANGED
@@ -17,15 +17,15 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
20
+ // dist/index.js
21
+ var dist_exports = {};
22
+ __export(dist_exports, {
23
23
  NetCDFLoader: () => NetCDFLoader,
24
24
  NetCDFReader: () => NetCDFReader
25
25
  });
26
- module.exports = __toCommonJS(src_exports);
26
+ module.exports = __toCommonJS(dist_exports);
27
27
 
28
- // src/iobuffer/iobuffer.ts
28
+ // dist/iobuffer/iobuffer.js
29
29
  var DEFAULT_BYTE_LENGTH = 1024 * 8;
30
30
  var IOBuffer = class {
31
31
  /**
@@ -448,7 +448,7 @@ var IOBuffer = class {
448
448
  }
449
449
  };
450
450
 
451
- // src/netcdfjs/read-type.ts
451
+ // dist/netcdfjs/read-type.js
452
452
  var TYPES = {
453
453
  BYTE: 1,
454
454
  CHAR: 2,
@@ -546,7 +546,7 @@ function trimNull(value) {
546
546
  return value;
547
547
  }
548
548
 
549
- // src/netcdfjs/read-header.ts
549
+ // dist/netcdfjs/read-header.js
550
550
  var ZERO = 0;
551
551
  var NC_DIMENSION = 10;
552
552
  var NC_VARIABLE = 11;
@@ -709,7 +709,7 @@ function padding(buffer) {
709
709
  }
710
710
  }
711
711
 
712
- // src/netcdfjs/read-data.ts
712
+ // dist/netcdfjs/read-data.js
713
713
  function readNonRecord(buffer, variable) {
714
714
  const type = str2num(variable.type);
715
715
  const size = variable.size / num2bytes(type);
@@ -733,7 +733,7 @@ function readRecord(buffer, variable, recordDimension) {
733
733
  return data;
734
734
  }
735
735
 
736
- // src/netcdfjs/netcdf-reader.ts
736
+ // dist/netcdfjs/netcdf-reader.js
737
737
  var NetCDFReader = class {
738
738
  constructor(data) {
739
739
  const buffer = new IOBuffer(data);
@@ -878,8 +878,8 @@ var NetCDFReader = class {
878
878
  }
879
879
  };
880
880
 
881
- // src/netcdf-loader.ts
882
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
881
+ // dist/netcdf-loader.js
882
+ var VERSION = true ? "4.2.0-alpha.4" : "latest";
883
883
  var NetCDFWorkerLoader = {
884
884
  name: "NetCDF",
885
885
  id: "mvt",
@@ -917,3 +917,4 @@ function parseNetCDF(arrayBuffer, options) {
917
917
  data: variables
918
918
  };
919
919
  }
920
+ //# sourceMappingURL=index.cjs.map