@loaders.gl/loader-utils 4.3.4 → 4.4.0-alpha.10

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 (189) hide show
  1. package/README.md +8 -0
  2. package/dist/format-types.d.ts +24 -0
  3. package/dist/format-types.d.ts.map +1 -0
  4. package/dist/format-types.js +5 -0
  5. package/dist/format-types.js.map +1 -0
  6. package/dist/index.cjs +201 -307
  7. package/dist/index.cjs.map +4 -4
  8. package/dist/index.d.ts +16 -17
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +6 -9
  11. package/dist/index.js.map +1 -0
  12. package/dist/json-loader.js +2 -1
  13. package/dist/json-loader.js.map +1 -0
  14. package/dist/lib/binary-utils/array-buffer-utils.d.ts +2 -2
  15. package/dist/lib/binary-utils/array-buffer-utils.d.ts.map +1 -1
  16. package/dist/lib/binary-utils/array-buffer-utils.js +1 -0
  17. package/dist/lib/binary-utils/array-buffer-utils.js.map +1 -0
  18. package/dist/lib/binary-utils/dataview-copy-utils.js +1 -0
  19. package/dist/lib/binary-utils/dataview-copy-utils.js.map +1 -0
  20. package/dist/lib/binary-utils/get-first-characters.d.ts +1 -1
  21. package/dist/lib/binary-utils/get-first-characters.d.ts.map +1 -1
  22. package/dist/lib/binary-utils/get-first-characters.js +1 -0
  23. package/dist/lib/binary-utils/get-first-characters.js.map +1 -0
  24. package/dist/lib/binary-utils/memory-conversion-utils.d.ts +10 -4
  25. package/dist/lib/binary-utils/memory-conversion-utils.d.ts.map +1 -1
  26. package/dist/lib/binary-utils/memory-conversion-utils.js +40 -4
  27. package/dist/lib/binary-utils/memory-conversion-utils.js.map +1 -0
  28. package/dist/lib/binary-utils/memory-copy-utils.js +1 -0
  29. package/dist/lib/binary-utils/memory-copy-utils.js.map +1 -0
  30. package/dist/lib/env-utils/assert.js +1 -0
  31. package/dist/lib/env-utils/assert.js.map +1 -0
  32. package/dist/lib/env-utils/globals.js +1 -0
  33. package/dist/lib/env-utils/globals.js.map +1 -0
  34. package/dist/lib/file-provider/data-view-file.d.ts.map +1 -1
  35. package/dist/lib/file-provider/data-view-file.js +3 -1
  36. package/dist/lib/file-provider/data-view-file.js.map +1 -0
  37. package/dist/lib/file-provider/file-handle-file.js +1 -0
  38. package/dist/lib/file-provider/file-handle-file.js.map +1 -0
  39. package/dist/lib/file-provider/file-provider-interface.js +1 -0
  40. package/dist/lib/file-provider/file-provider-interface.js.map +1 -0
  41. package/dist/lib/file-provider/file-provider.js +1 -0
  42. package/dist/lib/file-provider/file-provider.js.map +1 -0
  43. package/dist/lib/files/blob-file.js +1 -0
  44. package/dist/lib/files/blob-file.js.map +1 -0
  45. package/dist/lib/files/file.js +1 -0
  46. package/dist/lib/files/file.js.map +1 -0
  47. package/dist/lib/files/http-file.js +1 -0
  48. package/dist/lib/files/http-file.js.map +1 -0
  49. package/dist/lib/files/node-file-facade.js +1 -0
  50. package/dist/lib/files/node-file-facade.js.map +1 -0
  51. package/dist/lib/files/sources.js +1 -0
  52. package/dist/lib/files/sources.js.map +1 -0
  53. package/dist/lib/filesystems/filesystem.js +1 -0
  54. package/dist/lib/filesystems/filesystem.js.map +1 -0
  55. package/dist/lib/filesystems/node-filesystem-facade.js +1 -0
  56. package/dist/lib/filesystems/node-filesystem-facade.js.map +1 -0
  57. package/dist/lib/iterators/async-iteration.d.ts +14 -14
  58. package/dist/lib/iterators/async-iteration.d.ts.map +1 -1
  59. package/dist/lib/iterators/async-iteration.js +68 -16
  60. package/dist/lib/iterators/async-iteration.js.map +1 -0
  61. package/dist/lib/iterators/text-iterators.js +2 -1
  62. package/dist/lib/iterators/text-iterators.js.map +1 -0
  63. package/dist/lib/javascript-utils/is-type.d.ts +59 -0
  64. package/dist/lib/javascript-utils/is-type.d.ts.map +1 -0
  65. package/dist/lib/javascript-utils/is-type.js +68 -0
  66. package/dist/lib/javascript-utils/is-type.js.map +1 -0
  67. package/dist/lib/log-utils/log.js +2 -1
  68. package/dist/lib/log-utils/log.js.map +1 -0
  69. package/dist/lib/module-utils/js-module-utils.js +1 -0
  70. package/dist/lib/module-utils/js-module-utils.js.map +1 -0
  71. package/dist/lib/node/buffer.browser.js +1 -0
  72. package/dist/lib/node/buffer.browser.js.map +1 -0
  73. package/dist/lib/node/buffer.js +1 -0
  74. package/dist/lib/node/buffer.js.map +1 -0
  75. package/dist/lib/node/fs.browser.js +1 -0
  76. package/dist/lib/node/fs.browser.js.map +1 -0
  77. package/dist/lib/node/promisify.js +1 -0
  78. package/dist/lib/node/promisify.js.map +1 -0
  79. package/dist/lib/node/stream.browser.js +1 -0
  80. package/dist/lib/node/stream.browser.js.map +1 -0
  81. package/dist/lib/node/stream.js +1 -0
  82. package/dist/lib/node/stream.js.map +1 -0
  83. package/dist/lib/option-utils/merge-options.d.ts +12 -0
  84. package/dist/lib/option-utils/merge-options.d.ts.map +1 -0
  85. package/dist/lib/option-utils/{merge-loader-options.js → merge-options.js} +5 -1
  86. package/dist/lib/option-utils/merge-options.js.map +1 -0
  87. package/dist/lib/parser-utils/parse-json.js +1 -0
  88. package/dist/lib/parser-utils/parse-json.js.map +1 -0
  89. package/dist/lib/path-utils/file-aliases.js +1 -0
  90. package/dist/lib/path-utils/file-aliases.js.map +1 -0
  91. package/dist/lib/path-utils/get-cwd.js +1 -0
  92. package/dist/lib/path-utils/get-cwd.js.map +1 -0
  93. package/dist/lib/path-utils/path.js +2 -1
  94. package/dist/lib/path-utils/path.js.map +1 -0
  95. package/dist/lib/request-utils/request-scheduler.d.ts +4 -0
  96. package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -1
  97. package/dist/lib/request-utils/request-scheduler.js +15 -0
  98. package/dist/lib/request-utils/request-scheduler.js.map +1 -0
  99. package/dist/lib/sources/data-source.d.ts +26 -14
  100. package/dist/lib/sources/data-source.d.ts.map +1 -1
  101. package/dist/lib/sources/data-source.js +32 -9
  102. package/dist/lib/sources/data-source.js.map +1 -0
  103. package/dist/lib/sources/image-source.d.ts +1 -4
  104. package/dist/lib/sources/image-source.d.ts.map +1 -1
  105. package/dist/lib/sources/image-source.js +3 -2
  106. package/dist/lib/sources/image-source.js.map +1 -0
  107. package/dist/lib/sources/image-tile-source.d.ts +2 -1
  108. package/dist/lib/sources/image-tile-source.d.ts.map +1 -1
  109. package/dist/lib/sources/image-tile-source.js +1 -0
  110. package/dist/lib/sources/image-tile-source.js.map +1 -0
  111. package/dist/lib/sources/tile-source-adapter.d.ts +3 -3
  112. package/dist/lib/sources/tile-source-adapter.d.ts.map +1 -1
  113. package/dist/lib/sources/tile-source-adapter.js +1 -1
  114. package/dist/lib/sources/tile-source-adapter.js.map +1 -0
  115. package/dist/lib/sources/tile-source.d.ts +3 -5
  116. package/dist/lib/sources/tile-source.d.ts.map +1 -1
  117. package/dist/lib/sources/tile-source.js +1 -0
  118. package/dist/lib/sources/tile-source.js.map +1 -0
  119. package/dist/lib/sources/utils/image-type.js +1 -0
  120. package/dist/lib/sources/utils/image-type.js.map +1 -0
  121. package/dist/lib/sources/utils/utils.js +2 -1
  122. package/dist/lib/sources/utils/utils.js.map +1 -0
  123. package/dist/lib/sources/vector-source.d.ts +2 -4
  124. package/dist/lib/sources/vector-source.d.ts.map +1 -1
  125. package/dist/lib/sources/vector-source.js +2 -2
  126. package/dist/lib/sources/vector-source.js.map +1 -0
  127. package/dist/lib/sources/vector-tile-source.d.ts +2 -2
  128. package/dist/lib/sources/vector-tile-source.d.ts.map +1 -1
  129. package/dist/lib/sources/vector-tile-source.js +1 -0
  130. package/dist/lib/sources/vector-tile-source.js.map +1 -0
  131. package/dist/lib/worker-loader-utils/create-loader-worker.js +5 -1
  132. package/dist/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
  133. package/dist/lib/worker-loader-utils/encode-with-worker.d.ts +1 -1
  134. package/dist/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -1
  135. package/dist/lib/worker-loader-utils/encode-with-worker.js +5 -2
  136. package/dist/lib/worker-loader-utils/encode-with-worker.js.map +1 -0
  137. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +1 -1
  138. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
  139. package/dist/lib/worker-loader-utils/parse-with-worker.js +6 -3
  140. package/dist/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
  141. package/dist/loader-types.d.ts +99 -74
  142. package/dist/loader-types.d.ts.map +1 -1
  143. package/dist/loader-types.js +1 -0
  144. package/dist/loader-types.js.map +1 -0
  145. package/dist/source-types.d.ts +20 -8
  146. package/dist/source-types.d.ts.map +1 -1
  147. package/dist/source-types.js +2 -0
  148. package/dist/source-types.js.map +1 -0
  149. package/dist/types.d.ts +9 -4
  150. package/dist/types.d.ts.map +1 -1
  151. package/dist/types.js +1 -0
  152. package/dist/types.js.map +1 -0
  153. package/dist/workers/json-worker.js +1 -0
  154. package/dist/workers/json-worker.js.map +1 -0
  155. package/dist/writer-types.d.ts +22 -15
  156. package/dist/writer-types.d.ts.map +1 -1
  157. package/dist/writer-types.js +1 -0
  158. package/dist/writer-types.js.map +1 -0
  159. package/package.json +4 -7
  160. package/src/format-types.ts +27 -0
  161. package/src/index.ts +51 -17
  162. package/src/lib/binary-utils/array-buffer-utils.ts +3 -3
  163. package/src/lib/binary-utils/get-first-characters.ts +1 -1
  164. package/src/lib/binary-utils/memory-conversion-utils.ts +58 -8
  165. package/src/lib/file-provider/data-view-file.ts +6 -1
  166. package/src/lib/iterators/async-iteration.ts +94 -19
  167. package/src/lib/iterators/text-iterators.ts +1 -1
  168. package/src/lib/javascript-utils/is-type.ts +130 -0
  169. package/src/lib/node/buffer.ts +1 -1
  170. package/src/lib/option-utils/{merge-loader-options.ts → merge-options.ts} +10 -6
  171. package/src/lib/path-utils/path.ts +1 -1
  172. package/src/lib/request-utils/request-scheduler.ts +15 -0
  173. package/src/lib/sources/data-source.ts +53 -19
  174. package/src/lib/sources/image-source.ts +2 -7
  175. package/src/lib/sources/image-tile-source.ts +2 -4
  176. package/src/lib/sources/tile-source-adapter.ts +4 -4
  177. package/src/lib/sources/tile-source.ts +3 -9
  178. package/src/lib/sources/utils/utils.ts +1 -1
  179. package/src/lib/sources/vector-source.ts +2 -6
  180. package/src/lib/sources/vector-tile-source.ts +2 -5
  181. package/src/lib/worker-loader-utils/create-loader-worker.ts +4 -1
  182. package/src/lib/worker-loader-utils/encode-with-worker.ts +5 -2
  183. package/src/lib/worker-loader-utils/parse-with-worker.ts +5 -3
  184. package/src/loader-types.ts +126 -98
  185. package/src/source-types.ts +35 -10
  186. package/src/types.ts +17 -9
  187. package/src/writer-types.ts +25 -20
  188. package/dist/lib/option-utils/merge-loader-options.d.ts +0 -9
  189. package/dist/lib/option-utils/merge-loader-options.d.ts.map +0 -1
package/dist/index.cjs CHANGED
@@ -27,16 +27,12 @@ var dist_exports = {};
27
27
  __export(dist_exports, {
28
28
  BlobFile: () => BlobFile,
29
29
  DataSource: () => DataSource,
30
- DataViewFile: () => DataViewFile,
31
- FileHandleFile: () => FileHandleFile,
32
- FileProvider: () => FileProvider,
33
30
  HttpFile: () => HttpFile,
34
31
  ImageSource: () => ImageSource,
35
32
  JSONLoader: () => JSONLoader,
36
33
  NodeFile: () => NodeFileFacade,
37
34
  NodeFilesystem: () => NodeFileSystemFacade,
38
35
  RequestScheduler: () => RequestScheduler,
39
- VectorSource: () => VectorSource,
40
36
  _addAliases: () => addAliases,
41
37
  assert: () => assert,
42
38
  canEncodeWithWorker: () => canEncodeWithWorker,
@@ -53,25 +49,44 @@ __export(dist_exports, {
53
49
  copyPaddedStringToDataView: () => copyPaddedStringToDataView,
54
50
  copyStringToDataView: () => copyStringToDataView,
55
51
  copyToArray: () => copyToArray,
52
+ copyToArrayBuffer: () => copyToArrayBuffer2,
56
53
  createLoaderWorker: () => createLoaderWorker,
57
54
  document: () => document_,
55
+ ensureArrayBuffer: () => ensureArrayBuffer,
58
56
  forEach: () => forEach,
59
57
  getFirstCharacters: () => getFirstCharacters,
60
58
  getJSModule: () => getJSModule,
61
59
  getJSModuleOrNull: () => getJSModuleOrNull,
62
60
  getMagicString: () => getMagicString,
63
61
  getPathPrefix: () => getPathPrefix,
62
+ getRequiredOptions: () => getRequiredOptions,
64
63
  global: () => global_,
64
+ isArrayBuffer: () => isArrayBuffer,
65
+ isArrayBufferLike: () => isArrayBufferLike,
66
+ isAsyncIterable: () => isAsyncIterable,
67
+ isBlob: () => isBlob,
65
68
  isBrowser: () => isBrowser,
66
69
  isBuffer: () => isBuffer,
67
- isFileProvider: () => isFileProvider,
70
+ isFile: () => isFile,
71
+ isIterable: () => isIterable,
72
+ isIterator: () => isIterator,
73
+ isObject: () => isObject,
74
+ isPromise: () => isPromise,
75
+ isPureObject: () => isPureObject,
76
+ isReadableDOMStream: () => isReadableDOMStream,
77
+ isReadableNodeStream: () => isReadableNodeStream,
78
+ isReadableStream: () => isReadableStream,
79
+ isResponse: () => isResponse,
68
80
  isWorker: () => isWorker,
81
+ isWritableDOMStream: () => isWritableDOMStream,
82
+ isWritableNodeStream: () => isWritableNodeStream,
83
+ isWritableStream: () => isWritableStream,
69
84
  log: () => log,
70
85
  makeLineIterator: () => makeLineIterator,
71
86
  makeNumberedLineIterator: () => makeNumberedLineIterator,
72
87
  makeTextDecoderIterator: () => makeTextDecoderIterator,
73
88
  makeTextEncoderIterator: () => makeTextEncoderIterator,
74
- mergeLoaderOptions: () => mergeLoaderOptions,
89
+ mergeOptions: () => mergeOptions,
75
90
  nodeVersion: () => nodeVersion,
76
91
  padStringToByteAlignment: () => padStringToByteAlignment,
77
92
  padToNBytes: () => padToNBytes,
@@ -90,6 +105,8 @@ __export(dist_exports, {
90
105
  sliceArrayBuffer: () => sliceArrayBuffer,
91
106
  stream: () => stream_browser_exports,
92
107
  toArrayBuffer: () => toArrayBuffer2,
108
+ toArrayBufferIterator: () => toArrayBufferIterator,
109
+ toArrayBufferView: () => toArrayBufferView,
93
110
  toBuffer: () => toBuffer2,
94
111
  window: () => window_
95
112
  });
@@ -140,7 +157,7 @@ var nodeVersion = matches && parseFloat(matches[1]) || 0;
140
157
 
141
158
  // dist/lib/log-utils/log.js
142
159
  var import_log = require("@probe.gl/log");
143
- var VERSION = true ? "4.3.3" : "latest";
160
+ var VERSION = true ? "4.4.0-alpha.10" : "latest";
144
161
  var version = VERSION[0] >= "0" && VERSION[0] <= "9" ? `v${VERSION}` : "";
145
162
  function createLog() {
146
163
  const log2 = new import_log.Log({ id: "loaders.gl" });
@@ -153,8 +170,33 @@ function createLog() {
153
170
  }
154
171
  var log = createLog();
155
172
 
156
- // dist/lib/option-utils/merge-loader-options.js
157
- function mergeLoaderOptions(baseOptions, newOptions) {
173
+ // dist/lib/javascript-utils/is-type.js
174
+ var isBoolean = (value) => typeof value === "boolean";
175
+ var isFunction = (value) => typeof value === "function";
176
+ var isObject = (value) => value !== null && typeof value === "object";
177
+ var isPureObject = (value) => isObject(value) && value.constructor === {}.constructor;
178
+ var isArrayBuffer = (value) => typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer;
179
+ var isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
180
+ var isArrayBufferLike = (value) => isObject(value) && typeof value.byteLength === "number" && typeof value.slice === "function";
181
+ var isPromise = (value) => isObject(value) && "then" in value && isFunction(value.then);
182
+ var isIterable = (value) => Boolean(value) && isFunction(value[Symbol.iterator]);
183
+ var isAsyncIterable = (value) => Boolean(value) && isFunction(value[Symbol.asyncIterator]);
184
+ var isIterator = (value) => Boolean(value) && isFunction(value.next);
185
+ var isResponse = (value) => typeof Response !== "undefined" && value instanceof Response || isObject(value) && isFunction(value.arrayBuffer) && isFunction(value.text) && isFunction(value.json);
186
+ var isFile = (value) => typeof File !== "undefined" && value instanceof File;
187
+ var isBlob = (value) => typeof Blob !== "undefined" && value instanceof Blob;
188
+ var isWritableDOMStream = (value) => isObject(value) && isFunction(value.abort) && isFunction(value.getWriter);
189
+ var isReadableDOMStream = (value) => typeof ReadableStream !== "undefined" && value instanceof ReadableStream || isObject(value) && isFunction(value.tee) && isFunction(value.cancel) && isFunction(value.getReader);
190
+ var isWritableNodeStream = (value) => isObject(value) && isFunction(value.end) && isFunction(value.write) && isBoolean(value.writable);
191
+ var isReadableNodeStream = (value) => isObject(value) && isFunction(value.read) && isFunction(value.pipe) && isBoolean(value.readable);
192
+ var isReadableStream = (value) => isReadableDOMStream(value) || isReadableNodeStream(value);
193
+ var isWritableStream = (value) => isWritableDOMStream(value) || isWritableNodeStream(value);
194
+
195
+ // dist/lib/option-utils/merge-options.js
196
+ function getRequiredOptions(options) {
197
+ return options;
198
+ }
199
+ function mergeOptions(baseOptions, newOptions) {
158
200
  return mergeOptionsRecursively(baseOptions || {}, newOptions);
159
201
  }
160
202
  function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
@@ -271,7 +313,10 @@ async function parseData({ loader, arrayBuffer, options, context }) {
271
313
  options = {
272
314
  ...options,
273
315
  modules: loader && loader.options && loader.options.modules || {},
274
- worker: false
316
+ core: {
317
+ ...options.core,
318
+ worker: false
319
+ }
275
320
  };
276
321
  return await parser(data, { ...options }, context, loader);
277
322
  }
@@ -279,18 +324,21 @@ async function parseData({ loader, arrayBuffer, options, context }) {
279
324
  // dist/lib/worker-loader-utils/parse-with-worker.js
280
325
  var import_worker_utils2 = require("@loaders.gl/worker-utils");
281
326
  function canParseWithWorker(loader, options) {
327
+ var _a, _b;
282
328
  if (!import_worker_utils2.WorkerFarm.isSupported()) {
283
329
  return false;
284
330
  }
285
- if (!import_worker_utils2.isBrowser && !(options == null ? void 0 : options._nodeWorkers)) {
331
+ const nodeWorkers = (options == null ? void 0 : options._nodeWorkers) ?? ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._nodeWorkers);
332
+ if (!import_worker_utils2.isBrowser && !nodeWorkers) {
286
333
  return false;
287
334
  }
288
- return loader.worker && (options == null ? void 0 : options.worker);
335
+ const useWorkers = (options == null ? void 0 : options.worker) ?? ((_b = options == null ? void 0 : options.core) == null ? void 0 : _b.worker);
336
+ return Boolean(loader.worker && useWorkers);
289
337
  }
290
338
  async function parseWithWorker(loader, data, options, context, parseOnMainThread2) {
291
339
  const name = loader.id;
292
340
  const url = (0, import_worker_utils2.getWorkerURL)(loader, options);
293
- const workerFarm = import_worker_utils2.WorkerFarm.getWorkerFarm(options);
341
+ const workerFarm = import_worker_utils2.WorkerFarm.getWorkerFarm(options == null ? void 0 : options.core);
294
342
  const workerPool = workerFarm.getWorkerPool({ name, url });
295
343
  options = JSON.parse(JSON.stringify(options));
296
344
  context = JSON.parse(JSON.stringify(context || {}));
@@ -335,13 +383,16 @@ async function onMessage(parseOnMainThread2, job, type, payload) {
335
383
  // dist/lib/worker-loader-utils/encode-with-worker.js
336
384
  var import_worker_utils3 = require("@loaders.gl/worker-utils");
337
385
  function canEncodeWithWorker(writer, options) {
386
+ var _a, _b;
338
387
  if (!import_worker_utils3.WorkerFarm.isSupported()) {
339
388
  return false;
340
389
  }
341
- if (!isBrowser && !(options == null ? void 0 : options._nodeWorkers)) {
390
+ const nodeWorkers = (options == null ? void 0 : options._nodeWorkers) ?? ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._nodeWorkers);
391
+ const useWorkers = (options == null ? void 0 : options.worker) ?? ((_b = options == null ? void 0 : options.core) == null ? void 0 : _b.worker);
392
+ if (!isBrowser && !nodeWorkers) {
342
393
  return false;
343
394
  }
344
- return writer.worker && (options == null ? void 0 : options.worker);
395
+ return Boolean(writer.worker && useWorkers);
345
396
  }
346
397
 
347
398
  // dist/lib/binary-utils/get-first-characters.js
@@ -510,7 +561,7 @@ async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
510
561
  async function* makeTextEncoderIterator(textIterator) {
511
562
  const textEncoder = new TextEncoder();
512
563
  for await (const text of textIterator) {
513
- yield typeof text === "string" ? textEncoder.encode(text) : text;
564
+ yield typeof text === "string" ? textEncoder.encode(text).buffer : text;
514
565
  }
515
566
  }
516
567
  async function* makeLineIterator(textIterator) {
@@ -537,11 +588,14 @@ async function* makeNumberedLineIterator(lineIterator) {
537
588
  }
538
589
 
539
590
  // dist/lib/iterators/async-iteration.js
540
- async function forEach(iterator, visitor) {
591
+ async function forEach(iterable, visitor) {
592
+ const iterator = toAsyncIterator(iterable);
541
593
  while (true) {
542
594
  const { done, value } = await iterator.next();
543
595
  if (done) {
544
- iterator.return();
596
+ if (iterator.return) {
597
+ iterator.return();
598
+ }
545
599
  return;
546
600
  }
547
601
  const cancel = visitor(value);
@@ -553,10 +607,60 @@ async function forEach(iterator, visitor) {
553
607
  async function concatenateArrayBuffersAsync(asyncIterator) {
554
608
  const arrayBuffers = [];
555
609
  for await (const chunk of asyncIterator) {
556
- arrayBuffers.push(chunk);
610
+ arrayBuffers.push(copyToArrayBuffer(chunk));
557
611
  }
558
612
  return concatenateArrayBuffers(...arrayBuffers);
559
613
  }
614
+ async function* toArrayBufferIterator(asyncIterator) {
615
+ for await (const chunk of asyncIterator) {
616
+ yield copyToArrayBuffer(chunk);
617
+ }
618
+ }
619
+ function copyToArrayBuffer(chunk) {
620
+ if (chunk instanceof ArrayBuffer) {
621
+ return chunk;
622
+ }
623
+ if (ArrayBuffer.isView(chunk)) {
624
+ const { buffer, byteOffset, byteLength } = chunk;
625
+ return copyFromBuffer(buffer, byteOffset, byteLength);
626
+ }
627
+ return copyFromBuffer(chunk);
628
+ }
629
+ function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
630
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
631
+ const copy = new Uint8Array(view.length);
632
+ copy.set(view);
633
+ return copy.buffer;
634
+ }
635
+ function toAsyncIterator(iterable) {
636
+ if (typeof iterable[Symbol.asyncIterator] === "function") {
637
+ return iterable[Symbol.asyncIterator]();
638
+ }
639
+ if (typeof iterable[Symbol.iterator] === "function") {
640
+ const iterator = iterable[Symbol.iterator]();
641
+ return iteratorToAsyncIterator(iterator);
642
+ }
643
+ return iterable;
644
+ }
645
+ function iteratorToAsyncIterator(iterator) {
646
+ return {
647
+ next(value) {
648
+ return Promise.resolve(iterator.next(value));
649
+ },
650
+ return(value) {
651
+ if (typeof iterator.return === "function") {
652
+ return Promise.resolve(iterator.return(value));
653
+ }
654
+ return Promise.resolve({ done: true, value });
655
+ },
656
+ throw(error) {
657
+ if (typeof iterator.throw === "function") {
658
+ return Promise.resolve(iterator.throw(error));
659
+ }
660
+ return Promise.reject(error);
661
+ }
662
+ };
663
+ }
560
664
 
561
665
  // dist/lib/request-utils/request-scheduler.js
562
666
  var import_stats = require("@probe.gl/stats");
@@ -594,6 +698,20 @@ var RequestScheduler = class {
594
698
  this.stats.get(STAT_QUEUED_REQUESTS_EVER);
595
699
  this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
596
700
  }
701
+ /**
702
+ * Update scheduler props. Preserves active and queued requests.
703
+ */
704
+ setProps(props) {
705
+ if (props.throttleRequests !== void 0) {
706
+ this.props.throttleRequests = props.throttleRequests;
707
+ }
708
+ if (props.maxRequests !== void 0) {
709
+ this.props.maxRequests = props.maxRequests;
710
+ }
711
+ if (props.debounceTime !== void 0) {
712
+ this.props.debounceTime = props.debounceTime;
713
+ }
714
+ }
597
715
  /**
598
716
  * Called by an application that wants to issue a request, without having it deeply queued by the browser
599
717
  *
@@ -718,7 +836,7 @@ function resolvePath(filename2) {
718
836
  }
719
837
 
720
838
  // dist/json-loader.js
721
- var VERSION2 = true ? "4.3.3" : "latest";
839
+ var VERSION2 = true ? "4.4.0-alpha.10" : "latest";
722
840
  var JSONLoader = {
723
841
  dataType: null,
724
842
  batchType: null,
@@ -760,11 +878,15 @@ function toArrayBuffer2(data) {
760
878
  if (data instanceof ArrayBuffer) {
761
879
  return data;
762
880
  }
881
+ if (isSharedArrayBuffer(data)) {
882
+ return copyToArrayBuffer2(data);
883
+ }
763
884
  if (ArrayBuffer.isView(data)) {
885
+ const buffer = data.buffer;
764
886
  if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
765
- return data.buffer;
887
+ return buffer;
766
888
  }
767
- return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
889
+ return buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
768
890
  }
769
891
  if (typeof data === "string") {
770
892
  const text = data;
@@ -776,6 +898,31 @@ function toArrayBuffer2(data) {
776
898
  }
777
899
  throw new Error("toArrayBuffer");
778
900
  }
901
+ function ensureArrayBuffer(bufferSource) {
902
+ if (bufferSource instanceof ArrayBuffer) {
903
+ return bufferSource;
904
+ }
905
+ if (isSharedArrayBuffer(bufferSource)) {
906
+ return copyToArrayBuffer2(bufferSource);
907
+ }
908
+ const { buffer, byteOffset, byteLength } = bufferSource;
909
+ if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
910
+ return buffer;
911
+ }
912
+ return copyToArrayBuffer2(buffer, byteOffset, byteLength);
913
+ }
914
+ function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
915
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
916
+ const copy = new Uint8Array(view.length);
917
+ copy.set(view);
918
+ return copy.buffer;
919
+ }
920
+ function toArrayBufferView(data) {
921
+ if (ArrayBuffer.isView(data)) {
922
+ return data;
923
+ }
924
+ return new Uint8Array(data);
925
+ }
779
926
 
780
927
  // dist/lib/node/promisify.js
781
928
  function promisify1(fn) {
@@ -807,7 +954,7 @@ function getCWD() {
807
954
  // dist/lib/path-utils/path.js
808
955
  function filename(url) {
809
956
  const slashIndex = url ? url.lastIndexOf("/") : -1;
810
- return slashIndex >= 0 ? url.substr(slashIndex + 1) : "";
957
+ return slashIndex >= 0 ? url.substr(slashIndex + 1) : url;
811
958
  }
812
959
  function dirname(url) {
813
960
  const slashIndex = url ? url.lastIndexOf("/") : -1;
@@ -1129,288 +1276,31 @@ var NodeFileSystemFacade = class {
1129
1276
  }
1130
1277
  };
1131
1278
 
1132
- // dist/lib/file-provider/file-provider-interface.js
1133
- var isFileProvider = (fileProvider) => {
1134
- return (fileProvider == null ? void 0 : fileProvider.getUint8) && (fileProvider == null ? void 0 : fileProvider.slice) && (fileProvider == null ? void 0 : fileProvider.length);
1135
- };
1136
-
1137
- // dist/lib/file-provider/file-provider.js
1138
- var FileProvider = class {
1139
- /** The File object from which data is provided */
1140
- file;
1141
- size;
1142
- /** Create a new BrowserFile */
1143
- constructor(file, size) {
1144
- this.file = file;
1145
- this.size = BigInt(size);
1146
- }
1147
- static async create(file) {
1148
- var _a;
1149
- let size = 0n;
1150
- if (file.bigsize > 0n) {
1151
- size = file.bigsize;
1152
- } else if (file.size > 0) {
1153
- size = file.size;
1154
- } else {
1155
- const stats = await ((_a = file.stat) == null ? void 0 : _a.call(file));
1156
- size = (stats == null ? void 0 : stats.bigsize) ?? 0n;
1157
- }
1158
- return new FileProvider(file, size);
1159
- }
1160
- /**
1161
- * Truncates the file descriptor.
1162
- * @param length desired file lenght
1163
- */
1164
- async truncate(length) {
1165
- throw new Error("file loaded via range requests cannot be changed");
1166
- }
1167
- /**
1168
- * Append data to a file.
1169
- * @param buffer data to append
1170
- */
1171
- async append(buffer) {
1172
- throw new Error("file loaded via range requests cannot be changed");
1173
- }
1174
- /** Close file */
1175
- async destroy() {
1176
- throw new Error("file loaded via range requests cannot be changed");
1177
- }
1178
- /**
1179
- * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
1180
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1181
- */
1182
- async getUint8(offset) {
1183
- const arrayBuffer = await this.file.read(offset, 1);
1184
- const val = new Uint8Array(arrayBuffer).at(0);
1185
- if (val === void 0) {
1186
- throw new Error("something went wrong");
1187
- }
1188
- return val;
1189
- }
1190
- /**
1191
- * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
1192
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1193
- */
1194
- async getUint16(offset) {
1195
- const arrayBuffer = await this.file.read(offset, 2);
1196
- const val = new Uint16Array(arrayBuffer).at(0);
1197
- if (val === void 0) {
1198
- throw new Error("something went wrong");
1199
- }
1200
- return val;
1201
- }
1202
- /**
1203
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
1204
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1205
- */
1206
- async getUint32(offset) {
1207
- const arrayBuffer = await this.file.read(offset, 4);
1208
- const val = new Uint32Array(arrayBuffer).at(0);
1209
- if (val === void 0) {
1210
- throw new Error("something went wrong");
1211
- }
1212
- return val;
1213
- }
1214
- /**
1215
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
1216
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1217
- */
1218
- async getBigUint64(offset) {
1219
- const arrayBuffer = await this.file.read(offset, 8);
1220
- const val = new BigInt64Array(arrayBuffer).at(0);
1221
- if (val === void 0) {
1222
- throw new Error("something went wrong");
1223
- }
1224
- return val;
1225
- }
1226
- /**
1227
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
1228
- * @param startOffset The offset, in byte, from the start of the file where to start reading the data.
1229
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
1230
- */
1231
- async slice(startOffset, endOffset) {
1232
- const bigLength = BigInt(endOffset) - BigInt(startOffset);
1233
- if (bigLength > Number.MAX_SAFE_INTEGER) {
1234
- throw new Error("too big slice");
1235
- }
1236
- const length = Number(bigLength);
1237
- return await this.file.read(startOffset, length);
1238
- }
1239
- /**
1240
- * the length (in bytes) of the data.
1241
- */
1242
- get length() {
1243
- return this.size;
1244
- }
1245
- };
1246
-
1247
- // dist/lib/file-provider/file-handle-file.js
1248
- var FileHandleFile = class {
1249
- /** The FileHandle from which data is provided */
1250
- file;
1251
- /** Create a new FileHandleFile */
1252
- constructor(path, append = false) {
1253
- this.file = new NodeFileFacade(path, append ? "a+" : "r");
1254
- }
1255
- /**
1256
- * Truncates the file descriptor.
1257
- * @param length desired file lenght
1258
- */
1259
- async truncate(length) {
1260
- await this.file.truncate(length);
1261
- }
1262
- /**
1263
- * Append data to a file.
1264
- * @param buffer data to append
1265
- */
1266
- async append(buffer) {
1267
- await this.file.append(buffer);
1268
- }
1269
- /** Close file */
1270
- async destroy() {
1271
- await this.file.close();
1272
- }
1273
- /**
1274
- * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
1275
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1276
- */
1277
- async getUint8(offset) {
1278
- const arrayBuffer = await this.file.read(offset, 1);
1279
- const val = new Uint8Array(arrayBuffer).at(0);
1280
- if (val === void 0) {
1281
- throw new Error("something went wrong");
1282
- }
1283
- return val;
1284
- }
1285
- /**
1286
- * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
1287
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1288
- */
1289
- async getUint16(offset) {
1290
- const arrayBuffer = await this.file.read(offset, 2);
1291
- const val = new Uint16Array(arrayBuffer).at(0);
1292
- if (val === void 0) {
1293
- throw new Error("something went wrong");
1294
- }
1295
- return val;
1296
- }
1297
- /**
1298
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
1299
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1300
- */
1301
- async getUint32(offset) {
1302
- const arrayBuffer = await this.file.read(offset, 4);
1303
- const val = new Uint32Array(arrayBuffer).at(0);
1304
- if (val === void 0) {
1305
- throw new Error("something went wrong");
1306
- }
1307
- return val;
1308
- }
1309
- /**
1310
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
1311
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1312
- */
1313
- async getBigUint64(offset) {
1314
- const arrayBuffer = await this.file.read(offset, 8);
1315
- const val = new BigInt64Array(arrayBuffer).at(0);
1316
- if (val === void 0) {
1317
- throw new Error("something went wrong");
1318
- }
1319
- return val;
1320
- }
1321
- /**
1322
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
1323
- * @param startOffset The offset, in byte, from the start of the file where to start reading the data.
1324
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
1325
- */
1326
- async slice(startOffset, endOffset) {
1327
- const bigLength = endOffset - startOffset;
1328
- if (bigLength > Number.MAX_SAFE_INTEGER) {
1329
- throw new Error("too big slice");
1330
- }
1331
- const length = Number(bigLength);
1332
- return await this.file.read(startOffset, length);
1333
- }
1334
- /**
1335
- * the length (in bytes) of the data.
1336
- */
1337
- get length() {
1338
- return this.file.bigsize;
1339
- }
1340
- };
1341
-
1342
- // dist/lib/file-provider/data-view-file.js
1343
- var toNumber = (bigint) => {
1344
- if (bigint > Number.MAX_SAFE_INTEGER) {
1345
- throw new Error("Offset is out of bounds");
1346
- }
1347
- return Number(bigint);
1348
- };
1349
- var DataViewFile = class {
1350
- /** The DataView from which data is provided */
1351
- file;
1352
- constructor(file) {
1353
- this.file = file;
1354
- }
1355
- async destroy() {
1356
- }
1357
- /**
1358
- * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
1359
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1360
- */
1361
- async getUint8(offset) {
1362
- return this.file.getUint8(toNumber(offset));
1363
- }
1364
- /**
1365
- * Gets an unsigned 16-bit intege at the specified byte offset from the start of the file.
1366
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1367
- */
1368
- async getUint16(offset) {
1369
- return this.file.getUint16(toNumber(offset), true);
1370
- }
1371
- /**
1372
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
1373
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1374
- */
1375
- async getUint32(offset) {
1376
- return this.file.getUint32(toNumber(offset), true);
1377
- }
1378
- /**
1379
- * Gets an unsigned 64-bit integer at the specified byte offset from the start of the file.
1380
- * @param offset The offset, in bytes, from the start of the file where to read the data.
1381
- */
1382
- async getBigUint64(offset) {
1383
- return this.file.getBigUint64(toNumber(offset), true);
1384
- }
1385
- /**
1386
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
1387
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
1388
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
1389
- */
1390
- async slice(startOffset, endOffset) {
1391
- return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));
1392
- }
1393
- /** the length (in bytes) of the data. */
1394
- get length() {
1395
- return BigInt(this.file.byteLength);
1396
- }
1397
- };
1398
-
1399
1279
  // dist/lib/sources/data-source.js
1400
- var DataSource = class {
1401
- /** A resolved fetch function extracted from loadOptions prop */
1402
- fetch;
1280
+ var _DataSource = class {
1281
+ optionsType;
1282
+ options;
1283
+ data;
1284
+ url;
1403
1285
  /** The actual load options, if calling a loaders.gl loader */
1404
1286
  loadOptions;
1287
+ /** A resolved fetch function extracted from loadOptions prop */
1288
+ fetch;
1405
1289
  _needsRefresh = true;
1406
- props;
1407
- constructor(props) {
1408
- this.props = { ...props };
1409
- this.loadOptions = { ...props.loadOptions };
1290
+ constructor(data, options, defaultOptions) {
1291
+ var _a;
1292
+ if (defaultOptions) {
1293
+ this.options = mergeOptions({ ...defaultOptions, core: _DataSource.defaultOptions }, options);
1294
+ } else {
1295
+ this.options = { ...options };
1296
+ }
1297
+ this.data = data;
1298
+ this.url = typeof data === "string" ? resolvePath(data) : "";
1299
+ this.loadOptions = { ...(_a = this.options.core) == null ? void 0 : _a.loadOptions };
1410
1300
  this.fetch = getFetchFunction(this.loadOptions);
1411
1301
  }
1412
- setProps(props) {
1413
- this.props = Object.assign(this.props, props);
1302
+ setProps(options) {
1303
+ this.options = Object.assign(this.options, options);
1414
1304
  this.setNeedsRefresh();
1415
1305
  }
1416
1306
  /** Mark this data source as needing a refresh (redraw) */
@@ -1429,8 +1319,18 @@ var DataSource = class {
1429
1319
  return needsRefresh;
1430
1320
  }
1431
1321
  };
1322
+ var DataSource = _DataSource;
1323
+ __publicField(DataSource, "defaultOptions", {
1324
+ core: {
1325
+ type: "auto",
1326
+ attributions: [],
1327
+ loadOptions: {},
1328
+ loaders: []
1329
+ }
1330
+ });
1432
1331
  function getFetchFunction(options) {
1433
- const fetchFunction = options == null ? void 0 : options.fetch;
1332
+ var _a;
1333
+ const fetchFunction = (_a = options == null ? void 0 : options.core) == null ? void 0 : _a.fetch;
1434
1334
  if (fetchFunction && typeof fetchFunction === "function") {
1435
1335
  return (url, fetchOptions2) => fetchFunction(url, fetchOptions2);
1436
1336
  }
@@ -1442,14 +1342,8 @@ function getFetchFunction(options) {
1442
1342
  }
1443
1343
 
1444
1344
  // dist/lib/sources/image-source.js
1445
- var ImageSource = class extends DataSource {
1345
+ var ImageSource = class {
1446
1346
  };
1447
1347
  __publicField(ImageSource, "type", "template");
1448
1348
  __publicField(ImageSource, "testURL", (url) => false);
1449
-
1450
- // dist/lib/sources/vector-source.js
1451
- var VectorSource = class extends DataSource {
1452
- };
1453
- __publicField(VectorSource, "type", "template");
1454
- __publicField(VectorSource, "testURL", (url) => false);
1455
1349
  //# sourceMappingURL=index.cjs.map