@loaders.gl/csv 3.0.9 → 3.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.min.js CHANGED
@@ -5,5 +5,5 @@ v5.0.0-beta.0
5
5
  https://github.com/mholt/PapaParse
6
6
  License: MIT
7
7
  */
8
- var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==r?r:{},i={};function n(e){this._handle=null,this._finished=!1,this._completed=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},function(e){var t=l(e);t.chunkSize=parseInt(t.chunkSize),e.step||e.chunk||(t.chunkSize=null);this._handle=new a(t),this._handle.streamer=this,this._config=t}.call(this,e),this.parseChunk=function(e,t){if(this.isFirstChunk&&u(this._config.beforeFirstChunk)){var r=this._config.beforeFirstChunk(e);void 0!==r&&(e=r)}this.isFirstChunk=!1;var i=this._partialLine+e;this._partialLine="";var n=this._handle.parse(i,this._baseIndex,!this._finished);if(!this._handle.paused()&&!this._handle.aborted()){var s=n.meta.cursor;this._finished||(this._partialLine=i.substring(s-this._baseIndex),this._baseIndex=s),n&&n.data&&(this._rowCount+=n.data.length);var a=this._finished||this._config.preview&&this._rowCount>=this._config.preview;if(u(this._config.chunk)&&!t){if(this._config.chunk(n,this._handle),this._handle.paused()||this._handle.aborted())return;n=void 0,this._completeResults=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(n.data),this._completeResults.errors=this._completeResults.errors.concat(n.errors),this._completeResults.meta=n.meta),this._completed||!a||!u(this._config.complete)||n&&n.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),a||n&&n.meta.paused||this._nextChunk(),n}},this._sendError=function(e){u(this._config.error)&&this._config.error(e)}}function s(e){var t;e=e||{},n.call(this,e),this.stream=function(e){return t=e,this._nextChunk()},this._nextChunk=function(){if(!this._finished){var e=this._config.chunkSize,r=e?t.substr(0,e):t;return t=e?t.substr(e):"",this._finished=!t,this.parseChunk(r)}}}function a(e){var t,r,n,s=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,a=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,c=this,d=0,f=0,p=!1,g=!1,m=[],y={data:[],errors:[],meta:{}};if(u(e.step)){var w=e.step;e.step=function(t){if(y=t,_())v();else{if(v(),!y.data||0===y.data.length)return;d+=t.data.length,e.preview&&d>e.preview?r.abort():w(y,c)}}}function b(t){return"greedy"===e.skipEmptyLines?""===t.join("").trim():1===t.length&&0===t[0].length}function v(){if(y&&n&&(C("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+i.DefaultDelimiter+"'"),n=!1),e.skipEmptyLines)for(var t=0;t<y.data.length;t++)b(y.data[t])&&y.data.splice(t--,1);return _()&&function(){if(!y)return;function t(t){u(e.transformHeader)&&(t=e.transformHeader(t)),m.push(t)}if(Array.isArray(y.data[0])){for(var r=0;_()&&r<y.data.length;r++)y.data[r].forEach(t);y.data.splice(0,1)}else y.data.forEach(t)}(),function(){if(!y||!y.data||!e.header&&!e.dynamicTyping&&!e.transform)return y;function t(t,r){var i,n=e.header?{}:[];for(i=0;i<t.length;i++){var s=i,a=t[i];e.header&&(s=i>=m.length?"__parsed_extra":m[i]),e.transform&&(a=e.transform(a,s)),a=A(s,a),"__parsed_extra"===s?(n[s]=n[s]||[],n[s].push(a)):n[s]=a}return e.header&&(i>m.length?C("FieldMismatch","TooManyFields","Too many fields: expected "+m.length+" fields but parsed "+i,f+r):i<m.length&&C("FieldMismatch","TooFewFields","Too few fields: expected "+m.length+" fields but parsed "+i,f+r)),n}var r=1;!y.data[0]||Array.isArray(y.data[0])?(y.data=y.data.map(t),r=y.data.length):y.data=t(y.data,0);e.header&&y.meta&&(y.meta.fields=m);return f+=r,y}()}function _(){return e.header&&0===m.length}function A(t,r){return function(t){return e.dynamicTypingFunction&&void 0===e.dynamicTyping[t]&&(e.dynamicTyping[t]=e.dynamicTypingFunction(t)),!0===(e.dynamicTyping[t]||e.dynamicTyping)}(t)?"true"===r||"TRUE"===r||"false"!==r&&"FALSE"!==r&&(s.test(r)?parseFloat(r):a.test(r)?new Date(r):""===r?null:r):r}function C(e,t,r,i){y.errors.push({type:e,code:t,message:r,row:i})}this.parse=function(s,a,c){var d=e.quoteChar||'"';if(e.newline||(e.newline=function(e,t){e=e.substr(0,1048576);var r=new RegExp(o(t)+"([^]*?)"+o(t),"gm"),i=(e=e.replace(r,"")).split("\r"),n=e.split("\n"),s=n.length>1&&n[0].length<i[0].length;if(1===i.length||s)return"\n";for(var a=0,h=0;h<i.length;h++)"\n"===i[h][0]&&a++;return a>=i.length/2?"\r\n":"\r"}(s,d)),n=!1,e.delimiter)u(e.delimiter)&&(e.delimiter=e.delimiter(s),y.meta.delimiter=e.delimiter);else{var f=function(t,r,n,s,a){var o,l,u;a=a||[",","\t","|",";",i.RECORD_SEP,i.UNIT_SEP];for(var c=0;c<a.length;c++){var d=a[c],f=0,p=0,g=0;u=void 0;for(var m=new h({comments:s,delimiter:d,newline:r,preview:10}).parse(t),y=0;y<m.data.length;y++)if(n&&b(m.data[y]))g++;else{var w=m.data[y].length;p+=w,void 0!==u?w>1&&(f+=Math.abs(w-u),u=w):u=0}m.data.length>0&&(p/=m.data.length-g),(void 0===l||f>l)&&p>1.99&&(l=f,o=d)}return e.delimiter=o,{successful:!!o,bestDelimiter:o}}(s,e.newline,e.skipEmptyLines,e.comments,e.delimitersToGuess);f.successful?e.delimiter=f.bestDelimiter:(n=!0,e.delimiter=i.DefaultDelimiter),y.meta.delimiter=e.delimiter}var g=l(e);return e.preview&&e.header&&g.preview++,t=s,r=new h(g),y=r.parse(t,a,c),v(),p?{meta:{paused:!0}}:y||{meta:{paused:!1}}},this.paused=function(){return p},this.pause=function(){p=!0,r.abort(),t=t.substr(r.getCharIndex())},this.resume=function(){p=!1,c.streamer.parseChunk(t,!0)},this.aborted=function(){return g},this.abort=function(){g=!0,r.abort(),y.meta.aborted=!0,u(e.complete)&&e.complete(y),t=""}}function o(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function h(e){var t,r=(e=e||{}).delimiter,n=e.newline,s=e.comments,a=e.step,h=e.preview,l=e.fastMode,c=t=void 0===e.quoteChar?'"':e.quoteChar;if(void 0!==e.escapeChar&&(c=e.escapeChar),("string"!=typeof r||i.BAD_DELIMITERS.indexOf(r)>-1)&&(r=","),s===r)throw new Error("Comment character same as delimiter");!0===s?s="#":("string"!=typeof s||i.BAD_DELIMITERS.indexOf(s)>-1)&&(s=!1),"\n"!==n&&"\r"!==n&&"\r\n"!==n&&(n="\n");var d=0,f=!1;this.parse=function(e,i,p){if("string"!=typeof e)throw new Error("Input must be a string");var g=e.length,m=r.length,y=n.length,w=s.length,b=u(a);d=0;var v=[],_=[],A=[],C=0;if(!e)return P();if(l||!1!==l&&-1===e.indexOf(t)){for(var x=e.split(n),R=0;R<x.length;R++){if(A=x[R],d+=A.length,R!==x.length-1)d+=n.length;else if(p)return P();if(!s||A.substr(0,w)!==s){if(b){if(v=[],B(A.split(r)),I(),f)return P()}else B(A.split(r));if(h&&R>=h)return v=v.slice(0,h),P(!0)}}return P()}for(var E,k=e.indexOf(r,d),O=e.indexOf(n,d),S=new RegExp(o(c)+o(t),"g");;)if(e[d]!==t)if(s&&0===A.length&&e.substr(d,w)===s){if(-1===O)return P();d=O+y,O=e.indexOf(n,d),k=e.indexOf(r,d)}else if(-1!==k&&(k<O||-1===O))A.push(e.substring(d,k)),d=k+m,k=e.indexOf(r,d);else{if(-1===O)break;if(A.push(e.substring(d,O)),F(O+y),b&&(I(),f))return P();if(h&&v.length>=h)return P(!0)}else{for(E=d,d++;;){if(-1===(E=e.indexOf(t,E+1)))return p||_.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:v.length,index:d}),M();if(E===g-1)return M(e.substring(d,E).replace(S,t));if(t!==c||e[E+1]!==c){if(t===c||0===E||e[E-1]!==c){var j=D(-1===O?k:Math.min(k,O));if(e[E+1+j]===r){if(A.push(e.substring(d,E).replace(S,t)),d=E+1+j+m,k=e.indexOf(r,d),O=e.indexOf(n,d),b&&(I(),f))return P();if(h&&v.length>=h)return P(!0);break}var T=D(O);if(e.substr(E+1+T,y)===n){if(A.push(e.substring(d,E).replace(S,t)),F(E+1+T+y),k=e.indexOf(r,d),b&&(I(),f))return P();if(h&&v.length>=h)return P(!0);break}_.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:v.length,index:d}),E++}}else E++}if(b&&(I(),f))return P();if(h&&v.length>=h)return P(!0)}return M();function B(e){v.push(e),C=d}function D(t){var r=0;if(-1!==t){var i=e.substring(E+1,t);i&&""===i.trim()&&(r=i.length)}return r}function M(t){return p||(void 0===t&&(t=e.substr(d)),A.push(t),d=g,B(A),b&&I()),P()}function F(t){d=t,B(A),A=[],O=e.indexOf(n,d)}function P(e,t){return{data:t||!1?v[0]:v,errors:_,meta:{delimiter:r,linebreak:n,aborted:f,truncated:!!e,cursor:C+(i||0)}}}function I(){a(P(void 0,!0)),v=[],_=[]}},this.abort=function(){f=!0},this.getCharIndex=function(){return d}}function l(e){if("object"!=typeof e||null===e)return e;var t=Array.isArray(e)?[]:{};for(var r in e)t[r]=l(e[r]);return t}function u(e){return"function"==typeof e}e.exports=i,i.parse=function(e,t,r){var n=(t=t||{}).dynamicTyping||!1;u(n)&&(t.dynamicTypingFunction=n,n={});if(t.dynamicTyping=n,t.transform=!!u(t.transform)&&t.transform,t.worker&&i.WORKERS_SUPPORTED){var a=newWorker();return a.userStep=t.step,a.userChunk=t.chunk,a.userComplete=t.complete,a.userError=t.error,t.step=u(t.step),t.chunk=u(t.chunk),t.complete=u(t.complete),t.error=u(t.error),delete t.worker,void a.postMessage({input:e,config:t,workerId:a.id})}var o=null;"string"==typeof e&&(o=new s(t));o||(o=new r(t));return o.stream(e)},i.unparse=function(e,t){var r=!1,n=!0,s=",",a="\r\n",h='"',l=h+h,u=!1,c=null;!function(){if("object"!=typeof t)return;"string"!=typeof t.delimiter||i.BAD_DELIMITERS.filter((function(e){return-1!==t.delimiter.indexOf(e)})).length||(s=t.delimiter);("boolean"==typeof t.quotes||Array.isArray(t.quotes))&&(r=t.quotes);"boolean"!=typeof t.skipEmptyLines&&"string"!=typeof t.skipEmptyLines||(u=t.skipEmptyLines);"string"==typeof t.newline&&(a=t.newline);"string"==typeof t.quoteChar&&(h=t.quoteChar);"boolean"==typeof t.header&&(n=t.header);if(Array.isArray(t.columns)){if(0===t.columns.length)throw new Error("Option columns is empty");c=t.columns}void 0!==t.escapeChar&&(l=t.escapeChar+h)}();var d=new RegExp(o(h),"g");"string"==typeof e&&(e=JSON.parse(e));if(Array.isArray(e)){if(!e.length||Array.isArray(e[0]))return p(null,e,u);if("object"==typeof e[0])return p(c||f(e[0]),e,u)}else if("object"==typeof e)return"string"==typeof e.data&&(e.data=JSON.parse(e.data)),Array.isArray(e.data)&&(e.fields||(e.fields=e.meta&&e.meta.fields),e.fields||(e.fields=Array.isArray(e.data[0])?e.fields:f(e.data[0])),Array.isArray(e.data[0])||"object"==typeof e.data[0]||(e.data=[e.data])),p(e.fields||[],e.data||[],u);throw new Error("Unable to serialize unrecognized input");function f(e){if("object"!=typeof e)return[];var t=[];for(var r in e)t.push(r);return t}function p(e,t,r){var i="";"string"==typeof e&&(e=JSON.parse(e)),"string"==typeof t&&(t=JSON.parse(t));var o=Array.isArray(e)&&e.length>0,h=!Array.isArray(t[0]);if(o&&n){for(var l=0;l<e.length;l++)l>0&&(i+=s),i+=g(e[l],l);t.length>0&&(i+=a)}for(var u=0;u<t.length;u++){var c=o?e.length:t[u].length,d=!1,f=o?0===Object.keys(t[u]).length:0===t[u].length;if(r&&!o&&(d="greedy"===r?""===t[u].join("").trim():1===t[u].length&&0===t[u][0].length),"greedy"===r&&o){for(var p=[],m=0;m<c;m++){var y=h?e[m]:m;p.push(t[u][y])}d=""===p.join("").trim()}if(!d){for(var w=0;w<c;w++){w>0&&!f&&(i+=s);var b=o&&h?e[w]:w;i+=g(t[u][b],w)}u<t.length-1&&(!r||c>0&&!f)&&(i+=a)}}return i}function g(e,t){return null==e?"":e.constructor===Date?JSON.stringify(e).slice(1,25):(e=e.toString().replace(d,l),"boolean"==typeof r&&r||Array.isArray(r)&&r[t]||function(e,t){for(var r=0;r<t.length;r++)if(e.indexOf(t[r])>-1)return!0;return!1}(e,i.BAD_DELIMITERS)||e.indexOf(s)>-1||" "===e.charAt(0)||" "===e.charAt(e.length-1)?h+e+h:e)}},i.RECORD_SEP=String.fromCharCode(30),i.UNIT_SEP=String.fromCharCode(31),i.BYTE_ORDER_MARK="\ufeff",i.BAD_DELIMITERS=["\r","\n",'"',i.BYTE_ORDER_MARK],i.WORKERS_SUPPORTED=!1,i.NODE_STREAM_INPUT=1,i.LocalChunkSize=10485760,i.RemoteChunkSize=5242880,i.DefaultDelimiter=",",i.Parser=h,i.ParserHandle=a,i.ChunkStreamer=n,i.StringStreamer=s,s.prototype=Object.create(s.prototype),s.prototype.constructor=s},function(e,t,r){(function(t){const i=r(3),n="undefined"==typeof window?t:window;n.loaders=n.loaders||{},e.exports=Object.assign(n.loaders,i)}).call(this,r(2))},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";function i(e,t){if(!e)throw new Error("null row");if(!t)throw new Error("no headers");const r={};for(let i=0;i<t.length;i++)r[t[i]]=e[i];return r}function n(e,t){if(!e)throw new Error("null row");if(!t)throw new Error("no headers");const r=new Array(t.length);for(let i=0;i<t.length;i++)r[i]=e[t[i]];return r}let s;function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.r(t),r.d(t,"CSVLoader",(function(){return C}));class o extends Array{enqueue(e){return this.push(e)}dequeue(){return this.shift()}}s=Symbol.asyncIterator;class h{constructor(){a(this,"_values",void 0),a(this,"_settlers",void 0),a(this,"_closed",void 0),this._values=new o,this._settlers=new o,this._closed=!1}close(){for(;this._settlers.length>0;)this._settlers.dequeue().resolve({done:!0});this._closed=!0}[s](){return this}enqueue(e){if(this._closed)throw new Error("Closed");if(this._settlers.length>0){if(this._values.length>0)throw new Error("Illegal internal state");const t=this._settlers.dequeue();e instanceof Error?t.reject(e):t.resolve({value:e})}else this._values.enqueue(e)}next(){if(this._values.length>0){const e=this._values.dequeue();return e instanceof Error?Promise.reject(e):Promise.resolve({value:e})}if(this._closed){if(this._settlers.length>0)throw new Error("Illegal internal state");return Promise.resolve({done:!0})}return new Promise((e,t)=>{this._settlers.enqueue({resolve:e,reject:t})})}}function l(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class u{constructor(e,t){if(l(this,"schema",void 0),l(this,"options",void 0),l(this,"length",0),l(this,"rows",null),l(this,"cursor",0),l(this,"_headers",[]),this.options=t,this.schema=e,!Array.isArray(e)){this._headers=[];for(const t in e)this._headers[e[t].index]=e[t].name}}rowCount(){return this.length}addArrayRow(e,t){Number.isFinite(t)&&(this.cursor=t),this.rows=this.rows||new Array(100),this.rows[this.length]=e,this.length++}addObjectRow(e,t){Number.isFinite(t)&&(this.cursor=t),this.rows=this.rows||new Array(100),this.rows[this.length]=e,this.length++}getBatch(){let e=this.rows;if(!e)return null;e=e.slice(0,this.length),this.rows=null;return{shape:this.options.shape,batchType:"data",data:e,length:this.length,schema:this.schema,cursor:this.cursor}}}function c(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class d{constructor(e,t){if(c(this,"schema",void 0),c(this,"options",void 0),c(this,"length",0),c(this,"objectRows",null),c(this,"arrayRows",null),c(this,"cursor",0),c(this,"_headers",[]),this.options=t,this.schema=e,!Array.isArray(e)){this._headers=[];for(const t in e)this._headers[e[t].index]=e[t].name}}rowCount(){return this.length}addArrayRow(e,t){switch(Number.isFinite(t)&&(this.cursor=t),this.options.shape){case"object-row-table":const r=i(e,this._headers);this.addObjectRow(r,t);break;case"array-row-table":this.arrayRows=this.arrayRows||new Array(100),this.arrayRows[this.length]=e,this.length++}}addObjectRow(e,t){switch(Number.isFinite(t)&&(this.cursor=t),this.options.shape){case"array-row-table":const r=n(e,this._headers);this.addArrayRow(r,t);break;case"object-row-table":this.objectRows=this.objectRows||new Array(100),this.objectRows[this.length]=e,this.length++}}getBatch(){let e=this.arrayRows||this.objectRows;return e?(e=e.slice(0,this.length),this.arrayRows=null,this.objectRows=null,{shape:this.options.shape,batchType:"data",data:e,length:this.length,schema:this.schema,cursor:this.cursor}):null}}function f(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class p{constructor(e,t){f(this,"schema",void 0),f(this,"length",0),f(this,"allocated",0),f(this,"columns",{}),this.schema=e,this._reallocateColumns()}rowCount(){return this.length}addArrayRow(e){this._reallocateColumns();let t=0;for(const r in this.columns)this.columns[r][this.length]=e[t++];this.length++}addObjectRow(e){this._reallocateColumns();for(const t in e)this.columns[t][this.length]=e[t];this.length++}getBatch(){this._pruneColumns();const e=Array.isArray(this.schema)?this.columns:{};if(!Array.isArray(this.schema))for(const t in this.schema){const r=this.schema[t];e[r.name]=this.columns[r.index]}this.columns={};return{shape:"columnar-table",batchType:"data",data:e,schema:this.schema,length:this.length}}_reallocateColumns(){if(!(this.length<this.allocated)){this.allocated=this.allocated>0?this.allocated*=2:100,this.columns={};for(const e in this.schema){const t=this.schema[e],r=t.type||Float32Array,i=this.columns[t.index];if(i&&ArrayBuffer.isView(i)){const e=new r(this.allocated);e.set(i),this.columns[t.index]=e}else i?(i.length=this.allocated,this.columns[t.index]=i):this.columns[t.index]=new r(this.allocated)}}}_pruneColumns(){for(const[e,t]of Object.entries(this.columns))this.columns[e]=t.slice(0,this.length)}}function g(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const m={shape:"array-row-table",batchSize:"auto",batchDebounceMs:0,limit:0,_limitMB:0};class y{constructor(e,t){g(this,"schema",void 0),g(this,"options",void 0),g(this,"aggregator",null),g(this,"batchCount",0),g(this,"bytesUsed",0),g(this,"isChunkComplete",!1),g(this,"lastBatchEmittedMs",Date.now()),g(this,"totalLength",0),g(this,"totalBytes",0),g(this,"rowBytes",0),this.schema=e,this.options={...m,...t}}limitReached(){var e,t;return!!(Boolean(null===(e=this.options)||void 0===e?void 0:e.limit)&&this.totalLength>=this.options.limit)||!!(Boolean(null===(t=this.options)||void 0===t?void 0:t._limitMB)&&this.totalBytes/1e6>=this.options._limitMB)}addRow(e){this.limitReached()||(this.totalLength++,this.rowBytes=this.rowBytes||this._estimateRowMB(e),this.totalBytes+=this.rowBytes,Array.isArray(e)?this.addArrayRow(e):this.addObjectRow(e))}addArrayRow(e){if(!this.aggregator){const e=this._getTableBatchType();this.aggregator=new e(this.schema,this.options)}this.aggregator.addArrayRow(e)}addObjectRow(e){if(!this.aggregator){const e=this._getTableBatchType();this.aggregator=new e(this.schema,this.options)}this.aggregator.addObjectRow(e)}chunkComplete(e){e instanceof ArrayBuffer&&(this.bytesUsed+=e.byteLength),"string"==typeof e&&(this.bytesUsed+=e.length),this.isChunkComplete=!0}getFullBatch(e){return this._isFull()?this._getBatch(e):null}getFinalBatch(e){return this._getBatch(e)}_estimateRowMB(e){return Array.isArray(e)?8*e.length:8*Object.keys(e).length}_isFull(){if(!this.aggregator||0===this.aggregator.rowCount())return!1;if("auto"===this.options.batchSize){if(!this.isChunkComplete)return!1}else if(this.options.batchSize>this.aggregator.rowCount())return!1;return!(this.options.batchDebounceMs>Date.now()-this.lastBatchEmittedMs)&&(this.isChunkComplete=!1,this.lastBatchEmittedMs=Date.now(),!0)}_getBatch(e){if(!this.aggregator)return null;null!=e&&e.bytesUsed&&(this.bytesUsed=e.bytesUsed);const t=this.aggregator.getBatch();return t.count=this.batchCount,t.bytesUsed=this.bytesUsed,Object.assign(t,e),this.batchCount++,this.aggregator=null,t}_getTableBatchType(){switch(this.options.shape){case"row-table":return u;case"array-row-table":case"object-row-table":return d;case"columnar-table":return p;case"arrow-table":if(!y.ArrowBatch)throw new Error("TableBatchBuilder");return y.ArrowBatch;default:throw new Error("TableBatchBuilder")}}}g(y,"ArrowBatch",void 0);var w=r(0),b=r.n(w);const{ChunkStreamer:v}=b.a;function _(e){e=e||{},v.call(this,e),this.textDecoder=new TextDecoder(this._config.encoding),this.stream=async function(e){this._input=e;try{for await(const t of e)this.parseChunk(this.getStringChunk(t));this._finished=!0,this.parseChunk("")}catch(e){this._sendError(e)}},this._nextChunk=function(){},this.getStringChunk=function(e){return"string"==typeof e?e:this.textDecoder.decode(e,{stream:!0})}}_.prototype=Object.create(v.prototype),_.prototype.constructor=_;const A={csv:{shape:"object-row-table",optimizeMemoryUsage:!1,header:"auto",columnPrefix:"column",quoteChar:'"',escapeChar:'"',dynamicTyping:!0,comments:!1,skipEmptyLines:!0,delimitersToGuess:[",","\t","|",";"]}},C={id:"csv",module:"csv",name:"CSV",version:"3.0.9",extensions:["csv"],mimeTypes:["text/csv"],category:"table",parse:async(e,t)=>x((new TextDecoder).decode(e),t),parseText:(e,t)=>x(e,t),parseInBatches:function(e,t){var r;"auto"===(t={...t}).batchSize&&(t.batchSize=4e3);const i={...A.csv,...null===(r=t)||void 0===r?void 0:r.csv},n=new h;let s=!0,a=null,o=null,l=null;const u={...i,header:!1,download:!1,chunkSize:5242880,skipEmptyLines:!1,step(e){let r=e.data;if(i.skipEmptyLines){if(""===r.flat().join("").trim())return}const h=e.meta.cursor;if(s&&!a){if("auto"===i.header?R(r):Boolean(i.header))return void(a=r.map(E()))}s&&(s=!1,a||(a=k(i.columnPrefix,r.length)),l=function(e,t){const r=t?{}:[];for(let i=0;i<e.length;i++){const n=t&&t[i]||i;switch(typeof e[i]){case"number":case"boolean":r[n]={name:String(n),index:i,type:Float32Array};break;case"string":default:r[n]={name:String(n),index:i,type:Array}}}return r}(r,a)),i.optimizeMemoryUsage&&(r=JSON.parse(JSON.stringify(r))),o=o||new y(l,{shape:i.shape||"array-row-table",...t});try{o.addRow(r);const e=o&&o.getFullBatch({bytesUsed:h});e&&n.enqueue(e)}catch(e){n.enqueue(e)}},complete(e){try{const t=e.meta.cursor,r=o&&o.getFinalBatch({bytesUsed:t});r&&n.enqueue(r)}catch(e){n.enqueue(e)}n.close()}};return b.a.parse(e,u,_),n},options:A};async function x(e,t){const r={...A.csv,...null==t?void 0:t.csv},s=function(e){return b.a.parse(e,{download:!1,dynamicTyping:!0,preview:1}).data[0]}(e),a="auto"===r.header?R(s):Boolean(r.header),o={...r,header:a,download:!1,transformHeader:a?E():void 0,error:e=>{throw new Error(e)}},h=b.a.parse(e,o);let{data:l}=h;const u=h.meta.fields||k(r.columnPrefix,s.length);switch(r.shape){case"object-row-table":l=l.map(e=>Array.isArray(e)?i(e,u):e);break;case"array-row-table":l=l.map(e=>Array.isArray(e)?e:n(e,u))}return l}function R(e){return e&&e.every(e=>"string"==typeof e)}function E(){const e=new Set;return t=>{let r=t,i=1;for(;e.has(r);)r=`${t}.${i}`,i++;return e.add(r),r}}function k(e,t=0){const r=[];for(let i=0;i<t;i++)r.push(`${e}${i+1}`);return r}}])}));
8
+ var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==r?r:{},i={};function n(e){this._handle=null,this._finished=!1,this._completed=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},function(e){var t=l(e);t.chunkSize=parseInt(t.chunkSize),e.step||e.chunk||(t.chunkSize=null);this._handle=new a(t),this._handle.streamer=this,this._config=t}.call(this,e),this.parseChunk=function(e,t){if(this.isFirstChunk&&u(this._config.beforeFirstChunk)){var r=this._config.beforeFirstChunk(e);void 0!==r&&(e=r)}this.isFirstChunk=!1;var i=this._partialLine+e;this._partialLine="";var n=this._handle.parse(i,this._baseIndex,!this._finished);if(!this._handle.paused()&&!this._handle.aborted()){var s=n.meta.cursor;this._finished||(this._partialLine=i.substring(s-this._baseIndex),this._baseIndex=s),n&&n.data&&(this._rowCount+=n.data.length);var a=this._finished||this._config.preview&&this._rowCount>=this._config.preview;if(u(this._config.chunk)&&!t){if(this._config.chunk(n,this._handle),this._handle.paused()||this._handle.aborted())return;n=void 0,this._completeResults=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(n.data),this._completeResults.errors=this._completeResults.errors.concat(n.errors),this._completeResults.meta=n.meta),this._completed||!a||!u(this._config.complete)||n&&n.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),a||n&&n.meta.paused||this._nextChunk(),n}},this._sendError=function(e){u(this._config.error)&&this._config.error(e)}}function s(e){var t;e=e||{},n.call(this,e),this.stream=function(e){return t=e,this._nextChunk()},this._nextChunk=function(){if(!this._finished){var e=this._config.chunkSize,r=e?t.substr(0,e):t;return t=e?t.substr(e):"",this._finished=!t,this.parseChunk(r)}}}function a(e){var t,r,n,s=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,a=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,c=this,d=0,f=0,p=!1,g=!1,m=[],y={data:[],errors:[],meta:{}};if(u(e.step)){var w=e.step;e.step=function(t){if(y=t,_())v();else{if(v(),!y.data||0===y.data.length)return;d+=t.data.length,e.preview&&d>e.preview?r.abort():w(y,c)}}}function b(t){return"greedy"===e.skipEmptyLines?""===t.join("").trim():1===t.length&&0===t[0].length}function v(){if(y&&n&&(C("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+i.DefaultDelimiter+"'"),n=!1),e.skipEmptyLines)for(var t=0;t<y.data.length;t++)b(y.data[t])&&y.data.splice(t--,1);return _()&&function(){if(!y)return;function t(t){u(e.transformHeader)&&(t=e.transformHeader(t)),m.push(t)}if(Array.isArray(y.data[0])){for(var r=0;_()&&r<y.data.length;r++)y.data[r].forEach(t);y.data.splice(0,1)}else y.data.forEach(t)}(),function(){if(!y||!y.data||!e.header&&!e.dynamicTyping&&!e.transform)return y;function t(t,r){var i,n=e.header?{}:[];for(i=0;i<t.length;i++){var s=i,a=t[i];e.header&&(s=i>=m.length?"__parsed_extra":m[i]),e.transform&&(a=e.transform(a,s)),a=A(s,a),"__parsed_extra"===s?(n[s]=n[s]||[],n[s].push(a)):n[s]=a}return e.header&&(i>m.length?C("FieldMismatch","TooManyFields","Too many fields: expected "+m.length+" fields but parsed "+i,f+r):i<m.length&&C("FieldMismatch","TooFewFields","Too few fields: expected "+m.length+" fields but parsed "+i,f+r)),n}var r=1;!y.data[0]||Array.isArray(y.data[0])?(y.data=y.data.map(t),r=y.data.length):y.data=t(y.data,0);e.header&&y.meta&&(y.meta.fields=m);return f+=r,y}()}function _(){return e.header&&0===m.length}function A(t,r){return function(t){return e.dynamicTypingFunction&&void 0===e.dynamicTyping[t]&&(e.dynamicTyping[t]=e.dynamicTypingFunction(t)),!0===(e.dynamicTyping[t]||e.dynamicTyping)}(t)?"true"===r||"TRUE"===r||"false"!==r&&"FALSE"!==r&&(s.test(r)?parseFloat(r):a.test(r)?new Date(r):""===r?null:r):r}function C(e,t,r,i){y.errors.push({type:e,code:t,message:r,row:i})}this.parse=function(s,a,c){var d=e.quoteChar||'"';if(e.newline||(e.newline=function(e,t){e=e.substr(0,1048576);var r=new RegExp(o(t)+"([^]*?)"+o(t),"gm"),i=(e=e.replace(r,"")).split("\r"),n=e.split("\n"),s=n.length>1&&n[0].length<i[0].length;if(1===i.length||s)return"\n";for(var a=0,h=0;h<i.length;h++)"\n"===i[h][0]&&a++;return a>=i.length/2?"\r\n":"\r"}(s,d)),n=!1,e.delimiter)u(e.delimiter)&&(e.delimiter=e.delimiter(s),y.meta.delimiter=e.delimiter);else{var f=function(t,r,n,s,a){var o,l,u;a=a||[",","\t","|",";",i.RECORD_SEP,i.UNIT_SEP];for(var c=0;c<a.length;c++){var d=a[c],f=0,p=0,g=0;u=void 0;for(var m=new h({comments:s,delimiter:d,newline:r,preview:10}).parse(t),y=0;y<m.data.length;y++)if(n&&b(m.data[y]))g++;else{var w=m.data[y].length;p+=w,void 0!==u?w>1&&(f+=Math.abs(w-u),u=w):u=0}m.data.length>0&&(p/=m.data.length-g),(void 0===l||f>l)&&p>1.99&&(l=f,o=d)}return e.delimiter=o,{successful:!!o,bestDelimiter:o}}(s,e.newline,e.skipEmptyLines,e.comments,e.delimitersToGuess);f.successful?e.delimiter=f.bestDelimiter:(n=!0,e.delimiter=i.DefaultDelimiter),y.meta.delimiter=e.delimiter}var g=l(e);return e.preview&&e.header&&g.preview++,t=s,r=new h(g),y=r.parse(t,a,c),v(),p?{meta:{paused:!0}}:y||{meta:{paused:!1}}},this.paused=function(){return p},this.pause=function(){p=!0,r.abort(),t=t.substr(r.getCharIndex())},this.resume=function(){p=!1,c.streamer.parseChunk(t,!0)},this.aborted=function(){return g},this.abort=function(){g=!0,r.abort(),y.meta.aborted=!0,u(e.complete)&&e.complete(y),t=""}}function o(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function h(e){var t,r=(e=e||{}).delimiter,n=e.newline,s=e.comments,a=e.step,h=e.preview,l=e.fastMode,c=t=void 0===e.quoteChar?'"':e.quoteChar;if(void 0!==e.escapeChar&&(c=e.escapeChar),("string"!=typeof r||i.BAD_DELIMITERS.indexOf(r)>-1)&&(r=","),s===r)throw new Error("Comment character same as delimiter");!0===s?s="#":("string"!=typeof s||i.BAD_DELIMITERS.indexOf(s)>-1)&&(s=!1),"\n"!==n&&"\r"!==n&&"\r\n"!==n&&(n="\n");var d=0,f=!1;this.parse=function(e,i,p){if("string"!=typeof e)throw new Error("Input must be a string");var g=e.length,m=r.length,y=n.length,w=s.length,b=u(a);d=0;var v=[],_=[],A=[],C=0;if(!e)return P();if(l||!1!==l&&-1===e.indexOf(t)){for(var x=e.split(n),R=0;R<x.length;R++){if(A=x[R],d+=A.length,R!==x.length-1)d+=n.length;else if(p)return P();if(!s||A.substr(0,w)!==s){if(b){if(v=[],B(A.split(r)),I(),f)return P()}else B(A.split(r));if(h&&R>=h)return v=v.slice(0,h),P(!0)}}return P()}for(var E,k=e.indexOf(r,d),O=e.indexOf(n,d),S=new RegExp(o(c)+o(t),"g");;)if(e[d]!==t)if(s&&0===A.length&&e.substr(d,w)===s){if(-1===O)return P();d=O+y,O=e.indexOf(n,d),k=e.indexOf(r,d)}else if(-1!==k&&(k<O||-1===O))A.push(e.substring(d,k)),d=k+m,k=e.indexOf(r,d);else{if(-1===O)break;if(A.push(e.substring(d,O)),F(O+y),b&&(I(),f))return P();if(h&&v.length>=h)return P(!0)}else{for(E=d,d++;;){if(-1===(E=e.indexOf(t,E+1)))return p||_.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:v.length,index:d}),M();if(E===g-1)return M(e.substring(d,E).replace(S,t));if(t!==c||e[E+1]!==c){if(t===c||0===E||e[E-1]!==c){var j=D(-1===O?k:Math.min(k,O));if(e[E+1+j]===r){if(A.push(e.substring(d,E).replace(S,t)),d=E+1+j+m,k=e.indexOf(r,d),O=e.indexOf(n,d),b&&(I(),f))return P();if(h&&v.length>=h)return P(!0);break}var T=D(O);if(e.substr(E+1+T,y)===n){if(A.push(e.substring(d,E).replace(S,t)),F(E+1+T+y),k=e.indexOf(r,d),b&&(I(),f))return P();if(h&&v.length>=h)return P(!0);break}_.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:v.length,index:d}),E++}}else E++}if(b&&(I(),f))return P();if(h&&v.length>=h)return P(!0)}return M();function B(e){v.push(e),C=d}function D(t){var r=0;if(-1!==t){var i=e.substring(E+1,t);i&&""===i.trim()&&(r=i.length)}return r}function M(t){return p||(void 0===t&&(t=e.substr(d)),A.push(t),d=g,B(A),b&&I()),P()}function F(t){d=t,B(A),A=[],O=e.indexOf(n,d)}function P(e,t){return{data:t||!1?v[0]:v,errors:_,meta:{delimiter:r,linebreak:n,aborted:f,truncated:!!e,cursor:C+(i||0)}}}function I(){a(P(void 0,!0)),v=[],_=[]}},this.abort=function(){f=!0},this.getCharIndex=function(){return d}}function l(e){if("object"!=typeof e||null===e)return e;var t=Array.isArray(e)?[]:{};for(var r in e)t[r]=l(e[r]);return t}function u(e){return"function"==typeof e}e.exports=i,i.parse=function(e,t,r){var n=(t=t||{}).dynamicTyping||!1;u(n)&&(t.dynamicTypingFunction=n,n={});if(t.dynamicTyping=n,t.transform=!!u(t.transform)&&t.transform,t.worker&&i.WORKERS_SUPPORTED){var a=newWorker();return a.userStep=t.step,a.userChunk=t.chunk,a.userComplete=t.complete,a.userError=t.error,t.step=u(t.step),t.chunk=u(t.chunk),t.complete=u(t.complete),t.error=u(t.error),delete t.worker,void a.postMessage({input:e,config:t,workerId:a.id})}var o=null;"string"==typeof e&&(o=new s(t));o||(o=new r(t));return o.stream(e)},i.unparse=function(e,t){var r=!1,n=!0,s=",",a="\r\n",h='"',l=h+h,u=!1,c=null;!function(){if("object"!=typeof t)return;"string"!=typeof t.delimiter||i.BAD_DELIMITERS.filter((function(e){return-1!==t.delimiter.indexOf(e)})).length||(s=t.delimiter);("boolean"==typeof t.quotes||Array.isArray(t.quotes))&&(r=t.quotes);"boolean"!=typeof t.skipEmptyLines&&"string"!=typeof t.skipEmptyLines||(u=t.skipEmptyLines);"string"==typeof t.newline&&(a=t.newline);"string"==typeof t.quoteChar&&(h=t.quoteChar);"boolean"==typeof t.header&&(n=t.header);if(Array.isArray(t.columns)){if(0===t.columns.length)throw new Error("Option columns is empty");c=t.columns}void 0!==t.escapeChar&&(l=t.escapeChar+h)}();var d=new RegExp(o(h),"g");"string"==typeof e&&(e=JSON.parse(e));if(Array.isArray(e)){if(!e.length||Array.isArray(e[0]))return p(null,e,u);if("object"==typeof e[0])return p(c||f(e[0]),e,u)}else if("object"==typeof e)return"string"==typeof e.data&&(e.data=JSON.parse(e.data)),Array.isArray(e.data)&&(e.fields||(e.fields=e.meta&&e.meta.fields),e.fields||(e.fields=Array.isArray(e.data[0])?e.fields:f(e.data[0])),Array.isArray(e.data[0])||"object"==typeof e.data[0]||(e.data=[e.data])),p(e.fields||[],e.data||[],u);throw new Error("Unable to serialize unrecognized input");function f(e){if("object"!=typeof e)return[];var t=[];for(var r in e)t.push(r);return t}function p(e,t,r){var i="";"string"==typeof e&&(e=JSON.parse(e)),"string"==typeof t&&(t=JSON.parse(t));var o=Array.isArray(e)&&e.length>0,h=!Array.isArray(t[0]);if(o&&n){for(var l=0;l<e.length;l++)l>0&&(i+=s),i+=g(e[l],l);t.length>0&&(i+=a)}for(var u=0;u<t.length;u++){var c=o?e.length:t[u].length,d=!1,f=o?0===Object.keys(t[u]).length:0===t[u].length;if(r&&!o&&(d="greedy"===r?""===t[u].join("").trim():1===t[u].length&&0===t[u][0].length),"greedy"===r&&o){for(var p=[],m=0;m<c;m++){var y=h?e[m]:m;p.push(t[u][y])}d=""===p.join("").trim()}if(!d){for(var w=0;w<c;w++){w>0&&!f&&(i+=s);var b=o&&h?e[w]:w;i+=g(t[u][b],w)}u<t.length-1&&(!r||c>0&&!f)&&(i+=a)}}return i}function g(e,t){return null==e?"":e.constructor===Date?JSON.stringify(e).slice(1,25):(e=e.toString().replace(d,l),"boolean"==typeof r&&r||Array.isArray(r)&&r[t]||function(e,t){for(var r=0;r<t.length;r++)if(e.indexOf(t[r])>-1)return!0;return!1}(e,i.BAD_DELIMITERS)||e.indexOf(s)>-1||" "===e.charAt(0)||" "===e.charAt(e.length-1)?h+e+h:e)}},i.RECORD_SEP=String.fromCharCode(30),i.UNIT_SEP=String.fromCharCode(31),i.BYTE_ORDER_MARK="\ufeff",i.BAD_DELIMITERS=["\r","\n",'"',i.BYTE_ORDER_MARK],i.WORKERS_SUPPORTED=!1,i.NODE_STREAM_INPUT=1,i.LocalChunkSize=10485760,i.RemoteChunkSize=5242880,i.DefaultDelimiter=",",i.Parser=h,i.ParserHandle=a,i.ChunkStreamer=n,i.StringStreamer=s,s.prototype=Object.create(s.prototype),s.prototype.constructor=s},function(e,t,r){(function(t){const i=r(3),n="undefined"==typeof window?t:window;n.loaders=n.loaders||{},e.exports=Object.assign(n.loaders,i)}).call(this,r(2))},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";function i(e,t){if(!e)throw new Error("null row");if(!t)throw new Error("no headers");const r={};for(let i=0;i<t.length;i++)r[t[i]]=e[i];return r}function n(e,t){if(!e)throw new Error("null row");if(!t)throw new Error("no headers");const r=new Array(t.length);for(let i=0;i<t.length;i++)r[i]=e[t[i]];return r}let s;function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.r(t),r.d(t,"CSVLoader",(function(){return C}));class o extends Array{enqueue(e){return this.push(e)}dequeue(){return this.shift()}}s=Symbol.asyncIterator;class h{constructor(){a(this,"_values",void 0),a(this,"_settlers",void 0),a(this,"_closed",void 0),this._values=new o,this._settlers=new o,this._closed=!1}close(){for(;this._settlers.length>0;)this._settlers.dequeue().resolve({done:!0});this._closed=!0}[s](){return this}enqueue(e){if(this._closed)throw new Error("Closed");if(this._settlers.length>0){if(this._values.length>0)throw new Error("Illegal internal state");const t=this._settlers.dequeue();e instanceof Error?t.reject(e):t.resolve({value:e})}else this._values.enqueue(e)}next(){if(this._values.length>0){const e=this._values.dequeue();return e instanceof Error?Promise.reject(e):Promise.resolve({value:e})}if(this._closed){if(this._settlers.length>0)throw new Error("Illegal internal state");return Promise.resolve({done:!0})}return new Promise((e,t)=>{this._settlers.enqueue({resolve:e,reject:t})})}}function l(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class u{constructor(e,t){if(l(this,"schema",void 0),l(this,"options",void 0),l(this,"length",0),l(this,"rows",null),l(this,"cursor",0),l(this,"_headers",[]),this.options=t,this.schema=e,!Array.isArray(e)){this._headers=[];for(const t in e)this._headers[e[t].index]=e[t].name}}rowCount(){return this.length}addArrayRow(e,t){Number.isFinite(t)&&(this.cursor=t),this.rows=this.rows||new Array(100),this.rows[this.length]=e,this.length++}addObjectRow(e,t){Number.isFinite(t)&&(this.cursor=t),this.rows=this.rows||new Array(100),this.rows[this.length]=e,this.length++}getBatch(){let e=this.rows;if(!e)return null;e=e.slice(0,this.length),this.rows=null;return{shape:this.options.shape,batchType:"data",data:e,length:this.length,schema:this.schema,cursor:this.cursor}}}function c(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class d{constructor(e,t){if(c(this,"schema",void 0),c(this,"options",void 0),c(this,"length",0),c(this,"objectRows",null),c(this,"arrayRows",null),c(this,"cursor",0),c(this,"_headers",[]),this.options=t,this.schema=e,!Array.isArray(e)){this._headers=[];for(const t in e)this._headers[e[t].index]=e[t].name}}rowCount(){return this.length}addArrayRow(e,t){switch(Number.isFinite(t)&&(this.cursor=t),this.options.shape){case"object-row-table":const r=i(e,this._headers);this.addObjectRow(r,t);break;case"array-row-table":this.arrayRows=this.arrayRows||new Array(100),this.arrayRows[this.length]=e,this.length++}}addObjectRow(e,t){switch(Number.isFinite(t)&&(this.cursor=t),this.options.shape){case"array-row-table":const r=n(e,this._headers);this.addArrayRow(r,t);break;case"object-row-table":this.objectRows=this.objectRows||new Array(100),this.objectRows[this.length]=e,this.length++}}getBatch(){let e=this.arrayRows||this.objectRows;return e?(e=e.slice(0,this.length),this.arrayRows=null,this.objectRows=null,{shape:this.options.shape,batchType:"data",data:e,length:this.length,schema:this.schema,cursor:this.cursor}):null}}function f(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class p{constructor(e,t){f(this,"schema",void 0),f(this,"length",0),f(this,"allocated",0),f(this,"columns",{}),this.schema=e,this._reallocateColumns()}rowCount(){return this.length}addArrayRow(e){this._reallocateColumns();let t=0;for(const r in this.columns)this.columns[r][this.length]=e[t++];this.length++}addObjectRow(e){this._reallocateColumns();for(const t in e)this.columns[t][this.length]=e[t];this.length++}getBatch(){this._pruneColumns();const e=Array.isArray(this.schema)?this.columns:{};if(!Array.isArray(this.schema))for(const t in this.schema){const r=this.schema[t];e[r.name]=this.columns[r.index]}this.columns={};return{shape:"columnar-table",batchType:"data",data:e,schema:this.schema,length:this.length}}_reallocateColumns(){if(!(this.length<this.allocated)){this.allocated=this.allocated>0?this.allocated*=2:100,this.columns={};for(const e in this.schema){const t=this.schema[e],r=t.type||Float32Array,i=this.columns[t.index];if(i&&ArrayBuffer.isView(i)){const e=new r(this.allocated);e.set(i),this.columns[t.index]=e}else i?(i.length=this.allocated,this.columns[t.index]=i):this.columns[t.index]=new r(this.allocated)}}}_pruneColumns(){for(const[e,t]of Object.entries(this.columns))this.columns[e]=t.slice(0,this.length)}}function g(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const m={shape:"array-row-table",batchSize:"auto",batchDebounceMs:0,limit:0,_limitMB:0};class y{constructor(e,t){g(this,"schema",void 0),g(this,"options",void 0),g(this,"aggregator",null),g(this,"batchCount",0),g(this,"bytesUsed",0),g(this,"isChunkComplete",!1),g(this,"lastBatchEmittedMs",Date.now()),g(this,"totalLength",0),g(this,"totalBytes",0),g(this,"rowBytes",0),this.schema=e,this.options={...m,...t}}limitReached(){var e,t;return!!(Boolean(null===(e=this.options)||void 0===e?void 0:e.limit)&&this.totalLength>=this.options.limit)||!!(Boolean(null===(t=this.options)||void 0===t?void 0:t._limitMB)&&this.totalBytes/1e6>=this.options._limitMB)}addRow(e){this.limitReached()||(this.totalLength++,this.rowBytes=this.rowBytes||this._estimateRowMB(e),this.totalBytes+=this.rowBytes,Array.isArray(e)?this.addArrayRow(e):this.addObjectRow(e))}addArrayRow(e){if(!this.aggregator){const e=this._getTableBatchType();this.aggregator=new e(this.schema,this.options)}this.aggregator.addArrayRow(e)}addObjectRow(e){if(!this.aggregator){const e=this._getTableBatchType();this.aggregator=new e(this.schema,this.options)}this.aggregator.addObjectRow(e)}chunkComplete(e){e instanceof ArrayBuffer&&(this.bytesUsed+=e.byteLength),"string"==typeof e&&(this.bytesUsed+=e.length),this.isChunkComplete=!0}getFullBatch(e){return this._isFull()?this._getBatch(e):null}getFinalBatch(e){return this._getBatch(e)}_estimateRowMB(e){return Array.isArray(e)?8*e.length:8*Object.keys(e).length}_isFull(){if(!this.aggregator||0===this.aggregator.rowCount())return!1;if("auto"===this.options.batchSize){if(!this.isChunkComplete)return!1}else if(this.options.batchSize>this.aggregator.rowCount())return!1;return!(this.options.batchDebounceMs>Date.now()-this.lastBatchEmittedMs)&&(this.isChunkComplete=!1,this.lastBatchEmittedMs=Date.now(),!0)}_getBatch(e){if(!this.aggregator)return null;null!=e&&e.bytesUsed&&(this.bytesUsed=e.bytesUsed);const t=this.aggregator.getBatch();return t.count=this.batchCount,t.bytesUsed=this.bytesUsed,Object.assign(t,e),this.batchCount++,this.aggregator=null,t}_getTableBatchType(){switch(this.options.shape){case"row-table":return u;case"array-row-table":case"object-row-table":return d;case"columnar-table":return p;case"arrow-table":if(!y.ArrowBatch)throw new Error("TableBatchBuilder");return y.ArrowBatch;default:throw new Error("TableBatchBuilder")}}}g(y,"ArrowBatch",void 0);var w=r(0),b=r.n(w);const{ChunkStreamer:v}=b.a;function _(e){e=e||{},v.call(this,e),this.textDecoder=new TextDecoder(this._config.encoding),this.stream=async function(e){this._input=e;try{for await(const t of e)this.parseChunk(this.getStringChunk(t));this._finished=!0,this.parseChunk("")}catch(e){this._sendError(e)}},this._nextChunk=function(){},this.getStringChunk=function(e){return"string"==typeof e?e:this.textDecoder.decode(e,{stream:!0})}}_.prototype=Object.create(v.prototype),_.prototype.constructor=_;const A={csv:{shape:"object-row-table",optimizeMemoryUsage:!1,header:"auto",columnPrefix:"column",quoteChar:'"',escapeChar:'"',dynamicTyping:!0,comments:!1,skipEmptyLines:!0,delimitersToGuess:[",","\t","|",";"]}},C={id:"csv",module:"csv",name:"CSV",version:"3.0.13",extensions:["csv"],mimeTypes:["text/csv"],category:"table",parse:async(e,t)=>x((new TextDecoder).decode(e),t),parseText:(e,t)=>x(e,t),parseInBatches:function(e,t){var r;"auto"===(t={...t}).batchSize&&(t.batchSize=4e3);const i={...A.csv,...null===(r=t)||void 0===r?void 0:r.csv},n=new h;let s=!0,a=null,o=null,l=null;const u={...i,header:!1,download:!1,chunkSize:5242880,skipEmptyLines:!1,step(e){let r=e.data;if(i.skipEmptyLines){if(""===r.flat().join("").trim())return}const h=e.meta.cursor;if(s&&!a){if("auto"===i.header?R(r):Boolean(i.header))return void(a=r.map(E()))}s&&(s=!1,a||(a=k(i.columnPrefix,r.length)),l=function(e,t){const r=t?{}:[];for(let i=0;i<e.length;i++){const n=t&&t[i]||i;switch(typeof e[i]){case"number":case"boolean":r[n]={name:String(n),index:i,type:Float32Array};break;case"string":default:r[n]={name:String(n),index:i,type:Array}}}return r}(r,a)),i.optimizeMemoryUsage&&(r=JSON.parse(JSON.stringify(r))),o=o||new y(l,{shape:i.shape||"array-row-table",...t});try{o.addRow(r);const e=o&&o.getFullBatch({bytesUsed:h});e&&n.enqueue(e)}catch(e){n.enqueue(e)}},complete(e){try{const t=e.meta.cursor,r=o&&o.getFinalBatch({bytesUsed:t});r&&n.enqueue(r)}catch(e){n.enqueue(e)}n.close()}};return b.a.parse(e,u,_),n},options:A};async function x(e,t){const r={...A.csv,...null==t?void 0:t.csv},s=function(e){return b.a.parse(e,{download:!1,dynamicTyping:!0,preview:1}).data[0]}(e),a="auto"===r.header?R(s):Boolean(r.header),o={...r,header:a,download:!1,transformHeader:a?E():void 0,error:e=>{throw new Error(e)}},h=b.a.parse(e,o);let{data:l}=h;const u=h.meta.fields||k(r.columnPrefix,s.length);switch(r.shape){case"object-row-table":l=l.map(e=>Array.isArray(e)?i(e,u):e);break;case"array-row-table":l=l.map(e=>Array.isArray(e)?e:n(e,u))}return l}function R(e){return e&&e.every(e=>"string"==typeof e)}function E(){const e=new Set;return t=>{let r=t,i=1;for(;e.has(r);)r=`${t}.${i}`,i++;return e.add(r),r}}function k(e,t=0){const r=[];for(let i=0;i<t;i++)r.push(`${e}${i+1}`);return r}}])}));
9
9
  //# sourceMappingURL=dist.min.js.map