@loaders.gl/pointclouds 5.0.0-beta.2 → 5.0.0-beta.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.
Files changed (73) hide show
  1. package/LAS-README.md +1 -1
  2. package/PCD-README.md +1 -1
  3. package/PLY-README.md +1 -1
  4. package/README.md +1 -1
  5. package/dist/dist.dev.js +135 -91
  6. package/dist/dist.min.js +20 -20
  7. package/dist/las/las-loader-shared.cjs +1 -1
  8. package/dist/las/las-loader-shared.js +1 -1
  9. package/dist/las/las-loader-types.d.ts +2 -2
  10. package/dist/las/las-loader.cjs +4 -4
  11. package/dist/las/las-loader.cjs.map +2 -2
  12. package/dist/las/las-loader.d.ts +1 -1
  13. package/dist/las/las-loader.d.ts.map +1 -1
  14. package/dist/las/las-loader.js +1 -1
  15. package/dist/las/las-loader.js.map +1 -1
  16. package/dist/las/las-writer.cjs +1 -1
  17. package/dist/las/las-writer.js +1 -1
  18. package/dist/las/lib/las-extra-bytes.cjs +6 -1
  19. package/dist/las/lib/las-extra-bytes.cjs.map +2 -2
  20. package/dist/las/lib/las-extra-bytes.d.ts.map +1 -1
  21. package/dist/las/lib/las-extra-bytes.js +6 -4
  22. package/dist/las/lib/las-extra-bytes.js.map +1 -1
  23. package/dist/las-loader.cjs +4 -4
  24. package/dist/las-loader.cjs.map +2 -2
  25. package/dist/las-worker.js +704 -160
  26. package/dist/las-writer.cjs +1 -1
  27. package/dist/pcd/pcd-loader-types.cjs +3 -3
  28. package/dist/pcd/pcd-loader-types.cjs.map +2 -2
  29. package/dist/pcd/pcd-loader-types.d.ts +1 -1
  30. package/dist/pcd/pcd-loader-types.d.ts.map +1 -1
  31. package/dist/pcd/pcd-loader-types.js +2 -2
  32. package/dist/pcd/pcd-loader-types.js.map +1 -1
  33. package/dist/pcd/pcd-loader.cjs +4 -4
  34. package/dist/pcd/pcd-loader.cjs.map +2 -2
  35. package/dist/pcd/pcd-loader.d.ts +1 -1
  36. package/dist/pcd/pcd-loader.d.ts.map +1 -1
  37. package/dist/pcd/pcd-loader.js +1 -1
  38. package/dist/pcd/pcd-loader.js.map +1 -1
  39. package/dist/pcd/pcd-writer.cjs +1 -1
  40. package/dist/pcd/pcd-writer.js +1 -1
  41. package/dist/pcd-loader-types.cjs +3 -3
  42. package/dist/pcd-loader-types.cjs.map +2 -2
  43. package/dist/pcd-loader.cjs +4 -4
  44. package/dist/pcd-loader.cjs.map +2 -2
  45. package/dist/pcd-worker.js +984 -367
  46. package/dist/pcd-writer.cjs +1 -1
  47. package/dist/ply/ply-loader-types.cjs +3 -3
  48. package/dist/ply/ply-loader-types.cjs.map +2 -2
  49. package/dist/ply/ply-loader-types.d.ts +1 -1
  50. package/dist/ply/ply-loader-types.d.ts.map +1 -1
  51. package/dist/ply/ply-loader-types.js +2 -2
  52. package/dist/ply/ply-loader-types.js.map +1 -1
  53. package/dist/ply/ply-loader.cjs +4 -4
  54. package/dist/ply/ply-loader.cjs.map +2 -2
  55. package/dist/ply/ply-loader.d.ts +1 -1
  56. package/dist/ply/ply-loader.d.ts.map +1 -1
  57. package/dist/ply/ply-loader.js +1 -1
  58. package/dist/ply/ply-loader.js.map +1 -1
  59. package/dist/ply/ply-writer.cjs +1 -1
  60. package/dist/ply/ply-writer.js +1 -1
  61. package/dist/ply-loader-types.cjs +3 -3
  62. package/dist/ply-loader-types.cjs.map +2 -2
  63. package/dist/ply-loader.cjs +4 -4
  64. package/dist/ply-loader.cjs.map +2 -2
  65. package/dist/ply-worker.js +779 -162
  66. package/dist/ply-writer.cjs +1 -1
  67. package/package.json +4 -3
  68. package/src/las/las-loader.ts +1 -1
  69. package/src/las/lib/las-extra-bytes.ts +6 -4
  70. package/src/pcd/pcd-loader-types.ts +1 -1
  71. package/src/pcd/pcd-loader.ts +1 -1
  72. package/src/ply/ply-loader-types.ts +1 -1
  73. package/src/ply/ply-loader.ts +1 -1
@@ -1,15 +1,51 @@
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
 
9
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/node/worker_threads-browser.js
10
- var parentPort = null;
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
+
45
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/node/worker_threads-browser.js
46
+ var parentPort = globalThis.process?.getBuiltinModule?.("node:worker_threads")?.parentPort ?? null;
11
47
 
12
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-utils/get-transfer-list.js
48
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-transfer-list.js
13
49
  function getTransferList(object, recursive = true, transfers) {
14
50
  const transfersSet = transfers || /* @__PURE__ */ new Set();
15
51
  const seen = /* @__PURE__ */ new Set();
@@ -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);
@@ -57,7 +96,7 @@
57
96
  return false;
58
97
  }
59
98
 
60
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-farm/worker-body.js
99
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-body.js
61
100
  async function getParentPort() {
62
101
  return parentPort;
63
102
  }
@@ -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
  }
@@ -144,7 +183,7 @@
144
183
  return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
145
184
  }
146
185
 
147
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/async-queue/async-queue.js
186
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/async-queue/async-queue.js
148
187
  var AsyncQueue = class {
149
188
  constructor() {
150
189
  this._values = [];
@@ -211,7 +250,7 @@
211
250
  }
212
251
  };
213
252
 
214
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/shared-state.js
253
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/shared-state.js
215
254
  var SharedWorkerState = class {
216
255
  constructor(buffer) {
217
256
  if (typeof SharedArrayBuffer === "undefined" || !(buffer instanceof SharedArrayBuffer) || buffer.byteLength !== 16)
@@ -250,12 +289,19 @@
250
289
  }
251
290
  };
252
291
 
253
- // ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/create-worker.js
292
+ // ../../node_modules/@math.gl/tasks/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
+
299
+ // ../../node_modules/@math.gl/tasks/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,21 +497,516 @@
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
  }
455
504
  };
456
505
  }
457
506
 
458
- // ../../node_modules/@math.gl/core/dist/worker-utils/index.js
507
+ // ../../node_modules/@math.gl/tasks/dist/worker-utils/index.js
459
508
  var import_meta = {};
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/tasks/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/tasks/dist/tasks/task-channel.js
550
+ var TaskRequestError = class extends Error {
551
+ };
552
+ var TaskChannel = class {
553
+ constructor(options) {
554
+ this.options = options;
555
+ this.nextId = 1;
556
+ this.pending = /* @__PURE__ */ new Map();
557
+ this.incoming = /* @__PURE__ */ new Map();
558
+ }
559
+ /** Send a request without serializing other in-flight requests. */
560
+ request(operation, value, signal, transfer = []) {
561
+ if (this.failure)
562
+ return Promise.reject(this.failure.reason);
563
+ if (signal?.aborted)
564
+ return Promise.reject(signal.reason);
565
+ const id = this.nextId++;
566
+ return new Promise((resolve, reject) => {
567
+ const abort = () => {
568
+ const pending2 = this.pending.get(id);
569
+ if (!pending2)
570
+ return;
571
+ this.pending.delete(id);
572
+ pending2.cleanup();
573
+ reject(signal?.reason);
574
+ this.send({ source: "math.gl/tasks", kind: "cancel", id });
575
+ };
576
+ this.pending.set(id, {
577
+ resolve,
578
+ reject,
579
+ cleanup: () => signal?.removeEventListener("abort", abort)
580
+ });
581
+ signal?.addEventListener("abort", abort, { once: true });
582
+ this.send({ source: "math.gl/tasks", kind: "request", id, operation, value }, transfer);
583
+ });
584
+ }
585
+ /** Send a one-way notification. */
586
+ emit(operation, value, transfer = []) {
587
+ if (this.failure)
588
+ throw this.failure.reason;
589
+ this.send({ source: "math.gl/tasks", kind: "event", id: 0, operation, value }, transfer);
590
+ }
591
+ /** Dispatch a transport message; unrelated protocols are ignored. */
592
+ receive(message) {
593
+ if (this.failure || message?.source !== "math.gl/tasks")
594
+ return;
595
+ if (message.kind === "failure") {
596
+ const reason = new Error(message.error?.message ?? "Task channel failed");
597
+ this.close(reason);
598
+ this.options.onFailure?.(reason);
599
+ } else if (message.kind === "result" || message.kind === "error") {
600
+ const pending2 = this.pending.get(message.id);
601
+ if (!pending2)
602
+ return;
603
+ this.pending.delete(message.id);
604
+ pending2.cleanup();
605
+ if (message.kind === "result")
606
+ pending2.resolve(message.value);
607
+ else {
608
+ const error = new TaskRequestError(message.error?.message ?? "Task request failed");
609
+ error.name = message.error?.name ?? "Error";
610
+ pending2.reject(error);
611
+ }
612
+ } else if (message.kind === "cancel") {
613
+ this.incoming.get(message.id)?.abort(new DOMException("Task request cancelled", "AbortError"));
614
+ } else if (message.kind === "event") {
615
+ try {
616
+ this.options.handleEvent?.(message.operation, message.value);
617
+ } catch (error) {
618
+ this.fail(error);
619
+ }
620
+ } else if (message.kind === "request") {
621
+ if (this.incoming.has(message.id)) {
622
+ this.fail(new Error("Duplicate task request identifier"));
623
+ return;
624
+ }
625
+ const controller = new AbortController();
626
+ this.incoming.set(message.id, controller);
627
+ void Promise.resolve().then(() => {
628
+ controller.signal.throwIfAborted();
629
+ return this.options.handleRequest(message.operation, message.value, controller.signal);
630
+ }).then((value) => {
631
+ if (!controller.signal.aborted && !this.failure) {
632
+ this.send({ source: "math.gl/tasks", kind: "result", id: message.id, value }, this.options.getResultTransferList?.(value, message.value));
633
+ }
634
+ }).catch((reason) => {
635
+ if (!controller.signal.aborted && !this.failure) {
636
+ this.send({
637
+ source: "math.gl/tasks",
638
+ kind: "error",
639
+ id: message.id,
640
+ error: {
641
+ name: reason instanceof Error ? reason.name : "Error",
642
+ message: reason instanceof Error ? reason.message : String(reason)
643
+ }
644
+ });
645
+ }
646
+ }).finally(() => this.incoming.delete(message.id));
647
+ }
648
+ }
649
+ /** Reject all outstanding calls with a common cause and abort incoming callbacks. */
650
+ close(reason = new Error("Task channel closed")) {
651
+ if (this.failure)
652
+ return;
653
+ this.failure = { reason };
654
+ for (const pending2 of this.pending.values()) {
655
+ pending2.cleanup();
656
+ pending2.reject(reason);
657
+ }
658
+ this.pending.clear();
659
+ for (const controller of this.incoming.values())
660
+ controller.abort(reason);
661
+ this.incoming.clear();
662
+ }
663
+ send(message, transfer = []) {
664
+ if (this.failure)
665
+ return;
666
+ try {
667
+ this.options.send(message, transfer);
668
+ } catch (error) {
669
+ this.fail(error);
670
+ }
671
+ }
672
+ /** Invalidate the channel and notify the peer when the transport still works. */
673
+ fail(reason) {
674
+ if (this.failure)
675
+ return;
676
+ this.close(reason);
677
+ try {
678
+ this.options.send({
679
+ source: "math.gl/tasks",
680
+ kind: "failure",
681
+ id: 0,
682
+ error: {
683
+ name: reason instanceof Error ? reason.name : "Error",
684
+ message: reason instanceof Error ? reason.message : String(reason)
685
+ }
686
+ }, []);
687
+ } catch {
688
+ }
689
+ this.options.onFailure?.(reason);
690
+ }
691
+ };
692
+
693
+ // ../../node_modules/@math.gl/tasks/dist/tasks/task-runtime.js
694
+ function assertPayload(value) {
695
+ if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
696
+ throw new TypeError("Task payloads must be plain objects with named fields");
697
+ }
698
+ }
699
+ function clonePayload(value, ownership = "copy") {
700
+ assertPayload(value);
701
+ if (!["copy", "transfer", "share"].includes(ownership))
702
+ throw new TypeError("Invalid input ownership");
703
+ const transfer = getTransferList(value);
704
+ if (ownership === "share" && transfer.length)
705
+ throw new TypeError("Share requires shared storage");
706
+ return structuredClone(value, {
707
+ transfer: ownership === "transfer" ? transfer : []
708
+ });
709
+ }
710
+ function taskContext(state, context = {}) {
711
+ const signal = context.signal ?? new AbortController().signal;
712
+ return {
713
+ state,
714
+ signal,
715
+ requestHost: async (operation, payload, controls) => {
716
+ signal.throwIfAborted();
717
+ if (!context.requestHost)
718
+ throw new Error("No host request handler configured");
719
+ return context.requestHost(operation, payload, controls);
720
+ },
721
+ emitHost: (operation, payload) => {
722
+ signal.throwIfAborted();
723
+ context.emitHost?.(operation, payload);
724
+ },
725
+ throwIfAborted: () => {
726
+ signal.throwIfAborted();
727
+ context.throwIfAborted?.();
728
+ },
729
+ reportProgress: (progress) => context.reportProgress?.({
730
+ ...progress,
731
+ phase: progress.phase ?? "process",
732
+ unit: progress.unit ?? "items"
733
+ })
734
+ };
735
+ }
736
+ var TaskRuntime = class {
737
+ constructor(task) {
738
+ this.task = task;
739
+ this.initialized = false;
740
+ }
741
+ async initialize(input, context = {}) {
742
+ if (this.initialized)
743
+ throw new Error("Task is already initialized");
744
+ assertPayload(input);
745
+ await preloadTaskCode(this.task, context.signal);
746
+ context.signal?.throwIfAborted();
747
+ this.state = await this.task.initialize?.(input, taskContext(void 0, context));
748
+ this.initialized = true;
749
+ return {};
750
+ }
751
+ async destroy() {
752
+ if (this.initialized) {
753
+ this.initialized = false;
754
+ const state = this.state;
755
+ this.state = void 0;
756
+ if (this.task.initialize)
757
+ await this.task.destroy?.(state);
758
+ }
759
+ return {};
760
+ }
761
+ async process(input, options, context = {}) {
762
+ if (!this.initialized)
763
+ throw new Error("Task is not initialized");
764
+ if (!this.task.process)
765
+ throw new Error("Task has no atomic processor");
766
+ assertPayload(input);
767
+ const result = await this.task.process(input, options, taskContext(this.state, context));
768
+ assertPayload(result);
769
+ return result;
770
+ }
771
+ async *stream(inputs, options, context = {}) {
772
+ if (!this.initialized)
773
+ throw new Error("Task is not initialized");
774
+ if (!this.task.processInBatches)
775
+ throw new Error("Task has no streaming processor");
776
+ for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
777
+ assertPayload(output);
778
+ yield output;
779
+ }
780
+ }
781
+ };
782
+ async function initializeTaskWorker(task) {
783
+ if (!await WorkerBody.inWorkerThread())
784
+ throw new Error("initializeTaskWorker must run inside a worker");
785
+ if (installed)
786
+ throw new Error("A task is already installed in this worker");
787
+ installed = true;
788
+ const runtime = new TaskRuntime(task);
789
+ let channelStream;
790
+ const channel = new TaskChannel({
791
+ getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
792
+ send: (message, transfer) => {
793
+ const snapshot = structuredClone(message, { transfer });
794
+ void WorkerBody.postMessage("task-channel", snapshot).catch((reason) => channel.fail(reason));
795
+ },
796
+ handleRequest: async (operation, value, signal) => {
797
+ const request = value;
798
+ const context = {
799
+ signal,
800
+ reportProgress: (progress) => channel.emit("task:progress", { id: request.progressId, progress }),
801
+ requestHost: (operation2, payload, controls = {}) => {
802
+ const request2 = {
803
+ operation: operation2,
804
+ payload: clonePayload(payload, controls.inputOwnership),
805
+ outputOwnership: controls.outputOwnership ?? "copy"
806
+ };
807
+ return channel.request("task:host-request", request2, signal, getTransferList(request2));
808
+ },
809
+ emitHost: (operation2, payload) => channel.emit("task:host-event", { operation: operation2, payload, id: request.progressId })
810
+ };
811
+ switch (operation) {
812
+ case "initialize":
813
+ return runtime.initialize(request.input, context);
814
+ case "process":
815
+ return runtime.process(request.input, request.options, context);
816
+ case "stream-open": {
817
+ if (channelStream)
818
+ throw new Error("A task stream is already open");
819
+ async function* inputs() {
820
+ while (true) {
821
+ const result = await channel.request("task:next-input", { outputOwnership: "transfer" }, signal);
822
+ if (result.done)
823
+ return;
824
+ yield result.value;
825
+ }
826
+ }
827
+ channelStream = runtime.stream(inputs(), request.options, context)[Symbol.asyncIterator]();
828
+ return {};
829
+ }
830
+ case "stream-next":
831
+ if (!channelStream)
832
+ throw new Error("No active task stream");
833
+ return channelStream.next();
834
+ case "stream-close":
835
+ try {
836
+ await channelStream?.return?.();
837
+ } finally {
838
+ channelStream = void 0;
839
+ }
840
+ return {};
841
+ case "destroy":
842
+ return runtime.destroy();
843
+ default:
844
+ throw new Error("Unknown task channel operation");
845
+ }
846
+ }
847
+ });
848
+ await WorkerBody.addEventListener((type, payload) => {
849
+ if (type === "task-channel")
850
+ channel.receive(payload);
851
+ });
852
+ let streamOptions = {};
853
+ return createWorker(async (request, _options, context) => {
854
+ switch (request.operation) {
855
+ case "initialize":
856
+ return runtime.initialize(request.input, context);
857
+ case "destroy":
858
+ return runtime.destroy();
859
+ case "stream-options":
860
+ streamOptions = request.options;
861
+ return {};
862
+ case "process":
863
+ return runtime.process(request.input, request.options, context);
864
+ default:
865
+ throw new Error("Unknown task operation");
866
+ }
867
+ }, async function* (inputs, _options, context) {
868
+ async function* batches() {
869
+ for await (const input of inputs) {
870
+ assertPayload(input);
871
+ yield input;
872
+ }
873
+ }
874
+ try {
875
+ yield* runtime.stream(batches(), streamOptions, context);
876
+ } finally {
877
+ streamOptions = {};
878
+ }
879
+ }, () => preloadTaskCode(task));
880
+ }
881
+ var installed = false;
882
+
883
+ // ../core/src/worker-utils/lib/worker-api/task-runtime.ts
884
+ function normalizeTaskProgress(progress) {
885
+ return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
886
+ }
887
+ async function isWorkerThread() {
888
+ if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
889
+ return true;
890
+ if (typeof process !== "undefined" && process.versions?.node) {
891
+ const { isMainThread } = await Promise.resolve().then(() => (init_worker_threads_browser(), worker_threads_browser_exports));
892
+ return !isMainThread;
893
+ }
894
+ return false;
895
+ }
896
+ var initializeTaskWorker2 = initializeTaskWorker;
897
+
898
+ // ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
899
+ function getTransferList2(object, recursive = true, transfers) {
900
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
901
+ if (!object) {
902
+ } else if (isTransferable2(object)) {
903
+ transfersSet.add(object);
904
+ } else if (isTransferable2(object.buffer)) {
905
+ transfersSet.add(object.buffer);
906
+ } else if (ArrayBuffer.isView(object)) {
907
+ } else if (recursive && typeof object === "object") {
908
+ for (const key in object) {
909
+ getTransferList2(object[key], recursive, transfersSet);
910
+ }
911
+ }
912
+ return transfers === void 0 ? Array.from(transfersSet) : [];
913
+ }
914
+ function isTransferable2(object) {
915
+ if (!object) {
916
+ return false;
917
+ }
918
+ if (object instanceof ArrayBuffer) {
919
+ return true;
920
+ }
921
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
922
+ return true;
923
+ }
924
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
925
+ return true;
926
+ }
927
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
928
+ return true;
929
+ }
930
+ return false;
931
+ }
932
+
933
+ // ../core/src/worker-utils/lib/worker-api/create-worker.ts
934
+ async function createWorker2(process2, processInBatches) {
935
+ if (!await isWorkerThread()) return;
936
+ await initializeTaskWorker2(createWorkerTask(process2, processInBatches));
937
+ }
938
+ function createWorkerTask(process2, processInBatches) {
939
+ return {
940
+ id: "loaders.gl",
941
+ initialize: (state) => state,
942
+ destroy: (state) => state.port?.close(),
943
+ process: async ({ value }, options, context) => {
944
+ if (!process2) throw new Error("Worker does not support atomic processing");
945
+ return { value: await process2(value, options, createContext(context), context.state.context) };
946
+ },
947
+ ...processInBatches ? {
948
+ processInBatches: async function* (inputs, options, context) {
949
+ async function* values() {
950
+ for await (const input of inputs) yield input.value;
951
+ }
952
+ for await (const value of processInBatches(
953
+ values(),
954
+ options,
955
+ createContext(context),
956
+ context.state.context
957
+ )) {
958
+ yield { value };
959
+ }
960
+ }
961
+ } : {}
962
+ };
963
+ }
964
+ function createContext(context) {
965
+ let requestIdentifier = 0;
966
+ const port = context.state.port;
967
+ return {
968
+ signal: context.signal,
969
+ throwIfAborted: () => context.throwIfAborted(),
970
+ reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
971
+ process: port ? (input, options = {}, jobContext = {}) => {
972
+ context.throwIfAborted();
973
+ const identifier = ++requestIdentifier;
974
+ return new Promise((resolve, reject) => {
975
+ const onMessage = (event) => {
976
+ if (event.data.identifier !== identifier) return;
977
+ cleanup();
978
+ if (event.data.error) {
979
+ const error = new Error(event.data.error.message);
980
+ error.name = event.data.error.name;
981
+ reject(error);
982
+ } else resolve(event.data.value);
983
+ };
984
+ const onAbort = () => {
985
+ cleanup();
986
+ reject(context.signal.reason);
987
+ };
988
+ const cleanup = () => {
989
+ port.removeEventListener("message", onMessage);
990
+ context.signal.removeEventListener("abort", onAbort);
991
+ };
992
+ port.addEventListener("message", onMessage);
993
+ context.signal.addEventListener("abort", onAbort, { once: true });
994
+ port.start();
995
+ try {
996
+ const request = { identifier, input, options, context: jobContext };
997
+ port.postMessage(request, getTransferList2(request));
998
+ } catch (error) {
999
+ cleanup();
1000
+ reject(error);
1001
+ }
1002
+ });
1003
+ } : void 0
1004
+ };
1005
+ }
1006
+
463
1007
  // ../core/src/loader-utils/lib/worker-loader-utils/create-loader-worker.ts
464
1008
  async function createLoaderWorker(loader, selectLoader = () => loader) {
465
- await createWorker(
1009
+ await createWorker2(
466
1010
  (input, options, workerContext, loaderContext) => processLoaderWorkerData(
467
1011
  selectLoader(options || {}),
468
1012
  input,
@@ -12567,11 +13111,11 @@ return true;`);
12567
13111
  this._offsets = new OffsetsBufferBuilder(opts.type);
12568
13112
  }
12569
13113
  setValue(index, value) {
12570
- const pending = this._pending || (this._pending = /* @__PURE__ */ new Map());
12571
- const current = pending.get(index);
13114
+ const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
13115
+ const current = pending2.get(index);
12572
13116
  current && (this._pendingLength -= current.length);
12573
13117
  this._pendingLength += value instanceof MapRow ? value[kKeys].length : value.length;
12574
- pending.set(index, value);
13118
+ pending2.set(index, value);
12575
13119
  }
12576
13120
  setValid(index, isValid) {
12577
13121
  if (!super.setValid(index, isValid)) {
@@ -12594,12 +13138,12 @@ return true;`);
12594
13138
  return super.finish();
12595
13139
  }
12596
13140
  _flush() {
12597
- const pending = this._pending;
13141
+ const pending2 = this._pending;
12598
13142
  const pendingLength = this._pendingLength;
12599
13143
  this._pendingLength = 0;
12600
13144
  this._pending = void 0;
12601
- if (pending && pending.size > 0) {
12602
- this._flushPending(pending, pendingLength);
13145
+ if (pending2 && pending2.size > 0) {
13146
+ this._flushPending(pending2, pendingLength);
12603
13147
  }
12604
13148
  return this;
12605
13149
  }
@@ -15009,11 +15553,11 @@ return true;`);
15009
15553
  setValue(index, value) {
15010
15554
  return super.setValue(index, toUint8Array2(value));
15011
15555
  }
15012
- _flushPending(pending, pendingLength) {
15556
+ _flushPending(pending2, pendingLength) {
15013
15557
  const offsets = this._offsets;
15014
15558
  const data = this._values.reserve(pendingLength).buffer;
15015
15559
  let offset = 0;
15016
- for (const [index, value] of pending) {
15560
+ for (const [index, value] of pending2) {
15017
15561
  if (value === void 0) {
15018
15562
  offsets.set(index, 0);
15019
15563
  } else {
@@ -15042,11 +15586,11 @@ return true;`);
15042
15586
  setValue(index, value) {
15043
15587
  return super.setValue(index, toUint8Array2(value));
15044
15588
  }
15045
- _flushPending(pending, pendingLength) {
15589
+ _flushPending(pending2, pendingLength) {
15046
15590
  const offsets = this._offsets;
15047
15591
  const data = this._values.reserve(pendingLength).buffer;
15048
15592
  let offset = 0;
15049
- for (const [index, value] of pending) {
15593
+ for (const [index, value] of pending2) {
15050
15594
  if (value === void 0) {
15051
15595
  offsets.set(index, BigInt(0));
15052
15596
  } else {
@@ -15277,10 +15821,10 @@ return true;`);
15277
15821
  this.type = new List2(new Field2(name, child.type, true));
15278
15822
  return this.numChildren - 1;
15279
15823
  }
15280
- _flushPending(pending) {
15824
+ _flushPending(pending2) {
15281
15825
  const offsets = this._offsets;
15282
15826
  const [child] = this.children;
15283
- for (const [index, value] of pending) {
15827
+ for (const [index, value] of pending2) {
15284
15828
  if (typeof value === "undefined") {
15285
15829
  offsets.set(index, 0);
15286
15830
  } else {
@@ -15309,10 +15853,10 @@ return true;`);
15309
15853
  this.type = new LargeList2(new Field2(name, child.type, true));
15310
15854
  return this.numChildren - 1;
15311
15855
  }
15312
- _flushPending(pending) {
15856
+ _flushPending(pending2) {
15313
15857
  const offsets = this._offsets;
15314
15858
  const [child] = this.children;
15315
- for (const [index, value] of pending) {
15859
+ for (const [index, value] of pending2) {
15316
15860
  if (typeof value === "undefined") {
15317
15861
  offsets.set(index, BigInt(0));
15318
15862
  } else {
@@ -15334,11 +15878,11 @@ return true;`);
15334
15878
  }
15335
15879
  setValue(index, value) {
15336
15880
  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);
15881
+ const pending2 = this._pending || (this._pending = /* @__PURE__ */ new Map());
15882
+ const current = pending2.get(index);
15339
15883
  current && (this._pendingLength -= current.size);
15340
15884
  this._pendingLength += row.size;
15341
- pending.set(index, row);
15885
+ pending2.set(index, row);
15342
15886
  }
15343
15887
  addChild(child, name = `${this.numChildren}`) {
15344
15888
  if (this.numChildren > 0) {
@@ -15348,10 +15892,10 @@ return true;`);
15348
15892
  this.type = new Map_(new Field2(name, child.type, true), this.type.keysSorted);
15349
15893
  return this.numChildren - 1;
15350
15894
  }
15351
- _flushPending(pending) {
15895
+ _flushPending(pending2) {
15352
15896
  const offsets = this._offsets;
15353
15897
  const [child] = this.children;
15354
- for (const [index, value] of pending) {
15898
+ for (const [index, value] of pending2) {
15355
15899
  if (value === void 0) {
15356
15900
  offsets.set(index, 0);
15357
15901
  } else {
@@ -15514,7 +16058,7 @@ return true;`);
15514
16058
  return super.setValue(index, encodeUtf8(value));
15515
16059
  }
15516
16060
  // @ts-ignore
15517
- _flushPending(pending, pendingLength) {
16061
+ _flushPending(pending2, pendingLength) {
15518
16062
  }
15519
16063
  };
15520
16064
  Utf8Builder.prototype._flushPending = BinaryBuilder.prototype._flushPending;
@@ -15536,7 +16080,7 @@ return true;`);
15536
16080
  return super.setValue(index, encodeUtf8(value));
15537
16081
  }
15538
16082
  // @ts-ignore
15539
- _flushPending(pending, pendingLength) {
16083
+ _flushPending(pending2, pendingLength) {
15540
16084
  }
15541
16085
  };
15542
16086
  LargeUtf8Builder.prototype._flushPending = LargeBinaryBuilder.prototype._flushPending;
@@ -17734,8 +18278,8 @@ return true;`);
17734
18278
  return new JSONVectorLoader(body, header.nodes, header.buffers, this.dictionaries, this.schema.metadataVersion, header.variadicBufferCounts).visitMany(types);
17735
18279
  }
17736
18280
  };
17737
- function shouldAutoDestroy(self, options) {
17738
- return options && typeof options["autoDestroy"] === "boolean" ? options["autoDestroy"] : self["autoDestroy"];
18281
+ function shouldAutoDestroy(self2, options) {
18282
+ return options && typeof options["autoDestroy"] === "boolean" ? options["autoDestroy"] : self2["autoDestroy"];
17739
18283
  }
17740
18284
  function* readAllSync(source) {
17741
18285
  const reader = RecordBatchReader.from(source);
@@ -18973,12 +19517,6 @@ return true;`);
18973
19517
  metadata: serializeArrowMetadata(arrowSchema.metadata)
18974
19518
  };
18975
19519
  }
18976
- function deserializeArrowSchema(schema, options) {
18977
- return new Schema2(
18978
- schema.fields.map((field) => deserializeArrowField(field, options)),
18979
- deserializeArrowMetadata(schema.metadata)
18980
- );
18981
- }
18982
19520
  function serializeArrowMetadata(arrowMetadata) {
18983
19521
  return Object.fromEntries(arrowMetadata);
18984
19522
  }
@@ -19949,7 +20487,7 @@ return true;`);
19949
20487
  };
19950
20488
 
19951
20489
  // src/las/las-loader-shared.ts
19952
- var VERSION = true ? "5.0.0-beta.2" : "latest";
20490
+ var VERSION = true ? "5.0.0-beta.5" : "latest";
19953
20491
  var DEFAULT_LAS_SHAPE = "arrow-table";
19954
20492
  function getLASShape(options) {
19955
20493
  return options?.las?.shape || DEFAULT_LAS_SHAPE;
@@ -19994,7 +20532,24 @@ return true;`);
19994
20532
  return { ...mesh, attributes };
19995
20533
  }
19996
20534
 
19997
- // ../core/src/schema-utils/lib/arrow/split-arrow-buffers.ts
20535
+ // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-data.js
20536
+ function getArrowVariadicBuffers(data) {
20537
+ return data.variadicBuffers ?? [];
20538
+ }
20539
+ function createArrowData(type, offset, length, nullCount, buffers, children, dictionary, variadicBuffers) {
20540
+ return Reflect.construct(Data, [
20541
+ type,
20542
+ offset,
20543
+ length,
20544
+ nullCount,
20545
+ buffers,
20546
+ children,
20547
+ dictionary,
20548
+ variadicBuffers
20549
+ ]);
20550
+ }
20551
+
20552
+ // ../../node_modules/@math.gl/arrow/dist/arrow/split-arrow-buffers.js
19998
20553
  function splitArrowBuffers(input, options = {}) {
19999
20554
  const context = { ...options, copies: /* @__PURE__ */ new WeakMap() };
20000
20555
  if (isArrowTable2(input)) {
@@ -20017,17 +20572,12 @@ return true;`);
20017
20572
  function isArrowVector2(input) {
20018
20573
  return "data" in input && Array.isArray(input.data);
20019
20574
  }
20020
- function splitArrowTableBuffersInternal(table, options) {
20021
- const recordBatches = table.batches.map(
20022
- (recordBatch) => splitArrowRecordBatchBuffers(recordBatch, options)
20023
- );
20024
- return new Table(table.schema, recordBatches);
20575
+ function splitArrowTableBuffersInternal(arrowTable, options) {
20576
+ const recordBatches = arrowTable.batches.map((recordBatch) => splitArrowRecordBatchBuffers(recordBatch, options));
20577
+ return new Table(arrowTable.schema, recordBatches);
20025
20578
  }
20026
20579
  function splitArrowRecordBatchBuffers(recordBatch, options) {
20027
- return new RecordBatch3(
20028
- recordBatch.schema,
20029
- splitArrowDataBuffers(recordBatch.data, options)
20030
- );
20580
+ return new RecordBatch3(recordBatch.schema, splitArrowDataBuffers(recordBatch.data, options));
20031
20581
  }
20032
20582
  function splitArrowDataBuffers(data, options) {
20033
20583
  const children = data.children.map((childData) => splitArrowDataBuffers(childData, options));
@@ -20038,7 +20588,7 @@ return true;`);
20038
20588
  [BufferType.VALIDITY]: splitArrowBuffer(data.buffers[BufferType.VALIDITY], options),
20039
20589
  [BufferType.TYPE]: splitArrowBuffer(data.buffers[BufferType.TYPE], options)
20040
20590
  };
20041
- return new Data(
20591
+ return createArrowData(
20042
20592
  data.type,
20043
20593
  data.offset,
20044
20594
  data.length,
@@ -20046,7 +20596,8 @@ return true;`);
20046
20596
  data._nullCount,
20047
20597
  buffers,
20048
20598
  children,
20049
- dictionary
20599
+ dictionary,
20600
+ getArrowVariadicBuffers(data).map((buffer) => splitArrowBuffer(buffer, options))
20050
20601
  );
20051
20602
  }
20052
20603
  function splitArrowVectorBuffers(vector, options) {
@@ -20064,7 +20615,7 @@ return true;`);
20064
20615
  }
20065
20616
  let copy = options.copies.get(array);
20066
20617
  if (!copy) {
20067
- copy = array.slice();
20618
+ copy = array instanceof Uint8Array ? new Uint8Array(array) : array.slice();
20068
20619
  options.copies.set(array, copy);
20069
20620
  }
20070
20621
  return copy;
@@ -20073,23 +20624,50 @@ return true;`);
20073
20624
  return ArrayBuffer.isView(value) && !(value instanceof DataView);
20074
20625
  }
20075
20626
 
20076
- // ../core/src/schema-utils/lib/arrow/arrow-table-transport.ts
20077
- function dehydrateArrowTable(table, options) {
20078
- const splitTable = splitArrowBuffers(table, options);
20627
+ // ../../node_modules/@math.gl/arrow/dist/arrow/arrow-table-transport.js
20628
+ function dehydrateArrowTable(arrowTable, options) {
20629
+ const splitTable = splitArrowBuffers(arrowTable, options);
20079
20630
  return {
20080
- shape: "arrow-table",
20081
20631
  transport: "arrow-js",
20082
- schema: serializeArrowSchema(splitTable.schema),
20083
- batches: splitTable.batches.map((recordBatch) => dehydrateArrowRecordBatch(recordBatch))
20632
+ version: 1,
20633
+ schema: tableToIPC(new Table(splitTable.schema, [])),
20634
+ metadataVersion: splitTable.schema.metadataVersion,
20635
+ batches: splitTable.batches.map((batch) => dehydrateArrowData(batch.data))
20084
20636
  };
20085
20637
  }
20086
20638
  function hydrateArrowTable(table) {
20087
- const schema = deserializeArrowSchema(table.schema);
20088
- const recordBatches = table.batches.map(
20089
- (recordBatch) => new RecordBatch3(schema, hydrateArrowData(recordBatch.data))
20090
- );
20091
- return new Table(schema, recordBatches);
20639
+ if (table.transport !== "arrow-js" || table.version !== 1) {
20640
+ throw new Error("Unsupported Arrow column-buffer transport protocol.");
20641
+ }
20642
+ const decodedSchema = tableFromIPC(table.schema).schema;
20643
+ const schema = new Schema2(decodedSchema.fields, decodedSchema.metadata, decodedSchema.dictionaries, table.metadataVersion);
20644
+ const type = new Struct(schema.fields);
20645
+ const batches = table.batches.map((data) => new RecordBatch3(schema, hydrateArrowData(data, type)));
20646
+ return new Table(schema, batches);
20647
+ }
20648
+ function dehydrateArrowData(data) {
20649
+ return {
20650
+ offset: data.offset,
20651
+ length: data.length,
20652
+ nullCount: data.nullCount,
20653
+ buffers: {
20654
+ [BufferType.OFFSET]: data.buffers[BufferType.OFFSET],
20655
+ [BufferType.DATA]: data.buffers[BufferType.DATA],
20656
+ [BufferType.VALIDITY]: data.buffers[BufferType.VALIDITY],
20657
+ [BufferType.TYPE]: data.buffers[BufferType.TYPE]
20658
+ },
20659
+ children: data.children.map((child) => dehydrateArrowData(child)),
20660
+ variadicBuffers: getArrowVariadicBuffers(data),
20661
+ dictionary: data.dictionary?.data.map((chunk) => dehydrateArrowData(chunk))
20662
+ };
20092
20663
  }
20664
+ function hydrateArrowData(data, type) {
20665
+ const children = data.children.map((child, index) => hydrateArrowData(child, type.children[index].type));
20666
+ const dictionary = data.dictionary && DataType.isDictionary(type) ? new Vector(data.dictionary.map((chunk) => hydrateArrowData(chunk, type.dictionary))) : void 0;
20667
+ return createArrowData(type, data.offset, data.length, data.nullCount, data.buffers, children, dictionary, data.variadicBuffers);
20668
+ }
20669
+
20670
+ // ../core/src/arrow-worker-transport.ts
20093
20671
  function serializeArrowWorkerTable(result) {
20094
20672
  if (!isArrowTableWrapper(result)) {
20095
20673
  throw new Error("Workers require Arrow table output");
@@ -20118,45 +20696,6 @@ return true;`);
20118
20696
  table && table.shape === "arrow-table" && table.data && table.data.transport === "arrow-js" && Array.isArray(table.data.batches)
20119
20697
  );
20120
20698
  }
20121
- function dehydrateArrowRecordBatch(recordBatch) {
20122
- return { data: dehydrateArrowData(recordBatch.data) };
20123
- }
20124
- function dehydrateArrowData(data) {
20125
- return {
20126
- type: serializeArrowType(data.type),
20127
- offset: data.offset,
20128
- length: data.length,
20129
- // @ts-expect-error _nullCount is protected. Preserve the Arrow lazy null-count state.
20130
- nullCount: data._nullCount,
20131
- buffers: {
20132
- [BufferType.OFFSET]: data.buffers[BufferType.OFFSET],
20133
- [BufferType.DATA]: data.buffers[BufferType.DATA],
20134
- [BufferType.VALIDITY]: data.buffers[BufferType.VALIDITY],
20135
- [BufferType.TYPE]: data.buffers[BufferType.TYPE]
20136
- },
20137
- children: data.children.map((childData) => dehydrateArrowData(childData)),
20138
- dictionary: data.dictionary ? dehydrateArrowVector(data.dictionary) : void 0
20139
- };
20140
- }
20141
- function dehydrateArrowVector(vector) {
20142
- return { data: vector.data.map((data) => dehydrateArrowData(data)) };
20143
- }
20144
- function hydrateArrowData(data) {
20145
- const children = data.children.map((childData) => hydrateArrowData(childData));
20146
- const dictionary = data.dictionary ? hydrateArrowVector(data.dictionary) : void 0;
20147
- return new Data(
20148
- deserializeArrowType(data.type),
20149
- data.offset,
20150
- data.length,
20151
- data.nullCount,
20152
- data.buffers,
20153
- children,
20154
- dictionary
20155
- );
20156
- }
20157
- function hydrateArrowVector(vector) {
20158
- return new Vector(vector.data.map((data) => hydrateArrowData(data)));
20159
- }
20160
20699
 
20161
20700
  // src/las/lib/get-las-schema.ts
20162
20701
  function getLASSchema(lasHeader, attributes) {
@@ -20349,7 +20888,12 @@ return true;`);
20349
20888
  return attributes;
20350
20889
  }
20351
20890
  function readLASString(bytes, offset, length) {
20352
- return new TextDecoder().decode(bytes.subarray(offset, offset + length)).replace(/\0+$/, "").trim();
20891
+ const decoded = new TextDecoder().decode(bytes.subarray(offset, offset + length));
20892
+ let end = decoded.length;
20893
+ while (end > 0 && decoded[end - 1] === "\0") {
20894
+ end--;
20895
+ }
20896
+ return decoded.slice(0, end).trim();
20353
20897
  }
20354
20898
  function sanitizeExtraBytesName(name) {
20355
20899
  return name.trim().replace(/[^A-Za-z0-9_]+/g, "_");
@@ -20595,7 +21139,7 @@ return true;`);
20595
21139
  async function* parseLASInBatches(arrayBufferIterator, options = {}) {
20596
21140
  const batchSize = getBatchSize(options);
20597
21141
  const inputIterator = toAsyncIterator(arrayBufferIterator);
20598
- let pending = new Uint8Array(0);
21142
+ let pending2 = new Uint8Array(0);
20599
21143
  let absoluteOffset = 0;
20600
21144
  let header = null;
20601
21145
  let sourcePointIndex = 0;
@@ -20606,9 +21150,9 @@ return true;`);
20606
21150
  break;
20607
21151
  }
20608
21152
  const chunk = next.value;
20609
- pending = concatenateUint8Arrays2(pending, toUint8Array3(chunk));
21153
+ pending2 = concatenateUint8Arrays2(pending2, toUint8Array3(chunk));
20610
21154
  if (!header) {
20611
- header = tryParseHeader(pending, absoluteOffset);
21155
+ header = tryParseHeader(pending2, absoluteOffset);
20612
21156
  if (header) {
20613
21157
  header.totalToRead = header.pointsCount;
20614
21158
  }
@@ -20617,11 +21161,11 @@ return true;`);
20617
21161
  continue;
20618
21162
  }
20619
21163
  if (header.isCompressed) {
20620
- yield* parseLAZInBatches(pending, inputIterator, header, options);
21164
+ yield* parseLAZInBatches(pending2, inputIterator, header, options);
20621
21165
  return;
20622
21166
  }
20623
21167
  for (const batch of readAvailablePointBatches(
20624
- pending,
21168
+ pending2,
20625
21169
  absoluteOffset,
20626
21170
  header,
20627
21171
  sourcePointIndex,
@@ -20630,7 +21174,7 @@ return true;`);
20630
21174
  )) {
20631
21175
  sourcePointIndex = batch.sourcePointIndex;
20632
21176
  totalRead = batch.totalRead;
20633
- pending = batch.pending;
21177
+ pending2 = batch.pending;
20634
21178
  absoluteOffset = batch.absoluteOffset;
20635
21179
  yield parseLASArrowTableBatch(batch.arrayBuffer, batch.header, options);
20636
21180
  }
@@ -20814,11 +21358,11 @@ return true;`);
20814
21358
  );
20815
21359
  }
20816
21360
  async function* parseLAZInBatches(initialPending, inputIterator, header, options) {
20817
- const { pending, laszip } = await readLASZipVLRFromInput(initialPending, inputIterator, header);
21361
+ const { pending: pending2, laszip } = await readLASZipVLRFromInput(initialPending, inputIterator, header);
20818
21362
  validateTypeScriptLAZSupport(header, laszip);
20819
21363
  if (!laszip.variableChunks && header.pointsFormatId <= 5) {
20820
21364
  yield* parsePendingFixedLegacyLAZFileInArrowBatches(
20821
- pending,
21365
+ pending2,
20822
21366
  inputIterator,
20823
21367
  header,
20824
21368
  laszip,
@@ -20827,11 +21371,11 @@ return true;`);
20827
21371
  return;
20828
21372
  }
20829
21373
  if (!laszip.variableChunks && header.pointsFormatId >= 6 && header.pointsFormatId <= 10) {
20830
- yield* parsePendingLAZFileInArrowBatches(pending, inputIterator, header, laszip, options);
21374
+ yield* parsePendingLAZFileInArrowBatches(pending2, inputIterator, header, laszip, options);
20831
21375
  return;
20832
21376
  }
20833
21377
  for await (const batch of decodeLAZFileWithParsedVLRInBatches(
20834
- pending,
21378
+ pending2,
20835
21379
  inputIterator,
20836
21380
  header,
20837
21381
  laszip,
@@ -22032,10 +22576,10 @@ return true;`);
22032
22576
  }
22033
22577
  }
22034
22578
  async function readLASZipVLRFromInput(initialPending, inputIterator, header) {
22035
- let pending = initialPending;
22579
+ let pending2 = initialPending;
22036
22580
  while (true) {
22037
22581
  try {
22038
- return { pending, laszip: parseLASZipVLR(pending, header) };
22582
+ return { pending: pending2, laszip: parseLASZipVLR(pending2, header) };
22039
22583
  } catch (error) {
22040
22584
  if (!(error instanceof NeedsMoreData)) {
22041
22585
  throw error;
@@ -22045,7 +22589,7 @@ return true;`);
22045
22589
  if (next.done) {
22046
22590
  throw new NeedsMoreData("LASLoader: incomplete LASzip VLR");
22047
22591
  }
22048
- pending = concatenateUint8Arrays2(pending, toUint8Array3(next.value));
22592
+ pending2 = concatenateUint8Arrays2(pending2, toUint8Array3(next.value));
22049
22593
  }
22050
22594
  }
22051
22595
  async function collectRemainingInputBytes(initialPending, inputIterator) {
@@ -22969,10 +23513,10 @@ return true;`);
22969
23513
  [maximum[0], maximum[1], maximum[2]]
22970
23514
  ];
22971
23515
  }
22972
- function* readAvailablePointBatches(pending, absoluteOffset, header, sourcePointIndex, totalRead, batchSize) {
23516
+ function* readAvailablePointBatches(pending2, absoluteOffset, header, sourcePointIndex, totalRead, batchSize) {
22973
23517
  while (sourcePointIndex < header.pointsCount && totalRead < header.totalToRead) {
22974
23518
  const batch = readAvailableContiguousPointBatch(
22975
- pending,
23519
+ pending2,
22976
23520
  absoluteOffset,
22977
23521
  header,
22978
23522
  sourcePointIndex,
@@ -22982,25 +23526,25 @@ return true;`);
22982
23526
  if (!batch) {
22983
23527
  return;
22984
23528
  }
22985
- pending = batch.pending;
23529
+ pending2 = batch.pending;
22986
23530
  absoluteOffset = batch.absoluteOffset;
22987
23531
  sourcePointIndex = batch.sourcePointIndex;
22988
23532
  totalRead = batch.totalRead;
22989
23533
  yield batch;
22990
23534
  }
22991
23535
  }
22992
- function readAvailableContiguousPointBatch(pending, absoluteOffset, header, sourcePointIndex, totalRead, batchSize) {
23536
+ function readAvailableContiguousPointBatch(pending2, absoluteOffset, header, sourcePointIndex, totalRead, batchSize) {
22993
23537
  const pointRecordLength = header.pointsStructSize;
22994
23538
  const pointAbsoluteOffset = header.pointsOffset + sourcePointIndex * pointRecordLength;
22995
23539
  const pointPendingOffset = pointAbsoluteOffset - absoluteOffset;
22996
23540
  if (pointPendingOffset < 0) {
22997
23541
  throw new Error("LASLoader: invalid streaming point offset");
22998
23542
  }
22999
- if (pointPendingOffset + pointRecordLength > pending.byteLength) {
23543
+ if (pointPendingOffset + pointRecordLength > pending2.byteLength) {
23000
23544
  return null;
23001
23545
  }
23002
23546
  const availablePointCount = Math.floor(
23003
- (pending.byteLength - pointPendingOffset) / pointRecordLength
23547
+ (pending2.byteLength - pointPendingOffset) / pointRecordLength
23004
23548
  );
23005
23549
  const batchPointCount = Math.min(
23006
23550
  batchSize,
@@ -23015,38 +23559,38 @@ return true;`);
23015
23559
  totalRead += batchPointCount;
23016
23560
  const batchHeader = {
23017
23561
  ...header,
23018
- pointsOffset: pending.byteOffset + pointPendingOffset,
23562
+ pointsOffset: pending2.byteOffset + pointPendingOffset,
23019
23563
  pointsCount: batchPointCount,
23020
23564
  totalRead
23021
23565
  };
23022
23566
  const nextPointOffset = header.pointsOffset + sourcePointIndex * pointRecordLength;
23023
23567
  const discardByteCount = Math.max(
23024
23568
  0,
23025
- Math.min(pending.byteLength, nextPointOffset - absoluteOffset)
23569
+ Math.min(pending2.byteLength, nextPointOffset - absoluteOffset)
23026
23570
  );
23027
23571
  return {
23028
- arrayBuffer: pending.buffer,
23572
+ arrayBuffer: pending2.buffer,
23029
23573
  header: batchHeader,
23030
- pending: pending.subarray(discardByteCount),
23574
+ pending: pending2.subarray(discardByteCount),
23031
23575
  absoluteOffset: absoluteOffset + discardByteCount,
23032
23576
  sourcePointIndex,
23033
23577
  totalRead
23034
23578
  };
23035
23579
  }
23036
- function tryParseHeader(pending, absoluteOffset) {
23037
- if (absoluteOffset !== 0 || pending.byteLength < 227) {
23580
+ function tryParseHeader(pending2, absoluteOffset) {
23581
+ if (absoluteOffset !== 0 || pending2.byteLength < 227) {
23038
23582
  return null;
23039
23583
  }
23040
- const dataView = new DataView(pending.buffer, pending.byteOffset, pending.byteLength);
23584
+ const dataView = new DataView(pending2.buffer, pending2.byteOffset, pending2.byteLength);
23041
23585
  if (dataView.getUint32(0, true) !== LASF_SIGNATURE) {
23042
23586
  throw new Error("LASLoader: invalid LAS header");
23043
23587
  }
23044
23588
  const headerLength = dataView.getUint32(96, true);
23045
- if (pending.byteLength < Math.max(headerLength, 255)) {
23589
+ if (pending2.byteLength < Math.max(headerLength, 255)) {
23046
23590
  return null;
23047
23591
  }
23048
23592
  const header = parseLASHeader(
23049
- pending.buffer.slice(pending.byteOffset, pending.byteOffset + pending.byteLength)
23593
+ pending2.buffer.slice(pending2.byteOffset, pending2.byteOffset + pending2.byteLength)
23050
23594
  );
23051
23595
  return header;
23052
23596
  }