@loaders.gl/pointclouds 5.0.0-beta.2 → 5.0.0-beta.4

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.
@@ -1,13 +1,49 @@
1
1
  "use strict";
2
2
  (() => {
3
3
  var __defProp = Object.defineProperty;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __esm = (fn, res, err) => function __init() {
6
+ if (err) throw err[0];
7
+ try {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ } catch (e) {
10
+ throw err = [e], e;
11
+ }
12
+ };
4
13
  var __export = (target, all) => {
5
14
  for (var name in all)
6
15
  __defProp(target, name, { get: all[name], enumerable: true });
7
16
  };
8
17
 
18
+ // ../core/src/worker-utils/lib/node/worker_threads-browser.ts
19
+ var worker_threads_browser_exports = {};
20
+ __export(worker_threads_browser_exports, {
21
+ NodeWorker: () => NodeWorker,
22
+ parentPort: () => parentPort2
23
+ });
24
+ var NodeWorker, parentPort2;
25
+ var init_worker_threads_browser = __esm({
26
+ "../core/src/worker-utils/lib/node/worker_threads-browser.ts"() {
27
+ "use strict";
28
+ NodeWorker = class {
29
+ /** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
30
+ constructor(...arguments_) {
31
+ const runtimeProcess = globalThis.process;
32
+ const WorkerConstructor = runtimeProcess?.getBuiltinModule?.("node:worker_threads").Worker;
33
+ if (WorkerConstructor) {
34
+ return new WorkerConstructor(...arguments_);
35
+ }
36
+ }
37
+ /** No-op browser fallback matching the native Worker API. */
38
+ terminate() {
39
+ }
40
+ };
41
+ parentPort2 = null;
42
+ }
43
+ });
44
+
9
45
  // ../../node_modules/@math.gl/core/dist/worker-utils/lib/node/worker_threads-browser.js
10
- var parentPort = null;
46
+ var parentPort = globalThis.process?.getBuiltinModule?.("node:worker_threads")?.parentPort ?? null;
11
47
 
12
48
  // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-utils/get-transfer-list.js
13
49
  function getTransferList(object, recursive = true, transfers) {
@@ -22,6 +58,9 @@
22
58
  else if (ArrayBuffer.isView(value)) {
23
59
  if (isTransferable(value.buffer))
24
60
  transfersSet.add(value.buffer);
61
+ } else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
62
+ visit(value.port1);
63
+ visit(value.port2);
25
64
  } else if (recursive && value instanceof Map) {
26
65
  for (const [key, item] of value) {
27
66
  visit(key);
@@ -73,16 +112,16 @@
73
112
  */
74
113
  static set onmessage(onMessage) {
75
114
  async function handleMessage(message) {
76
- const parentPort2 = await getParentPort();
77
- const { type, payload } = parentPort2 ? message : message.data;
115
+ const parentPort3 = await getParentPort();
116
+ const { type, payload } = parentPort3 ? message : message.data;
78
117
  onMessage(type, payload);
79
118
  }
80
- getParentPort().then((parentPort2) => {
81
- if (parentPort2) {
82
- parentPort2.on("message", (message) => {
119
+ getParentPort().then((parentPort3) => {
120
+ if (parentPort3) {
121
+ parentPort3.on("message", (message) => {
83
122
  handleMessage(message);
84
123
  });
85
- parentPort2.on("exit", () => console.debug("Node worker closing"));
124
+ parentPort3.on("exit", () => console.debug("Node worker closing"));
86
125
  } else {
87
126
  globalThis.onmessage = handleMessage;
88
127
  }
@@ -100,9 +139,9 @@
100
139
  };
101
140
  onMessageWrapperMap.set(onMessage, onMessageWrapper);
102
141
  }
103
- const parentPort2 = await getParentPort();
104
- if (parentPort2) {
105
- parentPort2.on("message", onMessageWrapper);
142
+ const parentPort3 = await getParentPort();
143
+ if (parentPort3) {
144
+ parentPort3.on("message", onMessageWrapper);
106
145
  } else {
107
146
  globalThis.addEventListener("message", onMessageWrapper);
108
147
  }
@@ -113,9 +152,9 @@
113
152
  if (!onMessageWrapper) {
114
153
  return;
115
154
  }
116
- const parentPort2 = await getParentPort();
117
- if (parentPort2) {
118
- parentPort2.off("message", onMessageWrapper);
155
+ const parentPort3 = await getParentPort();
156
+ if (parentPort3) {
157
+ parentPort3.off("message", onMessageWrapper);
119
158
  } else {
120
159
  globalThis.removeEventListener("message", onMessageWrapper);
121
160
  }
@@ -125,12 +164,12 @@
125
164
  * @param type
126
165
  * @param payload
127
166
  */
128
- static async postMessage(type, payload) {
167
+ static async postMessage(type, payload, copy = false) {
129
168
  const data = { source: "loaders.gl", type, payload };
130
- const transferList = getTransferList(payload);
131
- const parentPort2 = await getParentPort();
132
- if (parentPort2) {
133
- parentPort2.postMessage(data, transferList);
169
+ const transferList = copy ? [] : getTransferList(payload);
170
+ const parentPort3 = await getParentPort();
171
+ if (parentPort3) {
172
+ parentPort3.postMessage(data, transferList);
134
173
  } else {
135
174
  globalThis.postMessage(data, transferList);
136
175
  }
@@ -250,12 +289,19 @@
250
289
  }
251
290
  };
252
291
 
292
+ // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/validate-output-ownership.js
293
+ function validateOutputOwnership(ownership) {
294
+ if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
295
+ throw new Error("Invalid worker output ownership");
296
+ }
297
+ }
298
+
253
299
  // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/create-worker.js
254
300
  var requestId = 0;
255
301
  var activeController = null;
256
302
  var activeInputBatches = null;
257
303
  var activeOutputAcknowledgements = null;
258
- async function createWorker(process, processInBatches) {
304
+ async function createWorker(process2, processInBatches, preload) {
259
305
  if (!await WorkerBody.inWorkerThread()) {
260
306
  return;
261
307
  }
@@ -296,23 +342,26 @@
296
342
  }
297
343
  switch (type) {
298
344
  case "preload":
345
+ await preload?.();
299
346
  WorkerBody.postMessage("done", {});
300
347
  break;
301
348
  case "process":
302
349
  throwIfAborted();
303
- if (!process) {
350
+ validateOutputOwnership(payload.options?.["outputOwnership"]);
351
+ if (!process2) {
304
352
  throw new Error("Worker does not support atomic processing");
305
353
  }
306
- const result = await process(payload.input, payload.options || {}, jobContext, payload.context || {});
354
+ const result = await process2(payload.input, payload.options || {}, jobContext, payload.context || {});
307
355
  throwIfAborted();
308
356
  reporter?.finish();
309
357
  await WorkerBody.postMessage("done", {
310
358
  result,
311
359
  executionMs: performance.now() - startedAt
312
- });
360
+ }, payload.options?.["outputOwnership"] === "copy");
313
361
  break;
314
362
  case "process-in-batches":
315
363
  throwIfAborted();
364
+ validateOutputOwnership(payload.options?.["outputOwnership"]);
316
365
  if (!processInBatches) {
317
366
  throw new Error("Worker does not support batched processing");
318
367
  }
@@ -324,7 +373,7 @@
324
373
  const resultIterator = processInBatches(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
325
374
  for await (const batch of resultIterator) {
326
375
  throwIfAborted();
327
- await WorkerBody.postMessage("output-batch", { result: batch });
376
+ await WorkerBody.postMessage("output-batch", { result: batch }, payload.options?.["outputOwnership"] === "copy");
328
377
  await outputAcknowledgements.next();
329
378
  }
330
379
  throwIfAborted();
@@ -422,14 +471,14 @@
422
471
  });
423
472
  }
424
473
  function createProgressReporter() {
425
- let pending;
474
+ let pending2;
426
475
  let finished = false;
427
476
  let scheduled = false;
428
477
  const flush = () => {
429
478
  scheduled = false;
430
- if (pending) {
431
- WorkerBody.postMessage("progress", { progress: pending });
432
- pending = void 0;
479
+ if (pending2) {
480
+ WorkerBody.postMessage("progress", { progress: pending2 });
481
+ pending2 = void 0;
433
482
  }
434
483
  };
435
484
  return {
@@ -437,9 +486,9 @@
437
486
  report(progress) {
438
487
  if (finished)
439
488
  return;
440
- if (pending && pending.phase !== progress.phase)
489
+ if (pending2 && pending2.phase !== progress.phase)
441
490
  flush();
442
- pending = { ...progress };
491
+ pending2 = { ...progress };
443
492
  if (!scheduled) {
444
493
  scheduled = true;
445
494
  setTimeout(flush, 0);
@@ -448,7 +497,7 @@
448
497
  /** Flushes final progress and suppresses reports from stale callbacks. */
449
498
  finish(discard = false) {
450
499
  if (discard)
451
- pending = void 0;
500
+ pending2 = void 0;
452
501
  flush();
453
502
  finished = true;
454
503
  }
@@ -460,9 +509,276 @@
460
509
  var path = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
461
510
  var moduleUrl = path ? `file://${path.startsWith("/") ? "" : "/"}${encodeURI(path).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta.url;
462
511
 
512
+ // ../../node_modules/@math.gl/core/dist/tasks/task-preload.js
513
+ var pending = /* @__PURE__ */ new WeakMap();
514
+ var loaded = /* @__PURE__ */ new WeakSet();
515
+ function preloadTaskCode(task, signal) {
516
+ if (!task.preload)
517
+ return Promise.resolve();
518
+ let promise = pending.get(task);
519
+ if (!promise) {
520
+ promise = Promise.resolve().then(() => task.preload()).then(() => {
521
+ loaded.add(task);
522
+ });
523
+ pending.set(task, promise);
524
+ void promise.catch(() => pending.delete(task));
525
+ }
526
+ return withSignal(promise, signal);
527
+ }
528
+ function withSignal(operation, signal) {
529
+ if (!signal)
530
+ return operation;
531
+ return new Promise((resolve, reject) => {
532
+ const abort = () => {
533
+ signal.removeEventListener("abort", abort);
534
+ reject(signal.reason);
535
+ };
536
+ signal.addEventListener("abort", abort, { once: true });
537
+ if (signal.aborted)
538
+ abort();
539
+ operation.then((value) => {
540
+ signal.removeEventListener("abort", abort);
541
+ resolve(value);
542
+ }, (error) => {
543
+ signal.removeEventListener("abort", abort);
544
+ reject(error);
545
+ });
546
+ });
547
+ }
548
+
549
+ // ../../node_modules/@math.gl/core/dist/tasks/task-runtime.js
550
+ function assertPayload(value) {
551
+ if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
552
+ throw new TypeError("Task payloads must be plain objects with named fields");
553
+ }
554
+ }
555
+ function taskContext(state, context = {}) {
556
+ const signal = context.signal ?? new AbortController().signal;
557
+ return {
558
+ state,
559
+ signal,
560
+ throwIfAborted: () => {
561
+ signal.throwIfAborted();
562
+ context.throwIfAborted?.();
563
+ },
564
+ reportProgress: (progress) => context.reportProgress?.({
565
+ ...progress,
566
+ phase: progress.phase ?? "process",
567
+ unit: progress.unit ?? "items"
568
+ })
569
+ };
570
+ }
571
+ var TaskRuntime = class {
572
+ constructor(task) {
573
+ this.task = task;
574
+ this.initialized = false;
575
+ }
576
+ async initialize(input, context = {}) {
577
+ if (this.initialized)
578
+ throw new Error("Task is already initialized");
579
+ assertPayload(input);
580
+ await preloadTaskCode(this.task, context.signal);
581
+ context.signal?.throwIfAborted();
582
+ this.state = await this.task.initialize?.(input, taskContext(void 0, context));
583
+ this.initialized = true;
584
+ return {};
585
+ }
586
+ async destroy() {
587
+ if (this.initialized) {
588
+ this.initialized = false;
589
+ const state = this.state;
590
+ this.state = void 0;
591
+ if (this.task.initialize)
592
+ await this.task.destroy?.(state);
593
+ }
594
+ return {};
595
+ }
596
+ async process(input, options, context = {}) {
597
+ if (!this.initialized)
598
+ throw new Error("Task is not initialized");
599
+ if (!this.task.process)
600
+ throw new Error("Task has no atomic processor");
601
+ assertPayload(input);
602
+ const result = await this.task.process(input, options, taskContext(this.state, context));
603
+ assertPayload(result);
604
+ return result;
605
+ }
606
+ async *stream(inputs, options, context = {}) {
607
+ if (!this.initialized)
608
+ throw new Error("Task is not initialized");
609
+ if (!this.task.processInBatches)
610
+ throw new Error("Task has no streaming processor");
611
+ for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
612
+ assertPayload(output);
613
+ yield output;
614
+ }
615
+ }
616
+ };
617
+ async function initializeTaskWorker(task) {
618
+ if (!await WorkerBody.inWorkerThread())
619
+ throw new Error("initializeTaskWorker must run inside a worker");
620
+ if (installed)
621
+ throw new Error("A task is already installed in this worker");
622
+ installed = true;
623
+ const runtime = new TaskRuntime(task);
624
+ let streamOptions = {};
625
+ return createWorker(async (request, _options, context) => {
626
+ switch (request.operation) {
627
+ case "initialize":
628
+ return runtime.initialize(request.input, context);
629
+ case "destroy":
630
+ return runtime.destroy();
631
+ case "stream-options":
632
+ streamOptions = request.options;
633
+ return {};
634
+ case "process":
635
+ return runtime.process(request.input, request.options, context);
636
+ default:
637
+ throw new Error("Unknown task operation");
638
+ }
639
+ }, async function* (inputs, _options, context) {
640
+ async function* batches() {
641
+ for await (const input of inputs) {
642
+ assertPayload(input);
643
+ yield input;
644
+ }
645
+ }
646
+ try {
647
+ yield* runtime.stream(batches(), streamOptions, context);
648
+ } finally {
649
+ streamOptions = {};
650
+ }
651
+ }, () => preloadTaskCode(task));
652
+ }
653
+ var installed = false;
654
+
655
+ // ../core/src/worker-utils/lib/worker-api/task-runtime.ts
656
+ function normalizeTaskProgress(progress) {
657
+ return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
658
+ }
659
+ async function isWorkerThread() {
660
+ if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
661
+ return true;
662
+ if (typeof process !== "undefined" && process.versions?.node) {
663
+ const { isMainThread } = await Promise.resolve().then(() => (init_worker_threads_browser(), worker_threads_browser_exports));
664
+ return !isMainThread;
665
+ }
666
+ return false;
667
+ }
668
+ var initializeTaskWorker2 = initializeTaskWorker;
669
+
670
+ // ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
671
+ function getTransferList2(object, recursive = true, transfers) {
672
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
673
+ if (!object) {
674
+ } else if (isTransferable2(object)) {
675
+ transfersSet.add(object);
676
+ } else if (isTransferable2(object.buffer)) {
677
+ transfersSet.add(object.buffer);
678
+ } else if (ArrayBuffer.isView(object)) {
679
+ } else if (recursive && typeof object === "object") {
680
+ for (const key in object) {
681
+ getTransferList2(object[key], recursive, transfersSet);
682
+ }
683
+ }
684
+ return transfers === void 0 ? Array.from(transfersSet) : [];
685
+ }
686
+ function isTransferable2(object) {
687
+ if (!object) {
688
+ return false;
689
+ }
690
+ if (object instanceof ArrayBuffer) {
691
+ return true;
692
+ }
693
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
694
+ return true;
695
+ }
696
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
697
+ return true;
698
+ }
699
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
700
+ return true;
701
+ }
702
+ return false;
703
+ }
704
+
705
+ // ../core/src/worker-utils/lib/worker-api/create-worker.ts
706
+ async function createWorker2(process2, processInBatches) {
707
+ if (!await isWorkerThread()) return;
708
+ await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
709
+ }
710
+ function createWorkerTask(process2, processInBatches) {
711
+ return {
712
+ id: "loaders.gl",
713
+ initialize: (state) => state,
714
+ destroy: (state) => state.port?.close(),
715
+ process: async ({ value }, options, context) => {
716
+ if (!process2) throw new Error("Worker does not support atomic processing");
717
+ return { value: await process2(value, options, createContext(context), context.state.context) };
718
+ },
719
+ ...processInBatches ? {
720
+ processInBatches: async function* (inputs, options, context) {
721
+ async function* values() {
722
+ for await (const input of inputs) yield input.value;
723
+ }
724
+ for await (const value of processInBatches(
725
+ values(),
726
+ options,
727
+ createContext(context),
728
+ context.state.context
729
+ )) {
730
+ yield { value };
731
+ }
732
+ }
733
+ } : {}
734
+ };
735
+ }
736
+ function createContext(context) {
737
+ let requestIdentifier = 0;
738
+ const port = context.state.port;
739
+ return {
740
+ signal: context.signal,
741
+ throwIfAborted: () => context.throwIfAborted(),
742
+ reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
743
+ process: port ? (input, options = {}, jobContext = {}) => {
744
+ context.throwIfAborted();
745
+ const identifier = ++requestIdentifier;
746
+ return new Promise((resolve, reject) => {
747
+ const onMessage = (event) => {
748
+ if (event.data.identifier !== identifier) return;
749
+ cleanup();
750
+ if (event.data.error) {
751
+ const error = new Error(event.data.error.message);
752
+ error.name = event.data.error.name;
753
+ reject(error);
754
+ } else resolve(event.data.value);
755
+ };
756
+ const onAbort = () => {
757
+ cleanup();
758
+ reject(context.signal.reason);
759
+ };
760
+ const cleanup = () => {
761
+ port.removeEventListener("message", onMessage);
762
+ context.signal.removeEventListener("abort", onAbort);
763
+ };
764
+ port.addEventListener("message", onMessage);
765
+ context.signal.addEventListener("abort", onAbort, { once: true });
766
+ port.start();
767
+ try {
768
+ const request = { identifier, input, options, context: jobContext };
769
+ port.postMessage(request, getTransferList2(request));
770
+ } catch (error) {
771
+ cleanup();
772
+ reject(error);
773
+ }
774
+ });
775
+ } : void 0
776
+ };
777
+ }
778
+
463
779
  // ../core/src/loader-utils/lib/worker-loader-utils/create-loader-worker.ts
464
780
  async function createLoaderWorker(loader, selectLoader = () => loader) {
465
- await createWorker(
781
+ await createWorker2(
466
782
  (input, options, workerContext, loaderContext) => processLoaderWorkerData(
467
783
  selectLoader(options || {}),
468
784
  input,
@@ -12567,11 +12883,11 @@ return true;`);
12567
12883
  this._offsets = new OffsetsBufferBuilder(opts.type);
12568
12884
  }
12569
12885
  setValue(index, value) {
12570
- const pending = this._pending || (this._pending = /* @__PURE__ */ new Map());
12571
- const current = pending.get(index);
12886
+ const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
12887
+ const current = pending2.get(index);
12572
12888
  current && (this._pendingLength -= current.length);
12573
12889
  this._pendingLength += value instanceof MapRow ? value[kKeys].length : value.length;
12574
- pending.set(index, value);
12890
+ pending2.set(index, value);
12575
12891
  }
12576
12892
  setValid(index, isValid) {
12577
12893
  if (!super.setValid(index, isValid)) {
@@ -12594,12 +12910,12 @@ return true;`);
12594
12910
  return super.finish();
12595
12911
  }
12596
12912
  _flush() {
12597
- const pending = this._pending;
12913
+ const pending2 = this._pending;
12598
12914
  const pendingLength = this._pendingLength;
12599
12915
  this._pendingLength = 0;
12600
12916
  this._pending = void 0;
12601
- if (pending && pending.size > 0) {
12602
- this._flushPending(pending, pendingLength);
12917
+ if (pending2 && pending2.size > 0) {
12918
+ this._flushPending(pending2, pendingLength);
12603
12919
  }
12604
12920
  return this;
12605
12921
  }
@@ -15009,11 +15325,11 @@ return true;`);
15009
15325
  setValue(index, value) {
15010
15326
  return super.setValue(index, toUint8Array2(value));
15011
15327
  }
15012
- _flushPending(pending, pendingLength) {
15328
+ _flushPending(pending2, pendingLength) {
15013
15329
  const offsets = this._offsets;
15014
15330
  const data = this._values.reserve(pendingLength).buffer;
15015
15331
  let offset = 0;
15016
- for (const [index, value] of pending) {
15332
+ for (const [index, value] of pending2) {
15017
15333
  if (value === void 0) {
15018
15334
  offsets.set(index, 0);
15019
15335
  } else {
@@ -15042,11 +15358,11 @@ return true;`);
15042
15358
  setValue(index, value) {
15043
15359
  return super.setValue(index, toUint8Array2(value));
15044
15360
  }
15045
- _flushPending(pending, pendingLength) {
15361
+ _flushPending(pending2, pendingLength) {
15046
15362
  const offsets = this._offsets;
15047
15363
  const data = this._values.reserve(pendingLength).buffer;
15048
15364
  let offset = 0;
15049
- for (const [index, value] of pending) {
15365
+ for (const [index, value] of pending2) {
15050
15366
  if (value === void 0) {
15051
15367
  offsets.set(index, BigInt(0));
15052
15368
  } else {
@@ -15277,10 +15593,10 @@ return true;`);
15277
15593
  this.type = new List2(new Field2(name, child.type, true));
15278
15594
  return this.numChildren - 1;
15279
15595
  }
15280
- _flushPending(pending) {
15596
+ _flushPending(pending2) {
15281
15597
  const offsets = this._offsets;
15282
15598
  const [child] = this.children;
15283
- for (const [index, value] of pending) {
15599
+ for (const [index, value] of pending2) {
15284
15600
  if (typeof value === "undefined") {
15285
15601
  offsets.set(index, 0);
15286
15602
  } else {
@@ -15309,10 +15625,10 @@ return true;`);
15309
15625
  this.type = new LargeList2(new Field2(name, child.type, true));
15310
15626
  return this.numChildren - 1;
15311
15627
  }
15312
- _flushPending(pending) {
15628
+ _flushPending(pending2) {
15313
15629
  const offsets = this._offsets;
15314
15630
  const [child] = this.children;
15315
- for (const [index, value] of pending) {
15631
+ for (const [index, value] of pending2) {
15316
15632
  if (typeof value === "undefined") {
15317
15633
  offsets.set(index, BigInt(0));
15318
15634
  } else {
@@ -15334,11 +15650,11 @@ return true;`);
15334
15650
  }
15335
15651
  setValue(index, value) {
15336
15652
  const row = value instanceof Map ? value : new Map(Object.entries(value));
15337
- const pending = this._pending || (this._pending = /* @__PURE__ */ new Map());
15338
- const current = pending.get(index);
15653
+ const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
15654
+ const current = pending2.get(index);
15339
15655
  current && (this._pendingLength -= current.size);
15340
15656
  this._pendingLength += row.size;
15341
- pending.set(index, row);
15657
+ pending2.set(index, row);
15342
15658
  }
15343
15659
  addChild(child, name = `${this.numChildren}`) {
15344
15660
  if (this.numChildren > 0) {
@@ -15348,10 +15664,10 @@ return true;`);
15348
15664
  this.type = new Map_(new Field2(name, child.type, true), this.type.keysSorted);
15349
15665
  return this.numChildren - 1;
15350
15666
  }
15351
- _flushPending(pending) {
15667
+ _flushPending(pending2) {
15352
15668
  const offsets = this._offsets;
15353
15669
  const [child] = this.children;
15354
- for (const [index, value] of pending) {
15670
+ for (const [index, value] of pending2) {
15355
15671
  if (value === void 0) {
15356
15672
  offsets.set(index, 0);
15357
15673
  } else {
@@ -15514,7 +15830,7 @@ return true;`);
15514
15830
  return super.setValue(index, encodeUtf8(value));
15515
15831
  }
15516
15832
  // @ts-ignore
15517
- _flushPending(pending, pendingLength) {
15833
+ _flushPending(pending2, pendingLength) {
15518
15834
  }
15519
15835
  };
15520
15836
  Utf8Builder.prototype._flushPending = BinaryBuilder.prototype._flushPending;
@@ -15536,7 +15852,7 @@ return true;`);
15536
15852
  return super.setValue(index, encodeUtf8(value));
15537
15853
  }
15538
15854
  // @ts-ignore
15539
- _flushPending(pending, pendingLength) {
15855
+ _flushPending(pending2, pendingLength) {
15540
15856
  }
15541
15857
  };
15542
15858
  LargeUtf8Builder.prototype._flushPending = LargeBinaryBuilder.prototype._flushPending;
@@ -17734,8 +18050,8 @@ return true;`);
17734
18050
  return new JSONVectorLoader(body, header.nodes, header.buffers, this.dictionaries, this.schema.metadataVersion, header.variadicBufferCounts).visitMany(types);
17735
18051
  }
17736
18052
  };
17737
- function shouldAutoDestroy(self, options) {
17738
- return options && typeof options["autoDestroy"] === "boolean" ? options["autoDestroy"] : self["autoDestroy"];
18053
+ function shouldAutoDestroy(self2, options) {
18054
+ return options && typeof options["autoDestroy"] === "boolean" ? options["autoDestroy"] : self2["autoDestroy"];
17739
18055
  }
17740
18056
  function* readAllSync(source) {
17741
18057
  const reader = RecordBatchReader.from(source);
@@ -19949,7 +20265,7 @@ return true;`);
19949
20265
  };
19950
20266
 
19951
20267
  // src/las/las-loader-shared.ts
19952
- var VERSION = true ? "5.0.0-beta.2" : "latest";
20268
+ var VERSION = true ? "5.0.0-beta.4" : "latest";
19953
20269
  var DEFAULT_LAS_SHAPE = "arrow-table";
19954
20270
  function getLASShape(options) {
19955
20271
  return options?.las?.shape || DEFAULT_LAS_SHAPE;
@@ -20349,7 +20665,12 @@ return true;`);
20349
20665
  return attributes;
20350
20666
  }
20351
20667
  function readLASString(bytes, offset, length) {
20352
- return new TextDecoder().decode(bytes.subarray(offset, offset + length)).replace(/\0+$/, "").trim();
20668
+ const decoded = new TextDecoder().decode(bytes.subarray(offset, offset + length));
20669
+ let end = decoded.length;
20670
+ while (end > 0 && decoded[end - 1] === "\0") {
20671
+ end--;
20672
+ }
20673
+ return decoded.slice(0, end).trim();
20353
20674
  }
20354
20675
  function sanitizeExtraBytesName(name) {
20355
20676
  return name.trim().replace(/[^A-Za-z0-9_]+/g, "_");
@@ -20595,7 +20916,7 @@ return true;`);
20595
20916
  async function* parseLASInBatches(arrayBufferIterator, options = {}) {
20596
20917
  const batchSize = getBatchSize(options);
20597
20918
  const inputIterator = toAsyncIterator(arrayBufferIterator);
20598
- let pending = new Uint8Array(0);
20919
+ let pending2 = new Uint8Array(0);
20599
20920
  let absoluteOffset = 0;
20600
20921
  let header = null;
20601
20922
  let sourcePointIndex = 0;
@@ -20606,9 +20927,9 @@ return true;`);
20606
20927
  break;
20607
20928
  }
20608
20929
  const chunk = next.value;
20609
- pending = concatenateUint8Arrays2(pending, toUint8Array3(chunk));
20930
+ pending2 = concatenateUint8Arrays2(pending2, toUint8Array3(chunk));
20610
20931
  if (!header) {
20611
- header = tryParseHeader(pending, absoluteOffset);
20932
+ header = tryParseHeader(pending2, absoluteOffset);
20612
20933
  if (header) {
20613
20934
  header.totalToRead = header.pointsCount;
20614
20935
  }
@@ -20617,11 +20938,11 @@ return true;`);
20617
20938
  continue;
20618
20939
  }
20619
20940
  if (header.isCompressed) {
20620
- yield* parseLAZInBatches(pending, inputIterator, header, options);
20941
+ yield* parseLAZInBatches(pending2, inputIterator, header, options);
20621
20942
  return;
20622
20943
  }
20623
20944
  for (const batch of readAvailablePointBatches(
20624
- pending,
20945
+ pending2,
20625
20946
  absoluteOffset,
20626
20947
  header,
20627
20948
  sourcePointIndex,
@@ -20630,7 +20951,7 @@ return true;`);
20630
20951
  )) {
20631
20952
  sourcePointIndex = batch.sourcePointIndex;
20632
20953
  totalRead = batch.totalRead;
20633
- pending = batch.pending;
20954
+ pending2 = batch.pending;
20634
20955
  absoluteOffset = batch.absoluteOffset;
20635
20956
  yield parseLASArrowTableBatch(batch.arrayBuffer, batch.header, options);
20636
20957
  }
@@ -20814,11 +21135,11 @@ return true;`);
20814
21135
  );
20815
21136
  }
20816
21137
  async function* parseLAZInBatches(initialPending, inputIterator, header, options) {
20817
- const { pending, laszip } = await readLASZipVLRFromInput(initialPending, inputIterator, header);
21138
+ const { pending: pending2, laszip } = await readLASZipVLRFromInput(initialPending, inputIterator, header);
20818
21139
  validateTypeScriptLAZSupport(header, laszip);
20819
21140
  if (!laszip.variableChunks && header.pointsFormatId <= 5) {
20820
21141
  yield* parsePendingFixedLegacyLAZFileInArrowBatches(
20821
- pending,
21142
+ pending2,
20822
21143
  inputIterator,
20823
21144
  header,
20824
21145
  laszip,
@@ -20827,11 +21148,11 @@ return true;`);
20827
21148
  return;
20828
21149
  }
20829
21150
  if (!laszip.variableChunks && header.pointsFormatId >= 6 && header.pointsFormatId <= 10) {
20830
- yield* parsePendingLAZFileInArrowBatches(pending, inputIterator, header, laszip, options);
21151
+ yield* parsePendingLAZFileInArrowBatches(pending2, inputIterator, header, laszip, options);
20831
21152
  return;
20832
21153
  }
20833
21154
  for await (const batch of decodeLAZFileWithParsedVLRInBatches(
20834
- pending,
21155
+ pending2,
20835
21156
  inputIterator,
20836
21157
  header,
20837
21158
  laszip,
@@ -22032,10 +22353,10 @@ return true;`);
22032
22353
  }
22033
22354
  }
22034
22355
  async function readLASZipVLRFromInput(initialPending, inputIterator, header) {
22035
- let pending = initialPending;
22356
+ let pending2 = initialPending;
22036
22357
  while (true) {
22037
22358
  try {
22038
- return { pending, laszip: parseLASZipVLR(pending, header) };
22359
+ return { pending: pending2, laszip: parseLASZipVLR(pending2, header) };
22039
22360
  } catch (error) {
22040
22361
  if (!(error instanceof NeedsMoreData)) {
22041
22362
  throw error;
@@ -22045,7 +22366,7 @@ return true;`);
22045
22366
  if (next.done) {
22046
22367
  throw new NeedsMoreData("LASLoader: incomplete LASzip VLR");
22047
22368
  }
22048
- pending = concatenateUint8Arrays2(pending, toUint8Array3(next.value));
22369
+ pending2 = concatenateUint8Arrays2(pending2, toUint8Array3(next.value));
22049
22370
  }
22050
22371
  }
22051
22372
  async function collectRemainingInputBytes(initialPending, inputIterator) {
@@ -22969,10 +23290,10 @@ return true;`);
22969
23290
  [maximum[0], maximum[1], maximum[2]]
22970
23291
  ];
22971
23292
  }
22972
- function* readAvailablePointBatches(pending, absoluteOffset, header, sourcePointIndex, totalRead, batchSize) {
23293
+ function* readAvailablePointBatches(pending2, absoluteOffset, header, sourcePointIndex, totalRead, batchSize) {
22973
23294
  while (sourcePointIndex < header.pointsCount && totalRead < header.totalToRead) {
22974
23295
  const batch = readAvailableContiguousPointBatch(
22975
- pending,
23296
+ pending2,
22976
23297
  absoluteOffset,
22977
23298
  header,
22978
23299
  sourcePointIndex,
@@ -22982,25 +23303,25 @@ return true;`);
22982
23303
  if (!batch) {
22983
23304
  return;
22984
23305
  }
22985
- pending = batch.pending;
23306
+ pending2 = batch.pending;
22986
23307
  absoluteOffset = batch.absoluteOffset;
22987
23308
  sourcePointIndex = batch.sourcePointIndex;
22988
23309
  totalRead = batch.totalRead;
22989
23310
  yield batch;
22990
23311
  }
22991
23312
  }
22992
- function readAvailableContiguousPointBatch(pending, absoluteOffset, header, sourcePointIndex, totalRead, batchSize) {
23313
+ function readAvailableContiguousPointBatch(pending2, absoluteOffset, header, sourcePointIndex, totalRead, batchSize) {
22993
23314
  const pointRecordLength = header.pointsStructSize;
22994
23315
  const pointAbsoluteOffset = header.pointsOffset + sourcePointIndex * pointRecordLength;
22995
23316
  const pointPendingOffset = pointAbsoluteOffset - absoluteOffset;
22996
23317
  if (pointPendingOffset < 0) {
22997
23318
  throw new Error("LASLoader: invalid streaming point offset");
22998
23319
  }
22999
- if (pointPendingOffset + pointRecordLength > pending.byteLength) {
23320
+ if (pointPendingOffset + pointRecordLength > pending2.byteLength) {
23000
23321
  return null;
23001
23322
  }
23002
23323
  const availablePointCount = Math.floor(
23003
- (pending.byteLength - pointPendingOffset) / pointRecordLength
23324
+ (pending2.byteLength - pointPendingOffset) / pointRecordLength
23004
23325
  );
23005
23326
  const batchPointCount = Math.min(
23006
23327
  batchSize,
@@ -23015,38 +23336,38 @@ return true;`);
23015
23336
  totalRead += batchPointCount;
23016
23337
  const batchHeader = {
23017
23338
  ...header,
23018
- pointsOffset: pending.byteOffset + pointPendingOffset,
23339
+ pointsOffset: pending2.byteOffset + pointPendingOffset,
23019
23340
  pointsCount: batchPointCount,
23020
23341
  totalRead
23021
23342
  };
23022
23343
  const nextPointOffset = header.pointsOffset + sourcePointIndex * pointRecordLength;
23023
23344
  const discardByteCount = Math.max(
23024
23345
  0,
23025
- Math.min(pending.byteLength, nextPointOffset - absoluteOffset)
23346
+ Math.min(pending2.byteLength, nextPointOffset - absoluteOffset)
23026
23347
  );
23027
23348
  return {
23028
- arrayBuffer: pending.buffer,
23349
+ arrayBuffer: pending2.buffer,
23029
23350
  header: batchHeader,
23030
- pending: pending.subarray(discardByteCount),
23351
+ pending: pending2.subarray(discardByteCount),
23031
23352
  absoluteOffset: absoluteOffset + discardByteCount,
23032
23353
  sourcePointIndex,
23033
23354
  totalRead
23034
23355
  };
23035
23356
  }
23036
- function tryParseHeader(pending, absoluteOffset) {
23037
- if (absoluteOffset !== 0 || pending.byteLength < 227) {
23357
+ function tryParseHeader(pending2, absoluteOffset) {
23358
+ if (absoluteOffset !== 0 || pending2.byteLength < 227) {
23038
23359
  return null;
23039
23360
  }
23040
- const dataView = new DataView(pending.buffer, pending.byteOffset, pending.byteLength);
23361
+ const dataView = new DataView(pending2.buffer, pending2.byteOffset, pending2.byteLength);
23041
23362
  if (dataView.getUint32(0, true) !== LASF_SIGNATURE) {
23042
23363
  throw new Error("LASLoader: invalid LAS header");
23043
23364
  }
23044
23365
  const headerLength = dataView.getUint32(96, true);
23045
- if (pending.byteLength < Math.max(headerLength, 255)) {
23366
+ if (pending2.byteLength < Math.max(headerLength, 255)) {
23046
23367
  return null;
23047
23368
  }
23048
23369
  const header = parseLASHeader(
23049
- pending.buffer.slice(pending.byteOffset, pending.byteOffset + pending.byteLength)
23370
+ pending2.buffer.slice(pending2.byteOffset, pending2.byteOffset + pending2.byteLength)
23050
23371
  );
23051
23372
  return header;
23052
23373
  }