@navaramap/worker 0.0.0

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 (71) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +3 -0
  3. package/dist/helpers/transferConstructedPolygonGeometry.d.ts +6 -0
  4. package/dist/helpers/transferConstructedPolylineGeometry.d.ts +6 -0
  5. package/dist/helpers/transferReturnedConstructedTerrainMesh.d.ts +6 -0
  6. package/dist/index.d.ts +4 -0
  7. package/dist/index.js +3203 -0
  8. package/dist/index.umd.cjs +11 -0
  9. package/dist/manager.d.ts +19 -0
  10. package/dist/pool.d.ts +17 -0
  11. package/dist/recyclingPool.d.ts +86 -0
  12. package/dist/tasks/constructPolygonBatchedFeature.d.ts +2 -0
  13. package/dist/tasks/constructPolylineBatchedFeature.d.ts +2 -0
  14. package/dist/tasks/constructQuantizedMeshTerrainMesh.d.ts +4 -0
  15. package/dist/tasks/constructTerrainMesh.d.ts +4 -0
  16. package/dist/tasks/getImageDataFromBlob.d.ts +12 -0
  17. package/dist/tasks/getImageDataFromImageBitmap.d.ts +1 -0
  18. package/dist/tasks/index.d.ts +26 -0
  19. package/dist/tasks/parseMvtTile.d.ts +15 -0
  20. package/dist/tasks/upsampleQuantizedMeshTerrainMesh.d.ts +2 -0
  21. package/dist/tasks/upsampleTerrainMesh.d.ts +2 -0
  22. package/dist/tasks/waitWasm.d.ts +8 -0
  23. package/dist/utils/index.d.ts +5 -0
  24. package/dist/utils/toExtentRadianF32Like.d.ts +3 -0
  25. package/dist/utils/toPolygonMaterialLike.d.ts +3 -0
  26. package/dist/utils/toPolylineMaterialLike.d.ts +3 -0
  27. package/dist/utils/toTransferableMartiniLike.d.ts +3 -0
  28. package/dist/utils/toTransferablePolygonBatchedFeatureLike.d.ts +3 -0
  29. package/dist/utils/toTransferablePolylineBatchedFeatureLike.d.ts +3 -0
  30. package/dist/utils/toTransferableRasterDEMDataLike.d.ts +3 -0
  31. package/dist/utils/toTransferableTileLike.d.ts +5 -0
  32. package/dist/utils/toUpsamplableTerrainGeometryLike.d.ts +3 -0
  33. package/dist/utils/toVec3Like.d.ts +3 -0
  34. package/dist/worker/index.d.ts +4 -0
  35. package/dist/worker/transfer.d.ts +1 -0
  36. package/package.json +37 -0
  37. package/src/helpers/transferConstructedPolygonGeometry.ts +25 -0
  38. package/src/helpers/transferConstructedPolylineGeometry.ts +28 -0
  39. package/src/helpers/transferReturnedConstructedTerrainMesh.ts +21 -0
  40. package/src/index.ts +4 -0
  41. package/src/manager.test.ts +45 -0
  42. package/src/manager.ts +43 -0
  43. package/src/pool.test.ts +87 -0
  44. package/src/pool.ts +150 -0
  45. package/src/recyclingPool.test.ts +404 -0
  46. package/src/recyclingPool.ts +385 -0
  47. package/src/tasks/constructPolygonBatchedFeature.ts +40 -0
  48. package/src/tasks/constructPolylineBatchedFeature.ts +36 -0
  49. package/src/tasks/constructQuantizedMeshTerrainMesh.ts +36 -0
  50. package/src/tasks/constructTerrainMesh.ts +44 -0
  51. package/src/tasks/getImageDataFromBlob.ts +30 -0
  52. package/src/tasks/getImageDataFromImageBitmap.ts +19 -0
  53. package/src/tasks/index.ts +31 -0
  54. package/src/tasks/parseMvtTile.ts +67 -0
  55. package/src/tasks/upsampleQuantizedMeshTerrainMesh.ts +38 -0
  56. package/src/tasks/upsampleTerrainMesh.ts +40 -0
  57. package/src/tasks/waitWasm.ts +19 -0
  58. package/src/utils/index.ts +5 -0
  59. package/src/utils/toExtentRadianF32Like.ts +6 -0
  60. package/src/utils/toPolygonMaterialLike.ts +20 -0
  61. package/src/utils/toPolylineMaterialLike.ts +17 -0
  62. package/src/utils/toTransferableMartiniLike.ts +6 -0
  63. package/src/utils/toTransferablePolygonBatchedFeatureLike.ts +41 -0
  64. package/src/utils/toTransferablePolylineBatchedFeatureLike.ts +21 -0
  65. package/src/utils/toTransferableRasterDEMDataLike.ts +22 -0
  66. package/src/utils/toTransferableTileLike.ts +34 -0
  67. package/src/utils/toUpsamplableTerrainGeometryLike.ts +14 -0
  68. package/src/utils/toVec3Like.ts +6 -0
  69. package/src/vite-env.d.ts +1 -0
  70. package/src/worker/index.ts +44 -0
  71. package/src/worker/transfer.ts +6 -0
@@ -0,0 +1,11 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@navaramap/engine`),require(`@navaramap/engine-worker`)):typeof define==`function`&&define.amd?define([`exports`,`@navaramap/engine`,`@navaramap/engine-worker`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.NavaraWorker={},e._navaramap_engine,e._navaramap_engine_worker))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e},d=(e,t,n)=>(n=e==null?{}:r(s(e)),u(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e));n=d(n,1);var f=!0,p=`Invariant failed`;function m(e,t){if(!e){if(f)throw Error(p);var n=typeof t==`function`?t():t,r=n?`${p}: ${n}`:p;throw Error(r)}}var h=l(((e,t)=>{t.exports={}})),g=l(((e,t)=>{var n=function(e){return e!==void 0&&e.versions!=null&&e.versions.node!=null&&e+``==`[object process]`};t.exports.isNode=n,t.exports.platform=typeof process<`u`&&n(process)?`node`:`browser`;var r=t.exports.platform===`node`&&h();t.exports.isMainThread=t.exports.platform===`node`?(!r||r.isMainThread)&&!process.connected:typeof Window<`u`,t.exports.cpus=t.exports.platform===`browser`?self.navigator.hardwareConcurrency:h().cpus().length})),_=l((e=>{function t(e,a){var o=this;if(!(this instanceof t))throw SyntaxError(`Constructor must be called with the new operator`);if(typeof e!=`function`)throw SyntaxError(`Function parameter handler(resolve, reject) missing`);var s=[],c=[];this.resolved=!1,this.rejected=!1,this.pending=!0,this[Symbol.toStringTag]=`Promise`;var l=function(e,t){s.push(e),c.push(t)};this.then=function(e,r){return new t(function(t,i){var a=e?n(e,t,i):t,o=r?n(r,t,i):i;l(a,o)},o)};var u=function(e){return o.resolved=!0,o.rejected=!1,o.pending=!1,s.forEach(function(t){t(e)}),l=function(t,n){t(e)},u=d=function(){},o},d=function(e){return o.resolved=!1,o.rejected=!0,o.pending=!1,c.forEach(function(t){t(e)}),l=function(t,n){n(e)},u=d=function(){},o};this.cancel=function(){return a?a.cancel():d(new r),o},this.timeout=function(e){if(a)a.timeout(e);else{var t=setTimeout(function(){d(new i(`Promise timed out after `+e+` ms`))},e);o.always(function(){clearTimeout(t)})}return o},e(function(e){u(e)},function(e){d(e)})}function n(e,t,n){return function(r){try{var i=e(r);i&&typeof i.then==`function`&&typeof i.catch==`function`?i.then(t,n):t(i)}catch(e){n(e)}}}t.prototype.catch=function(e){return this.then(null,e)},t.prototype.always=function(e){return this.then(e,e)},t.prototype.finally=function(e){let n=this,r=function(){return new t(e=>e()).then(e).then(()=>n)};return this.then(r,r)},t.all=function(e){return new t(function(t,n){var r=e.length,i=[];r?e.forEach(function(e,a){e.then(function(e){i[a]=e,r--,r==0&&t(i)},function(e){r=0,n(e)})}):t(i)})},t.defer=function(){var e={};return e.promise=new t(function(t,n){e.resolve=t,e.reject=n}),e};function r(e){this.message=e||`promise cancelled`,this.stack=Error().stack}r.prototype=Error(),r.prototype.constructor=Error,r.prototype.name=`CancellationError`,t.CancellationError=r;function i(e){this.message=e||`timeout exceeded`,this.stack=Error().stack}i.prototype=Error(),i.prototype.constructor=Error,i.prototype.name=`TimeoutError`,t.TimeoutError=i,e.Promise=t})),v=l((e=>{e.validateOptions=function(e,t,n){if(e){var r=e?Object.keys(e):[],i=r.find(e=>!t.includes(e));if(i)throw Error(`Object "`+n+`" contains an unknown option "`+i+`"`);var a=t.find(e=>Object.prototype[e]&&!r.includes(e));if(a)throw Error(`Object "`+n+`" contains an inherited option "`+a+`" which is not defined in the object itself but in its prototype. Only plain objects are allowed. Please remove the option from the prototype or override it with a value "undefined".`);return e}},e.workerOptsNames=[`credentials`,`name`,`type`],e.forkOptsNames=[`cwd`,`detached`,`env`,`execPath`,`execArgv`,`gid`,`serialization`,`signal`,`killSignal`,`silent`,`stdio`,`uid`,`windowsVerbatimArguments`,`timeout`],e.workerThreadOptsNames=[`argv`,`env`,`eval`,`execArgv`,`stdin`,`stdout`,`stderr`,`workerData`,`trackUnmanagedFds`,`transferList`,`resourceLimits`,`name`]})),ee=l(((e,t)=>{t.exports=`!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).worker=n()}(this,(function(){"use strict";function e(n){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(n)}function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t={};var r=function(e,n){this.message=e,this.transfer=n},o={};function i(e,n){var t=this;if(!(this instanceof i))throw new SyntaxError("Constructor must be called with the new operator");if("function"!=typeof e)throw new SyntaxError("Function parameter handler(resolve, reject) missing");var r=[],o=[];this.resolved=!1,this.rejected=!1,this.pending=!0,this[Symbol.toStringTag]="Promise";var a=function(e,n){r.push(e),o.push(n)};this.then=function(e,n){return new i((function(t,r){var o=e?s(e,t,r):t,i=n?s(n,t,r):r;a(o,i)}),t)};var f=function(e){return t.resolved=!0,t.rejected=!1,t.pending=!1,r.forEach((function(n){n(e)})),a=function(n,t){n(e)},f=d=function(){},t},d=function(e){return t.resolved=!1,t.rejected=!0,t.pending=!1,o.forEach((function(n){n(e)})),a=function(n,t){t(e)},f=d=function(){},t};this.cancel=function(){return n?n.cancel():d(new u),t},this.timeout=function(e){if(n)n.timeout(e);else{var r=setTimeout((function(){d(new c("Promise timed out after "+e+" ms"))}),e);t.always((function(){clearTimeout(r)}))}return t},e((function(e){f(e)}),(function(e){d(e)}))}function s(e,n,t){return function(r){try{var o=e(r);o&&"function"==typeof o.then&&"function"==typeof o.catch?o.then(n,t):n(o)}catch(e){t(e)}}}function u(e){this.message=e||"promise cancelled",this.stack=(new Error).stack}function c(e){this.message=e||"timeout exceeded",this.stack=(new Error).stack}return i.prototype.catch=function(e){return this.then(null,e)},i.prototype.always=function(e){return this.then(e,e)},i.prototype.finally=function(e){var n=this,t=function(){return new i((function(e){return e()})).then(e).then((function(){return n}))};return this.then(t,t)},i.all=function(e){return new i((function(n,t){var r=e.length,o=[];r?e.forEach((function(e,i){e.then((function(e){o[i]=e,0==--r&&n(o)}),(function(e){r=0,t(e)}))})):n(o)}))},i.defer=function(){var e={};return e.promise=new i((function(n,t){e.resolve=n,e.reject=t})),e},u.prototype=new Error,u.prototype.constructor=Error,u.prototype.name="CancellationError",i.CancellationError=u,c.prototype=new Error,c.prototype.constructor=Error,c.prototype.name="TimeoutError",i.TimeoutError=c,o.Promise=i,function(n){var t=r,i=o.Promise,s="__workerpool-cleanup__",u={exit:function(){}},c={addAbortListener:function(e){u.abortListeners.push(e)},emit:u.emit};if("undefined"!=typeof self&&"function"==typeof postMessage&&"function"==typeof addEventListener)u.on=function(e,n){addEventListener(e,(function(e){n(e.data)}))},u.send=function(e,n){n?postMessage(e,n):postMessage(e)};else{if("undefined"==typeof process)throw new Error("Script must be executed as a worker");var a;try{a=require("worker_threads")}catch(n){if("object"!==e(n)||null===n||"MODULE_NOT_FOUND"!==n.code)throw n}if(a&&null!==a.parentPort){var f=a.parentPort;u.send=f.postMessage.bind(f),u.on=f.on.bind(f),u.exit=process.exit.bind(process)}else u.on=process.on.bind(process),u.send=function(e){process.send(e)},u.on("disconnect",(function(){process.exit(1)})),u.exit=process.exit.bind(process)}function d(e){return e&&e.toJSON?JSON.parse(JSON.stringify(e)):JSON.parse(JSON.stringify(e,Object.getOwnPropertyNames(e)))}function l(e){return e&&"function"==typeof e.then&&"function"==typeof e.catch}u.methods={},u.methods.run=function(e,n){var t=new Function("return ("+e+").apply(this, arguments);");return t.worker=c,t.apply(t,n)},u.methods.methods=function(){return Object.keys(u.methods)},u.terminationHandler=void 0,u.abortListenerTimeout=1e3,u.abortListeners=[],u.terminateAndExit=function(e){var n=function(){u.exit(e)};if(!u.terminationHandler)return n();var t=u.terminationHandler(e);return l(t)?(t.then(n,n),t):(n(),new i((function(e,n){n(new Error("Worker terminating"))})))},u.cleanup=function(e){if(!u.abortListeners.length)return u.send({id:e,method:s,error:d(new Error("Worker terminating"))}),new i((function(e){e()}));var n,t=u.abortListeners.map((function(e){return e()})),r=new i((function(e,t){n=setTimeout((function(){t(new Error("Timeout occured waiting for abort handler, killing worker"))}),u.abortListenerTimeout)})),o=i.all(t).then((function(){clearTimeout(n),u.abortListeners.length||(u.abortListeners=[])}),(function(){clearTimeout(n),u.exit()}));return new i((function(e,n){o.then(e,n),r.then(e,n)})).then((function(){u.send({id:e,method:s,error:null})}),(function(n){u.send({id:e,method:s,error:n?d(n):null})}))};var p=null;u.on("message",(function(e){if("__workerpool-terminate__"===e)return u.terminateAndExit(0);if(e.method===s)return u.cleanup(e.id);try{var n=u.methods[e.method];if(!n)throw new Error('Unknown method "'+e.method+'"');p=e.id;var r=n.apply(n,e.params);l(r)?r.then((function(n){n instanceof t?u.send({id:e.id,result:n.message,error:null},n.transfer):u.send({id:e.id,result:n,error:null}),p=null})).catch((function(n){u.send({id:e.id,result:null,error:d(n)}),p=null})):(r instanceof t?u.send({id:e.id,result:r.message,error:null},r.transfer):u.send({id:e.id,result:r,error:null}),p=null)}catch(n){u.send({id:e.id,result:null,error:d(n)})}})),u.register=function(e,n){if(e)for(var t in e)e.hasOwnProperty(t)&&(u.methods[t]=e[t],u.methods[t].worker=c);n&&(u.terminationHandler=n.onTerminate,u.abortListenerTimeout=n.abortListenerTimeout||1e3),u.send("ready")},u.emit=function(e){if(p){if(e instanceof t)return void u.send({id:p,isEvent:!0,payload:e.message},e.transfer);u.send({id:p,isEvent:!0,payload:e})}},n.add=u.register,n.emit=u.emit}(t),n(t)}));
2
+ //# sourceMappingURL=worker.min.js.map
3
+ `})),y=l(((e,t)=>{var{Promise:n}=_(),r=g(),{validateOptions:i,forkOptsNames:a,workerThreadOptsNames:o,workerOptsNames:s}=v(),c=`__workerpool-terminate__`,l=`__workerpool-cleanup__`;function u(){var e=f();if(!e)throw Error(`WorkerPool: workerType = 'thread' is not supported, Node >= 11.7.0 required`);return e}function d(){if(typeof Worker!=`function`&&(typeof Worker!=`object`||typeof Worker.prototype.constructor!=`function`))throw Error(`WorkerPool: Web Workers not supported`)}function f(){try{return h()}catch(e){if(typeof e==`object`&&e&&e.code===`MODULE_NOT_FOUND`)return null;throw e}}function p(){if(r.platform===`browser`){if(typeof Blob>`u`)throw Error(`Blob not supported by the browser`);if(!window.URL||typeof window.URL.createObjectURL!=`function`)throw Error(`URL.createObjectURL not supported by the browser`);var e=new Blob([ee()],{type:`text/javascript`});return window.URL.createObjectURL(e)}else return __dirname+`/worker.js`}function m(e,t){if(t.workerType===`web`)return d(),y(e,t.workerOpts,Worker);if(t.workerType===`thread`)return n=u(),b(e,n,t);if(t.workerType===`process`||!t.workerType)return x(e,S(t),h());if(r.platform===`browser`)return d(),y(e,t.workerOpts,Worker);var n=f();return n?b(e,n,t):x(e,S(t),h())}function y(e,t,n){i(t,s,`workerOpts`);var r=new n(e,t);return r.isBrowserWorker=!0,r.on=function(e,t){this.addEventListener(e,function(e){t(e.data)})},r.send=function(e,t){this.postMessage(e,t)},r}function b(e,t,n){i(n?.workerThreadOpts,o,`workerThreadOpts`);var r=new t.Worker(e,{stdout:n?.emitStdStreams??!1,stderr:n?.emitStdStreams??!1,...n?.workerThreadOpts});return r.isWorkerThread=!0,r.send=function(e,t){this.postMessage(e,t)},r.kill=function(){return this.terminate(),!0},r.disconnect=function(){this.terminate()},n?.emitStdStreams&&(r.stdout.on(`data`,e=>r.emit(`stdout`,e)),r.stderr.on(`data`,e=>r.emit(`stderr`,e))),r}function x(e,t,n){i(t.forkOpts,a,`forkOpts`);var r=n.fork(e,t.forkArgs,t.forkOpts),o=r.send;return r.send=function(e){return o.call(r,e)},t.emitStdStreams&&(r.stdout.on(`data`,e=>r.emit(`stdout`,e)),r.stderr.on(`data`,e=>r.emit(`stderr`,e))),r.isChildProcess=!0,r}function S(e){e||={};var t=process.execArgv.join(` `),n=t.indexOf(`--inspect`)!==-1,r=t.indexOf(`--debug-brk`)!==-1,i=[];return n&&(i.push(`--inspect=`+e.debugPort),r&&i.push(`--debug-brk`)),process.execArgv.forEach(function(e){e.indexOf(`--max-old-space-size`)>-1&&i.push(e)}),Object.assign({},e,{forkArgs:e.forkArgs,forkOpts:Object.assign({},e.forkOpts,{execArgv:(e.forkOpts&&e.forkOpts.execArgv||[]).concat(i),stdio:e.emitStdStreams?`pipe`:void 0})})}function C(e){for(var t=Error(``),n=Object.keys(e),r=0;r<n.length;r++)t[n[r]]=e[n[r]];return t}function w(e,t){Object.values(e.processing).forEach(e=>e?.options?.on(t)),Object.values(e.tracking).forEach(e=>e?.options?.on(t))}function T(e,t){var n=this,r=t||{};this.script=e||p(),this.worker=m(this.script,r),this.debugPort=r.debugPort,this.forkOpts=r.forkOpts,this.forkArgs=r.forkArgs,this.workerOpts=r.workerOpts,this.workerThreadOpts=r.workerThreadOpts,this.workerTerminateTimeout=r.workerTerminateTimeout,e||(this.worker.ready=!0),this.requestQueue=[],this.worker.on(`stdout`,function(e){w(n,{stdout:e.toString()})}),this.worker.on(`stderr`,function(e){w(n,{stderr:e.toString()})}),this.worker.on(`message`,function(e){if(!n.terminated)if(typeof e==`string`&&e===`ready`)n.worker.ready=!0,a();else{var t=e.id,r=n.processing[t];if(r!==void 0)e.isEvent?r.options&&typeof r.options.on==`function`&&r.options.on(e.payload):(delete n.processing[t],n.terminating===!0&&n.terminate(),e.error?r.resolver.reject(C(e.error)):r.resolver.resolve(e.result));else{var r=n.tracking[t];r!==void 0&&e.isEvent&&r.options&&typeof r.options.on==`function`&&r.options.on(e.payload)}if(e.method===l){var i=n.tracking[e.id];i!==void 0&&(e.error?(clearTimeout(i.timeoutId),i.resolver.reject(C(e.error))):(n.tracking&&clearTimeout(i.timeoutId),i.resolver.reject(new te(i.error)))),delete n.tracking[t]}}});function i(e){for(var t in n.terminated=!0,n.processing)n.processing[t]!==void 0&&n.processing[t].resolver.reject(e);n.processing=Object.create(null)}function a(){for(let e of n.requestQueue.splice(0))n.worker.send(e.message,e.transfer)}var o=this.worker;this.worker.on(`error`,function(e){i(new E(`Workerpool Worker error: `+(e&&e.message?e.message:String(e||`Unknown worker error`)),e))}),this.worker.on(`exit`,function(e,t){var r=`Workerpool Worker terminated Unexpectedly
4
+ `;r+=" exitCode: `"+e+`\`
5
+ `,r+=" signalCode: `"+t+`\`
6
+ `,r+=" workerpool.script: `"+n.script+`\`
7
+ `,r+=" spawnArgs: `"+o.spawnargs+`\`
8
+ `,r+=" spawnfile: `"+o.spawnfile+`\`
9
+ `,r+=" stdout: `"+o.stdout+`\`
10
+ `,r+=" stderr: `"+o.stderr+`\`
11
+ `,i(new E(r))}),this.processing=Object.create(null),this.tracking=Object.create(null),this.terminating=!1,this.terminated=!1,this.cleaning=!1,this.terminationHandler=null,this.lastId=0}T.prototype.methods=function(){return this.exec(`methods`)},T.prototype.exec=function(e,t,r,i){r||=n.defer();var a=++this.lastId;this.processing[a]={id:a,resolver:r,options:i};var o={message:{id:a,method:e,params:t},transfer:i&&i.transfer};this.terminated?r.reject(new E(`Worker is terminated`)):this.worker.ready?this.worker.send(o.message,o.transfer):this.requestQueue.push(o);var s=this;return r.promise.catch(function(e){if(e instanceof n.CancellationError||e instanceof n.TimeoutError)return s.tracking[a]={id:a,resolver:n.defer(),options:i,error:e},delete s.processing[a],s.tracking[a].resolver.promise=s.tracking[a].resolver.promise.catch(function(e){if(delete s.tracking[a],e instanceof te)throw e.error;return s.terminateAndNotify(!0).then(function(){throw e},function(e){throw e})}),s.worker.send({id:a,method:l}),s.tracking[a].timeoutId=setTimeout(function(){s.tracking[a].resolver.reject(e)},s.workerTerminateTimeout),s.tracking[a].resolver.promise;throw e})},T.prototype.busy=function(){return this.cleaning||Object.keys(this.processing).length>0},T.prototype.terminate=function(e,t){var n=this;if(e){for(var r in this.processing)this.processing[r]!==void 0&&this.processing[r].resolver.reject(Error(`Worker terminated`));this.processing=Object.create(null)}for(var i of Object.values(n.tracking))clearTimeout(i.timeoutId),i.resolver.reject(Error(`Worker Terminating`));if(n.tracking=Object.create(null),typeof t==`function`&&(this.terminationHandler=t),this.busy())this.terminating=!0;else{var a=function(e){if(n.terminated=!0,n.cleaning=!1,n.worker!=null&&n.worker.removeAllListeners&&n.worker.removeAllListeners(`message`),n.worker=null,n.terminating=!1,n.terminationHandler)n.terminationHandler(e,n);else if(e)throw e};if(this.worker)if(typeof this.worker.kill==`function`){if(this.worker.killed){a(Error(`worker already killed!`));return}var o=setTimeout(function(){n.worker&&n.worker.kill()},this.workerTerminateTimeout);this.worker.once(`exit`,function(){clearTimeout(o),n.worker&&(n.worker.killed=!0),a()}),this.worker.ready?this.worker.send(c):this.requestQueue.push({message:c}),this.cleaning=!0;return}else if(typeof this.worker.terminate==`function`)this.worker.terminate(),this.worker.killed=!0;else throw Error(`Failed to terminate worker`);a()}},T.prototype.terminateAndNotify=function(e,t){var r=n.defer();return t&&r.promise.timeout(t),this.terminate(e,function(e,t){e?r.reject(e):r.resolve(t)}),r.promise};function te(e){this.error=e,this.stack=Error().stack}var E=class extends Error{constructor(e,t){super(e||`worker terminated`),this.cause=t}};t.exports=T,t.exports._tryRequireWorkerThreads=f,t.exports._setupProcessWorker=x,t.exports._setupBrowserWorker=y,t.exports._setupWorkerThreadWorker=b,t.exports.ensureWorkerThreads=u,t.exports.TerminateError=E})),b=l(((e,t)=>{function n(){this.tasks=[]}n.prototype.push=function(e){this.tasks.push(e)},n.prototype.pop=function(){return this.tasks.shift()},n.prototype.size=function(){return this.tasks.length},n.prototype.contains=function(e){return this.tasks.includes(e)},n.prototype.clear=function(){this.tasks.length=0};function r(){this.tasks=[]}r.prototype.push=function(e){this.tasks.push(e)},r.prototype.pop=function(){return this.tasks.pop()},r.prototype.size=function(){return this.tasks.length},r.prototype.contains=function(e){return this.tasks.includes(e)},r.prototype.clear=function(){this.tasks.length=0},t.exports={FIFOQueue:n,LIFOQueue:r}})),x=l(((e,t)=>{var n=65535;t.exports=r;function r(){this.ports=Object.create(null),this.length=0}r.prototype.nextAvailableStartingAt=function(e){for(;this.ports[e]===!0;)e++;if(e>=n)throw Error(`WorkerPool debug port limit reached: `+e+`>= `+n);return this.ports[e]=!0,this.length++,e},r.prototype.releasePort=function(e){delete this.ports[e],this.length--}})),S=l(((e,t)=>{var{Promise:n}=_(),r=y(),i=g(),{FIFOQueue:a,LIFOQueue:o}=b(),s=new(x());function c(e,t){typeof e==`string`?this.script=e||null:(this.script=null,t=e),this.workers=[],this.taskQueue=this._createQueue(t&&t.queueStrategy||`fifo`),t||={},this.forkArgs=Object.freeze(t.forkArgs||[]),this.forkOpts=Object.freeze(t.forkOpts||{}),this.workerOpts=Object.freeze(t.workerOpts||{}),this.workerThreadOpts=Object.freeze(t.workerThreadOpts||{}),this.debugPortStart=t.debugPortStart||43210,this.nodeWorker=t.nodeWorker,this.workerType=t.workerType||t.nodeWorker||`auto`,this.maxQueueSize=t.maxQueueSize||1/0,this.workerTerminateTimeout=t.workerTerminateTimeout||1e3,this.onCreateWorker=t.onCreateWorker||(()=>null),this.onTerminateWorker=t.onTerminateWorker||(()=>null),this.emitStdStreams=t.emitStdStreams||!1,t&&`maxWorkers`in t?(l(t.maxWorkers),this.maxWorkers=t.maxWorkers):this.maxWorkers=Math.max((i.cpus||4)-1,1),t&&`minWorkers`in t&&(t.minWorkers===`max`?this.minWorkers=this.maxWorkers:(u(t.minWorkers),this.minWorkers=t.minWorkers,this.maxWorkers=Math.max(this.minWorkers,this.maxWorkers)),this._ensureMinWorkers()),this._boundNext=this._next.bind(this),this.workerType===`thread`&&r.ensureWorkerThreads()}c.prototype.exec=function(e,t,r){if(t&&!Array.isArray(t))throw TypeError(`Array expected as argument "params"`);if(typeof e==`string`){var i=n.defer();if(this.taskQueue.size()>=this.maxQueueSize)throw Error(`Max queue size of `+this.maxQueueSize+` reached`);var a={method:e,params:t,resolver:i,timeout:null,options:r};this.taskQueue.push(a);var o=i.promise.timeout,s=this.taskQueue;return i.promise.timeout=function(e){return s.contains(a)?(a.timeout=e,i.promise):o.call(i.promise,e)},this._next(),i.promise}else if(typeof e==`function`)return this.exec(`run`,[String(e),t],r);else throw TypeError(`Function or string expected as argument "method"`)},c.prototype.proxy=function(){if(arguments.length>0)throw Error(`No arguments expected`);var e=this;return this.exec(`methods`).then(function(t){var n={};return t.forEach(function(t){n[t]=function(){return e.exec(t,Array.prototype.slice.call(arguments))}}),n})},c.prototype._next=function(){if(this.taskQueue.size()>0){var e=this._getWorker();if(e){var t=this,n=this.taskQueue.pop();if(n.resolver.promise.pending){var r=e.exec(n.method,n.params,n.resolver,n.options).then(t._boundNext).catch(function(){if(e.terminated)return t._removeWorker(e)}).then(function(){t._next()});typeof n.timeout==`number`&&r.timeout(n.timeout)}else t._next()}}},c.prototype._getWorker=function(){for(var e=this.workers,t=0;t<e.length;t++){var n=e[t];if(n.busy()===!1)return n}return e.length<this.maxWorkers?(n=this._createWorkerHandler(),e.push(n),n):null},c.prototype._removeWorker=function(e){var t=this;return s.releasePort(e.debugPort),this._removeWorkerFromList(e),this._ensureMinWorkers(),new n(function(n,r){e.terminate(!1,function(i){t.onTerminateWorker({forkArgs:e.forkArgs,forkOpts:e.forkOpts,workerThreadOpts:e.workerThreadOpts,script:e.script}),i?r(i):n(e)})})},c.prototype._removeWorkerFromList=function(e){var t=this.workers.indexOf(e);t!==-1&&this.workers.splice(t,1)},c.prototype.terminate=function(e,t){for(var r=this,i=this.taskQueue;i.size()>0;){var a=i.pop();if(a)a.resolver.reject(Error(`Pool terminated`));else break}i.clear();var o=function(e){s.releasePort(e.debugPort),this._removeWorkerFromList(e)}.bind(this),c=[];return this.workers.slice().forEach(function(n){var i=n.terminateAndNotify(e,t).then(o).always(function(){r.onTerminateWorker({forkArgs:n.forkArgs,forkOpts:n.forkOpts,workerThreadOpts:n.workerThreadOpts,script:n.script})});c.push(i)}),n.all(c)},c.prototype.stats=function(){var e=this.workers.length,t=this.workers.filter(function(e){return e.busy()}).length;return{totalWorkers:e,busyWorkers:t,idleWorkers:e-t,pendingTasks:this.taskQueue.size(),activeTasks:t}},c.prototype._ensureMinWorkers=function(){if(this.minWorkers)for(var e=this.workers.length;e<this.minWorkers;e++)this.workers.push(this._createWorkerHandler())},c.prototype._createWorkerHandler=function(){let e=this.onCreateWorker({forkArgs:this.forkArgs,forkOpts:this.forkOpts,workerOpts:this.workerOpts,workerThreadOpts:this.workerThreadOpts,script:this.script})||{};return new r(e.script||this.script,{forkArgs:e.forkArgs||this.forkArgs,forkOpts:e.forkOpts||this.forkOpts,workerOpts:e.workerOpts||this.workerOpts,workerThreadOpts:e.workerThreadOpts||this.workerThreadOpts,debugPort:s.nextAvailableStartingAt(this.debugPortStart),workerType:this.workerType,workerTerminateTimeout:this.workerTerminateTimeout,emitStdStreams:this.emitStdStreams})},c.prototype._createQueue=function(e){if(typeof e==`string`)switch(e){case`fifo`:return new a;case`lifo`:return new o;default:throw Error(`Unknown queue strategy: `+e)}if(!e)throw Error(`Queue strategy cannot be null or undefined`);for(var t=[`push`,`pop`,`size`,`contains`,`clear`],n=0;n<t.length;n++){var r=t[n];if(typeof e[r]!=`function`)throw Error(`Queue strategy must implement method: `+r)}return e};function l(e){if(!d(e)||!f(e)||e<1)throw TypeError(`Option maxWorkers must be an integer number >= 1`)}function u(e){if(!d(e)||!f(e)||e<0)throw TypeError(`Option minWorkers must be an integer number >= 0`)}function d(e){return typeof e==`number`}function f(e){return Math.round(e)==e}t.exports=c})),C=l(((e,t)=>{function n(e,t){this.message=e,this.transfer=t}t.exports=n})),w=l((e=>{var t=C(),n=_().Promise,r=`__workerpool-terminate__`,i=`__workerpool-cleanup__`,a=1e3,o={exit:function(){}},s={addAbortListener:function(e){o.abortListeners.push(e)},emit:o.emit};if(typeof self<`u`&&typeof postMessage==`function`&&typeof addEventListener==`function`)o.on=function(e,t){addEventListener(e,function(e){t(e.data)})},o.send=function(e,t){t?postMessage(e,t):postMessage(e)};else if(typeof process<`u`){var c;try{c=h()}catch(e){if(!(typeof e==`object`&&e&&e.code===`MODULE_NOT_FOUND`))throw e}if(c&&c.parentPort!==null){var l=c.parentPort;o.send=l.postMessage.bind(l),o.on=l.on.bind(l),o.exit=process.exit.bind(process)}else o.on=process.on.bind(process),o.send=function(e){process.send(e)},o.on(`disconnect`,function(){process.exit(1)}),o.exit=process.exit.bind(process)}else throw Error(`Script must be executed as a worker`);function u(e){return e&&e.toJSON?JSON.parse(JSON.stringify(e)):JSON.parse(JSON.stringify(e,Object.getOwnPropertyNames(e)))}function d(e){return e&&typeof e.then==`function`&&typeof e.catch==`function`}o.methods={},o.methods.run=function(e,t){var n=Function(`return (`+e+`).apply(this, arguments);`);return n.worker=s,n.apply(n,t)},o.methods.methods=function(){return Object.keys(o.methods)},o.terminationHandler=void 0,o.abortListenerTimeout=a,o.abortListeners=[],o.terminateAndExit=function(e){var t=function(){o.exit(e)};if(!o.terminationHandler)return t();var r=o.terminationHandler(e);return d(r)?(r.then(t,t),r):(t(),new n(function(e,t){t(Error(`Worker terminating`))}))},o.cleanup=function(e){if(!o.abortListeners.length)return o.send({id:e,method:i,error:u(Error(`Worker terminating`))}),new n(function(e){e()});var t=function(){o.exit()},r=function(){o.abortListeners.length||(o.abortListeners=[])};let a=o.abortListeners.map(e=>e()),s,c=new n((e,t)=>{s=setTimeout(function(){t(Error(`Timeout occured waiting for abort handler, killing worker`))},o.abortListenerTimeout)}),l=n.all(a).then(function(){clearTimeout(s),r()},function(){clearTimeout(s),t()});return new n(function(e,t){l.then(e,t),c.then(e,t)}).then(function(){o.send({id:e,method:i,error:null})},function(t){o.send({id:e,method:i,error:t?u(t):null})})};var f=null;o.on(`message`,function(e){if(e===r)return o.terminateAndExit(0);if(e.method===i)return o.cleanup(e.id);try{var n=o.methods[e.method];if(n){f=e.id;var a=n.apply(n,e.params);d(a)?a.then(function(n){n instanceof t?o.send({id:e.id,result:n.message,error:null},n.transfer):o.send({id:e.id,result:n,error:null}),f=null}).catch(function(t){o.send({id:e.id,result:null,error:u(t)}),f=null}):(a instanceof t?o.send({id:e.id,result:a.message,error:null},a.transfer):o.send({id:e.id,result:a,error:null}),f=null)}else throw Error(`Unknown method "`+e.method+`"`)}catch(t){o.send({id:e.id,result:null,error:u(t)})}}),o.register=function(e,t){if(e)for(var n in e)e.hasOwnProperty(n)&&(o.methods[n]=e[n],o.methods[n].worker=s);t&&(o.terminationHandler=t.onTerminate,o.abortListenerTimeout=t.abortListenerTimeout||a),o.send(`ready`)},o.emit=function(e){if(f){if(e instanceof t){o.send({id:f,isEvent:!0,payload:e.message},e.transfer);return}o.send({id:f,isEvent:!0,payload:e})}},e!==void 0&&(e.add=o.register,e.emit=o.emit)})),T=d(l((e=>{var{platform:t,isMainThread:n,cpus:r}=g(),{TerminateError:i}=y();function a(e,t){return new(S())(e,t)}e.pool=a;function o(e,t){w().add(e,t)}e.worker=o;var{Promise:s}=_();e.Transfer=C()}))(),1),te=5e3,E=3e4,ne=e=>T.pool(e,{maxWorkers:1,minWorkers:0,workerTerminateTimeout:E,workerOpts:{type:void 0}}),re=class{url;maxWorkerHeapBytes;slots;idleSweepTimer;terminated=!1;constructor(e,t,n){m(t>0,`maxWorkers must be a positive number.`),this.url=e,this.maxWorkerHeapBytes=n?.maxWorkerHeapBytes??268435456,this.slots=Array.from({length:t},()=>({pool:ne(e),tasksSinceSpawn:0,inflight:0,draining:!1,probing:!1,lastHeapBytes:void 0}))}exec(e,t,n){let r=this.pickSlot();r.inflight++;try{return r.pool.exec(e,t,n).then(e=>(this.onSettled(r),e)).catch(e=>{throw this.onSettled(r),e})}catch(e){throw this.onSettled(r),e}}warmUp(){let[e,...t]=this.slots;return this.warmSlot(e).then(()=>{for(let e of t)this.warmSlot(e).catch(()=>void 0)},e=>{if(t.length===0)throw e;return Promise.any(t.map(e=>this.warmSlot(e))).then(()=>void 0)})}canAcceptTasks(){return this.slots.some(e=>!e.draining)}stats(){let e={totalWorkers:0,busyWorkers:0,idleWorkers:0,pendingTasks:0,activeTasks:0,tasksSinceSpawn:0};for(let t of this.slots){let n=t.pool.stats();e.totalWorkers+=n.totalWorkers,e.busyWorkers+=n.busyWorkers,e.idleWorkers+=n.idleWorkers,e.pendingTasks+=n.pendingTasks,e.activeTasks+=n.activeTasks,e.tasksSinceSpawn+=t.tasksSinceSpawn}return e}heapStats(){let e=this.slots.map(e=>e.lastHeapBytes);return{perSlot:e,totalBytes:e.reduce((e,t)=>e+(t??0),0),maxWorkerHeapBytes:this.maxWorkerHeapBytes}}probeHeap(){if(!this.terminated)for(let e of this.slots)e.draining||this.probeSlot(e)}terminate(){this.idleSweepTimer!==void 0&&(clearTimeout(this.idleSweepTimer),this.idleSweepTimer=void 0),this.terminated=!0;for(let e of this.slots)e.pool.terminate()}pickSlot(){let e=this.slots.filter(e=>!e.draining);return(e.length>0?e:this.slots).reduce((e,t)=>t.inflight<e.inflight?t:e)}onSettled(e){e.inflight--,!this.terminated&&(e.tasksSinceSpawn++,e.tasksSinceSpawn>=128&&(e.draining=!0),e.draining&&e.inflight===0?this.recycleSlot(e):e.draining||this.probeSlot(e),this.armIdleSweep())}recycleSlot(e){e.pool.terminate(),e.pool=ne(this.url),e.tasksSinceSpawn=0,e.draining=!1,e.lastHeapBytes=void 0,this.warmSlot(e).catch(()=>void 0)}warmSlot(e){e.inflight++;let t=()=>{e.inflight--,!this.terminated&&e.draining&&e.inflight===0&&this.recycleSlot(e)};return new Promise((n,r)=>{try{e.pool.exec(`warmUp`).then(()=>{t(),n()}).catch(e=>{t(),r(e)})}catch(e){t(),r(e)}})}probeSlot(e){if(e.probing)return;e.probing=!0,e.inflight++;let t=t=>{e.probing=!1,e.inflight--,!this.terminated&&(t&&(e.draining=!0),e.draining&&e.inflight===0&&this.recycleSlot(e))};try{e.pool.exec(`getWasmMemoryUsage`).then(n=>{typeof n==`number`&&(e.lastHeapBytes=n),t(typeof n==`number`&&n>=this.maxWorkerHeapBytes)}).catch(()=>{t(!0)})}catch{t(!0)}}armIdleSweep(){this.idleSweepTimer!==void 0&&clearTimeout(this.idleSweepTimer),this.idleSweepTimer=setTimeout(()=>{this.idleSweepTimer=void 0;for(let e of this.slots)e.tasksSinceSpawn>0&&e.inflight===0&&this.recycleSlot(e)},te)}};function ie(e){return e!=null}var ae=class{x;y;z;constructor(e){this.x=e.x,this.y=e.y,this.z=e.z}},oe=class{vertices;uvs;indices;heights;max_height;min_height;rtc_translation;normals;skirt_vertices;skirt_uvs;skirt_indices;skirt_normals;watermask;constructor(e){this.vertices=e.transferVertices(),this.uvs=e.transferUvs(),this.indices=e.transferIndices(),this.heights=e.transferHeights(),this.max_height=e.max_height,this.min_height=e.min_height,this.rtc_translation=e.rtc_translation?new ae(e.rtc_translation):void 0,e.hasNormals()&&(this.normals=e.transferNormals()),e.hasSkirt()&&(this.skirt_vertices=e.transferSkirtVertices(),this.skirt_uvs=e.transferSkirtUvs(),this.skirt_indices=e.transferSkirtIndices(),this.skirt_normals=e.transferSkirtNormals()),e.hasWatermask()&&(this.watermask=e.transferWatermask())}transferVertices(){throw Error()}transferUvs(){throw Error()}transferIndices(){throw Error()}transferHeights(){throw Error()}transferNormals(){throw Error()}transferSkirtVertices(){throw Error()}transferSkirtUvs(){throw Error()}transferSkirtIndices(){throw Error()}transferSkirtNormals(){throw Error()}transferWatermask(){throw Error()}hasSkirt(){return this.skirt_vertices!==void 0&&this.skirt_uvs!==void 0&&this.skirt_indices!==void 0}hasNormals(){return this.normals!==void 0}hasWatermask(){return this.watermask!==void 0}},se=class{east;north;south;west;constructor(e){this.east=e.east,this.north=e.north,this.south=e.south,this.west=e.west}},ce=class{extent;position_3d_high;position_3d_high_size;position_3d_low;position_3d_low_size;position;position_size;normal;normal_size;scale_normal_and_cap;scale_normal_and_cap_size;batch_id;batch_id_size;batch_index;batch_index_size;indices;rtc_translation;outline_position;outline_position_size;outline_scale_normal_and_cap;outline_scale_normal_and_cap_size;outline_skip_indices;outline_batch_index;outline_batch_index_size;constructor(e){let t=e.extent;this.extent=t?new se(t):void 0,this.position_3d_high=e.position_3d_high()?.slice(),this.position_3d_high_size=e.position_3d_high_size(),this.position_3d_low=e.position_3d_low()?.slice(),this.position_3d_low_size=e.position_3d_low_size(),this.position=e.position()?.slice(),this.position_size=e.position_size(),this.normal=e.normal()?.slice(),this.normal_size=e.normal_size(),this.scale_normal_and_cap=e.scale_normal_and_cap()?.slice(),this.scale_normal_and_cap_size=e.scale_normal_and_cap_size(),this.batch_id=e.batch_id()?.slice(),this.batch_id_size=e.batch_id_size(),this.batch_index=e.batch_index()?.slice(),this.batch_index_size=e.batch_index_size(),this.indices=e.indices().slice(),this.rtc_translation=e.rtc_translation?new ae(e.rtc_translation):void 0;let n=e.outline();n&&(this.outline_position=n.position()?.slice(),this.outline_position_size=n.position_size(),this.outline_scale_normal_and_cap=n.scale_normal_and_cap()?.slice(),this.outline_scale_normal_and_cap_size=n.scale_normal_and_cap_size(),this.outline_skip_indices=n.skip_indices()?.slice(),this.outline_batch_index=n.batch_index()?.slice(),this.outline_batch_index_size=n.batch_index_size(),n.free())}},le=class{extent;position;position_size;position_high;position_high_size;position_low;position_low_size;start;start_size;start_high;start_high_size;start_low;start_low_size;forward_offset;forward_offset_size;end_high;end_high_size;end_low;end_low_size;start_normals;start_normals_size;end_normal_and_texture_coordinate_normalization_x;end_normal_and_texture_coordinate_normalization_x_size;right_normal_and_texture_coordinate_normalization_y;right_normal_and_texture_coordinate_normalization_y_size;batch_id;batch_id_size;batch_index;batch_index_size;indices;constructor(e){let t=e.extent;this.extent=t?new se(t):void 0,this.position=e.position().slice(),this.position_size=e.position_size(),this.position_high=e.position_high()?.slice(),this.position_high_size=e.position_high_size(),this.position_low=e.position_low()?.slice(),this.position_low_size=e.position_low_size(),this.start=e.start()?.slice(),this.start_size=e.start_size(),this.start_high=e.start_high()?.slice(),this.start_high_size=e.start_high_size(),this.start_low=e.start_low()?.slice(),this.start_low_size=e.start_low_size(),this.forward_offset=e.forward_offset()?.slice(),this.forward_offset_size=e.forward_offset_size(),this.end_high=e.end_high()?.slice(),this.end_high_size=e.end_high_size(),this.end_low=e.end_low()?.slice(),this.end_low_size=e.end_low_size(),this.start_normals=e.start_normals()?.slice(),this.start_normals_size=e.start_normals_size(),this.end_normal_and_texture_coordinate_normalization_x=e.end_normal_and_texture_coordinate_normalization_x()?.slice(),this.end_normal_and_texture_coordinate_normalization_x_size=e.end_normal_and_texture_coordinate_normalization_x_size(),this.right_normal_and_texture_coordinate_normalization_y=e.right_normal_and_texture_coordinate_normalization_y().slice(),this.right_normal_and_texture_coordinate_normalization_y_size=e.right_normal_and_texture_coordinate_normalization_y_size(),this.batch_id=e.batch_id()?.slice(),this.batch_id_size=e.batch_id_size(),this.batch_index=e.batch_index()?.slice(),this.batch_index_size=e.batch_index_size(),this.indices=e.indices().slice()}};function ue(e,t){return e==null||t==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function de(e,t){return e==null||t==null?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function fe(e){let t,n,r;e.length===2?(t=e===ue||e===de?e:pe,n=e,r=e):(t=ue,n=(t,n)=>ue(e(t),n),r=(t,n)=>e(t)-n);function i(e,r,i=0,a=e.length){if(i<a){if(t(r,r)!==0)return a;do{let t=i+a>>>1;n(e[t],r)<0?i=t+1:a=t}while(i<a)}return i}function a(e,r,i=0,a=e.length){if(i<a){if(t(r,r)!==0)return a;do{let t=i+a>>>1;n(e[t],r)<=0?i=t+1:a=t}while(i<a)}return i}function o(e,t,n=0,a=e.length){let o=i(e,t,n,a-1);return o>n&&r(e[o-1],t)>-r(e[o],t)?o-1:o}return{left:i,center:o,right:a}}function pe(){return 0}function me(e){return e===null?NaN:+e}var he=fe(ue);he.right,he.left,fe(me).center;var ge={value:()=>{}};function _e(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new ve(n)}function ve(e){this._=e}function ye(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}ve.prototype=_e.prototype={constructor:ve,on:function(e,t){var n=this._,r=ye(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=be(n[i],e.name)))return i;return}if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=xe(n[i],e.name,t);else if(t==null)for(i in n)n[i]=xe(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new ve(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function be(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function xe(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=ge,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var Se={svg:`http://www.w3.org/2000/svg`,xhtml:`http://www.w3.org/1999/xhtml`,xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};function Ce(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),Se.hasOwnProperty(t)?{space:Se[t],local:e}:e}function we(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===`http://www.w3.org/1999/xhtml`&&t.documentElement.namespaceURI===`http://www.w3.org/1999/xhtml`?t.createElement(e):t.createElementNS(n,e)}}function Te(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Ee(e){var t=Ce(e);return(t.local?Te:we)(t)}function De(){}function Oe(e){return e==null?De:function(){return this.querySelector(e)}}function ke(e){typeof e!=`function`&&(e=Oe(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=Array(o),c,l,u=0;u<o;++u)(c=a[u])&&(l=e.call(c,c.__data__,u,a))&&(`__data__`in c&&(l.__data__=c.__data__),s[u]=l);return new O(r,this._parents)}function Ae(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function je(){return[]}function Me(e){return e==null?je:function(){return this.querySelectorAll(e)}}function Ne(e){return function(){return Ae(e.apply(this,arguments))}}function Pe(e){e=typeof e==`function`?Ne(e):Me(e);for(var t=this._groups,n=t.length,r=[],i=[],a=0;a<n;++a)for(var o=t[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&(r.push(e.call(c,c.__data__,l,o)),i.push(c));return new O(r,i)}function Fe(e){return function(){return this.matches(e)}}function Ie(e){return function(t){return t.matches(e)}}var Le=Array.prototype.find;function Re(e){return function(){return Le.call(this.children,e)}}function ze(){return this.firstElementChild}function Be(e){return this.select(e==null?ze:Re(typeof e==`function`?e:Ie(e)))}var Ve=Array.prototype.filter;function He(){return Array.from(this.children)}function Ue(e){return function(){return Ve.call(this.children,e)}}function We(e){return this.selectAll(e==null?He:Ue(typeof e==`function`?e:Ie(e)))}function Ge(e){typeof e!=`function`&&(e=Fe(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new O(r,this._parents)}function Ke(e){return Array(e.length)}function qe(){return new O(this._enter||this._groups.map(Ke),this._parents)}function Je(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Je.prototype={constructor:Je,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Ye(e){return function(){return e}}function Xe(e,t,n,r,i,a){for(var o=0,s,c=t.length,l=a.length;o<l;++o)(s=t[o])?(s.__data__=a[o],r[o]=s):n[o]=new Je(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function Ze(e,t,n,r,i,a,o){var s,c,l=new Map,u=t.length,d=a.length,f=Array(u),p;for(s=0;s<u;++s)(c=t[s])&&(f[s]=p=o.call(c,c.__data__,s,t)+``,l.has(p)?i[s]=c:l.set(p,c));for(s=0;s<d;++s)p=o.call(e,a[s],s,a)+``,(c=l.get(p))?(r[s]=c,c.__data__=a[s],l.delete(p)):n[s]=new Je(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function Qe(e){return e.__data__}function $e(e,t){if(!arguments.length)return Array.from(this,Qe);var n=t?Ze:Xe,r=this._parents,i=this._groups;typeof e!=`function`&&(e=Ye(e));for(var a=i.length,o=Array(a),s=Array(a),c=Array(a),l=0;l<a;++l){var u=r[l],d=i[l],f=d.length,p=et(e.call(u,u&&u.__data__,l,r)),m=p.length,h=s[l]=Array(m),g=o[l]=Array(m);n(u,d,h,g,c[l]=Array(f),p,t);for(var _=0,v=0,ee,y;_<m;++_)if(ee=h[_]){for(_>=v&&(v=_+1);!(y=g[v])&&++v<m;);ee._next=y||null}}return o=new O(o,r),o._enter=s,o._exit=c,o}function et(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function tt(){return new O(this._exit||this._groups.map(Ke),this._parents)}function nt(e,t,n){var r=this.enter(),i=this,a=this.exit();return typeof e==`function`?(r=e(r),r&&=r.selection()):r=r.append(e+``),t!=null&&(i=t(i),i&&=i.selection()),n==null?a.remove():n(a),r&&i?r.merge(i).order():i}function rt(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,a=r.length,o=Math.min(i,a),s=Array(i),c=0;c<o;++c)for(var l=n[c],u=r[c],d=l.length,f=s[c]=Array(d),p,m=0;m<d;++m)(p=l[m]||u[m])&&(f[m]=p);for(;c<i;++c)s[c]=n[c];return new O(s,this._parents)}function it(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,a=r[i],o;--i>=0;)(o=r[i])&&(a&&o.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(o,a),a=o);return this}function at(e){e||=ot;function t(t,n){return t&&n?e(t.__data__,n.__data__):!t-!n}for(var n=this._groups,r=n.length,i=Array(r),a=0;a<r;++a){for(var o=n[a],s=o.length,c=i[a]=Array(s),l,u=0;u<s;++u)(l=o[u])&&(c[u]=l);c.sort(t)}return new O(i,this._parents).order()}function ot(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function st(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function ct(){return Array.from(this)}function lt(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null}function ut(){let e=0;for(let t of this)++e;return e}function dt(){return!this.node()}function ft(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],a=0,o=i.length,s;a<o;++a)(s=i[a])&&e.call(s,s.__data__,a,i);return this}function pt(e){return function(){this.removeAttribute(e)}}function mt(e){return function(){this.removeAttributeNS(e.space,e.local)}}function ht(e,t){return function(){this.setAttribute(e,t)}}function gt(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function _t(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function vt(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function yt(e,t){var n=Ce(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?mt:pt:typeof t==`function`?n.local?vt:_t:n.local?gt:ht)(n,t))}function bt(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function xt(e){return function(){this.style.removeProperty(e)}}function St(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Ct(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function wt(e,t,n){return arguments.length>1?this.each((t==null?xt:typeof t==`function`?Ct:St)(e,t,n??``)):D(this.node(),e)}function D(e,t){return e.style.getPropertyValue(t)||bt(e).getComputedStyle(e,null).getPropertyValue(t)}function Tt(e){return function(){delete this[e]}}function Et(e,t){return function(){this[e]=t}}function Dt(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Ot(e,t){return arguments.length>1?this.each((t==null?Tt:typeof t==`function`?Dt:Et)(e,t)):this.node()[e]}function kt(e){return e.trim().split(/^|\s+/)}function At(e){return e.classList||new jt(e)}function jt(e){this._node=e,this._names=kt(e.getAttribute(`class`)||``)}jt.prototype={add:function(e){this._names.indexOf(e)<0&&(this._names.push(e),this._node.setAttribute(`class`,this._names.join(` `)))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute(`class`,this._names.join(` `)))},contains:function(e){return this._names.indexOf(e)>=0}};function Mt(e,t){for(var n=At(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function Nt(e,t){for(var n=At(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function Pt(e){return function(){Mt(this,e)}}function Ft(e){return function(){Nt(this,e)}}function It(e,t){return function(){(t.apply(this,arguments)?Mt:Nt)(this,e)}}function Lt(e,t){var n=kt(e+``);if(arguments.length<2){for(var r=At(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?It:t?Pt:Ft)(n,t))}function Rt(){this.textContent=``}function zt(e){return function(){this.textContent=e}}function Bt(e){return function(){this.textContent=e.apply(this,arguments)??``}}function Vt(e){return arguments.length?this.each(e==null?Rt:(typeof e==`function`?Bt:zt)(e)):this.node().textContent}function Ht(){this.innerHTML=``}function Ut(e){return function(){this.innerHTML=e}}function Wt(e){return function(){this.innerHTML=e.apply(this,arguments)??``}}function Gt(e){return arguments.length?this.each(e==null?Ht:(typeof e==`function`?Wt:Ut)(e)):this.node().innerHTML}function Kt(){this.nextSibling&&this.parentNode.appendChild(this)}function qt(){return this.each(Kt)}function Jt(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Yt(){return this.each(Jt)}function Xt(e){var t=typeof e==`function`?e:Ee(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function Zt(){return null}function Qt(e,t){var n=typeof e==`function`?e:Ee(e),r=t==null?Zt:typeof t==`function`?t:Oe(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function $t(){var e=this.parentNode;e&&e.removeChild(this)}function en(){return this.each($t)}function tn(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function nn(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function rn(e){return this.select(e?nn:tn)}function an(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function on(e){return function(t){e.call(this,t,this.__data__)}}function sn(e){return e.trim().split(/^|\s+/).map(function(e){var t=``,n=e.indexOf(`.`);return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function cn(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,a;n<i;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function ln(e,t,n){return function(){var r=this.__on,i,a=on(t);if(r){for(var o=0,s=r.length;o<s;++o)if((i=r[o]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=n),i.value=t;return}}this.addEventListener(e.type,a,n),i={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(i):this.__on=[i]}}function un(e,t,n){var r=sn(e+``),i,a=r.length,o;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,l=s.length,u;c<l;++c)for(i=0,u=s[c];i<a;++i)if((o=r[i]).type===u.type&&o.name===u.name)return u.value}return}for(s=t?ln:cn,i=0;i<a;++i)this.each(s(r[i],t,n));return this}function dn(e,t,n){var r=bt(e),i=r.CustomEvent;typeof i==`function`?i=new i(t,n):(i=r.document.createEvent(`Event`),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function fn(e,t){return function(){return dn(this,e,t)}}function pn(e,t){return function(){return dn(this,e,t.apply(this,arguments))}}function mn(e,t){return this.each((typeof t==`function`?pn:fn)(e,t))}function*hn(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length,o;i<a;++i)(o=r[i])&&(yield o)}var gn=[null];function O(e,t){this._groups=e,this._parents=t}function k(){return new O([[document.documentElement]],gn)}function _n(){return this}O.prototype=k.prototype={constructor:O,select:ke,selectAll:Pe,selectChild:Be,selectChildren:We,filter:Ge,data:$e,enter:qe,exit:tt,join:nt,merge:rt,selection:_n,order:it,sort:at,call:st,nodes:ct,node:lt,size:ut,empty:dt,each:ft,attr:yt,style:wt,property:Ot,classed:Lt,text:Vt,html:Gt,raise:qt,lower:Yt,append:Xt,insert:Qt,remove:en,clone:rn,datum:an,on:un,dispatch:mn,[Symbol.iterator]:hn};function vn(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function yn(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function A(){}var j=.7,bn=1/j,M=`\\s*([+-]?\\d+)\\s*`,N=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,P=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,xn=/^#([0-9a-f]{3,8})$/,Sn=RegExp(`^rgb\\(${M},${M},${M}\\)$`),Cn=RegExp(`^rgb\\(${P},${P},${P}\\)$`),wn=RegExp(`^rgba\\(${M},${M},${M},${N}\\)$`),Tn=RegExp(`^rgba\\(${P},${P},${P},${N}\\)$`),En=RegExp(`^hsl\\(${N},${P},${P}\\)$`),Dn=RegExp(`^hsla\\(${N},${P},${P},${N}\\)$`),On={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};vn(A,F,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:kn,formatHex:kn,formatHex8:An,formatHsl:jn,formatRgb:Mn,toString:Mn});function kn(){return this.rgb().formatHex()}function An(){return this.rgb().formatHex8()}function jn(){return Vn(this).formatHsl()}function Mn(){return this.rgb().formatRgb()}function F(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=xn.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Nn(t):n===3?new I(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Pn(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Pn(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Sn.exec(e))?new I(t[1],t[2],t[3],1):(t=Cn.exec(e))?new I(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=wn.exec(e))?Pn(t[1],t[2],t[3],t[4]):(t=Tn.exec(e))?Pn(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=En.exec(e))?Bn(t[1],t[2]/100,t[3]/100,1):(t=Dn.exec(e))?Bn(t[1],t[2]/100,t[3]/100,t[4]):On.hasOwnProperty(e)?Nn(On[e]):e===`transparent`?new I(NaN,NaN,NaN,0):null}function Nn(e){return new I(e>>16&255,e>>8&255,e&255,1)}function Pn(e,t,n,r){return r<=0&&(e=t=n=NaN),new I(e,t,n,r)}function Fn(e){return e instanceof A||(e=F(e)),e?(e=e.rgb(),new I(e.r,e.g,e.b,e.opacity)):new I}function In(e,t,n,r){return arguments.length===1?Fn(e):new I(e,t,n,r??1)}function I(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}vn(I,In,yn(A,{brighter(e){return e=e==null?bn:bn**+e,new I(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?j:j**+e,new I(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new I(R(this.r),R(this.g),R(this.b),L(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Ln,formatHex:Ln,formatHex8:Rn,formatRgb:zn,toString:zn}));function Ln(){return`#${z(this.r)}${z(this.g)}${z(this.b)}`}function Rn(){return`#${z(this.r)}${z(this.g)}${z(this.b)}${z((isNaN(this.opacity)?1:this.opacity)*255)}`}function zn(){let e=L(this.opacity);return`${e===1?`rgb(`:`rgba(`}${R(this.r)}, ${R(this.g)}, ${R(this.b)}${e===1?`)`:`, ${e})`}`}function L(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function R(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function z(e){return e=R(e),(e<16?`0`:``)+e.toString(16)}function Bn(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new B(e,t,n,r)}function Vn(e){if(e instanceof B)return new B(e.h,e.s,e.l,e.opacity);if(e instanceof A||(e=F(e)),!e)return new B;if(e instanceof B)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=t===a?(n-r)/s+(n<r)*6:n===a?(r-t)/s+2:(t-n)/s+4,s/=c<.5?a+i:2-a-i,o*=60):s=c>0&&c<1?0:o,new B(o,s,c,e.opacity)}function Hn(e,t,n,r){return arguments.length===1?Vn(e):new B(e,t,n,r??1)}function B(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}vn(B,Hn,yn(A,{brighter(e){return e=e==null?bn:bn**+e,new B(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?j:j**+e,new B(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new I(Gn(e>=240?e-240:e+120,i,r),Gn(e,i,r),Gn(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new B(Un(this.h),Wn(this.s),Wn(this.l),L(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){let e=L(this.opacity);return`${e===1?`hsl(`:`hsla(`}${Un(this.h)}, ${Wn(this.s)*100}%, ${Wn(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function Un(e){return e=(e||0)%360,e<0?e+360:e}function Wn(e){return Math.max(0,Math.min(1,e||0))}function Gn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}var Kn=e=>()=>e;function qn(e,t){return function(n){return e+n*t}}function Jn(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function Yn(e){return(e=+e)==1?Xn:function(t,n){return n-t?Jn(t,n,e):Kn(isNaN(t)?n:t)}}function Xn(e,t){var n=t-e;return n?qn(e,n):Kn(isNaN(e)?t:e)}var Zn=(function e(t){var n=Yn(t);function r(e,t){var r=n((e=In(e)).r,(t=In(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=Xn(e.opacity,t.opacity);return function(t){return e.r=r(t),e.g=i(t),e.b=a(t),e.opacity=o(t),e+``}}return r.gamma=e,r})(1);function V(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var Qn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,$n=new RegExp(Qn.source,`g`);function er(e){return function(){return e}}function tr(e){return function(t){return e(t)+``}}function nr(e,t){var n=Qn.lastIndex=$n.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=Qn.exec(e))&&(i=$n.exec(t));)(a=i.index)>n&&(a=t.slice(n,a),s[o]?s[o]+=a:s[++o]=a),(r=r[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,c.push({i:o,x:V(r,i)})),n=$n.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?tr(c[0].x):er(t):(t=c.length,function(e){for(var n=0,r;n<t;++n)s[(r=c[n]).i]=r.x(e);return s.join(``)})}var rr=180/Math.PI,ir={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function ar(e,t,n,r,i,a){var o,s,c;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),e*r<t*n&&(e=-e,t=-t,c=-c,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(t,e)*rr,skewX:Math.atan(c)*rr,scaleX:o,scaleY:s}}var or;function sr(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?ir:ar(t.a,t.b,t.c,t.d,t.e,t.f)}function cr(e){return e==null||(or||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),or.setAttribute(`transform`,e),!(e=or.transform.baseVal.consolidate()))?ir:(e=e.matrix,ar(e.a,e.b,e.c,e.d,e.e,e.f))}function lr(e,t,n,r){function i(e){return e.length?e.pop()+` `:``}function a(e,r,i,a,o,s){if(e!==i||r!==a){var c=o.push(`translate(`,null,t,null,n);s.push({i:c-4,x:V(e,i)},{i:c-2,x:V(r,a)})}else (i||a)&&o.push(`translate(`+i+t+a+n)}function o(e,t,n,a){e===t?t&&n.push(i(n)+`rotate(`+t+r):(e-t>180?t+=360:t-e>180&&(e+=360),a.push({i:n.push(i(n)+`rotate(`,null,r)-2,x:V(e,t)}))}function s(e,t,n,a){e===t?t&&n.push(i(n)+`skewX(`+t+r):a.push({i:n.push(i(n)+`skewX(`,null,r)-2,x:V(e,t)})}function c(e,t,n,r,a,o){if(e!==n||t!==r){var s=a.push(i(a)+`scale(`,null,`,`,null,`)`);o.push({i:s-4,x:V(e,n)},{i:s-2,x:V(t,r)})}else (n!==1||r!==1)&&a.push(i(a)+`scale(`+n+`,`+r+`)`)}return function(t,n){var r=[],i=[];return t=e(t),n=e(n),a(t.translateX,t.translateY,n.translateX,n.translateY,r,i),o(t.rotate,n.rotate,r,i),s(t.skewX,n.skewX,r,i),c(t.scaleX,t.scaleY,n.scaleX,n.scaleY,r,i),t=n=null,function(e){for(var t=-1,n=i.length,a;++t<n;)r[(a=i[t]).i]=a.x(e);return r.join(``)}}}var ur=lr(sr,`px, `,`px)`,`deg)`),dr=lr(cr,`, `,`)`,`)`),H=0,fr=0,pr=0,mr=1e3,hr,U,gr=0,W=0,_r=0,G=typeof performance==`object`&&performance.now?performance:Date,vr=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function yr(){return W||=(vr(br),G.now()+_r)}function br(){W=0}function xr(){this._call=this._time=this._next=null}xr.prototype=Sr.prototype={constructor:xr,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?yr():+n)+(t==null?0:+t),!this._next&&U!==this&&(U?U._next=this:hr=this,U=this),this._call=e,this._time=n,Dr()},stop:function(){this._call&&(this._call=null,this._time=1/0,Dr())}};function Sr(e,t,n){var r=new xr;return r.restart(e,t,n),r}function Cr(){yr(),++H;for(var e=hr,t;e;)(t=W-e._time)>=0&&e._call.call(void 0,t),e=e._next;--H}function wr(){W=(gr=G.now())+_r,H=fr=0;try{Cr()}finally{H=0,Er(),W=0}}function Tr(){var e=G.now(),t=e-gr;t>mr&&(_r-=t,gr=e)}function Er(){for(var e,t=hr,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:hr=n);U=e,Dr(r)}function Dr(e){H||(fr&&=clearTimeout(fr),e-W>24?(e<1/0&&(fr=setTimeout(wr,e-G.now()-_r)),pr&&=clearInterval(pr)):(pr||=(gr=G.now(),setInterval(Tr,mr)),H=1,vr(wr)))}function Or(e,t,n){var r=new xr;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var kr=_e(`start`,`end`,`cancel`,`interrupt`),Ar=[];function jr(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Nr(e,n,{name:t,index:r,group:i,on:kr,tween:Ar,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function Mr(e,t){var n=q(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function K(e,t){var n=q(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function q(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function Nr(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Sr(a,0,n.time);function a(e){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=e&&o(e-n.delay)}function o(a){var l,u,d,f;if(n.state!==1)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===3)return Or(o);f.state===4?(f.state=6,f.timer.stop(),f.on.call(`interrupt`,e,e.__data__,f.index,f.group),delete r[l]):+l<t&&(f.state=6,f.timer.stop(),f.on.call(`cancel`,e,e.__data__,f.index,f.group),delete r[l])}if(Or(function(){n.state===3&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call(`start`,e,e.__data__,n.index,n.group),n.state===2){for(n.state=3,i=Array(d=n.tween.length),l=0,u=-1;l<d;++l)(f=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(i[++u]=f);i.length=u+1}}function s(t){for(var r=t<n.duration?n.ease.call(null,t/n.duration):(n.timer.restart(c),n.state=5,1),a=-1,o=i.length;++a<o;)i[a].call(e,r);n.state===5&&(n.on.call(`end`,e,e.__data__,n.index,n.group),c())}function c(){for(var i in n.state=6,n.timer.stop(),delete r[t],r)return;delete e.__transition}}function Pr(e,t){var n=e.__transition,r,i,a=!0,o;if(n){for(o in t=t==null?null:t+``,n){if((r=n[o]).name!==t){a=!1;continue}i=r.state>2&&r.state<5,r.state=6,r.timer.stop(),r.on.call(i?`interrupt`:`cancel`,e,e.__data__,r.index,r.group),delete n[o]}a&&delete e.__transition}}function Fr(e){return this.each(function(){Pr(this,e)})}function Ir(e,t){var n,r;return function(){var i=K(this,e),a=i.tween;if(a!==n){r=n=a;for(var o=0,s=r.length;o<s;++o)if(r[o].name===t){r=r.slice(),r.splice(o,1);break}}i.tween=r}}function Lr(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=K(this,e),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:t,value:n},c=0,l=i.length;c<l;++c)if(i[c].name===t){i[c]=s;break}c===l&&i.push(s)}a.tween=i}}function Rr(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=q(this.node(),n).tween,i=0,a=r.length,o;i<a;++i)if((o=r[i]).name===e)return o.value;return null}return this.each((t==null?Ir:Lr)(n,e,t))}function zr(e,t,n){var r=e._id;return e.each(function(){var e=K(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return q(e,r).value[t]}}function Br(e,t){var n;return(typeof t==`number`?V:t instanceof F?Zn:(n=F(t))?(t=n,Zn):nr)(e,t)}function Vr(e){return function(){this.removeAttribute(e)}}function Hr(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Ur(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttribute(e);return o===i?null:o===r?a:a=t(r=o,n)}}function Wr(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttributeNS(e.space,e.local);return o===i?null:o===r?a:a=t(r=o,n)}}function Gr(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttribute(e):(o=this.getAttribute(e),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function Kr(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function qr(e,t){var n=Ce(e),r=n===`transform`?dr:Br;return this.attrTween(e,typeof t==`function`?(n.local?Kr:Gr)(n,r,zr(this,`attr.`+e,t)):t==null?(n.local?Hr:Vr)(n):(n.local?Wr:Ur)(n,r,t))}function Jr(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Yr(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Xr(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Yr(e,i)),n}return i._value=t,i}function Zr(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Jr(e,i)),n}return i._value=t,i}function Qr(e,t){var n=`attr.`+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!=`function`)throw Error();var r=Ce(e);return this.tween(n,(r.local?Xr:Zr)(r,t))}function $r(e,t){return function(){Mr(this,e).delay=+t.apply(this,arguments)}}function ei(e,t){return t=+t,function(){Mr(this,e).delay=t}}function ti(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?$r:ei)(t,e)):q(this.node(),t).delay}function ni(e,t){return function(){K(this,e).duration=+t.apply(this,arguments)}}function ri(e,t){return t=+t,function(){K(this,e).duration=t}}function ii(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?ni:ri)(t,e)):q(this.node(),t).duration}function ai(e,t){if(typeof t!=`function`)throw Error();return function(){K(this,e).ease=t}}function oi(e){var t=this._id;return arguments.length?this.each(ai(t,e)):q(this.node(),t).ease}function si(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();K(this,e).ease=n}}function ci(e){if(typeof e!=`function`)throw Error();return this.each(si(this._id,e))}function li(e){typeof e!=`function`&&(e=Fe(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new J(r,this._parents,this._name,this._id)}function ui(e){if(e._id!==this._id)throw Error();for(var t=this._groups,n=e._groups,r=t.length,i=n.length,a=Math.min(r,i),o=Array(r),s=0;s<a;++s)for(var c=t[s],l=n[s],u=c.length,d=o[s]=Array(u),f,p=0;p<u;++p)(f=c[p]||l[p])&&(d[p]=f);for(;s<r;++s)o[s]=t[s];return new J(o,this._parents,this._name,this._id)}function di(e){return(e+``).trim().split(/^|\s+/).every(function(e){var t=e.indexOf(`.`);return t>=0&&(e=e.slice(0,t)),!e||e===`start`})}function fi(e,t,n){var r,i,a=di(t)?Mr:K;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function pi(e,t){var n=this._id;return arguments.length<2?q(this.node(),n).on.on(e):this.each(fi(n,e,t))}function mi(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function hi(){return this.on(`end.remove`,mi(this._id))}function gi(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=Oe(e));for(var r=this._groups,i=r.length,a=Array(i),o=0;o<i;++o)for(var s=r[o],c=s.length,l=a[o]=Array(c),u,d,f=0;f<c;++f)(u=s[f])&&(d=e.call(u,u.__data__,f,s))&&(`__data__`in u&&(d.__data__=u.__data__),l[f]=d,jr(l[f],t,n,f,l,q(u,n)));return new J(a,this._parents,t,n)}function _i(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=Me(e));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var c=r[s],l=c.length,u,d=0;d<l;++d)if(u=c[d]){for(var f=e.call(u,u.__data__,d,c),p,m=q(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&jr(p,t,n,h,f,m);a.push(f),o.push(u)}return new J(a,o,t,n)}var vi=k.prototype.constructor;function yi(){return new vi(this._groups,this._parents)}function bi(e,t){var n,r,i;return function(){var a=D(this,e),o=(this.style.removeProperty(e),D(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function xi(e){return function(){this.style.removeProperty(e)}}function Si(e,t,n){var r,i=n+``,a;return function(){var o=D(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function Ci(e,t,n){var r,i,a;return function(){var o=D(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),D(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function wi(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=K(this,e),l=c.on,u=c.value[a]==null?s||=xi(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function Ti(e,t,n){var r=(e+=``)==`transform`?ur:Br;return t==null?this.styleTween(e,bi(e,r)).on(`end.style.`+e,xi(e)):typeof t==`function`?this.styleTween(e,Ci(e,r,zr(this,`style.`+e,t))).each(wi(this._id,e)):this.styleTween(e,Si(e,r,t),n).on(`end.style.`+e,null)}function Ei(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Di(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&Ei(e,a,n)),r}return a._value=t,a}function Oi(e,t,n){var r=`style.`+(e+=``);if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!=`function`)throw Error();return this.tween(r,Di(e,t,n??``))}function ki(e){return function(){this.textContent=e}}function Ai(e){return function(){this.textContent=e(this)??``}}function ji(e){return this.tween(`text`,typeof e==`function`?Ai(zr(this,`text`,e)):ki(e==null?``:e+``))}function Mi(e){return function(t){this.textContent=e.call(this,t)}}function Ni(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&Mi(r)),t}return r._value=e,r}function Pi(e){var t=`text`;if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!=`function`)throw Error();return this.tween(t,Ni(e))}function Fi(){for(var e=this._name,t=this._id,n=zi(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)if(c=o[l]){var u=q(c,t);jr(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new J(r,this._parents,e,n)}function Ii(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},c={value:function(){--i===0&&a()}};n.each(function(){var n=K(this,r),i=n.on;i!==e&&(t=(e=i).copy(),t._.cancel.push(s),t._.interrupt.push(s),t._.end.push(c)),n.on=t}),i===0&&a()})}var Li=0;function J(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function Ri(e){return k().transition(e)}function zi(){return++Li}var Y=k.prototype;J.prototype=Ri.prototype={constructor:J,select:gi,selectAll:_i,selectChild:Y.selectChild,selectChildren:Y.selectChildren,filter:li,merge:ui,selection:yi,transition:Fi,call:Y.call,nodes:Y.nodes,node:Y.node,size:Y.size,empty:Y.empty,each:Y.each,on:pi,attr:qr,attrTween:Qr,style:Ti,styleTween:Oi,text:ji,textTween:Pi,remove:hi,tween:Rr,delay:ti,duration:ii,ease:oi,easeVarying:ci,end:Ii,[Symbol.iterator]:Y[Symbol.iterator]};function Bi(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Vi={time:null,delay:0,duration:250,ease:Bi};function Hi(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function Ui(e){var t,n;e instanceof J?(t=e._id,e=e._name):(t=zi(),(n=Vi).time=yr(),e=e==null?null:e+``);for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&jr(c,e,t,l,o,n||Hi(c,t));return new J(r,this._parents,e,t)}k.prototype.interrupt=Fr,k.prototype.transition=Ui;var{abs:Wi,max:Gi,min:Ki}=Math;[`w`,`e`].map(qi),[`n`,`s`].map(qi),[`n`,`w`,`e`,`s`,`nw`,`ne`,`sw`,`se`].map(qi);function qi(e){return{type:e}}function Ji(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString(`en`).replace(/,/g,``):e.toString(10)}function Yi(e,t){if((n=(e=t?e.toExponential(t-1):e.toExponential()).indexOf(`e`))<0)return null;var n,r=e.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+e.slice(n+1)]}function Xi(e){return e=Yi(Math.abs(e)),e?e[1]:NaN}function Zi(e,t){return function(n,r){for(var i=n.length,a=[],o=0,s=e[0],c=0;i>0&&s>0&&(c+s+1>r&&(s=Math.max(1,r-c)),a.push(n.substring(i-=s,i+s)),!((c+=s+1)>r));)s=e[o=(o+1)%e.length];return a.reverse().join(t)}}function Qi(e){return function(t){return t.replace(/[0-9]/g,function(t){return e[+t]})}}var $i=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function ea(e){if(!(t=$i.exec(e)))throw Error(`invalid format: `+e);var t;return new ta({fill:t[1],align:t[2],sign:t[3],symbol:t[4],zero:t[5],width:t[6],comma:t[7],precision:t[8]&&t[8].slice(1),trim:t[9],type:t[10]})}ea.prototype=ta.prototype;function ta(e){this.fill=e.fill===void 0?` `:e.fill+``,this.align=e.align===void 0?`>`:e.align+``,this.sign=e.sign===void 0?`-`:e.sign+``,this.symbol=e.symbol===void 0?``:e.symbol+``,this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?``:e.type+``}ta.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?`0`:``)+(this.width===void 0?``:Math.max(1,this.width|0))+(this.comma?`,`:``)+(this.precision===void 0?``:`.`+Math.max(0,this.precision|0))+(this.trim?`~`:``)+this.type};function na(e){out:for(var t=e.length,n=1,r=-1,i;n<t;++n)switch(e[n]){case`.`:r=i=n;break;case`0`:r===0&&(r=n),i=n;break;default:if(!+e[n])break out;r>0&&(r=0);break}return r>0?e.slice(0,r)+e.slice(i+1):e}var ra;function ia(e,t){var n=Yi(e,t);if(!n)return e+``;var r=n[0],i=n[1],a=i-(ra=Math.max(-8,Math.min(8,Math.floor(i/3)))*3)+1,o=r.length;return a===o?r:a>o?r+Array(a-o+1).join(`0`):a>0?r.slice(0,a)+`.`+r.slice(a):`0.`+Array(1-a).join(`0`)+Yi(e,Math.max(0,t+a-1))[0]}function aa(e,t){var n=Yi(e,t);if(!n)return e+``;var r=n[0],i=n[1];return i<0?`0.`+Array(-i).join(`0`)+r:r.length>i+1?r.slice(0,i+1)+`.`+r.slice(i+1):r+Array(i-r.length+2).join(`0`)}var oa={"%":(e,t)=>(e*100).toFixed(t),b:e=>Math.round(e).toString(2),c:e=>e+``,d:Ji,e:(e,t)=>e.toExponential(t),f:(e,t)=>e.toFixed(t),g:(e,t)=>e.toPrecision(t),o:e=>Math.round(e).toString(8),p:(e,t)=>aa(e*100,t),r:aa,s:ia,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function sa(e){return e}var ca=Array.prototype.map,la=[`y`,`z`,`a`,`f`,`p`,`n`,`µ`,`m`,``,`k`,`M`,`G`,`T`,`P`,`E`,`Z`,`Y`];function ua(e){var t=e.grouping===void 0||e.thousands===void 0?sa:Zi(ca.call(e.grouping,Number),e.thousands+``),n=e.currency===void 0?``:e.currency[0]+``,r=e.currency===void 0?``:e.currency[1]+``,i=e.decimal===void 0?`.`:e.decimal+``,a=e.numerals===void 0?sa:Qi(ca.call(e.numerals,String)),o=e.percent===void 0?`%`:e.percent+``,s=e.minus===void 0?`−`:e.minus+``,c=e.nan===void 0?`NaN`:e.nan+``;function l(e){e=ea(e);var l=e.fill,u=e.align,d=e.sign,f=e.symbol,p=e.zero,m=e.width,h=e.comma,g=e.precision,_=e.trim,v=e.type;v===`n`?(h=!0,v=`g`):oa[v]||(g===void 0&&(g=12),_=!0,v=`g`),(p||l===`0`&&u===`=`)&&(p=!0,l=`0`,u=`=`);var ee=f===`$`?n:f===`#`&&/[boxX]/.test(v)?`0`+v.toLowerCase():``,y=f===`$`?r:/[%p]/.test(v)?o:``,b=oa[v],x=/[defgprs%]/.test(v);g=g===void 0?6:/[gprs]/.test(v)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g));function S(e){var n=ee,r=y,o,f,S;if(v===`c`)r=b(e)+r,e=``;else{e=+e;var C=e<0||1/e<0;if(e=isNaN(e)?c:b(Math.abs(e),g),_&&(e=na(e)),C&&+e==0&&d!==`+`&&(C=!1),n=(C?d===`(`?d:s:d===`-`||d===`(`?``:d)+n,r=(v===`s`?la[8+ra/3]:``)+r+(C&&d===`(`?`)`:``),x){for(o=-1,f=e.length;++o<f;)if(S=e.charCodeAt(o),48>S||S>57){r=(S===46?i+e.slice(o+1):e.slice(o))+r,e=e.slice(0,o);break}}}h&&!p&&(e=t(e,1/0));var w=n.length+e.length+r.length,T=w<m?Array(m-w+1).join(l):``;switch(h&&p&&(e=t(T+e,T.length?m-r.length:1/0),T=``),u){case`<`:e=n+e+r+T;break;case`=`:e=n+T+e+r;break;case`^`:e=T.slice(0,w=T.length>>1)+n+e+r+T.slice(w);break;default:e=T+n+e+r;break}return a(e)}return S.toString=function(){return e+``},S}function u(e,t){var n=l((e=ea(e),e.type=`f`,e)),r=Math.max(-8,Math.min(8,Math.floor(Xi(t)/3)))*3,i=10**-r,a=la[8+r/3];return function(e){return n(i*e)+a}}return{format:l,formatPrefix:u}}var da;fa({thousands:`,`,grouping:[3],currency:[`$`,``]});function fa(e){return da=ua(e),da.format,da.formatPrefix,da}function X(e,t,n){this.k=e,this.x=t,this.y=n}X.prototype={constructor:X,scale:function(e){return e===1?this:new X(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new X(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return`translate(`+this.x+`,`+this.y+`) scale(`+this.k+`)`}};var pa=new X(1,0,0);ma.prototype=X.prototype;function ma(e){for(;!e.__zoom;)if(!(e=e.parentNode))return pa;return e.__zoom}function ha(e){let t=new ce(e);return{result:t,transfers:[t.batch_id?.buffer,t.batch_index?.buffer,t.normal?.buffer,t.position_3d_high?.buffer,t.position_3d_low?.buffer,t.position?.buffer,t.scale_normal_and_cap?.buffer,t.indices.buffer,t.outline_position?.buffer,t.outline_scale_normal_and_cap?.buffer,t.outline_skip_indices?.buffer,t.outline_batch_index?.buffer].filter(ie)}}function Z(e){return new n.TransferableTile(ga(e.coords),e.max_height,e.min_height,e.cached_mesh_handle?_a(e.cached_mesh_handle):void 0)}function ga(e){return new n.TileXYZ(e.x,e.y,e.z)}function _a(e){return new n.CachedMeshHandle(e.vertices,e.indices,e.uvs,e.heights)}function va(e){return new n.UpsamplableTerrainGeometry(e.uvs,e.indices,e.heights,e.normals,e.watermask)}function ya(e){return new n.ExtentRadianF32(e.west,e.south,e.east,e.north)}function ba(e){return new n.PolygonMaterial(e.show,e.castShadow,e.receiveShadow,e.color,e.clampToGround,e.tiled,e.height,e.extrudedHeight,e.wireframe,e.outline,e.perPositionHeight,e.__internal__)}function xa(e){let t=new n.TransferablePolygonBatchedFeature(e.crs,e.length);return t.setOuterRing(e.outer_ring.length,t=>{t.set(e.outer_ring)}),t.setOuterRingSizes(e.outer_ring_sizes.length,t=>{t.set(e.outer_ring_sizes)}),t.setHoles(e.holes.length,t=>{t.set(e.holes)}),t.setHolesSizes(e.holes_sizes.length,t=>{t.set(e.holes_sizes)}),t.setHolesTotalSizes(e.holes_total_sizes.length,t=>{t.set(e.holes_total_sizes)}),t.setHolesBoundaries(e.holes_boundaries.length,t=>{t.set(e.holes_boundaries)}),t.setExpectedWindingOrders(e.expected_winding_orders.length,t=>{t.set(e.expected_winding_orders)}),t.setBatchIds(e.batch_ids.length,t=>{t.set(e.batch_ids)}),t.setBatchIndices(e.batch_indices.length,t=>{t.set(e.batch_indices)}),t}var Sa;async function Q(){return Sa??=(0,n.default)(),Sa}async function Ca(){if(!Sa)return 0;let{memory:e}=await Sa;return e.buffer.byteLength}async function wa(e,t,r,i){await Q();let a=(0,n.constructPolygonBatchedFeature)(xa(e),ba(t),r,i?ya(i):void 0);if(!a)return;let{result:o,transfers:s}=ha(a);return a.free(),$(o,s)}function Ta(e){let t=new le(e);return{result:t,transfers:[t.position.buffer,t.position_high?.buffer,t.position_low?.buffer,t.start?.buffer,t.start_high?.buffer,t.start_low?.buffer,t.end_high?.buffer,t.end_low?.buffer,t.start_normals?.buffer,t.forward_offset?.buffer,t.end_normal_and_texture_coordinate_normalization_x?.buffer,t.right_normal_and_texture_coordinate_normalization_y.buffer,t.batch_id?.buffer,t.batch_index?.buffer,t.indices.buffer].filter(ie)}}function Ea(e){return new n.PolylineMaterial(e.show,e.castShadow,e.receiveShadow,e.color,e.clampToGround,e.tiled,e.height,e.width,e.maxWidth,e.__internal__)}function Da(e){let t=new n.TransferablePolylineBatchedFeature(e.crs,e.length);return t.setPoints(e.points.length,t=>{t.set(e.points)}),t.setPointsSizes(e.points_sizes.length,t=>{t.set(e.points_sizes)}),t.setBatchIds(e.batch_ids.length,t=>{t.set(e.batch_ids)}),t.setBatchIndices(e.batch_indices.length,t=>{t.set(e.batch_indices)}),t}async function Oa(e,t,r){await Q();let i=(0,n.constructPolylineBatchedFeature)(Da(e),Ea(t),r);if(!i)return;let{result:a,transfers:o}=Ta(i);return i.free(),$(a,o)}function ka(e){let t=new oe(e),n=[t.vertices.buffer,t.uvs.buffer,t.indices.buffer,t.heights.buffer];return t.normals&&n.push(t.normals.buffer),t.skirt_vertices&&n.push(t.skirt_vertices.buffer),t.skirt_uvs&&n.push(t.skirt_uvs.buffer),t.skirt_indices&&n.push(t.skirt_indices.buffer),t.skirt_normals&&n.push(t.skirt_normals.buffer),t.watermask&&n.push(t.watermask.buffer),{result:t,transfers:n}}async function Aa(e,t,r,i,a,o){await Q();let s=(0,n.constructQuantizedMeshTerrainMesh)(e,Z(t),r,i,a,o),{result:c,transfers:l}=ka(s);return s.free(),$({result:c},[...l])}function ja(e){return new n.TransferableRasterDEMData(new n.ElevationDecoder(e.decoder.r_scaler,e.decoder.g_scaler,e.decoder.b_scaler,e.decoder.offset,e.decoder.max_offset,e.decoder.min_offset,e.decoder.boundary,e.decoder.epsilon))}async function Ma(e,t,r,i,a,o){await Q();let s=i+1,c=n.TransferableMartini.fromSize(s),l=(0,n.constructTerrainMesh)(e,Z(t),ja(r),c,a,o),{result:u,transfers:d}=ka(l);return l.free(),$({result:u},[...d])}async function Na(e){let t=await createImageBitmap(e);try{let e=new OffscreenCanvas(t.width,t.height).getContext(`2d`);if(e===null)throw Error(`failed to get context of canvas`);e.drawImage(t,0,0);let n=e.getImageData(0,0,t.width,t.height).data;return $(n,[n.buffer])}finally{t.close()}}async function Pa(e,t){try{let n=t.getContext(`2d`);if(n===null)throw Error(`failed to get context of canvas`);return n.drawImage(e,0,0),n.getImageData(0,0,e.width,e.height).data}finally{e.close()}}async function Fa(e,t,r,i,a,o,s){await Q();let c=(0,n.parseMvtTile)(e,t,r,i,a?ya(a):void 0,o,s),l,u,d,f,p;try{l=c.f64_stream(),u=c.f32_stream(),d=c.u32_stream(),f=c.u8_stream(),p=c.meta()}finally{c.free()}return $({f64_stream:l,f32_stream:u,u32_stream:d,u8_stream:f,meta:p},[l.buffer,u.buffer,d.buffer,f.buffer])}async function Ia(e,t,r,i,a,o,s){await Q();let c=(0,n.upsampleQuantizedMeshTerrainMesh)(Z(e),Z(t),va(r),i,a,o,s),{result:l,transfers:u}=ka(c);return c.free(),$(l,u)}async function La(e,t,r,i,a,o,s){await Q();let c=(0,n.upsampleTerrainMesh)(Z(e),Z(t),ja(r),va(i),a,o,s),{result:l,transfers:u}=ka(c);return c.free(),$(l,u)}async function Ra(){await Q()}var za={constructTerrainMesh:Ma,constructQuantizedMeshTerrainMesh:Aa,upsampleTerrainMesh:La,upsampleQuantizedMeshTerrainMesh:Ia,getImageDataFromImageBitmap:Pa,getImageDataFromBlob:Na,constructPolygonBatchedFeature:wa,constructPolylineBatchedFeature:Oa,parseMvtTile:Fa,warmUp:Ra,getWasmMemoryUsage:Ca},$=(e,t)=>new T.Transfer(e,t),Ba=!1,Va=(...e)=>(Ba||=(T.worker(za),Ha(),!0),T.worker(...e));function Ha(){za.warmUp.worker?.addAbortListener(async()=>{})}var{initializeWorkerPool:Ua,terminateWorkerPool:Wa,warmUpWorkerPool:Ga,worker:Ka,workerPoolStats:qa,workerPoolHeapStats:Ja,probeWorkerPoolHeap:Ya}=(()=>{let e;return{initializeWorkerPool:(t,n,r)=>{if(e)throw Error(`Worker pool has already been initialized.`);e={pool:new re(t,n.total,r),manager:n}},terminateWorkerPool:()=>{e&&=(e.pool.terminate(),void 0)},warmUpWorkerPool:()=>(m(e,`initializeWorkerPool() must be invoked first.`),e.pool.warmUp()),worker:()=>(m(e,`initializeWorkerPool() must be invoked first.`),{pool:e.pool,manager:e.manager}),workerPoolStats:()=>e?.pool.stats(),workerPoolHeapStats:()=>e?.pool.heapStats(),probeWorkerPoolHeap:()=>e?.pool.probeHeap()}})(),Xa=()=>{let{pool:e,manager:t}=Ka();return t.canIncrement()&&e.canAcceptTasks()};function Za(e,t,n){let{pool:r,manager:i}=Ka();i.increment();try{return r.exec(e,t,n).then(e=>(i.decrement(),e)).catch(e=>{throw i.decrement(),e})}catch(e){throw i.decrement(),e}}e.canWorkerProcessImmediately=Xa,e.createConcurrencyManager=e=>{let t=0,n=()=>t!==e,r=()=>t!==0;return{total:e,actives:()=>t,idles:()=>e-t,increment:()=>{n()&&t++},decrement:()=>{r()&&t--},canIncrement:n,canDecrement:r,reset:()=>{t=0}}},e.initializeWorkerPool=Ua,e.probeWorkerPoolHeap=Ya,e.queueTask=Za,e.registerTasks=Va,e.terminateWorkerPool=Wa,e.transfer=$,e.warmUpWorkerPool=Ga,e.workerPoolHeapStats=Ja,e.workerPoolStats=qa});
@@ -0,0 +1,19 @@
1
+ export type ConcurrencyManager = {
2
+ /** Total concurrency */
3
+ total: number;
4
+ /** Increment the count according to the activated process */
5
+ increment: () => void;
6
+ /** Decrement the count according to the deactivated process */
7
+ decrement: () => void;
8
+ /** Reset the count */
9
+ reset: () => void;
10
+ /** The number of activated processes */
11
+ actives: () => number;
12
+ /** The number of idle processes */
13
+ idles: () => number;
14
+ /** Whether it can activate the process */
15
+ canIncrement: () => boolean;
16
+ /** Whether there is an activated process */
17
+ canDecrement: () => boolean;
18
+ };
19
+ export declare const createConcurrencyManager: (total: number) => ConcurrencyManager;
package/dist/pool.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { Promise } from 'workerpool';
2
+ import { ExecOptions } from 'workerpool/types/types';
3
+ import { ConcurrencyManager } from './manager';
4
+ import { RecyclingWorkerPoolOptions } from './recyclingPool';
5
+ import { CommonTasks } from './worker';
6
+ export type { Promise } from 'workerpool';
7
+ export type { RecyclingWorkerPoolOptions, WorkerPoolHeapStats, WorkerPoolStats, } from './recyclingPool';
8
+ declare const initializeWorkerPool: (url: string, manager: ConcurrencyManager, options?: RecyclingWorkerPoolOptions) => void, terminateWorkerPool: () => void, warmUpWorkerPool: () => globalThis.Promise<void>, workerPoolStats: () => import('./recyclingPool').WorkerPoolStats | undefined, workerPoolHeapStats: () => import('./recyclingPool').WorkerPoolHeapStats | undefined, probeWorkerPoolHeap: () => void | undefined;
9
+ export { initializeWorkerPool, terminateWorkerPool, warmUpWorkerPool, workerPoolStats, workerPoolHeapStats, probeWorkerPoolHeap, };
10
+ export declare const canWorkerProcessImmediately: () => boolean;
11
+ export type { ExecOptions } from 'workerpool/types/types';
12
+ type GetTaskName<Task> = Task extends Record<string, unknown> ? keyof Task : string;
13
+ type AnyFunction = (...args: any) => any;
14
+ export type WorkerTask<T extends Record<string, AnyFunction>> = T & CommonTasks;
15
+ export type TaskParams<Task extends CommonTasks, Name extends keyof Task> = Parameters<Task[Name] extends AnyFunction ? Task[Name] : (...args: unknown[]) => unknown>;
16
+ type MethodReturnType<Task extends CommonTasks, Name extends GetTaskName<Task>, R = Awaited<ReturnType<Task[Name]>>> = R extends infer U ? U : R;
17
+ export declare function queueTask<Task extends CommonTasks, Name extends GetTaskName<Task>>(method: Name, params?: TaskParams<Task, Name>, options?: ExecOptions): Promise<MethodReturnType<Task, Name>>;
@@ -0,0 +1,86 @@
1
+ import { Promise as WorkerpoolPromise } from 'workerpool';
2
+ import { default as Pool } from 'workerpool/types/Pool';
3
+ import { ExecOptions } from 'workerpool/types/types';
4
+ /**
5
+ * WASM linear memory budget per worker; a worker measured over this budget
6
+ * is recycled. Must be comfortably above the post-init baseline heap, or
7
+ * recycling would thrash.
8
+ */
9
+ export declare const MAX_WORKER_HEAP_BYTES_DEFAULT: number;
10
+ /**
11
+ * Backstop for when heap probes cannot run (a failed probe already recycles
12
+ * conservatively, so this only matters if probing silently stalls).
13
+ */
14
+ export declare const RECYCLE_AFTER_TASKS_BACKSTOP = 128;
15
+ export declare const RECYCLE_IDLE_MS = 5000;
16
+ /**
17
+ * How long workerpool waits for a worker to acknowledge a cleanup message
18
+ * (sent on cancel-while-running) before force-terminating it. A worker busy
19
+ * in a synchronous WASM task cannot respond until the task finishes, so the
20
+ * default (1s) would terminate exactly the long-running tasks the worker-side
21
+ * abort listener is meant to keep alive (see `keepWorkerAliveOnAbort`). Must
22
+ * comfortably exceed the longest expected task; a genuinely wedged worker
23
+ * still gets terminated once this elapses.
24
+ */
25
+ export declare const WORKER_TERMINATE_TIMEOUT_MS = 30000;
26
+ export type RecyclingWorkerPoolOptions = {
27
+ /** Overrides {@link MAX_WORKER_HEAP_BYTES_DEFAULT}. */
28
+ maxWorkerHeapBytes?: number;
29
+ };
30
+ export type WorkerPoolStats = ReturnType<Pool["stats"]> & {
31
+ tasksSinceSpawn: number;
32
+ };
33
+ export type WorkerPoolHeapStats = {
34
+ /** Last probed WASM heap per slot (undefined = not probed yet). */
35
+ perSlot: (number | undefined)[];
36
+ /** Sum of the probed heaps. */
37
+ totalBytes: number;
38
+ /** The per-worker budget slots are recycled against. */
39
+ maxWorkerHeapBytes: number;
40
+ };
41
+ export declare class RecyclingWorkerPool {
42
+ private readonly url;
43
+ private readonly maxWorkerHeapBytes;
44
+ private readonly slots;
45
+ private idleSweepTimer;
46
+ private terminated;
47
+ constructor(url: string, maxWorkers: number, options?: RecyclingWorkerPoolOptions);
48
+ exec<T extends (...args: any[]) => any>(method: string | T, params?: Parameters<T> | null, options?: ExecOptions): WorkerpoolPromise<ReturnType<T>>;
49
+ /**
50
+ * Pre-initializes WASM on the workers so that upcoming tasks don't pay
51
+ * the initialization latency. Warms a single worker and resolves once it
52
+ * is ready; the rest warm in the background. Correctness doesn't depend
53
+ * on warm workers (every task awaits WASM internally), and a slot whose
54
+ * warm-up fails surfaces the error on its next real task — the same
55
+ * policy as a recycled slot. Rejects only when every worker fails to
56
+ * warm, which signals a broken worker setup.
57
+ */
58
+ warmUp(): Promise<void>;
59
+ /**
60
+ * Whether at least one worker is still under its heap budget. When false,
61
+ * every slot is draining and upstream intake should pause until a recycled
62
+ * worker comes back (tasks dispatched anyway still run, on the
63
+ * least-loaded draining slot).
64
+ */
65
+ canAcceptTasks(): boolean;
66
+ stats(): WorkerPoolStats;
67
+ /**
68
+ * Aggregated WASM heap sizes from the most recent probes. Values are
69
+ * point-in-time samples taken after task settlements (or {@link probeHeap});
70
+ * under load they lag by the tasks queued ahead of the probe.
71
+ */
72
+ heapStats(): WorkerPoolHeapStats;
73
+ /**
74
+ * Requests a fresh heap probe on every non-draining slot (draining slots
75
+ * are about to be recycled anyway). Probes coalesce per slot, so calling
76
+ * this at display frequency is safe.
77
+ */
78
+ probeHeap(): void;
79
+ terminate(): void;
80
+ private pickSlot;
81
+ private onSettled;
82
+ private recycleSlot;
83
+ private warmSlot;
84
+ private probeSlot;
85
+ private armIdleSweep;
86
+ }
@@ -0,0 +1,2 @@
1
+ import { PolygonMaterialLike, TransferablePolygonBatchedFeatureLike, ConstructedPolygonGeometryLike, ExtentRadianF32Like } from '@navaramap/core';
2
+ export declare function constructPolygonBatchedFeature(transferableBatchedFeatureLike: TransferablePolygonBatchedFeatureLike, materialLike: PolygonMaterialLike, flat: boolean, tile_extent: ExtentRadianF32Like | undefined): Promise<ConstructedPolygonGeometryLike | undefined>;
@@ -0,0 +1,2 @@
1
+ import { TransferablePolylineBatchedFeatureLike, PolylineMaterialLike, ConstructedPolylineGeometryLike } from '@navaramap/core';
2
+ export declare function constructPolylineBatchedFeature(transferableBatchedFeatureLike: TransferablePolylineBatchedFeatureLike, materialLike: PolylineMaterialLike, flat: boolean): Promise<ConstructedPolylineGeometryLike | undefined>;
@@ -0,0 +1,4 @@
1
+ import { ReturnedConstructedTerrainMeshLike, TransferableTileLike } from '@navaramap/core';
2
+ export declare function constructQuantizedMeshTerrainMesh(bytes: Uint8Array, tile: TransferableTileLike, skirt: boolean, skirtExaggeration: number, geographic: boolean, tms: boolean): Promise<{
3
+ result: ReturnedConstructedTerrainMeshLike;
4
+ }>;
@@ -0,0 +1,4 @@
1
+ import { TransferableTileLike, TransferableRasterDEMDataLike, ReturnedConstructedTerrainMeshLike } from '@navaramap/core';
2
+ export declare function constructTerrainMesh(bytes: Uint8Array, tile: TransferableTileLike, rasterDEMData: TransferableRasterDEMDataLike, size: number, skirt: boolean, skirtExaggeration: number): Promise<{
3
+ result: ReturnedConstructedTerrainMeshLike;
4
+ }>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Decode a compressed image Blob into raw RGBA pixels entirely off the main
3
+ * thread. Running `createImageBitmap` inside the worker keeps the (potentially
4
+ * expensive) image decode off the main thread, which matters for DEM /
5
+ * elevation tiles that stream in large numbers while panning and zooming.
6
+ *
7
+ * The pixel buffer is transferred back to the caller (not structured-cloned),
8
+ * so the worker→main hand-off moves ownership instead of copying width*height*4
9
+ * bytes. The Blob argument is already cheap to pass in: its structured clone
10
+ * shares the immutable backing bytes by reference, and Blob is not transferable.
11
+ */
12
+ export declare function getImageDataFromBlob(blob: Blob): Promise<Uint8ClampedArray>;
@@ -0,0 +1 @@
1
+ export declare function getImageDataFromImageBitmap(img: ImageBitmap, canvas: OffscreenCanvas): Promise<Uint8ClampedArray>;
@@ -0,0 +1,26 @@
1
+ import { constructPolygonBatchedFeature } from './constructPolygonBatchedFeature';
2
+ import { constructPolylineBatchedFeature } from './constructPolylineBatchedFeature';
3
+ import { constructQuantizedMeshTerrainMesh } from './constructQuantizedMeshTerrainMesh';
4
+ import { constructTerrainMesh } from './constructTerrainMesh';
5
+ import { getImageDataFromBlob } from './getImageDataFromBlob';
6
+ import { getImageDataFromImageBitmap } from './getImageDataFromImageBitmap';
7
+ import { parseMvtTile } from './parseMvtTile';
8
+ import { upsampleQuantizedMeshTerrainMesh } from './upsampleQuantizedMeshTerrainMesh';
9
+ import { upsampleTerrainMesh } from './upsampleTerrainMesh';
10
+ import { getWasmMemoryUsage } from './waitWasm';
11
+ /** Pre-warm worker by initializing WASM module */
12
+ export declare function warmUp(): Promise<void>;
13
+ export declare const commonTasks: {
14
+ constructTerrainMesh: typeof constructTerrainMesh;
15
+ constructQuantizedMeshTerrainMesh: typeof constructQuantizedMeshTerrainMesh;
16
+ upsampleTerrainMesh: typeof upsampleTerrainMesh;
17
+ upsampleQuantizedMeshTerrainMesh: typeof upsampleQuantizedMeshTerrainMesh;
18
+ getImageDataFromImageBitmap: typeof getImageDataFromImageBitmap;
19
+ getImageDataFromBlob: typeof getImageDataFromBlob;
20
+ constructPolygonBatchedFeature: typeof constructPolygonBatchedFeature;
21
+ constructPolylineBatchedFeature: typeof constructPolylineBatchedFeature;
22
+ parseMvtTile: typeof parseMvtTile;
23
+ warmUp: typeof warmUp;
24
+ getWasmMemoryUsage: typeof getWasmMemoryUsage;
25
+ };
26
+ export type CommonTasks = typeof commonTasks;
@@ -0,0 +1,15 @@
1
+ import { ExtentRadianF32Like } from '@navaramap/core';
2
+ /**
3
+ * A whole tile's parsed groups packed into four per-type streams (see
4
+ * `navara_parser::mvt::pack_parsed_mvt_groups` for the segment order). The
5
+ * tile meta (per-group headers + per-layer property tables) rides along as a
6
+ * structured clone; only the four stream buffers are transferred.
7
+ */
8
+ export type ParsedMvtTileResultLike = {
9
+ f64_stream: Float64Array;
10
+ f32_stream: Float32Array;
11
+ u32_stream: Uint32Array;
12
+ u8_stream: Uint8Array;
13
+ meta: unknown;
14
+ };
15
+ export declare function parseMvtTile(bytes: Uint8Array, x: number, y: number, z: number, tileExtent: ExtentRadianF32Like | undefined, compression: number, configsJson: string): Promise<ParsedMvtTileResultLike>;
@@ -0,0 +1,2 @@
1
+ import { ReturnedConstructedTerrainMeshLike, TransferableTileLike, UpsamplableTerrainGeometryLike } from '@navaramap/core';
2
+ export declare function upsampleQuantizedMeshTerrainMesh(tile: TransferableTileLike, parentTile: TransferableTileLike, upsamplableGeometry: UpsamplableTerrainGeometryLike, skirt: boolean, skirtExaggeration: number, geographic: boolean, tms: boolean): Promise<ReturnedConstructedTerrainMeshLike>;
@@ -0,0 +1,2 @@
1
+ import { ReturnedConstructedTerrainMeshLike, TransferableRasterDEMDataLike, TransferableTileLike, UpsamplableTerrainGeometryLike } from '@navaramap/core';
2
+ export declare function upsampleTerrainMesh(tile: TransferableTileLike, parentTile: TransferableTileLike, rasterDEMData: TransferableRasterDEMDataLike, upsamplableGeometry: UpsamplableTerrainGeometryLike, skirt: boolean, skirtExaggeration: number, tms: boolean): Promise<ReturnedConstructedTerrainMeshLike>;
@@ -0,0 +1,8 @@
1
+ import { InitOutput } from '@navaramap/engine-worker';
2
+ export declare function waitWasm(): Promise<InitOutput>;
3
+ /**
4
+ * Reports this worker's WASM linear memory size in bytes (0 when WASM is not
5
+ * initialized yet). Linear memory only grows, so the main thread probes this
6
+ * after settled tasks to decide when to recycle the worker.
7
+ */
8
+ export declare function getWasmMemoryUsage(): Promise<number>;
@@ -0,0 +1,5 @@
1
+ export * from './toTransferableTileLike';
2
+ export * from './toTransferableMartiniLike';
3
+ export * from './toUpsamplableTerrainGeometryLike';
4
+ export * from './toExtentRadianF32Like';
5
+ export * from './toVec3Like';
@@ -0,0 +1,3 @@
1
+ import { ExtentRadianF32Like } from '@navaramap/core';
2
+ import { ExtentRadianF32 } from '@navaramap/engine-worker';
3
+ export declare function toExtentRadianF32Like(like: ExtentRadianF32Like): ExtentRadianF32;
@@ -0,0 +1,3 @@
1
+ import { PolygonMaterialLike } from '@navaramap/core';
2
+ import { PolygonMaterial } from '@navaramap/engine-worker';
3
+ export declare function toPolygonMaterialLike(like: PolygonMaterialLike): PolygonMaterial;
@@ -0,0 +1,3 @@
1
+ import { PolylineMaterialLike } from '@navaramap/core';
2
+ import { PolylineMaterial } from '@navaramap/engine-worker';
3
+ export declare function toPolylineMaterialLike(like: PolylineMaterialLike): PolylineMaterial;
@@ -0,0 +1,3 @@
1
+ import { TransferableMartiniLike } from '@navaramap/core';
2
+ import { TransferableMartini } from '@navaramap/engine-worker';
3
+ export declare function toTransferableMartini(like: TransferableMartiniLike): TransferableMartini;
@@ -0,0 +1,3 @@
1
+ import { TransferablePolygonBatchedFeatureLike } from '@navaramap/core';
2
+ import { TransferablePolygonBatchedFeature } from '@navaramap/engine-worker';
3
+ export declare function toTransferablePolygonBatchedFeatureLike(like: TransferablePolygonBatchedFeatureLike): TransferablePolygonBatchedFeature;
@@ -0,0 +1,3 @@
1
+ import { TransferablePolylineBatchedFeatureLike } from '@navaramap/core';
2
+ import { TransferablePolylineBatchedFeature } from '@navaramap/engine-worker';
3
+ export declare function toTransferablePolylineBatchedFeatureLike(like: TransferablePolylineBatchedFeatureLike): TransferablePolylineBatchedFeature;
@@ -0,0 +1,3 @@
1
+ import { TransferableRasterDEMDataLike } from '@navaramap/core';
2
+ import { TransferableRasterDEMData } from '@navaramap/engine-worker';
3
+ export declare function toTransferableRasterDEMDataLike(like: TransferableRasterDEMDataLike): TransferableRasterDEMData;
@@ -0,0 +1,5 @@
1
+ import { TransferableTileLike, TileXYZLike, CachedMeshHandleLike } from '@navaramap/core';
2
+ import { CachedMeshHandle, TileXYZ, TransferableTile } from '@navaramap/engine-worker';
3
+ export declare function toTransferableTile(like: TransferableTileLike): TransferableTile;
4
+ export declare function toTileXYZ(like: TileXYZLike): TileXYZ;
5
+ export declare function toCachedMeshHandle(like: CachedMeshHandleLike): CachedMeshHandle;
@@ -0,0 +1,3 @@
1
+ import { UpsamplableTerrainGeometryLike } from '@navaramap/core';
2
+ import { UpsamplableTerrainGeometry } from '@navaramap/engine-worker';
3
+ export declare function toUpsamplableTerrainGeometry(like: UpsamplableTerrainGeometryLike): UpsamplableTerrainGeometry;
@@ -0,0 +1,3 @@
1
+ import { Vec3Like } from '@navaramap/core';
2
+ import { Vec3 } from '@navaramap/engine-worker';
3
+ export declare function toVec3Like(like: Vec3): Vec3Like;
@@ -0,0 +1,4 @@
1
+ import { default as workerpool } from 'workerpool';
2
+ export { type CommonTasks } from '../tasks';
3
+ export * from './transfer';
4
+ export declare const registerTasks: (...args: Parameters<typeof workerpool.worker>) => void;
@@ -0,0 +1 @@
1
+ export declare const transfer: <T extends object>(message: T, transfer: Transferable[]) => T;
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@navaramap/worker",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "main": "dist/index.umd.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "src",
10
+ "dist"
11
+ ],
12
+ "license": "MIT OR Apache-2.0",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/eukarya-inc/navara.git",
16
+ "directory": "web/navara_worker"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "dependencies": {
22
+ "workerpool": "10.0.1",
23
+ "@navaramap/engine-worker": "0.0.0",
24
+ "@navaramap/core": "0.0.0"
25
+ },
26
+ "scripts": {
27
+ "type-check": "tsc && tsc -p tsconfig.node.json",
28
+ "build": "pnpm type-check && vite build --watch=false",
29
+ "build:dev": "vite build --mode development",
30
+ "build:dev:watch": "pnpm build:dev --watch",
31
+ "test": "vitest --passWithNoTests --watch=false",
32
+ "lint": "eslint . --fix",
33
+ "lint:check": "eslint .",
34
+ "format": "prettier --write --ignore-path ../../.gitignore --ignore-path ../../.prettierignore .",
35
+ "format:check": "prettier --check --ignore-path ../../.gitignore --ignore-path ../../.prettierignore ."
36
+ }
37
+ }
@@ -0,0 +1,25 @@
1
+ import { isNotNullish, ConstructedPolygonGeometryLike } from "@navaramap/core";
2
+ import type { ConstructedPolygonGeometry } from "@navaramap/engine-worker";
3
+
4
+ export function transferConstructedPolygonGeometry(
5
+ r: ConstructedPolygonGeometry,
6
+ ) {
7
+ const like = new ConstructedPolygonGeometryLike(r);
8
+ return {
9
+ result: like,
10
+ transfers: [
11
+ like.batch_id?.buffer,
12
+ like.batch_index?.buffer,
13
+ like.normal?.buffer,
14
+ like.position_3d_high?.buffer,
15
+ like.position_3d_low?.buffer,
16
+ like.position?.buffer,
17
+ like.scale_normal_and_cap?.buffer,
18
+ like.indices.buffer,
19
+ like.outline_position?.buffer,
20
+ like.outline_scale_normal_and_cap?.buffer,
21
+ like.outline_skip_indices?.buffer,
22
+ like.outline_batch_index?.buffer,
23
+ ].filter(isNotNullish),
24
+ };
25
+ }
@@ -0,0 +1,28 @@
1
+ import { ConstructedPolylineGeometryLike, isNotNullish } from "@navaramap/core";
2
+ import type { ConstructedPolylineGeometry } from "@navaramap/engine-worker";
3
+
4
+ export function transferConstructedPolylineGeometry(
5
+ r: ConstructedPolylineGeometry,
6
+ ) {
7
+ const like = new ConstructedPolylineGeometryLike(r);
8
+ return {
9
+ result: like,
10
+ transfers: [
11
+ like.position.buffer,
12
+ like.position_high?.buffer,
13
+ like.position_low?.buffer,
14
+ like.start?.buffer,
15
+ like.start_high?.buffer,
16
+ like.start_low?.buffer,
17
+ like.end_high?.buffer,
18
+ like.end_low?.buffer,
19
+ like.start_normals?.buffer,
20
+ like.forward_offset?.buffer,
21
+ like.end_normal_and_texture_coordinate_normalization_x?.buffer,
22
+ like.right_normal_and_texture_coordinate_normalization_y.buffer,
23
+ like.batch_id?.buffer,
24
+ like.batch_index?.buffer,
25
+ like.indices.buffer,
26
+ ].filter(isNotNullish),
27
+ };
28
+ }