@loaders.gl/core 5.0.0-beta.1 → 5.0.0-beta.2

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 (117) hide show
  1. package/README.md +3 -1
  2. package/dist/cluster-source.cjs +7228 -0
  3. package/dist/cluster-source.cjs.map +6 -0
  4. package/dist/cluster-source.d.ts +2 -0
  5. package/dist/cluster-source.d.ts.map +1 -0
  6. package/dist/cluster-source.js +2 -0
  7. package/dist/cluster-source.js.map +1 -0
  8. package/dist/dist.dev.js +894 -273
  9. package/dist/dist.min.js +3 -3
  10. package/dist/federated-table-scan-source.cjs +2677 -0
  11. package/dist/federated-table-scan-source.cjs.map +6 -0
  12. package/dist/federated-table-scan-source.d.ts +2 -0
  13. package/dist/federated-table-scan-source.d.ts.map +1 -0
  14. package/dist/federated-table-scan-source.js +2 -0
  15. package/dist/federated-table-scan-source.js.map +1 -0
  16. package/dist/index.cjs +12 -1045
  17. package/dist/index.cjs.map +3 -3
  18. package/dist/lib/init.js +1 -1
  19. package/dist/loader-utils/index.cjs +43 -1331
  20. package/dist/loader-utils/index.cjs.map +3 -3
  21. package/dist/loader-utils/json-loader.js +1 -1
  22. package/dist/loader-utils/lib/log-utils/log.js +1 -1
  23. package/dist/null-loader.js +1 -1
  24. package/dist/null-worker-node.js +169 -79
  25. package/dist/null-worker.js +166 -55
  26. package/dist/polyfills/images/encode-image-node.d.ts +18 -15
  27. package/dist/polyfills/images/encode-image-node.d.ts.map +1 -1
  28. package/dist/polyfills/images/encode-image-node.js +19 -33
  29. package/dist/polyfills/images/encode-image-node.js.map +1 -1
  30. package/dist/polyfills/images/image-codecs-node.d.ts +2 -6
  31. package/dist/polyfills/images/image-codecs-node.d.ts.map +1 -1
  32. package/dist/polyfills/images/image-codecs-node.js +2 -24
  33. package/dist/polyfills/images/image-codecs-node.js.map +1 -1
  34. package/dist/polyfills/images/load-sharp.d.ts +3 -0
  35. package/dist/polyfills/images/load-sharp.d.ts.map +1 -0
  36. package/dist/polyfills/images/load-sharp.js +11 -0
  37. package/dist/polyfills/images/load-sharp.js.map +1 -0
  38. package/dist/polyfills/images/node-image-bitmap.d.ts +1 -1
  39. package/dist/polyfills/images/node-image-bitmap.js +1 -1
  40. package/dist/polyfills/images/node-image-formats.d.ts +1 -1
  41. package/dist/polyfills/images/node-image-formats.d.ts.map +1 -1
  42. package/dist/polyfills/images/node-image-formats.js +10 -4
  43. package/dist/polyfills/images/node-image-formats.js.map +1 -1
  44. package/dist/polyfills/images/parse-image-node.d.ts +10 -2
  45. package/dist/polyfills/images/parse-image-node.d.ts.map +1 -1
  46. package/dist/polyfills/images/parse-image-node.js +20 -32
  47. package/dist/polyfills/images/parse-image-node.js.map +1 -1
  48. package/dist/polyfills/index.cjs +73 -149
  49. package/dist/vector-table-scan-source.cjs +1703 -0
  50. package/dist/vector-table-scan-source.cjs.map +6 -0
  51. package/dist/vector-table-scan-source.d.ts +2 -0
  52. package/dist/vector-table-scan-source.d.ts.map +1 -0
  53. package/dist/vector-table-scan-source.js +2 -0
  54. package/dist/vector-table-scan-source.js.map +1 -0
  55. package/dist/worker-utils/index.cjs +72 -1225
  56. package/dist/worker-utils/index.cjs.map +3 -3
  57. package/dist/worker-utils/lib/async-queue/async-queue.d.ts +1 -31
  58. package/dist/worker-utils/lib/async-queue/async-queue.d.ts.map +1 -1
  59. package/dist/worker-utils/lib/async-queue/async-queue.js +1 -87
  60. package/dist/worker-utils/lib/async-queue/async-queue.js.map +1 -1
  61. package/dist/worker-utils/lib/env-utils/version.js +1 -1
  62. package/dist/worker-utils/lib/worker-api/create-worker.d.ts +1 -8
  63. package/dist/worker-utils/lib/worker-api/create-worker.d.ts.map +1 -1
  64. package/dist/worker-utils/lib/worker-api/create-worker.js +1 -157
  65. package/dist/worker-utils/lib/worker-api/create-worker.js.map +1 -1
  66. package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +2 -49
  67. package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts.map +1 -1
  68. package/dist/worker-utils/lib/worker-api/process-on-worker.js +1 -345
  69. package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
  70. package/dist/worker-utils/lib/worker-farm/worker-body.d.ts +1 -19
  71. package/dist/worker-utils/lib/worker-farm/worker-body.d.ts.map +1 -1
  72. package/dist/worker-utils/lib/worker-farm/worker-body.js +1 -127
  73. package/dist/worker-utils/lib/worker-farm/worker-body.js.map +1 -1
  74. package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts +1 -57
  75. package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts.map +1 -1
  76. package/dist/worker-utils/lib/worker-farm/worker-farm.js +1 -112
  77. package/dist/worker-utils/lib/worker-farm/worker-farm.js.map +1 -1
  78. package/dist/worker-utils/lib/worker-farm/worker-job.d.ts +1 -33
  79. package/dist/worker-utils/lib/worker-farm/worker-job.d.ts.map +1 -1
  80. package/dist/worker-utils/lib/worker-farm/worker-job.js +1 -70
  81. package/dist/worker-utils/lib/worker-farm/worker-job.js.map +1 -1
  82. package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts +1 -93
  83. package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts.map +1 -1
  84. package/dist/worker-utils/lib/worker-farm/worker-pool.js +1 -242
  85. package/dist/worker-utils/lib/worker-farm/worker-pool.js.map +1 -1
  86. package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts +1 -66
  87. package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts.map +1 -1
  88. package/dist/worker-utils/lib/worker-farm/worker-thread.js +1 -171
  89. package/dist/worker-utils/lib/worker-farm/worker-thread.js.map +1 -1
  90. package/dist/worker-utils/null-worker-node.js +234 -144
  91. package/dist/worker-utils/null-worker-node.js.map +4 -4
  92. package/dist/worker-utils/null-worker.js +232 -121
  93. package/dist/worker-utils/null-worker.js.map +4 -4
  94. package/dist/worker-utils/types.d.ts +1 -99
  95. package/dist/worker-utils/types.d.ts.map +1 -1
  96. package/package.json +27 -29
  97. package/src/cluster-source.ts +1 -0
  98. package/src/federated-table-scan-source.ts +1 -0
  99. package/src/polyfills/README.md +2 -2
  100. package/src/polyfills/images/encode-image-node.ts +44 -37
  101. package/src/polyfills/images/image-codecs-node.ts +2 -37
  102. package/src/polyfills/images/load-sharp.ts +13 -0
  103. package/src/polyfills/images/node-image-bitmap.ts +1 -1
  104. package/src/polyfills/images/node-image-formats.ts +10 -4
  105. package/src/polyfills/images/parse-image-node.ts +31 -40
  106. package/src/vector-table-scan-source.ts +1 -0
  107. package/src/worker-utils/lib/async-queue/async-queue.ts +1 -96
  108. package/src/worker-utils/lib/worker-api/create-worker.ts +1 -201
  109. package/src/worker-utils/lib/worker-api/process-on-worker.ts +8 -464
  110. package/src/worker-utils/lib/worker-farm/worker-body.ts +1 -141
  111. package/src/worker-utils/lib/worker-farm/worker-farm.ts +1 -140
  112. package/src/worker-utils/lib/worker-farm/worker-job.ts +1 -81
  113. package/src/worker-utils/lib/worker-farm/worker-pool.ts +1 -312
  114. package/src/worker-utils/lib/worker-farm/worker-thread.ts +1 -202
  115. package/src/worker-utils/types.ts +14 -144
  116. package/src/polyfills/images/encode-image.node.ts.disabled +0 -41
  117. package/src/polyfills/images/parse-image.node.ts.disabled +0 -55
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/worker-utils/lib/async-queue/async-queue.ts", "../../src/worker-utils/lib/worker-utils/get-transfer-list.ts", "../../src/worker-utils/lib/node/worker_threads-browser.ts", "../../src/worker-utils/lib/worker-farm/worker-body.ts", "../../src/worker-utils/lib/worker-api/create-worker.ts", "../../src/worker-utils/workers/null-worker.ts"],
4
- "sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license\n// http://2ality.com/2016/10/asynchronous-iteration.html\n\n/**\n * Async Queue\n * - AsyncIterable: An async iterator can be\n * - Values can be pushed onto the queue\n * @example\n * const asyncQueue = new AsyncQueue();\n * setTimeout(() => asyncQueue.enqueue('tick'), 1000);\n * setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);\n * for await (const value of asyncQueue) {\n * console.log(value); // tick\n * }\n */\nexport default class AsyncQueue<T> {\n private _values: any[];\n private _settlers: any[];\n private _closed: boolean;\n\n constructor() {\n this._values = []; // enqueues > dequeues\n this._settlers = []; // dequeues > enqueues\n this._closed = false;\n }\n\n /** Return an async iterator for this queue */\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this;\n }\n\n /** Push a new value - the async iterator will yield a promise resolved to this value */\n push(value: T): void {\n return this.enqueue(value);\n }\n\n /**\n * Push a new value - the async iterator will yield a promise resolved to this value\n * Add an error - the async iterator will yield a promise rejected with this value\n */\n enqueue(value: T | Error): void {\n if (this._closed) {\n throw new Error('Closed');\n }\n\n if (this._settlers.length > 0) {\n if (this._values.length > 0) {\n throw new Error('Illegal internal state');\n }\n const settler = this._settlers.shift();\n if (value instanceof Error) {\n settler.reject(value);\n } else {\n settler.resolve({value});\n }\n } else {\n this._values.push(value);\n }\n }\n\n /** Indicate that we not waiting for more values - The async iterator will be done */\n close(): void {\n while (this._settlers.length > 0) {\n const settler = this._settlers.shift();\n settler.resolve({done: true});\n }\n this._closed = true;\n }\n\n // ITERATOR IMPLEMENTATION\n\n /** @returns a Promise for an IteratorResult */\n next(): Promise<IteratorResult<T, any>> {\n // If values in queue, yield the first value\n if (this._values.length > 0) {\n const value = this._values.shift();\n if (value instanceof Error) {\n return Promise.reject(value);\n }\n return Promise.resolve({done: false, value});\n }\n\n // If queue is closed, the iterator is done\n if (this._closed) {\n if (this._settlers.length > 0) {\n throw new Error('Illegal internal state');\n }\n return Promise.resolve({done: true, value: undefined});\n }\n\n // Yield a promise that waits for new values to be enqueued\n return new Promise((resolve, reject) => {\n this._settlers.push({resolve, reject});\n });\n }\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// NOTE - there is a copy of this function is both in core and loader-utils\n// core does not need all the utils in loader-utils, just this one.\n\n/**\n * Returns an array of Transferrable objects that can be used with postMessage\n * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage\n * @param object data to be sent via postMessage\n * @param recursive - not for application use\n * @param transfers - not for application use\n * @returns a transfer list that can be passed to postMessage\n */\nexport function getTransferList(\n object: any,\n recursive: boolean = true,\n transfers?: Set<any>\n): Transferable[] {\n // Make sure that items in the transfer list is unique\n const transfersSet = transfers || new Set();\n\n if (!object) {\n // ignore\n } else if (isTransferable(object)) {\n transfersSet.add(object);\n } else if (isTransferable(object.buffer)) {\n // Typed array\n transfersSet.add(object.buffer);\n } else if (ArrayBuffer.isView(object)) {\n // object is a TypeArray viewing into a SharedArrayBuffer (not transferable)\n // Do not iterate through the content in this case\n } else if (recursive && typeof object === 'object') {\n for (const key in object) {\n // Avoid perf hit - only go one level deep\n getTransferList(object[key], recursive, transfersSet);\n }\n }\n\n // If transfers is defined, is internal recursive call\n // Otherwise it's called by the user\n return transfers === undefined ? Array.from(transfersSet) : [];\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Transferable\nfunction isTransferable(object: unknown) {\n if (!object) {\n return false;\n }\n if (object instanceof ArrayBuffer) {\n return true;\n }\n if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) {\n return true;\n }\n if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) {\n return true;\n }\n // @ts-ignore\n if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) {\n return true;\n }\n return false;\n}\n\n/**\n * Recursively drop non serializable values like functions and regexps.\n * @param object\n */\nexport function getTransferListForWriter(object: object | null): object {\n if (object === null) {\n return {};\n }\n const clone = Object.assign({}, object);\n\n Object.keys(clone).forEach(key => {\n // Typed Arrays and Arrays are passed with no change\n if (\n typeof object[key] === 'object' &&\n !ArrayBuffer.isView(object[key]) &&\n !(object[key] instanceof Array)\n ) {\n clone[key] = getTransferListForWriter(object[key]);\n } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {\n clone[key] = {};\n } else {\n clone[key] = object[key];\n }\n });\n\n return clone;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/** Browser polyfill for Node.js built-in `worker_threads` module.\n * These fills are non-functional, and just intended to ensure that\n * `import 'worker_threads` doesn't break browser builds.\n * The replacement is done in package.json browser field\n */\nexport class NodeWorker {\n /** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */\n constructor(...arguments_: unknown[]) {\n const runtimeProcess = (\n globalThis as {\n process?: {\n getBuiltinModule?: (specifier: string) => {\n Worker?: new (...workerArguments: unknown[]) => NodeWorker;\n };\n };\n }\n ).process;\n const WorkerConstructor = runtimeProcess?.getBuiltinModule?.('node:worker_threads').Worker;\n if (WorkerConstructor) {\n return new WorkerConstructor(...arguments_);\n }\n }\n\n /** No-op browser fallback matching the native Worker API. */\n terminate() {}\n}\n\nexport type {NodeWorker as NodeWorkerType};\n\nexport const parentPort = null;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n// import type {TransferListItem} from '../node/worker_threads';\nimport {parentPort} from '../node/worker_threads';\n\ntype TransferListItem = any;\ntype WorkerMessageEvent = MessageEvent<WorkerMessageData> | WorkerMessageData;\ntype WorkerMessageListener = (type: WorkerMessageType, payload: WorkerMessagePayload) => any;\n\n/** Vile hack to defeat over-zealous bundlers from stripping out the require */\nasync function getParentPort() {\n // const isNode = globalThis.process;\n // let parentPort;\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.parentPort = require(\\'worker_threads\\').parentPort'); // eslint-disable-line no-eval\n // parentPort = globalThis.parentPort;\n // } catch {\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.workerThreadsPromise = import(\\'worker_threads\\')'); // eslint-disable-line no-eval\n // const workerThreads = await globalThis.workerThreadsPromise;\n // parentPort = workerThreads.parentPort;\n // } catch (error) {\n // console.error((error as Error).message); // eslint-disable-line no-console\n // }\n // }\n return parentPort;\n}\n\nconst onMessageWrapperMap = new Map<WorkerMessageListener, (message: WorkerMessageEvent) => void>();\n\n/**\n * Type safe wrapper for worker code\n */\nexport default class WorkerBody {\n /** Check that we are actually in a worker thread */\n static async inWorkerThread(): Promise<boolean> {\n return typeof self !== 'undefined' || Boolean(await getParentPort());\n }\n\n /*\n * (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n */\n static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any) {\n async function handleMessage(message) {\n const parentPort = await getParentPort();\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const {type, payload} = parentPort ? message : message.data;\n // if (!isKnownMessage(message)) {\n // return;\n // }\n onMessage(type, payload);\n }\n\n getParentPort().then(parentPort => {\n if (parentPort) {\n parentPort.on('message', message => {\n handleMessage(message);\n });\n // if (message == 'exit') { parentPort.unref(); }\n // eslint-disable-next-line\n parentPort.on('exit', () => console.debug('Node worker closing'));\n } else {\n // eslint-disable-next-line no-restricted-globals\n globalThis.onmessage = handleMessage;\n }\n });\n }\n\n static async addEventListener(onMessage: WorkerMessageListener) {\n let onMessageWrapper = onMessageWrapperMap.get(onMessage);\n\n if (!onMessageWrapper) {\n onMessageWrapper = (message: WorkerMessageEvent) => {\n const messageData = getWorkerMessageData(message);\n if (!messageData) {\n return;\n }\n onMessage(messageData.type, messageData.payload);\n };\n onMessageWrapperMap.set(onMessage, onMessageWrapper);\n }\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.on('message', onMessageWrapper);\n } else {\n globalThis.addEventListener('message', onMessageWrapper);\n }\n }\n\n static async removeEventListener(onMessage: WorkerMessageListener) {\n const onMessageWrapper = onMessageWrapperMap.get(onMessage);\n onMessageWrapperMap.delete(onMessage);\n if (!onMessageWrapper) {\n return;\n }\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.off('message', onMessageWrapper);\n } else {\n globalThis.removeEventListener('message', onMessageWrapper);\n }\n }\n\n /**\n * Send a message from a worker to creating thread (main thread)\n * @param type\n * @param payload\n */\n static async postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): Promise<void> {\n const data: WorkerMessageData = {source: 'loaders.gl', type, payload};\n // console.log('posting message', data);\n\n // Cast to Node compatible transfer list\n const transferList = getTransferList(payload) as TransferListItem[];\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.postMessage(data, transferList);\n // console.log('posted message', data);\n } else {\n // @ts-expect-error Outside of worker scopes this call has a third parameter\n globalThis.postMessage(data, transferList);\n }\n }\n}\n\n// Filter out noise messages sent to workers\nfunction getWorkerMessageData(message: WorkerMessageEvent): WorkerMessageData | null {\n if (!message || typeof message !== 'object') {\n return null;\n }\n const messageData = 'data' in message && message.type === 'message' ? message.data : message;\n return messageData &&\n typeof messageData.source === 'string' &&\n messageData.source.startsWith('loaders.gl')\n ? messageData\n : null;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {\n WorkerProgress,\n WorkerMessageType,\n WorkerMessagePayload,\n WorkerContext,\n WorkerJobContext,\n Process,\n ProcessInBatches\n} from '../../types';\nimport AsyncQueue from '../async-queue/async-queue';\nimport WorkerBody from '../worker-farm/worker-body';\n// import {validateWorkerVersion} from './validate-worker-version';\n\n/** Counter for jobs */\nlet requestId = 0;\nlet activeInputBatches: AsyncQueue<any> | null = null;\nlet activeOutputAcknowledgements: AsyncQueue<void> | null = null;\n\nexport type ProcessOnMainThread = (\n data: any,\n options?: {[key: string]: any},\n jobContext?: WorkerJobContext\n) => any;\n\n/**\n * Set up a WebWorkerGlobalScope to talk with the main thread\n */\nexport async function createWorker(\n process: Process,\n processInBatches?: ProcessInBatches\n): Promise<void> {\n if (!(await WorkerBody.inWorkerThread())) {\n return;\n }\n\n const context: WorkerContext = {\n process: processOnMainThread\n };\n\n // eslint-disable-next-line complexity\n WorkerBody.onmessage = async (type: WorkerMessageType, payload: WorkerMessagePayload) => {\n const reporter =\n type === 'process' || type === 'process-in-batches' ? createProgressReporter() : undefined;\n const jobContext = {...context, reportProgress: reporter?.report};\n try {\n switch (type) {\n case 'preload':\n WorkerBody.postMessage('done', {});\n break;\n\n case 'process':\n if (!process) {\n throw new Error('Worker does not support atomic processing');\n }\n const result = await process(\n payload.input,\n payload.options || {},\n jobContext,\n payload.context || {}\n );\n reporter?.finish();\n WorkerBody.postMessage('done', {result});\n break;\n\n case 'process-in-batches':\n if (!processInBatches) {\n throw new Error('Worker does not support batched processing');\n }\n const inputBatches = new AsyncQueue<any>();\n const outputAcknowledgements = new AsyncQueue<void>();\n activeInputBatches = inputBatches;\n activeOutputAcknowledgements = outputAcknowledgements;\n try {\n const resultIterator = processInBatches(\n createDemandDrivenIterator(inputBatches),\n payload.options || {},\n jobContext,\n payload.context || {}\n );\n for await (const batch of resultIterator) {\n await WorkerBody.postMessage('output-batch', {result: batch});\n await outputAcknowledgements.next();\n }\n reporter?.finish();\n await WorkerBody.postMessage('done', {});\n } finally {\n activeInputBatches = null;\n activeOutputAcknowledgements = null;\n }\n break;\n\n case 'input-batch':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.push(payload.input);\n break;\n\n case 'input-done':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.close();\n break;\n\n case 'output-ack':\n if (!activeOutputAcknowledgements) {\n throw new Error('Worker has no active batched processing session');\n }\n activeOutputAcknowledgements.push(undefined);\n break;\n\n default:\n }\n } catch (error) {\n reporter?.finish();\n const message = error instanceof Error ? error.message : '';\n WorkerBody.postMessage('error', {error: message});\n }\n };\n}\n\n/** Requests exactly one input batch whenever the worker-side processor advances its iterator. */\nasync function* createDemandDrivenIterator(inputBatches: AsyncQueue<any>): AsyncIterable<any> {\n while (true) {\n await WorkerBody.postMessage('input-request', {});\n const nextBatch = await inputBatches.next();\n if (nextBatch.done) {\n return;\n }\n yield nextBatch.value;\n }\n}\n\nfunction processOnMainThread(arrayBuffer: ArrayBuffer, options = {}, jobContext = {}) {\n return new Promise((resolve, reject) => {\n const id = requestId++;\n\n /**\n */\n const onMessage = (type: string, payload: WorkerMessagePayload) => {\n if (payload.id !== id) {\n // not ours\n return;\n }\n\n switch (type) {\n case 'done':\n WorkerBody.removeEventListener(onMessage);\n resolve(payload.result);\n break;\n\n case 'error':\n WorkerBody.removeEventListener(onMessage);\n reject(payload.error);\n break;\n\n default:\n // ignore\n }\n };\n\n WorkerBody.addEventListener(onMessage);\n\n // Ask the main thread to decode data\n const payload = {id, input: arrayBuffer, options, context: jobContext};\n WorkerBody.postMessage('process', payload);\n });\n}\n\n/** Coalesces same-phase reports per event-loop turn and flushes before settlement. */\nfunction createProgressReporter() {\n let pending: WorkerProgress | undefined;\n let finished = false;\n let scheduled = false;\n /** Posts the latest pending measurement. */\n const flush = (): void => {\n scheduled = false;\n if (pending) {\n WorkerBody.postMessage('progress', {progress: pending});\n pending = undefined;\n }\n };\n return {\n /** Records progress while retaining phase transitions. */\n report(progress: WorkerProgress): void {\n if (finished) return;\n if (pending && pending.phase !== progress.phase) flush();\n pending = {...progress};\n if (!scheduled) {\n scheduled = true;\n setTimeout(flush, 0);\n }\n },\n /** Flushes final progress and suppresses reports from stale callbacks. */\n finish(): void {\n flush();\n finished = true;\n }\n };\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(\n async data => {\n // @ts-ignore\n return data;\n },\n /** Echoes batches together with session-local state for worker protocol tests. */\n async function* processInBatches(iterator) {\n let batchIndex = 0;\n for await (const input of iterator) {\n yield {input, batchIndex};\n batchIndex++;\n }\n }\n);\n"],
5
- "mappings": ";;;AAmBA,MAAqB,aAArB,MAAmC;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IAER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C,WAAW;AACd,sBAAY;AACZ,qBAAW,OAAO,CAAC;AAAA,QACrB;AAAA,MACF;AAAA;AAAA,MAEA,SAAe;AACb,cAAM;AACN,mBAAW;AAAA,MACb;AAAA,IACF;AAAA,EACF;;;ACtMA;AAAA,IACE,OAAM,SAAQ;AAEZ,aAAO;AAAA,IACT;AAAA;AAAA,IAEA,gBAAgB,iBAAiB,UAAU;AACzC,UAAI,aAAa;AACjB,uBAAiB,SAAS,UAAU;AAClC,cAAM,EAAC,OAAO,WAAU;AACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF;",
6
- "names": ["parentPort", "processInBatches", "payload"]
3
+ "sources": ["../../../../node_modules/@math.gl/core/src/worker-utils/lib/node/worker_threads-browser.ts", "../../../../node_modules/@math.gl/core/src/worker-utils/lib/worker-utils/get-transfer-list.ts", "../../../../node_modules/@math.gl/core/src/worker-utils/lib/worker-farm/worker-body.ts", "../../../../node_modules/@math.gl/core/src/worker-utils/lib/async-queue/async-queue.ts", "../../../../node_modules/@math.gl/core/src/worker-utils/lib/worker-api/shared-state.ts", "../../../../node_modules/@math.gl/core/src/worker-utils/lib/worker-api/create-worker.ts", "../../../../node_modules/@math.gl/core/src/worker-utils/index.ts", "../../src/worker-utils/workers/null-worker.ts"],
4
+ "sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors\n\n/** Browser polyfill for Node.js built-in `worker_threads` module.\n * These fills are non-functional, and just intended to ensure that\n * `import 'worker_threads` doesn't break browser builds.\n * The replacement is done in package.json browser field\n */\nexport class NodeWorker {\n /** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */\n constructor(...arguments_: unknown[]) {\n const runtimeProcess = (\n globalThis as {\n process?: {\n getBuiltinModule?: (specifier: string) => {\n Worker?: new (...workerArguments: unknown[]) => NodeWorker;\n };\n };\n }\n ).process;\n const WorkerConstructor = runtimeProcess?.getBuiltinModule?.('node:worker_threads').Worker;\n if (WorkerConstructor) {\n return new WorkerConstructor(...arguments_);\n }\n }\n\n /** No-op browser fallback matching the native Worker API. */\n terminate() {}\n}\n\nexport type {NodeWorker as NodeWorkerType};\n\nexport const parentPort = null;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors\n\n// NOTE - there is a copy of this function is both in core and loader-utils\n// core does not need all the utils in loader-utils, just this one.\n\n/**\n * Returns an array of Transferrable objects that can be used with postMessage\n * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage\n * @param object data to be sent via postMessage\n * @param recursive - not for application use\n * @param transfers - not for application use\n * @returns a transfer list that can be passed to postMessage\n */\nexport function getTransferList(\n object: any,\n recursive: boolean = true,\n transfers?: Set<any>\n): Transferable[] {\n // Make sure that items in the transfer list is unique\n const transfersSet = transfers || new Set();\n\n const seen = new Set<object>();\n function visit(value: any): void {\n if (!value || typeof value !== 'object' || seen.has(value)) return;\n seen.add(value);\n if (isTransferable(value)) transfersSet.add(value);\n else if (ArrayBuffer.isView(value)) {\n if (isTransferable(value.buffer)) transfersSet.add(value.buffer);\n } else if (recursive && value instanceof Map) {\n for (const [key, item] of value) {\n visit(key);\n visit(item);\n }\n } else if (recursive && value instanceof Set) {\n for (const item of value) visit(item);\n } else if (recursive) {\n for (const key of Object.keys(value)) visit(value[key]);\n }\n }\n visit(object);\n\n // If transfers is defined, is internal recursive call\n // Otherwise it's called by the user\n return transfers === undefined ? Array.from(transfersSet) : [];\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Transferable\nfunction isTransferable(object: unknown) {\n if (!object) {\n return false;\n }\n if (object instanceof ArrayBuffer) {\n return true;\n }\n if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) {\n return true;\n }\n if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) {\n return true;\n }\n // @ts-ignore\n if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) {\n return true;\n }\n return false;\n}\n\n/**\n * Recursively drop non serializable values like functions and regexps.\n * @param object\n */\nexport function getTransferListForWriter(object: object | null): object {\n const seen = new Map<object, any>();\n function clone(value: any): any {\n if (typeof value === 'function' || value instanceof RegExp) return {};\n if (!value || typeof value !== 'object') return value;\n if (seen.has(value)) return seen.get(value);\n // Preserve structured-clone built-ins and backing-buffer identity.\n if (\n ArrayBuffer.isView(value) ||\n value instanceof ArrayBuffer ||\n (typeof SharedArrayBuffer !== 'undefined' && value instanceof SharedArrayBuffer) ||\n value instanceof Date ||\n (typeof WebAssembly !== 'undefined' && value instanceof WebAssembly.Module) ||\n isTransferable(value)\n )\n return value;\n const result: any =\n value instanceof Map\n ? new Map()\n : value instanceof Set\n ? new Set()\n : Array.isArray(value)\n ? []\n : {};\n seen.set(value, result);\n if (value instanceof Map) {\n for (const [key, item] of value) result.set(clone(key), clone(item));\n } else if (value instanceof Set) {\n for (const item of value) result.add(clone(item));\n } else {\n for (const key of Object.keys(value)) {\n Object.defineProperty(result, key, {\n value: clone(value[key]),\n enumerable: true,\n writable: true,\n configurable: true\n });\n }\n }\n return result;\n }\n return object === null ? {} : clone(object);\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors\n\nimport type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n// import type {TransferListItem} from '../node/worker_threads';\nimport {parentPort} from '../node/worker_threads';\n\ntype TransferListItem = any;\ntype WorkerMessageEvent = MessageEvent<WorkerMessageData> | WorkerMessageData;\ntype WorkerMessageListener = (type: WorkerMessageType, payload: WorkerMessagePayload) => any;\n\n/** Vile hack to defeat over-zealous bundlers from stripping out the require */\nasync function getParentPort() {\n // const isNode = globalThis.process;\n // let parentPort;\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.parentPort = require(\\'worker_threads\\').parentPort'); // eslint-disable-line no-eval\n // parentPort = globalThis.parentPort;\n // } catch {\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.workerThreadsPromise = import(\\'worker_threads\\')'); // eslint-disable-line no-eval\n // const workerThreads = await globalThis.workerThreadsPromise;\n // parentPort = workerThreads.parentPort;\n // } catch (error) {\n // console.error((error as Error).message); // eslint-disable-line no-console\n // }\n // }\n return parentPort;\n}\n\nconst onMessageWrapperMap = new Map<WorkerMessageListener, (message: WorkerMessageEvent) => void>();\n\n/**\n * Type safe wrapper for worker code\n */\nexport default class WorkerBody {\n /** Check that we are actually in a worker thread */\n static async inWorkerThread(): Promise<boolean> {\n const workerGlobalScope = (globalThis as any).WorkerGlobalScope;\n return (\n (typeof workerGlobalScope === 'function' && globalThis instanceof workerGlobalScope) ||\n Boolean(await getParentPort())\n );\n }\n\n /*\n * (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n */\n static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any) {\n async function handleMessage(message) {\n const parentPort = await getParentPort();\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const {type, payload} = parentPort ? message : message.data;\n // if (!isKnownMessage(message)) {\n // return;\n // }\n onMessage(type, payload);\n }\n\n getParentPort().then(parentPort => {\n if (parentPort) {\n parentPort.on('message', message => {\n handleMessage(message);\n });\n // if (message == 'exit') { parentPort.unref(); }\n // eslint-disable-next-line\n // biome-ignore lint/suspicious/noConsole: Preserve upstream worker diagnostics.\n parentPort.on('exit', () => console.debug('Node worker closing'));\n } else {\n // eslint-disable-next-line no-restricted-globals\n globalThis.onmessage = handleMessage;\n }\n });\n }\n\n static async addEventListener(onMessage: WorkerMessageListener) {\n let onMessageWrapper = onMessageWrapperMap.get(onMessage);\n\n if (!onMessageWrapper) {\n onMessageWrapper = (message: WorkerMessageEvent) => {\n const messageData = getWorkerMessageData(message);\n if (!messageData) {\n return;\n }\n onMessage(messageData.type, messageData.payload);\n };\n onMessageWrapperMap.set(onMessage, onMessageWrapper);\n }\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.on('message', onMessageWrapper);\n } else {\n globalThis.addEventListener('message', onMessageWrapper);\n }\n }\n\n static async removeEventListener(onMessage: WorkerMessageListener) {\n const onMessageWrapper = onMessageWrapperMap.get(onMessage);\n onMessageWrapperMap.delete(onMessage);\n if (!onMessageWrapper) {\n return;\n }\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.off('message', onMessageWrapper);\n } else {\n globalThis.removeEventListener('message', onMessageWrapper);\n }\n }\n\n /**\n * Send a message from a worker to creating thread (main thread)\n * @param type\n * @param payload\n */\n static async postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): Promise<void> {\n const data: WorkerMessageData = {source: 'loaders.gl', type, payload};\n // console.log('posting message', data);\n\n // Cast to Node compatible transfer list\n const transferList = getTransferList(payload) as TransferListItem[];\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.postMessage(data, transferList);\n // console.log('posted message', data);\n } else {\n // @ts-expect-error Outside of worker scopes this call has a third parameter\n globalThis.postMessage(data, transferList);\n }\n }\n}\n\n// Filter out noise messages sent to workers\nfunction getWorkerMessageData(message: WorkerMessageEvent): WorkerMessageData | null {\n if (!message || typeof message !== 'object') {\n return null;\n }\n const messageData = 'data' in message && message.type === 'message' ? message.data : message;\n return messageData &&\n typeof messageData.source === 'string' &&\n messageData.source.startsWith('loaders.gl')\n ? messageData\n : null;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors\n\n// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license\n// http://2ality.com/2016/10/asynchronous-iteration.html\n\n/**\n * Async Queue\n * - AsyncIterable: An async iterator can be\n * - Values can be pushed onto the queue\n * @example\n * const asyncQueue = new AsyncQueue();\n * setTimeout(() => asyncQueue.enqueue('tick'), 1000);\n * setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);\n * for await (const value of asyncQueue) {\n * console.log(value); // tick\n * }\n */\nexport default class AsyncQueue<T> {\n private _values: any[];\n private _settlers: any[];\n private _closed: boolean;\n\n constructor() {\n this._values = []; // enqueues > dequeues\n this._settlers = []; // dequeues > enqueues\n this._closed = false;\n }\n\n /** Return an async iterator for this queue */\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this;\n }\n\n /** Push a new value - the async iterator will yield a promise resolved to this value */\n push(value: T): void {\n return this.enqueue(value);\n }\n\n /**\n * Push a new value - the async iterator will yield a promise resolved to this value\n * Add an error - the async iterator will yield a promise rejected with this value\n */\n enqueue(value: T | Error): void {\n if (this._closed) {\n throw new Error('Closed');\n }\n\n if (this._settlers.length > 0) {\n if (this._values.length > 0) {\n throw new Error('Illegal internal state');\n }\n const settler = this._settlers.shift();\n if (value instanceof Error) {\n settler.reject(value);\n } else {\n settler.resolve({value});\n }\n } else {\n this._values.push(value);\n }\n }\n\n /** Indicate that we not waiting for more values - The async iterator will be done */\n close(): void {\n while (this._settlers.length > 0) {\n const settler = this._settlers.shift();\n settler.resolve({done: true});\n }\n this._closed = true;\n }\n\n // ITERATOR IMPLEMENTATION\n\n /** @returns a Promise for an IteratorResult */\n next(): Promise<IteratorResult<T, any>> {\n // If values in queue, yield the first value\n if (this._values.length > 0) {\n const value = this._values.shift();\n if (value instanceof Error) {\n return Promise.reject(value);\n }\n return Promise.resolve({done: false, value});\n }\n\n // If queue is closed, the iterator is done\n if (this._closed) {\n if (this._settlers.length > 0) {\n throw new Error('Illegal internal state');\n }\n return Promise.resolve({done: true, value: undefined});\n }\n\n // Yield a promise that waits for new values to be enqueued\n return new Promise((resolve, reject) => {\n this._settlers.push({resolve, reject});\n });\n }\n}\n", "// math.gl\n// SPDX-License-Identifier: MIT\n// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors\n\nimport WorkerThread from '../worker-farm/worker-thread';\nimport {isBrowser} from '../env-utils/globals';\n\nexport type WorkerCapabilities = {\n workers: boolean;\n sharedMemory: boolean;\n crossOriginIsolated: boolean | undefined;\n sharedMemoryUnavailableReason?: 'cross-origin-isolation' | 'unsupported' | 'blocked';\n};\n\n/** Probe the actual realm; browser sharing requires COOP/COEP isolation (Node does not). */\nexport function getWorkerCapabilities(): WorkerCapabilities {\n const isolated =\n typeof globalThis.crossOriginIsolated === 'boolean'\n ? globalThis.crossOriginIsolated\n : undefined;\n const capabilities: WorkerCapabilities = {\n workers: WorkerThread.isSupported(),\n sharedMemory: false,\n crossOriginIsolated: isolated\n };\n if (isBrowser && isolated !== true) {\n capabilities.sharedMemoryUnavailableReason = 'cross-origin-isolation';\n } else if (\n typeof SharedArrayBuffer === 'undefined' ||\n typeof Atomics === 'undefined' ||\n typeof structuredClone !== 'function'\n ) {\n capabilities.sharedMemoryUnavailableReason = 'unsupported';\n } else {\n try {\n const buffer = new SharedArrayBuffer(4);\n const cloned = structuredClone(buffer);\n Atomics.store(new Int32Array(buffer), 0, 17);\n capabilities.sharedMemory = Atomics.load(new Int32Array(cloned), 0) === 17;\n if (!capabilities.sharedMemory) capabilities.sharedMemoryUnavailableReason = 'blocked';\n } catch {\n capabilities.sharedMemoryUnavailableReason = 'blocked';\n }\n }\n return capabilities;\n}\n\nexport type SharedWorkerSnapshot = {\n cancelled: boolean;\n completed: number;\n /** -1 means unknown. */\n total: number;\n revision: number;\n};\n\n/** Same-version, single-job atomic control state. Each field is atomic; snapshots are not transactions. */\nexport class SharedWorkerState {\n readonly buffer: SharedArrayBuffer;\n private values: Int32Array;\n\n constructor(buffer: SharedArrayBuffer) {\n if (\n typeof SharedArrayBuffer === 'undefined' ||\n !(buffer instanceof SharedArrayBuffer) ||\n buffer.byteLength !== 16\n )\n throw new Error('Expected a 16-byte shared worker control buffer');\n this.buffer = buffer;\n this.values = new Int32Array(buffer);\n }\n\n get snapshot(): SharedWorkerSnapshot {\n return {\n cancelled: Atomics.load(this.values, 0) !== 0,\n completed: Atomics.load(this.values, 1),\n total: Atomics.load(this.values, 2),\n revision: Atomics.load(this.values, 3)\n };\n }\n\n cancel(): void {\n Atomics.store(this.values, 0, 1);\n Atomics.add(this.values, 3, 1);\n Atomics.notify(this.values, 0);\n }\n\n throwIfCancelled(): void {\n if (Atomics.load(this.values, 0) !== 0) {\n const error = new Error('Shared worker task was cancelled');\n error.name = 'AbortError';\n throw error;\n }\n }\n\n /** Integer counters for application-defined work; messages still carry phase names and units. */\n setProgress(completed: number, total = -1): void {\n if (\n !Number.isInteger(completed) ||\n completed < 0 ||\n completed > 0x7fffffff ||\n !Number.isInteger(total) ||\n total < -1 ||\n total > 0x7fffffff\n ) {\n throw new RangeError('Shared progress requires nonnegative int32 counts (or total -1)');\n }\n Atomics.store(this.values, 1, completed);\n Atomics.store(this.values, 2, total);\n Atomics.add(this.values, 3, 1);\n }\n}\n\n/** Returns null when unavailable, leaving message-based cancellation/progress usable. */\nexport function createSharedWorkerState(): SharedWorkerState | null {\n if (!getWorkerCapabilities().sharedMemory) return null;\n const state = new SharedWorkerState(new SharedArrayBuffer(16));\n state.setProgress(0);\n return state;\n}\n\n/** Caller-side setup: opt into shared control automatically for cooperative jobs when available. */\nexport function prepareSharedState<\n T extends {cancellationMode?: string; sharedState?: SharedArrayBuffer | false}\n>(options: T): T {\n if (options.sharedState === undefined && options.cancellationMode === 'cooperative') {\n const state = createSharedWorkerState();\n return state ? {...options, sharedState: state.buffer} : options;\n }\n if (options.sharedState) {\n if (!getWorkerCapabilities().sharedMemory)\n throw new Error('Shared worker memory is unavailable');\n new SharedWorkerState(options.sharedState).throwIfCancelled();\n }\n return options;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors\n\nimport type {\n WorkerProgress,\n WorkerMessageType,\n WorkerMessagePayload,\n WorkerContext,\n WorkerJobContext,\n Process,\n ProcessInBatches\n} from '../../types';\nimport {SharedWorkerState} from './shared-state';\nimport AsyncQueue from '../async-queue/async-queue';\nimport WorkerBody from '../worker-farm/worker-body';\n// import {validateWorkerVersion} from './validate-worker-version';\n\n/** Counter for jobs */\nlet requestId = 0;\nlet activeController: AbortController | null = null;\nlet activeInputBatches: AsyncQueue<any> | null = null;\nlet activeOutputAcknowledgements: AsyncQueue<void> | null = null;\n\nexport type ProcessOnMainThread = (\n data: any,\n options?: {[key: string]: any},\n jobContext?: WorkerJobContext\n) => any;\n\n/**\n * Set up a WebWorkerGlobalScope to talk with the main thread\n */\nexport async function createWorker(\n process: Process,\n processInBatches?: ProcessInBatches\n): Promise<void> {\n if (!(await WorkerBody.inWorkerThread())) {\n return;\n }\n\n const context: WorkerContext = {\n process: processOnMainThread\n };\n\n // eslint-disable-next-line complexity\n WorkerBody.onmessage = async (type: WorkerMessageType, payload: WorkerMessagePayload) => {\n if (type === 'cancel') {\n activeController?.abort();\n activeInputBatches?.close();\n activeOutputAcknowledgements?.close();\n return;\n }\n const controller =\n type === 'process' || type === 'process-in-batches' ? new AbortController() : undefined;\n if (controller) activeController = controller;\n const startedAt = performance.now();\n const reporter =\n type === 'process' || type === 'process-in-batches' ? createProgressReporter() : undefined;\n let sharedState: SharedWorkerState | undefined;\n const throwIfAborted = () => {\n controller?.signal.throwIfAborted();\n sharedState?.throwIfCancelled();\n };\n const jobContext = {\n ...context,\n signal: controller?.signal,\n sharedState,\n throwIfAborted,\n reportProgress: (progress: WorkerProgress) => {\n if (!controller?.signal.aborted && !sharedState?.snapshot.cancelled)\n reporter?.report(progress);\n }\n };\n try {\n if (controller && payload.options?.['sharedState']) {\n sharedState = new SharedWorkerState(payload.options['sharedState']);\n jobContext.sharedState = sharedState;\n }\n switch (type) {\n case 'preload':\n WorkerBody.postMessage('done', {});\n break;\n\n case 'process':\n throwIfAborted();\n if (!process) {\n throw new Error('Worker does not support atomic processing');\n }\n const result = await process(\n payload.input,\n payload.options || {},\n jobContext,\n payload.context || {}\n );\n throwIfAborted();\n reporter?.finish();\n await WorkerBody.postMessage('done', {\n result,\n executionMs: performance.now() - startedAt\n });\n break;\n\n case 'process-in-batches':\n throwIfAborted();\n if (!processInBatches) {\n throw new Error('Worker does not support batched processing');\n }\n const inputBatches = new AsyncQueue<any>();\n const outputAcknowledgements = new AsyncQueue<void>();\n activeInputBatches = inputBatches;\n activeOutputAcknowledgements = outputAcknowledgements;\n try {\n const resultIterator = processInBatches(\n createDemandDrivenIterator(inputBatches),\n payload.options || {},\n jobContext,\n payload.context || {}\n );\n for await (const batch of resultIterator) {\n throwIfAborted();\n await WorkerBody.postMessage('output-batch', {result: batch});\n await outputAcknowledgements.next();\n }\n throwIfAborted();\n reporter?.finish();\n await WorkerBody.postMessage('done', {executionMs: performance.now() - startedAt});\n } finally {\n activeInputBatches = null;\n activeOutputAcknowledgements = null;\n }\n break;\n\n case 'input-batch':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.push(payload.input);\n break;\n\n case 'input-done':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.close();\n break;\n\n case 'output-ack':\n if (!activeOutputAcknowledgements) {\n throw new Error('Worker has no active batched processing session');\n }\n activeOutputAcknowledgements.push(undefined);\n break;\n\n default:\n }\n } catch (error) {\n reporter?.finish(controller?.signal.aborted || sharedState?.snapshot.cancelled);\n const message = error instanceof Error ? error.message : '';\n await WorkerBody.postMessage('error', {\n error: message,\n errorName: error instanceof Error ? error.name : 'Error'\n });\n } finally {\n if (controller && activeController === controller) activeController = null;\n }\n };\n await WorkerBody.postMessage('ready', {});\n}\n\n/** Requests exactly one input batch whenever the worker-side processor advances its iterator. */\nasync function* createDemandDrivenIterator(inputBatches: AsyncQueue<any>): AsyncIterable<any> {\n while (true) {\n await WorkerBody.postMessage('input-request', {});\n const nextBatch = await inputBatches.next();\n if (nextBatch.done) {\n return;\n }\n yield nextBatch.value;\n }\n}\n\nfunction processOnMainThread(arrayBuffer: ArrayBuffer, options = {}, jobContext = {}) {\n const signal = activeController?.signal;\n signal?.throwIfAborted();\n return new Promise((resolve, reject) => {\n const id = requestId++;\n const cleanup = () => {\n signal?.removeEventListener('abort', abort);\n void WorkerBody.removeEventListener(onMessage);\n };\n const abort = () => {\n cleanup();\n reject(signal?.reason);\n };\n const onMessage = (type: string, payload: WorkerMessagePayload) => {\n if (payload.id !== id) return;\n if (type === 'done') {\n cleanup();\n resolve(payload.result);\n } else if (type === 'error') {\n cleanup();\n reject(payload.error);\n }\n };\n void WorkerBody.addEventListener(onMessage)\n .then(async () => {\n if (signal?.aborted) {\n abort();\n return;\n }\n signal?.addEventListener('abort', abort, {once: true});\n await WorkerBody.postMessage('process', {\n id,\n input: arrayBuffer,\n options,\n context: jobContext\n });\n })\n .catch(error => {\n cleanup();\n reject(error);\n });\n });\n}\n\n/** Coalesces same-phase reports per event-loop turn and flushes before settlement. */\nfunction createProgressReporter() {\n let pending: WorkerProgress | undefined;\n let finished = false;\n let scheduled = false;\n /** Posts the latest pending measurement. */\n const flush = (): void => {\n scheduled = false;\n if (pending) {\n WorkerBody.postMessage('progress', {progress: pending});\n pending = undefined;\n }\n };\n return {\n /** Records progress while retaining phase transitions. */\n report(progress: WorkerProgress): void {\n if (finished) return;\n if (pending && pending.phase !== progress.phase) flush();\n pending = {...progress};\n if (!scheduled) {\n scheduled = true;\n setTimeout(flush, 0);\n }\n },\n /** Flushes final progress and suppresses reports from stale callbacks. */\n finish(discard = false): void {\n if (discard) pending = undefined;\n flush();\n finished = true;\n }\n };\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors\n\nimport type {WorkerObject} from './types';\nimport {VERSION} from './lib/env-utils/version';\ndeclare const __filename: string;\n\n// TYPES\nexport type {\n LoadWorker,\n WorkerObject,\n WorkerOptions,\n WorkerProgress,\n WorkerJobMetrics,\n WorkerPoolStats,\n WorkerContext,\n WorkerJobContext,\n Process,\n ProcessInBatches,\n // Protocol\n WorkerMessage,\n WorkerMessageType,\n WorkerMessageData,\n WorkerMessagePayload\n} from './types';\n\n// GENERAL UTILS\nexport {assert} from './lib/env-utils/assert';\nexport {isBrowser, isWorker} from './lib/env-utils/globals';\n\n// WORKER UTILS - TYPES\nexport {default as WorkerJob} from './lib/worker-farm/worker-job';\nexport {default as WorkerThread} from './lib/worker-farm/worker-thread';\n\n// WORKER FARMS\nexport {default as WorkerFarm} from './lib/worker-farm/worker-farm';\nexport {default as WorkerPool} from './lib/worker-farm/worker-pool';\nexport {default as WorkerBody} from './lib/worker-farm/worker-body';\n\n// PROCESS ON WORKER\nexport type {ProcessOnWorkerOptions} from './lib/worker-api/process-on-worker';\nexport type {PreloadWorkerOptions} from './lib/worker-api/process-on-worker';\nexport {\n processOnWorker,\n processOnWorkerInBatches,\n preloadWorker,\n canProcessOnWorker,\n canProcessOnWorkerInBatches\n} from './lib/worker-api/process-on-worker';\nexport {createWorker} from './lib/worker-api/create-worker';\n\n// WORKER UTILS - EXPORTS\nexport {getWorkerURL} from './lib/worker-api/get-worker-url';\nexport {validateWorkerVersion} from './lib/worker-api/validate-worker-version';\nexport {getTransferList, getTransferListForWriter} from './lib/worker-utils/get-transfer-list';\n\n// LIBRARY UTILS\nexport {\n extractLoadLibraryOptions,\n getLibraryUrl,\n loadLibrary,\n type LoadLibraryOptions\n} from './lib/library-utils/library-utils';\n\n// PARSER UTILS\nexport {default as AsyncQueue} from './lib/async-queue/async-queue';\n\n// WORKER OBJECTS\n\n/** A null worker to test that worker processing is functional */\nconst path = typeof __filename === 'string' ? __filename.replace(/\\\\/g, '/') : '';\nconst moduleUrl = path\n ? `file://${path.startsWith('/') ? '' : '/'}${encodeURI(path).replace(/#/g, '%23').replace(/\\?/g, '%3F')}`\n : import.meta.url;\nexport const NullWorker: WorkerObject = {\n id: 'null',\n name: 'null',\n module: 'core',\n packageName: '@math.gl/core',\n // Drop the entire URL expression when classic bundles do not use this descriptor.\n worker: /* @__PURE__ */ (() => new URL('./workers/null-worker.js', moduleUrl).href)(),\n loadWorker: () =>\n new Worker(new URL('./workers/null-worker.js', import.meta.url), {type: 'module'}),\n version: VERSION,\n options: {\n null: {}\n }\n};\n\nexport type {WorkerAdmission, WorkerPoolProps} from './lib/worker-farm/worker-pool';\nexport {createWorkerResource, createResourceWorker} from './lib/worker-api/worker-resource';\nexport type {\n WorkerResource,\n WorkerResourceRunOptions,\n WorkerResourceObject,\n ResourceRequest\n} from './lib/worker-api/worker-resource';\n\nexport {\n getWorkerCapabilities,\n createSharedWorkerState,\n SharedWorkerState\n} from './lib/worker-api/shared-state';\nexport type {WorkerCapabilities, SharedWorkerSnapshot} from './lib/worker-api/shared-state';\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(\n async data => {\n // @ts-ignore\n return data;\n },\n /** Echoes batches together with session-local state for worker protocol tests. */\n async function* processInBatches(iterator) {\n let batchIndex = 0;\n for await (const input of iterator) {\n yield {input, batchIndex};\n batchIndex++;\n }\n }\n);\n"],
5
+ "mappings": ";;;AAiCO,MAAM,aAAa;;;AClBpB,WAAU,gBACd,QACA,YAAqB,MACrB,WAAoB;AAGpB,UAAM,eAAe,aAAa,oBAAI,IAAG;AAEzC,UAAM,OAAO,oBAAI,IAAG;AACpB,aAAS,MAAM,OAAU;AACvB,UAAI,CAAC,SAAS,OAAO,UAAU,YAAY,KAAK,IAAI,KAAK;AAAG;AAC5D,WAAK,IAAI,KAAK;AACd,UAAI,eAAe,KAAK;AAAG,qBAAa,IAAI,KAAK;eACxC,YAAY,OAAO,KAAK,GAAG;AAClC,YAAI,eAAe,MAAM,MAAM;AAAG,uBAAa,IAAI,MAAM,MAAM;MACjE,WAAW,aAAa,iBAAiB,KAAK;AAC5C,mBAAW,CAAC,KAAK,IAAI,KAAK,OAAO;AAC/B,gBAAM,GAAG;AACT,gBAAM,IAAI;QACZ;MACF,WAAW,aAAa,iBAAiB,KAAK;AAC5C,mBAAW,QAAQ;AAAO,gBAAM,IAAI;MACtC,WAAW,WAAW;AACpB,mBAAW,OAAO,OAAO,KAAK,KAAK;AAAG,gBAAM,MAAM,GAAG,CAAC;MACxD;IACF;AACA,UAAM,MAAM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ACL,mBAAW;MACb;;EAEJ;;;ACjQA;AAuEA,MAAM,OAAO,OAAO,eAAe,WAAW,WAAW,QAAQ,OAAO,GAAG,IAAI;AAC/E,MAAM,YAAY,OACd,UAAU,KAAK,WAAW,GAAG,IAAI,KAAK,GAAG,GAAG,UAAU,IAAI,EAAE,QAAQ,MAAM,KAAK,EAAE,QAAQ,OAAO,KAAK,CAAC,KACtG,YAAY;;;ACpEhB;AAAA,IACE,OAAM,SAAQ;AAEZ,aAAO;AAAA,IACT;AAAA;AAAA,IAEA,gBAAgB,iBAAiB,UAAU;AACzC,UAAI,aAAa;AACjB,uBAAiB,SAAS,UAAU;AAClC,cAAM,EAAC,OAAO,WAAU;AACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF;",
6
+ "names": ["parentPort", "processInBatches"]
7
7
  }
@@ -1,100 +1,2 @@
1
- /** Progress measured independently within a named phase. */
2
- export type WorkerProgress = {
3
- /** Operation being measured. */
4
- phase: string;
5
- /** Work completed in this phase. */
6
- completed: number;
7
- /** Expected work, when known. */
8
- total?: number;
9
- /** Measurement unit, such as bytes, rows, or tasks. */
10
- unit: string;
11
- };
12
- /** Shared worker execution options. */
13
- export type WorkerOptions = {
14
- /** Cancels queued or running work. */
15
- signal?: AbortSignal;
16
- /** Receives phase progress. Throwing aborts the job with that error. */
17
- onProgress?: (progress: WorkerProgress) => void;
18
- CDN?: string | null;
19
- worker?: boolean;
20
- /** Declares batch-protocol support for a custom worker, or disables batch offloading. */
21
- workerInBatches?: boolean;
22
- maxConcurrency?: number;
23
- maxMobileConcurrency?: number;
24
- reuseWorkers?: boolean;
25
- _workerType?: string;
26
- workerUrl?: string;
27
- [key: string]: any;
28
- };
29
- /**
30
- * Creates a fresh browser Worker instance for a worker descriptor.
31
- *
32
- * Returning `null` delegates to the existing URL-based worker resolution. This lets packages
33
- * expose bundler-resolved module workers without removing classic worker or CDN support.
34
- */
35
- export type LoadWorker = () => Worker | null;
36
- export type WorkerContext = {
37
- /** Reports progress from the active worker job. */
38
- reportProgress?: (progress: WorkerProgress) => void;
39
- process?: Process;
40
- processInBatches?: ProcessInBatches;
41
- };
42
- /** Serializable context sent with a single worker job. */
43
- export type WorkerJobContext = {
44
- [key: string]: any;
45
- };
46
- export type Process = (data: any, options?: {
47
- [key: string]: any;
48
- }, context?: WorkerContext, jobContext?: WorkerJobContext) => any;
49
- export type ProcessInBatches = (iterator: AsyncIterable<any> | Iterable<any>, options?: {
50
- [key: string]: any;
51
- }, context?: WorkerContext, jobContext?: WorkerJobContext) => AsyncIterable<any>;
52
- /**
53
- * A worker description object
54
- */
55
- export type WorkerObject = {
56
- id: string;
57
- name: string;
58
- module: string;
59
- version: string;
60
- worker?: string | boolean;
61
- /** Whether the built-in worker accepts stateful batch requests. */
62
- workerInBatches?: boolean;
63
- /** Browser worker filename when it differs from the worker id. */
64
- workerFile?: string;
65
- /** Creates a built-in browser worker, typically using `type: 'module'`. */
66
- loadWorker?: LoadWorker;
67
- /** Optional Node.js-specific worker filename (for example a `.cjs` asset). */
68
- workerNode?: string;
69
- /** Repository-relative source path for a Node test worker after package grouping. */
70
- workerSourceNode?: string;
71
- options: {
72
- [key: string]: any;
73
- };
74
- deprecatedOptions?: object;
75
- process?: Process;
76
- processInBatches?: ProcessInBatches;
77
- };
78
- export type WorkerMessageType = 'progress' | 'preload' | 'process' | 'done' | 'error' | 'process-in-batches' | 'input-request' | 'input-batch' | 'input-done' | 'output-batch' | 'output-ack';
79
- export type WorkerMessagePayload = {
80
- /** Phase progress from the worker. */
81
- progress?: WorkerProgress;
82
- id?: number;
83
- options?: {
84
- [key: string]: any;
85
- };
86
- context?: WorkerJobContext;
87
- input?: any;
88
- result?: any;
89
- error?: string;
90
- };
91
- export type WorkerMessageData = {
92
- source: 'loaders.gl';
93
- type: WorkerMessageType;
94
- payload: WorkerMessagePayload;
95
- };
96
- export type WorkerMessage = {
97
- type: string;
98
- data: WorkerMessageData;
99
- };
1
+ export type { LoadWorker, WorkerObject, WorkerOptions, WorkerProgress, WorkerContext, WorkerJobContext, Process, ProcessInBatches, WorkerMessage, WorkerMessageType, WorkerMessageData, WorkerMessagePayload } from '@math.gl/core/tasks';
100
2
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/worker-utils/types.ts"],"names":[],"mappings":"AAIA,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GAAG;IAC3B,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,uCAAuC;AACvC,MAAM,MAAM,aAAa,GAAG;IAC1B,sCAAsC;IACtC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,wEAAwE;IACxE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IAEhD,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yFAAyF;IACzF,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,MAAM,GAAG,IAAI,CAAC;AAE7C,MAAM,MAAM,aAAa,GAAG;IAC1B,mDAAmD;IACnD,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IACpD,OAAO,CAAC,EAAE,OAA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B,CAAC,EAAE,MAAM,CAAC;IAE3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC,CAAC;AAqBF,MAAM,MAAM,iBAAiB,GACzB,UAAU,GACV,SAAS,GACT,SAAS,GACT,MAAM,GACN,OAAO,GACP,oBAAoB,GACpB,eAAe,GACf,aAAa,GACb,YAAY,GACZ,cAAc,GACd,YAAY,CAAC;AAEjB,MAAM,MAAM,oBAAoB,GAAG;IACjC,sCAAsC;IACtC,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,oBAAoB,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,CAAC;CACzB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/worker-utils/types.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,OAAO,EACP,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loaders.gl/core",
3
- "version": "5.0.0-beta.1",
4
- "description": "The core API for working with loaders.gl loaders and writers",
3
+ "version": "5.0.0-beta.2",
4
+ "description": "Core loading and writing APIs, workers, schemas, and geometry utilities for loaders.gl",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "publishConfig": {
@@ -22,7 +22,13 @@
22
22
  "mesh",
23
23
  "point cloud",
24
24
  "webgl",
25
- "webgpu"
25
+ "webgpu",
26
+ "loaders.gl",
27
+ "Arrow",
28
+ "GeoArrow",
29
+ "GeoJSON",
30
+ "WKT",
31
+ "WKB"
26
32
  ],
27
33
  "types": "dist/index.d.ts",
28
34
  "main": "dist/index.cjs",
@@ -163,10 +169,10 @@
163
169
  "import": "./dist/geoarrow/clustering/cluster-index.js",
164
170
  "require": "./dist/geoarrow/clustering/cluster-index.cjs"
165
171
  },
166
- "./geoarrow/cluster-source": {
167
- "types": "./dist/geoarrow/clustering/cluster-source.d.ts",
168
- "import": "./dist/geoarrow/clustering/cluster-source.js",
169
- "require": "./dist/geoarrow/clustering/cluster-source.cjs"
172
+ "./cluster-source": {
173
+ "types": "./dist/cluster-source.d.ts",
174
+ "import": "./dist/cluster-source.js",
175
+ "require": "./dist/cluster-source.cjs"
170
176
  },
171
177
  "./geoarrow/get-representative-point": {
172
178
  "types": "./dist/geoarrow/clustering/get-representative-point.d.ts",
@@ -298,15 +304,15 @@
298
304
  "import": "./dist/scan/scan-query.js",
299
305
  "require": "./dist/scan/scan-query.cjs"
300
306
  },
301
- "./scan/federated-table-scan-source": {
302
- "types": "./dist/scan/federated-table-scan-source.d.ts",
303
- "import": "./dist/scan/federated-table-scan-source.js",
304
- "require": "./dist/scan/federated-table-scan-source.cjs"
307
+ "./federated-table-scan-source": {
308
+ "types": "./dist/federated-table-scan-source.d.ts",
309
+ "import": "./dist/federated-table-scan-source.js",
310
+ "require": "./dist/federated-table-scan-source.cjs"
305
311
  },
306
- "./scan/vector-table-scan-source": {
307
- "types": "./dist/scan/vector-table-scan-source.d.ts",
308
- "import": "./dist/scan/vector-table-scan-source.js",
309
- "require": "./dist/scan/vector-table-scan-source.cjs"
312
+ "./vector-table-scan-source": {
313
+ "types": "./dist/vector-table-scan-source.d.ts",
314
+ "import": "./dist/vector-table-scan-source.js",
315
+ "require": "./dist/vector-table-scan-source.cjs"
310
316
  },
311
317
  "./wkt": {
312
318
  "types": "./dist/wkt/index.d.ts",
@@ -378,28 +384,20 @@
378
384
  "build-constants": "esbuild src/constants/index.ts --bundle --platform=node --format=cjs --outfile=dist/constants/index.cjs"
379
385
  },
380
386
  "dependencies": {
381
- "@math.gl/core": "5.0.0-beta.1",
382
- "@math.gl/geometry": "5.0.0-beta.1",
383
- "@math.gl/geospatial": "5.0.0-beta.1",
387
+ "@math.gl/core": "5.0.0-beta.2",
388
+ "@math.gl/geometry": "5.0.0-beta.2",
389
+ "@math.gl/geospatial": "5.0.0-beta.2",
384
390
  "@types/geojson": "^7946.0.7",
385
391
  "apache-arrow": ">= 17.0.0",
386
392
  "probe.gl": "^5.0.0",
387
393
  "zod": "^4.1.12"
388
394
  },
389
- "gitHead": "89312301ed9e8ec89a58501c052a38284d1570c1",
395
+ "gitHead": "d259e5bc74caf8d75e808314b7fef2fa1bd70ff7",
390
396
  "peerDependencies": {
391
- "get-pixels": "^3.3.3",
392
- "ndarray": "^1.0.19",
393
- "save-pixels": "^2.3.6"
397
+ "sharp": "^0.35.5"
394
398
  },
395
399
  "peerDependenciesMeta": {
396
- "get-pixels": {
397
- "optional": true
398
- },
399
- "ndarray": {
400
- "optional": true
401
- },
402
- "save-pixels": {
400
+ "sharp": {
403
401
  "optional": true
404
402
  }
405
403
  }
@@ -0,0 +1 @@
1
+ export * from './geoarrow/clustering/cluster-source.js';
@@ -0,0 +1 @@
1
+ export * from './scan/federated-table-scan-source.js';
@@ -9,8 +9,8 @@ Under Node.js, importing `@loaders.gl/core/polyfills` also installs the minimal
9
9
  - a global `ImageBitmap` polyfill backed by decoded pixel data
10
10
  - a global `getImageBitmapData(image)` helper that unwraps that bitmap back to `{data, width, height}`
11
11
 
12
- This image support is intentionally minimal. It is designed for `ImageBitmapLoader` and parsed-image helpers, not as a full `createImageBitmap()` implementation.
12
+ This image support is intentionally minimal. It is designed for `ImageLoader` and parsed-image helpers, not as a full `createImageBitmap()` implementation.
13
13
 
14
- Image decoding and encoding also require the optional `get-pixels`, `ndarray`, and `save-pixels` packages. Install them only when those image operations are needed.
14
+ Node image decoding and encoding require the optional `sharp` peer dependency (`npm install sharp`). Other polyfills work without it, and it is loaded only when an image operation is requested.
15
15
 
16
16
  For documentation please visit the [website](https://loaders.gl).
@@ -1,45 +1,52 @@
1
- // loaders.gl
2
1
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
2
 
5
- // Use stackgl modules for DOM-less reading and writing of images
3
+ import {PassThrough} from 'node:stream';
4
+ import {loadSharp} from './load-sharp';
5
+ import {toArrayBuffer} from '../utils/buffer-utils';
6
6
 
7
- import savePixels from 'save-pixels';
8
- import ndarray from 'ndarray';
9
- import {bufferToArrayBuffer} from '../buffer/to-array-buffer.node.js';
7
+ /** Raw RGBA image accepted by the Node encoder. */
8
+ type NodeImageData = {
9
+ /** Interleaved RGBA pixels. */
10
+ data: Uint8Array;
11
+ /** Width in pixels. */
12
+ width: number;
13
+ /** Height in pixels. */
14
+ height: number;
15
+ };
10
16
 
11
- /**
12
- * Returns data bytes representing a compressed image in PNG or JPG format,
13
- * This data can be saved using file system (f) methods or
14
- * used in a request.
15
- * @param image to save
16
- * @param options
17
- * @param options.type='png' - png, jpg or image/png, image/jpg are valid
18
- * @param options.dataURI - Whether to include a data URI header
19
- * @return {*} bytes
20
- */
21
- export function encodeImageToStreamNode(
22
- image: {data: any; width: number; height: number},
23
- options: {type?: string; dataURI?: string}
24
- ) {
25
- // Support MIME type strings
26
- const type = options.type ? options.type.replace('image/', '') : 'jpeg';
27
- const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
17
+ /** Options for the Node image encoder. */
18
+ type NodeImageEncoderOptions = {
19
+ /** Output format name or MIME type; defaults to JPEG. */
20
+ type?: string;
21
+ /** Legacy option retained for callers. */
22
+ dataURI?: string;
23
+ };
28
24
 
29
- // Note: savePixels returns a stream
30
- return savePixels(pixels, type, options);
25
+ /** Encodes raw RGBA pixels with the optional Sharp backend. */
26
+ export async function encodeImageNode(
27
+ image: NodeImageData,
28
+ options: NodeImageEncoderOptions = {}
29
+ ): Promise<ArrayBuffer> {
30
+ const sharp = await loadSharp();
31
+ const requestedFormat = (options.type || 'jpeg').toLowerCase().replace(/^image\//, '');
32
+ const format = requestedFormat === 'jpg' ? 'jpeg' : requestedFormat;
33
+ const encodedImage = await sharp(Buffer.from(image.data), {
34
+ raw: {width: image.width, height: image.height, channels: 4}
35
+ })
36
+ .toFormat(format as keyof import('sharp').FormatEnum)
37
+ .toBuffer();
38
+ return toArrayBuffer(encodedImage);
31
39
  }
32
40
 
33
- export function encodeImageNode(image, options) {
34
- const imageStream = encodeImageToStreamNode(image, options);
35
-
36
- return new Promise(resolve => {
37
- const buffers: any[] = [];
38
- imageStream.on('data', buffer => buffers.push(buffer));
39
- // TODO - convert to arraybuffer?
40
- imageStream.on('end', () => {
41
- const buffer = Buffer.concat(buffers);
42
- resolve(bufferToArrayBuffer(buffer));
43
- });
44
- });
41
+ /** Streams an encoded image and forwards codec loading and encoding failures. */
42
+ export function encodeImageToStreamNode(
43
+ image: NodeImageData,
44
+ options: NodeImageEncoderOptions = {}
45
+ ): PassThrough {
46
+ const stream = new PassThrough();
47
+ void encodeImageNode(image, options).then(
48
+ arrayBuffer => stream.end(Buffer.from(arrayBuffer)),
49
+ error => stream.destroy(error)
50
+ );
51
+ return stream;
45
52
  }
@@ -1,40 +1,5 @@
1
- // loaders.gl
2
1
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import type {parseImageNode as parseImageImplementation} from './parse-image-node';
6
- import type {encodeImageNode as encodeImageImplementation} from './encode-image-node';
7
2
 
3
+ export {parseImageNode} from './parse-image-node';
4
+ export {encodeImageNode} from './encode-image-node';
8
5
  export {NODE_FORMAT_SUPPORT} from './node-image-formats';
9
-
10
- /** Loads the optional image decoder only when pixel decoding is requested. */
11
- export async function parseImageNode(
12
- ...parameters: Parameters<typeof parseImageImplementation>
13
- ): Promise<Awaited<ReturnType<typeof parseImageImplementation>>> {
14
- let decoder: typeof import('./parse-image-node');
15
- try {
16
- decoder = await import('./parse-image-node');
17
- } catch (error) {
18
- throw new Error(
19
- 'Node image decoding requires get-pixels. Install get-pixels to decode images.',
20
- {cause: error}
21
- );
22
- }
23
- return decoder.parseImageNode(...parameters);
24
- }
25
-
26
- /** Loads the optional image encoder only when image encoding is requested. */
27
- export async function encodeImageNode(
28
- ...parameters: Parameters<typeof encodeImageImplementation>
29
- ): Promise<Awaited<ReturnType<typeof encodeImageImplementation>>> {
30
- let encoder: typeof import('./encode-image-node');
31
- try {
32
- encoder = await import('./encode-image-node');
33
- } catch (error) {
34
- throw new Error(
35
- 'Node image encoding requires save-pixels and ndarray. Install save-pixels and ndarray to encode images.',
36
- {cause: error}
37
- );
38
- }
39
- return encoder.encodeImageNode(...parameters);
40
- }
@@ -0,0 +1,13 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ /** Loads the optional Node image codec only when image processing is requested. */
4
+ export async function loadSharp(): Promise<typeof import('sharp').default> {
5
+ try {
6
+ return (await import('sharp')).default;
7
+ } catch (error) {
8
+ throw new Error(
9
+ "Node image decoding and encoding require the optional 'sharp' package. Install it with 'npm install sharp'.",
10
+ {cause: error}
11
+ );
12
+ }
13
+ }
@@ -10,7 +10,7 @@ type NodeImageData = {
10
10
 
11
11
  /**
12
12
  * Minimal Node.js `ImageBitmap` polyfill backed by decoded pixel data.
13
- * This is intentionally limited to the functionality needed by `ImageBitmapLoader`
13
+ * This is intentionally limited to the functionality needed by `ImageLoader`
14
14
  * and `getImageBitmapData()`.
15
15
  */
16
16
  export class NodeImageBitmap {
@@ -1,6 +1,12 @@
1
- // loaders.gl
2
1
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
2
 
5
- /** Image MIME types supported when the optional Node decoder is installed. */
6
- export const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
3
+ /** Image MIME types supported by the optional Sharp Node backend. */
4
+ export const NODE_FORMAT_SUPPORT = [
5
+ 'image/png',
6
+ 'image/jpeg',
7
+ 'image/gif',
8
+ 'image/webp',
9
+ 'image/avif',
10
+ 'image/tiff',
11
+ 'image/svg+xml'
12
+ ];