(function webpackUniversalModuleDefinition(root, factory) { if (typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if (typeof define === 'function' && define.amd) define([], factory); else if (typeof exports === 'object') exports['loaders'] = factory(); else root['loaders'] = factory();})(globalThis, function () { "use strict";var __exports__=(()=>{var Qt=Object.create;var F=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,se=Object.prototype.hasOwnProperty;var ae=(t,e,r)=>e in t?F(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var oe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ne=(t,e)=>{for(var r in e)F(t,r,{get:e[r],enumerable:!0})},U=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of ee(e))!se.call(t,a)&&a!==r&&F(t,a,{get:()=>e[a],enumerable:!(s=te(e,a))||s.enumerable});return t},k=(t,e,r)=>(U(t,e,"default"),r&&U(r,e,"default")),ie=(t,e,r)=>(r=t!=null?Qt(re(t)):{},U(e||!t||!t.__esModule?F(r,"default",{value:t,enumerable:!0}):r,t)),ce=t=>U(F({},"__esModule",{value:!0}),t);var Bt=(t,e,r)=>(ae(t,typeof e!="symbol"?e+"":e,r),r);var _t=oe((je,Dt)=>{Dt.exports=globalThis.loaders});var D={};ne(D,{ArrowLikeDataType:()=>m,ArrowLikeField:()=>p,ArrowLikeSchema:()=>d,ArrowLikeTable:()=>H,AsyncQueue:()=>B,Binary:()=>nt,Bool:()=>V,ColumnarTableBatchAggregator:()=>S,Date:()=>I,DateDay:()=>ct,DateMillisecond:()=>lt,FixedSizeList:()=>bt,Float:()=>x,Float16:()=>st,Float32:()=>at,Float64:()=>ot,Int:()=>f,Int16:()=>X,Int32:()=>Z,Int64:()=>K,Int8:()=>G,Interval:()=>O,IntervalDayTime:()=>gt,IntervalYearMonth:()=>wt,Null:()=>J,RowTableBatchAggregator:()=>A,Struct:()=>yt,TableBatchBuilder:()=>R,Time:()=>T,TimeMillisecond:()=>ht,TimeSecond:()=>ut,Timestamp:()=>b,TimestampMicrosecond:()=>ft,TimestampMillisecond:()=>dt,TimestampNanosecond:()=>pt,TimestampSecond:()=>mt,Uint16:()=>tt,Uint32:()=>et,Uint64:()=>rt,Uint8:()=>Q,Utf8:()=>it,convertTable:()=>Vt,convertToArrayRow:()=>Y,convertToObjectRow:()=>W,deduceMeshField:()=>Ft,deduceMeshSchema:()=>Zt,deduceTableSchema:()=>w,getArrayTypeFromDataType:()=>z,getDataTypeFromArray:()=>L,getMeshBoundingBox:()=>Xt,getMeshSize:()=>Gt,getTableCell:()=>j,getTableCellAt:()=>Lt,getTableColumnIndex:()=>jt,getTableColumnName:()=>N,getTableLength:()=>h,getTableNumCols:()=>q,getTableRowAsArray:()=>C,getTableRowAsObject:()=>E,getTableRowShape:()=>zt,getTypeInfo:()=>Kt,isTable:()=>vt,makeArrayRowIterator:()=>It,makeBatchFromTable:()=>qt,makeMeshAttributeMetadata:()=>Rt,makeObjectRowIterator:()=>Tt,makeRowIterator:()=>$t,makeTableFromBatches:()=>Ht,makeTableFromData:()=>Pt});k(D,ie(_t(),1));function v(t,e="float32"){return t instanceof Date?"date-millisecond":t instanceof Number?e:typeof t=="string"?"utf8":(t===null||t==="undefined","null")}function L(t){let e=St(t);return e!=="null"?{type:e,nullable:!1}:t.length>0?(e=v(t[0]),{type:e,nullable:!0}):{type:"null",nullable:!0}}function St(t){switch(t.constructor){case Int8Array:return"int8";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int16Array:return"int16";case Uint16Array:return"uint16";case Int32Array:return"int32";case Uint32Array:return"uint32";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}function z(t,e){if(!e)switch(t){case"int8":return Int8Array;case"uint8":return Uint8Array;case"int16":return Int16Array;case"uint16":return Uint16Array;case"int32":return Int32Array;case"uint32":return Uint32Array;case"float32":return Float32Array;case"float64":return Float64Array;default:break}return Array}var $=class{schema;options;shape;length=0;rows=null;cursor=0;_headers=[];constructor(e,r){if(this.options=r,this.schema=e,!Array.isArray(e)){this._headers=[];for(let s in e)this._headers[e[s].index]=e[s].name}}rowCount(){return this.length}addArrayRow(e,r){Number.isFinite(r)&&(this.cursor=r),this.shape="array-row-table",this.rows=this.rows||new Array(100),this.rows[this.length]=e,this.length++}addObjectRow(e,r){Number.isFinite(r)&&(this.cursor=r),this.shape="object-row-table",this.rows=this.rows||new Array(100),this.rows[this.length]=e,this.length++}getBatch(){let e=this.rows;return e?(e=e.slice(0,this.length),this.rows=null,{shape:this.shape||"array-row-table",batchType:"data",data:e,length:this.length,schema:this.schema,cursor:this.cursor}):null}};function W(t,e){if(!t)throw new Error("null row");let r={};if(e)for(let s=0;s0?this.allocated*=2:100,this.columns={};for(let e in this.schema){let r=this.schema[e],s=r.type||Float32Array,a=this.columns[r.index];if(a&&ArrayBuffer.isView(a)){let u=new s(this.allocated);u.set(a),this.columns[r.index]=u}else a?(a.length=this.allocated,this.columns[r.index]=a):this.columns[r.index]=new s(this.allocated)}}}_pruneColumns(){for(let[e,r]of Object.entries(this.columns))this.columns[e]=r.slice(0,this.length)}};var le={shape:void 0,batchSize:"auto",batchDebounceMs:0,limit:0,_limitMB:0},ue="TableBatchBuilder",P=class{schema;options;aggregator=null;batchCount=0;bytesUsed=0;isChunkComplete=!1;lastBatchEmittedMs=Date.now();totalLength=0;totalBytes=0;rowBytes=0;constructor(e,r){this.schema=e,this.options={...le,...r}}limitReached(){return!!(Boolean(this.options?.limit)&&this.totalLength>=this.options.limit||Boolean(this.options?._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){let r=this._getTableBatchType();this.aggregator=new r(this.schema,this.options)}this.aggregator.addArrayRow(e)}addObjectRow(e){if(!this.aggregator){let r=this._getTableBatchType();this.aggregator=new r(this.schema,this.options)}this.aggregator.addObjectRow(e)}chunkComplete(e){e instanceof ArrayBuffer&&(this.bytesUsed+=e.byteLength),typeof e=="string"&&(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)?e.length*8:Object.keys(e).length*8}_isFull(){if(!this.aggregator||this.aggregator.rowCount()===0)return!1;if(this.options.batchSize==="auto"){if(!this.isChunkComplete)return!1}else if(this.options.batchSize>this.aggregator.rowCount())return!1;return this.options.batchDebounceMs>Date.now()-this.lastBatchEmittedMs?!1:(this.isChunkComplete=!1,this.lastBatchEmittedMs=Date.now(),!0)}_getBatch(e){if(!this.aggregator)return null;e?.bytesUsed&&(this.bytesUsed=e.bytesUsed);let r=this.aggregator.getBatch();return r.count=this.batchCount,r.bytesUsed=this.bytesUsed,Object.assign(r,e),this.batchCount++,this.aggregator=null,r}_getTableBatchType(){switch(this.options.shape){case"array-row-table":case"object-row-table":return A;case"columnar-table":return S;case"arrow-table":if(!P.ArrowBatch)throw new Error(ue);return P.ArrowBatch;default:return $}}},R=P;Bt(R,"ArrowBatch");function vt(t){switch(typeof t=="object"&&t?.shape){case"array-row-table":case"object-row-table":return Array.isArray(t.data);case"geojson-table":return Array.isArray(t.features);case"columnar-table":return t.data&&typeof t.data=="object";case"arrow-table":return Boolean(t?.data?.numRows!==void 0);default:return!1}}function h(t){switch(t.shape){case"array-row-table":case"object-row-table":return t.data.length;case"geojson-table":return t.features.length;case"arrow-table":return t.data.numRows;case"columnar-table":for(let r of Object.values(t.data))return r.length||0;return 0;default:throw new Error("table")}}function q(t){if(t.schema)return t.schema.fields.length;if(h(t)===0)throw new Error("empty table");switch(t.shape){case"array-row-table":return t.data[0].length;case"object-row-table":return Object.keys(t.data[0]).length;case"geojson-table":return Object.keys(t.features[0]).length;case"columnar-table":return Object.keys(t.data).length;case"arrow-table":return t.data.numCols;default:throw new Error("table")}}function j(t,e,r){switch(t.shape){case"array-row-table":let s=jt(t,r);return t.data[e][s];case"object-row-table":return t.data[e][r];case"geojson-table":return t.features[e][r];case"columnar-table":return t.data[r][e];case"arrow-table":let u=t.data,c=u.schema.fields.findIndex(l=>l.name===r);return u.getChildAt(c)?.get(e);default:throw new Error("todo")}}function Lt(t,e,r){switch(t.shape){case"array-row-table":return t.data[e][r];case"object-row-table":let s=N(t,r);return t.data[e][s];case"geojson-table":let a=N(t,r);return t.features[e][a];case"columnar-table":let u=N(t,r);return t.data[u][e];case"arrow-table":return t.data.getChildAt(r)?.get(e);default:throw new Error("todo")}}function zt(t){switch(t.shape){case"array-row-table":case"object-row-table":return t.shape;case"geojson-table":return"object-row-table";case"columnar-table":default:throw new Error("Not a row table")}}function jt(t,e){let r=t.schema?.fields.findIndex(s=>s.name===e);if(r===void 0)throw new Error(e);return r}function N(t,e){let r=t.schema?.fields[e]?.name;if(!r)throw new Error(`${e}`);return r}function E(t,e,r,s){switch(t.shape){case"object-row-table":return s?Object.fromEntries(Object.entries(t.data[e])):t.data[e];case"array-row-table":if(t.schema){let o=r||{};for(let n=0;nnew p(s.name,s.type,s.nullable,s.metadata)),this.metadata=r instanceof Map?r:new Map(Object.entries(r))}compareTo(e){if(this.metadata!==e.metadata||this.fields.length!==e.fields.length)return!1;for(let r=0;rr[a.name]);return new d(s,this.metadata)}selectAt(...e){let r=e.map(s=>this.fields[s]).filter(Boolean);return new d(r,this.metadata)}assign(e){let r,s=this.metadata;if(e instanceof d){let c=e;r=c.fields,s=Wt(Wt(new Map,this.metadata),c.metadata)}else r=e;let a=Object.create(null);for(let c of this.fields)a[c.name]=c;for(let c of r)a[c.name]=c;let u=Object.values(a);return new d(u,s)}};function Wt(t,e){return new Map([...t||new Map,...e||new Map])}function w(t){switch(t.shape){case"array-row-table":case"object-row-table":return me(t.data);case"geojson-table":return de(t.features);case"columnar-table":return he(t.data);case"arrow-table":default:throw new Error("Deduce schema")}}function he(t){let e=[];for(let[r,s]of Object.entries(t)){let a=fe(s,r);e.push(a)}return{fields:e,metadata:{}}}function me(t){if(!t.length)throw new Error("deduce from empty table");let e=[],r=t[0];for(let[s,a]of Object.entries(r))e.push(Yt(a,s));return{fields:e,metadata:{}}}function de(t){if(!t.length)throw new Error("deduce from empty table");let e=[],r=t[0].properties||{};for(let[s,a]of Object.entries(r))e.push(Yt(a,s));return{fields:e,metadata:{}}}function fe(t,e){if(ArrayBuffer.isView(t)){let r=L(t);return{name:e,type:r.type||"null",nullable:r.nullable}}if(Array.isArray(t)&&t.length>0){let r=t[0],s=v(r);return{name:e,type:s,nullable:!0}}throw new Error("empty table")}function Yt(t,e){let r=v(t);return{name:e,type:r,nullable:!0}}var Ot=class{table;columnName;constructor(e,r){this.table=e,this.columnName=r}get(e){return j(this.table,e,this.columnName)}toArray(){switch(this.table.shape){case"arrow-table":return this.table.data.getChild(this.columnName)?.toArray();case"columnar-table":return this.table.data[this.columnName];default:throw new Error(this.table.shape)}}},H=class{schema;table;constructor(e){let r=e.schema||w(e);this.schema=new d(r.fields,r.metadata),this.table={...e,schema:r}}get data(){return this.table.shape==="geojson-table"?this.table.features:this.table.data}get numCols(){return q(this.table)}get length(){return h(this.table)}getChild(e){return new Ot(this.table,e)}};function Pt(t){let e;switch(pe(t)){case"array-row-table":e={shape:"array-row-table",data:t};break;case"object-row-table":e={shape:"object-row-table",data:t};break;case"columnar-table":e={shape:"columnar-table",data:t};break;default:throw new Error("table")}let r=w(e);return{...e,schema:r}}function pe(t){if(Array.isArray(t)){if(t.length===0)throw new Error("cannot deduce type of empty table");let e=t[0];if(Array.isArray(e))return"array-row-table";if(e&&typeof e=="object")return"object-row-table"}if(t&&typeof t=="object")return"columnar-table";throw new Error("invalid table")}function qt(t){return{...t,length:h(t),batchType:"data"}}async function Ht(t){let e,r,s,a=null,u;for await(let c of t)switch(a=a||c.shape,u=u||c.schema,c.shape){case"array-row-table":e=e||[];for(let l=0;la?g:a,u=_>u?_:u,c=M>c?M:c}return[[e,r,s],[a,u,c]]}function Zt(t,e={}){return{fields:xe(t),metadata:e}}function Ft(t,e,r){let s=St(e.value),a=r||Rt(e);return{name:t,type:{type:"fixed-size-list",listSize:e.size,children:[{name:"value",type:s}]},nullable:!1,metadata:a}}function xe(t){let e=[];for(let r in t){let s=t[r];e.push(Ft(r,s))}return e}function Rt(t){let e={};return"byteOffset"in t&&(e.byteOffset=t.byteOffset.toString(10)),"byteStride"in t&&(e.byteStride=t.byteStride.toString(10)),"normalized"in t&&(e.normalized=t.normalized.toString()),e}var i;(function(t){t[t.NONE=0]="NONE",t[t.Null=1]="Null",t[t.Int=2]="Int",t[t.Float=3]="Float",t[t.Binary=4]="Binary",t[t.Utf8=5]="Utf8",t[t.Bool=6]="Bool",t[t.Decimal=7]="Decimal",t[t.Date=8]="Date",t[t.Time=9]="Time",t[t.Timestamp=10]="Timestamp",t[t.Interval=11]="Interval",t[t.List=12]="List",t[t.Struct=13]="Struct",t[t.Union=14]="Union",t[t.FixedSizeBinary=15]="FixedSizeBinary",t[t.FixedSizeList=16]="FixedSizeList",t[t.Map=17]="Map",t[t.Dictionary=-1]="Dictionary",t[t.Int8=-2]="Int8",t[t.Int16=-3]="Int16",t[t.Int32=-4]="Int32",t[t.Int64=-5]="Int64",t[t.Uint8=-6]="Uint8",t[t.Uint16=-7]="Uint16",t[t.Uint32=-8]="Uint32",t[t.Uint64=-9]="Uint64",t[t.Float16=-10]="Float16",t[t.Float32=-11]="Float32",t[t.Float64=-12]="Float64",t[t.DateDay=-13]="DateDay",t[t.DateMillisecond=-14]="DateMillisecond",t[t.TimestampSecond=-15]="TimestampSecond",t[t.TimestampMillisecond=-16]="TimestampMillisecond",t[t.TimestampMicrosecond=-17]="TimestampMicrosecond",t[t.TimestampNanosecond=-18]="TimestampNanosecond",t[t.TimeSecond=-19]="TimeSecond",t[t.TimeMillisecond=-20]="TimeMillisecond",t[t.TimeMicrosecond=-21]="TimeMicrosecond",t[t.TimeNanosecond=-22]="TimeNanosecond",t[t.DenseUnion=-23]="DenseUnion",t[t.SparseUnion=-24]="SparseUnion",t[t.IntervalDayTime=-25]="IntervalDayTime",t[t.IntervalYearMonth=-26]="IntervalYearMonth"})(i||(i={}));var m=class{static isNull(e){return e&&e.typeId===i.Null}static isInt(e){return e&&e.typeId===i.Int}static isFloat(e){return e&&e.typeId===i.Float}static isBinary(e){return e&&e.typeId===i.Binary}static isUtf8(e){return e&&e.typeId===i.Utf8}static isBool(e){return e&&e.typeId===i.Bool}static isDecimal(e){return e&&e.typeId===i.Decimal}static isDate(e){return e&&e.typeId===i.Date}static isTime(e){return e&&e.typeId===i.Time}static isTimestamp(e){return e&&e.typeId===i.Timestamp}static isInterval(e){return e&&e.typeId===i.Interval}static isList(e){return e&&e.typeId===i.List}static isStruct(e){return e&&e.typeId===i.Struct}static isUnion(e){return e&&e.typeId===i.Union}static isFixedSizeBinary(e){return e&&e.typeId===i.FixedSizeBinary}static isFixedSizeList(e){return e&&e.typeId===i.FixedSizeList}static isMap(e){return e&&e.typeId===i.Map}static isDictionary(e){return e&&e.typeId===i.Dictionary}get typeId(){return i.NONE}compareTo(e){return this===e}},J=class extends m{get typeId(){return i.Null}get[Symbol.toStringTag](){return"Null"}toString(){return"Null"}},V=class extends m{get typeId(){return i.Bool}get[Symbol.toStringTag](){return"Bool"}toString(){return"Bool"}},f=class extends m{isSigned;bitWidth;constructor(e,r){super(),this.isSigned=e,this.bitWidth=r}get typeId(){return i.Int}get[Symbol.toStringTag](){return"Int"}toString(){return`${this.isSigned?"I":"Ui"}nt${this.bitWidth}`}},G=class extends f{constructor(){super(!0,8)}},X=class extends f{constructor(){super(!0,16)}},Z=class extends f{constructor(){super(!0,32)}},K=class extends f{constructor(){super(!0,64)}},Q=class extends f{constructor(){super(!1,8)}},tt=class extends f{constructor(){super(!1,16)}},et=class extends f{constructor(){super(!1,32)}},rt=class extends f{constructor(){super(!1,64)}},Nt={HALF:16,SINGLE:32,DOUBLE:64},x=class extends m{precision;constructor(e){super(),this.precision=e}get typeId(){return i.Float}get[Symbol.toStringTag](){return"Float"}toString(){return`Float${this.precision}`}},st=class extends x{constructor(){super(Nt.HALF)}},at=class extends x{constructor(){super(Nt.SINGLE)}},ot=class extends x{constructor(){super(Nt.DOUBLE)}},nt=class extends m{constructor(){super()}get typeId(){return i.Binary}toString(){return"Binary"}get[Symbol.toStringTag](){return"Binary"}},it=class extends m{get typeId(){return i.Utf8}get[Symbol.toStringTag](){return"Utf8"}toString(){return"Utf8"}},Et={DAY:0,MILLISECOND:1},I=class extends m{unit;constructor(e){super(),this.unit=e}get typeId(){return i.Date}get[Symbol.toStringTag](){return"Date"}toString(){return`Date${(this.unit+1)*32}<${Et[this.unit]}>`}},ct=class extends I{constructor(){super(Et.DAY)}},lt=class extends I{constructor(){super(Et.MILLISECOND)}},y={SECOND:1,MILLISECOND:1e3,MICROSECOND:1e6,NANOSECOND:1e9},T=class extends m{unit;bitWidth;constructor(e,r){super(),this.unit=e,this.bitWidth=r}get typeId(){return i.Time}toString(){return`Time${this.bitWidth}<${y[this.unit]}>`}get[Symbol.toStringTag](){return"Time"}},ut=class extends T{constructor(){super(y.SECOND,32)}},ht=class extends T{constructor(){super(y.MILLISECOND,32)}},b=class extends m{unit;timezone;constructor(e,r=null){super(),this.unit=e,this.timezone=r}get typeId(){return i.Timestamp}get[Symbol.toStringTag](){return"Timestamp"}toString(){return`Timestamp<${y[this.unit]}${this.timezone?`, ${this.timezone}`:""}>`}},mt=class extends b{constructor(e=null){super(y.SECOND,e)}},dt=class extends b{constructor(e=null){super(y.MILLISECOND,e)}},ft=class extends b{constructor(e=null){super(y.MICROSECOND,e)}},pt=class extends b{constructor(e=null){super(y.NANOSECOND,e)}},Ct={DAY_TIME:0,YEAR_MONTH:1},O=class extends m{unit;constructor(e){super(),this.unit=e}get typeId(){return i.Interval}get[Symbol.toStringTag](){return"Interval"}toString(){return`Interval<${Ct[this.unit]}>`}},gt=class extends O{constructor(){super(Ct.DAY_TIME)}},wt=class extends O{constructor(){super(Ct.YEAR_MONTH)}},bt=class extends m{listSize;children;constructor(e,r){super(),this.listSize=e,this.children=[r]}get typeId(){return i.FixedSizeList}get valueType(){return this.children[0].type}get valueField(){return this.children[0]}get[Symbol.toStringTag](){return"FixedSizeList"}toString(){return`FixedSizeList[${this.listSize}]<${JSON.stringify(this.valueType)}>`}},yt=class extends m{children;constructor(e){super(),this.children=e}get typeId(){return i.Struct}toString(){return`Struct<{${this.children.map(e=>`${e.name}:${JSON.stringify(e.type)}`).join(", ")}}>`}get[Symbol.toStringTag](){return"Struct"}};function Kt(t){return{typeId:t.typeId,ArrayType:t.ArrayType,typeName:t.toString(),typeEnumName:Ae(t.typeId),precision:t.precision}}var xt=null;function Ae(t){if(!xt){xt={};for(let e in i)xt[i[e]]=e}return xt[t]}var At=class extends Array{enqueue(e){return this.push(e)}dequeue(){return this.shift()}},B=class{_values;_settlers;_closed;constructor(){this._values=new At,this._settlers=new At,this._closed=!1}close(){for(;this._settlers.length>0;)this._settlers.dequeue().resolve({done:!0});this._closed=!0}[Symbol.asyncIterator](){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");let r=this._settlers.dequeue();e instanceof Error?r.reject(e):r.resolve({value:e})}else this._values.enqueue(e)}next(){if(this._values.length>0){let 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,r)=>{this._settlers.enqueue({resolve:e,reject:r})})}};return ce(D);})(); return __exports__; });