@loaders.gl/ply 4.4.0-alpha.2 → 4.4.0-alpha.9

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
@@ -12525,11 +12525,14 @@ return true;`);
12525
12525
  }
12526
12526
 
12527
12527
  // ../loader-utils/src/lib/iterators/async-iteration.ts
12528
- async function forEach(iterator, visitor) {
12528
+ async function forEach(iterable, visitor) {
12529
+ const iterator = toAsyncIterator(iterable);
12529
12530
  while (true) {
12530
12531
  const { done, value } = await iterator.next();
12531
12532
  if (done) {
12532
- iterator.return();
12533
+ if (iterator.return) {
12534
+ iterator.return();
12535
+ }
12533
12536
  return;
12534
12537
  }
12535
12538
  const cancel = visitor(value);
@@ -12538,11 +12541,61 @@ return true;`);
12538
12541
  }
12539
12542
  }
12540
12543
  }
12544
+ async function* toArrayBufferIterator(asyncIterator) {
12545
+ for await (const chunk of asyncIterator) {
12546
+ yield copyToArrayBuffer(chunk);
12547
+ }
12548
+ }
12549
+ function copyToArrayBuffer(chunk) {
12550
+ if (chunk instanceof ArrayBuffer) {
12551
+ return chunk;
12552
+ }
12553
+ if (ArrayBuffer.isView(chunk)) {
12554
+ const { buffer, byteOffset, byteLength } = chunk;
12555
+ return copyFromBuffer(buffer, byteOffset, byteLength);
12556
+ }
12557
+ return copyFromBuffer(chunk);
12558
+ }
12559
+ function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
12560
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
12561
+ const copy = new Uint8Array(view.length);
12562
+ copy.set(view);
12563
+ return copy.buffer;
12564
+ }
12565
+ function toAsyncIterator(iterable) {
12566
+ if (typeof iterable[Symbol.asyncIterator] === "function") {
12567
+ return iterable[Symbol.asyncIterator]();
12568
+ }
12569
+ if (typeof iterable[Symbol.iterator] === "function") {
12570
+ const iterator = iterable[Symbol.iterator]();
12571
+ return iteratorToAsyncIterator(iterator);
12572
+ }
12573
+ return iterable;
12574
+ }
12575
+ function iteratorToAsyncIterator(iterator) {
12576
+ return {
12577
+ next(value) {
12578
+ return Promise.resolve(iterator.next(value));
12579
+ },
12580
+ return(value) {
12581
+ if (typeof iterator.return === "function") {
12582
+ return Promise.resolve(iterator.return(value));
12583
+ }
12584
+ return Promise.resolve({ done: true, value });
12585
+ },
12586
+ throw(error) {
12587
+ if (typeof iterator.throw === "function") {
12588
+ return Promise.resolve(iterator.throw(error));
12589
+ }
12590
+ return Promise.reject(error);
12591
+ }
12592
+ };
12593
+ }
12541
12594
 
12542
12595
  // src/lib/parse-ply-in-batches.ts
12543
12596
  var currentElement;
12544
12597
  async function* parsePLYInBatches(iterator, options) {
12545
- const lineIterator = makeLineIterator(makeTextDecoderIterator(iterator));
12598
+ const lineIterator = makeLineIterator(makeTextDecoderIterator(toArrayBufferIterator(iterator)));
12546
12599
  const header = await parsePLYHeader(lineIterator, options);
12547
12600
  let attributes;
12548
12601
  switch (header.format) {