@loaders.gl/pointclouds 5.0.0-beta.2 → 5.0.0-beta.4
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.dev.js +6 -1
- package/dist/dist.min.js +4 -4
- package/dist/las/las-loader-shared.cjs +1 -1
- package/dist/las/las-loader-shared.js +1 -1
- package/dist/las/las-writer.cjs +1 -1
- package/dist/las/las-writer.js +1 -1
- package/dist/las/lib/las-extra-bytes.cjs +6 -1
- package/dist/las/lib/las-extra-bytes.cjs.map +2 -2
- package/dist/las/lib/las-extra-bytes.d.ts.map +1 -1
- package/dist/las/lib/las-extra-bytes.js +6 -4
- package/dist/las/lib/las-extra-bytes.js.map +1 -1
- package/dist/las-worker.js +405 -84
- package/dist/las-writer.cjs +1 -1
- package/dist/pcd/pcd-loader-types.cjs +1 -1
- package/dist/pcd/pcd-loader-types.js +1 -1
- package/dist/pcd/pcd-writer.cjs +1 -1
- package/dist/pcd/pcd-writer.js +1 -1
- package/dist/pcd-loader-types.cjs +1 -1
- package/dist/pcd-worker.js +393 -57
- package/dist/pcd-writer.cjs +1 -1
- package/dist/ply/ply-loader-types.cjs +1 -1
- package/dist/ply/ply-loader-types.js +1 -1
- package/dist/ply/ply-writer.cjs +1 -1
- package/dist/ply/ply-writer.js +1 -1
- package/dist/ply-loader-types.cjs +1 -1
- package/dist/ply-worker.js +393 -57
- package/dist/ply-writer.cjs +1 -1
- package/package.json +4 -3
- package/src/las/lib/las-extra-bytes.ts +6 -4
package/dist/dist.min.js
CHANGED
|
@@ -23,10 +23,10 @@ return true;`)}function cv(r){return typeof r!="bigint"?Tr(r):`${Tr(r)}n`}var h0
|
|
|
23
23
|
`:`,
|
|
24
24
|
`),this._write(Qv(this._recordBatches[t])),this._recordBatchBlocks.push(new Nr(0,0,0));this._write(`
|
|
25
25
|
]`)}return this._schema&&this._write(`
|
|
26
|
-
}`),this._recordBatchesWithDictionaries=[],this._recordBatches=[],super.close()}}});function ug(r,t){if(lr(r))return eA(r,t);if(Sr(r))return tA(r,t);throw new Error("toDOMStream() must be called with an Iterable or AsyncIterable")}function tA(r,t){let e=null,n=t?.type==="bytes"||!1,s=t?.highWaterMark||Math.pow(2,24);return new ReadableStream(Object.assign(Object.assign({},t),{start(o){i(o,e||(e=r[Symbol.iterator]()))},pull(o){e?i(o,e):o.close()},cancel(){e?.return&&e.return(),e=null}}),Object.assign({highWaterMark:n?s:void 0},t));function i(o,a){let c,l=null,u=o.desiredSize||null;for(;!(l=a.next(n?u:null)).done;)if(ArrayBuffer.isView(l.value)&&(c=O(l.value))&&(u!=null&&n&&(u=u-c.byteLength+1),l.value=c),o.enqueue(l.value),u!=null&&--u<=0)return;o.close()}}function eA(r,t){let e=null,n=t?.type==="bytes"||!1,s=t?.highWaterMark||Math.pow(2,24);return new ReadableStream(Object.assign(Object.assign({},t),{start(o){return I(this,void 0,void 0,function*(){yield i(o,e||(e=r[Symbol.asyncIterator]()))})},pull(o){return I(this,void 0,void 0,function*(){e?yield i(o,e):o.close()})},cancel(){return I(this,void 0,void 0,function*(){e?.return&&(yield e.return()),e=null})}}),Object.assign({highWaterMark:n?s:void 0},t));function i(o,a){return I(this,void 0,void 0,function*(){let c,l=null,u=o.desiredSize||null;for(;!(l=yield a.next(n?u:null)).done;)if(ArrayBuffer.isView(l.value)&&(c=O(l.value))&&(u!=null&&n&&(u=u-c.byteLength+1),l.value=c),o.enqueue(l.value),u!=null&&--u<=0)return;o.close()})}}var fg=p(()=>{Pe();Gt();qn()});function pg(r){return new od(r)}var od,hg,dg,mg=p(()=>{Pe();Ga();od=class{constructor(t){this._numChunks=0,this._finished=!1,this._bufferedSize=0;let{["readableStrategy"]:e,["writableStrategy"]:n,["queueingStrategy"]:s="count"}=t,i=Bm(t,["readableStrategy","writableStrategy","queueingStrategy"]);this._controller=null,this._builder=Rr(i),this._getSize=s!=="bytes"?hg:dg;let{["highWaterMark"]:o=s==="bytes"?Math.pow(2,14):1e3}=Object.assign({},e),{["highWaterMark"]:a=s==="bytes"?Math.pow(2,14):1e3}=Object.assign({},n);this.readable=new ReadableStream({cancel:()=>{this._builder.clear()},pull:c=>{this._maybeFlush(this._builder,this._controller=c)},start:c=>{this._maybeFlush(this._builder,this._controller=c)}},{highWaterMark:o,size:s!=="bytes"?hg:dg}),this.writable=new WritableStream({abort:()=>{this._builder.clear()},write:()=>{this._maybeFlush(this._builder,this._controller)},close:()=>{this._maybeFlush(this._builder.finish(),this._controller)}},{highWaterMark:a,size:c=>this._writeValueAndReturnChunkSize(c)})}_writeValueAndReturnChunkSize(t){let e=this._bufferedSize;return this._bufferedSize=this._getSize(this._builder.append(t)),this._bufferedSize-e}_maybeFlush(t,e){e!=null&&(this._bufferedSize>=e.desiredSize&&++this._numChunks&&this._enqueue(e,t.toVector()),t.finished&&((t.length>0||this._numChunks===0)&&++this._numChunks&&this._enqueue(e,t.toVector()),!this._finished&&(this._finished=!0)&&this._enqueue(e,null)))}_enqueue(t,e){this._bufferedSize=0,this._controller=null,e==null?t.close():t.enqueue(e)}},hg=r=>{var t;return(t=r?.length)!==null&&t!==void 0?t:0},dg=r=>{var t;return(t=r?.byteLength)!==null&&t!==void 0?t:0}});function Ul(r,t){let e=new pr,n=null,s=new ReadableStream({cancel(){return I(this,void 0,void 0,function*(){yield e.close()})},start(a){return I(this,void 0,void 0,function*(){yield o(a,n||(n=yield i()))})},pull(a){return I(this,void 0,void 0,function*(){n?yield o(a,n):a.close()})}});return{writable:new WritableStream(e,Object.assign({highWaterMark:Math.pow(2,14)},r)),readable:s};function i(){return I(this,void 0,void 0,function*(){return yield(yield Oe.from(e)).open(t)})}function o(a,c){return I(this,void 0,void 0,function*(){let l=a.desiredSize,u=null;for(;!(u=yield c.next()).done;)if(a.enqueue(u.value),l!=null&&--l<=0)return;a.close()})}}var yg=p(()=>{Pe();ys();Ya()});function Nl(r,t){let e=new this(r),n=new $e(e),s=new ReadableStream({cancel(){return I(this,void 0,void 0,function*(){yield n.cancel()})},pull(o){return I(this,void 0,void 0,function*(){yield i(o)})},start(o){return I(this,void 0,void 0,function*(){yield i(o)})}},Object.assign({highWaterMark:Math.pow(2,14)},t));return{writable:new WritableStream(e,r),readable:s};function i(o){return I(this,void 0,void 0,function*(){let a=null,c=o.desiredSize;for(;a=yield n.read(c||null);)if(o.enqueue(a),c!=null&&(c-=a.byteLength)<=0)return;o.close()})}}var gg=p(()=>{Pe();ys()});function Xa(r){let t=Oe.from(r);return Ke(t)?t.then(e=>Xa(e)):t.isAsync()?t.readAll().then(e=>new st(e)):new st(t.readAll())}function Rl(r,t="stream",e=null){let n={compressionType:e};return(t==="stream"?Un:Nn).writeAll(r,n).toUint8Array(!0)}var bg=p(()=>{Ri();qn();Ya();El()});var ad={};Re(ad,{isArrowData:()=>Vl,isArrowDataType:()=>zl,isArrowField:()=>kl,isArrowRecordBatch:()=>jl,isArrowSchema:()=>Pl,isArrowTable:()=>ql,isArrowVector:()=>Gl});function Pl(r){return j.isSchema(r)}function kl(r){return S.isField(r)}function zl(r){return w.isDataType(r)}function Vl(r){return T.isData(r)}function Gl(r){return A.isVector(r)}function jl(r){return ct.isRecordBatch(r)}function ql(r){return st.isTable(r)}var cd=p(()=>{pe();yt();hr();he();Dn();Ri()});var wg,ld=p(()=>{Mc();ao();Mt();hr();yt();Ri();he();je();pe();Fa();Hc();vt();Ga();wh();Fh();xh();vh();Ah();Sh();Ih();Th();Uh();Eh();_h();Lh();Rh();kh();Ph();yl();bl();gl();Mh();Dh();Bh();Ch();Oh();Nh();ys();Ya();El();bg();Tl();Ll();ms();Dn();cd();Dc();dh();li();Ca();Gt();vo();Sa();dl();cd();Wa();wg=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},Nf),hh),Jf),Rf),ef),Kf),Ff),bh),ad),{compareSchemas:Ni,compareFields:V0,compareTypes:vl})});var zr={};Re(zr,{AsyncByteQueue:()=>pr,AsyncByteStream:()=>$e,AsyncMessageReader:()=>ki,AsyncRecordBatchFileReader:()=>Fo,AsyncRecordBatchStreamReader:()=>Cn,Binary:()=>ze,BinaryBuilder:()=>Bn,BinaryView:()=>H,BinaryViewBuilder:()=>Ln,Bool:()=>le,BoolBuilder:()=>pi,BufferType:()=>Z,Builder:()=>bt,ByteStream:()=>mr,CompressionType:()=>Ht,Data:()=>T,DataType:()=>w,DateBuilder:()=>Qr,DateDay:()=>Qn,DateDayBuilder:()=>bs,DateMillisecond:()=>ts,DateMillisecondBuilder:()=>ws,DateUnit:()=>mt,Date_:()=>Te,Decimal:()=>Ve,DecimalBuilder:()=>xs,DenseUnion:()=>bn,DenseUnionBuilder:()=>Ei,Dictionary:()=>Rt,DictionaryBuilder:()=>mi,Duration:()=>Me,DurationBuilder:()=>yr,DurationMicrosecond:()=>Ta,DurationMicrosecondBuilder:()=>Ls,DurationMillisecond:()=>La,DurationMillisecondBuilder:()=>_s,DurationNanosecond:()=>Ma,DurationNanosecondBuilder:()=>Ts,DurationSecond:()=>_a,DurationSecondBuilder:()=>Is,Field:()=>S,FixedSizeBinary:()=>Ge,FixedSizeBinaryBuilder:()=>vs,FixedSizeList:()=>gt,FixedSizeListBuilder:()=>yi,Float:()=>ae,Float16:()=>Cr,Float16Builder:()=>gi,Float32:()=>Xt,Float32Builder:()=>bi,Float64:()=>_e,Float64Builder:()=>wi,FloatBuilder:()=>tn,Int:()=>Lt,Int16:()=>Se,Int16Builder:()=>vi,Int32:()=>Dt,Int32Builder:()=>Ai,Int64:()=>Qe,Int64Builder:()=>Si,Int8:()=>Ae,Int8Builder:()=>xi,IntBuilder:()=>Ce,Interval:()=>ue,IntervalBuilder:()=>Pr,IntervalDayTime:()=>cs,IntervalDayTimeBuilder:()=>As,IntervalMonthDayNano:()=>Ia,IntervalMonthDayNanoBuilder:()=>Bs,IntervalUnit:()=>et,IntervalYearMonth:()=>ls,IntervalYearMonthBuilder:()=>Ss,JSONMessageReader:()=>zi,LargeBinary:()=>Fr,LargeBinaryBuilder:()=>In,LargeList:()=>tr,LargeListBuilder:()=>Mi,LargeUtf8:()=>Or,LargeUtf8Builder:()=>Ps,List:()=>Ct,ListBuilder:()=>Ti,MapBuilder:()=>Di,MapRow:()=>fr,Map_:()=>fe,Message:()=>ye,MessageHeader:()=>Q,MessageReader:()=>ks,MetadataVersion:()=>ht,Null:()=>Et,NullBuilder:()=>Ci,Precision:()=>ot,RecordBatch:()=>ct,RecordBatchFileReader:()=>Fn,RecordBatchFileWriter:()=>Nn,RecordBatchJSONWriter:()=>Ha,RecordBatchReader:()=>Oe,RecordBatchStreamReader:()=>kr,RecordBatchStreamWriter:()=>Un,RecordBatchWriter:()=>rn,Schema:()=>j,SparseUnion:()=>us,SparseUnionBuilder:()=>Oi,Struct:()=>ut,StructBuilder:()=>Fi,StructRow:()=>Kr,Table:()=>st,Time:()=>Kt,TimeBuilder:()=>br,TimeMicrosecond:()=>ns,TimeMicrosecondBuilder:()=>Us,TimeMillisecond:()=>rs,TimeMillisecondBuilder:()=>Es,TimeNanosecond:()=>ss,TimeNanosecondBuilder:()=>Ns,TimeSecond:()=>es,TimeSecondBuilder:()=>Os,TimeUnit:()=>v,Timestamp:()=>Jt,TimestampBuilder:()=>gr,TimestampMicrosecond:()=>os,TimestampMicrosecondBuilder:()=>Cs,TimestampMillisecond:()=>Xr,TimestampMillisecondBuilder:()=>Ds,TimestampNanosecond:()=>as,TimestampNanosecondBuilder:()=>Fs,TimestampSecond:()=>is,TimestampSecondBuilder:()=>Ms,Type:()=>d,Uint16:()=>Ie,Uint16Builder:()=>Ii,Uint32:()=>qt,Uint32Builder:()=>_i,Uint64:()=>Dr,Uint64Builder:()=>Li,Uint8:()=>Be,Uint8Builder:()=>Bi,Union:()=>De,UnionBuilder:()=>_n,UnionMode:()=>lt,Utf8:()=>ce,Utf8Builder:()=>Rs,Utf8View:()=>Le,Utf8ViewBuilder:()=>Ui,Vector:()=>A,Visitor:()=>F,builderThroughAsyncIterable:()=>qh,builderThroughIterable:()=>Sl,compressionRegistry:()=>zs,isArrowData:()=>Vl,isArrowDataType:()=>zl,isArrowField:()=>kl,isArrowRecordBatch:()=>jl,isArrowSchema:()=>Pl,isArrowTable:()=>ql,isArrowVector:()=>Gl,makeBuilder:()=>Rr,makeData:()=>D,makeTable:()=>$h,makeVector:()=>te,tableFromArrays:()=>Wh,tableFromIPC:()=>Xa,tableFromJSON:()=>jh,tableToIPC:()=>Rl,util:()=>wg,vectorFromArray:()=>Mo});var nn=p(()=>{ca();vt();Ya();El();fg();mg();yg();gg();ld();ld();Yt.toDOMStream=ug;bt.throughDOM=pg;Oe.throughDOM=Ul;Fn.throughDOM=Ul;kr.throughDOM=Ul;rn.throughDOM=Nl;Nn.throughDOM=Nl;Un.throughDOM=Nl});var $l,ud,xg=p(()=>{"use strict";nn();$l=new j([new S("POSITION",new gt(3,new S("value",new Xt,!1)),!1)]),ud=new j([...$l.fields,new S("indices",new Ct(new S("item",new qt,!1)),!0)])});var Vs=p(()=>{"use strict";Am();xg()});function sA(r,t="float32"){return r instanceof Date?"date-millisecond":typeof r=="number"?t:typeof r=="boolean"?"bool":typeof r=="string"?"utf8":"null"}function Ag(r){let t=fd(r);return t!=="null"?{type:t,nullable:!1}:r.length>0?(t=sA(r[0]),{type:t,nullable:!0}):{type:"null",nullable:!0}}function fd(r){if(typeof Float16Array<"u"&&r instanceof Float16Array)return"float16";switch(r.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 BigInt64Array:return"int64";case BigUint64Array:return"uint64";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}var hd=p(()=>{"use strict"});function No(r){return{fields:r.fields.map(t=>Vi(t)),metadata:Lg(r.metadata)}}function _g(r,t){return new j(r.fields.map(e=>sn(e,t)),Wl(r.metadata))}function Lg(r){return Object.fromEntries(r)}function Wl(r){return r?new Map(Object.entries(r)):new Map}function Vi(r){return{name:r.name,type:Yl(r.type),nullable:r.nullable,metadata:Lg(r.metadata)}}function sn(r,t){return new S(r.name,Ro(r.type,t),r.nullable,Wl(r.metadata))}function Yl(r){if(Sg(r,"BinaryView"))return"binary-view";if(Sg(r,"Utf8View"))return"utf8-view";if(iA(r,"LargeList"))return{type:"large-list",children:[Vi(r.valueField)]};switch(r.constructor){case Et:return"null";case ze:return"binary";case Ge:return{type:"fixed-size-binary",byteWidth:r.byteWidth};case le:return"bool";case Lt:let t=r;return`${t.isSigned?"":"u"}int${t.bitWidth}`;case Ae:return"int8";case Se:return"int16";case Dt:return"int32";case Qe:return"int64";case Be:return"uint8";case Ie:return"uint16";case qt:return"uint32";case Dr:return"uint64";case ae:switch(r.precision){case ot.HALF:return"float16";case ot.SINGLE:return"float32";case ot.DOUBLE:return"float64";default:return"float16"}case Cr:return"float16";case Xt:return"float32";case _e:return"float64";case ce:return"utf8";case Ve:let n=r;return{type:"decimal",bitWidth:n.bitWidth,precision:n.precision,scale:n.scale};case Te:return r.unit===mt.DAY?"date-day":"date-millisecond";case Qn:return"date-day";case ts:return"date-millisecond";case Kt:switch(r.unit){case v.SECOND:return"time-second";case v.MILLISECOND:return"time-millisecond";case v.MICROSECOND:return"time-microsecond";case v.NANOSECOND:return"time-nanosecond";default:return"time-second"}case rs:return"time-millisecond";case es:return"time-second";case ns:return"time-microsecond";case ss:return"time-nanosecond";case Jt:switch(r.unit){case v.SECOND:return"timestamp-second";case v.MILLISECOND:return"timestamp-millisecond";case v.MICROSECOND:return"timestamp-microsecond";case v.NANOSECOND:return"timestamp-nanosecond";default:return"timestamp-second"}case is:return"timestamp-second";case Xr:return"timestamp-millisecond";case os:return"timestamp-microsecond";case as:return"timestamp-nanosecond";case ue:switch(r.unit){case et.DAY_TIME:return"interval-daytime";case et.YEAR_MONTH:return"interval-yearmonth";default:return"interval-daytime"}case cs:return"interval-daytime";case ls:return"interval-yearmonth";case fe:let c=r;return{type:"map",keysSorted:c.keysSorted,children:c.children.map(g=>Vi(g))};case Ct:let u=r.valueField;return{type:"list",children:[Vi(u)]};case gt:let f=r;return{type:"fixed-size-list",listSize:f.listSize,children:[Vi(f.children[0])]};case ut:return{type:"struct",children:r.children.map(g=>Vi(g))};case us:case bn:let m=r;return{type:m instanceof bn?"dense-union":"sparse-union",typeIds:m.typeIds,children:m.children.map(g=>Vi(g)),typeIdToChildIndex:{...m.typeIdToChildIndex}};case Rt:let y=r;return{type:"dictionary",id:y.id,indices:oA(y.indices),dictionary:Yl(y.dictionary),isOrdered:y.isOrdered};default:throw new Error(`arrow type not supported: ${r.constructor.name}`)}}function Ro(r,t){if(typeof r=="object")switch(r.type){case"decimal":return new Ve(r.scale,r.precision,r.bitWidth);case"map":{let e=r.children.map(n=>sn(n,t));return new fe(e[0],r.keysSorted)}case"list":{let e=sn(r.children[0],t);return new Ct(e)}case"large-list":{let e=sn(r.children[0],t),n=Ka("LargeList");if(!n)throw new Error("LargeList requires an Apache Arrow runtime that exports the LargeList constructor");return new n(e)}case"fixed-size-list":{let e=sn(r.children[0],t);return new gt(r.listSize,e)}case"fixed-size-binary":return new Ge(r.byteWidth);case"struct":{let e=r.children.map(n=>sn(n,t));return new ut(e)}case"sparse-union":case"dense-union":{let e=r.children.map(n=>sn(n,t));return r.type==="dense-union"?new bn(r.typeIds,e):new us(r.typeIds,e)}case"dictionary":return new Rt(Ro(r.dictionary,t),cA(r.indices),r.id,r.isOrdered);default:throw new Error("array type not supported")}switch(r){case"null":return new Et;case"binary":return Bg("BinaryView",new ze,t);case"binary-view":return Ig("BinaryView");case"bool":return new le;case"int8":return new Ae;case"int16":return new Se;case"int32":return new Dt;case"int64":return new Qe;case"uint8":return new Be;case"uint16":return new Ie;case"uint32":return new qt;case"uint64":return new Dr;case"float16":return new Cr;case"float32":return new Xt;case"float64":return new _e;case"utf8":return Bg("Utf8View",new ce,t);case"utf8-view":return Ig("Utf8View");case"date-day":return new Qn;case"date-millisecond":return new ts;case"time-second":return new es;case"time-millisecond":return new rs;case"time-microsecond":return new ns;case"time-nanosecond":return new ss;case"timestamp-second":return new is;case"timestamp-millisecond":return new Xr;case"timestamp-microsecond":return new os;case"timestamp-nanosecond":return new as;case"interval-daytime":return new cs;case"interval-yearmonth":return new ls;default:throw new Error("array type not supported")}}function Ka(r){return zr[r]}function Sg(r,t){let e=Ka(t);if(e&&r instanceof e)return!0;let n=w;return!!(t==="BinaryView"?n.isBinaryView:n.isUtf8View)?.(r)}function iA(r,t){let e=Ka(t);return!!(e&&r instanceof e)}function Bg(r,t,e){let n=e?.viewTypes||"never";if(n==="never")return t;let s=Ka(r);if(s)return new s;if(n==="require")throw new Error(`${r} requires apache-arrow 21.2.0 or later; the installed runtime does not support it`);return t}function Ig(r){let t=Ka(r);if(!t)throw new Error(`${r} requires apache-arrow 21.2.0 or later; the installed runtime does not support it`);return new t}function oA(r){if(r instanceof Lt){let e=`${r.isSigned?"int":"uint"}${r.bitWidth}`;if(aA(e))return e}switch(r.constructor){case Ae:return"int8";case Se:return"int16";case Dt:return"int32";case Be:return"uint8";case Ie:return"uint16";case qt:return"uint32";default:throw new Error(`arrow dictionary index type not supported: ${r.constructor.name}`)}}function aA(r){return["int8","int16","int32","uint8","uint16","uint32"].includes(r)}function cA(r){switch(r){case"int8":return new Ae;case"int16":return new Se;case"int32":return new Dt;case"uint8":return new Be;case"uint16":return new Ie;case"uint32":return new qt;default:throw new Error(`schema dictionary index type not supported: ${r}`)}}var Ja=p(()=>{"use strict";nn()});function on(r){let t=r?.POSITION;if(!t||!("value"in t)||!t.value.length)return null;let e=1/0,n=1/0,s=1/0,i=-1/0,o=-1/0,a=-1/0,c=t.value,l=c.length;for(let u=0;u<l;u+=3){let f=c[u],h=c[u+1],m=c[u+2];e=f<e?f:e,n=h<n?h:n,s=m<s?m:s,i=f>i?f:i,o=h>o?h:o,a=m>a?m:a}return[[e,n,s],[i,o,a]]}var dd=p(()=>{"use strict"});function Tg(r){return r.type instanceof gt?r.type.listSize:1}function pd(r,t,e){let n=lA(r,t,e);return new A([n])}function lA(r,t,e){let n=uA(r,t,e),s=n.children[0].type,i=e==="float16"&&jn(r)?na(r):r,o={[Z.DATA]:i},a=new T(s,0,i.length,0,o);return new T(n,0,i.length/t,0,void 0,[a])}function uA(r,t,e){let n=e||Ag(r).type,s=Ro(n);return new gt(t,new S("value",s,!1))}var md=p(()=>{"use strict";Vs();nn();hd();Ja()});function Ee(r,t){switch(t){case"columnar-table":return fA(r);case"arrow-table":return hA(r);default:throw new Error(t)}}function fA(r){let t={},e=Dg(r);for(let[n,s]of Object.entries(r.attributes))t[n]=s.value;return{shape:"columnar-table",schema:r.schema,data:t,topology:r.topology,indices:e?r.indices:void 0}}function hA(r,t){return Zl(r.attributes,{schema:r.schema,topology:r.topology,mode:r.mode,boundingBox:r.header?.boundingBox,indices:Dg(r)?r.indices:void 0})}function Zl(r,t={}){let e=[],n={},s=pA(r);for(let c of s){let l=r[c],{value:u,size:f=1}=l,h=dA(u,f,l.componentType);if(n[c]=h,e.push(mA(t.schema,c,h,l.componentType)),c==="POSITION"&&t.indices?.value?.length){let m=ud.fields.find(y=>y.name==="indices");n.indices=gA(t.indices.value,h.length,m.type),e.push(m)}}let i=new j(e,bA(t)),o=n[s[0]]?.length===0?new st(i):new st(i,n);return{shape:"arrow-table",schema:No(o.schema),data:o,topology:t.topology||"point-list",indices:t.indices}}function dA(r,t,e){if(e==="float16"){let n=jn(r)?na(r):r;if(t===1){let s=new T(new Cr,0,n.length,0,{[Z.DATA]:n});return new A([s])}return pd(r,t,e)}return t===1?te(r):pd(r,t)}function pA(r){let t=Object.keys(r),e=Mg.filter(s=>s in r),n=t.filter(s=>!Mg.includes(s));return[...e,...n]}function Dg(r){return!!r.indices?.value?.length}function mA(r,t,e,n){if(t==="POSITION"&&yA(e)){let i=$l.fields[0],o=r?.fields.find(c=>c.name===t);if(!o?.metadata)return i;let a=new Map(i.metadata);for(let[c,l]of Object.entries(o.metadata))a.set(c,l);return new S(i.name,i.type,i.nullable,a)}let s=r?.fields.find(i=>i.name===t);if(n==="float16"){let i=new Map(Object.entries(s?.metadata||{}));return i.set("componentType","float16"),new S(t,e.type,!1,i)}if(s&&s.type.toString()!==e.type.toString()){let i=sn(s);return new S(t,e.type,i.nullable,i.metadata)}return s?sn(s):new S(t,e.type,!1)}function yA(r){return r.type instanceof gt&&r.type.listSize===3&&r.type.children[0].type instanceof Xt}function gA(r,t,e){let n=e,s=r instanceof Uint32Array?r:Uint32Array.from(r),i=new Int32Array(t+1);t>0&&i.fill(s.length,1);let o=new Uint8Array(Math.ceil(t/8));t>0&&(o[0]=1);let a=new T(n.children[0].type,0,s.length,0,{[Z.DATA]:s}),c=new T(n,0,t,Math.max(0,t-1),{[Z.OFFSET]:i,[Z.VALIDITY]:o},[a]);return new A([c])}function bA(r){let t={...r.schema?.metadata};return r.topology&&(t.topology||=r.topology),Number.isFinite(r.mode)&&(t.mode||=String(r.mode)),r.boundingBox&&(t.boundingBox||=JSON.stringify(r.boundingBox)),Wl(t)}var Mg,Cg=p(()=>{"use strict";Vs();Vs();nn();md();Ja();Mg=["POSITION"]});function ee(r){if(r.shape==="arrow-table")return wA(r);throw new Error(r.shape)}function wA(r){let t=r.data,e=No(t.schema),n=e.fields,s={},i=[];for(let u of n){let{name:f}=u;if(f==="indices")continue;let h=t.getChild(f),m=Tg(h),y=BA(h,m),g=vA(u.metadata),x=g.componentType==="float16"?IA(y):y,B=i.find(q=>q.data.length===h.data.length&&s[q.name].value.constructor===x.constructor&&q.data.every((M,b)=>Fg(M,h.data[b])));s[f]={value:B?s[B.name].value:x,size:m,...g},B||i.push({name:f,data:h.data})}SA(e);let o=e.metadata.topology,a=_A(e),c=LA(t),l=s.POSITION?.transform?.type==="quantization"?xA(e)||on(s):on(s);return{schema:e,attributes:s,topology:o,mode:a,indices:c,header:{vertexCount:t.numRows,boundingBox:l??void 0}}}function xA(r){let t=r.metadata?.boundingBox;if(!t)return null;try{let e=JSON.parse(t);if(Array.isArray(e)&&e.length===2&&e.every(n=>Array.isArray(n)&&n.length===3&&n.every(s=>typeof s=="number")))return e}catch{}return null}function vA(r={}){let t={};if(r.byteOffset!==void 0&&(t.byteOffset=Number(r.byteOffset)),r.byteStride!==void 0&&(t.byteStride=Number(r.byteStride)),r.normalized!==void 0&&(t.normalized=r.normalized==="true"),r.componentType==="float16"&&(t.componentType="float16"),r["loaders.gl.transform"])try{let e=JSON.parse(r["loaders.gl.transform"]);AA(e)&&(t.transform=e)}catch{}return t}function AA(r){if(!r||typeof r!="object"||!("type"in r))return!1;let t=r;return t.type==="octahedron"?Number.isInteger(t.bits)&&t.bits>=1&&t.bits<=30:t.type==="quantization"&&Number.isInteger(t.bits)&&t.bits>=1&&t.bits<=30&&Array.isArray(t.origin)&&t.origin.every(e=>typeof e=="number")&&typeof t.range=="number"}function SA(r){r.metadata||={},r.metadata.topology||="point-list",r.metadata.mode||="0"}function BA(r,t){if(!(r.type instanceof gt))return r.toArray();let n=r.data[0].children[0].values.constructor,s=new n(r.length*t),i=0;for(let o of r.data){let a=o.children[0],c=o.length*t,l=a.offset||o.offset*t,u=l+c<=a.values.length?l:0,f=a.values.subarray(u,u+c);s.set(f,i),i+=c}return s}function IA(r){let t=hc(r.length);for(let e=0;e<r.length;e++)dc(t,e,Hu(r,e));return t}function _A(r){let t=Number(r.metadata?.mode);return Number.isFinite(t)?t:0}function LA(r){let t=r.getChild("indices");if(!t?.isValid(0))return;let e=t.data[0],n=e.valueOffsets,s=n[e.offset],i=n[e.offset+1];return{value:e.children[0].values.subarray(s,i),size:1}}function Fg(r,t){let e=Object.values(t.buffers);return r.type.toString()===t.type.toString()&&r.offset===t.offset&&r.length===t.length&&r.nullCount===t.nullCount&&r.dictionary===t.dictionary&&Object.values(r.buffers).every((n,s)=>{let i=e[s];return n===i||!!(n&&i&&n.buffer===i.buffer&&n.byteOffset===i.byteOffset&&n.byteLength===i.byteLength)})&&r.children.length===t.children.length&&r.children.every((n,s)=>Fg(n,t.children[s]))}var Og=p(()=>{"use strict";Vs();nn();md();Ja();dd()});function Gi(r,t={}){return{fields:TA(r),metadata:t}}function Eg(r,t,e){let n=t.componentType||fd(t.value),s=e||Ug(t),i=t.size===1?n:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:n}]};return{name:r,type:i,nullable:!1,metadata:s}}function TA(r){let t=[];for(let e in r){let n=r[e];t.push(Eg(e,n))}return t}function Ug(r){let t={};return"byteOffset"in r&&(t.byteOffset=r.byteOffset.toString(10)),"byteStride"in r&&(t.byteStride=r.byteStride.toString(10)),"normalized"in r&&(t.normalized=r.normalized.toString()),r.componentType&&(t.componentType=r.componentType),r.transform&&(t["loaders.gl.transform"]=JSON.stringify(r.transform)),t}var Ng=p(()=>{"use strict";hd()});var or=p(()=>{"use strict";dd();Cg();Og();Ng()});var Rg,Pg=p(()=>{"use strict";Rg={name:"LAS",id:"las",module:"pointclouds",encoding:"binary",format:"las",extensions:["las","laz"],mimeTypes:["application/octet-stream"],text:!1,binary:!0,tests:["LASF"]}});function zg(r){return r?.las?.shape||kg}function Gg(r,t){if(t==="uint8norm"||!r.attributes.COLOR_0)return r;let e=r.attributes.COLOR_0,n=e.value instanceof Uint16Array?65535:255,s=t==="float16"?ti(e.value,n):sa(e.value,n),i={...r.attributes};for(let[o,a]of Object.entries(i))a.value===e.value&&(i[o]={...a,value:s,normalized:!1,...t==="float16"?{componentType:"float16"}:{}});return{...r,attributes:i}}var MA,kg,Vg,jg=p(()=>{"use strict";Vs();Pg();MA="5.0.0-beta.2",kg="arrow-table";Vg={...Rg,dataType:null,batchType:null,version:MA,worker:!1,options:{las:{shape:kg,fp64:!1,colorDepth:8,colorFormat:"uint8norm",columns:void 0,extraBytes:"raw",recoverMissingChunkTable:!1,compatibilityMode:"auto"}}}});function qg(r,t={}){let e={...t,copies:new WeakMap};return DA(r)?OA(r,e):CA(r)?$g(r,e):FA(r)?Wg(r,e):Xl(r,e)}function DA(r){return"batches"in r}function CA(r){return"schema"in r&&"data"in r&&!Array.isArray(r.data)}function FA(r){return"data"in r&&Array.isArray(r.data)}function OA(r,t){let e=r.batches.map(n=>$g(n,t));return new st(r.schema,e)}function $g(r,t){return new ct(r.schema,Xl(r.data,t))}function Xl(r,t){let e=r.children.map(i=>Xl(i,t)),n=r.dictionary?Wg(r.dictionary,t):void 0,s={[Z.OFFSET]:Hl(r.buffers[Z.OFFSET],t),[Z.DATA]:Hl(r.buffers[Z.DATA],t),[Z.VALIDITY]:Hl(r.buffers[Z.VALIDITY],t),[Z.TYPE]:Hl(r.buffers[Z.TYPE],t)};return new T(r.type,r.offset,r.length,r._nullCount,s,e,n)}function Wg(r,t){return new A(r.data.map(e=>Xl(e,t)))}function Hl(r,t){if(!EA(r)||t.copy==="none"||t.copy!=="all"&&r.byteOffset===0&&r.byteLength===r.buffer.byteLength)return r;let e=t.copies.get(r);return e||(e=r.slice(),t.copies.set(r,e)),e}function EA(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}var yd=p(()=>{"use strict";nn()});function UA(r,t){let e=qg(r,t);return{shape:"arrow-table",transport:"arrow-js",schema:No(e.schema),batches:e.batches.map(n=>kA(n))}}function NA(r){let t=_g(r.schema),e=r.batches.map(n=>new ct(t,bd(n.data)));return new st(t,e)}function re(r){if(!RA(r))throw new Error("Workers require Arrow table output");let{data:t,...e}=r;return{...structuredClone(e),data:UA(t,{copy:"all"})}}function Po(r){if(!PA(r))throw new Error("Workers require Arrow column transport");return{...r,data:NA(r.data)}}function RA(r){let t=r;return!!(t&&t.shape==="arrow-table"&&t.data&&typeof t.data=="object"&&"batches"in t.data)}function PA(r){let t=r;return!!(t&&t.shape==="arrow-table"&&t.data&&t.data.transport==="arrow-js"&&Array.isArray(t.data.batches))}function kA(r){return{data:gd(r.data)}}function gd(r){return{type:Yl(r.type),offset:r.offset,length:r.length,nullCount:r._nullCount,buffers:{[Z.OFFSET]:r.buffers[Z.OFFSET],[Z.DATA]:r.buffers[Z.DATA],[Z.VALIDITY]:r.buffers[Z.VALIDITY],[Z.TYPE]:r.buffers[Z.TYPE]},children:r.children.map(t=>gd(t)),dictionary:r.dictionary?zA(r.dictionary):void 0}}function zA(r){return{data:r.data.map(t=>gd(t))}}function bd(r){let t=r.children.map(n=>bd(n)),e=r.dictionary?VA(r.dictionary):void 0;return new T(Ro(r.type),r.offset,r.length,r.nullCount,r.buffers,t,e)}function VA(r){return new A(r.data.map(t=>bd(t)))}var Yg=p(()=>{"use strict";nn();Ja();yd()});var Gs=p(()=>{"use strict";Yg();yd()});function Zg(...r){return GA(r)}function GA(r){let t=r.map(i=>i instanceof ArrayBuffer?new Uint8Array(i):i),e=t.reduce((i,o)=>i+o.byteLength,0),n=new Uint8Array(e),s=0;for(let i of t)n.set(i,s),s+=i.byteLength;return n.buffer}var Hg=p(()=>{"use strict"});function jA(r){return ArrayBuffer.isView(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r)}var js,Xg=p(()=>{"use strict";js=class{offset=0;ended=!1;maxRewindBytes;chunks=[];scratch=new ArrayBuffer(8);checkpoints=[];constructor(t){this.maxRewindBytes=t?.maxRewindBytes||0}get arrayBuffers(){return this.chunks.map(t=>t.buffer)}write(t){this.chunks.push(jA(t))}end(){this.chunks=[],this.checkpoints=[],this.offset=0,this.ended=!0}hasAvailableBytes(t){return this.getAvailableByteLength()>=t}getAvailableByteLength(){let t=-this.offset;for(let e of this.chunks)t+=e.byteLength,t>0;return Math.max(0,t)}findBufferOffsets(t){let e=-this.offset,n=[];for(let s=0;s<this.chunks.length;s++){let i=this.chunks[s];if(e+i.byteLength<=0){e+=i.byteLength;continue}let o=e<=0?Math.abs(e):0,a;if(o+t<=i.byteLength)return a=o+t,n.push([s,[o,a]]),n;a=i.byteLength,n.push([s,[o,a]]),t-=i.byteLength-o,e+=i.byteLength}return null}getDataView(t){let e=this.findBufferOffsets(t);if(!e){if(this.ended)throw new Error("binary data exhausted");return null}let n;if(e.length===1){let[s,[i,o]]=e[0],a=this.chunks[s];n=new DataView(a.buffer,a.byteOffset+i,o-i)}else{let s=this.combineBufferOffsets(e);n=new DataView(s.buffer,s.byteOffset,s.byteLength)}return this.offset+=t,this.disposeBuffers(),n}readByte(){let t=this.findBufferOffsets(1);if(!t)throw new Error("binary data exhausted");let[e,[n]]=t[0],s=this.chunks[e][n];return this.offset++,this.disposeBuffers(),s}readUint16LE(){let t=this.readByte(),e=this.readByte();return t|e<<8}readUint32LE(){let t=this.readByte(),e=this.readByte(),n=this.readByte(),s=this.readByte();return(t|e<<8|n<<16|s<<24>>>0)>>>0}readInt32LE(){return this.readUint32LE()|0}readFloat64LE(){let t=this.getContiguousDataView(8);if(t)return t.getFloat64(0,!0);let e=new Uint8Array(this.scratch);return this.readInto(e,0,8),new DataView(this.scratch).getFloat64(0,!0)}readInto(t,e,n){let s=this.findBufferOffsets(n);if(!s)throw new Error("binary data exhausted");let i=e;for(let[o,[a,c]]of s){let l=this.chunks[o];t.set(l.subarray(a,c),i),i+=c-a}this.offset+=n,this.disposeBuffers()}readBytes(t){let e=this.findBufferOffsets(t);if(!e)throw new Error("binary data exhausted");let n;if(e.length===1){let[s,[i,o]]=e[0];n=this.chunks[s].subarray(i,o)}else n=this.combineBufferOffsets(e);return this.offset+=t,this.disposeBuffers(),n}skip(t){this.offset+=t}rewind(t){this.offset-=t}checkpoint(){let t={offset:this.offset};return this.checkpoints.push(t),t}restore(t){this.offset=t.offset,this.checkpoints.pop()}discardConsumed(){this.disposeBuffers()}_combineArrayBuffers(t){return this.combineBufferOffsets(t).buffer}getContiguousDataView(t){let e=this.findBufferOffsets(t);if(!e||e.length!==1)return null;let[n,[s,i]]=e[0],o=this.chunks[n],a=new DataView(o.buffer,o.byteOffset+s,i-s);return this.offset+=t,this.disposeBuffers(),a}disposeBuffers(){let t=this.checkpoints.length>0?Math.min(...this.checkpoints.map(e=>e.offset)):Number.POSITIVE_INFINITY;for(;this.chunks.length>0&&this.offset-this.maxRewindBytes>=this.chunks[0].byteLength&&t>=this.chunks[0].byteLength;){this.offset-=this.chunks[0].byteLength;for(let e of this.checkpoints)e.offset-=this.chunks[0].byteLength;t-=this.chunks[0].byteLength,this.chunks.shift()}}combineBufferOffsets(t){let e=0;for(let[,[i,o]]of t)e+=o-i;let n=new Uint8Array(e),s=0;for(let[i,[o,a]]of t){let c=this.chunks[i];n.set(c.subarray(o,a),s),s+=a-o}return n}}});async function*Kl(r,t={}){let e=new TextDecoder(void 0,t);for await(let n of r)yield typeof n=="string"?n:e.decode(n,{stream:!0})}async function*Jl(r){let t="";for await(let e of r){t+=e;let n;for(n=t.indexOf(`
|
|
26
|
+
}`),this._recordBatchesWithDictionaries=[],this._recordBatches=[],super.close()}}});function ug(r,t){if(lr(r))return eA(r,t);if(Sr(r))return tA(r,t);throw new Error("toDOMStream() must be called with an Iterable or AsyncIterable")}function tA(r,t){let e=null,n=t?.type==="bytes"||!1,s=t?.highWaterMark||Math.pow(2,24);return new ReadableStream(Object.assign(Object.assign({},t),{start(o){i(o,e||(e=r[Symbol.iterator]()))},pull(o){e?i(o,e):o.close()},cancel(){e?.return&&e.return(),e=null}}),Object.assign({highWaterMark:n?s:void 0},t));function i(o,a){let c,l=null,u=o.desiredSize||null;for(;!(l=a.next(n?u:null)).done;)if(ArrayBuffer.isView(l.value)&&(c=O(l.value))&&(u!=null&&n&&(u=u-c.byteLength+1),l.value=c),o.enqueue(l.value),u!=null&&--u<=0)return;o.close()}}function eA(r,t){let e=null,n=t?.type==="bytes"||!1,s=t?.highWaterMark||Math.pow(2,24);return new ReadableStream(Object.assign(Object.assign({},t),{start(o){return I(this,void 0,void 0,function*(){yield i(o,e||(e=r[Symbol.asyncIterator]()))})},pull(o){return I(this,void 0,void 0,function*(){e?yield i(o,e):o.close()})},cancel(){return I(this,void 0,void 0,function*(){e?.return&&(yield e.return()),e=null})}}),Object.assign({highWaterMark:n?s:void 0},t));function i(o,a){return I(this,void 0,void 0,function*(){let c,l=null,u=o.desiredSize||null;for(;!(l=yield a.next(n?u:null)).done;)if(ArrayBuffer.isView(l.value)&&(c=O(l.value))&&(u!=null&&n&&(u=u-c.byteLength+1),l.value=c),o.enqueue(l.value),u!=null&&--u<=0)return;o.close()})}}var fg=p(()=>{Pe();Gt();qn()});function pg(r){return new od(r)}var od,hg,dg,mg=p(()=>{Pe();Ga();od=class{constructor(t){this._numChunks=0,this._finished=!1,this._bufferedSize=0;let{["readableStrategy"]:e,["writableStrategy"]:n,["queueingStrategy"]:s="count"}=t,i=Bm(t,["readableStrategy","writableStrategy","queueingStrategy"]);this._controller=null,this._builder=Rr(i),this._getSize=s!=="bytes"?hg:dg;let{["highWaterMark"]:o=s==="bytes"?Math.pow(2,14):1e3}=Object.assign({},e),{["highWaterMark"]:a=s==="bytes"?Math.pow(2,14):1e3}=Object.assign({},n);this.readable=new ReadableStream({cancel:()=>{this._builder.clear()},pull:c=>{this._maybeFlush(this._builder,this._controller=c)},start:c=>{this._maybeFlush(this._builder,this._controller=c)}},{highWaterMark:o,size:s!=="bytes"?hg:dg}),this.writable=new WritableStream({abort:()=>{this._builder.clear()},write:()=>{this._maybeFlush(this._builder,this._controller)},close:()=>{this._maybeFlush(this._builder.finish(),this._controller)}},{highWaterMark:a,size:c=>this._writeValueAndReturnChunkSize(c)})}_writeValueAndReturnChunkSize(t){let e=this._bufferedSize;return this._bufferedSize=this._getSize(this._builder.append(t)),this._bufferedSize-e}_maybeFlush(t,e){e!=null&&(this._bufferedSize>=e.desiredSize&&++this._numChunks&&this._enqueue(e,t.toVector()),t.finished&&((t.length>0||this._numChunks===0)&&++this._numChunks&&this._enqueue(e,t.toVector()),!this._finished&&(this._finished=!0)&&this._enqueue(e,null)))}_enqueue(t,e){this._bufferedSize=0,this._controller=null,e==null?t.close():t.enqueue(e)}},hg=r=>{var t;return(t=r?.length)!==null&&t!==void 0?t:0},dg=r=>{var t;return(t=r?.byteLength)!==null&&t!==void 0?t:0}});function Ul(r,t){let e=new pr,n=null,s=new ReadableStream({cancel(){return I(this,void 0,void 0,function*(){yield e.close()})},start(a){return I(this,void 0,void 0,function*(){yield o(a,n||(n=yield i()))})},pull(a){return I(this,void 0,void 0,function*(){n?yield o(a,n):a.close()})}});return{writable:new WritableStream(e,Object.assign({highWaterMark:Math.pow(2,14)},r)),readable:s};function i(){return I(this,void 0,void 0,function*(){return yield(yield Oe.from(e)).open(t)})}function o(a,c){return I(this,void 0,void 0,function*(){let l=a.desiredSize,u=null;for(;!(u=yield c.next()).done;)if(a.enqueue(u.value),l!=null&&--l<=0)return;a.close()})}}var yg=p(()=>{Pe();ys();Ya()});function Nl(r,t){let e=new this(r),n=new $e(e),s=new ReadableStream({cancel(){return I(this,void 0,void 0,function*(){yield n.cancel()})},pull(o){return I(this,void 0,void 0,function*(){yield i(o)})},start(o){return I(this,void 0,void 0,function*(){yield i(o)})}},Object.assign({highWaterMark:Math.pow(2,14)},t));return{writable:new WritableStream(e,r),readable:s};function i(o){return I(this,void 0,void 0,function*(){let a=null,c=o.desiredSize;for(;a=yield n.read(c||null);)if(o.enqueue(a),c!=null&&(c-=a.byteLength)<=0)return;o.close()})}}var gg=p(()=>{Pe();ys()});function Xa(r){let t=Oe.from(r);return Ke(t)?t.then(e=>Xa(e)):t.isAsync()?t.readAll().then(e=>new st(e)):new st(t.readAll())}function Rl(r,t="stream",e=null){let n={compressionType:e};return(t==="stream"?Un:Nn).writeAll(r,n).toUint8Array(!0)}var bg=p(()=>{Ri();qn();Ya();El()});var ad={};Re(ad,{isArrowData:()=>Vl,isArrowDataType:()=>zl,isArrowField:()=>kl,isArrowRecordBatch:()=>jl,isArrowSchema:()=>Pl,isArrowTable:()=>ql,isArrowVector:()=>Gl});function Pl(r){return j.isSchema(r)}function kl(r){return S.isField(r)}function zl(r){return w.isDataType(r)}function Vl(r){return T.isData(r)}function Gl(r){return A.isVector(r)}function jl(r){return ct.isRecordBatch(r)}function ql(r){return st.isTable(r)}var cd=p(()=>{pe();yt();hr();he();Dn();Ri()});var wg,ld=p(()=>{Mc();ao();Mt();hr();yt();Ri();he();je();pe();Fa();Hc();vt();Ga();wh();Fh();xh();vh();Ah();Sh();Ih();Th();Uh();Eh();_h();Lh();Rh();kh();Ph();yl();bl();gl();Mh();Dh();Bh();Ch();Oh();Nh();ys();Ya();El();bg();Tl();Ll();ms();Dn();cd();Dc();dh();li();Ca();Gt();vo();Sa();dl();cd();Wa();wg=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},Nf),hh),Jf),Rf),ef),Kf),Ff),bh),ad),{compareSchemas:Ni,compareFields:V0,compareTypes:vl})});var zr={};Re(zr,{AsyncByteQueue:()=>pr,AsyncByteStream:()=>$e,AsyncMessageReader:()=>ki,AsyncRecordBatchFileReader:()=>Fo,AsyncRecordBatchStreamReader:()=>Cn,Binary:()=>ze,BinaryBuilder:()=>Bn,BinaryView:()=>H,BinaryViewBuilder:()=>Ln,Bool:()=>le,BoolBuilder:()=>pi,BufferType:()=>Z,Builder:()=>bt,ByteStream:()=>mr,CompressionType:()=>Ht,Data:()=>T,DataType:()=>w,DateBuilder:()=>Qr,DateDay:()=>Qn,DateDayBuilder:()=>bs,DateMillisecond:()=>ts,DateMillisecondBuilder:()=>ws,DateUnit:()=>mt,Date_:()=>Te,Decimal:()=>Ve,DecimalBuilder:()=>xs,DenseUnion:()=>bn,DenseUnionBuilder:()=>Ei,Dictionary:()=>Rt,DictionaryBuilder:()=>mi,Duration:()=>Me,DurationBuilder:()=>yr,DurationMicrosecond:()=>Ta,DurationMicrosecondBuilder:()=>Ls,DurationMillisecond:()=>La,DurationMillisecondBuilder:()=>_s,DurationNanosecond:()=>Ma,DurationNanosecondBuilder:()=>Ts,DurationSecond:()=>_a,DurationSecondBuilder:()=>Is,Field:()=>S,FixedSizeBinary:()=>Ge,FixedSizeBinaryBuilder:()=>vs,FixedSizeList:()=>gt,FixedSizeListBuilder:()=>yi,Float:()=>ae,Float16:()=>Cr,Float16Builder:()=>gi,Float32:()=>Xt,Float32Builder:()=>bi,Float64:()=>_e,Float64Builder:()=>wi,FloatBuilder:()=>tn,Int:()=>Lt,Int16:()=>Se,Int16Builder:()=>vi,Int32:()=>Dt,Int32Builder:()=>Ai,Int64:()=>Qe,Int64Builder:()=>Si,Int8:()=>Ae,Int8Builder:()=>xi,IntBuilder:()=>Ce,Interval:()=>ue,IntervalBuilder:()=>Pr,IntervalDayTime:()=>cs,IntervalDayTimeBuilder:()=>As,IntervalMonthDayNano:()=>Ia,IntervalMonthDayNanoBuilder:()=>Bs,IntervalUnit:()=>et,IntervalYearMonth:()=>ls,IntervalYearMonthBuilder:()=>Ss,JSONMessageReader:()=>zi,LargeBinary:()=>Fr,LargeBinaryBuilder:()=>In,LargeList:()=>tr,LargeListBuilder:()=>Mi,LargeUtf8:()=>Or,LargeUtf8Builder:()=>Ps,List:()=>Ct,ListBuilder:()=>Ti,MapBuilder:()=>Di,MapRow:()=>fr,Map_:()=>fe,Message:()=>ye,MessageHeader:()=>Q,MessageReader:()=>ks,MetadataVersion:()=>ht,Null:()=>Et,NullBuilder:()=>Ci,Precision:()=>ot,RecordBatch:()=>ct,RecordBatchFileReader:()=>Fn,RecordBatchFileWriter:()=>Nn,RecordBatchJSONWriter:()=>Ha,RecordBatchReader:()=>Oe,RecordBatchStreamReader:()=>kr,RecordBatchStreamWriter:()=>Un,RecordBatchWriter:()=>rn,Schema:()=>j,SparseUnion:()=>us,SparseUnionBuilder:()=>Oi,Struct:()=>ut,StructBuilder:()=>Fi,StructRow:()=>Kr,Table:()=>st,Time:()=>Kt,TimeBuilder:()=>br,TimeMicrosecond:()=>ns,TimeMicrosecondBuilder:()=>Us,TimeMillisecond:()=>rs,TimeMillisecondBuilder:()=>Es,TimeNanosecond:()=>ss,TimeNanosecondBuilder:()=>Ns,TimeSecond:()=>es,TimeSecondBuilder:()=>Os,TimeUnit:()=>v,Timestamp:()=>Jt,TimestampBuilder:()=>gr,TimestampMicrosecond:()=>os,TimestampMicrosecondBuilder:()=>Cs,TimestampMillisecond:()=>Xr,TimestampMillisecondBuilder:()=>Ds,TimestampNanosecond:()=>as,TimestampNanosecondBuilder:()=>Fs,TimestampSecond:()=>is,TimestampSecondBuilder:()=>Ms,Type:()=>d,Uint16:()=>Ie,Uint16Builder:()=>Ii,Uint32:()=>qt,Uint32Builder:()=>_i,Uint64:()=>Dr,Uint64Builder:()=>Li,Uint8:()=>Be,Uint8Builder:()=>Bi,Union:()=>De,UnionBuilder:()=>_n,UnionMode:()=>lt,Utf8:()=>ce,Utf8Builder:()=>Rs,Utf8View:()=>Le,Utf8ViewBuilder:()=>Ui,Vector:()=>A,Visitor:()=>F,builderThroughAsyncIterable:()=>qh,builderThroughIterable:()=>Sl,compressionRegistry:()=>zs,isArrowData:()=>Vl,isArrowDataType:()=>zl,isArrowField:()=>kl,isArrowRecordBatch:()=>jl,isArrowSchema:()=>Pl,isArrowTable:()=>ql,isArrowVector:()=>Gl,makeBuilder:()=>Rr,makeData:()=>D,makeTable:()=>$h,makeVector:()=>te,tableFromArrays:()=>Wh,tableFromIPC:()=>Xa,tableFromJSON:()=>jh,tableToIPC:()=>Rl,util:()=>wg,vectorFromArray:()=>Mo});var nn=p(()=>{ca();vt();Ya();El();fg();mg();yg();gg();ld();ld();Yt.toDOMStream=ug;bt.throughDOM=pg;Oe.throughDOM=Ul;Fn.throughDOM=Ul;kr.throughDOM=Ul;rn.throughDOM=Nl;Nn.throughDOM=Nl;Un.throughDOM=Nl});var $l,ud,xg=p(()=>{"use strict";nn();$l=new j([new S("POSITION",new gt(3,new S("value",new Xt,!1)),!1)]),ud=new j([...$l.fields,new S("indices",new Ct(new S("item",new qt,!1)),!0)])});var Vs=p(()=>{"use strict";Am();xg()});function sA(r,t="float32"){return r instanceof Date?"date-millisecond":typeof r=="number"?t:typeof r=="boolean"?"bool":typeof r=="string"?"utf8":"null"}function Ag(r){let t=fd(r);return t!=="null"?{type:t,nullable:!1}:r.length>0?(t=sA(r[0]),{type:t,nullable:!0}):{type:"null",nullable:!0}}function fd(r){if(typeof Float16Array<"u"&&r instanceof Float16Array)return"float16";switch(r.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 BigInt64Array:return"int64";case BigUint64Array:return"uint64";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}var hd=p(()=>{"use strict"});function No(r){return{fields:r.fields.map(t=>Vi(t)),metadata:Lg(r.metadata)}}function _g(r,t){return new j(r.fields.map(e=>sn(e,t)),Wl(r.metadata))}function Lg(r){return Object.fromEntries(r)}function Wl(r){return r?new Map(Object.entries(r)):new Map}function Vi(r){return{name:r.name,type:Yl(r.type),nullable:r.nullable,metadata:Lg(r.metadata)}}function sn(r,t){return new S(r.name,Ro(r.type,t),r.nullable,Wl(r.metadata))}function Yl(r){if(Sg(r,"BinaryView"))return"binary-view";if(Sg(r,"Utf8View"))return"utf8-view";if(iA(r,"LargeList"))return{type:"large-list",children:[Vi(r.valueField)]};switch(r.constructor){case Et:return"null";case ze:return"binary";case Ge:return{type:"fixed-size-binary",byteWidth:r.byteWidth};case le:return"bool";case Lt:let t=r;return`${t.isSigned?"":"u"}int${t.bitWidth}`;case Ae:return"int8";case Se:return"int16";case Dt:return"int32";case Qe:return"int64";case Be:return"uint8";case Ie:return"uint16";case qt:return"uint32";case Dr:return"uint64";case ae:switch(r.precision){case ot.HALF:return"float16";case ot.SINGLE:return"float32";case ot.DOUBLE:return"float64";default:return"float16"}case Cr:return"float16";case Xt:return"float32";case _e:return"float64";case ce:return"utf8";case Ve:let n=r;return{type:"decimal",bitWidth:n.bitWidth,precision:n.precision,scale:n.scale};case Te:return r.unit===mt.DAY?"date-day":"date-millisecond";case Qn:return"date-day";case ts:return"date-millisecond";case Kt:switch(r.unit){case v.SECOND:return"time-second";case v.MILLISECOND:return"time-millisecond";case v.MICROSECOND:return"time-microsecond";case v.NANOSECOND:return"time-nanosecond";default:return"time-second"}case rs:return"time-millisecond";case es:return"time-second";case ns:return"time-microsecond";case ss:return"time-nanosecond";case Jt:switch(r.unit){case v.SECOND:return"timestamp-second";case v.MILLISECOND:return"timestamp-millisecond";case v.MICROSECOND:return"timestamp-microsecond";case v.NANOSECOND:return"timestamp-nanosecond";default:return"timestamp-second"}case is:return"timestamp-second";case Xr:return"timestamp-millisecond";case os:return"timestamp-microsecond";case as:return"timestamp-nanosecond";case ue:switch(r.unit){case et.DAY_TIME:return"interval-daytime";case et.YEAR_MONTH:return"interval-yearmonth";default:return"interval-daytime"}case cs:return"interval-daytime";case ls:return"interval-yearmonth";case fe:let c=r;return{type:"map",keysSorted:c.keysSorted,children:c.children.map(g=>Vi(g))};case Ct:let u=r.valueField;return{type:"list",children:[Vi(u)]};case gt:let f=r;return{type:"fixed-size-list",listSize:f.listSize,children:[Vi(f.children[0])]};case ut:return{type:"struct",children:r.children.map(g=>Vi(g))};case us:case bn:let m=r;return{type:m instanceof bn?"dense-union":"sparse-union",typeIds:m.typeIds,children:m.children.map(g=>Vi(g)),typeIdToChildIndex:{...m.typeIdToChildIndex}};case Rt:let y=r;return{type:"dictionary",id:y.id,indices:oA(y.indices),dictionary:Yl(y.dictionary),isOrdered:y.isOrdered};default:throw new Error(`arrow type not supported: ${r.constructor.name}`)}}function Ro(r,t){if(typeof r=="object")switch(r.type){case"decimal":return new Ve(r.scale,r.precision,r.bitWidth);case"map":{let e=r.children.map(n=>sn(n,t));return new fe(e[0],r.keysSorted)}case"list":{let e=sn(r.children[0],t);return new Ct(e)}case"large-list":{let e=sn(r.children[0],t),n=Ka("LargeList");if(!n)throw new Error("LargeList requires an Apache Arrow runtime that exports the LargeList constructor");return new n(e)}case"fixed-size-list":{let e=sn(r.children[0],t);return new gt(r.listSize,e)}case"fixed-size-binary":return new Ge(r.byteWidth);case"struct":{let e=r.children.map(n=>sn(n,t));return new ut(e)}case"sparse-union":case"dense-union":{let e=r.children.map(n=>sn(n,t));return r.type==="dense-union"?new bn(r.typeIds,e):new us(r.typeIds,e)}case"dictionary":return new Rt(Ro(r.dictionary,t),cA(r.indices),r.id,r.isOrdered);default:throw new Error("array type not supported")}switch(r){case"null":return new Et;case"binary":return Bg("BinaryView",new ze,t);case"binary-view":return Ig("BinaryView");case"bool":return new le;case"int8":return new Ae;case"int16":return new Se;case"int32":return new Dt;case"int64":return new Qe;case"uint8":return new Be;case"uint16":return new Ie;case"uint32":return new qt;case"uint64":return new Dr;case"float16":return new Cr;case"float32":return new Xt;case"float64":return new _e;case"utf8":return Bg("Utf8View",new ce,t);case"utf8-view":return Ig("Utf8View");case"date-day":return new Qn;case"date-millisecond":return new ts;case"time-second":return new es;case"time-millisecond":return new rs;case"time-microsecond":return new ns;case"time-nanosecond":return new ss;case"timestamp-second":return new is;case"timestamp-millisecond":return new Xr;case"timestamp-microsecond":return new os;case"timestamp-nanosecond":return new as;case"interval-daytime":return new cs;case"interval-yearmonth":return new ls;default:throw new Error("array type not supported")}}function Ka(r){return zr[r]}function Sg(r,t){let e=Ka(t);if(e&&r instanceof e)return!0;let n=w;return!!(t==="BinaryView"?n.isBinaryView:n.isUtf8View)?.(r)}function iA(r,t){let e=Ka(t);return!!(e&&r instanceof e)}function Bg(r,t,e){let n=e?.viewTypes||"never";if(n==="never")return t;let s=Ka(r);if(s)return new s;if(n==="require")throw new Error(`${r} requires apache-arrow 21.2.0 or later; the installed runtime does not support it`);return t}function Ig(r){let t=Ka(r);if(!t)throw new Error(`${r} requires apache-arrow 21.2.0 or later; the installed runtime does not support it`);return new t}function oA(r){if(r instanceof Lt){let e=`${r.isSigned?"int":"uint"}${r.bitWidth}`;if(aA(e))return e}switch(r.constructor){case Ae:return"int8";case Se:return"int16";case Dt:return"int32";case Be:return"uint8";case Ie:return"uint16";case qt:return"uint32";default:throw new Error(`arrow dictionary index type not supported: ${r.constructor.name}`)}}function aA(r){return["int8","int16","int32","uint8","uint16","uint32"].includes(r)}function cA(r){switch(r){case"int8":return new Ae;case"int16":return new Se;case"int32":return new Dt;case"uint8":return new Be;case"uint16":return new Ie;case"uint32":return new qt;default:throw new Error(`schema dictionary index type not supported: ${r}`)}}var Ja=p(()=>{"use strict";nn()});function on(r){let t=r?.POSITION;if(!t||!("value"in t)||!t.value.length)return null;let e=1/0,n=1/0,s=1/0,i=-1/0,o=-1/0,a=-1/0,c=t.value,l=c.length;for(let u=0;u<l;u+=3){let f=c[u],h=c[u+1],m=c[u+2];e=f<e?f:e,n=h<n?h:n,s=m<s?m:s,i=f>i?f:i,o=h>o?h:o,a=m>a?m:a}return[[e,n,s],[i,o,a]]}var dd=p(()=>{"use strict"});function Tg(r){return r.type instanceof gt?r.type.listSize:1}function pd(r,t,e){let n=lA(r,t,e);return new A([n])}function lA(r,t,e){let n=uA(r,t,e),s=n.children[0].type,i=e==="float16"&&jn(r)?na(r):r,o={[Z.DATA]:i},a=new T(s,0,i.length,0,o);return new T(n,0,i.length/t,0,void 0,[a])}function uA(r,t,e){let n=e||Ag(r).type,s=Ro(n);return new gt(t,new S("value",s,!1))}var md=p(()=>{"use strict";Vs();nn();hd();Ja()});function Ee(r,t){switch(t){case"columnar-table":return fA(r);case"arrow-table":return hA(r);default:throw new Error(t)}}function fA(r){let t={},e=Dg(r);for(let[n,s]of Object.entries(r.attributes))t[n]=s.value;return{shape:"columnar-table",schema:r.schema,data:t,topology:r.topology,indices:e?r.indices:void 0}}function hA(r,t){return Zl(r.attributes,{schema:r.schema,topology:r.topology,mode:r.mode,boundingBox:r.header?.boundingBox,indices:Dg(r)?r.indices:void 0})}function Zl(r,t={}){let e=[],n={},s=pA(r);for(let c of s){let l=r[c],{value:u,size:f=1}=l,h=dA(u,f,l.componentType);if(n[c]=h,e.push(mA(t.schema,c,h,l.componentType)),c==="POSITION"&&t.indices?.value?.length){let m=ud.fields.find(y=>y.name==="indices");n.indices=gA(t.indices.value,h.length,m.type),e.push(m)}}let i=new j(e,bA(t)),o=n[s[0]]?.length===0?new st(i):new st(i,n);return{shape:"arrow-table",schema:No(o.schema),data:o,topology:t.topology||"point-list",indices:t.indices}}function dA(r,t,e){if(e==="float16"){let n=jn(r)?na(r):r;if(t===1){let s=new T(new Cr,0,n.length,0,{[Z.DATA]:n});return new A([s])}return pd(r,t,e)}return t===1?te(r):pd(r,t)}function pA(r){let t=Object.keys(r),e=Mg.filter(s=>s in r),n=t.filter(s=>!Mg.includes(s));return[...e,...n]}function Dg(r){return!!r.indices?.value?.length}function mA(r,t,e,n){if(t==="POSITION"&&yA(e)){let i=$l.fields[0],o=r?.fields.find(c=>c.name===t);if(!o?.metadata)return i;let a=new Map(i.metadata);for(let[c,l]of Object.entries(o.metadata))a.set(c,l);return new S(i.name,i.type,i.nullable,a)}let s=r?.fields.find(i=>i.name===t);if(n==="float16"){let i=new Map(Object.entries(s?.metadata||{}));return i.set("componentType","float16"),new S(t,e.type,!1,i)}if(s&&s.type.toString()!==e.type.toString()){let i=sn(s);return new S(t,e.type,i.nullable,i.metadata)}return s?sn(s):new S(t,e.type,!1)}function yA(r){return r.type instanceof gt&&r.type.listSize===3&&r.type.children[0].type instanceof Xt}function gA(r,t,e){let n=e,s=r instanceof Uint32Array?r:Uint32Array.from(r),i=new Int32Array(t+1);t>0&&i.fill(s.length,1);let o=new Uint8Array(Math.ceil(t/8));t>0&&(o[0]=1);let a=new T(n.children[0].type,0,s.length,0,{[Z.DATA]:s}),c=new T(n,0,t,Math.max(0,t-1),{[Z.OFFSET]:i,[Z.VALIDITY]:o},[a]);return new A([c])}function bA(r){let t={...r.schema?.metadata};return r.topology&&(t.topology||=r.topology),Number.isFinite(r.mode)&&(t.mode||=String(r.mode)),r.boundingBox&&(t.boundingBox||=JSON.stringify(r.boundingBox)),Wl(t)}var Mg,Cg=p(()=>{"use strict";Vs();Vs();nn();md();Ja();Mg=["POSITION"]});function ee(r){if(r.shape==="arrow-table")return wA(r);throw new Error(r.shape)}function wA(r){let t=r.data,e=No(t.schema),n=e.fields,s={},i=[];for(let u of n){let{name:f}=u;if(f==="indices")continue;let h=t.getChild(f),m=Tg(h),y=BA(h,m),g=vA(u.metadata),x=g.componentType==="float16"?IA(y):y,B=i.find(q=>q.data.length===h.data.length&&s[q.name].value.constructor===x.constructor&&q.data.every((M,b)=>Fg(M,h.data[b])));s[f]={value:B?s[B.name].value:x,size:m,...g},B||i.push({name:f,data:h.data})}SA(e);let o=e.metadata.topology,a=_A(e),c=LA(t),l=s.POSITION?.transform?.type==="quantization"?xA(e)||on(s):on(s);return{schema:e,attributes:s,topology:o,mode:a,indices:c,header:{vertexCount:t.numRows,boundingBox:l??void 0}}}function xA(r){let t=r.metadata?.boundingBox;if(!t)return null;try{let e=JSON.parse(t);if(Array.isArray(e)&&e.length===2&&e.every(n=>Array.isArray(n)&&n.length===3&&n.every(s=>typeof s=="number")))return e}catch{}return null}function vA(r={}){let t={};if(r.byteOffset!==void 0&&(t.byteOffset=Number(r.byteOffset)),r.byteStride!==void 0&&(t.byteStride=Number(r.byteStride)),r.normalized!==void 0&&(t.normalized=r.normalized==="true"),r.componentType==="float16"&&(t.componentType="float16"),r["loaders.gl.transform"])try{let e=JSON.parse(r["loaders.gl.transform"]);AA(e)&&(t.transform=e)}catch{}return t}function AA(r){if(!r||typeof r!="object"||!("type"in r))return!1;let t=r;return t.type==="octahedron"?Number.isInteger(t.bits)&&t.bits>=1&&t.bits<=30:t.type==="quantization"&&Number.isInteger(t.bits)&&t.bits>=1&&t.bits<=30&&Array.isArray(t.origin)&&t.origin.every(e=>typeof e=="number")&&typeof t.range=="number"}function SA(r){r.metadata||={},r.metadata.topology||="point-list",r.metadata.mode||="0"}function BA(r,t){if(!(r.type instanceof gt))return r.toArray();let n=r.data[0].children[0].values.constructor,s=new n(r.length*t),i=0;for(let o of r.data){let a=o.children[0],c=o.length*t,l=a.offset||o.offset*t,u=l+c<=a.values.length?l:0,f=a.values.subarray(u,u+c);s.set(f,i),i+=c}return s}function IA(r){let t=hc(r.length);for(let e=0;e<r.length;e++)dc(t,e,Hu(r,e));return t}function _A(r){let t=Number(r.metadata?.mode);return Number.isFinite(t)?t:0}function LA(r){let t=r.getChild("indices");if(!t?.isValid(0))return;let e=t.data[0],n=e.valueOffsets,s=n[e.offset],i=n[e.offset+1];return{value:e.children[0].values.subarray(s,i),size:1}}function Fg(r,t){let e=Object.values(t.buffers);return r.type.toString()===t.type.toString()&&r.offset===t.offset&&r.length===t.length&&r.nullCount===t.nullCount&&r.dictionary===t.dictionary&&Object.values(r.buffers).every((n,s)=>{let i=e[s];return n===i||!!(n&&i&&n.buffer===i.buffer&&n.byteOffset===i.byteOffset&&n.byteLength===i.byteLength)})&&r.children.length===t.children.length&&r.children.every((n,s)=>Fg(n,t.children[s]))}var Og=p(()=>{"use strict";Vs();nn();md();Ja();dd()});function Gi(r,t={}){return{fields:TA(r),metadata:t}}function Eg(r,t,e){let n=t.componentType||fd(t.value),s=e||Ug(t),i=t.size===1?n:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:n}]};return{name:r,type:i,nullable:!1,metadata:s}}function TA(r){let t=[];for(let e in r){let n=r[e];t.push(Eg(e,n))}return t}function Ug(r){let t={};return"byteOffset"in r&&(t.byteOffset=r.byteOffset.toString(10)),"byteStride"in r&&(t.byteStride=r.byteStride.toString(10)),"normalized"in r&&(t.normalized=r.normalized.toString()),r.componentType&&(t.componentType=r.componentType),r.transform&&(t["loaders.gl.transform"]=JSON.stringify(r.transform)),t}var Ng=p(()=>{"use strict";hd()});var or=p(()=>{"use strict";dd();Cg();Og();Ng()});var Rg,Pg=p(()=>{"use strict";Rg={name:"LAS",id:"las",module:"pointclouds",encoding:"binary",format:"las",extensions:["las","laz"],mimeTypes:["application/octet-stream"],text:!1,binary:!0,tests:["LASF"]}});function zg(r){return r?.las?.shape||kg}function Gg(r,t){if(t==="uint8norm"||!r.attributes.COLOR_0)return r;let e=r.attributes.COLOR_0,n=e.value instanceof Uint16Array?65535:255,s=t==="float16"?ti(e.value,n):sa(e.value,n),i={...r.attributes};for(let[o,a]of Object.entries(i))a.value===e.value&&(i[o]={...a,value:s,normalized:!1,...t==="float16"?{componentType:"float16"}:{}});return{...r,attributes:i}}var MA,kg,Vg,jg=p(()=>{"use strict";Vs();Pg();MA="5.0.0-beta.4",kg="arrow-table";Vg={...Rg,dataType:null,batchType:null,version:MA,worker:!1,options:{las:{shape:kg,fp64:!1,colorDepth:8,colorFormat:"uint8norm",columns:void 0,extraBytes:"raw",recoverMissingChunkTable:!1,compatibilityMode:"auto"}}}});function qg(r,t={}){let e={...t,copies:new WeakMap};return DA(r)?OA(r,e):CA(r)?$g(r,e):FA(r)?Wg(r,e):Xl(r,e)}function DA(r){return"batches"in r}function CA(r){return"schema"in r&&"data"in r&&!Array.isArray(r.data)}function FA(r){return"data"in r&&Array.isArray(r.data)}function OA(r,t){let e=r.batches.map(n=>$g(n,t));return new st(r.schema,e)}function $g(r,t){return new ct(r.schema,Xl(r.data,t))}function Xl(r,t){let e=r.children.map(i=>Xl(i,t)),n=r.dictionary?Wg(r.dictionary,t):void 0,s={[Z.OFFSET]:Hl(r.buffers[Z.OFFSET],t),[Z.DATA]:Hl(r.buffers[Z.DATA],t),[Z.VALIDITY]:Hl(r.buffers[Z.VALIDITY],t),[Z.TYPE]:Hl(r.buffers[Z.TYPE],t)};return new T(r.type,r.offset,r.length,r._nullCount,s,e,n)}function Wg(r,t){return new A(r.data.map(e=>Xl(e,t)))}function Hl(r,t){if(!EA(r)||t.copy==="none"||t.copy!=="all"&&r.byteOffset===0&&r.byteLength===r.buffer.byteLength)return r;let e=t.copies.get(r);return e||(e=r.slice(),t.copies.set(r,e)),e}function EA(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}var yd=p(()=>{"use strict";nn()});function UA(r,t){let e=qg(r,t);return{shape:"arrow-table",transport:"arrow-js",schema:No(e.schema),batches:e.batches.map(n=>kA(n))}}function NA(r){let t=_g(r.schema),e=r.batches.map(n=>new ct(t,bd(n.data)));return new st(t,e)}function re(r){if(!RA(r))throw new Error("Workers require Arrow table output");let{data:t,...e}=r;return{...structuredClone(e),data:UA(t,{copy:"all"})}}function Po(r){if(!PA(r))throw new Error("Workers require Arrow column transport");return{...r,data:NA(r.data)}}function RA(r){let t=r;return!!(t&&t.shape==="arrow-table"&&t.data&&typeof t.data=="object"&&"batches"in t.data)}function PA(r){let t=r;return!!(t&&t.shape==="arrow-table"&&t.data&&t.data.transport==="arrow-js"&&Array.isArray(t.data.batches))}function kA(r){return{data:gd(r.data)}}function gd(r){return{type:Yl(r.type),offset:r.offset,length:r.length,nullCount:r._nullCount,buffers:{[Z.OFFSET]:r.buffers[Z.OFFSET],[Z.DATA]:r.buffers[Z.DATA],[Z.VALIDITY]:r.buffers[Z.VALIDITY],[Z.TYPE]:r.buffers[Z.TYPE]},children:r.children.map(t=>gd(t)),dictionary:r.dictionary?zA(r.dictionary):void 0}}function zA(r){return{data:r.data.map(t=>gd(t))}}function bd(r){let t=r.children.map(n=>bd(n)),e=r.dictionary?VA(r.dictionary):void 0;return new T(Ro(r.type),r.offset,r.length,r.nullCount,r.buffers,t,e)}function VA(r){return new A(r.data.map(t=>bd(t)))}var Yg=p(()=>{"use strict";nn();Ja();yd()});var Gs=p(()=>{"use strict";Yg();yd()});function Zg(...r){return GA(r)}function GA(r){let t=r.map(i=>i instanceof ArrayBuffer?new Uint8Array(i):i),e=t.reduce((i,o)=>i+o.byteLength,0),n=new Uint8Array(e),s=0;for(let i of t)n.set(i,s),s+=i.byteLength;return n.buffer}var Hg=p(()=>{"use strict"});function jA(r){return ArrayBuffer.isView(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r)}var js,Xg=p(()=>{"use strict";js=class{offset=0;ended=!1;maxRewindBytes;chunks=[];scratch=new ArrayBuffer(8);checkpoints=[];constructor(t){this.maxRewindBytes=t?.maxRewindBytes||0}get arrayBuffers(){return this.chunks.map(t=>t.buffer)}write(t){this.chunks.push(jA(t))}end(){this.chunks=[],this.checkpoints=[],this.offset=0,this.ended=!0}hasAvailableBytes(t){return this.getAvailableByteLength()>=t}getAvailableByteLength(){let t=-this.offset;for(let e of this.chunks)t+=e.byteLength,t>0;return Math.max(0,t)}findBufferOffsets(t){let e=-this.offset,n=[];for(let s=0;s<this.chunks.length;s++){let i=this.chunks[s];if(e+i.byteLength<=0){e+=i.byteLength;continue}let o=e<=0?Math.abs(e):0,a;if(o+t<=i.byteLength)return a=o+t,n.push([s,[o,a]]),n;a=i.byteLength,n.push([s,[o,a]]),t-=i.byteLength-o,e+=i.byteLength}return null}getDataView(t){let e=this.findBufferOffsets(t);if(!e){if(this.ended)throw new Error("binary data exhausted");return null}let n;if(e.length===1){let[s,[i,o]]=e[0],a=this.chunks[s];n=new DataView(a.buffer,a.byteOffset+i,o-i)}else{let s=this.combineBufferOffsets(e);n=new DataView(s.buffer,s.byteOffset,s.byteLength)}return this.offset+=t,this.disposeBuffers(),n}readByte(){let t=this.findBufferOffsets(1);if(!t)throw new Error("binary data exhausted");let[e,[n]]=t[0],s=this.chunks[e][n];return this.offset++,this.disposeBuffers(),s}readUint16LE(){let t=this.readByte(),e=this.readByte();return t|e<<8}readUint32LE(){let t=this.readByte(),e=this.readByte(),n=this.readByte(),s=this.readByte();return(t|e<<8|n<<16|s<<24>>>0)>>>0}readInt32LE(){return this.readUint32LE()|0}readFloat64LE(){let t=this.getContiguousDataView(8);if(t)return t.getFloat64(0,!0);let e=new Uint8Array(this.scratch);return this.readInto(e,0,8),new DataView(this.scratch).getFloat64(0,!0)}readInto(t,e,n){let s=this.findBufferOffsets(n);if(!s)throw new Error("binary data exhausted");let i=e;for(let[o,[a,c]]of s){let l=this.chunks[o];t.set(l.subarray(a,c),i),i+=c-a}this.offset+=n,this.disposeBuffers()}readBytes(t){let e=this.findBufferOffsets(t);if(!e)throw new Error("binary data exhausted");let n;if(e.length===1){let[s,[i,o]]=e[0];n=this.chunks[s].subarray(i,o)}else n=this.combineBufferOffsets(e);return this.offset+=t,this.disposeBuffers(),n}skip(t){this.offset+=t}rewind(t){this.offset-=t}checkpoint(){let t={offset:this.offset};return this.checkpoints.push(t),t}restore(t){this.offset=t.offset,this.checkpoints.pop()}discardConsumed(){this.disposeBuffers()}_combineArrayBuffers(t){return this.combineBufferOffsets(t).buffer}getContiguousDataView(t){let e=this.findBufferOffsets(t);if(!e||e.length!==1)return null;let[n,[s,i]]=e[0],o=this.chunks[n],a=new DataView(o.buffer,o.byteOffset+s,i-s);return this.offset+=t,this.disposeBuffers(),a}disposeBuffers(){let t=this.checkpoints.length>0?Math.min(...this.checkpoints.map(e=>e.offset)):Number.POSITIVE_INFINITY;for(;this.chunks.length>0&&this.offset-this.maxRewindBytes>=this.chunks[0].byteLength&&t>=this.chunks[0].byteLength;){this.offset-=this.chunks[0].byteLength;for(let e of this.checkpoints)e.offset-=this.chunks[0].byteLength;t-=this.chunks[0].byteLength,this.chunks.shift()}}combineBufferOffsets(t){let e=0;for(let[,[i,o]]of t)e+=o-i;let n=new Uint8Array(e),s=0;for(let[i,[o,a]]of t){let c=this.chunks[i];n.set(c.subarray(o,a),s),s+=a-o}return n}}});async function*Kl(r,t={}){let e=new TextDecoder(void 0,t);for await(let n of r)yield typeof n=="string"?n:e.decode(n,{stream:!0})}async function*Jl(r){let t="";for await(let e of r){t+=e;let n;for(n=t.indexOf(`
|
|
27
27
|
`);n>=0;){let s=t.slice(0,n+1);t=t.slice(n+1),yield s,n=t.indexOf(`
|
|
28
|
-
`)}}t.length>0&&(yield t)}var Kg=p(()=>{"use strict"});async function wd(r,t){let e=qA(r);for(;;){let{done:n,value:s}=await e.next();if(n){e.return&&e.return();return}if(t(s))return}}async function xd(r){let t=[];for await(let e of r)t.push(Qg(e));return Zg(...t)}async function*Ql(r){for await(let t of r)yield Qg(t)}function Qg(r){if(r instanceof ArrayBuffer)return r;if(ArrayBuffer.isView(r)){let{buffer:t,byteOffset:e,byteLength:n}=r;return Jg(t,e,n)}return Jg(r)}function Jg(r,t=0,e=r.byteLength-t){let n=new Uint8Array(r,t,e),s=new Uint8Array(n.length);return s.set(n),s.buffer}function qA(r){if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r[Symbol.iterator]=="function"){let t=r[Symbol.iterator]();return $A(t)}return r}function $A(r){return{next(t){return Promise.resolve(r.next(t))},return(t){return typeof r.return=="function"?Promise.resolve(r.return(t)):Promise.resolve({done:!0,value:t})},throw(t){return typeof r.throw=="function"?Promise.resolve(r.throw(t)):Promise.reject(t)}}}var tb=p(()=>{"use strict";Hg()});function $d(r){return new Sd(r)}function Id(r){return{intensity:!!r.intensities,classification:!!r.classifications,color:!!(r.colors||r.rawColors),gpsTime:!!r.gpsTimes,nir:!!r.nir,scanAngle:!!r.scanAngles,userData:!!r.userData,pointSourceId:!!r.pointSourceIds,flags:!!(r.scannerChannels||r.scanDirectionFlags||r.edgeOfFlightLines||r.syntheticFlags||r.keyPointFlags||r.withheldFlags||r.overlapFlags),waveform:!!r.waveforms,extraBytes:!!r.extraBytes}}function cb(r){return(r.intensity?1:0)|(r.classification?2:0)|(r.color?4:0)|(r.gpsTime?8:0)|(r.nir?16:0)|(r.scanAngle?32:0)|(r.userData?64:0)|(r.pointSourceId?128:0)|(r.flags?256:0)|(r.waveform?512:0)|(r.extraBytes?1024:0)}function Gr(r,t){return new Bd(r,t)}function fu(r,t){let e=Gr(r,t),n=new Uint8Array(t.pointCount*t.pointDataRecordLength);return e.decodeInto(n,0,t.pointCount),n}function lb(r,t){if(!mu(t.pointDataRecordFormat))throw new it("Legacy LAZ chunk byte length is not self-describing");let e=Wo(r),n=$o(t),s=t.pointDataRecordLength,i=rc(t.pointDataRecordFormat,n),o=s+4,a=i*4;if(e.byteLength<o+a)throw new it;let c=new DataView(e.buffer,e.byteOffset,e.byteLength),l=o+a;for(let u=0;u<i;u++)l+=c.getUint32(o+u*4,!0);if(e.byteLength<l)throw new it;return l}function Wd(r,t){let e=new eu(Wo(r)),n=new ne(e),s=It(32,2);n.readInitBytes();let i=[],o=0,a=0,c=t.pointCount;for(let l=0;l<t.chunkCount;l++){let u;t.variable?(o=s.decompress(n,o,0)>>>0,u=o):(u=Math.min(t.chunkSize,c),c-=u),a=s.decompress(n,a,1)>>>0,i.push({pointCount:u,byteLength:a})}return i}function hu(r){if(!mu(r.pointDataRecordFormat))return r.pointDataRecordLength+4;let t=$o(r);return r.pointDataRecordLength+4+rc(r.pointDataRecordFormat,t)*4}function du(r,t){if(!mu(t.pointDataRecordFormat))throw new it("Legacy LAZ chunk byte length is not self-describing");let e=_d(Wo(r),t);if(!e)throw new it("LAZ chunk decoder needs the complete layered size header");return e.byteLength}function _d(r,t){let e=$o(t),n=t.pointDataRecordLength+4,s=rc(t.pointDataRecordFormat,e),i=s*4;if(r.byteLength<n+i)return null;let o=new DataView(r.buffer,r.byteOffset,r.byteLength),a=n+i,c=[];for(let u=0;u<s;u++){let f=o.getUint32(n+u*4,!0);a+=f,c.push(f)}let l=n+i;return{byteLength:a,layerByteLengths:c,getByteLength:u=>l+c.slice(0,u).reduce((f,h)=>f+h,0)}}function WA(r,t){if(t.extraBytes)return rc(r.pointDataRecordFormat,$o(r));let e=2;return t.classifications&&(e=3),(t.scannerChannels||t.scanDirectionFlags||t.edgeOfFlightLines||t.syntheticFlags||t.keyPointFlags||t.withheldFlags||t.overlapFlags)&&(e=4),t.intensities&&(e=5),t.scanAngles&&(e=6),t.userData&&(e=7),t.pointSourceIds&&(e=8),t.gpsTimes&&(e=9),(t.colors||t.rawColors)&&(e=10),t.nir&&(e=11),t.waveforms&&(e=r.pointDataRecordFormat===9?10:12),Math.min(e,rc(r.pointDataRecordFormat,$o(r)))}function Ad(r){let t=r.byteItemVersion===1?4:2;return Math.max(tS,r.pointDataRecordLength*t+512)}function nb(r){return r[0]<r[1]?r[1]<r[2]?r[1]:Math.max(r[0],r[2]):r[0]<r[2]?r[0]:Math.max(r[1],r[2])}function rS(r,t,e,n){let s=$o(t);for(let i of[t.point10ItemVersion,t.gpsTime11ItemVersion,t.rgb12ItemVersion,t.byteItemVersion])if(i!==void 0&&i!==1&&i!==2)throw new Error(`Unsupported legacy LASzip item version ${i}`);switch(t.pointDataRecordFormat){case 0:return new Od(r,s,t);case 1:return new Ed(r,s,t);case 2:return new Ud(r,s,t);case 3:return new Nd(r,s,t,e==="point-data"?n:null);case 4:return new Rd(r,s,t);case 5:return new Pd(r,s,t);case 6:return new kd(r,s,e,t,n);case 7:return new zd(r,s,e,t,n);case 8:return new Vd(r,s,e,t,n);case 9:return new Gd(r,s,e,t,n);case 10:return new jd(r,s,e,t,n);default:throw new Error(`TypeScript LAZ decoder does not support point format ${t.pointDataRecordFormat}`)}}function nS(r){return r<=5||r>=6&&r<=10}function It(r,t){let e=new Td(r,t);return e.init(),e}function ge(r,t){return Array.from({length:r},()=>new jt(t))}function $o(r){let t=sS(r.pointDataRecordFormat),e=r.pointDataRecordLength-t;if(e<0)throw new Error(`Invalid point record length ${r.pointDataRecordLength}`);return e}function sS(r){switch(r){case 0:return 20;case 1:return 28;case 2:return 26;case 3:return 34;case 4:return 57;case 5:return 63;case 6:return 30;case 7:return 36;case 8:return 38;case 9:return 59;case 10:return 67;default:throw new Error(`TypeScript LAZ decoder does not support point format ${r}`)}}function mu(r){return r>=6&&r<=10}function rc(r,t){switch(r){case 6:return 9+t;case 7:return 10+t;case 8:return 11+t;case 9:return 10+t;case 10:return 12+t;default:throw new Error(`TypeScript LAZ decoder does not support point format ${r}`)}}function iS(){return{x:0,y:0,z:0,intensity:0,returns:0,flags:0,classification:0,userData:0,scanAngle:0,pointSourceId:0,gpsTime:0}}function sb(){return{x:0,y:0,z:0,intensity:0,bitByte:0,classification:0,scanAngleRank:0,userData:0,pointSourceId:0}}function oS(r,t){r.x=zo(t),r.y=zo(t),r.z=zo(t),r.intensity=Ys(t),r.bitByte=t.getByte(),r.classification=t.getByte(),r.scanAngleRank=qd(t.getByte()),r.userData=t.getByte(),r.pointSourceId=Ys(t)}function aS(r,t){r.x=t.x,r.y=t.y,r.z=t.z,r.intensity=t.intensity,r.bitByte=t.bitByte,r.classification=t.classification,r.scanAngleRank=t.scanAngleRank,r.userData=t.userData,r.pointSourceId=t.pointSourceId}function cS(r,t,e){Ue(r.x,t,e),Ue(r.y,t,e+4),Ue(r.z,t,e+8),ar(r.intensity,t,e+12),t[e+14]=r.bitByte,t[e+15]=r.classification,t[e+16]=r.scanAngleRank&255,t[e+17]=r.userData,ar(r.pointSourceId,t,e+18)}function Rn(r,t,e,n,s,i,o){let a=o*3;t[a]=r.x*s[0]+i[0],t[a+1]=r.y*s[1]+i[1],t[a+2]=r.z*s[2]+i[2],e&&(e[o]=r.intensity),n&&(n[o]=r.classification&31)}function Wi(r,t,e){let n=r.classification>>5;t.syntheticFlags&&(t.syntheticFlags[e]=n&1),t.keyPointFlags&&(t.keyPointFlags[e]=n>>1&1),t.withheldFlags&&(t.withheldFlags[e]=n>>2&1),t.overlapFlags&&(t.overlapFlags[e]=0),t.scanAngles&&(t.scanAngles[e]=r.scanAngleRank),t.userData&&(t.userData[e]=r.userData),t.pointSourceIds&&(t.pointSourceIds[e]=r.pointSourceId),t.returnNumbers&&(t.returnNumbers[e]=r.bitByte&7),t.numberOfReturns&&(t.numberOfReturns[e]=r.bitByte>>3&7),t.scannerChannels&&(t.scannerChannels[e]=0),t.scanDirectionFlags&&(t.scanDirectionFlags[e]=r.bitByte>>6&1),t.edgeOfFlightLines&&(t.edgeOfFlightLines[e]=r.bitByte>>7&1)}function ib(r){return r.bitByte&7}function ob(r){return r.bitByte>>3&7}function lS(r){return r.bitByte>>6&1}function ab(r,t){r.x=t.x,r.y=t.y,r.z=t.z,r.intensity=t.intensity,r.returns=t.returns,r.flags=t.flags,r.classification=t.classification,r.userData=t.userData,r.scanAngle=t.scanAngle,r.pointSourceId=t.pointSourceId,r.gpsTime=t.gpsTime}function uS(r,t,e){r.x=Vr(t,e),r.y=Vr(t,e+4),r.z=Vr(t,e+8),r.intensity=au(t,e+12),r.returns=t[e+14],r.flags=t[e+15],r.classification=t[e+16],r.userData=t[e+17],r.scanAngle=wS(t,e+18),r.pointSourceId=au(t,e+20),r.gpsTime=vS(t,e+22)}function fS(r,t){r.x=zo(t),r.y=zo(t),r.z=zo(t),r.intensity=Ys(t),r.returns=t.getByte(),r.flags=t.getByte(),r.classification=t.getByte(),r.userData=t.getByte(),r.scanAngle=Zd(Ys(t)),r.pointSourceId=Ys(t),r.gpsTime=db(t)}function hS(r,t,e){Ue(r.x,t,e),Ue(r.y,t,e+4),Ue(r.z,t,e+8),ar(r.intensity,t,e+12),t[e+14]=r.returns,t[e+15]=r.flags,t[e+16]=r.classification,t[e+17]=r.userData,xS(r.scanAngle,t,e+18),ar(r.pointSourceId,t,e+20),pb(r.gpsTime,t,e+22)}function nc(r,t,e){Ws(r,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Yi(r,t,e),Zi(r,t,e)}function Ws(r,t,e,n,s,i,o){let a=o*3;t[a]=r.x*s[0]+i[0],t[a+1]=r.y*s[1]+i[1],t[a+2]=r.z*s[2]+i[2],e&&(e[o]=r.intensity),n&&(n[o]=r.classification)}function Yi(r,t,e){t.gpsTimes&&(t.gpsTimes[e]=r.gpsTime)}function Zi(r,t,e){t.scanAngles&&(t.scanAngles[e]=r.scanAngle),t.userData&&(t.userData[e]=r.userData),t.pointSourceIds&&(t.pointSourceIds[e]=r.pointSourceId),t.returnNumbers&&(t.returnNumbers[e]=r.returns&15),t.numberOfReturns&&(t.numberOfReturns[e]=r.returns>>4),t.scannerChannels&&(t.scannerChannels[e]=r.flags>>4&3),t.scanDirectionFlags&&(t.scanDirectionFlags[e]=r.flags>>6&1),t.edgeOfFlightLines&&(t.edgeOfFlightLines[e]=r.flags>>7&1),t.syntheticFlags&&(t.syntheticFlags[e]=r.flags&1),t.keyPointFlags&&(t.keyPointFlags[e]=r.flags>>1&1),t.withheldFlags&&(t.withheldFlags[e]=r.flags>>2&1),t.overlapFlags&&(t.overlapFlags[e]=r.flags>>3&1)}function ou(r,t,e){t.nir&&(t.nir[e]=r)}function Hi(r,t,e,n,s){if(n.colors){let o=s*4;n.colors[o]=r&255,n.colors[o+1]=t&255,n.colors[o+2]=e&255,n.colors[o+3]=255;return}if(!n.rawColors)return;let i=s*3;n.rawColors[i]=r,n.rawColors[i+1]=t,n.rawColors[i+2]=e}function dS(r){return r.flags>>4&3}function pS(r,t){r.flags=(t&3)<<4|r.flags&-49}function mS(r,t){r.flags=t&15|r.flags&240}function yS(r,t){r.flags=(t&1)<<6|r.flags&191}function gS(r,t){r.flags=(t&1)<<7|r.flags&127}function bS(r){return r.flags&15|(r.flags>>6&1)<<4|(r.flags>>7&1)<<5}function au(r,t){return r[t]|r[t+1]<<8}function Ys(r){let t=r.getByte(),e=r.getByte();return t|e<<8}function ar(r,t,e){t[e]=r&255,t[e+1]=r>>8&255}function wS(r,t){return Zd(au(r,t))}function xS(r,t,e){ar(r,t,e)}function cu(r,t){return(r[t]|r[t+1]<<8|r[t+2]<<16|r[t+3]<<24>>>0)>>>0}function lu(r,t,e){Ue(r,t,e)}function fb(r,t){let e=cu(r,t),n=cu(r,t+4);return BigInt(n)<<32n|BigInt(e)}function hb(r,t,e){lu(Number(r&0xffffffffn),t,e),lu(Number(r>>32n&0xffffffffn),t,e+4)}function Vr(r,t){return r[t]|r[t+1]<<8|r[t+2]<<16|r[t+3]<<24}function zo(r){let t=r.getByte(),e=r.getByte(),n=r.getByte(),s=r.getByte();return t|e<<8|n<<16|s<<24}function Ue(r,t,e){t[e]=r&255,t[e+1]=r>>8&255,t[e+2]=r>>16&255,t[e+3]=r>>24&255}function vS(r,t){for(let e=0;e<8;e++)Yd[e]=r[t+e];return ji.getFloat64(0,!0)}function db(r){for(let t=0;t<8;t++)Yd[t]=r.getByte();return ji.getFloat64(0,!0)}function pb(r,t,e){ji.setFloat64(0,r,!0);for(let n=0;n<8;n++)t[e+n]=Yd[n]}function $s(r){return r<=0?0:r>=255?255:r}function Zd(r){let t=r&65535;return t&32768?t-65536:t}function qd(r){let t=r&255;return t&128?t-256:t}function cn(r){return r|0}function uu(r){return ji.setFloat64(0,r,!0),ji.getBigUint64(0,!0)}function Vo(r){return ji.setBigUint64(0,r,!0),ji.getFloat64(0,!0)}function qs(r,t){let e=BigInt.asIntN(64,BigInt.asIntN(64,uu(r))+BigInt(t));return Vo(BigInt.asUintN(64,e))}function Wo(r){return r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function AS(r){let t=r.reduce((s,i)=>s+i.byteLength,0),e=new Uint8Array(t),n=0;for(let s of r)e.set(s,n),n+=s.byteLength;return e}var it,Sd,Bd,ko,YA,pu,ZA,HA,Qa,XA,eb,KA,JA,an,Go,tu,QA,vd,ub,Yd,ji,tS,rb,eS,eu,jt,Ld,ne,Td,jo,Zs,tc,Hs,Nt,Md,qi,Dd,ec,Cd,ru,nu,su,Fd,$i,Od,qo,Ed,Ud,Nd,iu,Rd,Pd,kd,zd,Vd,Gd,jd,mb=p(()=>{"use strict";it=class extends Error{constructor(t="LAZ chunk decoder needs more compressed data"){super(t),this.name="NeedsMoreData"}},Sd=class{metadata;chunks=[];closed=!1;compressed=null;cursor=null;fedByteLength=0;requiredByteLength=null;progressiveRequiredByteLength=null;progressiveSelectionKey=null;constructor(t){this.metadata=t}feed(t){if(this.closed)throw new Error("Cannot feed a closed LAZ chunk decoder");let e=Wo(t);this.chunks.push(e),this.compressed=null,this.fedByteLength+=e.byteLength}close(){this.closed=!0}get remainingPointCount(){return this.cursor?.remainingPointCount??this.metadata.pointCount}decode(){if(!this.closed)throw new it("LAZ chunk decoder input is not closed");return this.decodeAvailable()}readBatch(t){if(!this.cursor){if(!this.hasCompleteChunk())return null;let i=this.getCompressedAvailable(),o=this.requiredByteLength??i.byteLength;this.cursor=Gr(i.subarray(0,o),this.metadata)}if(this.cursor.remainingPointCount<=0)return null;let e=this.metadata.pointDataRecordLength,n=Math.min(t,this.cursor.remainingPointCount),s=new Uint8Array(n*e);return this.cursor.decodeInto(s,0,n),s}readPositionDataBatch(t,e){if(t.colors||t.rawColors||t.nir)throw new Error("Position-only LAZ batches cannot request color or NIR output");return this.readPointDataBatch(t,e)}readPointDataBatch(t,e){let n=this.metadata.pointDataRecordFormat;if(n<6||n>10)throw new Error("Progressive LAZ point-data batches require point formats 6-10");let s=n===7||n===8||n===10;if((t.colors||t.rawColors)&&!s)throw new Error(`Point format ${n} does not contain RGB data`);if(t.nir&&n!==8&&n!==10)throw new Error("NIR output requires point format 8 or 10");if(t.waveforms&&n!==9&&n!==10)throw new Error("Waveform output requires point format 9 or 10");if(!this.cursor){let o=this.getProgressivePointData(t);if(!o)return null;this.cursor=Gr(o,this.metadata)}if(this.cursor.remainingPointCount<=0)return 0;let i=Math.min(e,this.cursor.remainingPointCount);return this.cursor.decodeIntoPointData(t,i)}hasCompleteChunk(){if(!mu(this.metadata.pointDataRecordFormat))return this.closed;if(this.requiredByteLength!==null)return this.fedByteLength>=this.requiredByteLength;if(this.fedByteLength<hu(this.metadata))return!1;try{let t=this.getCompressedAvailable();return this.requiredByteLength=lb(t,this.metadata),this.requiredByteLength<=this.fedByteLength}catch(t){if(t instanceof it)return!1;throw t}}decodeAvailable(){let t=this.getCompressedAvailable(),e=this.requiredByteLength??t.byteLength;return fu(t.subarray(0,e),this.metadata)}getCompressedAvailable(){return this.compressed||=AS(this.chunks),this.compressed}getProgressivePointData(t){let e=cb(Id(t));if(this.progressiveSelectionKey!==e&&(this.progressiveRequiredByteLength=null,this.progressiveSelectionKey=e),this.progressiveRequiredByteLength===null){let o=this.getCompressedAvailable(),a=_d(o,this.metadata);if(!a)return null;let c=WA(this.metadata,t);this.progressiveRequiredByteLength=a.getByteLength(c)}if(this.fedByteLength<this.progressiveRequiredByteLength)return null;let n=this.getCompressedAvailable(),s=_d(n,this.metadata),i=new Uint8Array(s.byteLength);return i.set(n.subarray(0,Math.min(n.byteLength,s.byteLength))),i}};Bd=class{metadata;stream;decoder=null;pointIndex=0;outputMode=null;pointDataSelectionKey=null;constructor(t,e){this.metadata=e,this.stream=new eu(Wo(t))}feed(t){if(this.metadata.pointDataRecordFormat>5)throw new Error("Only legacy PDRF 0-5 LAZ cursors accept additional compressed input");this.stream.append(Wo(t))}discardConsumedInput(){if(this.metadata.pointDataRecordFormat>5)throw new Error("Only legacy PDRF 0-5 LAZ cursors can discard consumed input");this.stream.discardConsumedInput()}get remainingPointCount(){return this.metadata.pointCount-this.pointIndex}get compressedByteOffset(){return this.stream.byteOffset}get requiredInputByteLength(){if(this.metadata.pointDataRecordFormat>5)return this.stream.byteOffset;let t=this.pointIndex===0?this.metadata.pointDataRecordLength+4:Ad(this.metadata);return this.stream.byteOffset+t}decodeInto(t,e,n){let s=Math.min(n,this.remainingPointCount),i=this.selectOutputMode("raw",s);if(!i)return 0;let o=e;for(let a=0;a<s;a++)o=i.decompress(t,o);return this.pointIndex+=s,s}decodeAvailableInto(t,e,n,s=!1){if(this.metadata.pointDataRecordFormat>5)throw new Error("Available-point decoding is limited to legacy PDRF 0-5 LAZ chunks");let i=Math.min(n,this.remainingPointCount);if(i===0)return 0;let o=this.selectOutputMode("raw",i),a=0,c=e;for(;a<i;){let l=this.pointIndex===0?this.metadata.pointDataRecordLength+4:Ad(this.metadata);if(!s&&this.stream.availableByteLength<l)break;try{c=o.decompress(t,c)}catch(u){throw u instanceof it&&!s?new Error(`Legacy LAZ point exceeded the ${l}-byte streaming lookahead`):u}a++,this.pointIndex++}return a}decodeAvailableIntoPointData(t,e,n=!1){if(this.metadata.pointDataRecordFormat>5)throw new Error("Available point-data decoding is limited to legacy PDRF 0-5 LAZ chunks");let s=Math.min(e,this.remainingPointCount);if(s===0)return 0;let i=Id(t),o=this.selectOutputMode("point-data",s,i),a=0,c=t.pointOffset;for(;a<s;){let l=this.pointIndex===0?this.metadata.pointDataRecordLength+4:Ad(this.metadata);if(!n&&this.stream.availableByteLength<l)break;try{t.pointOffset=c+a,o.decompressPointData?o.decompressPointData(t,t.pointOffset):o.decompressPointDataBatch(t,1)}catch(u){throw t.pointOffset=c,u instanceof it&&!n?new Error(`Legacy LAZ point exceeded the ${l}-byte streaming lookahead`):u}a++,this.pointIndex++}return t.pointOffset=c,a}decodeIntoPointData(t,e){let n=Math.min(e,this.remainingPointCount);if(n>0&&!nS(this.metadata.pointDataRecordFormat))throw new Error(`TypeScript LAZ decoder does not support direct point-data output for point format ${this.metadata.pointDataRecordFormat}`);let s=Id(t),i=this.selectOutputMode("point-data",n,s);if(!i)return 0;if(i.decompressPointDataBatch)i.decompressPointDataBatch(t,n);else for(let o=0;o<n;o++)i.decompressPointData(t,t.pointOffset+o);return this.pointIndex+=n,n}selectOutputMode(t,e,n=null){if(e===0)return null;if(this.outputMode&&this.outputMode!==t)throw new Error("Cannot mix raw and point-data decoding in one LAZ chunk cursor");if(t==="point-data"){let s=cb(n);if(this.pointDataSelectionKey!==null&&this.pointDataSelectionKey!==s)throw new Error("Cannot change selected point-data fields in one LAZ chunk cursor");this.pointDataSelectionKey=s}return this.outputMode=t,this.decoder||=rS(this.stream,this.metadata,t,n),this.decoder}};ko=16777216,YA=4294967295,pu=13,ZA=1<<pu,HA=2**(31-pu),Qa=15,XA=1<<Qa,eb=2**(31-Qa),KA=[[0,1,2,3,4,5,3,4,4,5,5,5,5,5,5,5],[1,0,1,3,3,3,3,3,3,3,3,3,3,3,3,3],[2,1,2,4,4,4,4,4,4,4,4,3,3,3,3,3],[3,3,4,5,4,4,4,4,4,4,4,4,4,4,4,4],[4,3,4,4,5,4,4,4,4,4,4,4,4,4,4,4],[5,3,4,4,4,5,4,4,4,4,4,4,4,4,4,4],[3,3,4,4,4,4,5,4,4,4,4,4,4,4,4,4],[4,3,4,4,4,4,4,5,4,4,4,4,4,4,4,4],[4,3,4,4,4,4,4,4,5,4,4,4,4,4,4,4],[5,3,4,4,4,4,4,4,4,5,4,4,4,4,4,4],[5,3,4,4,4,4,4,4,4,4,5,4,4,4,4,4],[5,3,3,4,4,4,4,4,4,4,4,5,5,4,4,4],[5,3,3,4,4,4,4,4,4,4,4,5,5,5,4,4],[5,3,3,4,4,4,4,4,4,4,4,4,5,5,5,4],[5,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5],[5,3,3,4,4,4,4,4,4,4,4,4,4,4,5,5]],JA=[[0,1,2,3,4,5,6,7,7,7,7,7,7,7,7,7],[1,0,1,2,3,4,5,6,7,7,7,7,7,7,7,7],[2,1,0,1,2,3,4,5,6,7,7,7,7,7,7,7],[3,2,1,0,1,2,3,4,5,6,7,7,7,7,7,7],[4,3,2,1,0,1,2,3,4,5,6,7,7,7,7,7],[5,4,3,2,1,0,1,2,3,4,5,6,7,7,7,7],[6,5,4,3,2,1,0,1,2,3,4,5,6,7,7,7],[7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,7],[7,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7],[7,7,7,6,5,4,3,2,1,0,1,2,3,4,5,6],[7,7,7,7,6,5,4,3,2,1,0,1,2,3,4,5],[7,7,7,7,7,6,5,4,3,2,1,0,1,2,3,4],[7,7,7,7,7,7,6,5,4,3,2,1,0,1,2,3],[7,7,7,7,7,7,7,6,5,4,3,2,1,0,1,2],[7,7,7,7,7,7,7,7,6,5,4,3,2,1,0,1],[7,7,7,7,7,7,7,7,7,6,5,4,3,2,1,0]],an=500,Go=-10,tu=511,QA=an-Go+1,vd=an-Go+2,ub=new ArrayBuffer(8),Yd=new Uint8Array(ub),ji=new DataView(ub),tS=16*1024;rb=[[15,14,13,12,11,10,9,8],[14,0,1,3,6,10,10,9],[13,1,2,4,7,11,11,10],[12,3,4,5,8,12,12,11],[11,6,7,8,9,13,13,12],[10,10,11,12,13,14,14,13],[9,10,11,12,13,14,15,14],[8,9,10,11,12,13,14,15]],eS=[[0,1,2,3,4,5,6,7],[1,0,1,2,3,4,5,6],[2,1,0,1,2,3,4,5],[3,2,1,0,1,2,3,4],[4,3,2,1,0,1,2,3],[5,4,3,2,1,0,1,2],[6,5,4,3,2,1,0,1],[7,6,5,4,3,2,1,0]],eu=class{bytes;length;offset=0;discardedByteLength=0;constructor(t){this.bytes=t,this.length=t.byteLength}get byteOffset(){return this.discardedByteLength+this.offset}get availableByteLength(){return this.length-this.offset}get data(){return this.length===this.bytes.byteLength?this.bytes:this.bytes.subarray(0,this.length)}append(t){if(t.byteLength===0)return;let e=this.length+t.byteLength;if(e>this.bytes.byteLength){let n=Math.max(e,Math.max(64,this.bytes.byteLength*2)),s=new Uint8Array(n);s.set(this.bytes.subarray(0,this.length)),this.bytes=s}this.bytes.set(t,this.length),this.length=e}discardConsumedInput(){this.offset!==0&&(this.bytes=this.bytes.slice(this.offset,this.length),this.discardedByteLength+=this.offset,this.length-=this.offset,this.offset=0)}getByte(){if(this.offset>=this.length)throw new it;return this.bytes[this.offset++]}getBytes(t,e,n){if(this.offset+n>this.length)throw new it;t.set(this.bytes.subarray(this.offset,this.offset+n),e),this.offset+=n}consume(t){if(this.offset+t>this.length)throw new it;let e=this.offset;return this.offset+=t,e}getUint32(){let t=this.getByte(),e=this.getByte(),n=this.getByte(),s=this.getByte();return(t|e<<8|n<<16|s<<24>>>0)>>>0}},jt=class{symbols;distribution;symbolCount;decoderTable;totalCount=0;updateCycle;symbolsUntilUpdate;lastSymbol;tableSize=0;tableShift=0;constructor(t){if(t<2||t>2048)throw new Error(`Invalid arithmetic model symbol count ${t}`);if(this.symbols=t,this.lastSymbol=t-1,t>16){let e=3;for(;t>1<<e+2;)e++;this.tableSize=1<<e,this.tableShift=Qa-e,this.decoderTable=new Uint32Array(this.tableSize+2)}else this.decoderTable=null;this.distribution=new Uint32Array(t),this.symbolCount=new Uint32Array(t),this.symbolCount.fill(1),this.updateCycle=t,this.symbolsUntilUpdate=t,this.update(),this.symbolsUntilUpdate=this.updateCycle=t+6>>1}update(){if(this.totalCount+=this.updateCycle,this.totalCount>XA){this.totalCount=0;for(let i=0;i<this.symbols;i++)this.symbolCount[i]=this.symbolCount[i]+1>>1,this.totalCount+=this.symbolCount[i]}let t=0,e=0,n=2147483648/this.totalCount|0;if(this.decoderTable){for(let i=0;i<this.symbols;i++){this.distribution[i]=n*t/eb|0,t+=this.symbolCount[i];let o=this.distribution[i]>>this.tableShift;for(;e<o;)this.decoderTable[++e]=i-1}for(this.decoderTable[0]=0;e<=this.tableSize;)this.decoderTable[++e]=this.symbols-1}else for(let i=0;i<this.symbols;i++)this.distribution[i]=n*t/eb|0,t+=this.symbolCount[i];this.updateCycle=5*this.updateCycle>>2;let s=this.symbols+6<<3;this.updateCycle>s&&(this.updateCycle=s),this.symbolsUntilUpdate=this.updateCycle}},Ld=class{updateCycle=4;bitsUntilUpdate=4;bit0Prob=1<<pu-1;bit0Count=1;bitCount=2;update(){this.bitCount+=this.updateCycle,this.bitCount>ZA&&(this.bitCount=this.bitCount+1>>1,this.bit0Count=this.bit0Count+1>>1,this.bit0Count===this.bitCount&&this.bitCount++);let t=2147483648/this.bitCount|0;this.bit0Prob=this.bit0Count*t/HA|0,this.updateCycle=5*this.updateCycle>>2,this.updateCycle>64&&(this.updateCycle=64),this.bitsUntilUpdate=this.updateCycle}},ne=class{input;inputBytes=null;inputOffset=0;inputEnd=0;value=0;length=YA;valid=!1;constructor(t=null){this.input=t}initStream(t,e){e?(this.inputBytes=t.data,this.inputOffset=t.consume(e),this.inputEnd=this.inputOffset+e,this.input=null,this.readInitBytes(),this.valid=!0):this.valid=!1}readInitBytes(){if(this.inputBytes){let e=this.inputOffset;if(e+4>this.inputEnd)throw new it;this.value=(this.inputBytes[e]<<24>>>0|this.inputBytes[e+1]<<16|this.inputBytes[e+2]<<8|this.inputBytes[e+3])>>>0,this.inputOffset=e+4;return}let t=this.input;this.value=(t.getByte()<<24>>>0|t.getByte()<<16|t.getByte()<<8|t.getByte())>>>0}decodeBit(t){let e=this.value,n=this.length,s=t.bit0Prob*(n>>>pu),i=e>=s?1:0;return i===0?(this.length=s>>>0,t.bit0Count++):(this.value=e-s>>>0,this.length=n-s>>>0),this.length<ko&&this.renormalize(),--t.bitsUntilUpdate===0&&t.update(),i}decodeSymbol(t){let e,n,s=this.length,i=s,o=this.value,a=t.distribution,c=t.decoderTable;if(c){s>>>=Qa;let l=o/s|0,u=l>>t.tableShift;e=c[u];let f=c[u+1]+1;for(;f>e+1;){let h=e+f>>1;a[h]>l?f=h:e=h}n=a[e]*s,e!==t.lastSymbol&&(i=a[e+1]*s)}else{n=0,e=0,s>>>=Qa;let l=t.symbols,u=l>>1;do{let f=s*a[u];f>o?(l=u,i=f):(e=u,n=f),u=e+l>>1}while(u!==e)}return this.value=o-n>>>0,this.length=i-n>>>0,this.length<ko&&this.renormalize(),t.symbolCount[e]++,--t.symbolsUntilUpdate===0&&t.update(),e}readBits(t){if(t>19){let i=this.readShort();return(this.readBits(t-16)<<16|i)>>>0}let e=this.length>>>t,n=this.value,s=n/e|0;return this.value=n-e*s>>>0,this.length=e>>>0,e<ko&&this.renormalize(),s>>>0}readShort(){let t=this.length>>>16,e=this.value,n=e/t|0;return this.value=e-t*n>>>0,this.length=t>>>0,t<ko&&this.renormalize(),n&65535}readInt(){let t=this.readShort();return(this.readShort()<<16|t)>>>0}readUint64(){let t=this.readInt(),e=this.readInt();return BigInt(e)<<32n|BigInt(t)}renormalize(){let t=this.value,e=this.length;if(this.inputBytes){let n=this.inputBytes,s=this.inputEnd,i=this.inputOffset;do{if(i>=s)throw new it;t=(t<<8|n[i++])>>>0,e=e<<8>>>0}while(e<ko);this.inputOffset=i}else{let n=this.input;do t=(t<<8|n.getByte())>>>0,e=e<<8>>>0;while(e<ko)}this.value=t,this.length=e}},Td=class{contexts;bitsHigh;corrBits;corrRange;corrMin;mBits=[];mCorrector0=new Ld;mCorrector=[];k=0;constructor(t=16,e=1,n=8,s=0){if(this.contexts=e,this.bitsHigh=n,s){for(this.corrBits=0,this.corrRange=s;s;)s>>=1,this.corrBits++;this.corrRange===1<<this.corrBits-1&&this.corrBits--,this.corrMin=-(this.corrRange/2)}else t&&t<32?(this.corrBits=t,this.corrRange=1<<t,this.corrMin=-(this.corrRange/2)):(this.corrBits=32,this.corrRange=0,this.corrMin=-2147483648)}init(){if(!this.mBits.length){for(let t=0;t<this.contexts;t++)this.mBits.push(new jt(this.corrBits+1));for(let t=1;t<=this.corrBits;t++){let e=t<=this.bitsHigh?1<<t:1<<this.bitsHigh;this.mCorrector.push(new jt(e))}}}decompress(t,e,n){let s=t.decodeSymbol(this.mBits[n]);this.k=s;let i;if(s)if(s<32){let a=this.bitsHigh,c=this.mCorrector[s-1];if(s<=a)i=t.decodeSymbol(c);else{let l=s-a;i=t.decodeSymbol(c),i=i<<l|t.readBits(l)}i>=1<<s-1?i+=1:i-=(1<<s)-1}else i=this.corrMin;else i=t.decodeBit(this.mCorrector0);let o=cn(e+i);return this.corrRange===0||(o<0?o=cn(o+this.corrRange):o>=this.corrRange&&(o=cn(o-this.corrRange))),o}},jo=class{value0=0;value1=0;value2=0;value3=0;value4=0;high=!0;add(t){this.high?t<this.value2?(this.value4=this.value3,this.value3=this.value2,t<this.value0?(this.value2=this.value1,this.value1=this.value0,this.value0=t):t<this.value1?(this.value2=this.value1,this.value1=t):this.value2=t):(t<this.value3?(this.value4=this.value3,this.value3=t):this.value4=t,this.high=!1):this.value2<t?(this.value0=this.value1,this.value1=this.value2,this.value4<t?(this.value2=this.value3,this.value3=this.value4,this.value4=t):this.value3<t?(this.value2=this.value3,this.value3=t):this.value2=t):(this.value1<t?(this.value0=this.value1,this.value1=t):this.value0=t,this.high=!0)}get(){return this.value2}};Zs=class{itemVersion;stream;decoder;changedValuesModel=new jt(64);bitByteModel=ge(256,256);classificationModel=ge(256,256);scanAngleRankModel=ge(2,256);userDataModel=ge(256,256);intensity=It(16,4);pointSourceId=It(16,1);dx=It(32,2);dy=It(32,22);z=It(32,20);lastIntensity=new Array(16).fill(0);lastHeight=new Array(8).fill(0);lastXDiffMedian=Array.from({length:16},()=>new jo);lastYDiffMedian=Array.from({length:16},()=>new jo);haveLast=!1;last=sb();firstPoint=sb();legacyXDiffs=[0,0,0];legacyYDiffs=[0,0,0];legacyDifferenceIndex=0;legacyScanAngle=null;constructor(t,e=2){this.itemVersion=e,this.stream=t,this.decoder=new ne(t),e===1&&(this.legacyScanAngle=It(8,2),this.dx=It(32,1),this.dy=It(32,20),this.intensity=It(16,1))}getDecoder(){return this.decoder}decompress(t,e){let n=this.decompressPoint();return cS(n,t,e),e+20}decompressPoint(){if(!this.haveLast)return this.haveLast=!0,oS(this.last,this.stream),aS(this.firstPoint,this.last),this.itemVersion===2&&(this.last.intensity=0),this.firstPoint;if(this.itemVersion===1)return this.decompressLegacyPoint();let t=this.decoder.decodeSymbol(this.changedValuesModel);if(t){t&32&&(this.last.bitByte=this.decoder.decodeSymbol(this.bitByteModel[this.last.bitByte]));let h=ib(this.last),m=ob(this.last),y=rb[m][h];if(t&16?(this.last.intensity=this.intensity.decompress(this.decoder,this.lastIntensity[y],y<3?y:3)&65535,this.lastIntensity[y]=this.last.intensity):this.last.intensity=this.lastIntensity[y],t&8&&(this.last.classification=this.decoder.decodeSymbol(this.classificationModel[this.last.classification])),t&4){let g=this.decoder.decodeSymbol(this.scanAngleRankModel[lS(this.last)]);this.last.scanAngleRank=qd(this.last.scanAngleRank+g)}t&2&&(this.last.userData=this.decoder.decodeSymbol(this.userDataModel[this.last.userData])),t&1&&(this.last.pointSourceId=this.pointSourceId.decompress(this.decoder,this.last.pointSourceId,0)&65535)}let e=ib(this.last),n=ob(this.last),s=rb[n][e],i=eS[n][e],o=this.lastXDiffMedian[s].get(),a=this.dx.decompress(this.decoder,o,n===1?1:0);this.last.x=cn(this.last.x+a),this.lastXDiffMedian[s].add(a);let c=this.lastYDiffMedian[s].get(),l=Math.min(this.dx.k,20)&-2,u=this.dy.decompress(this.decoder,c,(n===1?1:0)+l);this.last.y=cn(this.last.y+u),this.lastYDiffMedian[s].add(u);let f=Math.min(this.dx.k+this.dy.k>>1,18)&-2;return this.last.z=this.z.decompress(this.decoder,this.lastHeight[i],(n===1?1:0)+f),this.lastHeight[i]=this.last.z,this.last}decompressLegacyPoint(){let t=this.dx.decompress(this.decoder,nb(this.legacyXDiffs),0);this.last.x=cn(this.last.x+t);let e=this.dx.k,n=this.dy.decompress(this.decoder,nb(this.legacyYDiffs),Math.min(e,19));this.last.y=cn(this.last.y+n),e=e+this.dy.k>>1,this.last.z=this.z.decompress(this.decoder,this.last.z,Math.min(e,19));let s=this.decoder.decodeSymbol(this.changedValuesModel);return s&32&&(this.last.intensity=this.intensity.decompress(this.decoder,this.last.intensity,0)&65535),s&16&&(this.last.bitByte=this.decoder.decodeSymbol(this.bitByteModel[this.last.bitByte])),s&8&&(this.last.classification=this.decoder.decodeSymbol(this.classificationModel[this.last.classification])),s&4&&(this.last.scanAngleRank=qd(this.legacyScanAngle.decompress(this.decoder,this.last.scanAngleRank&255,e<3?1:0))),s&2&&(this.last.userData=this.decoder.decodeSymbol(this.userDataModel[this.last.userData])),s&1&&(this.last.pointSourceId=this.pointSourceId.decompress(this.decoder,this.last.pointSourceId,0)&65535),this.legacyXDiffs[this.legacyDifferenceIndex]=t,this.legacyYDiffs[this.legacyDifferenceIndex]=n,this.legacyDifferenceIndex=(this.legacyDifferenceIndex+1)%3,this.last}readFirstMetadata(){this.decoder.readInitBytes()}},tc=class{itemVersion;stream;decoder;haveLast=!1;lastRed=0;lastGreen=0;lastBlue=0;usedModel=new jt(128);diffModel=ge(6,256);legacyRgb=null;constructor(t,e,n=2){this.itemVersion=n,this.stream=t,this.decoder=e,n===1&&(this.usedModel=new jt(64),this.legacyRgb=It(8,6))}decompress(t,e){return this.decompressRgb(),ar(this.lastRed,t,e),ar(this.lastGreen,t,e+2),ar(this.lastBlue,t,e+4),e+6}decompressRgb(){if(!this.haveLast){this.haveLast=!0,this.lastRed=Ys(this.stream),this.lastGreen=Ys(this.stream),this.lastBlue=Ys(this.stream);return}let t=this.decoder.decodeSymbol(this.usedModel);if(this.itemVersion===1){this.lastRed=this.decodeLegacyColor(this.lastRed,0,t),this.lastGreen=this.decodeLegacyColor(this.lastGreen,1,t),this.lastBlue=this.decodeLegacyColor(this.lastBlue,2,t);return}let e=0,n=0,s=0;if(t&1?e=this.decoder.decodeSymbol(this.diffModel[0])+(this.lastRed&255)&255:e=this.lastRed&255,t&2?e|=(this.decoder.decodeSymbol(this.diffModel[1])+(this.lastRed>>8)&255)<<8:e|=this.lastRed&65280,t&64){let i=(e&255)-(this.lastRed&255);t&4?n=this.decoder.decodeSymbol(this.diffModel[2])+$s(i+(this.lastGreen&255))&255:n=this.lastGreen&255,t&16?(i=(i+((n&255)-(this.lastGreen&255)))/2|0,s=this.decoder.decodeSymbol(this.diffModel[4])+$s(i+(this.lastBlue&255))&255):s=this.lastBlue&255,i=(e>>8)-(this.lastRed>>8),t&8?n|=(this.decoder.decodeSymbol(this.diffModel[3])+$s(i+(this.lastGreen>>8))&255)<<8:n|=this.lastGreen&65280,t&32?(i=(i+(n>>8)-(this.lastGreen>>8))/2|0,s|=(this.decoder.decodeSymbol(this.diffModel[5])+$s(i+(this.lastBlue>>8))&255)<<8):s|=this.lastBlue&65280}else n=e,s=e;this.lastRed=e,this.lastGreen=n,this.lastBlue=s}decodeLegacyColor(t,e,n){let s=0;for(let i=0;i<2;i++){let o=e*2+i,a=t>>i*8&255,c=n&1<<o?this.legacyRgb.decompress(this.decoder,a,o):a;s|=c<<i*8}return s}get decodedRed(){return this.lastRed}get decodedGreen(){return this.lastGreen}get decodedBlue(){return this.lastBlue}},Hs=class{itemVersion;stream;decoder;count;haveLast=!1;last;models;legacyBytes;constructor(t,e,n,s=2){this.itemVersion=s,this.stream=t,this.decoder=e,this.count=n,this.last=new Uint8Array(n),this.models=ge(n,256),this.legacyBytes=s===1?It(8,n):null}get byteCount(){return this.count}decompress(t,e){return this.decompressToTarget(t,e),e+this.count}decompressToTarget(t,e=0){if(this.count!==0){if(!this.haveLast){this.stream.getBytes(this.last,0,this.count),t?.set(this.last,e),this.haveLast=!0;return}for(let n=0;n<this.count;n++){let s=this.itemVersion===1?this.legacyBytes.decompress(this.decoder,this.last[n],n):this.last[n]+this.decoder.decodeSymbol(this.models[n])&255;t&&(t[e+n]=s),this.last[n]=s}}}};(function(r){r[r.Full=0]="Full",r[r.PointData=1]="PointData"})(Nt||(Nt={}));Md=class{changedValuesModel=ge(8,128);scannerChannelModel=new jt(3);returnNumberGpsSameModel=new jt(13);numberReturnsModel=ge(16,16);returnNumberModel=ge(16,16);classModel=[];flagModel=[];userDataModel=[];gpsTimeMultiModel;gpsTime0DiffModel;dx=It(32,2);dy=It(32,22);z=It(32,20);intensity=null;scanAngle;pointSourceId;gpsTime;haveLast=!1;last=iS();lastIntensity=[];lastZ=new Array(8).fill(0);lastXDiffMedian=Array.from({length:12},()=>new jo);lastYDiffMedian=Array.from({length:12},()=>new jo);lastGpsSequence=0;nextGpsSequence=0;lastGpsTime=[];lastGpsTimeDiff=[];multiExtremeCounter=[];gpsTimeChange=!1;constructor(t,e){(t===Nt.Full||e?.classification)&&(this.classModel=ge(64,256)),(t===Nt.Full||e?.intensity)&&(this.intensity=It(16,4),this.lastIntensity=new Array(8).fill(0)),(t===Nt.Full||e?.userData)&&(this.userDataModel=ge(64,256)),(t===Nt.Full||e?.scanAngle)&&(this.scanAngle=It(16,2)),(t===Nt.Full||e?.pointSourceId)&&(this.pointSourceId=It(16,1)),(t===Nt.Full||e?.flags)&&(this.flagModel=ge(64,64)),(t===Nt.Full||e?.gpsTime)&&(this.gpsTimeMultiModel=new jt(515),this.gpsTime0DiffModel=new jt(5),this.gpsTime=It(32,9),this.lastGpsTime=new Array(4).fill(0),this.lastGpsTimeDiff=new Array(4).fill(0),this.multiExtremeCounter=new Array(4).fill(0))}},qi=class{stream;contexts;activeContext=null;decompressOptionalFields;xy=new ne;z=new ne;classification;flags;intensity;scanAngle;userData;pointSourceId;gpsTime;sizes=[];currentScannerChannel=0;itemContextChannel=0;itemVersion;constructor(t,e=Nt.Full,n=3,s=null){this.stream=t,this.itemVersion=n,this.contexts=Array.from({length:4},()=>new Md(e,s)),this.decompressOptionalFields=e===Nt.Full,this.classification=this.decompressOptionalFields||s?.classification?new ne:null,this.flags=this.decompressOptionalFields||s?.flags?new ne:null,this.intensity=this.decompressOptionalFields||s?.intensity?new ne:null,this.scanAngle=this.decompressOptionalFields||s?.scanAngle?new ne:null,this.userData=this.decompressOptionalFields||s?.userData?new ne:null,this.pointSourceId=this.decompressOptionalFields||s?.pointSourceId?new ne:null,this.gpsTime=this.decompressOptionalFields||s?.gpsTime?new ne:null}readSizes(){this.sizes=[];for(let t=0;t<9;t++)this.sizes.push(this.stream.getUint32())}readData(){let t=0;this.xy.initStream(this.stream,this.sizes[t++]),this.z.initStream(this.stream,this.sizes[t++]),this.initializeOptionalStream(this.classification,this.sizes[t++]),this.initializeOptionalStream(this.flags,this.sizes[t++]),this.initializeOptionalStream(this.intensity,this.sizes[t++]),this.initializeOptionalStream(this.scanAngle,this.sizes[t++]),this.initializeOptionalStream(this.userData,this.sizes[t++]),this.initializeOptionalStream(this.pointSourceId,this.sizes[t++]),this.initializeOptionalStream(this.gpsTime,this.sizes[t++])}initializeOptionalStream(t,e){t?t.initStream(this.stream,e):this.stream.consume(e)}decompress(t,e){let n=this.decompressPoint(t,e);return hS(n,t,e),e+30}decompressPoint(t,e=0){let n=this.gpsTime!==null;if(!this.activeContext){let rt=this.contexts[0].last;t?(this.stream.getBytes(t,e,30),uS(rt,t,e)):fS(rt,this.stream),this.currentScannerChannel=dS(rt),this.itemContextChannel=this.currentScannerChannel;let tt=this.contexts[this.currentScannerChannel];return tt.last!==rt&&ab(tt.last,rt),tt.haveLast=!0,n&&(tt.lastGpsTime[0]=tt.last.gpsTime),this.activeContext=tt,tt.lastZ.fill(tt.last.z),tt.lastIntensity.length&&tt.lastIntensity.fill(tt.last.intensity),tt.last}let s=this.activeContext,i=s.last.returns,o=i&15,a=(o===1?1:0)|(o>=i>>4?1:0)<<1|(s.gpsTimeChange?1:0)<<2,c=this.xy.decodeSymbol(s.changedValuesModel[a]),l=!!(c>>6&1),u=!!(c>>5&1),f=!!(c>>4&1),h=!!(c>>3&1),m=!!(c>>2&1),y=!!(c>>1&1),g=!!(c&1),x=g&&!y,B=y&&!g,q=g&&y;this.itemContextChannel=0;let M=this.currentScannerChannel,b=s;if(l){let rt=this.xy.decodeSymbol(s.scannerChannelModel);M=(M+rt+1)%4,b=this.contexts[M],this.activeContext=b,this.itemContextChannel=M}this.currentScannerChannel=M,this.itemVersion>=4&&(this.itemContextChannel=M),b.haveLast||(b.haveLast=!0,ab(b.last,s.last),b.lastZ.fill(s.last.z),b.lastIntensity.length&&b.lastIntensity.fill(s.last.intensity),n&&(b.lastGpsTime[0]=s.last.gpsTime)),pS(b.last,M);let C=b.last.returns>>4,_=b.last.returns&15;m&&(C=this.xy.decodeSymbol(b.numberReturnsModel[C])),x?_=(_+1)%16:B?_=(_+15)%16:q&&(_=f?this.xy.decodeSymbol(b.returnNumberModel[_]):(_+this.xy.decodeSymbol(b.returnNumberGpsSameModel)+2)%16),b.last.returns=C<<4|_;let $=KA[C][_]<<1|(f?1:0),X=b.lastXDiffMedian[$].get(),ft=b.dx.decompress(this.xy,X,C===1?1:0);b.last.x=cn(b.last.x+ft),b.lastXDiffMedian[$].add(ft);let dt=Math.min(b.dx.k,20)&-2,Bt=b.lastYDiffMedian[$].get(),se=b.dy.decompress(this.xy,Bt,(C===1?1:0)|dt);if(b.last.y=cn(b.last.y+se),b.lastYDiffMedian[$].add(se),this.z.valid){let rt=Math.min(b.dx.k+b.dy.k>>1,18)&-2,tt=JA[C][_],Ye=b.z.decompress(this.z,b.lastZ[tt],(C===1?1:0)|rt);b.last.z=Ye,b.lastZ[tt]=Ye}if(this.classification?.valid){let rt=(_===1&&_>=C?1:0)|(b.last.classification&31)<<1;b.last.classification=this.classification.decodeSymbol(b.classModel[rt])}if(this.flags?.valid){let rt=bS(b.last),tt=this.flags.decodeSymbol(b.flagModel[rt]);gS(b.last,tt>>5&1),yS(b.last,tt>>4&1),mS(b.last,tt&15)}if(this.intensity?.valid){let rt=(f?1:0)|(_>=C?1:0)<<1|(_===1?1:0)<<2,tt=b.intensity.decompress(this.intensity,b.lastIntensity[rt],rt>>1);b.lastIntensity[rt]=tt&65535,b.last.intensity=tt&65535}if(h&&this.scanAngle&&(b.last.scanAngle=Zd(b.scanAngle.decompress(this.scanAngle,b.last.scanAngle,f?1:0))),this.userData?.valid){let rt=b.last.userData>>2;b.last.userData=this.userData.decodeSymbol(b.userDataModel[rt])}return u&&this.pointSourceId&&(b.last.pointSourceId=b.pointSourceId.decompress(this.pointSourceId,b.last.pointSourceId,0)&65535),f&&this.gpsTime&&this.decodeGpsTime(b),b.gpsTimeChange=f,b.last}decodeGpsTime(t){let e=this.gpsTime;for(;;){if(t.lastGpsTimeDiff[t.lastGpsSequence]===0){let n=e.decodeSymbol(t.gpsTime0DiffModel);if(n===0){let s=t.gpsTime.decompress(e,0,0);t.lastGpsTimeDiff[t.lastGpsSequence]=s,t.lastGpsTime[t.lastGpsSequence]=qs(t.lastGpsTime[t.lastGpsSequence],s),t.multiExtremeCounter[t.lastGpsSequence]=0}else if(n===1){t.nextGpsSequence=t.nextGpsSequence+1&3;let s=uu(t.lastGpsTime[t.lastGpsSequence]),i=t.gpsTime.decompress(e,Number(s>>32n)|0,8),o=e.readInt();t.lastGpsTime[t.nextGpsSequence]=Vo(BigInt(i>>>0)<<32n|BigInt(o)),t.lastGpsSequence=t.nextGpsSequence,t.lastGpsTimeDiff[t.lastGpsSequence]=0,t.multiExtremeCounter[t.lastGpsSequence]=0}else{t.lastGpsSequence=t.lastGpsSequence+n-1&3;continue}}else{let n=e.decodeSymbol(t.gpsTimeMultiModel),s=0;if(n===1){let i=t.gpsTime.decompress(e,t.lastGpsTimeDiff[t.lastGpsSequence],1);t.lastGpsTime[t.lastGpsSequence]=qs(t.lastGpsTime[t.lastGpsSequence],i),t.multiExtremeCounter[t.lastGpsSequence]=0}else if(n<tu){if(n===0)s=t.gpsTime.decompress(e,0,7),t.multiExtremeCounter[t.lastGpsSequence]++,t.multiExtremeCounter[t.lastGpsSequence]>3&&(t.multiExtremeCounter[t.lastGpsSequence]=0,t.lastGpsTimeDiff[t.lastGpsSequence]=s);else if(n<an){let i=n<10?2:3;s=t.gpsTime.decompress(e,n*t.lastGpsTimeDiff[t.lastGpsSequence],i)}else n===an?(s=t.gpsTime.decompress(e,an*t.lastGpsTimeDiff[t.lastGpsSequence],4),t.multiExtremeCounter[t.lastGpsSequence]++,t.multiExtremeCounter[t.lastGpsSequence]>3&&(t.multiExtremeCounter[t.lastGpsSequence]=0,t.lastGpsTimeDiff[t.lastGpsSequence]=s)):(n=an-n,n>Go?s=t.gpsTime.decompress(e,n*t.lastGpsTimeDiff[t.lastGpsSequence],5):(s=t.gpsTime.decompress(e,Go*t.lastGpsTimeDiff[t.lastGpsSequence],6),t.multiExtremeCounter[t.lastGpsSequence]++,t.multiExtremeCounter[t.lastGpsSequence]>3&&(t.multiExtremeCounter[t.lastGpsSequence]=0,t.lastGpsTimeDiff[t.lastGpsSequence]=s)));t.lastGpsTime[t.lastGpsSequence]=qs(t.lastGpsTime[t.lastGpsSequence],s)}else if(n===tu){t.nextGpsSequence=t.nextGpsSequence+1&3;let i=uu(t.lastGpsTime[t.lastGpsSequence]),o=t.gpsTime.decompress(e,Number(i>>32n)|0,8),a=e.readInt();t.lastGpsTime[t.nextGpsSequence]=Vo(BigInt(o>>>0)<<32n|BigInt(a)),t.lastGpsSequence=t.nextGpsSequence,t.lastGpsTimeDiff[t.lastGpsSequence]=0,t.multiExtremeCounter[t.lastGpsSequence]=0}else if(n>=tu){t.lastGpsSequence=t.lastGpsSequence+n-tu&3;continue}}t.last.gpsTime=t.lastGpsTime[t.lastGpsSequence];break}}},Dd=class{haveLast=!1;lastRed=0;lastGreen=0;lastBlue=0;usedModel=new jt(128);diffModel=ge(6,256)},ec=class{stream;contexts=Array.from({length:4},()=>new Dd);activeContext=null;lastChannel=-1;rgbCount=0;rgb=new ne;decodedRed=0;decodedGreen=0;decodedBlue=0;itemVersion;constructor(t,e=3){this.stream=t,this.itemVersion=e}readSizes(){this.rgbCount=this.stream.getUint32()}readData(){this.rgb.initStream(this.stream,this.rgbCount)}decompress(t,e,n){return this.decompressRgb(n),ar(this.decodedRed,t,e),ar(this.decodedGreen,t,e+2),ar(this.decodedBlue,t,e+4),e+6}decompressRgb(t){if(this.lastChannel===-1){this.decodedRed=this.stream.getByte()|this.stream.getByte()<<8,this.decodedGreen=this.stream.getByte()|this.stream.getByte()<<8,this.decodedBlue=this.stream.getByte()|this.stream.getByte()<<8;let c=this.contexts[t];c.lastRed=this.decodedRed,c.lastGreen=this.decodedGreen,c.lastBlue=this.decodedBlue,c.haveLast=!0,this.lastChannel=t,this.activeContext=c;return}if(this.rgbCount===0){let c=this.activeContext;this.decodedRed=c.lastRed,this.decodedGreen=c.lastGreen,this.decodedBlue=c.lastBlue;return}let e=this.activeContext,n=e;if(t!==this.lastChannel){let c=e;e=this.contexts[t],n=c,this.lastChannel=t,e.haveLast||(e.haveLast=!0,e.lastRed=c.lastRed,e.lastGreen=c.lastGreen,e.lastBlue=c.lastBlue,n=e),this.itemVersion>=4&&(n=e),this.activeContext=e}let s=this.rgb.decodeSymbol(e.usedModel),i=0,o=0,a=0;if(s&1?i=this.rgb.decodeSymbol(e.diffModel[0])+(n.lastRed&255)&255:i=n.lastRed&255,s&2){let c=this.rgb.decodeSymbol(e.diffModel[1]);i|=(c+(n.lastRed>>8)&255)<<8}else i|=n.lastRed&65280;if(s&64){let c=(i&255)-(n.lastRed&255);if(s&4?o=this.rgb.decodeSymbol(e.diffModel[2])+$s(c+(n.lastGreen&255))&255:o=n.lastGreen&255,s&16){let l=this.rgb.decodeSymbol(e.diffModel[4]);c=(c+((o&255)-(n.lastGreen&255)))/2|0,a=l+$s(c+(n.lastBlue&255))&255}else a=n.lastBlue&255;if(c=(i>>8)-(n.lastRed>>8),s&8){let l=this.rgb.decodeSymbol(e.diffModel[3]);o|=(l+$s(c+(n.lastGreen>>8))&255)<<8}else o|=n.lastGreen&65280;if(s&32){let l=this.rgb.decodeSymbol(e.diffModel[5]);c=(c+(o>>8)-(n.lastGreen>>8))/2|0,a|=(l+$s(c+(n.lastBlue>>8))&255)<<8}else a|=n.lastBlue&65280}else o=i,a=i;n.lastRed=i,n.lastGreen=o,n.lastBlue=a,this.decodedRed=i,this.decodedGreen=o,this.decodedBlue=a}},Cd=class{haveLast=!1;lastValue=0;usedModel=new jt(4);diffModel=ge(2,256)},ru=class{stream;contexts=Array.from({length:4},()=>new Cd);lastChannel=-1;nirCount=0;nir=new ne;scratch=new Uint8Array(2);decodedNir=0;itemVersion;constructor(t,e=3){this.stream=t,this.itemVersion=e}readSizes(){this.nirCount=this.stream.getUint32()}readData(){this.nir.initStream(this.stream,this.nirCount)}decompress(t,e,n){if(this.lastChannel===-1){this.stream.getBytes(t,e,2);let c=this.contexts[n];return c.lastValue=au(t,e),c.haveLast=!0,this.lastChannel=n,this.decodedNir=c.lastValue,e+2}if(this.nirCount===0)return ar(this.contexts[this.lastChannel].lastValue,t,e),this.decodedNir=this.contexts[this.lastChannel].lastValue,e+2;let s=this.contexts[n],i=this.contexts[this.lastChannel];n!==this.lastChannel&&(this.lastChannel=n,s.haveLast||(s.haveLast=!0,s.lastValue=i.lastValue,i=s),this.itemVersion>=4&&(i=s));let o=this.nir.decodeSymbol(s.usedModel),a=o&1?this.nir.decodeSymbol(s.diffModel[0])+(i.lastValue&255)&255:i.lastValue&255;return a|=o&2?(this.nir.decodeSymbol(s.diffModel[1])+(i.lastValue>>8)&255)<<8:i.lastValue&65280,i.lastValue=a,this.decodedNir=a,ar(a,t,e),e+2}decompressNir(t){return this.decompress(this.scratch,0,t),this.decodedNir}},nu=class{haveLast=!1;descriptorIndex=0;offset=0n;packetSize=0;returnPointBits=0;xBits=0;yBits=0;zBits=0;lastOffsetDifference=0;lastOffsetDifferenceSymbol=0;descriptorModel=new jt(256);offsetDifferenceModels=ge(4,4);offsetDifferenceDecompressor=It(32,1);packetSizeDecompressor=It(32,1);returnPointDecompressor=It(32,1);vectorDecompressor=It(32,3)},su=class{stream;contexts=Array.from({length:4},()=>new nu);lastChannel=-1;wavePacketByteCount=0;decoder=new ne;itemVersion;constructor(t,e){this.stream=t,this.itemVersion=e}readSizes(){this.wavePacketByteCount=this.stream.getUint32()}readData(){this.decoder.initStream(this.stream,this.wavePacketByteCount)}decompress(t,e,n){if(this.lastChannel===-1){this.stream.getBytes(t,e,29);let a=this.contexts[n];return this.readContext(a,t,e),a.haveLast=!0,this.lastChannel=n,e+29}let s=this.contexts[this.lastChannel],i=this.contexts[n],o=i;return n!==this.lastChannel&&(o=s,i.haveLast?this.itemVersion>=4&&(o=i):(this.copyLastWavePacket(i,s),i.haveLast=!0,o=i),this.lastChannel=n),this.wavePacketByteCount&&this.decodeContext(i,o),this.writeContext(o,t,e),e+29}decompressToTarget(t,e,n){this.decompress(t,e,n)}decodeContext(t,e){e.descriptorIndex=this.decoder.decodeSymbol(t.descriptorModel);let n=this.decoder.decodeSymbol(t.offsetDifferenceModels[t.lastOffsetDifferenceSymbol]);switch(t.lastOffsetDifferenceSymbol=n,n){case 0:break;case 1:e.offset=BigInt.asUintN(64,e.offset+BigInt(e.packetSize));break;case 2:t.lastOffsetDifference=t.offsetDifferenceDecompressor.decompress(this.decoder,t.lastOffsetDifference,0),e.offset=BigInt.asUintN(64,e.offset+BigInt(t.lastOffsetDifference));break;default:e.offset=this.decoder.readUint64();break}e.packetSize=t.packetSizeDecompressor.decompress(this.decoder,e.packetSize|0,0)>>>0,e.returnPointBits=t.returnPointDecompressor.decompress(this.decoder,e.returnPointBits,0),e.xBits=t.vectorDecompressor.decompress(this.decoder,e.xBits,0),e.yBits=t.vectorDecompressor.decompress(this.decoder,e.yBits,1),e.zBits=t.vectorDecompressor.decompress(this.decoder,e.zBits,2)}copyLastWavePacket(t,e){t.descriptorIndex=e.descriptorIndex,t.offset=e.offset,t.packetSize=e.packetSize,t.returnPointBits=e.returnPointBits,t.xBits=e.xBits,t.yBits=e.yBits,t.zBits=e.zBits}readContext(t,e,n){t.descriptorIndex=e[n],t.offset=fb(e,n+1),t.packetSize=cu(e,n+9),t.returnPointBits=Vr(e,n+13),t.xBits=Vr(e,n+17),t.yBits=Vr(e,n+21),t.zBits=Vr(e,n+25)}writeContext(t,e,n){e[n]=t.descriptorIndex,hb(t.offset,e,n+1),lu(t.packetSize,e,n+9),Ue(t.returnPointBits,e,n+13),Ue(t.xBits,e,n+17),Ue(t.yBits,e,n+21),Ue(t.zBits,e,n+25)}},Fd=class{haveLast=!1;last;byteModel;constructor(t){this.last=new Uint8Array(t),this.byteModel=ge(t,256)}},$i=class{stream;count;contexts;lastChannel=-1;byteCount;byteDecoder;itemVersion;constructor(t,e,n=3){this.stream=t,this.count=e,this.itemVersion=n,this.contexts=Array.from({length:4},()=>new Fd(e)),this.byteCount=new Array(e).fill(0),this.byteDecoder=Array.from({length:e},()=>new ne)}readSizes(){for(let t=0;t<this.count;t++)this.byteCount[t]=this.stream.getUint32()}readData(){for(let t=0;t<this.count;t++)this.byteDecoder[t].initStream(this.stream,this.byteCount[t])}decompress(t,e,n){if(this.lastChannel===-1){this.stream.getBytes(t,e,this.count);let o=this.contexts[n];return o.last.set(t.subarray(e,e+this.count)),o.haveLast=!0,this.lastChannel=n,e+this.count}let s=this.contexts[n],i=this.contexts[this.lastChannel].last;n!==this.lastChannel&&(this.lastChannel=n,s.haveLast||(s.haveLast=!0,s.last.set(i),i=this.contexts[this.lastChannel].last),this.itemVersion>=4&&(i=s.last));for(let o=0;o<this.count;o++)if(this.byteCount[o]){let a=i[o]+this.byteDecoder[o].decodeSymbol(s.byteModel[o])&255;t[e+o]=a,i[o]=a}else t[e+o]=i[o];return e+this.count}};Od=class{point;bytes;first=!0;constructor(t,e,n){this.point=new Zs(t,n.point10ItemVersion??2),this.bytes=new Hs(t,this.point.getDecoder(),e,n.byteItemVersion??2)}decompress(t,e){return e=this.point.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e)}decompressPointDataBatch(t,e){for(let n=0;n<e;n++)this.decompressPointData(t,t.pointOffset+n)}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},qo=class{itemVersion;stream;decoder;gpsTimeMultiModel=new jt(516);gpsTime0DiffModel=new jt(6);gpsTime=It(32,9);lastGpsSequence=0;nextGpsSequence=0;lastGpsTime=new Array(4).fill(0);lastGpsTimeDiff=new Array(4).fill(0);multiExtremeCounter=new Array(4).fill(0);haveLast=!1;constructor(t,e,n=2){this.itemVersion=n,this.stream=t,this.decoder=e,n===1&&(this.gpsTimeMultiModel=new jt(512),this.gpsTime0DiffModel=new jt(3),this.gpsTime=It(32,6))}decompress(t,e){return pb(this.decompressGpsTime(),t,e),e+8}decompressGpsTime(){return this.haveLast?(this.itemVersion===1?this.decodeLegacyGpsTime():this.decodeGpsTime(),this.lastGpsTime[this.lastGpsSequence]):(this.lastGpsTime[0]=db(this.stream),this.haveLast=!0,this.lastGpsTime[0])}decodeLegacyGpsTime(){let t=this.lastGpsTimeDiff[0];if(t===0){let o=this.decoder.decodeSymbol(this.gpsTime0DiffModel);if(o===1){let a=this.gpsTime.decompress(this.decoder,0,0);this.lastGpsTimeDiff[0]=a,this.lastGpsTime[0]=qs(this.lastGpsTime[0],a)}else o===2&&(this.lastGpsTime[0]=Vo(this.decoder.readUint64()));return}let e=this.decoder.decodeSymbol(this.gpsTimeMultiModel);if(e===511)return;if(e===510){this.lastGpsTime[0]=Vo(this.decoder.readUint64());return}let n=e===1?1:e===0?2:e<10?3:e<50?4:5,s=e===0?Math.trunc(t/4):cn(e*t),i=this.gpsTime.decompress(this.decoder,s,n);e===1?(this.lastGpsTimeDiff[0]=i,this.multiExtremeCounter[0]=0):(e===0||e===509)&&++this.multiExtremeCounter[0]>3&&(this.lastGpsTimeDiff[0]=i,this.multiExtremeCounter[0]=0),this.lastGpsTime[0]=qs(this.lastGpsTime[0],i)}decodeGpsTime(){for(;;){if(this.lastGpsTimeDiff[this.lastGpsSequence]===0){let n=this.decoder.decodeSymbol(this.gpsTime0DiffModel);if(n===0)break;if(n===1){let s=this.gpsTime.decompress(this.decoder,0,0);this.lastGpsTimeDiff[this.lastGpsSequence]=s,this.lastGpsTime[this.lastGpsSequence]=qs(this.lastGpsTime[this.lastGpsSequence],s),this.multiExtremeCounter[this.lastGpsSequence]=0;break}if(n===2){this.readFullGpsTime();break}this.lastGpsSequence=this.lastGpsSequence+n-2&3;continue}let t=this.decoder.decodeSymbol(this.gpsTimeMultiModel),e=0;if(t===1){let n=this.gpsTime.decompress(this.decoder,this.lastGpsTimeDiff[this.lastGpsSequence],1);this.lastGpsTime[this.lastGpsSequence]=qs(this.lastGpsTime[this.lastGpsSequence],n),this.multiExtremeCounter[this.lastGpsSequence]=0}else if(t<QA){if(t===0)e=this.gpsTime.decompress(this.decoder,0,7),this.multiExtremeCounter[this.lastGpsSequence]++,this.multiExtremeCounter[this.lastGpsSequence]>3&&(this.multiExtremeCounter[this.lastGpsSequence]=0,this.lastGpsTimeDiff[this.lastGpsSequence]=e);else if(t<an){let n=t<10?2:3;e=this.gpsTime.decompress(this.decoder,t*this.lastGpsTimeDiff[this.lastGpsSequence],n)}else t===an?(e=this.gpsTime.decompress(this.decoder,an*this.lastGpsTimeDiff[this.lastGpsSequence],4),this.multiExtremeCounter[this.lastGpsSequence]++,this.multiExtremeCounter[this.lastGpsSequence]>3&&(this.multiExtremeCounter[this.lastGpsSequence]=0,this.lastGpsTimeDiff[this.lastGpsSequence]=e)):(t=an-t,t>Go?e=this.gpsTime.decompress(this.decoder,t*this.lastGpsTimeDiff[this.lastGpsSequence],5):(e=this.gpsTime.decompress(this.decoder,Go*this.lastGpsTimeDiff[this.lastGpsSequence],6),this.multiExtremeCounter[this.lastGpsSequence]++,this.multiExtremeCounter[this.lastGpsSequence]>3&&(this.multiExtremeCounter[this.lastGpsSequence]=0,this.lastGpsTimeDiff[this.lastGpsSequence]=e)));this.lastGpsTime[this.lastGpsSequence]=qs(this.lastGpsTime[this.lastGpsSequence],e)}else if(t===vd)this.readFullGpsTime();else if(t>=vd){this.lastGpsSequence=this.lastGpsSequence+t-vd&3;continue}break}}readFullGpsTime(){this.nextGpsSequence=this.nextGpsSequence+1&3;let t=uu(this.lastGpsTime[this.lastGpsSequence]),e=this.gpsTime.decompress(this.decoder,Number(t>>32n)|0,8),n=this.decoder.readInt();this.lastGpsTime[this.nextGpsSequence]=Vo(BigInt(e>>>0)<<32n|BigInt(n)),this.lastGpsSequence=this.nextGpsSequence,this.lastGpsTimeDiff[this.lastGpsSequence]=0,this.multiExtremeCounter[this.lastGpsSequence]=0}},Ed=class{point;gpsTime;bytes;first=!0;constructor(t,e,n){this.point=new Zs(t,n.point10ItemVersion??2);let s=this.point.getDecoder();this.gpsTime=new qo(t,s,n.gpsTime11ItemVersion??2),this.bytes=new Hs(t,s,e,n.byteItemVersion??2)}decompress(t,e){return e=this.point.decompress(t,e),e=this.gpsTime.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint(),s=this.gpsTime.decompressGpsTime();this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e),t.gpsTimes&&(t.gpsTimes[e]=s)}decompressPointDataBatch(t,e){for(let n=0;n<e;n++)this.decompressPointData(t,t.pointOffset+n)}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},Ud=class{point;rgb;bytes;first=!0;constructor(t,e,n){this.point=new Zs(t,n.point10ItemVersion??2);let s=this.point.getDecoder();this.rgb=new tc(t,s,n.rgb12ItemVersion??2),this.bytes=new Hs(t,s,e,n.byteItemVersion??2)}decompress(t,e){return e=this.point.decompress(t,e),e=this.rgb.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.rgb.decompressRgb(),this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e),Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){for(let n=0;n<e;n++)this.decompressPointData(t,t.pointOffset+n)}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},Nd=class{point;gpsTime;rgb;bytes;first=!0;directCommonOutput;constructor(t,e,n,s=null){this.point=new Zs(t,n.point10ItemVersion??2);let i=this.point.getDecoder();this.gpsTime=new qo(t,i,n.gpsTime11ItemVersion??2),this.rgb=new tc(t,i,n.rgb12ItemVersion??2),this.bytes=new Hs(t,i,e,n.byteItemVersion??2),this.directCommonOutput=!!(s&&!s.gpsTime&&!s.scanAngle&&!s.userData&&!s.pointSourceId&&!s.flags&&!s.waveform&&!s.extraBytes)}decompress(t,e){return e=this.point.decompress(t,e),e=this.gpsTime.decompress(t,e),e=this.rgb.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint(),s=this.gpsTime.decompressGpsTime();if(this.rgb.decompressRgb(),this.directCommonOutput){if(this.bytes.decompressToTarget(),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),t.colors){let i=e*4;t.colors[i]=this.rgb.decodedRed&255,t.colors[i+1]=this.rgb.decodedGreen&255,t.colors[i+2]=this.rgb.decodedBlue&255,t.colors[i+3]=255}else if(t.rawColors){let i=e*3;t.rawColors[i]=this.rgb.decodedRed,t.rawColors[i+1]=this.rgb.decodedGreen,t.rawColors[i+2]=this.rgb.decodedBlue}return}this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e),t.gpsTimes&&(t.gpsTimes[e]=s),Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.colors,a=t.rawColors,c=t.scale,l=t.offset,u=this.bytes.byteCount,f=t.pointOffset;if(!!!(t.gpsTimes||t.scanAngles||t.userData||t.pointSourceIds||t.returnNumbers||t.numberOfReturns||t.scannerChannels||t.scanDirectionFlags||t.edgeOfFlightLines||t.syntheticFlags||t.keyPointFlags||t.withheldFlags||t.overlapFlags)&&!t.extraBytes){for(let m=0;m<e;m++){let y=this.point.decompressPoint();if(this.gpsTime.decompressGpsTime(),this.rgb.decompressRgb(),this.bytes.decompressToTarget(),this.readFirstMetadata(),Rn(y,n,s,i,c,l,f),o){let g=f*4;o[g]=this.rgb.decodedRed&255,o[g+1]=this.rgb.decodedGreen&255,o[g+2]=this.rgb.decodedBlue&255,o[g+3]=255}else if(a){let g=f*3;a[g]=this.rgb.decodedRed,a[g+1]=this.rgb.decodedGreen,a[g+2]=this.rgb.decodedBlue}f++}return}for(let m=0;m<e;m++){let y=this.point.decompressPoint(),g=this.gpsTime.decompressGpsTime();this.rgb.decompressRgb(),this.bytes.decompressToTarget(t.extraBytes,f*u),this.readFirstMetadata(),Rn(y,n,s,i,c,l,f),Wi(y,t,f),t.gpsTimes&&(t.gpsTimes[f]=g),Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,f),f++}}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},iu=class{stream;decoder;context=new nu;constructor(t,e){this.stream=t,this.decoder=e}decompress(t,e){let n=this.context;if(!n.haveLast)return this.stream.getBytes(t,e,29),this.readContext(t,e),n.haveLast=!0,e+29;n.descriptorIndex=this.decoder.decodeSymbol(n.descriptorModel);let s=this.decoder.decodeSymbol(n.offsetDifferenceModels[n.lastOffsetDifferenceSymbol]);switch(n.lastOffsetDifferenceSymbol=s,s){case 0:break;case 1:n.offset=BigInt.asUintN(64,n.offset+BigInt(n.packetSize));break;case 2:n.lastOffsetDifference=n.offsetDifferenceDecompressor.decompress(this.decoder,n.lastOffsetDifference,0),n.offset=BigInt.asUintN(64,n.offset+BigInt(n.lastOffsetDifference));break;default:n.offset=this.decoder.readUint64();break}return n.packetSize=n.packetSizeDecompressor.decompress(this.decoder,n.packetSize|0,0)>>>0,n.returnPointBits=n.returnPointDecompressor.decompress(this.decoder,n.returnPointBits,0),n.xBits=n.vectorDecompressor.decompress(this.decoder,n.xBits,0),n.yBits=n.vectorDecompressor.decompress(this.decoder,n.yBits,1),n.zBits=n.vectorDecompressor.decompress(this.decoder,n.zBits,2),this.writeContext(t,e),e+29}decompressToTarget(t,e){this.decompress(t,e)}readContext(t,e){let n=this.context;n.descriptorIndex=t[e],n.offset=fb(t,e+1),n.packetSize=cu(t,e+9),n.returnPointBits=Vr(t,e+13),n.xBits=Vr(t,e+17),n.yBits=Vr(t,e+21),n.zBits=Vr(t,e+25)}writeContext(t,e){let n=this.context;t[e]=n.descriptorIndex,hb(n.offset,t,e+1),lu(n.packetSize,t,e+9),Ue(n.returnPointBits,t,e+13),Ue(n.xBits,t,e+17),Ue(n.yBits,t,e+21),Ue(n.zBits,t,e+25)}},Rd=class{point;gpsTime;wavePacket;bytes;waveformScratch=new Uint8Array(29);first=!0;constructor(t,e,n){this.point=new Zs(t,n.point10ItemVersion??2);let s=this.point.getDecoder();this.gpsTime=new qo(t,s,n.gpsTime11ItemVersion??2),this.wavePacket=new iu(t,s),this.bytes=new Hs(t,s,e,n.byteItemVersion??2)}decompress(t,e){return e=this.point.decompress(t,e),e=this.gpsTime.decompress(t,e),e=this.wavePacket.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint(),s=this.gpsTime.decompressGpsTime();t.waveforms?this.wavePacket.decompressToTarget(t.waveforms,e*29):this.wavePacket.decompressToTarget(this.waveformScratch,0),this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e),t.gpsTimes&&(t.gpsTimes[e]=s)}decompressPointDataBatch(t,e){for(let n=0;n<e;n++)this.decompressPointData(t,t.pointOffset+n)}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},Pd=class{point;gpsTime;rgb;wavePacket;bytes;waveformScratch=new Uint8Array(29);first=!0;constructor(t,e,n){this.point=new Zs(t,n.point10ItemVersion??2);let s=this.point.getDecoder();this.gpsTime=new qo(t,s,n.gpsTime11ItemVersion??2),this.rgb=new tc(t,s,n.rgb12ItemVersion??2),this.wavePacket=new iu(t,s),this.bytes=new Hs(t,s,e,n.byteItemVersion??2)}decompress(t,e){return e=this.point.decompress(t,e),e=this.gpsTime.decompress(t,e),e=this.rgb.decompress(t,e),e=this.wavePacket.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint(),s=this.gpsTime.decompressGpsTime();this.rgb.decompressRgb(),t.waveforms?this.wavePacket.decompressToTarget(t.waveforms,e*29):this.wavePacket.decompressToTarget(this.waveformScratch,0),this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e),t.gpsTimes&&(t.gpsTimes[e]=s),Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){for(let n=0;n<e;n++)this.decompressPointData(t,t.pointOffset+n)}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},kd=class{stream;point;bytes;extraByteCount;first=!0;constructor(t,e,n,s,i){this.stream=t,this.extraByteCount=e,this.point=new qi(t,n==="raw"?Nt.Full:Nt.PointData,s.point14ItemVersion??3,i),this.bytes=(n==="raw"||i?.extraBytes)&&e?new $i(t,e,s.byte14ItemVersion??3):null}decompress(t,e){return e=this.point.decompress(t,e),this.bytes&&(e=this.bytes.decompress(t,e,this.point.itemContextChannel)),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,e*this.extraByteCount,this.point.itemContextChannel):this.first&&this.extraByteCount&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),nc(n,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.scale,a=t.offset,c=t.pointOffset;for(let l=0;l<e;l++){let u=this.point.decompressPoint();this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,c*this.extraByteCount,this.point.itemContextChannel):this.first&&this.extraByteCount&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),Ws(u,n,s,i,o,a,c++),Yi(u,t,c-1),Zi(u,t,c-1)}}readFirstMetadata(){if(this.first){this.stream.getUint32(),this.point.readSizes();let t=0;if(this.bytes)this.bytes.readSizes();else for(let e=0;e<this.extraByteCount;e++)t+=this.stream.getUint32();this.point.readData(),this.bytes?this.bytes.readData():this.stream.consume(t),this.first=!1}}},zd=class{stream;point;rgb;bytes;extraByteCount;first=!0;constructor(t,e,n,s,i){this.stream=t,this.extraByteCount=e,this.point=new qi(t,n==="raw"?Nt.Full:Nt.PointData,s.point14ItemVersion??3,i),this.rgb=n==="raw"||i?.color?new ec(t,s.rgb14ItemVersion??3):null,this.bytes=(n==="raw"||i?.extraBytes)&&e?new $i(t,e,s.byte14ItemVersion??3):null}decompress(t,e){return e=this.point.decompress(t,e),e=this.rgb.decompress(t,e,this.point.itemContextChannel),this.bytes&&(e=this.bytes.decompress(t,e,this.point.itemContextChannel)),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.first&&this.stream.consume(6),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,e*this.extraByteCount,this.point.itemContextChannel):this.first&&this.extraByteCount&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),nc(n,t,e),this.rgb&&Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.colors,a=t.rawColors,c=t.scale,l=t.offset,u=t.pointOffset,f=e;if(this.first&&f>0){let y=this.point.decompressPoint();if(this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.stream.consume(6),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,u*this.extraByteCount,this.point.itemContextChannel):this.extraByteCount&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),Ws(y,n,s,i,c,l,u),Yi(y,t,u),Zi(y,t,u),o&&this.rgb){let g=u*4;o[g]=this.rgb.decodedRed&255,o[g+1]=this.rgb.decodedGreen&255,o[g+2]=this.rgb.decodedBlue&255,o[g+3]=255}else if(a&&this.rgb){let g=u*3;a[g]=this.rgb.decodedRed,a[g+1]=this.rgb.decodedGreen,a[g+2]=this.rgb.decodedBlue}u++,f--}let h=!!(t.gpsTimes||t.scanAngles||t.userData||t.pointSourceIds||t.returnNumbers||t.numberOfReturns||t.scannerChannels||t.scanDirectionFlags||t.edgeOfFlightLines||t.syntheticFlags||t.keyPointFlags||t.withheldFlags||t.overlapFlags),m=!!(this.bytes&&t.extraBytes);if(!h&&!m){for(let y=0;y<f;y++){let g=this.point.decompressPoint();if(this.rgb?.decompressRgb(this.point.itemContextChannel),Ws(g,n,s,i,c,l,u),o&&this.rgb){let x=u*4;o[x]=this.rgb.decodedRed&255,o[x+1]=this.rgb.decodedGreen&255,o[x+2]=this.rgb.decodedBlue&255,o[x+3]=255}else if(a&&this.rgb){let x=u*3;a[x]=this.rgb.decodedRed,a[x+1]=this.rgb.decodedGreen,a[x+2]=this.rgb.decodedBlue}u++}return}for(let y=0;y<f;y++){let g=this.point.decompressPoint();if(this.rgb?.decompressRgb(this.point.itemContextChannel),this.bytes&&t.extraBytes&&this.bytes.decompress(t.extraBytes,u*this.extraByteCount,this.point.itemContextChannel),Ws(g,n,s,i,c,l,u),Yi(g,t,u),Zi(g,t,u),o&&this.rgb){let x=u*4;o[x]=this.rgb.decodedRed&255,o[x+1]=this.rgb.decodedGreen&255,o[x+2]=this.rgb.decodedBlue&255,o[x+3]=255}else if(a&&this.rgb){let x=u*3;a[x]=this.rgb.decodedRed,a[x+1]=this.rgb.decodedGreen,a[x+2]=this.rgb.decodedBlue}u++}}readFirstMetadata(){if(this.first){this.stream.getUint32(),this.point.readSizes();let t=this.rgb?0:this.stream.getUint32();this.rgb?.readSizes();let e=0;if(this.bytes)this.bytes.readSizes();else for(let n=0;n<this.extraByteCount;n++)e+=this.stream.getUint32();this.point.readData(),this.rgb?this.rgb.readData():this.stream.consume(t),this.bytes?this.bytes.readData():this.stream.consume(e),this.first=!1}}},Vd=class{stream;point;rgb;nir;bytes;extraByteCount;first=!0;constructor(t,e,n,s,i){this.stream=t,this.extraByteCount=e,this.point=new qi(t,n==="raw"?Nt.Full:Nt.PointData,s.point14ItemVersion??3,i),this.rgb=n==="raw"||i?.color?new ec(t,s.rgb14ItemVersion??3):null,this.nir=n==="raw"||i?.nir?new ru(t,s.rgb14ItemVersion??3):null,this.bytes=(n==="raw"||i?.extraBytes)&&e?new $i(t,e,s.byte14ItemVersion??3):null}decompress(t,e){return e=this.point.decompress(t,e),e=this.rgb.decompress(t,e,this.point.itemContextChannel),e=this.nir.decompress(t,e,this.point.itemContextChannel),this.bytes&&(e=this.bytes.decompress(t,e,this.point.itemContextChannel)),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.first&&this.stream.consume(6),!this.nir&&this.first&&this.stream.consume(2);let s=this.nir?this.nir.decompressNir(this.point.itemContextChannel):0;this.bytes&&t.extraBytes&&this.bytes.decompress(t.extraBytes,e*this.extraByteCount,this.point.itemContextChannel),this.first&&this.stream.consume(this.bytes?0:this.extraByteCount),this.readFirstMetadata(),nc(n,t,e),ou(s,t,e),this.rgb&&Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.colors,a=t.rawColors,c=t.scale,l=t.offset,u=t.pointOffset;for(let f=0;f<e;f++){let h=this.point.decompressPoint();this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.first&&this.stream.consume(6),!this.nir&&this.first&&this.stream.consume(2);let m=this.nir?this.nir.decompressNir(this.point.itemContextChannel):0;if(this.bytes&&t.extraBytes&&this.bytes.decompress(t.extraBytes,u*this.extraByteCount,this.point.itemContextChannel),this.first&&this.stream.consume(this.bytes?0:this.extraByteCount),this.readFirstMetadata(),Ws(h,n,s,i,c,l,u),Yi(h,t,u),Zi(h,t,u),o&&this.rgb){let y=u*4;o[y]=this.rgb.decodedRed&255,o[y+1]=this.rgb.decodedGreen&255,o[y+2]=this.rgb.decodedBlue&255,o[y+3]=255}else if(a&&this.rgb){let y=u*3;a[y]=this.rgb.decodedRed,a[y+1]=this.rgb.decodedGreen,a[y+2]=this.rgb.decodedBlue}ou(m,t,u),u++}}readFirstMetadata(){if(this.first){this.stream.getUint32(),this.point.readSizes();let t=this.rgb?0:this.stream.getUint32();this.rgb?.readSizes();let e=this.nir?0:this.stream.getUint32();this.nir?.readSizes();let n=0;if(this.bytes)this.bytes.readSizes();else for(let s=0;s<this.extraByteCount;s++)n+=this.stream.getUint32();this.point.readData(),this.rgb?this.rgb.readData():this.stream.consume(t),this.nir?this.nir.readData():this.stream.consume(e),this.bytes?this.bytes.readData():this.stream.consume(n),this.first=!1}}},Gd=class{stream;point;wavePacket;bytes;extraByteCount;first=!0;waveformScratch=new Uint8Array(29);constructor(t,e,n,s,i){this.stream=t,this.extraByteCount=e,this.point=new qi(t,n==="raw"?Nt.Full:Nt.PointData,s.point14ItemVersion??3,i),this.wavePacket=n==="raw"||i?.waveform?new su(t,s.wavePacketItemVersion??3):null,this.bytes=(n==="raw"||i?.extraBytes)&&e?new $i(t,e,s.byte14ItemVersion??3):null}decompress(t,e){return e=this.point.decompress(t,e),e=this.wavePacket.decompress(t,e,this.point.itemContextChannel),this.bytes&&(e=this.bytes.decompress(t,e,this.point.itemContextChannel)),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.wavePacket?(this.wavePacket.decompressToTarget(this.waveformScratch,0,this.point.itemContextChannel),t.waveforms&&t.waveforms.set(this.waveformScratch,e*29)):this.first&&this.stream.consume(29),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,e*this.extraByteCount,this.point.itemContextChannel):this.first&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),nc(n,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.scale,a=t.offset,c=t.pointOffset;for(let l=0;l<e;l++){let u=this.point.decompressPoint();this.wavePacket?(this.wavePacket.decompressToTarget(this.waveformScratch,0,this.point.itemContextChannel),t.waveforms&&t.waveforms.set(this.waveformScratch,c*29)):this.first&&this.stream.consume(29),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,c*this.extraByteCount,this.point.itemContextChannel):this.first&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),Ws(u,n,s,i,o,a,c++),Yi(u,t,c-1),Zi(u,t,c-1)}}readFirstMetadata(){if(this.first){this.stream.getUint32(),this.point.readSizes();let t=this.wavePacket?0:this.stream.getUint32();this.wavePacket?.readSizes();let e=0;if(this.bytes)this.bytes.readSizes();else for(let n=0;n<this.extraByteCount;n++)e+=this.stream.getUint32();this.point.readData(),this.wavePacket?this.wavePacket.readData():this.stream.consume(t),this.bytes?this.bytes.readData():this.stream.consume(e),this.first=!1}}},jd=class{stream;point;rgb;nir;wavePacket;bytes;extraByteCount;first=!0;waveformScratch=new Uint8Array(29);constructor(t,e,n,s,i){this.stream=t,this.extraByteCount=e,this.point=new qi(t,n==="raw"?Nt.Full:Nt.PointData,s.point14ItemVersion??3,i),this.rgb=n==="raw"||i?.color?new ec(t,s.rgb14ItemVersion??3):null,this.nir=n==="raw"||i?.nir?new ru(t,s.rgb14ItemVersion??3):null,this.wavePacket=n==="raw"||i?.waveform?new su(t,s.wavePacketItemVersion??3):null,this.bytes=(n==="raw"||i?.extraBytes)&&e?new $i(t,e,s.byte14ItemVersion??3):null}decompress(t,e){return e=this.point.decompress(t,e),e=this.rgb.decompress(t,e,this.point.itemContextChannel),e=this.nir.decompress(t,e,this.point.itemContextChannel),e=this.wavePacket.decompress(t,e,this.point.itemContextChannel),this.bytes&&(e=this.bytes.decompress(t,e,this.point.itemContextChannel)),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.first&&this.stream.consume(6);let s=this.nir?this.nir.decompressNir(this.point.itemContextChannel):0;this.first&&this.stream.consume(this.nir?0:2),this.wavePacket?(this.wavePacket.decompressToTarget(this.waveformScratch,0,this.point.itemContextChannel),t.waveforms&&t.waveforms.set(this.waveformScratch,e*29)):this.first&&this.stream.consume(29),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,e*this.extraByteCount,this.point.itemContextChannel):this.first&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),nc(n,t,e),ou(s,t,e),this.rgb&&Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.colors,a=t.rawColors,c=t.scale,l=t.offset,u=t.pointOffset;for(let f=0;f<e;f++){let h=this.point.decompressPoint();this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.first&&this.stream.consume(6);let m=this.nir?this.nir.decompressNir(this.point.itemContextChannel):0;if(this.first&&this.stream.consume(this.nir?0:2),this.wavePacket?(this.wavePacket.decompressToTarget(this.waveformScratch,0,this.point.itemContextChannel),t.waveforms&&t.waveforms.set(this.waveformScratch,u*29)):this.first&&this.stream.consume(29),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,u*this.extraByteCount,this.point.itemContextChannel):this.first&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),Ws(h,n,s,i,c,l,u),Yi(h,t,u),Zi(h,t,u),o&&this.rgb){let y=u*4;o[y]=this.rgb.decodedRed&255,o[y+1]=this.rgb.decodedGreen&255,o[y+2]=this.rgb.decodedBlue&255,o[y+3]=255}else if(a&&this.rgb){let y=u*3;a[y]=this.rgb.decodedRed,a[y+1]=this.rgb.decodedGreen,a[y+2]=this.rgb.decodedBlue}ou(m,t,u),u++}}readFirstMetadata(){if(this.first){this.stream.getUint32(),this.point.readSizes();let t=this.rgb?0:this.stream.getUint32();this.rgb?.readSizes();let e=this.nir?0:this.stream.getUint32();this.nir?.readSizes();let n=this.wavePacket?0:this.stream.getUint32();this.wavePacket?.readSizes();let s=0;if(this.bytes)this.bytes.readSizes();else for(let i=0;i<this.extraByteCount;i++)s+=this.stream.getUint32();this.point.readData(),this.rgb?this.rgb.readData():this.stream.consume(t),this.nir?this.nir.readData():this.stream.consume(e),this.wavePacket?this.wavePacket.readData():this.stream.consume(n),this.bytes?this.bytes.readData():this.stream.consume(s),this.first=!1}}}});function We(r){return r|0}var Ot,Hd,$t,_t,Xi,yb=p(()=>{"use strict";Ot=class{symbols;distribution;symbolCount;lastSymbol;totalCount=0;updateCycle;symbolsUntilUpdate;constructor(t){if(t<2||t>2048)throw new Error(`Invalid arithmetic model symbol count ${t}`);this.symbols=t,this.lastSymbol=t-1,this.distribution=new Uint32Array(t),this.symbolCount=new Uint32Array(t),this.symbolCount.fill(1),this.updateCycle=t,this.symbolsUntilUpdate=t,this.update(),this.symbolsUntilUpdate=this.updateCycle=t+6>>1}update(){if(this.totalCount+=this.updateCycle,this.totalCount>32768){this.totalCount=0;for(let s=0;s<this.symbols;s++)this.symbolCount[s]=this.symbolCount[s]+1>>1,this.totalCount+=this.symbolCount[s]}let t=0,e=2147483648/this.totalCount|0;for(let s=0;s<this.symbols;s++)this.distribution[s]=e*t/65536|0,t+=this.symbolCount[s];this.updateCycle=5*this.updateCycle>>2;let n=this.symbols+6<<3;this.updateCycle>n&&(this.updateCycle=n),this.symbolsUntilUpdate=this.updateCycle}},Hd=class{updateCycle=4;bitsUntilUpdate=4;bit0Probability=4096;bit0Count=1;bitCount=2;update(){this.bitCount+=this.updateCycle,this.bitCount>8192&&(this.bitCount=this.bitCount+1>>1,this.bit0Count=this.bit0Count+1>>1,this.bit0Count===this.bitCount&&this.bitCount++);let t=2147483648/this.bitCount|0;this.bit0Probability=this.bit0Count*t/262144|0,this.updateCycle=5*this.updateCycle>>2,this.updateCycle>64&&(this.updateCycle=64),this.bitsUntilUpdate=this.updateCycle}},$t=class{bytes=[];base=0;length=4294967295;finished=!1;encodeBit(t,e){let n=t.bit0Probability*(this.length>>>13);if(e===0)this.length=n>>>0,t.bit0Count++;else if(e===1)this.addToBase(n),this.length=this.length-n>>>0;else throw new Error(`Invalid arithmetic bit ${e}`);this.renormalizeIfNeeded(),--t.bitsUntilUpdate===0&&t.update()}encodeSymbol(t,e){if(!Number.isInteger(e)||e<0||e>t.lastSymbol)throw new Error(`Invalid arithmetic symbol ${e}`);let n=this.length,s;e===t.lastSymbol?(s=t.distribution[e]*(n>>>15),this.addToBase(s),this.length=n-s>>>0):(n>>>=15,s=t.distribution[e]*n,this.addToBase(s),this.length=t.distribution[e+1]*n-s>>>0),this.renormalizeIfNeeded(),t.symbolCount[e]++,--t.symbolsUntilUpdate===0&&t.update()}writeBits(t,e){if(!Number.isInteger(t)||t<1||t>32)throw new Error(`Invalid arithmetic bit count ${t}`);t>19&&(this.writeShort(e&65535),e>>>=16,t-=16);let n=this.length>>>t;this.addToBase(e*n),this.length=n>>>0,this.renormalizeIfNeeded()}writeShort(t){let e=this.length>>>16;this.addToBase((t&65535)*e),this.length=e>>>0,this.renormalizeIfNeeded()}writeInt(t){this.writeShort(t&65535),this.writeShort(t>>>16)}finish(){if(this.finished)return Uint8Array.from(this.bytes);this.finished=!0;let t=this.base,e=!0;return this.length>2*16777216?(this.base=this.base+16777216>>>0,this.length=8388608):(this.base=this.base+8388608>>>0,this.length=32768,e=!1),t>this.base&&this.propagateCarry(),this.renormalize(),this.bytes.push(0,0),e&&this.bytes.push(0),Uint8Array.from(this.bytes)}addToBase(t){let e=this.base;this.base=this.base+t>>>0,e>this.base&&this.propagateCarry()}propagateCarry(){let t=this.bytes.length-1;for(;t>=0&&this.bytes[t]===255;)this.bytes[t--]=0;if(t<0)throw new Error("LASzip arithmetic carry precedes encoded output");this.bytes[t]++}renormalizeIfNeeded(){this.length<16777216&&this.renormalize()}renormalize(){do this.bytes.push(this.base>>>24),this.base=this.base<<8>>>0,this.length=this.length<<8>>>0;while(this.length<16777216)}},_t=class{encoder;contexts;bitsHigh;correctionBits;correctionRange;correctionMinimum;bitModels;zeroBitCorrector=new Hd;correctorModels;k=0;constructor(t,e=16,n=1,s=8,i=0){if(this.encoder=t,this.contexts=n,this.bitsHigh=s,i){let o=i,a=0;for(;o;)o>>=1,a++;i===2**(a-1)&&a--,this.correctionBits=a,this.correctionRange=i,this.correctionMinimum=-(i/2)}else e&&e<32?(this.correctionBits=e,this.correctionRange=2**e,this.correctionMinimum=-(this.correctionRange/2)):(this.correctionBits=32,this.correctionRange=0,this.correctionMinimum=-2147483648);this.bitModels=Array.from({length:this.contexts},()=>new Ot(this.correctionBits+1)),this.correctorModels=Array.from({length:this.correctionBits},(o,a)=>{let c=a+1;return new Ot(2**Math.min(c,this.bitsHigh))})}compress(t,e,n=0){if(!Number.isInteger(n)||n<0||n>=this.contexts)throw new Error(`Invalid integer compressor context ${n}`);let s=We(e-t);this.correctionRange&&(s<this.correctionMinimum?s+=this.correctionRange:s>this.correctionMinimum+this.correctionRange-1&&(s-=this.correctionRange)),this.writeCorrector(s,this.bitModels[n])}writeCorrector(t,e){let n=t<=0?-t:t-1,s=0;for(;n;)n>>>=1,s++;if(this.k=s,this.encoder.encodeSymbol(e,s),s===0){this.encoder.encodeBit(this.zeroBitCorrector,t);return}if(s===32){if(t!==this.correctionMinimum)throw new Error(`Invalid ${s}-bit integer correction ${t}`);return}let i=t<0?t+(2**s-1):t-1,o=this.correctorModels[s-1];if(s<=this.bitsHigh)this.encoder.encodeSymbol(o,i);else{let a=s-this.bitsHigh,c=2**a-1,l=i&c;i>>>=a,this.encoder.encodeSymbol(o,i),this.encoder.writeBits(a,l)}}},Xi=class{value0=0;value1=0;value2=0;value3=0;value4=0;high=!0;add(t){this.high?t<this.value2?(this.value4=this.value3,this.value3=this.value2,t<this.value0?(this.value2=this.value1,this.value1=this.value0,this.value0=t):t<this.value1?(this.value2=this.value1,this.value1=t):this.value2=t):(t<this.value3?(this.value4=this.value3,this.value3=t):this.value4=t,this.high=!1):this.value2<t?(this.value0=this.value1,this.value1=this.value2,this.value4<t?(this.value2=this.value3,this.value3=this.value4,this.value4=t):this.value3<t?(this.value2=this.value3,this.value3=t):this.value2=t):(this.value1<t?(this.value0=this.value1,this.value1=t):this.value0=t,this.high=!0)}get(){return this.value2}}});function op(r,t){let e=OS(r);if(TS(e,t),t.pointCount===0)return new Uint8Array(0);if(t.pointDataRecordFormat<=5)return LS(e,t);let n=t.pointDataRecordLength,s=t.pointDataRecordFormat,i=Bu[s],o=n-i,a=e.subarray(0,n),c=vb(a,0),l=new rp(c),u=s===7||s===8||s===10?vu(a,30):null,f=u?new np(u,Yo(c)):null,h=s===8||s===10?new sp(sc(a,36),Yo(c)):null,m=s===9?30:s===10?38:-1,y=m>=0?new tp(Au(a,m),Yo(c),t.wavePacketItemVersion??3):null,g=o?new ip(a.subarray(i,n),Yo(c)):null;for(let X=1;X<t.pointCount;X++){let ft=X*n,dt=e.subarray(ft,ft+n),Bt=l.encode(vb(dt,0));f?.encode(vu(dt,30),Bt),h?.encode(sc(dt,36),Bt),y?.encode(Au(dt,m),Bt),g?.encode(dt.subarray(i,n),Bt)}let x=l.finish(),B=f?.finish(),q=h?.finish(),M=y?.finish(),b=g?.finish()||[],C=[...x,...B?[B]:[],...q?[q]:[],...M?[M]:[],...b],_=new Uint8Array(4+C.length*4),$=new DataView(_.buffer);$.setUint32(0,t.pointCount,!0);for(let X=0;X<C.length;X++)$.setUint32(4+X*4,C[X].byteLength,!0);return Tb([a,_,...C])}function ap(r,t={}){if(r.length===0)return new Uint8Array(0);let e=new $t,n=new _t(e,32,2),s=0,i=0;for(let o of r)MS(o),t.variable&&(n.compress(s,o.pointCount,0),s=o.pointCount),n.compress(i,o.byteLength,1),i=o.byteLength;return e.finish()}function cp(r){let t=r.pointDataRecordFormat<=5,e=r.itemVersion||(t?2:3);if(t&&e!==2)throw new Error("Legacy LASzip point formats require item version 2");if(!t&&e!==3)throw new Error("Modern LASzip point formats require item version 3");let n=DS(r.pointDataRecordFormat,r.pointDataRecordLength),s=bb+n.length*6,i=new Uint8Array(gb+s),o=new DataView(i.buffer),a=gb;_b(o,2,"laszip encoded",16),o.setUint16(18,22204,!0),o.setUint16(20,s,!0),_b(o,22,"loaders.gl LAZ writer",32),o.setUint16(a,t?2:3,!0),o.setUint16(a+2,0,!0),o.setUint8(a+4,t?2:3),o.setUint8(a+5,0),o.setUint16(a+6,1,!0),o.setUint32(a+8,0,!0),o.setUint32(a+12,r.chunkSize,!0),i.fill(255,a+16,a+32),o.setUint16(a+32,n.length,!0);for(let c=0;c<n.length;c++){let l=a+bb+c*6,u=n[c];o.setUint16(l,u.type,!0),o.setUint16(l+2,u.size,!0),o.setUint16(l+4,u.version??e,!0)}return i}function LS(r,t){let e=t.pointDataRecordLength,n=t.pointDataRecordFormat,s=Bu[n],i=e-s,o=r.subarray(0,e),a=new $t,c=new Xd(a,Ab(o,0)),l=n===1||n===3||n===4||n===5?new Kd(a,Sb(o,20)):null,u=n===2?20:n===3||n===5?28:-1,f=u>=0?new Jd(a,vu(o,u)):null,h=n===4?28:n===5?34:-1,m=h>=0?new Qd(a,Au(o,h)):null,y=i?new ep(a,o.subarray(s,e)):null;for(let g=1;g<t.pointCount;g++){let x=g*e,B=r.subarray(x,x+e);c.encode(Ab(B,0)),l?.encode(Sb(B,20)),f?.encode(vu(B,u)),m?.encode(Au(B,h)),y?.encode(B.subarray(s,e))}return Tb([o,a.finish()])}function TS(r,t){if([t.point10ItemVersion,t.gpsTime11ItemVersion,t.rgb12ItemVersion,t.byteItemVersion].some(s=>s!==void 0&&s!==2))throw new Error("TypeScript LAZ encoder only supports legacy item version 2");if(!Number.isInteger(t.pointCount)||t.pointCount<0)throw new Error(`Invalid LAZ chunk point count ${t.pointCount}`);let e=Bu[t.pointDataRecordFormat];if(!e)throw new Error(`TypeScript LAZ encoder does not support point format ${t.pointDataRecordFormat}`);if(!Number.isInteger(t.pointDataRecordLength)||t.pointDataRecordLength<e)throw new Error(`Invalid point record length ${t.pointDataRecordLength} for point format ${t.pointDataRecordFormat}`);if(t.point14ItemVersion!==void 0&&t.point14ItemVersion!==3)throw new Error("TypeScript LAZ encoder only supports Point14 item version 3");if(t.pointDataRecordFormat>=7&&t.rgb14ItemVersion!==void 0&&t.rgb14ItemVersion!==3)throw new Error("TypeScript LAZ encoder only supports RGB14 item version 3");if((t.pointDataRecordFormat===9||t.pointDataRecordFormat===10)&&t.wavePacketItemVersion!==void 0&&t.wavePacketItemVersion!==3)throw new Error("TypeScript LAZ encoder only supports WavePacket14 item version 3");if(t.pointDataRecordLength>e&&t.byte14ItemVersion!==void 0&&t.byte14ItemVersion!==3)throw new Error("TypeScript LAZ encoder only supports Byte14 item version 3");let n=t.pointCount*t.pointDataRecordLength;if(r.byteLength!==n)throw new Error(`LAZ chunk input has ${r.byteLength} bytes; expected ${n}`)}function MS(r){if(!Number.isInteger(r.pointCount)||r.pointCount<=0||r.pointCount>4294967295)throw new Error(`Invalid LAZ chunk point count ${r.pointCount}`);if(!Number.isInteger(r.byteLength)||r.byteLength<=0||r.byteLength>4294967295)throw new Error(`Invalid LAZ chunk byte length ${r.byteLength}`)}function DS(r,t){let e=Bu[r];if(!e||t<e)throw new Error(`Invalid point record length ${t} for point format ${r}`);if(r<=5){let i=[{type:6,size:20}];(r===1||r===3||r===4||r===5)&&i.push({type:7,size:8}),(r===2||r===3||r===5)&&i.push({type:8,size:6}),(r===4||r===5)&&i.push({type:9,size:29,version:1});let o=t-e;return o>0&&i.push({type:0,size:o}),i}let n=[{type:10,size:30}];r===7?n.push({type:11,size:6}):r===8?n.push({type:12,size:8}):r===10&&n.push({type:12,size:8}),(r===9||r===10)&&n.push({type:13,size:29});let s=t-e;return s>0&&n.push({type:14,size:s}),n}function vb(r,t){let e=new DataView(r.buffer,r.byteOffset+t,30);return{x:e.getInt32(0,!0),y:e.getInt32(4,!0),z:e.getInt32(8,!0),intensity:e.getUint16(12,!0),returns:e.getUint8(14),flags:e.getUint8(15),classification:e.getUint8(16),userData:e.getUint8(17),scanAngle:e.getInt16(18,!0),pointSourceId:e.getUint16(20,!0),gpsTimeBits:e.getBigUint64(22,!0)}}function Ab(r,t){let e=new DataView(r.buffer,r.byteOffset+t,20);return{x:e.getInt32(0,!0),y:e.getInt32(4,!0),z:e.getInt32(8,!0),intensity:e.getUint16(12,!0),bitByte:e.getUint8(14),classification:e.getUint8(15),scanAngleRank:e.getInt8(16),userData:e.getUint8(17),pointSourceId:e.getUint16(18,!0)}}function vu(r,t){return{red:sc(r,t),green:sc(r,t+2),blue:sc(r,t+4)}}function Au(r,t){let e=new DataView(r.buffer,r.byteOffset+t,29);return{descriptorIndex:e.getUint8(0),offset:e.getBigUint64(1,!0),packetSize:e.getUint32(9,!0),returnPointBits:e.getInt32(13,!0),xBits:e.getInt32(17,!0),yBits:e.getInt32(21,!0),zBits:e.getInt32(25,!0)}}function Sb(r,t){return new DataView(r.buffer,r.byteOffset+t,8).getFloat64(0,!0)}function Bb(r,t){return BigInt.asIntN(64,Su(r)-Su(t))}function Su(r){let t=new ArrayBuffer(8),e=new DataView(t);return e.setFloat64(0,r,!0),e.getBigUint64(0,!0)}function sc(r,t){return r[t]|r[t+1]<<8}function CS(r,t){r.x=t.x,r.y=t.y,r.z=t.z,r.intensity=t.intensity,r.returns=t.returns,r.flags=t.flags,r.classification=t.classification,r.userData=t.userData,r.scanAngle=t.scanAngle,r.pointSourceId=t.pointSourceId,r.gpsTimeBits=t.gpsTimeBits}function Yo(r){return r.flags>>4&3}function Ib(r){return r.flags>>2&48|r.flags&15}function xr(r,t){return Array.from({length:r},()=>new Ot(t))}function be(r){return r&255}function FS(r){return r&255}function Xs(r){return Math.min(255,Math.max(0,r))}function Lb(r,t){let e=Math.fround(Math.fround(r)/Math.fround(t));return e>=0?Math.trunc(e+.5):Math.trunc(e-.5)}function OS(r){return r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Tb(r){let t=r.reduce((s,i)=>s+i.byteLength,0),e=new Uint8Array(t),n=0;for(let s of r)e.set(s,n),n+=s.byteLength;return e}function _b(r,t,e,n){for(let s=0;s<n;s++)r.setUint8(t+s,e.charCodeAt(s)||0)}var Bu,gb,bb,wr,Ki,wb,xb,SS,BS,IS,_S,Xd,Kd,Jd,Qd,yu,tp,ep,gu,rp,bu,np,wu,sp,xu,ip,Mb=p(()=>{"use strict";yb();Bu={0:20,1:28,2:26,3:34,4:57,5:63,6:30,7:36,8:38,9:59,10:67},gb=54,bb=34,wr=500,Ki=-10,wb=511,xb=wr-Ki+2,SS=[[0,1,2,3,4,5,3,4,4,5,5,5,5,5,5,5],[1,0,1,3,3,3,3,3,3,3,3,3,3,3,3,3],[2,1,2,4,4,4,4,4,4,4,4,3,3,3,3,3],[3,3,4,5,4,4,4,4,4,4,4,4,4,4,4,4],[4,3,4,4,5,4,4,4,4,4,4,4,4,4,4,4],[5,3,4,4,4,5,4,4,4,4,4,4,4,4,4,4],[3,3,4,4,4,4,5,4,4,4,4,4,4,4,4,4],[4,3,4,4,4,4,4,5,4,4,4,4,4,4,4,4],[4,3,4,4,4,4,4,4,5,4,4,4,4,4,4,4],[5,3,4,4,4,4,4,4,4,5,4,4,4,4,4,4],[5,3,4,4,4,4,4,4,4,4,5,4,4,4,4,4],[5,3,3,4,4,4,4,4,4,4,4,5,5,4,4,4],[5,3,3,4,4,4,4,4,4,4,4,5,5,5,4,4],[5,3,3,4,4,4,4,4,4,4,4,4,5,5,5,4],[5,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5],[5,3,3,4,4,4,4,4,4,4,4,4,4,4,5,5]],BS=[[15,14,13,12,11,10,9,8],[14,0,1,3,6,10,10,9],[13,1,2,4,7,11,11,10],[12,3,4,5,8,12,12,11],[11,6,7,8,9,13,13,12],[10,10,11,12,13,14,14,13],[9,10,11,12,13,14,15,14],[8,9,10,11,12,13,14,15]],IS=[[0,1,2,3,4,5,6,7],[1,0,1,2,3,4,5,6],[2,1,0,1,2,3,4,5],[3,2,1,0,1,2,3,4],[4,3,2,1,0,1,2,3],[5,4,3,2,1,0,1,2],[6,5,4,3,2,1,0,1],[7,6,5,4,3,2,1,0]],_S=[[0,1,2,3,4,5,6,7,7,7,7,7,7,7,7,7],[1,0,1,2,3,4,5,6,7,7,7,7,7,7,7,7],[2,1,0,1,2,3,4,5,6,7,7,7,7,7,7,7],[3,2,1,0,1,2,3,4,5,6,7,7,7,7,7,7],[4,3,2,1,0,1,2,3,4,5,6,7,7,7,7,7],[5,4,3,2,1,0,1,2,3,4,5,6,7,7,7,7],[6,5,4,3,2,1,0,1,2,3,4,5,6,7,7,7],[7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,7],[7,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7],[7,7,7,6,5,4,3,2,1,0,1,2,3,4,5,6],[7,7,7,7,6,5,4,3,2,1,0,1,2,3,4,5],[7,7,7,7,7,6,5,4,3,2,1,0,1,2,3,4],[7,7,7,7,7,7,6,5,4,3,2,1,0,1,2,3],[7,7,7,7,7,7,7,6,5,4,3,2,1,0,1,2],[7,7,7,7,7,7,7,7,6,5,4,3,2,1,0,1],[7,7,7,7,7,7,7,7,7,6,5,4,3,2,1,0]];Xd=class{encoder;changedValuesModel=new Ot(64);bitByteModels=xr(256,256);classificationModels=xr(256,256);scanAngleRankModels=xr(2,256);userDataModels=xr(256,256);intensityCompressor;pointSourceIdCompressor;xDifferenceCompressor;yDifferenceCompressor;zCompressor;lastIntensity=new Array(16).fill(0);lastHeight=new Array(8).fill(0);lastXDifferenceMedian=Array.from({length:16},()=>new Xi);lastYDifferenceMedian=Array.from({length:16},()=>new Xi);last;constructor(t,e){this.encoder=t,this.last={...e},this.intensityCompressor=new _t(t,16,4),this.pointSourceIdCompressor=new _t(t,16,1),this.xDifferenceCompressor=new _t(t,32,2),this.yDifferenceCompressor=new _t(t,32,22),this.zCompressor=new _t(t,32,20)}encode(t){let e=this.last,n=t.bitByte&7,s=t.bitByte>>3&7,i=BS[s][n],o=IS[s][n],a=(t.bitByte!==e.bitByte?32:0)|(t.intensity!==this.lastIntensity[i]?16:0)|(t.classification!==e.classification?8:0)|(t.scanAngleRank!==e.scanAngleRank?4:0)|(t.userData!==e.userData?2:0)|(t.pointSourceId!==e.pointSourceId?1:0);this.encoder.encodeSymbol(this.changedValuesModel,a),a&32&&this.encoder.encodeSymbol(this.bitByteModels[e.bitByte],t.bitByte),a&16&&(this.intensityCompressor.compress(this.lastIntensity[i],t.intensity,i<3?i:3),this.lastIntensity[i]=t.intensity),a&8&&this.encoder.encodeSymbol(this.classificationModels[e.classification],t.classification),a&4&&this.encoder.encodeSymbol(this.scanAngleRankModels[t.bitByte>>6&1],FS(t.scanAngleRank-e.scanAngleRank)),a&2&&this.encoder.encodeSymbol(this.userDataModels[e.userData],t.userData),a&1&&this.pointSourceIdCompressor.compress(e.pointSourceId,t.pointSourceId);let c=this.lastXDifferenceMedian[i].get(),l=We(t.x-e.x);this.xDifferenceCompressor.compress(c,l,s===1?1:0),this.lastXDifferenceMedian[i].add(l);let u=this.lastYDifferenceMedian[i].get(),f=Math.min(this.xDifferenceCompressor.k,20)&-2,h=We(t.y-e.y);this.yDifferenceCompressor.compress(u,h,(s===1?1:0)+f),this.lastYDifferenceMedian[i].add(h);let m=Math.min(this.xDifferenceCompressor.k+this.yDifferenceCompressor.k>>1,18)&-2;this.zCompressor.compress(this.lastHeight[o],t.z,(s===1?1:0)+m),this.lastHeight[o]=t.z,this.last={...t}}},Kd=class{encoder;gpsTimeMultiModel;gpsTime0DiffModel;gpsTime;lastGpsTime;lastGpsTimeDifference=[0,0,0,0];multiExtremeCounter=[0,0,0,0];lastGpsSequence=0;nextGpsSequence=0;constructor(t,e){this.encoder=t,this.gpsTimeMultiModel=new Ot(516),this.gpsTime0DiffModel=new Ot(6),this.gpsTime=new _t(t,32,9),this.lastGpsTime=[e,0,0,0]}encode(t){let e=this.lastGpsSequence,n=Bb(t,this.lastGpsTime[e]),s=Number(BigInt.asIntN(32,n)),i=n===BigInt(s);if(this.lastGpsTimeDifference[e]===0)if(i)s===0?this.encoder.encodeSymbol(this.gpsTime0DiffModel,0):(this.encoder.encodeSymbol(this.gpsTime0DiffModel,1),this.gpsTime.compress(0,s,0),this.lastGpsTimeDifference[e]=s,this.multiExtremeCounter[e]=0);else if(this.selectSequence(t,!1)){this.encode(t);return}else this.encoder.encodeSymbol(this.gpsTime0DiffModel,2),this.startSequence(t);else if(i){let o=this.lastGpsTimeDifference[e],a=Lb(s,o);a===1?(this.encoder.encodeSymbol(this.gpsTimeMultiModel,1),this.gpsTime.compress(o,s,1),this.multiExtremeCounter[e]=0):a>0&&a<wr?(this.encoder.encodeSymbol(this.gpsTimeMultiModel,a),this.gpsTime.compress(We(a*o),s,a<10?2:3)):a>=wr?(this.encoder.encodeSymbol(this.gpsTimeMultiModel,wr),this.gpsTime.compress(We(wr*o),s,4),this.recordExtremeDifference(e,s)):a<0&&a>Ki?(this.encoder.encodeSymbol(this.gpsTimeMultiModel,wr-a),this.gpsTime.compress(We(a*o),s,5)):a<0?(this.encoder.encodeSymbol(this.gpsTimeMultiModel,wr-Ki),this.gpsTime.compress(We(Ki*o),s,6),this.recordExtremeDifference(e,s)):(this.encoder.encodeSymbol(this.gpsTimeMultiModel,0),this.gpsTime.compress(0,s,7),this.recordExtremeDifference(e,s))}else if(this.selectSequence(t,!0)){this.encode(t);return}else this.encoder.encodeSymbol(this.gpsTimeMultiModel,xb),this.startSequence(t);this.lastGpsTime[this.lastGpsSequence]=t}selectSequence(t,e){for(let n=1;n<4;n++){let s=this.lastGpsSequence+n&3,i=Bb(t,this.lastGpsTime[s]);if(i===BigInt.asIntN(32,i))return this.encoder.encodeSymbol(e?this.gpsTimeMultiModel:this.gpsTime0DiffModel,e?xb+n:n+2),this.lastGpsSequence=s,!0}return!1}startSequence(t){let e=Su(this.lastGpsTime[this.lastGpsSequence]),n=Su(t);this.gpsTime.compress(Number(BigInt.asIntN(32,e>>32n)),Number(BigInt.asIntN(32,n>>32n)),8),this.encoder.writeInt(Number(n&0xffffffffn)),this.nextGpsSequence=this.nextGpsSequence+1&3,this.lastGpsSequence=this.nextGpsSequence,this.lastGpsTimeDifference[this.lastGpsSequence]=0,this.multiExtremeCounter[this.lastGpsSequence]=0}recordExtremeDifference(t,e){this.multiExtremeCounter[t]++,this.multiExtremeCounter[t]>3&&(this.multiExtremeCounter[t]=0,this.lastGpsTimeDifference[t]=e)}},Jd=class{encoder;usedModel=new Ot(128);differenceModels=xr(6,256);red;green;blue;constructor(t,e){this.encoder=t,this.red=e.red,this.green=e.green,this.blue=e.blue}encode(t){let e=this.red,n=this.green,s=this.blue,i=((t.red&255)!==(e&255)?1:0)|((t.red&65280)!==(e&65280)?2:0)|((t.green&255)!==(n&255)?4:0)|((t.green&65280)!==(n&65280)?8:0)|((t.blue&255)!==(s&255)?16:0)|((t.blue&65280)!==(s&65280)?32:0);((t.red&255)!==(t.green&255)||(t.red&255)!==(t.blue&255)||(t.red&65280)!==(t.green&65280)||(t.red&65280)!==(t.blue&65280))&&(i|=64),this.encoder.encodeSymbol(this.usedModel,i);let o=0,a=0;i&1&&(o=(t.red&255)-(e&255),this.encoder.encodeSymbol(this.differenceModels[0],be(o))),i&2&&(a=(t.red>>8)-(e>>8),this.encoder.encodeSymbol(this.differenceModels[1],be(a))),i&64&&(i&4&&this.encoder.encodeSymbol(this.differenceModels[2],be((t.green&255)-Xs(o+(n&255)))),i&16&&(o=Math.trunc((o+(t.green&255)-(n&255))/2),this.encoder.encodeSymbol(this.differenceModels[4],be((t.blue&255)-Xs(o+(s&255))))),i&8&&this.encoder.encodeSymbol(this.differenceModels[3],be((t.green>>8)-Xs(a+(n>>8)))),i&32&&(a=Math.trunc((a+(t.green>>8)-(n>>8))/2),this.encoder.encodeSymbol(this.differenceModels[5],be((t.blue>>8)-Xs(a+(s>>8)))))),this.red=t.red,this.green=t.green,this.blue=t.blue}},Qd=class{encoder;descriptorModel;offsetDifferenceModels;offsetDifferenceCompressor;packetSizeCompressor;returnPointCompressor;vectorCompressor;last;lastOffsetDifference=0;lastOffsetDifferenceSymbol=0;constructor(t,e){this.encoder=t,this.descriptorModel=new Ot(256),this.offsetDifferenceModels=xr(4,4),this.offsetDifferenceCompressor=new _t(t,32,1),this.packetSizeCompressor=new _t(t,32,1),this.returnPointCompressor=new _t(t,32,1),this.vectorCompressor=new _t(t,32,3),this.last={...e}}encode(t){let e=this.last;this.encoder.encodeSymbol(this.descriptorModel,t.descriptorIndex);let n=0;if(t.offset===e.offset)n=0;else if(t.offset===e.offset+BigInt(e.packetSize))n=1;else{let s=BigInt.asIntN(64,t.offset-e.offset);s===BigInt.asIntN(32,s)?n=2:n=3}if(this.encoder.encodeSymbol(this.offsetDifferenceModels[this.lastOffsetDifferenceSymbol],n),this.lastOffsetDifferenceSymbol=n,n===2){let s=Number(BigInt.asIntN(32,t.offset-e.offset));this.offsetDifferenceCompressor.compress(this.lastOffsetDifference,s,0),this.lastOffsetDifference=s}n===3&&(this.encoder.writeInt(Number(t.offset&0xffffffffn)),this.encoder.writeInt(Number(t.offset>>32n))),this.packetSizeCompressor.compress(e.packetSize,t.packetSize,0),this.returnPointCompressor.compress(e.returnPointBits,t.returnPointBits,0),this.vectorCompressor.compress(e.xBits,t.xBits,0),this.vectorCompressor.compress(e.yBits,t.yBits,1),this.vectorCompressor.compress(e.zBits,t.zBits,2),this.last={...t}}},yu=class{packet;descriptorModel=new Ot(256);offsetDifferenceModels=xr(4,4);offsetDifferenceCompressor;packetSizeCompressor;returnPointCompressor;vectorCompressor;lastOffsetDifference=0;lastOffsetDifferenceSymbol=0;haveLast=!1;constructor(t,e){this.packet={...e},this.offsetDifferenceCompressor=new _t(t,32,1),this.packetSizeCompressor=new _t(t,32,1),this.returnPointCompressor=new _t(t,32,1),this.vectorCompressor=new _t(t,32,3),this.haveLast=!0}},tp=class{encoder=new $t;contexts=new Array(4).fill(null);itemVersion;lastChannel;constructor(t,e,n){this.itemVersion=n,this.lastChannel=e,this.contexts[e]=new yu(this.encoder,t)}encode(t,e){let n=this.contexts[this.lastChannel],s=this.contexts[e],i=s;e!==this.lastChannel&&(s?this.itemVersion<4&&(i=s,s=n):(s=new yu(this.encoder,n.packet),this.contexts[e]=s,i=s),this.lastChannel=e),this.encodePacket(i,s,t)}finish(){return this.encoder.finish()}encodePacket(t,e,n){let s=e.packet;this.encoder.encodeSymbol(t.descriptorModel,n.descriptorIndex);let i=0;if(n.offset===s.offset?i=0:n.offset===s.offset+BigInt(s.packetSize)?i=1:BigInt.asIntN(64,n.offset-s.offset)===BigInt.asIntN(32,n.offset-s.offset)?i=2:i=3,this.encoder.encodeSymbol(t.offsetDifferenceModels[t.lastOffsetDifferenceSymbol],i),t.lastOffsetDifferenceSymbol=i,i===2){let o=Number(BigInt.asIntN(32,n.offset-s.offset));t.offsetDifferenceCompressor.compress(t.lastOffsetDifference,o,0),t.lastOffsetDifference=o}else i===3&&(this.encoder.writeInt(Number(n.offset&0xffffffffn)),this.encoder.writeInt(Number(n.offset>>32n)));t.packetSizeCompressor.compress(s.packetSize,n.packetSize,0),t.returnPointCompressor.compress(s.returnPointBits,n.returnPointBits,0),t.vectorCompressor.compress(s.xBits,n.xBits,0),t.vectorCompressor.compress(s.yBits,n.yBits,1),t.vectorCompressor.compress(s.zBits,n.zBits,2),e.packet={...n}}},ep=class{encoder;models;last;constructor(t,e){this.encoder=t,this.models=xr(e.byteLength,256),this.last=new Uint8Array(e)}encode(t){for(let e=0;e<t.byteLength;e++){let n=t[e]-this.last[e];this.encoder.encodeSymbol(this.models[e],be(n)),this.last[e]=t[e]}}},gu=class{changedValuesModels=xr(8,128);scannerChannelModel=new Ot(3);returnNumberGpsSameModel=new Ot(13);numberReturnsModels=new Array(16).fill(null);returnNumberModels=new Array(16).fill(null);classificationModels=new Array(64).fill(null);flagModels=new Array(64).fill(null);userDataModels=new Array(64).fill(null);gpsTimeMultiplierModel=new Ot(515);gpsTimeZeroDifferenceModel=new Ot(5);xDifferenceCompressor;yDifferenceCompressor;zCompressor;intensityCompressor;scanAngleCompressor;pointSourceIdCompressor;gpsTimeCompressor;lastXDifferenceMedian=Array.from({length:12},()=>new Xi);lastYDifferenceMedian=Array.from({length:12},()=>new Xi);lastZ;lastIntensity;lastGpsTimeBits;lastGpsTimeDifference=new Array(4).fill(0);gpsTimeExtremeCounter=new Array(4).fill(0);lastGpsSequence=0;nextGpsSequence=0;gpsTimeChanged=!1;last;constructor(t,e){this.last={...t},this.xDifferenceCompressor=new _t(e.xy,32,2),this.yDifferenceCompressor=new _t(e.xy,32,22),this.zCompressor=new _t(e.z,32,20),this.intensityCompressor=new _t(e.intensity,16,4),this.scanAngleCompressor=new _t(e.scanAngle,16,2),this.pointSourceIdCompressor=new _t(e.pointSourceId,16,1),this.gpsTimeCompressor=new _t(e.gpsTime,32,9),this.lastZ=new Array(8).fill(t.z),this.lastIntensity=new Array(8).fill(t.intensity),this.lastGpsTimeBits=[t.gpsTimeBits,0n,0n,0n]}},rp=class{layers={xy:new $t,z:new $t,classification:new $t,flags:new $t,intensity:new $t,scanAngle:new $t,userData:new $t,pointSourceId:new $t,gpsTime:new $t};contexts=new Array(4).fill(null);currentScannerChannel;changed={classification:!1,flags:!1,intensity:!1,scanAngle:!1,userData:!1,pointSourceId:!1,gpsTime:!1};constructor(t){this.currentScannerChannel=Yo(t),this.contexts[this.currentScannerChannel]=new gu(t,this.layers)}encode(t){let e=this.contexts[this.currentScannerChannel],n=e.last,s=Yo(t);s!==this.currentScannerChannel&&this.contexts[s]&&(n=this.contexts[s].last);let i=t.pointSourceId!==n.pointSourceId,o=t.gpsTimeBits!==n.gpsTimeBits,a=t.scanAngle!==n.scanAngle,c=n.returns>>4,l=n.returns&15,u=t.returns>>4,f=t.returns&15,h=(l===1?1:0)|(l>=c?2:0)|(e.gpsTimeChanged?4:0),m=(s!==this.currentScannerChannel?64:0)|(i?32:0)|(o?16:0)|(a?8:0)|(u!==c?4:0);f!==l&&(f===(l+1)%16?m|=1:f===(l+15)%16?m|=2:m|=3),this.layers.xy.encodeSymbol(e.changedValuesModels[h],m);let y=0;if(s!==this.currentScannerChannel){let xt=s-this.currentScannerChannel;this.layers.xy.encodeSymbol(e.scannerChannelModel,(xt+3)%4),this.contexts[s]||=new gu(e.last,this.layers),this.currentScannerChannel=s,y=s,n=this.contexts[s].last}let g=this.contexts[this.currentScannerChannel];if(u!==c){let xt=g.numberReturnsModels[c];xt||(xt=new Ot(16),g.numberReturnsModels[c]=xt),this.layers.xy.encodeSymbol(xt,u)}if((m&3)===3)if(o){let xt=g.returnNumberModels[l];xt||(xt=new Ot(16),g.returnNumberModels[l]=xt),this.layers.xy.encodeSymbol(xt,f)}else{let xt=f-l;this.layers.xy.encodeSymbol(g.returnNumberGpsSameModel,(xt+14)%16)}let x=SS[u][f],B=_S[u][f],q=(f===1?2:0)|(f>=u?1:0),M=x<<1|(o?1:0),b=g.lastXDifferenceMedian[M].get(),C=We(t.x-n.x);g.xDifferenceCompressor.compress(b,C,u===1?1:0),g.lastXDifferenceMedian[M].add(C);let _=g.lastYDifferenceMedian[M].get(),$=We(t.y-n.y),X=(u===1?1:0)|Math.min(g.xDifferenceCompressor.k,20)&-2;g.yDifferenceCompressor.compress(_,$,X),g.lastYDifferenceMedian[M].add($);let ft=(u===1?1:0)|Math.min(g.xDifferenceCompressor.k+g.yDifferenceCompressor.k>>1,18)&-2;g.zCompressor.compress(g.lastZ[B],t.z,ft),g.lastZ[B]=t.z,t.classification!==n.classification&&(this.changed.classification=!0);let dt=(n.classification&31)<<1|(q===3?1:0),Bt=g.classificationModels[dt];Bt||(Bt=new Ot(256),g.classificationModels[dt]=Bt),this.layers.classification.encodeSymbol(Bt,t.classification);let se=Ib(n),rt=Ib(t);rt!==se&&(this.changed.flags=!0);let tt=g.flagModels[se];tt||(tt=new Ot(64),g.flagModels[se]=tt),this.layers.flags.encodeSymbol(tt,rt),t.intensity!==n.intensity&&(this.changed.intensity=!0);let Ye=q<<1|(o?1:0);g.intensityCompressor.compress(g.lastIntensity[Ye],t.intensity,q),g.lastIntensity[Ye]=t.intensity,a&&(this.changed.scanAngle=!0,g.scanAngleCompressor.compress(n.scanAngle,t.scanAngle,o?1:0)),t.userData!==n.userData&&(this.changed.userData=!0);let Ne=n.userData>>2,Ze=g.userDataModels[Ne];return Ze||(Ze=new Ot(256),g.userDataModels[Ne]=Ze),this.layers.userData.encodeSymbol(Ze,t.userData),i&&(this.changed.pointSourceId=!0,g.pointSourceIdCompressor.compress(n.pointSourceId,t.pointSourceId)),o&&(this.changed.gpsTime=!0,this.encodeGpsTime(g,t.gpsTimeBits)),CS(g.last,t),g.gpsTimeChanged=o,y}finish(){return[this.layers.xy.finish(),this.layers.z.finish(),this.changed.classification?this.layers.classification.finish():new Uint8Array(0),this.changed.flags?this.layers.flags.finish():new Uint8Array(0),this.changed.intensity?this.layers.intensity.finish():new Uint8Array(0),this.changed.scanAngle?this.layers.scanAngle.finish():new Uint8Array(0),this.changed.userData?this.layers.userData.finish():new Uint8Array(0),this.changed.pointSourceId?this.layers.pointSourceId.finish():new Uint8Array(0),this.changed.gpsTime?this.layers.gpsTime.finish():new Uint8Array(0)]}encodeGpsTime(t,e){let n=t.lastGpsSequence,s=BigInt.asIntN(64,e-t.lastGpsTimeBits[n]),i=Number(BigInt.asIntN(32,s)),o=s===BigInt(i);if(t.lastGpsTimeDifference[n]===0)if(o)this.layers.gpsTime.encodeSymbol(t.gpsTimeZeroDifferenceModel,0),t.gpsTimeCompressor.compress(0,i,0),t.lastGpsTimeDifference[n]=i,t.gpsTimeExtremeCounter[n]=0;else if(this.selectGpsTimeSequence(t,e,!1)){this.encodeGpsTime(t,e);return}else this.layers.gpsTime.encodeSymbol(t.gpsTimeZeroDifferenceModel,1),this.startGpsTimeSequence(t,e);else if(o){let a=t.lastGpsTimeDifference[n],c=Lb(i,a);c===1?(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,1),t.gpsTimeCompressor.compress(a,i,1),t.gpsTimeExtremeCounter[n]=0):c>0?c<wr?(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,c),t.gpsTimeCompressor.compress(We(c*a),i,c<10?2:3)):(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,wr),t.gpsTimeCompressor.compress(We(wr*a),i,4),this.recordExtremeGpsDifference(t,n,i)):c<0?c>Ki?(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,wr-c),t.gpsTimeCompressor.compress(We(c*a),i,5)):(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,wr-Ki),t.gpsTimeCompressor.compress(We(Ki*a),i,6),this.recordExtremeGpsDifference(t,n,i)):(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,0),t.gpsTimeCompressor.compress(0,i,7),this.recordExtremeGpsDifference(t,n,i))}else if(this.selectGpsTimeSequence(t,e,!0)){this.encodeGpsTime(t,e);return}else this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,wb),this.startGpsTimeSequence(t,e);t.lastGpsTimeBits[t.lastGpsSequence]=e}selectGpsTimeSequence(t,e,n){for(let s=1;s<4;s++){let i=t.lastGpsSequence+s&3,o=BigInt.asIntN(64,e-t.lastGpsTimeBits[i]);if(o===BigInt.asIntN(32,o)){let a=n?wb+s:s+1,c=n?t.gpsTimeMultiplierModel:t.gpsTimeZeroDifferenceModel;return this.layers.gpsTime.encodeSymbol(c,a),t.lastGpsSequence=i,!0}}return!1}startGpsTimeSequence(t,e){let n=t.lastGpsTimeBits[t.lastGpsSequence];t.gpsTimeCompressor.compress(Number(BigInt.asIntN(32,n>>32n)),Number(BigInt.asIntN(32,e>>32n)),8),this.layers.gpsTime.writeInt(Number(e&0xffffffffn)),t.nextGpsSequence=t.nextGpsSequence+1&3,t.lastGpsSequence=t.nextGpsSequence,t.lastGpsTimeDifference[t.lastGpsSequence]=0,t.gpsTimeExtremeCounter[t.lastGpsSequence]=0}recordExtremeGpsDifference(t,e,n){t.gpsTimeExtremeCounter[e]++,t.gpsTimeExtremeCounter[e]>3&&(t.lastGpsTimeDifference[e]=n,t.gpsTimeExtremeCounter[e]=0)}},bu=class{red;green;blue;usedModel=new Ot(128);differenceModels=xr(6,256);constructor(t){this.red=t.red,this.green=t.green,this.blue=t.blue}},np=class{encoder=new $t;contexts=new Array(4).fill(null);currentContext;changed=!1;constructor(t,e){this.currentContext=e,this.contexts[e]=new bu(t)}encode(t,e){let n=this.contexts[this.currentContext];e!==this.currentContext&&(this.currentContext=e,this.contexts[e]||(this.contexts[e]=new bu({red:n.red,green:n.green,blue:n.blue}),n=this.contexts[e]));let s=this.contexts[this.currentContext],i=((t.red&255)!==(n.red&255)?1:0)|((t.red&65280)!==(n.red&65280)?2:0)|((t.green&255)!==(n.green&255)?4:0)|((t.green&65280)!==(n.green&65280)?8:0)|((t.blue&255)!==(n.blue&255)?16:0)|((t.blue&65280)!==(n.blue&65280)?32:0);((t.red&255)!==(t.green&255)||(t.red&255)!==(t.blue&255)||(t.red&65280)!==(t.green&65280)||(t.red&65280)!==(t.blue&65280))&&(i|=64),this.encoder.encodeSymbol(s.usedModel,i);let o=0,a=0;if(i&1&&(o=(t.red&255)-(n.red&255),this.encoder.encodeSymbol(s.differenceModels[0],be(o))),i&2&&(a=(t.red>>8)-(n.red>>8),this.encoder.encodeSymbol(s.differenceModels[1],be(a))),i&64){if(i&4){let c=(t.green&255)-Xs(o+(n.green&255));this.encoder.encodeSymbol(s.differenceModels[2],be(c))}if(i&16){o=Math.trunc((o+(t.green&255)-(n.green&255))/2);let c=(t.blue&255)-Xs(o+(n.blue&255));this.encoder.encodeSymbol(s.differenceModels[4],be(c))}if(i&8){let c=(t.green>>8)-Xs(a+(n.green>>8));this.encoder.encodeSymbol(s.differenceModels[3],be(c))}if(i&32){a=Math.trunc((a+(t.green>>8)-(n.green>>8))/2);let c=(t.blue>>8)-Xs(a+(n.blue>>8));this.encoder.encodeSymbol(s.differenceModels[5],be(c))}}this.changed||=i!==0,n.red=t.red,n.green=t.green,n.blue=t.blue}finish(){return this.changed?this.encoder.finish():new Uint8Array(0)}},wu=class{value;usedModel=new Ot(4);differenceModels=xr(2,256);constructor(t){this.value=t}},sp=class{encoder=new $t;contexts=new Array(4).fill(null);currentContext;changed=!1;constructor(t,e){this.currentContext=e,this.contexts[e]=new wu(t)}encode(t,e){let n=this.contexts[this.currentContext];e!==this.currentContext&&(this.currentContext=e,this.contexts[e]||(this.contexts[e]=new wu(n.value),n=this.contexts[e]));let s=this.contexts[this.currentContext],i=((t&255)!==(n.value&255)?1:0)|((t&65280)!==(n.value&65280)?2:0);this.encoder.encodeSymbol(s.usedModel,i),i&1&&this.encoder.encodeSymbol(s.differenceModels[0],be((t&255)-(n.value&255))),i&2&&this.encoder.encodeSymbol(s.differenceModels[1],be((t>>8)-(n.value>>8))),this.changed||=i!==0,n.value=t}finish(){return this.changed?this.encoder.finish():new Uint8Array(0)}},xu=class{values;models;constructor(t){this.values=t.slice(),this.models=xr(t.byteLength,256)}},ip=class{encoders;contexts=new Array(4).fill(null);changed;currentContext;constructor(t,e){this.encoders=Array.from({length:t.byteLength},()=>new $t),this.changed=new Array(t.byteLength).fill(!1),this.currentContext=e,this.contexts[e]=new xu(t)}encode(t,e){let n=this.contexts[this.currentContext];e!==this.currentContext&&(this.currentContext=e,this.contexts[e]||(this.contexts[e]=new xu(n.values),n=this.contexts[e]));let s=this.contexts[this.currentContext];for(let i=0;i<t.byteLength;i++){let o=t[i]-n.values[i];this.encoders[i].encodeSymbol(s.models[i],be(o)),o&&(this.changed[i]=!0,n.values[i]=t[i])}}finish(){return this.encoders.map((t,e)=>this.changed[e]?t.finish():new Uint8Array(0))}}});function ic(r){return{...r,batchType:"data",length:r.data.numRows}}var Db=p(()=>{"use strict"});var Zo=p(()=>{"use strict";Xg();Kg();tb();mb();Mb();Db()});function Cb(r,t){let e=ES(r);return Gi(t,e)}function ES(r){let t={};return t.las_pointsOffset=r.pointsOffset.toString(10),t.las_pointsFormatId=r.pointsFormatId.toString(10),t.las_pointsStructSize=r.pointsStructSize.toString(10),t.las_pointsCount=r.pointsCount.toString(10),t.las_scale=JSON.stringify(r.scale),t.las_offset=JSON.stringify(r.offset),r.maxs!==void 0&&(t.las_maxs=JSON.stringify(r.maxs)),r.mins!==void 0&&(t.las_mins=JSON.stringify(r.mins)),t.las_totalToRead=r.totalToRead.toString(10),t.las_pointsFortotalReadmatId=r.totalRead.toString(10),r.versionAsString!==void 0&&(t.las_versionAsString=r.versionAsString),r.isCompressed!==void 0&&(t.las_isCompressed=r.isCompressed.toString()),t}var Fb=p(()=>{"use strict";or()});function Ob(r,t){let e=t.vlrs.find(y=>y.userId==="lascompatible"&&y.recordId===22204);if(!e)return;if(!["1.0","1.1","1.2","1.3"].includes(r.versionAsString||"")||![1,3,4,5].includes(r.pointsFormatId))throw new Error("LASLoader: compatibility mode requires a legacy LAS point format");let n=new DataView(e.data.buffer,e.data.byteOffset,e.data.byteLength);if(n.byteLength<4)throw new Error("LASLoader: truncated LASzip compatibility VLR");let s=n.getUint16(2,!0);if(s!==3&&s!==4||n.byteLength!==(s===3?156:174))throw new Error(`LASLoader: unsupported LASzip compatibility VLR version ${s} or length`);let i=new Map,o=0;for(let y of t.extraBytes){let g=y.dataType>20?y.dataType-20:y.dataType>10?y.dataType-10:y.dataType,x=y.dataType>20?3:y.dataType>10?2:1,B=y.dataType===0?y.options:g<=2?x:g<=4?2*x:g<=6||g===9?4*x:8*x;if(y.dataType>30||!B)throw new Error("LASLoader: invalid compatibility Extra Bytes layout");i.set(y.name,{byteOffset:o,dataType:y.dataType}),o+=B}let a={1:28,3:34,4:57,5:63}[r.pointsFormatId];if(o!==r.pointsStructSize-a)throw new Error("LASLoader: compatibility descriptors do not match point record length");let c=oc(i,"LAS 1.4 scan angle",4),l=oc(i,"LAS 1.4 extended returns",1),u=oc(i,"LAS 1.4 classification",1),f=oc(i,"LAS 1.4 flags and channel",1),h=i.has("LAS 1.4 NIR band")?oc(i,"LAS 1.4 NIR band",3):void 0,m=r.pointsFormatId===1?6:r.pointsFormatId===3?h===void 0?7:8:r.pointsFormatId===4?9:10;if(r.pointsFormatId===5&&h===void 0)throw new Error("LASLoader: compatibility waveform color points require NIR");return{pointDataRecordFormat:m,version:s===3?"1.4":"1.5",scanAngleByteOffset:c,returnsByteOffset:l,classificationByteOffset:u,flagsByteOffset:f,nirByteOffset:h}}function oc(r,t,e){let n=r.get(t);if(!n||n.dataType!==e)throw new Error(`LASLoader: missing or invalid compatibility field ${t}`);return n.byteOffset}function lp(r,t,e,n,s){if(!s.classifications&&!s.returnNumbers&&!s.numberOfReturns&&!s.scanAngles&&!s.overlapFlags&&!s.scannerChannels&&!s.nir)return;let i=r.getUint8(t+n.returnsByteOffset),o=r.getUint8(t+n.flagsByteOffset);if(s.classifications&&(s.classifications[e]+=r.getUint8(t+n.classificationByteOffset)),s.returnNumbers&&(s.returnNumbers[e]+=i>>4),s.numberOfReturns&&(s.numberOfReturns[e]+=i&15),s.scanAngles){let a=s.scanAngles[e],c=Math.fround(a/Math.fround(.006)),l=Math.sign(c)*Math.floor(Math.abs(c)+.5);s.scanAngles[e]=l+r.getInt16(t+n.scanAngleByteOffset,!0)}s.overlapFlags&&(s.overlapFlags[e]=o&1),s.scannerChannels&&(s.scannerChannels[e]=o>>1&3),s.nir&&n.nirByteOffset!==void 0&&(s.nir[e]=r.getUint16(t+n.nirByteOffset,!0))}var Eb=p(()=>{"use strict"});function Nb(r){if(r.byteLength%192!==0)throw new Error(`LAS Extra Bytes VLR length ${r.byteLength} is not a multiple of 192`);let t=[],e=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let n=0;n<r.byteLength;n+=192){let s=[e.getFloat64(n+112,!0),e.getFloat64(n+120,!0),e.getFloat64(n+128,!0)],i=[e.getFloat64(n+136,!0),e.getFloat64(n+144,!0),e.getFloat64(n+152,!0)];t.push({dataType:r[n+2],options:r[n+3],name:Ub(r,n+4,32),description:Ub(r,n+160,32),scale:s[0],offset:i[0],scales:s,offsets:i,data:r.slice(n,n+192)})}return t}function Rb(r,t,e){let n=0,s=new Set,i=[];for(let o=0;o<t.length;o++){let a=t[o],c=NS(a.dataType),l=RS(a.dataType),f=PS(c)*l;if(a.dataType<1||a.dataType>30||!f)throw new Error(`Unsupported typed LAS Extra Bytes data type ${a.dataType}`);let h=`EXTRA_BYTES_${US(a.name)}`;h==="EXTRA_BYTES_"&&(h=`EXTRA_BYTES_${o}`);let m=h,y=1;for(;s.has(h);)h=`${m}_${y++}`;s.add(h);let g=a.options&8?a.scales.slice(0,l):new Array(l).fill(1),x=a.options&16?a.offsets.slice(0,l):new Array(l).fill(0),q=c!==10&&(c===7||c===8?g.some(M=>M!==1)||x.some(M=>M!==0):!!(a.options&24));i.push({name:h,value:up(c,r*l,q),size:l,scalarDataType:c,byteOffset:n,byteLength:f,outputFloat64:q,scales:g,offsets:x}),n+=f}if(n!==e)throw new Error(`LAS Extra Bytes descriptors use ${n} bytes; point records provide ${e}`);return i}function Ub(r,t,e){return new TextDecoder().decode(r.subarray(t,t+e)).replace(/\0+$/,"").trim()}function US(r){return r.trim().replace(/[^A-Za-z0-9_]+/g,"_")}function NS(r){return r>20?r-20:r>10?r-10:r}function RS(r){return r>20?3:r>10?2:1}function PS(r){return r<=2?1:r<=4?2:r<=6||r===9?4:r===7||r===8||r===10?8:0}function kS(r,t,e){switch(e){case 1:return r.getUint8(t);case 2:return r.getInt8(t);case 3:return r.getUint16(t,!0);case 4:return r.getInt16(t,!0);case 5:return r.getUint32(t,!0);case 6:return r.getInt32(t,!0);case 7:return r.getBigUint64(t,!0);case 8:return r.getBigInt64(t,!0);case 9:return r.getFloat32(t,!0);case 10:return r.getFloat64(t,!0);default:throw new Error(`Unsupported typed LAS Extra Bytes scalar data type ${e}`)}}function up(r,t,e){if(e&&r!==10)return new Float64Array(t);switch(r){case 1:return new Uint8Array(t);case 2:return new Int8Array(t);case 3:return new Uint16Array(t);case 4:return new Int16Array(t);case 5:return new Uint32Array(t);case 6:return new Int32Array(t);case 7:return new BigUint64Array(t);case 8:return new BigInt64Array(t);case 9:return new Float32Array(t);case 10:return new Float64Array(t);default:throw new Error(`Unsupported typed LAS Extra Bytes scalar data type ${r}`)}}function fp(r,t,e,n,s){let i=kS(r,t,e.scalarDataType);e.value instanceof BigInt64Array||e.value instanceof BigUint64Array?e.value[n]=i:e.value[n]=Number(i)*e.scales[s]+e.offsets[s]}var Pb=p(()=>{"use strict"});function Js(r,t,e){return{pointDataRecordFormat:r.pointsFormatId,pointDataRecordLength:r.pointsStructSize,pointCount:e,point10ItemVersion:t.items.find(n=>n.type===6)?.version,gpsTime11ItemVersion:t.items.find(n=>n.type===7)?.version,rgb12ItemVersion:t.items.find(n=>n.type===8)?.version,byteItemVersion:t.items.find(n=>n.type===0)?.version,point14ItemVersion:t.point14ItemVersion??void 0,rgb14ItemVersion:t.rgb14ItemVersion??void 0,wavePacketItemVersion:t.wavePacketItemVersion??void 0,byte14ItemVersion:t.byte14ItemVersion??void 0}}function jb(r,t={}){let e=Hb(r);if(e.isCompressed){let s=new Uint8Array(r),i=gp(s,e);if(bp(e,i),e.pointsFormatId<=5||e.pointsFormatId>=6&&e.pointsFormatId<=10)return WS(s,e,i,t);let o=e2(r,e,i),a=e.pointsCount;return _u(o,{...e,pointsOffset:0,pointsCount:a,totalToRead:a,totalRead:a},t)}let n=e.pointsCount;return _u(r,{...e,totalToRead:n,totalRead:n},t)}function qb(r,t,e){if(t.pointDataRecordFormat<6||t.pointDataRecordFormat>8)throw new Error(`LASLoader: standalone Arrow chunk decode supports PDRF 6-8; received ${t.pointDataRecordFormat}`);let n=t.pointCount,s={pointsOffset:0,pointsFormatId:t.pointDataRecordFormat,pointsStructSize:t.pointDataRecordLength,pointsCount:n,scale:t.scale,offset:t.offset,maxs:[0,0,0],mins:[0,0,0],totalToRead:n,totalRead:n,hasColor:Xb(t.pointDataRecordFormat),versionAsString:"1.4",isCompressed:!0,headerSize:Gb,vlrCount:0},i=Du(n,s,e);if(i.waveforms||i.extraBytes||i.typedExtraBytes)throw new Error("LASLoader: standalone Arrow chunk decode only supports direct LAZ columns");let a=Gr(r,t).decodeIntoPointData(i.target,n);if(a!==n)throw new Error(`LASLoader: standalone LAZ chunk produced ${a} points; expected ${n}`);return $b(s,i,n,e,!0)}function WS(r,t,e,n){let s=t.pointsCount,i=Du(s,t,n),o=wp(r,t,e,n),a=0,c=t.pointsOffset+(e.compressor===1?0:Wt);for(let l of o)YS(r,c,l.byteLength,l.pointCount,t,e,i,a),c+=l.byteLength,a+=l.pointCount;if(a!==s)throw new Error(`LASLoader: decoded ${a} LAZ points; expected ${s}`);return $b(t,i,s,n)}function $b(r,t,e,n,s=!1){let i=s&&t.rawColors?t.rawColors:t.colors?t.colors:t.rawColors?e1(t.rawColors,e,n):null;return hp({...r,pointsOffset:0,pointsCount:e,totalRead:e},t.positions,i,t.intensities,t.classifications,t.syntheticFlags,t.keyPointFlags,t.withheldFlags,t.overlapFlags,t.gpsTimes,t.nir,t.scanAngles,t.userData,t.pointSourceIds,t.returnNumbers,t.numberOfReturns,t.scannerChannels,t.scanDirectionFlags,t.edgeOfFlightLines,t.waveforms,t.extraBytes,t.typedExtraBytes)}function YS(r,t,e,n,s,i,o,a){let c=r.subarray(t,t+e);if(c.byteLength!==e)throw new it("LASLoader: truncated LAZ chunk");let l=Gr(c,Js(s,i,n));o.target.pointOffset=a;let u=l.decodeIntoPointData(o.target,n);if(u!==n)throw new Error(`LASLoader: decoded ${u} points from a ${n}-point LAZ chunk`);vp(o,a,n)}async function*Wb(r,t={}){let e=Xo(t),n=k2(r),s=new Uint8Array(0),i=0,o=null,a=0,c=0;for(;;){let l=await n.next();if(l.done)break;let u=l.value;if(s=r1(s,Bp(u)),o||(o=P2(s,i),o&&(o.totalToRead=o.pointsCount)),!!o){if(o.isCompressed){yield*XS(s,n,o,t);return}for(let f of N2(s,i,o,a,c,e))a=f.sourcePointIndex,c=f.totalRead,s=f.pending,i=f.absoluteOffset,yield _u(f.arrayBuffer,f.header,t)}}if(!o)throw new Error("LASLoader: incomplete LAS header");if(c<o.totalToRead)throw new Error("LASLoader: truncated LAS point data")}async function*ZS(r,t,e,n,s){if(n.variableChunks){let m=await x2(r,t);yield*Zb(m,e,n,s);return}if(e.pointsFormatId<=5){yield*HS(r,t,e,n,s);return}let i={...e,totalToRead:e.pointsCount},o=Xo(s),a=Mu(o,e.pointsStructSize,Cu(s)),c=0,l=[],u=new js;u.write(r),await Qi(u,t,e.pointsOffset+Wt,"LASLoader: incomplete compressed LAZ point data"),u.skip(e.pointsOffset);let f=Fu(u.getDataView(Wt));for(;c<e.pointsCount;){let m=Math.min(n.chunkSize,e.pointsCount-c),y=Js(e,n,m),g=await B2(u,t,y);l.push(g),Ap(u,g,a.stats);let x=u.readBytes(g);s.las?.recoverMissingChunkTable&&f===e.pointsOffset&&xp(x,y);for(let B of Sp(x,y,i,a))yield B;c+=m}await Tu(u,t,e,n,f,l,s);let h=Ji(i,a);h&&(yield h)}async function*HS(r,t,e,n,s={}){let i={...e,totalToRead:e.pointsCount},o=Xo(s),a=Mu(o,e.pointsStructSize,Cu(s)),c=[],l=new js;l.write(r),await Qi(l,t,e.pointsOffset+(n.compressor===1?0:Wt),"LASLoader: incomplete compressed LAZ point data"),l.skip(e.pointsOffset);let u=n.compressor===1?0:Fu(l.getDataView(Wt)),f=0;for(;f<e.pointsCount;){let m=n.compressor===1?e.pointsCount:Math.min(n.chunkSize,e.pointsCount-f),y=Js(e,n,m),g=Gr(new Uint8Array(0),y),x=0,B=0,q=!1;for(;g.remainingPointCount>0;){let M=l.getAvailableByteLength(),b=Yb(M,x,g.requiredInputByteLength-B);if(b>x){let X=l.checkpoint();l.skip(x);let ft=b-x;Ap(l,ft,a.stats),g.feed(l.readBytes(ft)),l.restore(X),x=b}let C=o-a.batchPointCount,_=g.decodeAvailableInto(a.rawBatch,a.batchPointCount*e.pointsStructSize,C,q);if(_>0){if(n.compressor===1){let X=g.compressedByteOffset-B;l.skip(X),x-=X,B=g.compressedByteOffset,g.discardConsumedInput()}if(a.batchPointCount+=_,a.batchPointCount===o){let X=Ji(i,a);X&&(yield X)}continue}if(q)throw new it(`LASLoader: truncated legacy LAZ chunk after ${m-g.remainingPointCount} of ${m} points with ${M} bytes available`);let $=await t.next();$.done?q=!0:l.write($.value)}l.skip(g.compressedByteOffset-B),c.push(g.compressedByteOffset),f+=m}n.compressor!==1&&await Tu(l,t,e,n,u,c,s);let h=Ji(i,a);h&&(yield h)}function Yb(r,t,e){return Math.min(r,Math.max(e,t+$S))}async function*XS(r,t,e,n){let{pending:s,laszip:i}=await w2(r,t,e);if(bp(e,i),!i.variableChunks&&e.pointsFormatId<=5){yield*KS(s,t,e,i,n);return}if(!i.variableChunks&&e.pointsFormatId>=6&&e.pointsFormatId<=10){yield*JS(s,t,e,i,n);return}for await(let o of ZS(s,t,e,i,n))yield _u(o.arrayBuffer,o.header,n)}async function*KS(r,t,e,n,s){let i={...e,totalToRead:e.pointsCount},o=Du(Xo(s),e,s),a=Cu(s),c=[],l=new js;l.write(r),await Qi(l,t,e.pointsOffset+(n.compressor===1?0:Wt),"LASLoader: incomplete compressed LAZ point data"),l.skip(e.pointsOffset);let u=n.compressor===1?0:Fu(l.getDataView(Wt)),f=0;for(;f<e.pointsCount;){let m=n.compressor===1?e.pointsCount:Math.min(n.chunkSize,e.pointsCount-f),y=Js(e,n,m),g=Gr(new Uint8Array(0),y),x=0,B=0,q=!1;for(;g.remainingPointCount>0;){let M=l.getAvailableByteLength(),b=Yb(M,x,g.requiredInputByteLength-B);if(b>x){let X=l.checkpoint();l.skip(x);let ft=b-x;Ap(l,ft,a),g.feed(l.readBytes(ft)),l.restore(X),x=b}o.target.pointOffset=o.batchPointCount;let C=o.batchCapacity-o.batchPointCount,_=g.decodeAvailableIntoPointData(o.target,C,q);if(_>0){if(n.compressor===1){let X=g.compressedByteOffset-B;l.skip(X),x-=X,B=g.compressedByteOffset,g.discardConsumedInput()}if(vp(o,o.batchPointCount,_),o.batchPointCount+=_,o.batchPointCount===o.batchCapacity){let X=Lu(i,o,s);X&&(yield X)}continue}if(q)throw new it(`LASLoader: truncated legacy LAZ chunk after ${m-g.remainingPointCount} of ${m} points with ${M} bytes available`);let $=await t.next();$.done?q=!0:l.write($.value)}l.skip(g.compressedByteOffset-B),c.push(g.compressedByteOffset),f+=m}n.compressor!==1&&await Tu(l,t,e,n,u,c,s);let h=Lu(i,o,s);h&&(yield h)}async function*JS(r,t,e,n,s){let i={...e,totalToRead:e.pointsCount},o=Du(Xo(s),e,s),a=0,c=[],l=new js;l.write(r),await Qi(l,t,e.pointsOffset+Wt,"LASLoader: incomplete compressed LAZ point data"),l.skip(e.pointsOffset);let u=Fu(l.getDataView(Wt));for(;a<e.pointsCount;){let h=Math.min(n.chunkSize,e.pointsCount-a),m=Js(e,n,h),y=yield*QS(l,t,m,i,o,s,!!(s.las?.recoverMissingChunkTable&&u===e.pointsOffset));c.push(y),a+=h}await Tu(l,t,e,n,u,c,s);let f=Lu(i,o,s);f&&(yield f)}async function*QS(r,t,e,n,s,i,o){let a=hu(e);await Qi(r,t,a,"LASLoader: incomplete layered LAZ chunk header");let c=r.readBytes(a);o&&xp(c,e);let l=du(c,e),u=$d(e);u.feed(c);let f=a;for(;f<l;){if(yield*kb(u,n,s,i),r.getAvailableByteLength()===0){let m=await t.next();if(m.done)throw new it("LASLoader: incomplete layered LAZ chunk payload");r.write(m.value)}let h=Math.min(r.getAvailableByteLength(),l-f);u.feed(r.readBytes(h)),f+=h}if(u.close(),yield*kb(u,n,s,i),u.remainingPointCount!==0)throw new it(`LASLoader: layered LAZ chunk produced ${e.pointCount-u.remainingPointCount} of ${e.pointCount} points`);return l}function*kb(r,t,e,n){for(;r.remainingPointCount>0;){let s=e.batchCapacity-e.batchPointCount;e.target.pointOffset=e.batchPointCount;let i=r.readPointDataBatch(e.target,s);if(!i)return;if(vp(e,e.batchPointCount,i),e.batchPointCount+=i,e.batchPointCount===e.batchCapacity){let o=Lu(t,e,n);o&&(yield o)}}}function*t2(r,t,e,n,s={}){let i=n||gp(new Uint8Array(r),t);if(bp(t,i),t.pointsFormatId<=5||i.variableChunks){yield*Zb(new Uint8Array(r),t,i,{...s,batchSize:e});return}let o={...t,totalToRead:t.pointsCount},a=Mu(e,t.pointsStructSize),c=new Uint8Array(r),l=wp(c,t,i,s),u=t.pointsOffset+(i.compressor===1?0:Wt);for(let h of l){let m=Js(t,i,h.pointCount),y=c.subarray(u,u+h.byteLength);for(let g of Sp(y,m,o,a))yield g;u+=h.byteLength}let f=Ji(o,a);f&&(yield f)}function*Zb(r,t,e,n={}){let s=Xo(n),i={...t,totalToRead:t.pointsCount},o=Mu(s,t.pointsStructSize,Cu(n)),a=wp(r,t,e,n),c=t.pointsOffset+(e.compressor===1?0:Wt);for(let u of a){let f=r.subarray(c,c+u.byteLength);if(f.byteLength<u.byteLength)throw new it("LASLoader: truncated legacy LAZ chunk");let h=Js(t,e,u.pointCount);if(e.compressor===1)yield*Sp(f,h,i,o);else{let m=fu(f,h);C2(m.byteLength,o.stats),yield*F2(m,i,o)}c+=u.byteLength}let l=Ji(i,o);l&&(yield l)}function e2(r,t,e){let n=t.pointsCount,s=new Uint8Array(n*t.pointsStructSize),i=0;for(let o of t2(r,t,zb,e)){let a=new Uint8Array(o.arrayBuffer);s.set(a,i),i+=a.byteLength}return s}function Hb(r){let t=new DataView(r);if(r.byteLength<227||t.getUint32(0,!0)!==Vb)throw new Error("LASLoader: invalid LAS header");let e=t.getUint8(24),n=t.getUint8(25);if(e!==1||n>5)throw new Error(`LASLoader: unsupported LAS version ${e}.${n}`);let s=t.getUint16(94,!0),i=t.getUint16(6,!0),o=t.getUint32(100,!0),a=t.getUint8(104),c=a&VS,l=!!(a&zS),u=t.getUint32(107,!0),h=(e>1||n>=4?Ks(t,247):u)||u,m=t.getUint32(96,!0),y=t.getUint16(105,!0);if(n===5){if(s<393)throw new Error("LASLoader: LAS 1.5 header must be at least 393 bytes");if(c<6||c>10)throw new Error(`LASLoader: LAS 1.5 requires point data record formats 6-10; received ${c}`);if((i&16)===0)throw new Error("LASLoader: LAS 1.5 requires the WKT global encoding flag");if((i&65440)!==0)throw new Error("LASLoader: LAS 1.5 Global Encoding contains reserved bits");if((i&64)!==0&&(i&1)===0)throw new Error("LASLoader: LAS 1.5 Time Offset Flag requires GPS Time Type");let b=t.getFloat64(375,!0),C=t.getFloat64(383,!0);if(!Number.isFinite(b)||!Number.isFinite(C)||b!==0&&C!==0&&b<C)throw new Error("LASLoader: LAS 1.5 GPS time range is invalid")}let g=[t.getFloat64(131,!0),t.getFloat64(139,!0),t.getFloat64(147,!0)],x=[t.getFloat64(155,!0),t.getFloat64(163,!0),t.getFloat64(171,!0)],B=[t.getFloat64(179,!0),t.getFloat64(195,!0),t.getFloat64(211,!0)],q=[t.getFloat64(187,!0),t.getFloat64(203,!0),t.getFloat64(219,!0)],M={pointsOffset:m,pointsFormatId:c,pointsStructSize:y,pointsCount:h,scale:g,offset:x,maxs:B,mins:q,totalToRead:h,totalRead:0,hasColor:Xb(c),versionAsString:`${e}.${n}`,isCompressed:l,headerSize:s,vlrCount:o,userHeaderData:n===5&&s>393?new Uint8Array(r,393,s-393).slice():void 0};return r2(r,M)&&(M.metadata=n2(r,M)),M}function r2(r,t){let e=t.headerSize+t.vlrCount*54;return r.byteLength>=Math.max(e,t.pointsOffset)}function n2(r,t){let e=new DataView(r),s=(t.versionAsString||"1.0").split(".").map(Number),i=s[0]>1||s[0]===1&&s[1]>=4,o=s2(e,t),a=i?Ks(e,235):0,c=i?e.getUint32(243,!0):0,l=i2(e,a,c),u={fileSourceId:e.getUint16(4,!0),globalEncoding:e.getUint16(6,!0),waveformDataOffset:s[0]>1||s[0]===1&&s[1]>=3?e.getBigUint64(227,!0):void 0,projectId:f2(new Uint8Array(r,8,16)),systemIdentifier:Ho(new Uint8Array(r),26,32),generatingSoftware:Ho(new Uint8Array(r),58,32),creationDayOfYear:e.getUint16(90,!0),creationYear:e.getUint16(92,!0),headerSize:t.headerSize,userHeaderData:t.userHeaderData,vlrCount:t.vlrCount,evlrOffset:a||void 0,evlrCount:c||void 0,maxGpsTime:s[1]===5?e.getFloat64(375,!0):void 0,minGpsTime:s[1]===5?e.getFloat64(383,!0):void 0,timeOffset:s[1]===5?e.getUint16(391,!0):void 0,pointsByReturn:u2(e,i),vlrs:o,evlrs:l,extraBytes:[],waveformPacketDescriptors:[]};for(let f of o.concat(l.map(h=>({...h,data:h.data||new Uint8Array}))))o2(f,u);return u.compatibility=Ob(t,u),a2(u),u}function s2(r,t){let e=new Uint8Array(r.buffer,r.byteOffset,r.byteLength),n=[],s=t.headerSize;for(let i=0;i<t.vlrCount&&!(s+54>e.byteLength);i++){let o=r.getUint16(s+20,!0),a=s+54;if(a+o>e.byteLength)break;n.push({reserved:r.getUint16(s,!0),userId:Ho(e,s+2,16),recordId:r.getUint16(s+18,!0),description:Ho(e,s+22,32),offset:s,data:e.slice(a,a+o)}),s=a+o}return n}function i2(r,t,e){if(!t||!e||t>=r.byteLength)return[];let n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength),s=[],i=t;for(let o=0;o<e&&!(i+60>n.byteLength);o++){let a=Ks(r,i+20),c=i+60;if(a>n.byteLength-c)break;s.push({reserved:r.getUint16(i,!0),userId:Ho(n,i+2,16),recordId:r.getUint16(i+18,!0),description:Ho(n,i+28,32),offset:i,data:n.slice(c,c+a),dataOffset:c,dataLength:a}),i=c+a}return s}function o2(r,t){let e=r.data;e&&(r.userId==="LASF_Spec"&&r.recordId===4?t.extraBytes.push(...Nb(e)):r.userId==="LASF_Spec"&&r.recordId>=100&&r.recordId<=354?t.waveformPacketDescriptors.push(l2(r.recordId,e)):r.userId==="LASF_Projection"&&r.recordId===2111?t.wktMathTransform=Iu(e):r.userId==="LASF_Projection"&&r.recordId===2112?t.wkt=Iu(e):r.userId==="LASF_Projection"&&r.recordId===34735?t.geotiff={...t.geotiff,keys:h2(e)}:r.userId==="LASF_Projection"&&r.recordId===34736?t.geotiff={...t.geotiff,doubles:d2(e)}:r.userId==="LASF_Projection"&&r.recordId===34737&&(t.geotiff={...t.geotiff,ascii:Iu(e)}))}function a2(r){let t=r.geotiff,e=t?.keys;if(!t||!e||e.length<4)return;let n=e[3];if(e.length<4+n*4)return;let s=[];for(let i=0;i<n;i++){let o=4+i*4,a={keyId:e[o],tiffTagLocation:e[o+1],count:e[o+2],valueOffset:e[o+3]};a.value=c2(a,t),a.value===void 0&&delete a.value,s.push(a)}t.keyDirectory={version:e[0],keyRevision:e[1],minorRevision:e[2],entries:s}}function c2(r,t){if(r.tiffTagLocation===0)return r.valueOffset;if(r.tiffTagLocation===34735&&t.keys){let e=t.keys.slice(r.valueOffset,r.valueOffset+r.count);return e.length===r.count?Array.from(e):void 0}if(r.tiffTagLocation===34736&&t.doubles){let e=t.doubles.slice(r.valueOffset,r.valueOffset+r.count);return e.length!==r.count?void 0:r.count===1?e[0]:Array.from(e)}if(r.tiffTagLocation===34737&&t.ascii!==void 0){let e=r.valueOffset+r.count;return e>t.ascii.length?void 0:t.ascii.slice(r.valueOffset,e).replace(/\|$/,"")}}function l2(r,t){if(t.byteLength<28)throw new Error(`LASLoader: waveform descriptor VLR ${r} is truncated`);let e=new DataView(t.buffer,t.byteOffset,t.byteLength);return{recordId:r,bitsPerSample:e.getUint8(2),compressionType:e.getUint8(3),numberOfSamples:e.getUint32(4,!0),temporalSampleSpacing:e.getUint32(8,!0),digitizerGain:e.getFloat64(12,!0),digitizerOffset:e.getFloat64(20,!0)}}function u2(r,t){let e=t?15:5,n=t?255:111,s=[];for(let i=0;i<e;i++)s.push(t?Ks(r,n+i*8):r.getUint32(n+i*4,!0));return s}function Ho(r,t,e){return Iu(r.subarray(t,t+e))}function Iu(r){let t=r.length;for(;t>0&&r[t-1]===0;)t--;return new TextDecoder().decode(r.subarray(0,t)).trim()}function f2(r){let t=(n,s)=>Array.from(r.subarray(n,n+s),i=>i.toString(16).padStart(2,"0")).reverse().join(""),e=(n,s)=>Array.from(r.subarray(n,n+s),i=>i.toString(16).padStart(2,"0")).join("");return`${t(0,4)}-${t(4,2)}-${t(6,2)}-${e(8,2)}${e(10,6)}`}function h2(r){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),e=new Uint16Array(Math.floor(r.byteLength/2));for(let n=0;n<e.length;n++)e[n]=t.getUint16(n*2,!0);return e}function d2(r){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),e=new Float64Array(Math.floor(r.byteLength/8));for(let n=0;n<e.length;n++)e[n]=t.getFloat64(n*8,!0);return e}function _u(r,t,e={}){let n=t.pointsCount,s=e.las?.fp64?Float64Array:Float32Array,i=new s(n*3),o=t1(e),a=t.hasColor&&o.color?new Uint8Array(n*4):null,c=o.intensity?new Uint16Array(n):null,l=o.classification?new Uint8Array(n):null,u=o.synthetic?new Uint8Array(n):null,f=o.keyPoint?new Uint8Array(n):null,h=o.withheld?new Uint8Array(n):null,m=o.overlap?new Uint8Array(n):null,y=o.gpsTime&&mp(t.pointsFormatId)>=0?new Float64Array(n):null,g=o.nir&&(yp(t.pointsFormatId)>=0||e.las?.compatibilityMode!=="raw"&&t.metadata?.compatibility?.nirByteOffset!==void 0)?new Uint16Array(n):null,x=o.scanAngle?new Int16Array(n):null,B=o.userData?new Uint8Array(n):null,q=o.pointSourceId?new Uint16Array(n):null,M=o.returnNumber?new Uint8Array(n):null,b=o.numberOfReturns?new Uint8Array(n):null,C=o.scannerChannel?new Uint8Array(n):null,_=o.scanDirectionFlag?new Uint8Array(n):null,$=o.edgeOfFlightLine?new Uint8Array(n):null,X=o.waveform&&pp(t.pointsFormatId)>=0?new Uint8Array(n*29):null,ft=Math.max(0,t.pointsStructSize-Pn(t.pointsFormatId)),dt=o.extraBytes&&e.las?.extraBytes!=="typed"&&ft?new Uint8Array(n*ft):null,Bt=o.extraBytes&&e.las?.extraBytes==="typed"?Jb(n,t):null;return m2(p2(r),t,e,{positions:i,colors:a,intensities:c,classifications:l,syntheticFlags:u,keyPointFlags:f,withheldFlags:h,overlapFlags:m,gpsTimes:y,nir:g,scanAngles:x,userData:B,pointSourceIds:q,returnNumbers:M,numberOfReturns:b,scannerChannels:C,scanDirectionFlags:_,edgeOfFlightLines:$,waveforms:X,extraBytes:dt,typedExtraBytes:Bt,pointOffset:0,sourcePointIndex:0,pointCount:n}),hp(t,i,a,c,l,u,f,h,m,y,g,x,B,q,M,b,C,_,$,X,dt,Bt)}function hp(r,t,e,n,s,i,o,a,c,l,u,f,h,m,y,g,x,B,q,M,b,C){let _={POSITION:{value:t,size:3}};if(n&&(_.intensity={value:n,size:1}),s&&(_.classification={value:s,size:1}),i&&(_.synthetic={value:i,size:1}),o&&(_.keyPoint={value:o,size:1}),a&&(_.withheld={value:a,size:1}),c&&(_.overlap={value:c,size:1}),e&&(_.COLOR_0={value:e,size:e instanceof Uint16Array?3:4}),l&&(_.GPS_TIME={value:l,size:1}),u&&(_.NIR={value:u,size:1}),f&&(_.scanAngle={value:f,size:1}),h&&(_.userData={value:h,size:1}),m&&(_.pointSourceId={value:m,size:1}),y&&(_.returnNumber={value:y,size:1}),g&&(_.numberOfReturns={value:g,size:1}),x&&(_.scannerChannel={value:x,size:1}),B&&(_.scanDirectionFlag={value:B,size:1}),q&&(_.edgeOfFlightLine={value:q,size:1}),M&&(_.WAVEFORM={value:M,size:29}),b&&(_.EXTRA_BYTES={value:b,size:b.length/Math.max(r.pointsCount,1)}),C)for(let ft of C)_[ft.name]={value:ft.value,size:ft.size};let $={};for(let[ft,dt]of Object.entries(_))!(dt.value instanceof BigInt64Array)&&!(dt.value instanceof BigUint64Array)&&($[ft]={...dt,value:dt.value});let X=Cb(r,$);return{...Zl(_,{schema:X,topology:"point-list",mode:0,boundingBox:U2(r)}),loader:"las",loaderData:r,progress:r.totalRead/r.totalToRead}}function p2(r){return ArrayBuffer.isView(r)?new DataView(r.buffer,r.byteOffset,r.byteLength):new DataView(r)}function m2(r,t,e,n){let{scale:[s,i,o],offset:[a,c,l]}=t,u=t.pointsFormatId,f=t.pointsStructSize,h=n.colors?dp(u):-1,m=h>=0?g2(r,t,n.sourcePointIndex,n.pointCount,e.las?.colorDepth):!1,y=n.intensities,g=n.classifications,x=n.syntheticFlags,B=n.keyPointFlags,q=n.withheldFlags,M=n.overlapFlags,b=n.gpsTimes,C=n.nir,_=n.scanAngles,$=n.userData,X=n.pointSourceIds,ft=n.returnNumbers,dt=n.numberOfReturns,Bt=n.scannerChannels,se=n.scanDirectionFlags,rt=n.edgeOfFlightLines,tt=n.waveforms,Ye=n.extraBytes,Ne=n.typedExtraBytes,Ze=b?mp(u):-1,xt=C?yp(u):-1;for(let Gn=0;Gn<n.pointCount;Gn++){let Qs=n.sourcePointIndex+Gn,wt=t.pointsOffset+Qs*f,pt=n.pointOffset+Gn;n.positions[pt*3]=r.getInt32(wt,!0)*s+a,n.positions[pt*3+1]=r.getInt32(wt+4,!0)*i+c,n.positions[pt*3+2]=r.getInt32(wt+8,!0)*o+l,y&&(y[pt]=r.getUint16(wt+12,!0)),g&&(g[pt]=y2(r,wt,u)),b&&Ze>=0&&(b[pt]=r.getFloat64(wt+Ze,!0)),C&&xt>=0&&(C[pt]=r.getUint16(wt+xt,!0)),_&&(_[pt]=u<=5?r.getInt8(wt+16):r.getInt16(wt+18,!0)),$&&($[pt]=r.getUint8(wt+17)),X&&(X[pt]=r.getUint16(wt+(u<=5?18:20),!0));let un=r.getUint8(wt+14),qr=r.getUint8(wt+15),fn=u<=5?qr>>5:qr;if(x&&(x[pt]=fn&1),B&&(B[pt]=fn>>1&1),q&&(q[pt]=fn>>2&1),M&&(M[pt]=u<=5?0:fn>>3&1),ft&&(ft[pt]=u<=5?un&7:un&15),dt&&(dt[pt]=u<=5?un>>3&7:un>>4),Bt&&(Bt[pt]=u<=5?0:qr>>4&3),se&&(se[pt]=u<=5?un>>6&1:qr>>6&1),rt&&(rt[pt]=u<=5?un>>7&1:qr>>7&1),tt){let vr=pp(u);if(vr>=0){let Ar=new Uint8Array(r.buffer,r.byteOffset+wt+vr,29);tt.set(Ar,pt*29)}}if(Ye){let vr=Pn(u),Ar=t.pointsStructSize-vr;Ar>0&&Ye.set(new Uint8Array(r.buffer,r.byteOffset+wt+vr,Ar),pt*Ar)}if(Ne&&M2(r,wt,u,pt,Ne),e.las?.compatibilityMode!=="raw"&&t.metadata?.compatibility&&lp(r,wt+Pn(u),pt,t.metadata.compatibility,n),h>=0&&n.colors){let vr=r.getUint16(wt+h,!0),Ar=r.getUint16(wt+h+2,!0),eo=r.getUint16(wt+h+4,!0);n.colors[pt*4]=m?vr/256:vr,n.colors[pt*4+1]=m?Ar/256:Ar,n.colors[pt*4+2]=m?eo/256:eo,n.colors[pt*4+3]=255}}}function y2(r,t,e){return e<=5?r.getUint8(t+15)&31:r.getUint8(t+16)}function Xb(r){return dp(r)>=0}function dp(r){switch(r){case 2:return 20;case 3:return 28;case 5:return 28;case 7:case 8:case 10:return 30;default:return-1}}function pp(r){switch(r){case 4:return 28;case 5:return 34;case 9:return 30;case 10:return 38;default:return-1}}function mp(r){return r===1||r===3||r===4||r===5?20:r>=6&&r<=10?22:-1}function yp(r){return r===8||r===10?36:-1}function g2(r,t,e,n,s){if(s===8)return!1;if(s===16)return!0;if(s!=="auto")return!1;let i=dp(t.pointsFormatId);if(i<0)return!1;for(let o=0;o<n;o++){let a=t.pointsOffset+(e+o)*t.pointsStructSize;if(r.getUint16(a+i,!0)>255||r.getUint16(a+i+2,!0)>255||r.getUint16(a+i+4,!0)>255)return!0}return!1}function Xo(r){let t=r.batchSize??r.core?.batchSize;return typeof t=="number"?t:zb}function gp(r,t){let e=new DataView(r.buffer,r.byteOffset,r.byteLength),n=t.headerSize||Gb,s=t.vlrCount||0;for(let i=0;i<s;i++){if(n+54>r.byteLength)throw new it("LASLoader: incomplete VLR header");let o=E2(r,n+2,16),a=e.getUint16(n+18,!0),c=e.getUint16(n+20,!0),l=n+54;if(l+c>r.byteLength)throw new it("LASLoader: incomplete VLR data");if(o===GS&&a===jS){if(c<34)throw new Error("LASLoader: malformed LASzip VLR");let u=e.getUint32(l+12,!0),f=e.getUint16(l+32,!0);if(34+f*6>c)throw new Error("LASLoader: malformed LASzip VLR item table");let m=null,y=null,g=null,x=null,B=null,q=[];for(let M=0;M<f;M++){let b=l+34+M*6,C=e.getUint16(b,!0),_=e.getUint16(b+2,!0),$=e.getUint16(b+4,!0);if(q.push({type:C,size:_,version:$}),[0,6,7,8].includes(C)){if($!==1&&$!==2)throw new Error(`LASLoader: unsupported legacy LASzip item type ${C} version ${$}`)}else if(C===9){if($!==1)throw new Error(`LASLoader: unsupported WavePacket13 item version ${$}`);g=$}else if([10,11,12,14].includes(C)){if($!==2&&$!==3&&$!==4)throw new Error(`LASLoader: unsupported LAS 1.4 item type ${C} version ${$}`);C===10?m=$:C===11||C===12?y=$:B=$}else if(C===13){if($!==3&&$!==4)throw new Error(`LASLoader: unsupported WavePacket14 item version ${$}`);x=$}}return{compressor:e.getUint16(l,!0),coder:e.getUint16(l+2,!0),chunkSize:u,variableChunks:e.getUint16(l,!0)!==1&&(u===0||u===qS),items:q,point14ItemVersion:m,rgb14ItemVersion:y,wavePacket13ItemVersion:g,wavePacketItemVersion:x,byte14ItemVersion:B}}n=l+c}throw new Error("LASLoader: compressed LAZ file does not contain a LASzip VLR")}function bp(r,t){if(![0,1,2,3,4,5,6,7,8,9,10].includes(r.pointsFormatId))throw new Error(`LASLoader: TypeScript LAZ streaming only supports point formats 0-10; received ${r.pointsFormatId}`);if(r.pointsFormatId<=5&&t.compressor!==1&&t.compressor!==2)throw new Error(`LASLoader: legacy TypeScript LAZ decoding requires LASzip compressor 1 or 2; received ${t.compressor}`);if(r.pointsFormatId>=6&&t.compressor!==3)throw new Error(`LASLoader: LAS 1.4 TypeScript LAZ decoding requires LASzip compressor 3; received ${t.compressor}`);if(t.coder!==0)throw new Error(`LASLoader: TypeScript LAZ decoding requires LASzip arithmetic coder 0; received ${t.coder}`);if(b2(r,t.items),r.pointsFormatId>=6&&!t.point14ItemVersion)throw new Error(`LASLoader: point format ${r.pointsFormatId} requires a Point14 LASzip item`);if((r.pointsFormatId===4||r.pointsFormatId===5)&&!t.wavePacket13ItemVersion)throw new Error(`LASLoader: point format ${r.pointsFormatId} requires a WavePacket13 LASzip item`);if((r.pointsFormatId===7||r.pointsFormatId===8||r.pointsFormatId===10)&&!t.rgb14ItemVersion)throw new Error(`LASLoader: point format ${r.pointsFormatId} requires an RGB14 or RGBNIR14 LASzip item`);if(r.pointsFormatId>=6&&r.pointsStructSize>Pn(r.pointsFormatId)&&!t.byte14ItemVersion)throw new Error(`LASLoader: point format ${r.pointsFormatId} with Extra Bytes requires a Byte14 LASzip item`);if((r.pointsFormatId===9||r.pointsFormatId===10)&&!t.wavePacketItemVersion)throw new Error(`LASLoader: point format ${r.pointsFormatId} requires a WavePacket14 LASzip item`)}function b2(r,t){let e=r.pointsFormatId,n=Pn(e),s=r.pointsStructSize-n;if(s<0)throw new Error(`LASLoader: point format ${e} record length ${r.pointsStructSize} is smaller than ${n}`);let i=[];switch(e){case 0:i.push({type:6,size:20});break;case 1:i.push({type:6,size:20},{type:7,size:8});break;case 2:i.push({type:6,size:20},{type:8,size:6});break;case 3:i.push({type:6,size:20},{type:7,size:8},{type:8,size:6});break;case 4:i.push({type:6,size:20},{type:7,size:8},{type:9,size:29});break;case 5:i.push({type:6,size:20},{type:7,size:8},{type:8,size:6},{type:9,size:29});break;case 6:i.push({type:10,size:30});break;case 7:i.push({type:10,size:30},{type:11,size:6});break;case 8:i.push({type:10,size:30},{type:12,size:8});break;case 9:i.push({type:10,size:30},{type:13,size:29});break;case 10:i.push({type:10,size:30},{type:12,size:8},{type:13,size:29});break;default:return}if(s>0&&i.push({type:e<=5?0:14,size:s}),t.length!==i.length)throw new Error(`LASLoader: point format ${e} has ${t.length} LASzip items; expected ${i.length}`);for(let o=0;o<i.length;o++){let a=t[o],c=i[o];if(a.type!==c.type)throw new Error(`LASLoader: LASzip item ${o} has type ${a.type}; expected ${c.type} for point format ${e}`);if(a.size!==c.size)throw new Error(`LASLoader: LASzip item ${o} has size ${a.size}; expected ${c.size} for point format ${e}`)}}async function w2(r,t,e){let n=r;for(;;){try{return{pending:n,laszip:gp(n,e)}}catch(i){if(!(i instanceof it))throw i}let s=await t.next();if(s.done)throw new it("LASLoader: incomplete LASzip VLR");n=r1(n,Bp(s.value))}}async function x2(r,t){let e=[r],n=r.byteLength;for(;;){let o=await t.next();if(o.done)break;let a=Bp(o.value);e.push(a),n+=a.byteLength}if(e.length===1)return r;let s=new Uint8Array(n),i=0;for(let o of e)s.set(o,i),i+=o.byteLength;return s}async function Tu(r,t,e,n,s,i,o){if(o.las?.recoverMissingChunkTable&&s===e.pointsOffset){if(n.variableChunks)throw new Error("LASLoader: cannot recover a missing variable-size LAZ chunk table");for(;;){if(r.getAvailableByteLength())throw new Error("LASLoader: unexpected bytes after recovered LAZ chunks");let h=await t.next();if(h.done)return;r.write(h.value)}}let a=i.reduce((h,m)=>h+m,0),c=e.pointsOffset+Wt+a,l=s===-1?c:s;if(!Number.isSafeInteger(l)||l<c)throw new Error("LASLoader: LAZ chunk table byte lengths overlap the chunk table");let u=l-c;await Qi(r,t,u,"LASLoader: incomplete LAZ chunk table"),r.skip(u);let f=await S2(r,t,e,n);if(f.length!==i.length)throw new Error(`LASLoader: LAZ chunk table contains ${f.length} chunks; decoded ${i.length}`);for(let h=0;h<f.length;h++)if(f[h].byteLength!==i[h])throw new Error(`LASLoader: LAZ chunk ${h} has ${f[h].byteLength} table bytes; decoded ${i[h]}`);s===-1&&await v2(r,t,l)}async function v2(r,t,e){let n=new Uint8Array(Wt),s=0;for(;;){let o=r.getAvailableByteLength();if(o>0){let c=r.readBytes(Math.min(o,65536));A2(n,c),s+=c.byteLength;continue}let a=await t.next();if(a.done)break;r.write(a.value)}if(s<Wt)throw new it("LASLoader: incomplete non-seekable LAZ chunk-table footer");let i=Ks(new DataView(n.buffer),0);if(!Number.isSafeInteger(i)||i!==e)throw new Error(`LASLoader: non-seekable LAZ footer points to ${i}; expected ${e}`)}function A2(r,t){if(t.byteLength>=r.byteLength){r.set(t.subarray(t.byteLength-r.byteLength));return}r.copyWithin(0,t.byteLength),r.set(t,r.byteLength-t.byteLength)}async function S2(r,t,e,n){let s=64;for(;;){let i=r.getAvailableByteLength();if(i>=8){let a=r.checkpoint();try{let c=r.readBytes(Math.min(i,s)),l=Kb(c,e,n);return r.restore(a),l}catch(c){if(r.restore(a),!(c instanceof it))throw c;if(s*=2,s<=i)continue}}let o=await t.next();if(o.done)throw new it("LASLoader: incomplete LAZ chunk table");r.write(o.value)}}async function Qi(r,t,e,n){for(;!r.hasAvailableBytes(e);){let s=await t.next();if(s.done)throw new it(n);r.write(s.value)}}async function B2(r,t,e){for(;;){let n=r.checkpoint(),s;try{s=I2(r,e)}finally{r.restore(n)}if(s!==null)return await Qi(r,t,s,"LASLoader: truncated LAZ chunk"),s;let i=await t.next();if(i.done)throw new it("LASLoader: truncated LAZ chunk");r.write(i.value)}}function I2(r,t){if(t.pointDataRecordFormat<6||t.pointDataRecordFormat>10)return null;let e=t.pointDataRecordLength-Pn(t.pointDataRecordFormat);if(e<0)throw new Error(`Invalid point record length ${t.pointDataRecordLength}`);let n=_2(t.pointDataRecordFormat)+e,s=t.pointDataRecordLength+4,i=n*4,o=s+i;if(!r.hasAvailableBytes(o))return null;r.skip(s);let a=o;for(let c=0;c<n;c++)a+=r.readUint32LE();return a}function Pn(r){switch(r){case 0:return 20;case 1:return 28;case 2:return 26;case 3:return 34;case 4:return 57;case 5:return 63;case 6:return 30;case 7:return 36;case 8:return 38;case 9:return 59;case 10:return 67;default:throw new Error(`Unsupported LAS point format ${r}`)}}function _2(r){switch(r){case 6:return 9;case 7:return 10;case 8:return 11;case 9:return 10;case 10:return 12;default:throw new Error(`Unsupported LAS 1.4 point format ${r}`)}}function wp(r,t,e,n){if(e.compressor===1)return[{pointCount:t.pointsCount,byteLength:r.byteLength-t.pointsOffset}];let s=z2(new DataView(r.buffer,r.byteOffset,r.byteLength),t.pointsOffset);return L2(r,t,e,s,n)}function L2(r,t,e,n,s){if(s.las?.recoverMissingChunkTable&&n===t.pointsOffset)return T2(r,t,e);if(!Number.isSafeInteger(n)||n<0||n+8>r.byteLength)throw new it("LASLoader: incomplete LAZ chunk table");let i=Kb(r.subarray(n),t,e),o=i.reduce((a,c)=>a+c.byteLength,0);if(t.pointsOffset+Wt+o>n)throw new Error("LASLoader: LAZ chunk table byte lengths overlap the chunk table");return i}function T2(r,t,e){if(e.variableChunks||!e.chunkSize)throw new Error("LASLoader: cannot recover a missing variable-size LAZ chunk table");let n=[],s=t.pointsOffset+Wt,i=0;for(;i<t.pointsCount;){let o=Math.min(e.chunkSize,t.pointsCount-i),a=Js(t,e,o),c=r.subarray(s),l;if(t.pointsFormatId<=5){let u=Gr(c,a),f=new Uint8Array(Math.min(o,256)*t.pointsStructSize);for(;u.remainingPointCount;)u.decodeInto(f,0,Math.min(u.remainingPointCount,256));l=u.compressedByteOffset}else xp(c,a),l=du(c,a);if(!l||s+l>r.byteLength)throw new it("LASLoader: truncated LAZ chunk during table recovery");n.push({pointCount:o,byteLength:l}),s+=l,i+=o}if(s!==r.byteLength)throw new Error("LASLoader: unexpected bytes after recovered LAZ chunks");return n}function xp(r,t){if(r.byteLength<t.pointDataRecordLength+4)throw new it("LASLoader: truncated recovered layered LAZ chunk header");let n=new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(t.pointDataRecordLength,!0);if(n!==t.pointCount)throw new Error(`LASLoader: recovered layered LAZ chunk contains ${n} points; expected ${t.pointCount}`)}function Kb(r,t,e){if(r.byteLength<8)throw new it("LASLoader: incomplete LAZ chunk table");let n=new DataView(r.buffer,r.byteOffset,r.byteLength),s=n.getUint32(0,!0),i=n.getUint32(4,!0);if(s!==0)throw new Error(`LASLoader: unsupported LAZ chunk table version ${s}`);if(i===0){if(t.pointsCount!==0)throw new Error("LASLoader: missing LAZ chunk table");return[]}let o=Wd(r.subarray(8),{chunkCount:i,pointCount:t.pointsCount,chunkSize:e.chunkSize,variable:e.variableChunks}),a=0;for(let c of o){if(c.pointCount===0||c.byteLength===0)throw new Error("LASLoader: invalid empty LAZ chunk-table entry");a+=c.pointCount}if(a!==t.pointsCount)throw new Error(`LASLoader: LAZ chunk table contains ${a} points; expected ${t.pointsCount}`);return o}function Mu(r,t,e){return e&&e.rawBatchAllocations++,{rawBatch:new Uint8Array(r*t),batchPointCount:0,totalRead:0,rawBatchAllocations:1,stats:e}}function Du(r,t,e){let n=e.las?.fp64?Float64Array:Float32Array,s=new n(r*3),i=t1(e),o=t.hasColor&&i.color&&(e.las?.colorDepth===16||e.las?.colorDepth==="auto"),a=t.hasColor&&i.color&&!o?new Uint8Array(r*4):null,c=o?new Uint16Array(r*3):null,l=i.intensity?new Uint16Array(r):null,u=i.classification?new Uint8Array(r):null,f=i.synthetic?new Uint8Array(r):null,h=i.keyPoint?new Uint8Array(r):null,m=i.withheld?new Uint8Array(r):null,y=i.overlap?new Uint8Array(r):null,g=i.gpsTime&&mp(t.pointsFormatId)>=0?new Float64Array(r):null,x=i.nir&&(yp(t.pointsFormatId)>=0||e.las?.compatibilityMode!=="raw"&&t.metadata?.compatibility?.nirByteOffset!==void 0)?new Uint16Array(r):null,B=i.scanAngle?new Int16Array(r):null,q=i.userData?new Uint8Array(r):null,M=i.pointSourceId?new Uint16Array(r):null,b=i.returnNumber?new Uint8Array(r):null,C=i.numberOfReturns?new Uint8Array(r):null,_=i.scannerChannel?new Uint8Array(r):null,$=i.scanDirectionFlag?new Uint8Array(r):null,X=i.edgeOfFlightLine?new Uint8Array(r):null,ft=i.waveform&&pp(t.pointsFormatId)>=0?new Uint8Array(r*29):null,dt=Math.max(0,t.pointsStructSize-Pn(t.pointsFormatId)),Bt=i.extraBytes&&e.las?.extraBytes!=="typed"&&dt?new Uint8Array(r*dt):null,se=i.extraBytes&&e.las?.extraBytes==="typed"?Jb(r,t):null,rt=se?.length&&dt?new Uint8Array(r*dt):null,tt=i.classification||i.returnNumber||i.numberOfReturns||i.scanAngle||i.overlap||i.scannerChannel||i.nir,Ye=e.las?.compatibilityMode==="raw"||!tt?null:t.metadata?.compatibility||null,Ne=Ye&&!Bt&&!rt?new Uint8Array(r*dt):null;return{batchCapacity:r,positions:s,colors:a,rawColors:c,intensities:l,classifications:u,syntheticFlags:f,keyPointFlags:h,withheldFlags:m,overlapFlags:y,gpsTimes:g,nir:x,scanAngles:B,userData:q,pointSourceIds:M,returnNumbers:b,numberOfReturns:C,scannerChannels:_,scanDirectionFlags:$,edgeOfFlightLines:X,waveforms:ft,extraBytes:Bt,typedExtraBytes:se,typedExtraBytesSource:rt,compatibilityLayout:Ye,compatibilityExtraBytesSource:Ne,target:{positions:s,intensities:l,classifications:u,syntheticFlags:f,keyPointFlags:h,withheldFlags:m,overlapFlags:y,gpsTimes:g,nir:x,scanAngles:B,userData:q,pointSourceIds:M,returnNumbers:b,numberOfReturns:C,scannerChannels:_,scanDirectionFlags:$,edgeOfFlightLines:X,waveforms:ft,extraBytes:Bt||rt||Ne,colors:a,rawColors:c,pointOffset:0,scale:t.scale,offset:t.offset},batchPointCount:0,totalRead:0}}function Jb(r,t){let e=t.pointsStructSize-Pn(t.pointsFormatId);return Rb(r,t.metadata?.extraBytes||[],e)}function Qb(r){return r<=2?1:r<=4?2:r<=6||r===9?4:r===7||r===8||r===10?8:0}function M2(r,t,e,n,s){let i=t+Pn(e);for(let o of s){let a=n*o.size,c=i+o.byteOffset;for(let l=0;l<o.size;l++)fp(r,c+l*Qb(o.scalarDataType),o,a+l,l)}}function D2(r,t,e,n,s){let i=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let o=0;o<n;o++){let a=e+o,c=a*t;for(let l of s){let u=a*l.size,f=Qb(l.scalarDataType);for(let h=0;h<l.size;h++)fp(i,c+l.byteOffset+h*f,l,u+h,h)}}}function vp(r,t,e){let n=r.extraBytes||r.typedExtraBytesSource||r.compatibilityExtraBytesSource;if(r.compatibilityLayout&&n&&e){let s=new DataView(n.buffer,n.byteOffset,n.byteLength),i=n.length/r.batchCapacity;for(let o=t;o<t+e;o++)lp(s,o*i,o,r.compatibilityLayout,r)}!r.typedExtraBytesSource||!r.typedExtraBytes?.length||e===0||D2(r.typedExtraBytesSource,r.typedExtraBytesSource.length/r.batchCapacity,t,e,r.typedExtraBytes)}function Cu(r){return r.las?.lazStreamingStats}function Ap(r,t,e){if(!e)return;let n=r.findBufferOffsets(t);n&&n.length>1&&(e.copiedBytes+=t,e.chunkConcatenations++)}function C2(r,t){t&&(t.copiedBytes+=r,t.decodedChunkAllocations++)}function*Sp(r,t,e,n){let s=e.pointsStructSize,i=Gr(r,t);for(;i.remainingPointCount>0;){let o=n.rawBatch.byteLength/s,a=o-n.batchPointCount,c=i.decodeInto(n.rawBatch,n.batchPointCount*s,a);if(n.batchPointCount+=c,n.batchPointCount===o){let l=Ji(e,n);l&&(yield l)}}}function*F2(r,t,e){let n=t.pointsStructSize,s=r.byteLength/n;for(let i=0;i<s;i++){let o=i*n,a=e.batchPointCount*n;if(e.rawBatch.set(r.subarray(o,o+n),a),e.batchPointCount++,e.batchPointCount===e.rawBatch.byteLength/n){let c=Ji(t,e);c&&(yield c)}}}function Ji(r,t){if(t.batchPointCount===0)return null;let e=t.batchPointCount*r.pointsStructSize,n=e===t.rawBatch.byteLength,s=n?t.rawBatch.buffer:t.rawBatch.buffer.slice(0,e);t.totalRead+=t.batchPointCount;let i={...r,pointsOffset:0,pointsCount:t.batchPointCount,totalRead:t.totalRead};return t.batchPointCount=0,n&&(t.rawBatch=new Uint8Array(t.rawBatch.byteLength),t.rawBatchAllocations++,t.stats&&t.stats.rawBatchAllocations++),{arrayBuffer:s,header:i}}function Lu(r,t,e){if(t.batchPointCount===0)return null;t.totalRead+=t.batchPointCount;let n={...r,pointsOffset:0,pointsCount:t.batchPointCount,totalRead:t.totalRead},s=t.batchPointCount,i=s===t.batchCapacity,o=i?t.positions:t.positions.subarray(0,s*3),a=t.intensities?i?t.intensities:t.intensities.subarray(0,s):null,c=t.classifications?i?t.classifications:t.classifications.subarray(0,s):null,l=t.syntheticFlags?i?t.syntheticFlags:t.syntheticFlags.subarray(0,s):null,u=t.keyPointFlags?i?t.keyPointFlags:t.keyPointFlags.subarray(0,s):null,f=t.withheldFlags?i?t.withheldFlags:t.withheldFlags.subarray(0,s):null,h=t.overlapFlags?i?t.overlapFlags:t.overlapFlags.subarray(0,s):null,m=t.colors?i?t.colors:t.colors.subarray(0,s*4):t.rawColors?e1(t.rawColors,s,e):null,y=t.gpsTimes?i?t.gpsTimes:t.gpsTimes.subarray(0,s):null,g=t.nir?i?t.nir:t.nir.subarray(0,s):null,x=t.scanAngles?i?t.scanAngles:t.scanAngles.subarray(0,s):null,B=t.userData?i?t.userData:t.userData.subarray(0,s):null,q=t.pointSourceIds?i?t.pointSourceIds:t.pointSourceIds.subarray(0,s):null,M=t.returnNumbers?i?t.returnNumbers:t.returnNumbers.subarray(0,s):null,b=t.numberOfReturns?i?t.numberOfReturns:t.numberOfReturns.subarray(0,s):null,C=t.scannerChannels?i?t.scannerChannels:t.scannerChannels.subarray(0,s):null,_=t.scanDirectionFlags?i?t.scanDirectionFlags:t.scanDirectionFlags.subarray(0,s):null,$=t.edgeOfFlightLines?i?t.edgeOfFlightLines:t.edgeOfFlightLines.subarray(0,s):null,X=t.waveforms?i?t.waveforms:t.waveforms.subarray(0,s*29):null,ft=t.extraBytes?t.extraBytes.length/t.batchCapacity:0,dt=t.extraBytes?i?t.extraBytes:t.extraBytes.subarray(0,s*ft):null,Bt=t.typedExtraBytes?t.typedExtraBytes.map(rt=>({...rt,value:i?rt.value:rt.value.subarray(0,s*rt.size)})):null,se=hp(n,o,m,a,c,l,u,f,h,y,g,x,B,q,M,b,C,_,$,X,dt,Bt);if(t.batchPointCount=0,i){let rt=e.las?.fp64?Float64Array:Float32Array;t.positions=new rt(t.positions.length),t.colors=t.colors?new Uint8Array(t.colors.length):null,t.rawColors=t.rawColors?new Uint16Array(t.rawColors.length):null,t.intensities=t.intensities?new Uint16Array(t.intensities.length):null,t.classifications=t.classifications?new Uint8Array(t.classifications.length):null,t.syntheticFlags=t.syntheticFlags?new Uint8Array(t.syntheticFlags.length):null,t.keyPointFlags=t.keyPointFlags?new Uint8Array(t.keyPointFlags.length):null,t.withheldFlags=t.withheldFlags?new Uint8Array(t.withheldFlags.length):null,t.overlapFlags=t.overlapFlags?new Uint8Array(t.overlapFlags.length):null,t.gpsTimes=t.gpsTimes?new Float64Array(t.gpsTimes.length):null,t.nir=t.nir?new Uint16Array(t.nir.length):null,t.scanAngles=t.scanAngles?new Int16Array(t.scanAngles.length):null,t.userData=t.userData?new Uint8Array(t.userData.length):null,t.pointSourceIds=t.pointSourceIds?new Uint16Array(t.pointSourceIds.length):null,t.returnNumbers=t.returnNumbers?new Uint8Array(t.returnNumbers.length):null,t.numberOfReturns=t.numberOfReturns?new Uint8Array(t.numberOfReturns.length):null,t.scannerChannels=t.scannerChannels?new Uint8Array(t.scannerChannels.length):null,t.scanDirectionFlags=t.scanDirectionFlags?new Uint8Array(t.scanDirectionFlags.length):null,t.edgeOfFlightLines=t.edgeOfFlightLines?new Uint8Array(t.edgeOfFlightLines.length):null,t.waveforms=t.waveforms?new Uint8Array(t.waveforms.length):null,t.extraBytes=t.extraBytes?new Uint8Array(t.extraBytes.length):null,t.typedExtraBytes=t.typedExtraBytes?t.typedExtraBytes.map(tt=>({...tt,value:up(tt.scalarDataType,tt.value.length,tt.outputFloat64)})):null,t.typedExtraBytesSource=t.typedExtraBytesSource?new Uint8Array(t.typedExtraBytesSource.length):null,t.target.positions=t.positions,t.target.colors=t.colors,t.target.rawColors=t.rawColors,t.target.intensities=t.intensities,t.target.classifications=t.classifications,t.target.syntheticFlags=t.syntheticFlags,t.target.keyPointFlags=t.keyPointFlags,t.target.withheldFlags=t.withheldFlags,t.target.overlapFlags=t.overlapFlags,t.target.gpsTimes=t.gpsTimes,t.target.nir=t.nir,t.target.scanAngles=t.scanAngles,t.target.userData=t.userData,t.target.pointSourceIds=t.pointSourceIds,t.target.returnNumbers=t.returnNumbers,t.target.numberOfReturns=t.numberOfReturns,t.target.scannerChannels=t.scannerChannels,t.target.scanDirectionFlags=t.scanDirectionFlags,t.target.edgeOfFlightLines=t.edgeOfFlightLines,t.target.waveforms=t.waveforms,t.compatibilityExtraBytesSource=t.compatibilityExtraBytesSource?new Uint8Array(t.compatibilityExtraBytesSource.length):null,t.target.extraBytes=t.extraBytes||t.typedExtraBytesSource||t.compatibilityExtraBytesSource}return se}function t1(r){let t=r.las?.columns;if(!t)return{intensity:!0,classification:!0,synthetic:!0,keyPoint:!0,withheld:!0,overlap:!0,color:!0,gpsTime:!0,nir:!0,scanAngle:!0,userData:!0,pointSourceId:!0,returnNumber:!0,numberOfReturns:!0,scannerChannel:!0,scanDirectionFlag:!0,edgeOfFlightLine:!0,waveform:!0,extraBytes:r.las?.extraBytes==="typed"};let e=!1,n=!1,s=!1,i=!1,o=!1,a=!1,c=!1,l=!1,u=!1,f=!1,h=!1,m=!1,y=!1,g=!1,x=!1,B=!1,q=!1,M=!1,b=!1;for(let C of t)switch(C){case"POSITION":break;case"intensity":e=!0;break;case"classification":n=!0;break;case"synthetic":s=!0;break;case"keyPoint":i=!0;break;case"withheld":o=!0;break;case"overlap":a=!0;break;case"COLOR_0":c=!0;break;case"GPS_TIME":l=!0;break;case"NIR":u=!0;break;case"scanAngle":f=!0;break;case"userData":h=!0;break;case"pointSourceId":m=!0;break;case"returnNumber":y=!0;break;case"numberOfReturns":g=!0;break;case"scannerChannel":x=!0;break;case"scanDirectionFlag":B=!0;break;case"edgeOfFlightLine":q=!0;break;case"WAVEFORM":M=!0;break;case"EXTRA_BYTES":b=!0;break;default:throw new Error(`LASLoader: unsupported column ${C}`)}return{intensity:e,classification:n,synthetic:s,keyPoint:i,withheld:o,overlap:a,color:c,gpsTime:l,nir:u,scanAngle:f,userData:h,pointSourceId:m,returnNumber:y,numberOfReturns:g,scannerChannel:x,scanDirectionFlag:B,edgeOfFlightLine:q,waveform:M,extraBytes:b}}function e1(r,t,e){let n=new Uint8Array(t*4),s=new Uint32Array(n.buffer);if(O2(r,t,e.las?.colorDepth))for(let o=0;o<t;o++){let a=o*3,c=r[a]>>8&255,l=r[a+1]>>8&255,u=r[a+2]>>8&255;s[o]=4278190080|u<<16|l<<8|c}else for(let o=0;o<t;o++){let a=o*3,c=r[a]&255,l=r[a+1]&255,u=r[a+2]&255;s[o]=4278190080|u<<16|l<<8|c}return n}function O2(r,t,e){if(e===8)return!1;if(e===16)return!0;if(e!=="auto")return!1;for(let n=0;n<t*3;n++)if(r[n]>255)return!0;return!1}function E2(r,t,e){let n=t,s=t+e;for(;n<s&&r[n]!==0;)n++;return String.fromCharCode(...r.subarray(t,n))}function U2(r){let t=r.mins||[0,0,0],e=r.maxs||[0,0,0];return[[t[0],t[1],t[2]],[e[0],e[1],e[2]]]}function*N2(r,t,e,n,s,i){for(;n<e.pointsCount&&s<e.totalToRead;){let o=R2(r,t,e,n,s,i);if(!o)return;r=o.pending,t=o.absoluteOffset,n=o.sourcePointIndex,s=o.totalRead,yield o}}function R2(r,t,e,n,s,i){let o=e.pointsStructSize,c=e.pointsOffset+n*o-t;if(c<0)throw new Error("LASLoader: invalid streaming point offset");if(c+o>r.byteLength)return null;let l=Math.floor((r.byteLength-c)/o),u=Math.min(i,l,e.pointsCount-n,e.totalToRead-s);if(u<=0)return null;n+=u,s+=u;let f={...e,pointsOffset:r.byteOffset+c,pointsCount:u,totalRead:s},h=e.pointsOffset+n*o,m=Math.max(0,Math.min(r.byteLength,h-t));return{arrayBuffer:r.buffer,header:f,pending:r.subarray(m),absoluteOffset:t+m,sourcePointIndex:n,totalRead:s}}function P2(r,t){if(t!==0||r.byteLength<227)return null;let e=new DataView(r.buffer,r.byteOffset,r.byteLength);if(e.getUint32(0,!0)!==Vb)throw new Error("LASLoader: invalid LAS header");let n=e.getUint32(96,!0);return r.byteLength<Math.max(n,255)?null:Hb(r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength))}function r1(r,t){if(r.byteLength===0)return t;let e=new Uint8Array(r.byteLength+t.byteLength);return e.set(r),e.set(t,r.byteLength),e}function Bp(r){let t=ArrayBuffer.isView(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r),e=new Uint8Array(t.byteLength);return e.set(t),e}function k2(r){if(Symbol.asyncIterator in r)return r[Symbol.asyncIterator]();let t=r[Symbol.iterator]();return{async next(){return t.next()}}}function z2(r,t){return n1(r,t)?r.byteLength<Wt?0:Ks(r,r.byteLength-Wt):Ks(r,t)}function Fu(r){return n1(r,0)?-1:Ks(r,0)}function n1(r,t){return r.byteLength>=t+8&&r.getUint32(t,!0)===4294967295&&r.getUint32(t+4,!0)===4294967295}function Ks(r,t){if(r.byteLength<t+8)return 0;let e=r.getUint32(t,!0);return r.getUint32(t+4,!0)*2**32+e}var zb,Vb,Gb,zS,VS,GS,jS,qS,Wt,$S,s1=p(()=>{"use strict";or();Zo();Fb();Eb();Pb();zb=1e3*100,Vb=1179861324,Gb=375,zS=128,VS=63,GS="laszip encoded",jS=22204,qS=4294967295,Wt=8,$S=64*1024});function i1(r,t){let e=t?.las?._chunk;return e?qb(r,e.metadata,t||{}):jb(r,t)}function Ou(r,t){let e=t?.las?.colorFormat===void 0||t.las.colorFormat==="uint8norm"?r:{...Ee(Gg(ee(r),t.las.colorFormat),"arrow-table"),loader:r.loader,loaderData:r.loaderData,progress:r.progress};return zg(t)==="arrow-table"?e:{...ee(e),loader:e.loader,loaderData:e.loaderData,progress:e.progress}}async function*G2(r,t){for await(let e of r)yield Ou(e,t)}function o1(r,t){return Ou(Po(r),t)}var V2,a1=p(()=>{"use strict";or();jg();Gs();s1();V2={...Vg,worker:!0,workerInBatches:!0,serializeWorkerResult:re,serializeWorkerBatch:re,deserializeWorkerResult:o1,deserializeWorkerBatch:o1,parse:async(r,t)=>Ou(i1(r,t),t),parseSync:(r,t)=>Ou(i1(r,t),t),parseInBatches:async function*(r,t){yield*G2(Wb(r,t),t)}}});var c1={};Re(c1,{LASLoaderWithParser:()=>V2});var l1=p(()=>{"use strict";a1()});function v1(r,t){let e=r.length,n=new Uint8Array(t),s=0,i=0,o,a,c;do if(o=r[s++],o<32){if(o++,i+o>t)throw new Error("Output buffer is not large enough");if(s+o>e)throw new Error("Invalid compressed data");do n[i++]=r[s++];while(--o)}else{if(a=o>>5,c=i-((o&31)<<8)-1,s>=e)throw new Error("Invalid compressed data");if(a===7&&(a+=r[s++],s>=e))throw new Error("Invalid compressed data");if(c-=r[s++],i+a+2>t)throw new Error("Output buffer is not large enough");if(c<0)throw new Error("Invalid compressed data");if(c>=i)throw new Error("Invalid compressed data");do n[i++]=n[c++];while(--a+2)}while(s<e);return n}var A1=p(()=>{"use strict"});function S1(r,t,e="uint8norm"){let n=[];for(let s of Object.keys(r.offset))switch(s){case"x":n.push({name:"POSITION",type:{type:"fixed-size-list",listSize:3,children:[{name:"xyz",type:"float32"}]},metadata:{attribute:"POSITION"}});break;case"y":case"z":break;case"normal_x":n.push({name:"NORMAL",type:{type:"fixed-size-list",listSize:3,children:[{name:"xyz",type:"float32"}]},metadata:{attribute:"NORMAL"}});break;case"normal_y":case"normal_z":break;case"rgb":let i=e==="float16"?"float16":e==="float32"?"float32":"uint8";n.push({name:"COLOR_0",type:{type:"fixed-size-list",listSize:3,children:[{name:"rgb",type:i}]},metadata:{attribute:"COLOR",...e==="float16"?{componentType:"float16"}:{}}});break;default:}return{fields:n,metadata:t}}var B1=p(()=>{"use strict"});function ta(r,t){let e=new TextDecoder().decode(r),n=ac(e),s={};switch(n.data){case"ascii":s=CB(n,e);break;case"binary":s=FB(n,r);break;case"binary_compressed":s=OB(n,r);break;default:throw new Error(`PCD: ${n.data} files are not supported`)}s=DB(s,t?.pcd?.colorFormat);let i=MB(n,s),o=Object.fromEntries([["topology","point-list"],["mode","0"],["boundingBox",JSON.stringify(i.boundingBox)]]),a=S1(n,o,t?.pcd?.colorFormat);return{loader:"pcd",loaderData:n,header:i,schema:a,topology:"point-list",mode:0,attributes:s}}function MB(r,t){if(typeof r.width=="number"&&typeof r.height=="number"){let e=r.width*r.height,n=on(t);if(!n)throw new Error("PCD point cloud is missing positions");return{vertexCount:e,boundingBox:n}}return{vertexCount:r.vertexCount,boundingBox:r.boundingBox}}function DB(r,t="uint8norm"){let e={POSITION:{value:new Float32Array(r.position),size:3}};return r.normal&&r.normal.length>0&&(e.NORMAL={value:new Float32Array(r.normal),size:3}),r.color&&r.color.length>0&&(e.COLOR_0=Fp(r.color,t)),r.intensity&&r.intensity.length>0&&(e.COLOR_0=Fp(r.color,t)),!e.COLOR_0&&r.label&&r.label.length>0&&(e.COLOR_0=Fp(r.label,t)),e}function Fp(r,t){return t==="float16"?{value:ti(r,255),size:3,componentType:"float16"}:t==="float32"?{value:Float32Array.from(r,e=>e/255),size:3}:{value:new Uint8Array(r),size:3}}function ac(r){let t=r.search(/[\r\n]DATA\s(\S*)\s/i),e=/[\r\n]DATA\s(\S*)\s/i.exec(r.substr(t-1)),n={};if(n.data=e&&e[1],e!==null&&(n.headerLen=(e&&e[0].length)+t),n.str=r.substr(0,n.headerLen),n.str=n.str.replace(/\#.*/gi,""),n.version=/VERSION (.*)/i.exec(n.str),n.fields=/FIELDS (.*)/i.exec(n.str),n.size=/SIZE (.*)/i.exec(n.str),n.type=/TYPE (.*)/i.exec(n.str),n.count=/COUNT (.*)/i.exec(n.str),n.width=/WIDTH (.*)/i.exec(n.str),n.height=/HEIGHT (.*)/i.exec(n.str),n.viewpoint=/VIEWPOINT (.*)/i.exec(n.str),n.points=/POINTS (.*)/i.exec(n.str),n.version!==null&&(n.version=parseFloat(n.version[1])),n.fields!==null&&(n.fields=n.fields[1].split(" ")),n.type!==null&&(n.type=n.type[1].split(" ")),n.width!==null&&(n.width=parseInt(n.width[1],10)),n.height!==null&&(n.height=parseInt(n.height[1],10)),n.viewpoint!==null&&(n.viewpoint=n.viewpoint[1]),n.points!==null&&(n.points=parseInt(n.points[1],10)),n.points===null&&typeof n.width=="number"&&typeof n.height=="number"&&(n.points=n.width*n.height),n.size!==null&&(n.size=n.size[1].split(" ").map(i=>parseInt(i,10))),n.count!==null)n.count=n.count[1].split(" ").map(i=>parseInt(i,10));else if(n.count=[],n.fields!==null)for(let i=0;i<n.fields.length;i++)n.count.push(1);n.offset={};let s=0;for(let i=0,o=n.fields.length;i<o;i++)n.data==="ascii"?n.offset[n.fields[i]]=i:(n.offset[n.fields[i]]=s,s+=n.size[i]*n.count[i]);return n.rowSize=s,n}function CB(r,t){let e=[],n=[],s=[],i=[],o=[],a=r.offset,l=t.substr(r.headerLen).split(`
|
|
29
|
-
`);for(let u=0;u<l.length;u++)if(l[u]!==""){let f=l[u].split(" ");if(a.x!==void 0&&(e.push(parseFloat(f[a.x])),e.push(parseFloat(f[a.y])),e.push(parseFloat(f[a.z]))),a.rgb!==void 0){let h=parseFloat(f[a.rgb]),m=new Float32Array([h]),y=new DataView(m.buffer,0);s.push(y.getUint8(0)),s.push(y.getUint8(1)),s.push(y.getUint8(2))}a.normal_x!==void 0&&(n.push(parseFloat(f[a.normal_x])),n.push(parseFloat(f[a.normal_y])),n.push(parseFloat(f[a.normal_z]))),a.intensity!==void 0&&i.push(parseFloat(f[a.intensity])),a.label!==void 0&&o.push(parseInt(f[a.label]))}return{position:e,normal:n,color:s}}function FB(r,t){let e=[],n=[],s=[],i=[],o=[],a=new DataView(t,r.headerLen),c=r.offset;for(let l=0,u=0;l<r.points;l++,u+=r.rowSize)c.x!==void 0&&(e.push(a.getFloat32(u+c.x,we)),e.push(a.getFloat32(u+c.y,we)),e.push(a.getFloat32(u+c.z,we))),c.rgb!==void 0&&(s.push(a.getUint8(u+c.rgb+0)),s.push(a.getUint8(u+c.rgb+1)),s.push(a.getUint8(u+c.rgb+2))),c.normal_x!==void 0&&(n.push(a.getFloat32(u+c.normal_x,we)),n.push(a.getFloat32(u+c.normal_y,we)),n.push(a.getFloat32(u+c.normal_z,we))),c.intensity!==void 0&&i.push(a.getFloat32(u+c.intensity,we)),c.label!==void 0&&o.push(a.getInt32(u+c.label,we));return{position:e,normal:n,color:s,intensity:i,label:o}}function OB(r,t){let e=[],n=[],s=[],i=[],o=[],a=new Uint32Array(t.slice(r.headerLen,r.headerLen+8)),c=a[0],l=a[1],u=v1(new Uint8Array(t,r.headerLen+8,c),l),f=new DataView(u.buffer),h=r.offset;for(let m=0;m<r.points;m++){if(h.x!==void 0&&(e.push(f.getFloat32(r.points*h.x+r.size[0]*m,we)),e.push(f.getFloat32(r.points*h.y+r.size[1]*m,we)),e.push(f.getFloat32(r.points*h.z+r.size[2]*m,we))),h.rgb!==void 0&&(s.push(f.getUint8(r.points*h.rgb+r.size[3]*m+0)),s.push(f.getUint8(r.points*h.rgb+r.size[3]*m+1)),s.push(f.getUint8(r.points*h.rgb+r.size[3]*m+2))),h.normal_x!==void 0&&(n.push(f.getFloat32(r.points*h.normal_x+r.size[4]*m,we)),n.push(f.getFloat32(r.points*h.normal_y+r.size[5]*m,we)),n.push(f.getFloat32(r.points*h.normal_z+r.size[6]*m,we))),h.intensity!==void 0){let y=r.fields.indexOf("intensity");i.push(f.getFloat32(r.points*h.intensity+r.size[y]*m,we))}if(h.label!==void 0){let y=r.fields.indexOf("label");o.push(f.getInt32(r.points*h.label+r.size[y]*m,we))}}return{position:e,normal:n,color:s,intensity:i,label:o}}var we,I1=p(()=>{"use strict";Vs();or();A1();B1();we=!0;});var _1,L1=p(()=>{"use strict";_1={name:"PCD (Point Cloud Data)",id:"pcd",module:"pointclouds",encoding:"text",format:"pcd",extensions:["pcd"],mimeTypes:["text/plain"],category:"pointcloud",text:!0,binary:!0}});async function UB(){let{PCDLoaderWithParser:r}=await Promise.resolve().then(()=>(Ep(),Op));return r}var EB,T1,M1=p(()=>{"use strict";L1();Gs();EB="5.0.0-beta.
|
|
28
|
+
`)}}t.length>0&&(yield t)}var Kg=p(()=>{"use strict"});async function wd(r,t){let e=qA(r);for(;;){let{done:n,value:s}=await e.next();if(n){e.return&&e.return();return}if(t(s))return}}async function xd(r){let t=[];for await(let e of r)t.push(Qg(e));return Zg(...t)}async function*Ql(r){for await(let t of r)yield Qg(t)}function Qg(r){if(r instanceof ArrayBuffer)return r;if(ArrayBuffer.isView(r)){let{buffer:t,byteOffset:e,byteLength:n}=r;return Jg(t,e,n)}return Jg(r)}function Jg(r,t=0,e=r.byteLength-t){let n=new Uint8Array(r,t,e),s=new Uint8Array(n.length);return s.set(n),s.buffer}function qA(r){if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r[Symbol.iterator]=="function"){let t=r[Symbol.iterator]();return $A(t)}return r}function $A(r){return{next(t){return Promise.resolve(r.next(t))},return(t){return typeof r.return=="function"?Promise.resolve(r.return(t)):Promise.resolve({done:!0,value:t})},throw(t){return typeof r.throw=="function"?Promise.resolve(r.throw(t)):Promise.reject(t)}}}var tb=p(()=>{"use strict";Hg()});function $d(r){return new Sd(r)}function Id(r){return{intensity:!!r.intensities,classification:!!r.classifications,color:!!(r.colors||r.rawColors),gpsTime:!!r.gpsTimes,nir:!!r.nir,scanAngle:!!r.scanAngles,userData:!!r.userData,pointSourceId:!!r.pointSourceIds,flags:!!(r.scannerChannels||r.scanDirectionFlags||r.edgeOfFlightLines||r.syntheticFlags||r.keyPointFlags||r.withheldFlags||r.overlapFlags),waveform:!!r.waveforms,extraBytes:!!r.extraBytes}}function cb(r){return(r.intensity?1:0)|(r.classification?2:0)|(r.color?4:0)|(r.gpsTime?8:0)|(r.nir?16:0)|(r.scanAngle?32:0)|(r.userData?64:0)|(r.pointSourceId?128:0)|(r.flags?256:0)|(r.waveform?512:0)|(r.extraBytes?1024:0)}function Gr(r,t){return new Bd(r,t)}function fu(r,t){let e=Gr(r,t),n=new Uint8Array(t.pointCount*t.pointDataRecordLength);return e.decodeInto(n,0,t.pointCount),n}function lb(r,t){if(!mu(t.pointDataRecordFormat))throw new it("Legacy LAZ chunk byte length is not self-describing");let e=Wo(r),n=$o(t),s=t.pointDataRecordLength,i=rc(t.pointDataRecordFormat,n),o=s+4,a=i*4;if(e.byteLength<o+a)throw new it;let c=new DataView(e.buffer,e.byteOffset,e.byteLength),l=o+a;for(let u=0;u<i;u++)l+=c.getUint32(o+u*4,!0);if(e.byteLength<l)throw new it;return l}function Wd(r,t){let e=new eu(Wo(r)),n=new ne(e),s=It(32,2);n.readInitBytes();let i=[],o=0,a=0,c=t.pointCount;for(let l=0;l<t.chunkCount;l++){let u;t.variable?(o=s.decompress(n,o,0)>>>0,u=o):(u=Math.min(t.chunkSize,c),c-=u),a=s.decompress(n,a,1)>>>0,i.push({pointCount:u,byteLength:a})}return i}function hu(r){if(!mu(r.pointDataRecordFormat))return r.pointDataRecordLength+4;let t=$o(r);return r.pointDataRecordLength+4+rc(r.pointDataRecordFormat,t)*4}function du(r,t){if(!mu(t.pointDataRecordFormat))throw new it("Legacy LAZ chunk byte length is not self-describing");let e=_d(Wo(r),t);if(!e)throw new it("LAZ chunk decoder needs the complete layered size header");return e.byteLength}function _d(r,t){let e=$o(t),n=t.pointDataRecordLength+4,s=rc(t.pointDataRecordFormat,e),i=s*4;if(r.byteLength<n+i)return null;let o=new DataView(r.buffer,r.byteOffset,r.byteLength),a=n+i,c=[];for(let u=0;u<s;u++){let f=o.getUint32(n+u*4,!0);a+=f,c.push(f)}let l=n+i;return{byteLength:a,layerByteLengths:c,getByteLength:u=>l+c.slice(0,u).reduce((f,h)=>f+h,0)}}function WA(r,t){if(t.extraBytes)return rc(r.pointDataRecordFormat,$o(r));let e=2;return t.classifications&&(e=3),(t.scannerChannels||t.scanDirectionFlags||t.edgeOfFlightLines||t.syntheticFlags||t.keyPointFlags||t.withheldFlags||t.overlapFlags)&&(e=4),t.intensities&&(e=5),t.scanAngles&&(e=6),t.userData&&(e=7),t.pointSourceIds&&(e=8),t.gpsTimes&&(e=9),(t.colors||t.rawColors)&&(e=10),t.nir&&(e=11),t.waveforms&&(e=r.pointDataRecordFormat===9?10:12),Math.min(e,rc(r.pointDataRecordFormat,$o(r)))}function Ad(r){let t=r.byteItemVersion===1?4:2;return Math.max(tS,r.pointDataRecordLength*t+512)}function nb(r){return r[0]<r[1]?r[1]<r[2]?r[1]:Math.max(r[0],r[2]):r[0]<r[2]?r[0]:Math.max(r[1],r[2])}function rS(r,t,e,n){let s=$o(t);for(let i of[t.point10ItemVersion,t.gpsTime11ItemVersion,t.rgb12ItemVersion,t.byteItemVersion])if(i!==void 0&&i!==1&&i!==2)throw new Error(`Unsupported legacy LASzip item version ${i}`);switch(t.pointDataRecordFormat){case 0:return new Od(r,s,t);case 1:return new Ed(r,s,t);case 2:return new Ud(r,s,t);case 3:return new Nd(r,s,t,e==="point-data"?n:null);case 4:return new Rd(r,s,t);case 5:return new Pd(r,s,t);case 6:return new kd(r,s,e,t,n);case 7:return new zd(r,s,e,t,n);case 8:return new Vd(r,s,e,t,n);case 9:return new Gd(r,s,e,t,n);case 10:return new jd(r,s,e,t,n);default:throw new Error(`TypeScript LAZ decoder does not support point format ${t.pointDataRecordFormat}`)}}function nS(r){return r<=5||r>=6&&r<=10}function It(r,t){let e=new Td(r,t);return e.init(),e}function ge(r,t){return Array.from({length:r},()=>new jt(t))}function $o(r){let t=sS(r.pointDataRecordFormat),e=r.pointDataRecordLength-t;if(e<0)throw new Error(`Invalid point record length ${r.pointDataRecordLength}`);return e}function sS(r){switch(r){case 0:return 20;case 1:return 28;case 2:return 26;case 3:return 34;case 4:return 57;case 5:return 63;case 6:return 30;case 7:return 36;case 8:return 38;case 9:return 59;case 10:return 67;default:throw new Error(`TypeScript LAZ decoder does not support point format ${r}`)}}function mu(r){return r>=6&&r<=10}function rc(r,t){switch(r){case 6:return 9+t;case 7:return 10+t;case 8:return 11+t;case 9:return 10+t;case 10:return 12+t;default:throw new Error(`TypeScript LAZ decoder does not support point format ${r}`)}}function iS(){return{x:0,y:0,z:0,intensity:0,returns:0,flags:0,classification:0,userData:0,scanAngle:0,pointSourceId:0,gpsTime:0}}function sb(){return{x:0,y:0,z:0,intensity:0,bitByte:0,classification:0,scanAngleRank:0,userData:0,pointSourceId:0}}function oS(r,t){r.x=zo(t),r.y=zo(t),r.z=zo(t),r.intensity=Ys(t),r.bitByte=t.getByte(),r.classification=t.getByte(),r.scanAngleRank=qd(t.getByte()),r.userData=t.getByte(),r.pointSourceId=Ys(t)}function aS(r,t){r.x=t.x,r.y=t.y,r.z=t.z,r.intensity=t.intensity,r.bitByte=t.bitByte,r.classification=t.classification,r.scanAngleRank=t.scanAngleRank,r.userData=t.userData,r.pointSourceId=t.pointSourceId}function cS(r,t,e){Ue(r.x,t,e),Ue(r.y,t,e+4),Ue(r.z,t,e+8),ar(r.intensity,t,e+12),t[e+14]=r.bitByte,t[e+15]=r.classification,t[e+16]=r.scanAngleRank&255,t[e+17]=r.userData,ar(r.pointSourceId,t,e+18)}function Rn(r,t,e,n,s,i,o){let a=o*3;t[a]=r.x*s[0]+i[0],t[a+1]=r.y*s[1]+i[1],t[a+2]=r.z*s[2]+i[2],e&&(e[o]=r.intensity),n&&(n[o]=r.classification&31)}function Wi(r,t,e){let n=r.classification>>5;t.syntheticFlags&&(t.syntheticFlags[e]=n&1),t.keyPointFlags&&(t.keyPointFlags[e]=n>>1&1),t.withheldFlags&&(t.withheldFlags[e]=n>>2&1),t.overlapFlags&&(t.overlapFlags[e]=0),t.scanAngles&&(t.scanAngles[e]=r.scanAngleRank),t.userData&&(t.userData[e]=r.userData),t.pointSourceIds&&(t.pointSourceIds[e]=r.pointSourceId),t.returnNumbers&&(t.returnNumbers[e]=r.bitByte&7),t.numberOfReturns&&(t.numberOfReturns[e]=r.bitByte>>3&7),t.scannerChannels&&(t.scannerChannels[e]=0),t.scanDirectionFlags&&(t.scanDirectionFlags[e]=r.bitByte>>6&1),t.edgeOfFlightLines&&(t.edgeOfFlightLines[e]=r.bitByte>>7&1)}function ib(r){return r.bitByte&7}function ob(r){return r.bitByte>>3&7}function lS(r){return r.bitByte>>6&1}function ab(r,t){r.x=t.x,r.y=t.y,r.z=t.z,r.intensity=t.intensity,r.returns=t.returns,r.flags=t.flags,r.classification=t.classification,r.userData=t.userData,r.scanAngle=t.scanAngle,r.pointSourceId=t.pointSourceId,r.gpsTime=t.gpsTime}function uS(r,t,e){r.x=Vr(t,e),r.y=Vr(t,e+4),r.z=Vr(t,e+8),r.intensity=au(t,e+12),r.returns=t[e+14],r.flags=t[e+15],r.classification=t[e+16],r.userData=t[e+17],r.scanAngle=wS(t,e+18),r.pointSourceId=au(t,e+20),r.gpsTime=vS(t,e+22)}function fS(r,t){r.x=zo(t),r.y=zo(t),r.z=zo(t),r.intensity=Ys(t),r.returns=t.getByte(),r.flags=t.getByte(),r.classification=t.getByte(),r.userData=t.getByte(),r.scanAngle=Zd(Ys(t)),r.pointSourceId=Ys(t),r.gpsTime=db(t)}function hS(r,t,e){Ue(r.x,t,e),Ue(r.y,t,e+4),Ue(r.z,t,e+8),ar(r.intensity,t,e+12),t[e+14]=r.returns,t[e+15]=r.flags,t[e+16]=r.classification,t[e+17]=r.userData,xS(r.scanAngle,t,e+18),ar(r.pointSourceId,t,e+20),pb(r.gpsTime,t,e+22)}function nc(r,t,e){Ws(r,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Yi(r,t,e),Zi(r,t,e)}function Ws(r,t,e,n,s,i,o){let a=o*3;t[a]=r.x*s[0]+i[0],t[a+1]=r.y*s[1]+i[1],t[a+2]=r.z*s[2]+i[2],e&&(e[o]=r.intensity),n&&(n[o]=r.classification)}function Yi(r,t,e){t.gpsTimes&&(t.gpsTimes[e]=r.gpsTime)}function Zi(r,t,e){t.scanAngles&&(t.scanAngles[e]=r.scanAngle),t.userData&&(t.userData[e]=r.userData),t.pointSourceIds&&(t.pointSourceIds[e]=r.pointSourceId),t.returnNumbers&&(t.returnNumbers[e]=r.returns&15),t.numberOfReturns&&(t.numberOfReturns[e]=r.returns>>4),t.scannerChannels&&(t.scannerChannels[e]=r.flags>>4&3),t.scanDirectionFlags&&(t.scanDirectionFlags[e]=r.flags>>6&1),t.edgeOfFlightLines&&(t.edgeOfFlightLines[e]=r.flags>>7&1),t.syntheticFlags&&(t.syntheticFlags[e]=r.flags&1),t.keyPointFlags&&(t.keyPointFlags[e]=r.flags>>1&1),t.withheldFlags&&(t.withheldFlags[e]=r.flags>>2&1),t.overlapFlags&&(t.overlapFlags[e]=r.flags>>3&1)}function ou(r,t,e){t.nir&&(t.nir[e]=r)}function Hi(r,t,e,n,s){if(n.colors){let o=s*4;n.colors[o]=r&255,n.colors[o+1]=t&255,n.colors[o+2]=e&255,n.colors[o+3]=255;return}if(!n.rawColors)return;let i=s*3;n.rawColors[i]=r,n.rawColors[i+1]=t,n.rawColors[i+2]=e}function dS(r){return r.flags>>4&3}function pS(r,t){r.flags=(t&3)<<4|r.flags&-49}function mS(r,t){r.flags=t&15|r.flags&240}function yS(r,t){r.flags=(t&1)<<6|r.flags&191}function gS(r,t){r.flags=(t&1)<<7|r.flags&127}function bS(r){return r.flags&15|(r.flags>>6&1)<<4|(r.flags>>7&1)<<5}function au(r,t){return r[t]|r[t+1]<<8}function Ys(r){let t=r.getByte(),e=r.getByte();return t|e<<8}function ar(r,t,e){t[e]=r&255,t[e+1]=r>>8&255}function wS(r,t){return Zd(au(r,t))}function xS(r,t,e){ar(r,t,e)}function cu(r,t){return(r[t]|r[t+1]<<8|r[t+2]<<16|r[t+3]<<24>>>0)>>>0}function lu(r,t,e){Ue(r,t,e)}function fb(r,t){let e=cu(r,t),n=cu(r,t+4);return BigInt(n)<<32n|BigInt(e)}function hb(r,t,e){lu(Number(r&0xffffffffn),t,e),lu(Number(r>>32n&0xffffffffn),t,e+4)}function Vr(r,t){return r[t]|r[t+1]<<8|r[t+2]<<16|r[t+3]<<24}function zo(r){let t=r.getByte(),e=r.getByte(),n=r.getByte(),s=r.getByte();return t|e<<8|n<<16|s<<24}function Ue(r,t,e){t[e]=r&255,t[e+1]=r>>8&255,t[e+2]=r>>16&255,t[e+3]=r>>24&255}function vS(r,t){for(let e=0;e<8;e++)Yd[e]=r[t+e];return ji.getFloat64(0,!0)}function db(r){for(let t=0;t<8;t++)Yd[t]=r.getByte();return ji.getFloat64(0,!0)}function pb(r,t,e){ji.setFloat64(0,r,!0);for(let n=0;n<8;n++)t[e+n]=Yd[n]}function $s(r){return r<=0?0:r>=255?255:r}function Zd(r){let t=r&65535;return t&32768?t-65536:t}function qd(r){let t=r&255;return t&128?t-256:t}function cn(r){return r|0}function uu(r){return ji.setFloat64(0,r,!0),ji.getBigUint64(0,!0)}function Vo(r){return ji.setBigUint64(0,r,!0),ji.getFloat64(0,!0)}function qs(r,t){let e=BigInt.asIntN(64,BigInt.asIntN(64,uu(r))+BigInt(t));return Vo(BigInt.asUintN(64,e))}function Wo(r){return r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function AS(r){let t=r.reduce((s,i)=>s+i.byteLength,0),e=new Uint8Array(t),n=0;for(let s of r)e.set(s,n),n+=s.byteLength;return e}var it,Sd,Bd,ko,YA,pu,ZA,HA,Qa,XA,eb,KA,JA,an,Go,tu,QA,vd,ub,Yd,ji,tS,rb,eS,eu,jt,Ld,ne,Td,jo,Zs,tc,Hs,Nt,Md,qi,Dd,ec,Cd,ru,nu,su,Fd,$i,Od,qo,Ed,Ud,Nd,iu,Rd,Pd,kd,zd,Vd,Gd,jd,mb=p(()=>{"use strict";it=class extends Error{constructor(t="LAZ chunk decoder needs more compressed data"){super(t),this.name="NeedsMoreData"}},Sd=class{metadata;chunks=[];closed=!1;compressed=null;cursor=null;fedByteLength=0;requiredByteLength=null;progressiveRequiredByteLength=null;progressiveSelectionKey=null;constructor(t){this.metadata=t}feed(t){if(this.closed)throw new Error("Cannot feed a closed LAZ chunk decoder");let e=Wo(t);this.chunks.push(e),this.compressed=null,this.fedByteLength+=e.byteLength}close(){this.closed=!0}get remainingPointCount(){return this.cursor?.remainingPointCount??this.metadata.pointCount}decode(){if(!this.closed)throw new it("LAZ chunk decoder input is not closed");return this.decodeAvailable()}readBatch(t){if(!this.cursor){if(!this.hasCompleteChunk())return null;let i=this.getCompressedAvailable(),o=this.requiredByteLength??i.byteLength;this.cursor=Gr(i.subarray(0,o),this.metadata)}if(this.cursor.remainingPointCount<=0)return null;let e=this.metadata.pointDataRecordLength,n=Math.min(t,this.cursor.remainingPointCount),s=new Uint8Array(n*e);return this.cursor.decodeInto(s,0,n),s}readPositionDataBatch(t,e){if(t.colors||t.rawColors||t.nir)throw new Error("Position-only LAZ batches cannot request color or NIR output");return this.readPointDataBatch(t,e)}readPointDataBatch(t,e){let n=this.metadata.pointDataRecordFormat;if(n<6||n>10)throw new Error("Progressive LAZ point-data batches require point formats 6-10");let s=n===7||n===8||n===10;if((t.colors||t.rawColors)&&!s)throw new Error(`Point format ${n} does not contain RGB data`);if(t.nir&&n!==8&&n!==10)throw new Error("NIR output requires point format 8 or 10");if(t.waveforms&&n!==9&&n!==10)throw new Error("Waveform output requires point format 9 or 10");if(!this.cursor){let o=this.getProgressivePointData(t);if(!o)return null;this.cursor=Gr(o,this.metadata)}if(this.cursor.remainingPointCount<=0)return 0;let i=Math.min(e,this.cursor.remainingPointCount);return this.cursor.decodeIntoPointData(t,i)}hasCompleteChunk(){if(!mu(this.metadata.pointDataRecordFormat))return this.closed;if(this.requiredByteLength!==null)return this.fedByteLength>=this.requiredByteLength;if(this.fedByteLength<hu(this.metadata))return!1;try{let t=this.getCompressedAvailable();return this.requiredByteLength=lb(t,this.metadata),this.requiredByteLength<=this.fedByteLength}catch(t){if(t instanceof it)return!1;throw t}}decodeAvailable(){let t=this.getCompressedAvailable(),e=this.requiredByteLength??t.byteLength;return fu(t.subarray(0,e),this.metadata)}getCompressedAvailable(){return this.compressed||=AS(this.chunks),this.compressed}getProgressivePointData(t){let e=cb(Id(t));if(this.progressiveSelectionKey!==e&&(this.progressiveRequiredByteLength=null,this.progressiveSelectionKey=e),this.progressiveRequiredByteLength===null){let o=this.getCompressedAvailable(),a=_d(o,this.metadata);if(!a)return null;let c=WA(this.metadata,t);this.progressiveRequiredByteLength=a.getByteLength(c)}if(this.fedByteLength<this.progressiveRequiredByteLength)return null;let n=this.getCompressedAvailable(),s=_d(n,this.metadata),i=new Uint8Array(s.byteLength);return i.set(n.subarray(0,Math.min(n.byteLength,s.byteLength))),i}};Bd=class{metadata;stream;decoder=null;pointIndex=0;outputMode=null;pointDataSelectionKey=null;constructor(t,e){this.metadata=e,this.stream=new eu(Wo(t))}feed(t){if(this.metadata.pointDataRecordFormat>5)throw new Error("Only legacy PDRF 0-5 LAZ cursors accept additional compressed input");this.stream.append(Wo(t))}discardConsumedInput(){if(this.metadata.pointDataRecordFormat>5)throw new Error("Only legacy PDRF 0-5 LAZ cursors can discard consumed input");this.stream.discardConsumedInput()}get remainingPointCount(){return this.metadata.pointCount-this.pointIndex}get compressedByteOffset(){return this.stream.byteOffset}get requiredInputByteLength(){if(this.metadata.pointDataRecordFormat>5)return this.stream.byteOffset;let t=this.pointIndex===0?this.metadata.pointDataRecordLength+4:Ad(this.metadata);return this.stream.byteOffset+t}decodeInto(t,e,n){let s=Math.min(n,this.remainingPointCount),i=this.selectOutputMode("raw",s);if(!i)return 0;let o=e;for(let a=0;a<s;a++)o=i.decompress(t,o);return this.pointIndex+=s,s}decodeAvailableInto(t,e,n,s=!1){if(this.metadata.pointDataRecordFormat>5)throw new Error("Available-point decoding is limited to legacy PDRF 0-5 LAZ chunks");let i=Math.min(n,this.remainingPointCount);if(i===0)return 0;let o=this.selectOutputMode("raw",i),a=0,c=e;for(;a<i;){let l=this.pointIndex===0?this.metadata.pointDataRecordLength+4:Ad(this.metadata);if(!s&&this.stream.availableByteLength<l)break;try{c=o.decompress(t,c)}catch(u){throw u instanceof it&&!s?new Error(`Legacy LAZ point exceeded the ${l}-byte streaming lookahead`):u}a++,this.pointIndex++}return a}decodeAvailableIntoPointData(t,e,n=!1){if(this.metadata.pointDataRecordFormat>5)throw new Error("Available point-data decoding is limited to legacy PDRF 0-5 LAZ chunks");let s=Math.min(e,this.remainingPointCount);if(s===0)return 0;let i=Id(t),o=this.selectOutputMode("point-data",s,i),a=0,c=t.pointOffset;for(;a<s;){let l=this.pointIndex===0?this.metadata.pointDataRecordLength+4:Ad(this.metadata);if(!n&&this.stream.availableByteLength<l)break;try{t.pointOffset=c+a,o.decompressPointData?o.decompressPointData(t,t.pointOffset):o.decompressPointDataBatch(t,1)}catch(u){throw t.pointOffset=c,u instanceof it&&!n?new Error(`Legacy LAZ point exceeded the ${l}-byte streaming lookahead`):u}a++,this.pointIndex++}return t.pointOffset=c,a}decodeIntoPointData(t,e){let n=Math.min(e,this.remainingPointCount);if(n>0&&!nS(this.metadata.pointDataRecordFormat))throw new Error(`TypeScript LAZ decoder does not support direct point-data output for point format ${this.metadata.pointDataRecordFormat}`);let s=Id(t),i=this.selectOutputMode("point-data",n,s);if(!i)return 0;if(i.decompressPointDataBatch)i.decompressPointDataBatch(t,n);else for(let o=0;o<n;o++)i.decompressPointData(t,t.pointOffset+o);return this.pointIndex+=n,n}selectOutputMode(t,e,n=null){if(e===0)return null;if(this.outputMode&&this.outputMode!==t)throw new Error("Cannot mix raw and point-data decoding in one LAZ chunk cursor");if(t==="point-data"){let s=cb(n);if(this.pointDataSelectionKey!==null&&this.pointDataSelectionKey!==s)throw new Error("Cannot change selected point-data fields in one LAZ chunk cursor");this.pointDataSelectionKey=s}return this.outputMode=t,this.decoder||=rS(this.stream,this.metadata,t,n),this.decoder}};ko=16777216,YA=4294967295,pu=13,ZA=1<<pu,HA=2**(31-pu),Qa=15,XA=1<<Qa,eb=2**(31-Qa),KA=[[0,1,2,3,4,5,3,4,4,5,5,5,5,5,5,5],[1,0,1,3,3,3,3,3,3,3,3,3,3,3,3,3],[2,1,2,4,4,4,4,4,4,4,4,3,3,3,3,3],[3,3,4,5,4,4,4,4,4,4,4,4,4,4,4,4],[4,3,4,4,5,4,4,4,4,4,4,4,4,4,4,4],[5,3,4,4,4,5,4,4,4,4,4,4,4,4,4,4],[3,3,4,4,4,4,5,4,4,4,4,4,4,4,4,4],[4,3,4,4,4,4,4,5,4,4,4,4,4,4,4,4],[4,3,4,4,4,4,4,4,5,4,4,4,4,4,4,4],[5,3,4,4,4,4,4,4,4,5,4,4,4,4,4,4],[5,3,4,4,4,4,4,4,4,4,5,4,4,4,4,4],[5,3,3,4,4,4,4,4,4,4,4,5,5,4,4,4],[5,3,3,4,4,4,4,4,4,4,4,5,5,5,4,4],[5,3,3,4,4,4,4,4,4,4,4,4,5,5,5,4],[5,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5],[5,3,3,4,4,4,4,4,4,4,4,4,4,4,5,5]],JA=[[0,1,2,3,4,5,6,7,7,7,7,7,7,7,7,7],[1,0,1,2,3,4,5,6,7,7,7,7,7,7,7,7],[2,1,0,1,2,3,4,5,6,7,7,7,7,7,7,7],[3,2,1,0,1,2,3,4,5,6,7,7,7,7,7,7],[4,3,2,1,0,1,2,3,4,5,6,7,7,7,7,7],[5,4,3,2,1,0,1,2,3,4,5,6,7,7,7,7],[6,5,4,3,2,1,0,1,2,3,4,5,6,7,7,7],[7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,7],[7,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7],[7,7,7,6,5,4,3,2,1,0,1,2,3,4,5,6],[7,7,7,7,6,5,4,3,2,1,0,1,2,3,4,5],[7,7,7,7,7,6,5,4,3,2,1,0,1,2,3,4],[7,7,7,7,7,7,6,5,4,3,2,1,0,1,2,3],[7,7,7,7,7,7,7,6,5,4,3,2,1,0,1,2],[7,7,7,7,7,7,7,7,6,5,4,3,2,1,0,1],[7,7,7,7,7,7,7,7,7,6,5,4,3,2,1,0]],an=500,Go=-10,tu=511,QA=an-Go+1,vd=an-Go+2,ub=new ArrayBuffer(8),Yd=new Uint8Array(ub),ji=new DataView(ub),tS=16*1024;rb=[[15,14,13,12,11,10,9,8],[14,0,1,3,6,10,10,9],[13,1,2,4,7,11,11,10],[12,3,4,5,8,12,12,11],[11,6,7,8,9,13,13,12],[10,10,11,12,13,14,14,13],[9,10,11,12,13,14,15,14],[8,9,10,11,12,13,14,15]],eS=[[0,1,2,3,4,5,6,7],[1,0,1,2,3,4,5,6],[2,1,0,1,2,3,4,5],[3,2,1,0,1,2,3,4],[4,3,2,1,0,1,2,3],[5,4,3,2,1,0,1,2],[6,5,4,3,2,1,0,1],[7,6,5,4,3,2,1,0]],eu=class{bytes;length;offset=0;discardedByteLength=0;constructor(t){this.bytes=t,this.length=t.byteLength}get byteOffset(){return this.discardedByteLength+this.offset}get availableByteLength(){return this.length-this.offset}get data(){return this.length===this.bytes.byteLength?this.bytes:this.bytes.subarray(0,this.length)}append(t){if(t.byteLength===0)return;let e=this.length+t.byteLength;if(e>this.bytes.byteLength){let n=Math.max(e,Math.max(64,this.bytes.byteLength*2)),s=new Uint8Array(n);s.set(this.bytes.subarray(0,this.length)),this.bytes=s}this.bytes.set(t,this.length),this.length=e}discardConsumedInput(){this.offset!==0&&(this.bytes=this.bytes.slice(this.offset,this.length),this.discardedByteLength+=this.offset,this.length-=this.offset,this.offset=0)}getByte(){if(this.offset>=this.length)throw new it;return this.bytes[this.offset++]}getBytes(t,e,n){if(this.offset+n>this.length)throw new it;t.set(this.bytes.subarray(this.offset,this.offset+n),e),this.offset+=n}consume(t){if(this.offset+t>this.length)throw new it;let e=this.offset;return this.offset+=t,e}getUint32(){let t=this.getByte(),e=this.getByte(),n=this.getByte(),s=this.getByte();return(t|e<<8|n<<16|s<<24>>>0)>>>0}},jt=class{symbols;distribution;symbolCount;decoderTable;totalCount=0;updateCycle;symbolsUntilUpdate;lastSymbol;tableSize=0;tableShift=0;constructor(t){if(t<2||t>2048)throw new Error(`Invalid arithmetic model symbol count ${t}`);if(this.symbols=t,this.lastSymbol=t-1,t>16){let e=3;for(;t>1<<e+2;)e++;this.tableSize=1<<e,this.tableShift=Qa-e,this.decoderTable=new Uint32Array(this.tableSize+2)}else this.decoderTable=null;this.distribution=new Uint32Array(t),this.symbolCount=new Uint32Array(t),this.symbolCount.fill(1),this.updateCycle=t,this.symbolsUntilUpdate=t,this.update(),this.symbolsUntilUpdate=this.updateCycle=t+6>>1}update(){if(this.totalCount+=this.updateCycle,this.totalCount>XA){this.totalCount=0;for(let i=0;i<this.symbols;i++)this.symbolCount[i]=this.symbolCount[i]+1>>1,this.totalCount+=this.symbolCount[i]}let t=0,e=0,n=2147483648/this.totalCount|0;if(this.decoderTable){for(let i=0;i<this.symbols;i++){this.distribution[i]=n*t/eb|0,t+=this.symbolCount[i];let o=this.distribution[i]>>this.tableShift;for(;e<o;)this.decoderTable[++e]=i-1}for(this.decoderTable[0]=0;e<=this.tableSize;)this.decoderTable[++e]=this.symbols-1}else for(let i=0;i<this.symbols;i++)this.distribution[i]=n*t/eb|0,t+=this.symbolCount[i];this.updateCycle=5*this.updateCycle>>2;let s=this.symbols+6<<3;this.updateCycle>s&&(this.updateCycle=s),this.symbolsUntilUpdate=this.updateCycle}},Ld=class{updateCycle=4;bitsUntilUpdate=4;bit0Prob=1<<pu-1;bit0Count=1;bitCount=2;update(){this.bitCount+=this.updateCycle,this.bitCount>ZA&&(this.bitCount=this.bitCount+1>>1,this.bit0Count=this.bit0Count+1>>1,this.bit0Count===this.bitCount&&this.bitCount++);let t=2147483648/this.bitCount|0;this.bit0Prob=this.bit0Count*t/HA|0,this.updateCycle=5*this.updateCycle>>2,this.updateCycle>64&&(this.updateCycle=64),this.bitsUntilUpdate=this.updateCycle}},ne=class{input;inputBytes=null;inputOffset=0;inputEnd=0;value=0;length=YA;valid=!1;constructor(t=null){this.input=t}initStream(t,e){e?(this.inputBytes=t.data,this.inputOffset=t.consume(e),this.inputEnd=this.inputOffset+e,this.input=null,this.readInitBytes(),this.valid=!0):this.valid=!1}readInitBytes(){if(this.inputBytes){let e=this.inputOffset;if(e+4>this.inputEnd)throw new it;this.value=(this.inputBytes[e]<<24>>>0|this.inputBytes[e+1]<<16|this.inputBytes[e+2]<<8|this.inputBytes[e+3])>>>0,this.inputOffset=e+4;return}let t=this.input;this.value=(t.getByte()<<24>>>0|t.getByte()<<16|t.getByte()<<8|t.getByte())>>>0}decodeBit(t){let e=this.value,n=this.length,s=t.bit0Prob*(n>>>pu),i=e>=s?1:0;return i===0?(this.length=s>>>0,t.bit0Count++):(this.value=e-s>>>0,this.length=n-s>>>0),this.length<ko&&this.renormalize(),--t.bitsUntilUpdate===0&&t.update(),i}decodeSymbol(t){let e,n,s=this.length,i=s,o=this.value,a=t.distribution,c=t.decoderTable;if(c){s>>>=Qa;let l=o/s|0,u=l>>t.tableShift;e=c[u];let f=c[u+1]+1;for(;f>e+1;){let h=e+f>>1;a[h]>l?f=h:e=h}n=a[e]*s,e!==t.lastSymbol&&(i=a[e+1]*s)}else{n=0,e=0,s>>>=Qa;let l=t.symbols,u=l>>1;do{let f=s*a[u];f>o?(l=u,i=f):(e=u,n=f),u=e+l>>1}while(u!==e)}return this.value=o-n>>>0,this.length=i-n>>>0,this.length<ko&&this.renormalize(),t.symbolCount[e]++,--t.symbolsUntilUpdate===0&&t.update(),e}readBits(t){if(t>19){let i=this.readShort();return(this.readBits(t-16)<<16|i)>>>0}let e=this.length>>>t,n=this.value,s=n/e|0;return this.value=n-e*s>>>0,this.length=e>>>0,e<ko&&this.renormalize(),s>>>0}readShort(){let t=this.length>>>16,e=this.value,n=e/t|0;return this.value=e-t*n>>>0,this.length=t>>>0,t<ko&&this.renormalize(),n&65535}readInt(){let t=this.readShort();return(this.readShort()<<16|t)>>>0}readUint64(){let t=this.readInt(),e=this.readInt();return BigInt(e)<<32n|BigInt(t)}renormalize(){let t=this.value,e=this.length;if(this.inputBytes){let n=this.inputBytes,s=this.inputEnd,i=this.inputOffset;do{if(i>=s)throw new it;t=(t<<8|n[i++])>>>0,e=e<<8>>>0}while(e<ko);this.inputOffset=i}else{let n=this.input;do t=(t<<8|n.getByte())>>>0,e=e<<8>>>0;while(e<ko)}this.value=t,this.length=e}},Td=class{contexts;bitsHigh;corrBits;corrRange;corrMin;mBits=[];mCorrector0=new Ld;mCorrector=[];k=0;constructor(t=16,e=1,n=8,s=0){if(this.contexts=e,this.bitsHigh=n,s){for(this.corrBits=0,this.corrRange=s;s;)s>>=1,this.corrBits++;this.corrRange===1<<this.corrBits-1&&this.corrBits--,this.corrMin=-(this.corrRange/2)}else t&&t<32?(this.corrBits=t,this.corrRange=1<<t,this.corrMin=-(this.corrRange/2)):(this.corrBits=32,this.corrRange=0,this.corrMin=-2147483648)}init(){if(!this.mBits.length){for(let t=0;t<this.contexts;t++)this.mBits.push(new jt(this.corrBits+1));for(let t=1;t<=this.corrBits;t++){let e=t<=this.bitsHigh?1<<t:1<<this.bitsHigh;this.mCorrector.push(new jt(e))}}}decompress(t,e,n){let s=t.decodeSymbol(this.mBits[n]);this.k=s;let i;if(s)if(s<32){let a=this.bitsHigh,c=this.mCorrector[s-1];if(s<=a)i=t.decodeSymbol(c);else{let l=s-a;i=t.decodeSymbol(c),i=i<<l|t.readBits(l)}i>=1<<s-1?i+=1:i-=(1<<s)-1}else i=this.corrMin;else i=t.decodeBit(this.mCorrector0);let o=cn(e+i);return this.corrRange===0||(o<0?o=cn(o+this.corrRange):o>=this.corrRange&&(o=cn(o-this.corrRange))),o}},jo=class{value0=0;value1=0;value2=0;value3=0;value4=0;high=!0;add(t){this.high?t<this.value2?(this.value4=this.value3,this.value3=this.value2,t<this.value0?(this.value2=this.value1,this.value1=this.value0,this.value0=t):t<this.value1?(this.value2=this.value1,this.value1=t):this.value2=t):(t<this.value3?(this.value4=this.value3,this.value3=t):this.value4=t,this.high=!1):this.value2<t?(this.value0=this.value1,this.value1=this.value2,this.value4<t?(this.value2=this.value3,this.value3=this.value4,this.value4=t):this.value3<t?(this.value2=this.value3,this.value3=t):this.value2=t):(this.value1<t?(this.value0=this.value1,this.value1=t):this.value0=t,this.high=!0)}get(){return this.value2}};Zs=class{itemVersion;stream;decoder;changedValuesModel=new jt(64);bitByteModel=ge(256,256);classificationModel=ge(256,256);scanAngleRankModel=ge(2,256);userDataModel=ge(256,256);intensity=It(16,4);pointSourceId=It(16,1);dx=It(32,2);dy=It(32,22);z=It(32,20);lastIntensity=new Array(16).fill(0);lastHeight=new Array(8).fill(0);lastXDiffMedian=Array.from({length:16},()=>new jo);lastYDiffMedian=Array.from({length:16},()=>new jo);haveLast=!1;last=sb();firstPoint=sb();legacyXDiffs=[0,0,0];legacyYDiffs=[0,0,0];legacyDifferenceIndex=0;legacyScanAngle=null;constructor(t,e=2){this.itemVersion=e,this.stream=t,this.decoder=new ne(t),e===1&&(this.legacyScanAngle=It(8,2),this.dx=It(32,1),this.dy=It(32,20),this.intensity=It(16,1))}getDecoder(){return this.decoder}decompress(t,e){let n=this.decompressPoint();return cS(n,t,e),e+20}decompressPoint(){if(!this.haveLast)return this.haveLast=!0,oS(this.last,this.stream),aS(this.firstPoint,this.last),this.itemVersion===2&&(this.last.intensity=0),this.firstPoint;if(this.itemVersion===1)return this.decompressLegacyPoint();let t=this.decoder.decodeSymbol(this.changedValuesModel);if(t){t&32&&(this.last.bitByte=this.decoder.decodeSymbol(this.bitByteModel[this.last.bitByte]));let h=ib(this.last),m=ob(this.last),y=rb[m][h];if(t&16?(this.last.intensity=this.intensity.decompress(this.decoder,this.lastIntensity[y],y<3?y:3)&65535,this.lastIntensity[y]=this.last.intensity):this.last.intensity=this.lastIntensity[y],t&8&&(this.last.classification=this.decoder.decodeSymbol(this.classificationModel[this.last.classification])),t&4){let g=this.decoder.decodeSymbol(this.scanAngleRankModel[lS(this.last)]);this.last.scanAngleRank=qd(this.last.scanAngleRank+g)}t&2&&(this.last.userData=this.decoder.decodeSymbol(this.userDataModel[this.last.userData])),t&1&&(this.last.pointSourceId=this.pointSourceId.decompress(this.decoder,this.last.pointSourceId,0)&65535)}let e=ib(this.last),n=ob(this.last),s=rb[n][e],i=eS[n][e],o=this.lastXDiffMedian[s].get(),a=this.dx.decompress(this.decoder,o,n===1?1:0);this.last.x=cn(this.last.x+a),this.lastXDiffMedian[s].add(a);let c=this.lastYDiffMedian[s].get(),l=Math.min(this.dx.k,20)&-2,u=this.dy.decompress(this.decoder,c,(n===1?1:0)+l);this.last.y=cn(this.last.y+u),this.lastYDiffMedian[s].add(u);let f=Math.min(this.dx.k+this.dy.k>>1,18)&-2;return this.last.z=this.z.decompress(this.decoder,this.lastHeight[i],(n===1?1:0)+f),this.lastHeight[i]=this.last.z,this.last}decompressLegacyPoint(){let t=this.dx.decompress(this.decoder,nb(this.legacyXDiffs),0);this.last.x=cn(this.last.x+t);let e=this.dx.k,n=this.dy.decompress(this.decoder,nb(this.legacyYDiffs),Math.min(e,19));this.last.y=cn(this.last.y+n),e=e+this.dy.k>>1,this.last.z=this.z.decompress(this.decoder,this.last.z,Math.min(e,19));let s=this.decoder.decodeSymbol(this.changedValuesModel);return s&32&&(this.last.intensity=this.intensity.decompress(this.decoder,this.last.intensity,0)&65535),s&16&&(this.last.bitByte=this.decoder.decodeSymbol(this.bitByteModel[this.last.bitByte])),s&8&&(this.last.classification=this.decoder.decodeSymbol(this.classificationModel[this.last.classification])),s&4&&(this.last.scanAngleRank=qd(this.legacyScanAngle.decompress(this.decoder,this.last.scanAngleRank&255,e<3?1:0))),s&2&&(this.last.userData=this.decoder.decodeSymbol(this.userDataModel[this.last.userData])),s&1&&(this.last.pointSourceId=this.pointSourceId.decompress(this.decoder,this.last.pointSourceId,0)&65535),this.legacyXDiffs[this.legacyDifferenceIndex]=t,this.legacyYDiffs[this.legacyDifferenceIndex]=n,this.legacyDifferenceIndex=(this.legacyDifferenceIndex+1)%3,this.last}readFirstMetadata(){this.decoder.readInitBytes()}},tc=class{itemVersion;stream;decoder;haveLast=!1;lastRed=0;lastGreen=0;lastBlue=0;usedModel=new jt(128);diffModel=ge(6,256);legacyRgb=null;constructor(t,e,n=2){this.itemVersion=n,this.stream=t,this.decoder=e,n===1&&(this.usedModel=new jt(64),this.legacyRgb=It(8,6))}decompress(t,e){return this.decompressRgb(),ar(this.lastRed,t,e),ar(this.lastGreen,t,e+2),ar(this.lastBlue,t,e+4),e+6}decompressRgb(){if(!this.haveLast){this.haveLast=!0,this.lastRed=Ys(this.stream),this.lastGreen=Ys(this.stream),this.lastBlue=Ys(this.stream);return}let t=this.decoder.decodeSymbol(this.usedModel);if(this.itemVersion===1){this.lastRed=this.decodeLegacyColor(this.lastRed,0,t),this.lastGreen=this.decodeLegacyColor(this.lastGreen,1,t),this.lastBlue=this.decodeLegacyColor(this.lastBlue,2,t);return}let e=0,n=0,s=0;if(t&1?e=this.decoder.decodeSymbol(this.diffModel[0])+(this.lastRed&255)&255:e=this.lastRed&255,t&2?e|=(this.decoder.decodeSymbol(this.diffModel[1])+(this.lastRed>>8)&255)<<8:e|=this.lastRed&65280,t&64){let i=(e&255)-(this.lastRed&255);t&4?n=this.decoder.decodeSymbol(this.diffModel[2])+$s(i+(this.lastGreen&255))&255:n=this.lastGreen&255,t&16?(i=(i+((n&255)-(this.lastGreen&255)))/2|0,s=this.decoder.decodeSymbol(this.diffModel[4])+$s(i+(this.lastBlue&255))&255):s=this.lastBlue&255,i=(e>>8)-(this.lastRed>>8),t&8?n|=(this.decoder.decodeSymbol(this.diffModel[3])+$s(i+(this.lastGreen>>8))&255)<<8:n|=this.lastGreen&65280,t&32?(i=(i+(n>>8)-(this.lastGreen>>8))/2|0,s|=(this.decoder.decodeSymbol(this.diffModel[5])+$s(i+(this.lastBlue>>8))&255)<<8):s|=this.lastBlue&65280}else n=e,s=e;this.lastRed=e,this.lastGreen=n,this.lastBlue=s}decodeLegacyColor(t,e,n){let s=0;for(let i=0;i<2;i++){let o=e*2+i,a=t>>i*8&255,c=n&1<<o?this.legacyRgb.decompress(this.decoder,a,o):a;s|=c<<i*8}return s}get decodedRed(){return this.lastRed}get decodedGreen(){return this.lastGreen}get decodedBlue(){return this.lastBlue}},Hs=class{itemVersion;stream;decoder;count;haveLast=!1;last;models;legacyBytes;constructor(t,e,n,s=2){this.itemVersion=s,this.stream=t,this.decoder=e,this.count=n,this.last=new Uint8Array(n),this.models=ge(n,256),this.legacyBytes=s===1?It(8,n):null}get byteCount(){return this.count}decompress(t,e){return this.decompressToTarget(t,e),e+this.count}decompressToTarget(t,e=0){if(this.count!==0){if(!this.haveLast){this.stream.getBytes(this.last,0,this.count),t?.set(this.last,e),this.haveLast=!0;return}for(let n=0;n<this.count;n++){let s=this.itemVersion===1?this.legacyBytes.decompress(this.decoder,this.last[n],n):this.last[n]+this.decoder.decodeSymbol(this.models[n])&255;t&&(t[e+n]=s),this.last[n]=s}}}};(function(r){r[r.Full=0]="Full",r[r.PointData=1]="PointData"})(Nt||(Nt={}));Md=class{changedValuesModel=ge(8,128);scannerChannelModel=new jt(3);returnNumberGpsSameModel=new jt(13);numberReturnsModel=ge(16,16);returnNumberModel=ge(16,16);classModel=[];flagModel=[];userDataModel=[];gpsTimeMultiModel;gpsTime0DiffModel;dx=It(32,2);dy=It(32,22);z=It(32,20);intensity=null;scanAngle;pointSourceId;gpsTime;haveLast=!1;last=iS();lastIntensity=[];lastZ=new Array(8).fill(0);lastXDiffMedian=Array.from({length:12},()=>new jo);lastYDiffMedian=Array.from({length:12},()=>new jo);lastGpsSequence=0;nextGpsSequence=0;lastGpsTime=[];lastGpsTimeDiff=[];multiExtremeCounter=[];gpsTimeChange=!1;constructor(t,e){(t===Nt.Full||e?.classification)&&(this.classModel=ge(64,256)),(t===Nt.Full||e?.intensity)&&(this.intensity=It(16,4),this.lastIntensity=new Array(8).fill(0)),(t===Nt.Full||e?.userData)&&(this.userDataModel=ge(64,256)),(t===Nt.Full||e?.scanAngle)&&(this.scanAngle=It(16,2)),(t===Nt.Full||e?.pointSourceId)&&(this.pointSourceId=It(16,1)),(t===Nt.Full||e?.flags)&&(this.flagModel=ge(64,64)),(t===Nt.Full||e?.gpsTime)&&(this.gpsTimeMultiModel=new jt(515),this.gpsTime0DiffModel=new jt(5),this.gpsTime=It(32,9),this.lastGpsTime=new Array(4).fill(0),this.lastGpsTimeDiff=new Array(4).fill(0),this.multiExtremeCounter=new Array(4).fill(0))}},qi=class{stream;contexts;activeContext=null;decompressOptionalFields;xy=new ne;z=new ne;classification;flags;intensity;scanAngle;userData;pointSourceId;gpsTime;sizes=[];currentScannerChannel=0;itemContextChannel=0;itemVersion;constructor(t,e=Nt.Full,n=3,s=null){this.stream=t,this.itemVersion=n,this.contexts=Array.from({length:4},()=>new Md(e,s)),this.decompressOptionalFields=e===Nt.Full,this.classification=this.decompressOptionalFields||s?.classification?new ne:null,this.flags=this.decompressOptionalFields||s?.flags?new ne:null,this.intensity=this.decompressOptionalFields||s?.intensity?new ne:null,this.scanAngle=this.decompressOptionalFields||s?.scanAngle?new ne:null,this.userData=this.decompressOptionalFields||s?.userData?new ne:null,this.pointSourceId=this.decompressOptionalFields||s?.pointSourceId?new ne:null,this.gpsTime=this.decompressOptionalFields||s?.gpsTime?new ne:null}readSizes(){this.sizes=[];for(let t=0;t<9;t++)this.sizes.push(this.stream.getUint32())}readData(){let t=0;this.xy.initStream(this.stream,this.sizes[t++]),this.z.initStream(this.stream,this.sizes[t++]),this.initializeOptionalStream(this.classification,this.sizes[t++]),this.initializeOptionalStream(this.flags,this.sizes[t++]),this.initializeOptionalStream(this.intensity,this.sizes[t++]),this.initializeOptionalStream(this.scanAngle,this.sizes[t++]),this.initializeOptionalStream(this.userData,this.sizes[t++]),this.initializeOptionalStream(this.pointSourceId,this.sizes[t++]),this.initializeOptionalStream(this.gpsTime,this.sizes[t++])}initializeOptionalStream(t,e){t?t.initStream(this.stream,e):this.stream.consume(e)}decompress(t,e){let n=this.decompressPoint(t,e);return hS(n,t,e),e+30}decompressPoint(t,e=0){let n=this.gpsTime!==null;if(!this.activeContext){let rt=this.contexts[0].last;t?(this.stream.getBytes(t,e,30),uS(rt,t,e)):fS(rt,this.stream),this.currentScannerChannel=dS(rt),this.itemContextChannel=this.currentScannerChannel;let tt=this.contexts[this.currentScannerChannel];return tt.last!==rt&&ab(tt.last,rt),tt.haveLast=!0,n&&(tt.lastGpsTime[0]=tt.last.gpsTime),this.activeContext=tt,tt.lastZ.fill(tt.last.z),tt.lastIntensity.length&&tt.lastIntensity.fill(tt.last.intensity),tt.last}let s=this.activeContext,i=s.last.returns,o=i&15,a=(o===1?1:0)|(o>=i>>4?1:0)<<1|(s.gpsTimeChange?1:0)<<2,c=this.xy.decodeSymbol(s.changedValuesModel[a]),l=!!(c>>6&1),u=!!(c>>5&1),f=!!(c>>4&1),h=!!(c>>3&1),m=!!(c>>2&1),y=!!(c>>1&1),g=!!(c&1),x=g&&!y,B=y&&!g,q=g&&y;this.itemContextChannel=0;let M=this.currentScannerChannel,b=s;if(l){let rt=this.xy.decodeSymbol(s.scannerChannelModel);M=(M+rt+1)%4,b=this.contexts[M],this.activeContext=b,this.itemContextChannel=M}this.currentScannerChannel=M,this.itemVersion>=4&&(this.itemContextChannel=M),b.haveLast||(b.haveLast=!0,ab(b.last,s.last),b.lastZ.fill(s.last.z),b.lastIntensity.length&&b.lastIntensity.fill(s.last.intensity),n&&(b.lastGpsTime[0]=s.last.gpsTime)),pS(b.last,M);let C=b.last.returns>>4,_=b.last.returns&15;m&&(C=this.xy.decodeSymbol(b.numberReturnsModel[C])),x?_=(_+1)%16:B?_=(_+15)%16:q&&(_=f?this.xy.decodeSymbol(b.returnNumberModel[_]):(_+this.xy.decodeSymbol(b.returnNumberGpsSameModel)+2)%16),b.last.returns=C<<4|_;let $=KA[C][_]<<1|(f?1:0),X=b.lastXDiffMedian[$].get(),ft=b.dx.decompress(this.xy,X,C===1?1:0);b.last.x=cn(b.last.x+ft),b.lastXDiffMedian[$].add(ft);let dt=Math.min(b.dx.k,20)&-2,Bt=b.lastYDiffMedian[$].get(),se=b.dy.decompress(this.xy,Bt,(C===1?1:0)|dt);if(b.last.y=cn(b.last.y+se),b.lastYDiffMedian[$].add(se),this.z.valid){let rt=Math.min(b.dx.k+b.dy.k>>1,18)&-2,tt=JA[C][_],Ye=b.z.decompress(this.z,b.lastZ[tt],(C===1?1:0)|rt);b.last.z=Ye,b.lastZ[tt]=Ye}if(this.classification?.valid){let rt=(_===1&&_>=C?1:0)|(b.last.classification&31)<<1;b.last.classification=this.classification.decodeSymbol(b.classModel[rt])}if(this.flags?.valid){let rt=bS(b.last),tt=this.flags.decodeSymbol(b.flagModel[rt]);gS(b.last,tt>>5&1),yS(b.last,tt>>4&1),mS(b.last,tt&15)}if(this.intensity?.valid){let rt=(f?1:0)|(_>=C?1:0)<<1|(_===1?1:0)<<2,tt=b.intensity.decompress(this.intensity,b.lastIntensity[rt],rt>>1);b.lastIntensity[rt]=tt&65535,b.last.intensity=tt&65535}if(h&&this.scanAngle&&(b.last.scanAngle=Zd(b.scanAngle.decompress(this.scanAngle,b.last.scanAngle,f?1:0))),this.userData?.valid){let rt=b.last.userData>>2;b.last.userData=this.userData.decodeSymbol(b.userDataModel[rt])}return u&&this.pointSourceId&&(b.last.pointSourceId=b.pointSourceId.decompress(this.pointSourceId,b.last.pointSourceId,0)&65535),f&&this.gpsTime&&this.decodeGpsTime(b),b.gpsTimeChange=f,b.last}decodeGpsTime(t){let e=this.gpsTime;for(;;){if(t.lastGpsTimeDiff[t.lastGpsSequence]===0){let n=e.decodeSymbol(t.gpsTime0DiffModel);if(n===0){let s=t.gpsTime.decompress(e,0,0);t.lastGpsTimeDiff[t.lastGpsSequence]=s,t.lastGpsTime[t.lastGpsSequence]=qs(t.lastGpsTime[t.lastGpsSequence],s),t.multiExtremeCounter[t.lastGpsSequence]=0}else if(n===1){t.nextGpsSequence=t.nextGpsSequence+1&3;let s=uu(t.lastGpsTime[t.lastGpsSequence]),i=t.gpsTime.decompress(e,Number(s>>32n)|0,8),o=e.readInt();t.lastGpsTime[t.nextGpsSequence]=Vo(BigInt(i>>>0)<<32n|BigInt(o)),t.lastGpsSequence=t.nextGpsSequence,t.lastGpsTimeDiff[t.lastGpsSequence]=0,t.multiExtremeCounter[t.lastGpsSequence]=0}else{t.lastGpsSequence=t.lastGpsSequence+n-1&3;continue}}else{let n=e.decodeSymbol(t.gpsTimeMultiModel),s=0;if(n===1){let i=t.gpsTime.decompress(e,t.lastGpsTimeDiff[t.lastGpsSequence],1);t.lastGpsTime[t.lastGpsSequence]=qs(t.lastGpsTime[t.lastGpsSequence],i),t.multiExtremeCounter[t.lastGpsSequence]=0}else if(n<tu){if(n===0)s=t.gpsTime.decompress(e,0,7),t.multiExtremeCounter[t.lastGpsSequence]++,t.multiExtremeCounter[t.lastGpsSequence]>3&&(t.multiExtremeCounter[t.lastGpsSequence]=0,t.lastGpsTimeDiff[t.lastGpsSequence]=s);else if(n<an){let i=n<10?2:3;s=t.gpsTime.decompress(e,n*t.lastGpsTimeDiff[t.lastGpsSequence],i)}else n===an?(s=t.gpsTime.decompress(e,an*t.lastGpsTimeDiff[t.lastGpsSequence],4),t.multiExtremeCounter[t.lastGpsSequence]++,t.multiExtremeCounter[t.lastGpsSequence]>3&&(t.multiExtremeCounter[t.lastGpsSequence]=0,t.lastGpsTimeDiff[t.lastGpsSequence]=s)):(n=an-n,n>Go?s=t.gpsTime.decompress(e,n*t.lastGpsTimeDiff[t.lastGpsSequence],5):(s=t.gpsTime.decompress(e,Go*t.lastGpsTimeDiff[t.lastGpsSequence],6),t.multiExtremeCounter[t.lastGpsSequence]++,t.multiExtremeCounter[t.lastGpsSequence]>3&&(t.multiExtremeCounter[t.lastGpsSequence]=0,t.lastGpsTimeDiff[t.lastGpsSequence]=s)));t.lastGpsTime[t.lastGpsSequence]=qs(t.lastGpsTime[t.lastGpsSequence],s)}else if(n===tu){t.nextGpsSequence=t.nextGpsSequence+1&3;let i=uu(t.lastGpsTime[t.lastGpsSequence]),o=t.gpsTime.decompress(e,Number(i>>32n)|0,8),a=e.readInt();t.lastGpsTime[t.nextGpsSequence]=Vo(BigInt(o>>>0)<<32n|BigInt(a)),t.lastGpsSequence=t.nextGpsSequence,t.lastGpsTimeDiff[t.lastGpsSequence]=0,t.multiExtremeCounter[t.lastGpsSequence]=0}else if(n>=tu){t.lastGpsSequence=t.lastGpsSequence+n-tu&3;continue}}t.last.gpsTime=t.lastGpsTime[t.lastGpsSequence];break}}},Dd=class{haveLast=!1;lastRed=0;lastGreen=0;lastBlue=0;usedModel=new jt(128);diffModel=ge(6,256)},ec=class{stream;contexts=Array.from({length:4},()=>new Dd);activeContext=null;lastChannel=-1;rgbCount=0;rgb=new ne;decodedRed=0;decodedGreen=0;decodedBlue=0;itemVersion;constructor(t,e=3){this.stream=t,this.itemVersion=e}readSizes(){this.rgbCount=this.stream.getUint32()}readData(){this.rgb.initStream(this.stream,this.rgbCount)}decompress(t,e,n){return this.decompressRgb(n),ar(this.decodedRed,t,e),ar(this.decodedGreen,t,e+2),ar(this.decodedBlue,t,e+4),e+6}decompressRgb(t){if(this.lastChannel===-1){this.decodedRed=this.stream.getByte()|this.stream.getByte()<<8,this.decodedGreen=this.stream.getByte()|this.stream.getByte()<<8,this.decodedBlue=this.stream.getByte()|this.stream.getByte()<<8;let c=this.contexts[t];c.lastRed=this.decodedRed,c.lastGreen=this.decodedGreen,c.lastBlue=this.decodedBlue,c.haveLast=!0,this.lastChannel=t,this.activeContext=c;return}if(this.rgbCount===0){let c=this.activeContext;this.decodedRed=c.lastRed,this.decodedGreen=c.lastGreen,this.decodedBlue=c.lastBlue;return}let e=this.activeContext,n=e;if(t!==this.lastChannel){let c=e;e=this.contexts[t],n=c,this.lastChannel=t,e.haveLast||(e.haveLast=!0,e.lastRed=c.lastRed,e.lastGreen=c.lastGreen,e.lastBlue=c.lastBlue,n=e),this.itemVersion>=4&&(n=e),this.activeContext=e}let s=this.rgb.decodeSymbol(e.usedModel),i=0,o=0,a=0;if(s&1?i=this.rgb.decodeSymbol(e.diffModel[0])+(n.lastRed&255)&255:i=n.lastRed&255,s&2){let c=this.rgb.decodeSymbol(e.diffModel[1]);i|=(c+(n.lastRed>>8)&255)<<8}else i|=n.lastRed&65280;if(s&64){let c=(i&255)-(n.lastRed&255);if(s&4?o=this.rgb.decodeSymbol(e.diffModel[2])+$s(c+(n.lastGreen&255))&255:o=n.lastGreen&255,s&16){let l=this.rgb.decodeSymbol(e.diffModel[4]);c=(c+((o&255)-(n.lastGreen&255)))/2|0,a=l+$s(c+(n.lastBlue&255))&255}else a=n.lastBlue&255;if(c=(i>>8)-(n.lastRed>>8),s&8){let l=this.rgb.decodeSymbol(e.diffModel[3]);o|=(l+$s(c+(n.lastGreen>>8))&255)<<8}else o|=n.lastGreen&65280;if(s&32){let l=this.rgb.decodeSymbol(e.diffModel[5]);c=(c+(o>>8)-(n.lastGreen>>8))/2|0,a|=(l+$s(c+(n.lastBlue>>8))&255)<<8}else a|=n.lastBlue&65280}else o=i,a=i;n.lastRed=i,n.lastGreen=o,n.lastBlue=a,this.decodedRed=i,this.decodedGreen=o,this.decodedBlue=a}},Cd=class{haveLast=!1;lastValue=0;usedModel=new jt(4);diffModel=ge(2,256)},ru=class{stream;contexts=Array.from({length:4},()=>new Cd);lastChannel=-1;nirCount=0;nir=new ne;scratch=new Uint8Array(2);decodedNir=0;itemVersion;constructor(t,e=3){this.stream=t,this.itemVersion=e}readSizes(){this.nirCount=this.stream.getUint32()}readData(){this.nir.initStream(this.stream,this.nirCount)}decompress(t,e,n){if(this.lastChannel===-1){this.stream.getBytes(t,e,2);let c=this.contexts[n];return c.lastValue=au(t,e),c.haveLast=!0,this.lastChannel=n,this.decodedNir=c.lastValue,e+2}if(this.nirCount===0)return ar(this.contexts[this.lastChannel].lastValue,t,e),this.decodedNir=this.contexts[this.lastChannel].lastValue,e+2;let s=this.contexts[n],i=this.contexts[this.lastChannel];n!==this.lastChannel&&(this.lastChannel=n,s.haveLast||(s.haveLast=!0,s.lastValue=i.lastValue,i=s),this.itemVersion>=4&&(i=s));let o=this.nir.decodeSymbol(s.usedModel),a=o&1?this.nir.decodeSymbol(s.diffModel[0])+(i.lastValue&255)&255:i.lastValue&255;return a|=o&2?(this.nir.decodeSymbol(s.diffModel[1])+(i.lastValue>>8)&255)<<8:i.lastValue&65280,i.lastValue=a,this.decodedNir=a,ar(a,t,e),e+2}decompressNir(t){return this.decompress(this.scratch,0,t),this.decodedNir}},nu=class{haveLast=!1;descriptorIndex=0;offset=0n;packetSize=0;returnPointBits=0;xBits=0;yBits=0;zBits=0;lastOffsetDifference=0;lastOffsetDifferenceSymbol=0;descriptorModel=new jt(256);offsetDifferenceModels=ge(4,4);offsetDifferenceDecompressor=It(32,1);packetSizeDecompressor=It(32,1);returnPointDecompressor=It(32,1);vectorDecompressor=It(32,3)},su=class{stream;contexts=Array.from({length:4},()=>new nu);lastChannel=-1;wavePacketByteCount=0;decoder=new ne;itemVersion;constructor(t,e){this.stream=t,this.itemVersion=e}readSizes(){this.wavePacketByteCount=this.stream.getUint32()}readData(){this.decoder.initStream(this.stream,this.wavePacketByteCount)}decompress(t,e,n){if(this.lastChannel===-1){this.stream.getBytes(t,e,29);let a=this.contexts[n];return this.readContext(a,t,e),a.haveLast=!0,this.lastChannel=n,e+29}let s=this.contexts[this.lastChannel],i=this.contexts[n],o=i;return n!==this.lastChannel&&(o=s,i.haveLast?this.itemVersion>=4&&(o=i):(this.copyLastWavePacket(i,s),i.haveLast=!0,o=i),this.lastChannel=n),this.wavePacketByteCount&&this.decodeContext(i,o),this.writeContext(o,t,e),e+29}decompressToTarget(t,e,n){this.decompress(t,e,n)}decodeContext(t,e){e.descriptorIndex=this.decoder.decodeSymbol(t.descriptorModel);let n=this.decoder.decodeSymbol(t.offsetDifferenceModels[t.lastOffsetDifferenceSymbol]);switch(t.lastOffsetDifferenceSymbol=n,n){case 0:break;case 1:e.offset=BigInt.asUintN(64,e.offset+BigInt(e.packetSize));break;case 2:t.lastOffsetDifference=t.offsetDifferenceDecompressor.decompress(this.decoder,t.lastOffsetDifference,0),e.offset=BigInt.asUintN(64,e.offset+BigInt(t.lastOffsetDifference));break;default:e.offset=this.decoder.readUint64();break}e.packetSize=t.packetSizeDecompressor.decompress(this.decoder,e.packetSize|0,0)>>>0,e.returnPointBits=t.returnPointDecompressor.decompress(this.decoder,e.returnPointBits,0),e.xBits=t.vectorDecompressor.decompress(this.decoder,e.xBits,0),e.yBits=t.vectorDecompressor.decompress(this.decoder,e.yBits,1),e.zBits=t.vectorDecompressor.decompress(this.decoder,e.zBits,2)}copyLastWavePacket(t,e){t.descriptorIndex=e.descriptorIndex,t.offset=e.offset,t.packetSize=e.packetSize,t.returnPointBits=e.returnPointBits,t.xBits=e.xBits,t.yBits=e.yBits,t.zBits=e.zBits}readContext(t,e,n){t.descriptorIndex=e[n],t.offset=fb(e,n+1),t.packetSize=cu(e,n+9),t.returnPointBits=Vr(e,n+13),t.xBits=Vr(e,n+17),t.yBits=Vr(e,n+21),t.zBits=Vr(e,n+25)}writeContext(t,e,n){e[n]=t.descriptorIndex,hb(t.offset,e,n+1),lu(t.packetSize,e,n+9),Ue(t.returnPointBits,e,n+13),Ue(t.xBits,e,n+17),Ue(t.yBits,e,n+21),Ue(t.zBits,e,n+25)}},Fd=class{haveLast=!1;last;byteModel;constructor(t){this.last=new Uint8Array(t),this.byteModel=ge(t,256)}},$i=class{stream;count;contexts;lastChannel=-1;byteCount;byteDecoder;itemVersion;constructor(t,e,n=3){this.stream=t,this.count=e,this.itemVersion=n,this.contexts=Array.from({length:4},()=>new Fd(e)),this.byteCount=new Array(e).fill(0),this.byteDecoder=Array.from({length:e},()=>new ne)}readSizes(){for(let t=0;t<this.count;t++)this.byteCount[t]=this.stream.getUint32()}readData(){for(let t=0;t<this.count;t++)this.byteDecoder[t].initStream(this.stream,this.byteCount[t])}decompress(t,e,n){if(this.lastChannel===-1){this.stream.getBytes(t,e,this.count);let o=this.contexts[n];return o.last.set(t.subarray(e,e+this.count)),o.haveLast=!0,this.lastChannel=n,e+this.count}let s=this.contexts[n],i=this.contexts[this.lastChannel].last;n!==this.lastChannel&&(this.lastChannel=n,s.haveLast||(s.haveLast=!0,s.last.set(i),i=this.contexts[this.lastChannel].last),this.itemVersion>=4&&(i=s.last));for(let o=0;o<this.count;o++)if(this.byteCount[o]){let a=i[o]+this.byteDecoder[o].decodeSymbol(s.byteModel[o])&255;t[e+o]=a,i[o]=a}else t[e+o]=i[o];return e+this.count}};Od=class{point;bytes;first=!0;constructor(t,e,n){this.point=new Zs(t,n.point10ItemVersion??2),this.bytes=new Hs(t,this.point.getDecoder(),e,n.byteItemVersion??2)}decompress(t,e){return e=this.point.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e)}decompressPointDataBatch(t,e){for(let n=0;n<e;n++)this.decompressPointData(t,t.pointOffset+n)}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},qo=class{itemVersion;stream;decoder;gpsTimeMultiModel=new jt(516);gpsTime0DiffModel=new jt(6);gpsTime=It(32,9);lastGpsSequence=0;nextGpsSequence=0;lastGpsTime=new Array(4).fill(0);lastGpsTimeDiff=new Array(4).fill(0);multiExtremeCounter=new Array(4).fill(0);haveLast=!1;constructor(t,e,n=2){this.itemVersion=n,this.stream=t,this.decoder=e,n===1&&(this.gpsTimeMultiModel=new jt(512),this.gpsTime0DiffModel=new jt(3),this.gpsTime=It(32,6))}decompress(t,e){return pb(this.decompressGpsTime(),t,e),e+8}decompressGpsTime(){return this.haveLast?(this.itemVersion===1?this.decodeLegacyGpsTime():this.decodeGpsTime(),this.lastGpsTime[this.lastGpsSequence]):(this.lastGpsTime[0]=db(this.stream),this.haveLast=!0,this.lastGpsTime[0])}decodeLegacyGpsTime(){let t=this.lastGpsTimeDiff[0];if(t===0){let o=this.decoder.decodeSymbol(this.gpsTime0DiffModel);if(o===1){let a=this.gpsTime.decompress(this.decoder,0,0);this.lastGpsTimeDiff[0]=a,this.lastGpsTime[0]=qs(this.lastGpsTime[0],a)}else o===2&&(this.lastGpsTime[0]=Vo(this.decoder.readUint64()));return}let e=this.decoder.decodeSymbol(this.gpsTimeMultiModel);if(e===511)return;if(e===510){this.lastGpsTime[0]=Vo(this.decoder.readUint64());return}let n=e===1?1:e===0?2:e<10?3:e<50?4:5,s=e===0?Math.trunc(t/4):cn(e*t),i=this.gpsTime.decompress(this.decoder,s,n);e===1?(this.lastGpsTimeDiff[0]=i,this.multiExtremeCounter[0]=0):(e===0||e===509)&&++this.multiExtremeCounter[0]>3&&(this.lastGpsTimeDiff[0]=i,this.multiExtremeCounter[0]=0),this.lastGpsTime[0]=qs(this.lastGpsTime[0],i)}decodeGpsTime(){for(;;){if(this.lastGpsTimeDiff[this.lastGpsSequence]===0){let n=this.decoder.decodeSymbol(this.gpsTime0DiffModel);if(n===0)break;if(n===1){let s=this.gpsTime.decompress(this.decoder,0,0);this.lastGpsTimeDiff[this.lastGpsSequence]=s,this.lastGpsTime[this.lastGpsSequence]=qs(this.lastGpsTime[this.lastGpsSequence],s),this.multiExtremeCounter[this.lastGpsSequence]=0;break}if(n===2){this.readFullGpsTime();break}this.lastGpsSequence=this.lastGpsSequence+n-2&3;continue}let t=this.decoder.decodeSymbol(this.gpsTimeMultiModel),e=0;if(t===1){let n=this.gpsTime.decompress(this.decoder,this.lastGpsTimeDiff[this.lastGpsSequence],1);this.lastGpsTime[this.lastGpsSequence]=qs(this.lastGpsTime[this.lastGpsSequence],n),this.multiExtremeCounter[this.lastGpsSequence]=0}else if(t<QA){if(t===0)e=this.gpsTime.decompress(this.decoder,0,7),this.multiExtremeCounter[this.lastGpsSequence]++,this.multiExtremeCounter[this.lastGpsSequence]>3&&(this.multiExtremeCounter[this.lastGpsSequence]=0,this.lastGpsTimeDiff[this.lastGpsSequence]=e);else if(t<an){let n=t<10?2:3;e=this.gpsTime.decompress(this.decoder,t*this.lastGpsTimeDiff[this.lastGpsSequence],n)}else t===an?(e=this.gpsTime.decompress(this.decoder,an*this.lastGpsTimeDiff[this.lastGpsSequence],4),this.multiExtremeCounter[this.lastGpsSequence]++,this.multiExtremeCounter[this.lastGpsSequence]>3&&(this.multiExtremeCounter[this.lastGpsSequence]=0,this.lastGpsTimeDiff[this.lastGpsSequence]=e)):(t=an-t,t>Go?e=this.gpsTime.decompress(this.decoder,t*this.lastGpsTimeDiff[this.lastGpsSequence],5):(e=this.gpsTime.decompress(this.decoder,Go*this.lastGpsTimeDiff[this.lastGpsSequence],6),this.multiExtremeCounter[this.lastGpsSequence]++,this.multiExtremeCounter[this.lastGpsSequence]>3&&(this.multiExtremeCounter[this.lastGpsSequence]=0,this.lastGpsTimeDiff[this.lastGpsSequence]=e)));this.lastGpsTime[this.lastGpsSequence]=qs(this.lastGpsTime[this.lastGpsSequence],e)}else if(t===vd)this.readFullGpsTime();else if(t>=vd){this.lastGpsSequence=this.lastGpsSequence+t-vd&3;continue}break}}readFullGpsTime(){this.nextGpsSequence=this.nextGpsSequence+1&3;let t=uu(this.lastGpsTime[this.lastGpsSequence]),e=this.gpsTime.decompress(this.decoder,Number(t>>32n)|0,8),n=this.decoder.readInt();this.lastGpsTime[this.nextGpsSequence]=Vo(BigInt(e>>>0)<<32n|BigInt(n)),this.lastGpsSequence=this.nextGpsSequence,this.lastGpsTimeDiff[this.lastGpsSequence]=0,this.multiExtremeCounter[this.lastGpsSequence]=0}},Ed=class{point;gpsTime;bytes;first=!0;constructor(t,e,n){this.point=new Zs(t,n.point10ItemVersion??2);let s=this.point.getDecoder();this.gpsTime=new qo(t,s,n.gpsTime11ItemVersion??2),this.bytes=new Hs(t,s,e,n.byteItemVersion??2)}decompress(t,e){return e=this.point.decompress(t,e),e=this.gpsTime.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint(),s=this.gpsTime.decompressGpsTime();this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e),t.gpsTimes&&(t.gpsTimes[e]=s)}decompressPointDataBatch(t,e){for(let n=0;n<e;n++)this.decompressPointData(t,t.pointOffset+n)}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},Ud=class{point;rgb;bytes;first=!0;constructor(t,e,n){this.point=new Zs(t,n.point10ItemVersion??2);let s=this.point.getDecoder();this.rgb=new tc(t,s,n.rgb12ItemVersion??2),this.bytes=new Hs(t,s,e,n.byteItemVersion??2)}decompress(t,e){return e=this.point.decompress(t,e),e=this.rgb.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.rgb.decompressRgb(),this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e),Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){for(let n=0;n<e;n++)this.decompressPointData(t,t.pointOffset+n)}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},Nd=class{point;gpsTime;rgb;bytes;first=!0;directCommonOutput;constructor(t,e,n,s=null){this.point=new Zs(t,n.point10ItemVersion??2);let i=this.point.getDecoder();this.gpsTime=new qo(t,i,n.gpsTime11ItemVersion??2),this.rgb=new tc(t,i,n.rgb12ItemVersion??2),this.bytes=new Hs(t,i,e,n.byteItemVersion??2),this.directCommonOutput=!!(s&&!s.gpsTime&&!s.scanAngle&&!s.userData&&!s.pointSourceId&&!s.flags&&!s.waveform&&!s.extraBytes)}decompress(t,e){return e=this.point.decompress(t,e),e=this.gpsTime.decompress(t,e),e=this.rgb.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint(),s=this.gpsTime.decompressGpsTime();if(this.rgb.decompressRgb(),this.directCommonOutput){if(this.bytes.decompressToTarget(),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),t.colors){let i=e*4;t.colors[i]=this.rgb.decodedRed&255,t.colors[i+1]=this.rgb.decodedGreen&255,t.colors[i+2]=this.rgb.decodedBlue&255,t.colors[i+3]=255}else if(t.rawColors){let i=e*3;t.rawColors[i]=this.rgb.decodedRed,t.rawColors[i+1]=this.rgb.decodedGreen,t.rawColors[i+2]=this.rgb.decodedBlue}return}this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e),t.gpsTimes&&(t.gpsTimes[e]=s),Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.colors,a=t.rawColors,c=t.scale,l=t.offset,u=this.bytes.byteCount,f=t.pointOffset;if(!!!(t.gpsTimes||t.scanAngles||t.userData||t.pointSourceIds||t.returnNumbers||t.numberOfReturns||t.scannerChannels||t.scanDirectionFlags||t.edgeOfFlightLines||t.syntheticFlags||t.keyPointFlags||t.withheldFlags||t.overlapFlags)&&!t.extraBytes){for(let m=0;m<e;m++){let y=this.point.decompressPoint();if(this.gpsTime.decompressGpsTime(),this.rgb.decompressRgb(),this.bytes.decompressToTarget(),this.readFirstMetadata(),Rn(y,n,s,i,c,l,f),o){let g=f*4;o[g]=this.rgb.decodedRed&255,o[g+1]=this.rgb.decodedGreen&255,o[g+2]=this.rgb.decodedBlue&255,o[g+3]=255}else if(a){let g=f*3;a[g]=this.rgb.decodedRed,a[g+1]=this.rgb.decodedGreen,a[g+2]=this.rgb.decodedBlue}f++}return}for(let m=0;m<e;m++){let y=this.point.decompressPoint(),g=this.gpsTime.decompressGpsTime();this.rgb.decompressRgb(),this.bytes.decompressToTarget(t.extraBytes,f*u),this.readFirstMetadata(),Rn(y,n,s,i,c,l,f),Wi(y,t,f),t.gpsTimes&&(t.gpsTimes[f]=g),Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,f),f++}}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},iu=class{stream;decoder;context=new nu;constructor(t,e){this.stream=t,this.decoder=e}decompress(t,e){let n=this.context;if(!n.haveLast)return this.stream.getBytes(t,e,29),this.readContext(t,e),n.haveLast=!0,e+29;n.descriptorIndex=this.decoder.decodeSymbol(n.descriptorModel);let s=this.decoder.decodeSymbol(n.offsetDifferenceModels[n.lastOffsetDifferenceSymbol]);switch(n.lastOffsetDifferenceSymbol=s,s){case 0:break;case 1:n.offset=BigInt.asUintN(64,n.offset+BigInt(n.packetSize));break;case 2:n.lastOffsetDifference=n.offsetDifferenceDecompressor.decompress(this.decoder,n.lastOffsetDifference,0),n.offset=BigInt.asUintN(64,n.offset+BigInt(n.lastOffsetDifference));break;default:n.offset=this.decoder.readUint64();break}return n.packetSize=n.packetSizeDecompressor.decompress(this.decoder,n.packetSize|0,0)>>>0,n.returnPointBits=n.returnPointDecompressor.decompress(this.decoder,n.returnPointBits,0),n.xBits=n.vectorDecompressor.decompress(this.decoder,n.xBits,0),n.yBits=n.vectorDecompressor.decompress(this.decoder,n.yBits,1),n.zBits=n.vectorDecompressor.decompress(this.decoder,n.zBits,2),this.writeContext(t,e),e+29}decompressToTarget(t,e){this.decompress(t,e)}readContext(t,e){let n=this.context;n.descriptorIndex=t[e],n.offset=fb(t,e+1),n.packetSize=cu(t,e+9),n.returnPointBits=Vr(t,e+13),n.xBits=Vr(t,e+17),n.yBits=Vr(t,e+21),n.zBits=Vr(t,e+25)}writeContext(t,e){let n=this.context;t[e]=n.descriptorIndex,hb(n.offset,t,e+1),lu(n.packetSize,t,e+9),Ue(n.returnPointBits,t,e+13),Ue(n.xBits,t,e+17),Ue(n.yBits,t,e+21),Ue(n.zBits,t,e+25)}},Rd=class{point;gpsTime;wavePacket;bytes;waveformScratch=new Uint8Array(29);first=!0;constructor(t,e,n){this.point=new Zs(t,n.point10ItemVersion??2);let s=this.point.getDecoder();this.gpsTime=new qo(t,s,n.gpsTime11ItemVersion??2),this.wavePacket=new iu(t,s),this.bytes=new Hs(t,s,e,n.byteItemVersion??2)}decompress(t,e){return e=this.point.decompress(t,e),e=this.gpsTime.decompress(t,e),e=this.wavePacket.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint(),s=this.gpsTime.decompressGpsTime();t.waveforms?this.wavePacket.decompressToTarget(t.waveforms,e*29):this.wavePacket.decompressToTarget(this.waveformScratch,0),this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e),t.gpsTimes&&(t.gpsTimes[e]=s)}decompressPointDataBatch(t,e){for(let n=0;n<e;n++)this.decompressPointData(t,t.pointOffset+n)}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},Pd=class{point;gpsTime;rgb;wavePacket;bytes;waveformScratch=new Uint8Array(29);first=!0;constructor(t,e,n){this.point=new Zs(t,n.point10ItemVersion??2);let s=this.point.getDecoder();this.gpsTime=new qo(t,s,n.gpsTime11ItemVersion??2),this.rgb=new tc(t,s,n.rgb12ItemVersion??2),this.wavePacket=new iu(t,s),this.bytes=new Hs(t,s,e,n.byteItemVersion??2)}decompress(t,e){return e=this.point.decompress(t,e),e=this.gpsTime.decompress(t,e),e=this.rgb.decompress(t,e),e=this.wavePacket.decompress(t,e),e=this.bytes.decompress(t,e),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint(),s=this.gpsTime.decompressGpsTime();this.rgb.decompressRgb(),t.waveforms?this.wavePacket.decompressToTarget(t.waveforms,e*29):this.wavePacket.decompressToTarget(this.waveformScratch,0),this.bytes.decompressToTarget(t.extraBytes,e*this.bytes.byteCount),this.readFirstMetadata(),Rn(n,t.positions,t.intensities,t.classifications,t.scale,t.offset,e),Wi(n,t,e),t.gpsTimes&&(t.gpsTimes[e]=s),Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){for(let n=0;n<e;n++)this.decompressPointData(t,t.pointOffset+n)}readFirstMetadata(){this.first&&(this.point.readFirstMetadata(),this.first=!1)}},kd=class{stream;point;bytes;extraByteCount;first=!0;constructor(t,e,n,s,i){this.stream=t,this.extraByteCount=e,this.point=new qi(t,n==="raw"?Nt.Full:Nt.PointData,s.point14ItemVersion??3,i),this.bytes=(n==="raw"||i?.extraBytes)&&e?new $i(t,e,s.byte14ItemVersion??3):null}decompress(t,e){return e=this.point.decompress(t,e),this.bytes&&(e=this.bytes.decompress(t,e,this.point.itemContextChannel)),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,e*this.extraByteCount,this.point.itemContextChannel):this.first&&this.extraByteCount&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),nc(n,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.scale,a=t.offset,c=t.pointOffset;for(let l=0;l<e;l++){let u=this.point.decompressPoint();this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,c*this.extraByteCount,this.point.itemContextChannel):this.first&&this.extraByteCount&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),Ws(u,n,s,i,o,a,c++),Yi(u,t,c-1),Zi(u,t,c-1)}}readFirstMetadata(){if(this.first){this.stream.getUint32(),this.point.readSizes();let t=0;if(this.bytes)this.bytes.readSizes();else for(let e=0;e<this.extraByteCount;e++)t+=this.stream.getUint32();this.point.readData(),this.bytes?this.bytes.readData():this.stream.consume(t),this.first=!1}}},zd=class{stream;point;rgb;bytes;extraByteCount;first=!0;constructor(t,e,n,s,i){this.stream=t,this.extraByteCount=e,this.point=new qi(t,n==="raw"?Nt.Full:Nt.PointData,s.point14ItemVersion??3,i),this.rgb=n==="raw"||i?.color?new ec(t,s.rgb14ItemVersion??3):null,this.bytes=(n==="raw"||i?.extraBytes)&&e?new $i(t,e,s.byte14ItemVersion??3):null}decompress(t,e){return e=this.point.decompress(t,e),e=this.rgb.decompress(t,e,this.point.itemContextChannel),this.bytes&&(e=this.bytes.decompress(t,e,this.point.itemContextChannel)),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.first&&this.stream.consume(6),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,e*this.extraByteCount,this.point.itemContextChannel):this.first&&this.extraByteCount&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),nc(n,t,e),this.rgb&&Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.colors,a=t.rawColors,c=t.scale,l=t.offset,u=t.pointOffset,f=e;if(this.first&&f>0){let y=this.point.decompressPoint();if(this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.stream.consume(6),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,u*this.extraByteCount,this.point.itemContextChannel):this.extraByteCount&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),Ws(y,n,s,i,c,l,u),Yi(y,t,u),Zi(y,t,u),o&&this.rgb){let g=u*4;o[g]=this.rgb.decodedRed&255,o[g+1]=this.rgb.decodedGreen&255,o[g+2]=this.rgb.decodedBlue&255,o[g+3]=255}else if(a&&this.rgb){let g=u*3;a[g]=this.rgb.decodedRed,a[g+1]=this.rgb.decodedGreen,a[g+2]=this.rgb.decodedBlue}u++,f--}let h=!!(t.gpsTimes||t.scanAngles||t.userData||t.pointSourceIds||t.returnNumbers||t.numberOfReturns||t.scannerChannels||t.scanDirectionFlags||t.edgeOfFlightLines||t.syntheticFlags||t.keyPointFlags||t.withheldFlags||t.overlapFlags),m=!!(this.bytes&&t.extraBytes);if(!h&&!m){for(let y=0;y<f;y++){let g=this.point.decompressPoint();if(this.rgb?.decompressRgb(this.point.itemContextChannel),Ws(g,n,s,i,c,l,u),o&&this.rgb){let x=u*4;o[x]=this.rgb.decodedRed&255,o[x+1]=this.rgb.decodedGreen&255,o[x+2]=this.rgb.decodedBlue&255,o[x+3]=255}else if(a&&this.rgb){let x=u*3;a[x]=this.rgb.decodedRed,a[x+1]=this.rgb.decodedGreen,a[x+2]=this.rgb.decodedBlue}u++}return}for(let y=0;y<f;y++){let g=this.point.decompressPoint();if(this.rgb?.decompressRgb(this.point.itemContextChannel),this.bytes&&t.extraBytes&&this.bytes.decompress(t.extraBytes,u*this.extraByteCount,this.point.itemContextChannel),Ws(g,n,s,i,c,l,u),Yi(g,t,u),Zi(g,t,u),o&&this.rgb){let x=u*4;o[x]=this.rgb.decodedRed&255,o[x+1]=this.rgb.decodedGreen&255,o[x+2]=this.rgb.decodedBlue&255,o[x+3]=255}else if(a&&this.rgb){let x=u*3;a[x]=this.rgb.decodedRed,a[x+1]=this.rgb.decodedGreen,a[x+2]=this.rgb.decodedBlue}u++}}readFirstMetadata(){if(this.first){this.stream.getUint32(),this.point.readSizes();let t=this.rgb?0:this.stream.getUint32();this.rgb?.readSizes();let e=0;if(this.bytes)this.bytes.readSizes();else for(let n=0;n<this.extraByteCount;n++)e+=this.stream.getUint32();this.point.readData(),this.rgb?this.rgb.readData():this.stream.consume(t),this.bytes?this.bytes.readData():this.stream.consume(e),this.first=!1}}},Vd=class{stream;point;rgb;nir;bytes;extraByteCount;first=!0;constructor(t,e,n,s,i){this.stream=t,this.extraByteCount=e,this.point=new qi(t,n==="raw"?Nt.Full:Nt.PointData,s.point14ItemVersion??3,i),this.rgb=n==="raw"||i?.color?new ec(t,s.rgb14ItemVersion??3):null,this.nir=n==="raw"||i?.nir?new ru(t,s.rgb14ItemVersion??3):null,this.bytes=(n==="raw"||i?.extraBytes)&&e?new $i(t,e,s.byte14ItemVersion??3):null}decompress(t,e){return e=this.point.decompress(t,e),e=this.rgb.decompress(t,e,this.point.itemContextChannel),e=this.nir.decompress(t,e,this.point.itemContextChannel),this.bytes&&(e=this.bytes.decompress(t,e,this.point.itemContextChannel)),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.first&&this.stream.consume(6),!this.nir&&this.first&&this.stream.consume(2);let s=this.nir?this.nir.decompressNir(this.point.itemContextChannel):0;this.bytes&&t.extraBytes&&this.bytes.decompress(t.extraBytes,e*this.extraByteCount,this.point.itemContextChannel),this.first&&this.stream.consume(this.bytes?0:this.extraByteCount),this.readFirstMetadata(),nc(n,t,e),ou(s,t,e),this.rgb&&Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.colors,a=t.rawColors,c=t.scale,l=t.offset,u=t.pointOffset;for(let f=0;f<e;f++){let h=this.point.decompressPoint();this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.first&&this.stream.consume(6),!this.nir&&this.first&&this.stream.consume(2);let m=this.nir?this.nir.decompressNir(this.point.itemContextChannel):0;if(this.bytes&&t.extraBytes&&this.bytes.decompress(t.extraBytes,u*this.extraByteCount,this.point.itemContextChannel),this.first&&this.stream.consume(this.bytes?0:this.extraByteCount),this.readFirstMetadata(),Ws(h,n,s,i,c,l,u),Yi(h,t,u),Zi(h,t,u),o&&this.rgb){let y=u*4;o[y]=this.rgb.decodedRed&255,o[y+1]=this.rgb.decodedGreen&255,o[y+2]=this.rgb.decodedBlue&255,o[y+3]=255}else if(a&&this.rgb){let y=u*3;a[y]=this.rgb.decodedRed,a[y+1]=this.rgb.decodedGreen,a[y+2]=this.rgb.decodedBlue}ou(m,t,u),u++}}readFirstMetadata(){if(this.first){this.stream.getUint32(),this.point.readSizes();let t=this.rgb?0:this.stream.getUint32();this.rgb?.readSizes();let e=this.nir?0:this.stream.getUint32();this.nir?.readSizes();let n=0;if(this.bytes)this.bytes.readSizes();else for(let s=0;s<this.extraByteCount;s++)n+=this.stream.getUint32();this.point.readData(),this.rgb?this.rgb.readData():this.stream.consume(t),this.nir?this.nir.readData():this.stream.consume(e),this.bytes?this.bytes.readData():this.stream.consume(n),this.first=!1}}},Gd=class{stream;point;wavePacket;bytes;extraByteCount;first=!0;waveformScratch=new Uint8Array(29);constructor(t,e,n,s,i){this.stream=t,this.extraByteCount=e,this.point=new qi(t,n==="raw"?Nt.Full:Nt.PointData,s.point14ItemVersion??3,i),this.wavePacket=n==="raw"||i?.waveform?new su(t,s.wavePacketItemVersion??3):null,this.bytes=(n==="raw"||i?.extraBytes)&&e?new $i(t,e,s.byte14ItemVersion??3):null}decompress(t,e){return e=this.point.decompress(t,e),e=this.wavePacket.decompress(t,e,this.point.itemContextChannel),this.bytes&&(e=this.bytes.decompress(t,e,this.point.itemContextChannel)),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.wavePacket?(this.wavePacket.decompressToTarget(this.waveformScratch,0,this.point.itemContextChannel),t.waveforms&&t.waveforms.set(this.waveformScratch,e*29)):this.first&&this.stream.consume(29),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,e*this.extraByteCount,this.point.itemContextChannel):this.first&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),nc(n,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.scale,a=t.offset,c=t.pointOffset;for(let l=0;l<e;l++){let u=this.point.decompressPoint();this.wavePacket?(this.wavePacket.decompressToTarget(this.waveformScratch,0,this.point.itemContextChannel),t.waveforms&&t.waveforms.set(this.waveformScratch,c*29)):this.first&&this.stream.consume(29),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,c*this.extraByteCount,this.point.itemContextChannel):this.first&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),Ws(u,n,s,i,o,a,c++),Yi(u,t,c-1),Zi(u,t,c-1)}}readFirstMetadata(){if(this.first){this.stream.getUint32(),this.point.readSizes();let t=this.wavePacket?0:this.stream.getUint32();this.wavePacket?.readSizes();let e=0;if(this.bytes)this.bytes.readSizes();else for(let n=0;n<this.extraByteCount;n++)e+=this.stream.getUint32();this.point.readData(),this.wavePacket?this.wavePacket.readData():this.stream.consume(t),this.bytes?this.bytes.readData():this.stream.consume(e),this.first=!1}}},jd=class{stream;point;rgb;nir;wavePacket;bytes;extraByteCount;first=!0;waveformScratch=new Uint8Array(29);constructor(t,e,n,s,i){this.stream=t,this.extraByteCount=e,this.point=new qi(t,n==="raw"?Nt.Full:Nt.PointData,s.point14ItemVersion??3,i),this.rgb=n==="raw"||i?.color?new ec(t,s.rgb14ItemVersion??3):null,this.nir=n==="raw"||i?.nir?new ru(t,s.rgb14ItemVersion??3):null,this.wavePacket=n==="raw"||i?.waveform?new su(t,s.wavePacketItemVersion??3):null,this.bytes=(n==="raw"||i?.extraBytes)&&e?new $i(t,e,s.byte14ItemVersion??3):null}decompress(t,e){return e=this.point.decompress(t,e),e=this.rgb.decompress(t,e,this.point.itemContextChannel),e=this.nir.decompress(t,e,this.point.itemContextChannel),e=this.wavePacket.decompress(t,e,this.point.itemContextChannel),this.bytes&&(e=this.bytes.decompress(t,e,this.point.itemContextChannel)),this.readFirstMetadata(),e}decompressPointData(t,e){let n=this.point.decompressPoint();this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.first&&this.stream.consume(6);let s=this.nir?this.nir.decompressNir(this.point.itemContextChannel):0;this.first&&this.stream.consume(this.nir?0:2),this.wavePacket?(this.wavePacket.decompressToTarget(this.waveformScratch,0,this.point.itemContextChannel),t.waveforms&&t.waveforms.set(this.waveformScratch,e*29)):this.first&&this.stream.consume(29),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,e*this.extraByteCount,this.point.itemContextChannel):this.first&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),nc(n,t,e),ou(s,t,e),this.rgb&&Hi(this.rgb.decodedRed,this.rgb.decodedGreen,this.rgb.decodedBlue,t,e)}decompressPointDataBatch(t,e){let n=t.positions,s=t.intensities,i=t.classifications,o=t.colors,a=t.rawColors,c=t.scale,l=t.offset,u=t.pointOffset;for(let f=0;f<e;f++){let h=this.point.decompressPoint();this.rgb?this.rgb.decompressRgb(this.point.itemContextChannel):this.first&&this.stream.consume(6);let m=this.nir?this.nir.decompressNir(this.point.itemContextChannel):0;if(this.first&&this.stream.consume(this.nir?0:2),this.wavePacket?(this.wavePacket.decompressToTarget(this.waveformScratch,0,this.point.itemContextChannel),t.waveforms&&t.waveforms.set(this.waveformScratch,u*29)):this.first&&this.stream.consume(29),this.bytes&&t.extraBytes?this.bytes.decompress(t.extraBytes,u*this.extraByteCount,this.point.itemContextChannel):this.first&&this.stream.consume(this.extraByteCount),this.readFirstMetadata(),Ws(h,n,s,i,c,l,u),Yi(h,t,u),Zi(h,t,u),o&&this.rgb){let y=u*4;o[y]=this.rgb.decodedRed&255,o[y+1]=this.rgb.decodedGreen&255,o[y+2]=this.rgb.decodedBlue&255,o[y+3]=255}else if(a&&this.rgb){let y=u*3;a[y]=this.rgb.decodedRed,a[y+1]=this.rgb.decodedGreen,a[y+2]=this.rgb.decodedBlue}ou(m,t,u),u++}}readFirstMetadata(){if(this.first){this.stream.getUint32(),this.point.readSizes();let t=this.rgb?0:this.stream.getUint32();this.rgb?.readSizes();let e=this.nir?0:this.stream.getUint32();this.nir?.readSizes();let n=this.wavePacket?0:this.stream.getUint32();this.wavePacket?.readSizes();let s=0;if(this.bytes)this.bytes.readSizes();else for(let i=0;i<this.extraByteCount;i++)s+=this.stream.getUint32();this.point.readData(),this.rgb?this.rgb.readData():this.stream.consume(t),this.nir?this.nir.readData():this.stream.consume(e),this.wavePacket?this.wavePacket.readData():this.stream.consume(n),this.bytes?this.bytes.readData():this.stream.consume(s),this.first=!1}}}});function We(r){return r|0}var Ot,Hd,$t,_t,Xi,yb=p(()=>{"use strict";Ot=class{symbols;distribution;symbolCount;lastSymbol;totalCount=0;updateCycle;symbolsUntilUpdate;constructor(t){if(t<2||t>2048)throw new Error(`Invalid arithmetic model symbol count ${t}`);this.symbols=t,this.lastSymbol=t-1,this.distribution=new Uint32Array(t),this.symbolCount=new Uint32Array(t),this.symbolCount.fill(1),this.updateCycle=t,this.symbolsUntilUpdate=t,this.update(),this.symbolsUntilUpdate=this.updateCycle=t+6>>1}update(){if(this.totalCount+=this.updateCycle,this.totalCount>32768){this.totalCount=0;for(let s=0;s<this.symbols;s++)this.symbolCount[s]=this.symbolCount[s]+1>>1,this.totalCount+=this.symbolCount[s]}let t=0,e=2147483648/this.totalCount|0;for(let s=0;s<this.symbols;s++)this.distribution[s]=e*t/65536|0,t+=this.symbolCount[s];this.updateCycle=5*this.updateCycle>>2;let n=this.symbols+6<<3;this.updateCycle>n&&(this.updateCycle=n),this.symbolsUntilUpdate=this.updateCycle}},Hd=class{updateCycle=4;bitsUntilUpdate=4;bit0Probability=4096;bit0Count=1;bitCount=2;update(){this.bitCount+=this.updateCycle,this.bitCount>8192&&(this.bitCount=this.bitCount+1>>1,this.bit0Count=this.bit0Count+1>>1,this.bit0Count===this.bitCount&&this.bitCount++);let t=2147483648/this.bitCount|0;this.bit0Probability=this.bit0Count*t/262144|0,this.updateCycle=5*this.updateCycle>>2,this.updateCycle>64&&(this.updateCycle=64),this.bitsUntilUpdate=this.updateCycle}},$t=class{bytes=[];base=0;length=4294967295;finished=!1;encodeBit(t,e){let n=t.bit0Probability*(this.length>>>13);if(e===0)this.length=n>>>0,t.bit0Count++;else if(e===1)this.addToBase(n),this.length=this.length-n>>>0;else throw new Error(`Invalid arithmetic bit ${e}`);this.renormalizeIfNeeded(),--t.bitsUntilUpdate===0&&t.update()}encodeSymbol(t,e){if(!Number.isInteger(e)||e<0||e>t.lastSymbol)throw new Error(`Invalid arithmetic symbol ${e}`);let n=this.length,s;e===t.lastSymbol?(s=t.distribution[e]*(n>>>15),this.addToBase(s),this.length=n-s>>>0):(n>>>=15,s=t.distribution[e]*n,this.addToBase(s),this.length=t.distribution[e+1]*n-s>>>0),this.renormalizeIfNeeded(),t.symbolCount[e]++,--t.symbolsUntilUpdate===0&&t.update()}writeBits(t,e){if(!Number.isInteger(t)||t<1||t>32)throw new Error(`Invalid arithmetic bit count ${t}`);t>19&&(this.writeShort(e&65535),e>>>=16,t-=16);let n=this.length>>>t;this.addToBase(e*n),this.length=n>>>0,this.renormalizeIfNeeded()}writeShort(t){let e=this.length>>>16;this.addToBase((t&65535)*e),this.length=e>>>0,this.renormalizeIfNeeded()}writeInt(t){this.writeShort(t&65535),this.writeShort(t>>>16)}finish(){if(this.finished)return Uint8Array.from(this.bytes);this.finished=!0;let t=this.base,e=!0;return this.length>2*16777216?(this.base=this.base+16777216>>>0,this.length=8388608):(this.base=this.base+8388608>>>0,this.length=32768,e=!1),t>this.base&&this.propagateCarry(),this.renormalize(),this.bytes.push(0,0),e&&this.bytes.push(0),Uint8Array.from(this.bytes)}addToBase(t){let e=this.base;this.base=this.base+t>>>0,e>this.base&&this.propagateCarry()}propagateCarry(){let t=this.bytes.length-1;for(;t>=0&&this.bytes[t]===255;)this.bytes[t--]=0;if(t<0)throw new Error("LASzip arithmetic carry precedes encoded output");this.bytes[t]++}renormalizeIfNeeded(){this.length<16777216&&this.renormalize()}renormalize(){do this.bytes.push(this.base>>>24),this.base=this.base<<8>>>0,this.length=this.length<<8>>>0;while(this.length<16777216)}},_t=class{encoder;contexts;bitsHigh;correctionBits;correctionRange;correctionMinimum;bitModels;zeroBitCorrector=new Hd;correctorModels;k=0;constructor(t,e=16,n=1,s=8,i=0){if(this.encoder=t,this.contexts=n,this.bitsHigh=s,i){let o=i,a=0;for(;o;)o>>=1,a++;i===2**(a-1)&&a--,this.correctionBits=a,this.correctionRange=i,this.correctionMinimum=-(i/2)}else e&&e<32?(this.correctionBits=e,this.correctionRange=2**e,this.correctionMinimum=-(this.correctionRange/2)):(this.correctionBits=32,this.correctionRange=0,this.correctionMinimum=-2147483648);this.bitModels=Array.from({length:this.contexts},()=>new Ot(this.correctionBits+1)),this.correctorModels=Array.from({length:this.correctionBits},(o,a)=>{let c=a+1;return new Ot(2**Math.min(c,this.bitsHigh))})}compress(t,e,n=0){if(!Number.isInteger(n)||n<0||n>=this.contexts)throw new Error(`Invalid integer compressor context ${n}`);let s=We(e-t);this.correctionRange&&(s<this.correctionMinimum?s+=this.correctionRange:s>this.correctionMinimum+this.correctionRange-1&&(s-=this.correctionRange)),this.writeCorrector(s,this.bitModels[n])}writeCorrector(t,e){let n=t<=0?-t:t-1,s=0;for(;n;)n>>>=1,s++;if(this.k=s,this.encoder.encodeSymbol(e,s),s===0){this.encoder.encodeBit(this.zeroBitCorrector,t);return}if(s===32){if(t!==this.correctionMinimum)throw new Error(`Invalid ${s}-bit integer correction ${t}`);return}let i=t<0?t+(2**s-1):t-1,o=this.correctorModels[s-1];if(s<=this.bitsHigh)this.encoder.encodeSymbol(o,i);else{let a=s-this.bitsHigh,c=2**a-1,l=i&c;i>>>=a,this.encoder.encodeSymbol(o,i),this.encoder.writeBits(a,l)}}},Xi=class{value0=0;value1=0;value2=0;value3=0;value4=0;high=!0;add(t){this.high?t<this.value2?(this.value4=this.value3,this.value3=this.value2,t<this.value0?(this.value2=this.value1,this.value1=this.value0,this.value0=t):t<this.value1?(this.value2=this.value1,this.value1=t):this.value2=t):(t<this.value3?(this.value4=this.value3,this.value3=t):this.value4=t,this.high=!1):this.value2<t?(this.value0=this.value1,this.value1=this.value2,this.value4<t?(this.value2=this.value3,this.value3=this.value4,this.value4=t):this.value3<t?(this.value2=this.value3,this.value3=t):this.value2=t):(this.value1<t?(this.value0=this.value1,this.value1=t):this.value0=t,this.high=!0)}get(){return this.value2}}});function op(r,t){let e=OS(r);if(TS(e,t),t.pointCount===0)return new Uint8Array(0);if(t.pointDataRecordFormat<=5)return LS(e,t);let n=t.pointDataRecordLength,s=t.pointDataRecordFormat,i=Bu[s],o=n-i,a=e.subarray(0,n),c=vb(a,0),l=new rp(c),u=s===7||s===8||s===10?vu(a,30):null,f=u?new np(u,Yo(c)):null,h=s===8||s===10?new sp(sc(a,36),Yo(c)):null,m=s===9?30:s===10?38:-1,y=m>=0?new tp(Au(a,m),Yo(c),t.wavePacketItemVersion??3):null,g=o?new ip(a.subarray(i,n),Yo(c)):null;for(let X=1;X<t.pointCount;X++){let ft=X*n,dt=e.subarray(ft,ft+n),Bt=l.encode(vb(dt,0));f?.encode(vu(dt,30),Bt),h?.encode(sc(dt,36),Bt),y?.encode(Au(dt,m),Bt),g?.encode(dt.subarray(i,n),Bt)}let x=l.finish(),B=f?.finish(),q=h?.finish(),M=y?.finish(),b=g?.finish()||[],C=[...x,...B?[B]:[],...q?[q]:[],...M?[M]:[],...b],_=new Uint8Array(4+C.length*4),$=new DataView(_.buffer);$.setUint32(0,t.pointCount,!0);for(let X=0;X<C.length;X++)$.setUint32(4+X*4,C[X].byteLength,!0);return Tb([a,_,...C])}function ap(r,t={}){if(r.length===0)return new Uint8Array(0);let e=new $t,n=new _t(e,32,2),s=0,i=0;for(let o of r)MS(o),t.variable&&(n.compress(s,o.pointCount,0),s=o.pointCount),n.compress(i,o.byteLength,1),i=o.byteLength;return e.finish()}function cp(r){let t=r.pointDataRecordFormat<=5,e=r.itemVersion||(t?2:3);if(t&&e!==2)throw new Error("Legacy LASzip point formats require item version 2");if(!t&&e!==3)throw new Error("Modern LASzip point formats require item version 3");let n=DS(r.pointDataRecordFormat,r.pointDataRecordLength),s=bb+n.length*6,i=new Uint8Array(gb+s),o=new DataView(i.buffer),a=gb;_b(o,2,"laszip encoded",16),o.setUint16(18,22204,!0),o.setUint16(20,s,!0),_b(o,22,"loaders.gl LAZ writer",32),o.setUint16(a,t?2:3,!0),o.setUint16(a+2,0,!0),o.setUint8(a+4,t?2:3),o.setUint8(a+5,0),o.setUint16(a+6,1,!0),o.setUint32(a+8,0,!0),o.setUint32(a+12,r.chunkSize,!0),i.fill(255,a+16,a+32),o.setUint16(a+32,n.length,!0);for(let c=0;c<n.length;c++){let l=a+bb+c*6,u=n[c];o.setUint16(l,u.type,!0),o.setUint16(l+2,u.size,!0),o.setUint16(l+4,u.version??e,!0)}return i}function LS(r,t){let e=t.pointDataRecordLength,n=t.pointDataRecordFormat,s=Bu[n],i=e-s,o=r.subarray(0,e),a=new $t,c=new Xd(a,Ab(o,0)),l=n===1||n===3||n===4||n===5?new Kd(a,Sb(o,20)):null,u=n===2?20:n===3||n===5?28:-1,f=u>=0?new Jd(a,vu(o,u)):null,h=n===4?28:n===5?34:-1,m=h>=0?new Qd(a,Au(o,h)):null,y=i?new ep(a,o.subarray(s,e)):null;for(let g=1;g<t.pointCount;g++){let x=g*e,B=r.subarray(x,x+e);c.encode(Ab(B,0)),l?.encode(Sb(B,20)),f?.encode(vu(B,u)),m?.encode(Au(B,h)),y?.encode(B.subarray(s,e))}return Tb([o,a.finish()])}function TS(r,t){if([t.point10ItemVersion,t.gpsTime11ItemVersion,t.rgb12ItemVersion,t.byteItemVersion].some(s=>s!==void 0&&s!==2))throw new Error("TypeScript LAZ encoder only supports legacy item version 2");if(!Number.isInteger(t.pointCount)||t.pointCount<0)throw new Error(`Invalid LAZ chunk point count ${t.pointCount}`);let e=Bu[t.pointDataRecordFormat];if(!e)throw new Error(`TypeScript LAZ encoder does not support point format ${t.pointDataRecordFormat}`);if(!Number.isInteger(t.pointDataRecordLength)||t.pointDataRecordLength<e)throw new Error(`Invalid point record length ${t.pointDataRecordLength} for point format ${t.pointDataRecordFormat}`);if(t.point14ItemVersion!==void 0&&t.point14ItemVersion!==3)throw new Error("TypeScript LAZ encoder only supports Point14 item version 3");if(t.pointDataRecordFormat>=7&&t.rgb14ItemVersion!==void 0&&t.rgb14ItemVersion!==3)throw new Error("TypeScript LAZ encoder only supports RGB14 item version 3");if((t.pointDataRecordFormat===9||t.pointDataRecordFormat===10)&&t.wavePacketItemVersion!==void 0&&t.wavePacketItemVersion!==3)throw new Error("TypeScript LAZ encoder only supports WavePacket14 item version 3");if(t.pointDataRecordLength>e&&t.byte14ItemVersion!==void 0&&t.byte14ItemVersion!==3)throw new Error("TypeScript LAZ encoder only supports Byte14 item version 3");let n=t.pointCount*t.pointDataRecordLength;if(r.byteLength!==n)throw new Error(`LAZ chunk input has ${r.byteLength} bytes; expected ${n}`)}function MS(r){if(!Number.isInteger(r.pointCount)||r.pointCount<=0||r.pointCount>4294967295)throw new Error(`Invalid LAZ chunk point count ${r.pointCount}`);if(!Number.isInteger(r.byteLength)||r.byteLength<=0||r.byteLength>4294967295)throw new Error(`Invalid LAZ chunk byte length ${r.byteLength}`)}function DS(r,t){let e=Bu[r];if(!e||t<e)throw new Error(`Invalid point record length ${t} for point format ${r}`);if(r<=5){let i=[{type:6,size:20}];(r===1||r===3||r===4||r===5)&&i.push({type:7,size:8}),(r===2||r===3||r===5)&&i.push({type:8,size:6}),(r===4||r===5)&&i.push({type:9,size:29,version:1});let o=t-e;return o>0&&i.push({type:0,size:o}),i}let n=[{type:10,size:30}];r===7?n.push({type:11,size:6}):r===8?n.push({type:12,size:8}):r===10&&n.push({type:12,size:8}),(r===9||r===10)&&n.push({type:13,size:29});let s=t-e;return s>0&&n.push({type:14,size:s}),n}function vb(r,t){let e=new DataView(r.buffer,r.byteOffset+t,30);return{x:e.getInt32(0,!0),y:e.getInt32(4,!0),z:e.getInt32(8,!0),intensity:e.getUint16(12,!0),returns:e.getUint8(14),flags:e.getUint8(15),classification:e.getUint8(16),userData:e.getUint8(17),scanAngle:e.getInt16(18,!0),pointSourceId:e.getUint16(20,!0),gpsTimeBits:e.getBigUint64(22,!0)}}function Ab(r,t){let e=new DataView(r.buffer,r.byteOffset+t,20);return{x:e.getInt32(0,!0),y:e.getInt32(4,!0),z:e.getInt32(8,!0),intensity:e.getUint16(12,!0),bitByte:e.getUint8(14),classification:e.getUint8(15),scanAngleRank:e.getInt8(16),userData:e.getUint8(17),pointSourceId:e.getUint16(18,!0)}}function vu(r,t){return{red:sc(r,t),green:sc(r,t+2),blue:sc(r,t+4)}}function Au(r,t){let e=new DataView(r.buffer,r.byteOffset+t,29);return{descriptorIndex:e.getUint8(0),offset:e.getBigUint64(1,!0),packetSize:e.getUint32(9,!0),returnPointBits:e.getInt32(13,!0),xBits:e.getInt32(17,!0),yBits:e.getInt32(21,!0),zBits:e.getInt32(25,!0)}}function Sb(r,t){return new DataView(r.buffer,r.byteOffset+t,8).getFloat64(0,!0)}function Bb(r,t){return BigInt.asIntN(64,Su(r)-Su(t))}function Su(r){let t=new ArrayBuffer(8),e=new DataView(t);return e.setFloat64(0,r,!0),e.getBigUint64(0,!0)}function sc(r,t){return r[t]|r[t+1]<<8}function CS(r,t){r.x=t.x,r.y=t.y,r.z=t.z,r.intensity=t.intensity,r.returns=t.returns,r.flags=t.flags,r.classification=t.classification,r.userData=t.userData,r.scanAngle=t.scanAngle,r.pointSourceId=t.pointSourceId,r.gpsTimeBits=t.gpsTimeBits}function Yo(r){return r.flags>>4&3}function Ib(r){return r.flags>>2&48|r.flags&15}function xr(r,t){return Array.from({length:r},()=>new Ot(t))}function be(r){return r&255}function FS(r){return r&255}function Xs(r){return Math.min(255,Math.max(0,r))}function Lb(r,t){let e=Math.fround(Math.fround(r)/Math.fround(t));return e>=0?Math.trunc(e+.5):Math.trunc(e-.5)}function OS(r){return r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Tb(r){let t=r.reduce((s,i)=>s+i.byteLength,0),e=new Uint8Array(t),n=0;for(let s of r)e.set(s,n),n+=s.byteLength;return e}function _b(r,t,e,n){for(let s=0;s<n;s++)r.setUint8(t+s,e.charCodeAt(s)||0)}var Bu,gb,bb,wr,Ki,wb,xb,SS,BS,IS,_S,Xd,Kd,Jd,Qd,yu,tp,ep,gu,rp,bu,np,wu,sp,xu,ip,Mb=p(()=>{"use strict";yb();Bu={0:20,1:28,2:26,3:34,4:57,5:63,6:30,7:36,8:38,9:59,10:67},gb=54,bb=34,wr=500,Ki=-10,wb=511,xb=wr-Ki+2,SS=[[0,1,2,3,4,5,3,4,4,5,5,5,5,5,5,5],[1,0,1,3,3,3,3,3,3,3,3,3,3,3,3,3],[2,1,2,4,4,4,4,4,4,4,4,3,3,3,3,3],[3,3,4,5,4,4,4,4,4,4,4,4,4,4,4,4],[4,3,4,4,5,4,4,4,4,4,4,4,4,4,4,4],[5,3,4,4,4,5,4,4,4,4,4,4,4,4,4,4],[3,3,4,4,4,4,5,4,4,4,4,4,4,4,4,4],[4,3,4,4,4,4,4,5,4,4,4,4,4,4,4,4],[4,3,4,4,4,4,4,4,5,4,4,4,4,4,4,4],[5,3,4,4,4,4,4,4,4,5,4,4,4,4,4,4],[5,3,4,4,4,4,4,4,4,4,5,4,4,4,4,4],[5,3,3,4,4,4,4,4,4,4,4,5,5,4,4,4],[5,3,3,4,4,4,4,4,4,4,4,5,5,5,4,4],[5,3,3,4,4,4,4,4,4,4,4,4,5,5,5,4],[5,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5],[5,3,3,4,4,4,4,4,4,4,4,4,4,4,5,5]],BS=[[15,14,13,12,11,10,9,8],[14,0,1,3,6,10,10,9],[13,1,2,4,7,11,11,10],[12,3,4,5,8,12,12,11],[11,6,7,8,9,13,13,12],[10,10,11,12,13,14,14,13],[9,10,11,12,13,14,15,14],[8,9,10,11,12,13,14,15]],IS=[[0,1,2,3,4,5,6,7],[1,0,1,2,3,4,5,6],[2,1,0,1,2,3,4,5],[3,2,1,0,1,2,3,4],[4,3,2,1,0,1,2,3],[5,4,3,2,1,0,1,2],[6,5,4,3,2,1,0,1],[7,6,5,4,3,2,1,0]],_S=[[0,1,2,3,4,5,6,7,7,7,7,7,7,7,7,7],[1,0,1,2,3,4,5,6,7,7,7,7,7,7,7,7],[2,1,0,1,2,3,4,5,6,7,7,7,7,7,7,7],[3,2,1,0,1,2,3,4,5,6,7,7,7,7,7,7],[4,3,2,1,0,1,2,3,4,5,6,7,7,7,7,7],[5,4,3,2,1,0,1,2,3,4,5,6,7,7,7,7],[6,5,4,3,2,1,0,1,2,3,4,5,6,7,7,7],[7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,7],[7,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7],[7,7,7,6,5,4,3,2,1,0,1,2,3,4,5,6],[7,7,7,7,6,5,4,3,2,1,0,1,2,3,4,5],[7,7,7,7,7,6,5,4,3,2,1,0,1,2,3,4],[7,7,7,7,7,7,6,5,4,3,2,1,0,1,2,3],[7,7,7,7,7,7,7,6,5,4,3,2,1,0,1,2],[7,7,7,7,7,7,7,7,6,5,4,3,2,1,0,1],[7,7,7,7,7,7,7,7,7,6,5,4,3,2,1,0]];Xd=class{encoder;changedValuesModel=new Ot(64);bitByteModels=xr(256,256);classificationModels=xr(256,256);scanAngleRankModels=xr(2,256);userDataModels=xr(256,256);intensityCompressor;pointSourceIdCompressor;xDifferenceCompressor;yDifferenceCompressor;zCompressor;lastIntensity=new Array(16).fill(0);lastHeight=new Array(8).fill(0);lastXDifferenceMedian=Array.from({length:16},()=>new Xi);lastYDifferenceMedian=Array.from({length:16},()=>new Xi);last;constructor(t,e){this.encoder=t,this.last={...e},this.intensityCompressor=new _t(t,16,4),this.pointSourceIdCompressor=new _t(t,16,1),this.xDifferenceCompressor=new _t(t,32,2),this.yDifferenceCompressor=new _t(t,32,22),this.zCompressor=new _t(t,32,20)}encode(t){let e=this.last,n=t.bitByte&7,s=t.bitByte>>3&7,i=BS[s][n],o=IS[s][n],a=(t.bitByte!==e.bitByte?32:0)|(t.intensity!==this.lastIntensity[i]?16:0)|(t.classification!==e.classification?8:0)|(t.scanAngleRank!==e.scanAngleRank?4:0)|(t.userData!==e.userData?2:0)|(t.pointSourceId!==e.pointSourceId?1:0);this.encoder.encodeSymbol(this.changedValuesModel,a),a&32&&this.encoder.encodeSymbol(this.bitByteModels[e.bitByte],t.bitByte),a&16&&(this.intensityCompressor.compress(this.lastIntensity[i],t.intensity,i<3?i:3),this.lastIntensity[i]=t.intensity),a&8&&this.encoder.encodeSymbol(this.classificationModels[e.classification],t.classification),a&4&&this.encoder.encodeSymbol(this.scanAngleRankModels[t.bitByte>>6&1],FS(t.scanAngleRank-e.scanAngleRank)),a&2&&this.encoder.encodeSymbol(this.userDataModels[e.userData],t.userData),a&1&&this.pointSourceIdCompressor.compress(e.pointSourceId,t.pointSourceId);let c=this.lastXDifferenceMedian[i].get(),l=We(t.x-e.x);this.xDifferenceCompressor.compress(c,l,s===1?1:0),this.lastXDifferenceMedian[i].add(l);let u=this.lastYDifferenceMedian[i].get(),f=Math.min(this.xDifferenceCompressor.k,20)&-2,h=We(t.y-e.y);this.yDifferenceCompressor.compress(u,h,(s===1?1:0)+f),this.lastYDifferenceMedian[i].add(h);let m=Math.min(this.xDifferenceCompressor.k+this.yDifferenceCompressor.k>>1,18)&-2;this.zCompressor.compress(this.lastHeight[o],t.z,(s===1?1:0)+m),this.lastHeight[o]=t.z,this.last={...t}}},Kd=class{encoder;gpsTimeMultiModel;gpsTime0DiffModel;gpsTime;lastGpsTime;lastGpsTimeDifference=[0,0,0,0];multiExtremeCounter=[0,0,0,0];lastGpsSequence=0;nextGpsSequence=0;constructor(t,e){this.encoder=t,this.gpsTimeMultiModel=new Ot(516),this.gpsTime0DiffModel=new Ot(6),this.gpsTime=new _t(t,32,9),this.lastGpsTime=[e,0,0,0]}encode(t){let e=this.lastGpsSequence,n=Bb(t,this.lastGpsTime[e]),s=Number(BigInt.asIntN(32,n)),i=n===BigInt(s);if(this.lastGpsTimeDifference[e]===0)if(i)s===0?this.encoder.encodeSymbol(this.gpsTime0DiffModel,0):(this.encoder.encodeSymbol(this.gpsTime0DiffModel,1),this.gpsTime.compress(0,s,0),this.lastGpsTimeDifference[e]=s,this.multiExtremeCounter[e]=0);else if(this.selectSequence(t,!1)){this.encode(t);return}else this.encoder.encodeSymbol(this.gpsTime0DiffModel,2),this.startSequence(t);else if(i){let o=this.lastGpsTimeDifference[e],a=Lb(s,o);a===1?(this.encoder.encodeSymbol(this.gpsTimeMultiModel,1),this.gpsTime.compress(o,s,1),this.multiExtremeCounter[e]=0):a>0&&a<wr?(this.encoder.encodeSymbol(this.gpsTimeMultiModel,a),this.gpsTime.compress(We(a*o),s,a<10?2:3)):a>=wr?(this.encoder.encodeSymbol(this.gpsTimeMultiModel,wr),this.gpsTime.compress(We(wr*o),s,4),this.recordExtremeDifference(e,s)):a<0&&a>Ki?(this.encoder.encodeSymbol(this.gpsTimeMultiModel,wr-a),this.gpsTime.compress(We(a*o),s,5)):a<0?(this.encoder.encodeSymbol(this.gpsTimeMultiModel,wr-Ki),this.gpsTime.compress(We(Ki*o),s,6),this.recordExtremeDifference(e,s)):(this.encoder.encodeSymbol(this.gpsTimeMultiModel,0),this.gpsTime.compress(0,s,7),this.recordExtremeDifference(e,s))}else if(this.selectSequence(t,!0)){this.encode(t);return}else this.encoder.encodeSymbol(this.gpsTimeMultiModel,xb),this.startSequence(t);this.lastGpsTime[this.lastGpsSequence]=t}selectSequence(t,e){for(let n=1;n<4;n++){let s=this.lastGpsSequence+n&3,i=Bb(t,this.lastGpsTime[s]);if(i===BigInt.asIntN(32,i))return this.encoder.encodeSymbol(e?this.gpsTimeMultiModel:this.gpsTime0DiffModel,e?xb+n:n+2),this.lastGpsSequence=s,!0}return!1}startSequence(t){let e=Su(this.lastGpsTime[this.lastGpsSequence]),n=Su(t);this.gpsTime.compress(Number(BigInt.asIntN(32,e>>32n)),Number(BigInt.asIntN(32,n>>32n)),8),this.encoder.writeInt(Number(n&0xffffffffn)),this.nextGpsSequence=this.nextGpsSequence+1&3,this.lastGpsSequence=this.nextGpsSequence,this.lastGpsTimeDifference[this.lastGpsSequence]=0,this.multiExtremeCounter[this.lastGpsSequence]=0}recordExtremeDifference(t,e){this.multiExtremeCounter[t]++,this.multiExtremeCounter[t]>3&&(this.multiExtremeCounter[t]=0,this.lastGpsTimeDifference[t]=e)}},Jd=class{encoder;usedModel=new Ot(128);differenceModels=xr(6,256);red;green;blue;constructor(t,e){this.encoder=t,this.red=e.red,this.green=e.green,this.blue=e.blue}encode(t){let e=this.red,n=this.green,s=this.blue,i=((t.red&255)!==(e&255)?1:0)|((t.red&65280)!==(e&65280)?2:0)|((t.green&255)!==(n&255)?4:0)|((t.green&65280)!==(n&65280)?8:0)|((t.blue&255)!==(s&255)?16:0)|((t.blue&65280)!==(s&65280)?32:0);((t.red&255)!==(t.green&255)||(t.red&255)!==(t.blue&255)||(t.red&65280)!==(t.green&65280)||(t.red&65280)!==(t.blue&65280))&&(i|=64),this.encoder.encodeSymbol(this.usedModel,i);let o=0,a=0;i&1&&(o=(t.red&255)-(e&255),this.encoder.encodeSymbol(this.differenceModels[0],be(o))),i&2&&(a=(t.red>>8)-(e>>8),this.encoder.encodeSymbol(this.differenceModels[1],be(a))),i&64&&(i&4&&this.encoder.encodeSymbol(this.differenceModels[2],be((t.green&255)-Xs(o+(n&255)))),i&16&&(o=Math.trunc((o+(t.green&255)-(n&255))/2),this.encoder.encodeSymbol(this.differenceModels[4],be((t.blue&255)-Xs(o+(s&255))))),i&8&&this.encoder.encodeSymbol(this.differenceModels[3],be((t.green>>8)-Xs(a+(n>>8)))),i&32&&(a=Math.trunc((a+(t.green>>8)-(n>>8))/2),this.encoder.encodeSymbol(this.differenceModels[5],be((t.blue>>8)-Xs(a+(s>>8)))))),this.red=t.red,this.green=t.green,this.blue=t.blue}},Qd=class{encoder;descriptorModel;offsetDifferenceModels;offsetDifferenceCompressor;packetSizeCompressor;returnPointCompressor;vectorCompressor;last;lastOffsetDifference=0;lastOffsetDifferenceSymbol=0;constructor(t,e){this.encoder=t,this.descriptorModel=new Ot(256),this.offsetDifferenceModels=xr(4,4),this.offsetDifferenceCompressor=new _t(t,32,1),this.packetSizeCompressor=new _t(t,32,1),this.returnPointCompressor=new _t(t,32,1),this.vectorCompressor=new _t(t,32,3),this.last={...e}}encode(t){let e=this.last;this.encoder.encodeSymbol(this.descriptorModel,t.descriptorIndex);let n=0;if(t.offset===e.offset)n=0;else if(t.offset===e.offset+BigInt(e.packetSize))n=1;else{let s=BigInt.asIntN(64,t.offset-e.offset);s===BigInt.asIntN(32,s)?n=2:n=3}if(this.encoder.encodeSymbol(this.offsetDifferenceModels[this.lastOffsetDifferenceSymbol],n),this.lastOffsetDifferenceSymbol=n,n===2){let s=Number(BigInt.asIntN(32,t.offset-e.offset));this.offsetDifferenceCompressor.compress(this.lastOffsetDifference,s,0),this.lastOffsetDifference=s}n===3&&(this.encoder.writeInt(Number(t.offset&0xffffffffn)),this.encoder.writeInt(Number(t.offset>>32n))),this.packetSizeCompressor.compress(e.packetSize,t.packetSize,0),this.returnPointCompressor.compress(e.returnPointBits,t.returnPointBits,0),this.vectorCompressor.compress(e.xBits,t.xBits,0),this.vectorCompressor.compress(e.yBits,t.yBits,1),this.vectorCompressor.compress(e.zBits,t.zBits,2),this.last={...t}}},yu=class{packet;descriptorModel=new Ot(256);offsetDifferenceModels=xr(4,4);offsetDifferenceCompressor;packetSizeCompressor;returnPointCompressor;vectorCompressor;lastOffsetDifference=0;lastOffsetDifferenceSymbol=0;haveLast=!1;constructor(t,e){this.packet={...e},this.offsetDifferenceCompressor=new _t(t,32,1),this.packetSizeCompressor=new _t(t,32,1),this.returnPointCompressor=new _t(t,32,1),this.vectorCompressor=new _t(t,32,3),this.haveLast=!0}},tp=class{encoder=new $t;contexts=new Array(4).fill(null);itemVersion;lastChannel;constructor(t,e,n){this.itemVersion=n,this.lastChannel=e,this.contexts[e]=new yu(this.encoder,t)}encode(t,e){let n=this.contexts[this.lastChannel],s=this.contexts[e],i=s;e!==this.lastChannel&&(s?this.itemVersion<4&&(i=s,s=n):(s=new yu(this.encoder,n.packet),this.contexts[e]=s,i=s),this.lastChannel=e),this.encodePacket(i,s,t)}finish(){return this.encoder.finish()}encodePacket(t,e,n){let s=e.packet;this.encoder.encodeSymbol(t.descriptorModel,n.descriptorIndex);let i=0;if(n.offset===s.offset?i=0:n.offset===s.offset+BigInt(s.packetSize)?i=1:BigInt.asIntN(64,n.offset-s.offset)===BigInt.asIntN(32,n.offset-s.offset)?i=2:i=3,this.encoder.encodeSymbol(t.offsetDifferenceModels[t.lastOffsetDifferenceSymbol],i),t.lastOffsetDifferenceSymbol=i,i===2){let o=Number(BigInt.asIntN(32,n.offset-s.offset));t.offsetDifferenceCompressor.compress(t.lastOffsetDifference,o,0),t.lastOffsetDifference=o}else i===3&&(this.encoder.writeInt(Number(n.offset&0xffffffffn)),this.encoder.writeInt(Number(n.offset>>32n)));t.packetSizeCompressor.compress(s.packetSize,n.packetSize,0),t.returnPointCompressor.compress(s.returnPointBits,n.returnPointBits,0),t.vectorCompressor.compress(s.xBits,n.xBits,0),t.vectorCompressor.compress(s.yBits,n.yBits,1),t.vectorCompressor.compress(s.zBits,n.zBits,2),e.packet={...n}}},ep=class{encoder;models;last;constructor(t,e){this.encoder=t,this.models=xr(e.byteLength,256),this.last=new Uint8Array(e)}encode(t){for(let e=0;e<t.byteLength;e++){let n=t[e]-this.last[e];this.encoder.encodeSymbol(this.models[e],be(n)),this.last[e]=t[e]}}},gu=class{changedValuesModels=xr(8,128);scannerChannelModel=new Ot(3);returnNumberGpsSameModel=new Ot(13);numberReturnsModels=new Array(16).fill(null);returnNumberModels=new Array(16).fill(null);classificationModels=new Array(64).fill(null);flagModels=new Array(64).fill(null);userDataModels=new Array(64).fill(null);gpsTimeMultiplierModel=new Ot(515);gpsTimeZeroDifferenceModel=new Ot(5);xDifferenceCompressor;yDifferenceCompressor;zCompressor;intensityCompressor;scanAngleCompressor;pointSourceIdCompressor;gpsTimeCompressor;lastXDifferenceMedian=Array.from({length:12},()=>new Xi);lastYDifferenceMedian=Array.from({length:12},()=>new Xi);lastZ;lastIntensity;lastGpsTimeBits;lastGpsTimeDifference=new Array(4).fill(0);gpsTimeExtremeCounter=new Array(4).fill(0);lastGpsSequence=0;nextGpsSequence=0;gpsTimeChanged=!1;last;constructor(t,e){this.last={...t},this.xDifferenceCompressor=new _t(e.xy,32,2),this.yDifferenceCompressor=new _t(e.xy,32,22),this.zCompressor=new _t(e.z,32,20),this.intensityCompressor=new _t(e.intensity,16,4),this.scanAngleCompressor=new _t(e.scanAngle,16,2),this.pointSourceIdCompressor=new _t(e.pointSourceId,16,1),this.gpsTimeCompressor=new _t(e.gpsTime,32,9),this.lastZ=new Array(8).fill(t.z),this.lastIntensity=new Array(8).fill(t.intensity),this.lastGpsTimeBits=[t.gpsTimeBits,0n,0n,0n]}},rp=class{layers={xy:new $t,z:new $t,classification:new $t,flags:new $t,intensity:new $t,scanAngle:new $t,userData:new $t,pointSourceId:new $t,gpsTime:new $t};contexts=new Array(4).fill(null);currentScannerChannel;changed={classification:!1,flags:!1,intensity:!1,scanAngle:!1,userData:!1,pointSourceId:!1,gpsTime:!1};constructor(t){this.currentScannerChannel=Yo(t),this.contexts[this.currentScannerChannel]=new gu(t,this.layers)}encode(t){let e=this.contexts[this.currentScannerChannel],n=e.last,s=Yo(t);s!==this.currentScannerChannel&&this.contexts[s]&&(n=this.contexts[s].last);let i=t.pointSourceId!==n.pointSourceId,o=t.gpsTimeBits!==n.gpsTimeBits,a=t.scanAngle!==n.scanAngle,c=n.returns>>4,l=n.returns&15,u=t.returns>>4,f=t.returns&15,h=(l===1?1:0)|(l>=c?2:0)|(e.gpsTimeChanged?4:0),m=(s!==this.currentScannerChannel?64:0)|(i?32:0)|(o?16:0)|(a?8:0)|(u!==c?4:0);f!==l&&(f===(l+1)%16?m|=1:f===(l+15)%16?m|=2:m|=3),this.layers.xy.encodeSymbol(e.changedValuesModels[h],m);let y=0;if(s!==this.currentScannerChannel){let xt=s-this.currentScannerChannel;this.layers.xy.encodeSymbol(e.scannerChannelModel,(xt+3)%4),this.contexts[s]||=new gu(e.last,this.layers),this.currentScannerChannel=s,y=s,n=this.contexts[s].last}let g=this.contexts[this.currentScannerChannel];if(u!==c){let xt=g.numberReturnsModels[c];xt||(xt=new Ot(16),g.numberReturnsModels[c]=xt),this.layers.xy.encodeSymbol(xt,u)}if((m&3)===3)if(o){let xt=g.returnNumberModels[l];xt||(xt=new Ot(16),g.returnNumberModels[l]=xt),this.layers.xy.encodeSymbol(xt,f)}else{let xt=f-l;this.layers.xy.encodeSymbol(g.returnNumberGpsSameModel,(xt+14)%16)}let x=SS[u][f],B=_S[u][f],q=(f===1?2:0)|(f>=u?1:0),M=x<<1|(o?1:0),b=g.lastXDifferenceMedian[M].get(),C=We(t.x-n.x);g.xDifferenceCompressor.compress(b,C,u===1?1:0),g.lastXDifferenceMedian[M].add(C);let _=g.lastYDifferenceMedian[M].get(),$=We(t.y-n.y),X=(u===1?1:0)|Math.min(g.xDifferenceCompressor.k,20)&-2;g.yDifferenceCompressor.compress(_,$,X),g.lastYDifferenceMedian[M].add($);let ft=(u===1?1:0)|Math.min(g.xDifferenceCompressor.k+g.yDifferenceCompressor.k>>1,18)&-2;g.zCompressor.compress(g.lastZ[B],t.z,ft),g.lastZ[B]=t.z,t.classification!==n.classification&&(this.changed.classification=!0);let dt=(n.classification&31)<<1|(q===3?1:0),Bt=g.classificationModels[dt];Bt||(Bt=new Ot(256),g.classificationModels[dt]=Bt),this.layers.classification.encodeSymbol(Bt,t.classification);let se=Ib(n),rt=Ib(t);rt!==se&&(this.changed.flags=!0);let tt=g.flagModels[se];tt||(tt=new Ot(64),g.flagModels[se]=tt),this.layers.flags.encodeSymbol(tt,rt),t.intensity!==n.intensity&&(this.changed.intensity=!0);let Ye=q<<1|(o?1:0);g.intensityCompressor.compress(g.lastIntensity[Ye],t.intensity,q),g.lastIntensity[Ye]=t.intensity,a&&(this.changed.scanAngle=!0,g.scanAngleCompressor.compress(n.scanAngle,t.scanAngle,o?1:0)),t.userData!==n.userData&&(this.changed.userData=!0);let Ne=n.userData>>2,Ze=g.userDataModels[Ne];return Ze||(Ze=new Ot(256),g.userDataModels[Ne]=Ze),this.layers.userData.encodeSymbol(Ze,t.userData),i&&(this.changed.pointSourceId=!0,g.pointSourceIdCompressor.compress(n.pointSourceId,t.pointSourceId)),o&&(this.changed.gpsTime=!0,this.encodeGpsTime(g,t.gpsTimeBits)),CS(g.last,t),g.gpsTimeChanged=o,y}finish(){return[this.layers.xy.finish(),this.layers.z.finish(),this.changed.classification?this.layers.classification.finish():new Uint8Array(0),this.changed.flags?this.layers.flags.finish():new Uint8Array(0),this.changed.intensity?this.layers.intensity.finish():new Uint8Array(0),this.changed.scanAngle?this.layers.scanAngle.finish():new Uint8Array(0),this.changed.userData?this.layers.userData.finish():new Uint8Array(0),this.changed.pointSourceId?this.layers.pointSourceId.finish():new Uint8Array(0),this.changed.gpsTime?this.layers.gpsTime.finish():new Uint8Array(0)]}encodeGpsTime(t,e){let n=t.lastGpsSequence,s=BigInt.asIntN(64,e-t.lastGpsTimeBits[n]),i=Number(BigInt.asIntN(32,s)),o=s===BigInt(i);if(t.lastGpsTimeDifference[n]===0)if(o)this.layers.gpsTime.encodeSymbol(t.gpsTimeZeroDifferenceModel,0),t.gpsTimeCompressor.compress(0,i,0),t.lastGpsTimeDifference[n]=i,t.gpsTimeExtremeCounter[n]=0;else if(this.selectGpsTimeSequence(t,e,!1)){this.encodeGpsTime(t,e);return}else this.layers.gpsTime.encodeSymbol(t.gpsTimeZeroDifferenceModel,1),this.startGpsTimeSequence(t,e);else if(o){let a=t.lastGpsTimeDifference[n],c=Lb(i,a);c===1?(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,1),t.gpsTimeCompressor.compress(a,i,1),t.gpsTimeExtremeCounter[n]=0):c>0?c<wr?(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,c),t.gpsTimeCompressor.compress(We(c*a),i,c<10?2:3)):(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,wr),t.gpsTimeCompressor.compress(We(wr*a),i,4),this.recordExtremeGpsDifference(t,n,i)):c<0?c>Ki?(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,wr-c),t.gpsTimeCompressor.compress(We(c*a),i,5)):(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,wr-Ki),t.gpsTimeCompressor.compress(We(Ki*a),i,6),this.recordExtremeGpsDifference(t,n,i)):(this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,0),t.gpsTimeCompressor.compress(0,i,7),this.recordExtremeGpsDifference(t,n,i))}else if(this.selectGpsTimeSequence(t,e,!0)){this.encodeGpsTime(t,e);return}else this.layers.gpsTime.encodeSymbol(t.gpsTimeMultiplierModel,wb),this.startGpsTimeSequence(t,e);t.lastGpsTimeBits[t.lastGpsSequence]=e}selectGpsTimeSequence(t,e,n){for(let s=1;s<4;s++){let i=t.lastGpsSequence+s&3,o=BigInt.asIntN(64,e-t.lastGpsTimeBits[i]);if(o===BigInt.asIntN(32,o)){let a=n?wb+s:s+1,c=n?t.gpsTimeMultiplierModel:t.gpsTimeZeroDifferenceModel;return this.layers.gpsTime.encodeSymbol(c,a),t.lastGpsSequence=i,!0}}return!1}startGpsTimeSequence(t,e){let n=t.lastGpsTimeBits[t.lastGpsSequence];t.gpsTimeCompressor.compress(Number(BigInt.asIntN(32,n>>32n)),Number(BigInt.asIntN(32,e>>32n)),8),this.layers.gpsTime.writeInt(Number(e&0xffffffffn)),t.nextGpsSequence=t.nextGpsSequence+1&3,t.lastGpsSequence=t.nextGpsSequence,t.lastGpsTimeDifference[t.lastGpsSequence]=0,t.gpsTimeExtremeCounter[t.lastGpsSequence]=0}recordExtremeGpsDifference(t,e,n){t.gpsTimeExtremeCounter[e]++,t.gpsTimeExtremeCounter[e]>3&&(t.lastGpsTimeDifference[e]=n,t.gpsTimeExtremeCounter[e]=0)}},bu=class{red;green;blue;usedModel=new Ot(128);differenceModels=xr(6,256);constructor(t){this.red=t.red,this.green=t.green,this.blue=t.blue}},np=class{encoder=new $t;contexts=new Array(4).fill(null);currentContext;changed=!1;constructor(t,e){this.currentContext=e,this.contexts[e]=new bu(t)}encode(t,e){let n=this.contexts[this.currentContext];e!==this.currentContext&&(this.currentContext=e,this.contexts[e]||(this.contexts[e]=new bu({red:n.red,green:n.green,blue:n.blue}),n=this.contexts[e]));let s=this.contexts[this.currentContext],i=((t.red&255)!==(n.red&255)?1:0)|((t.red&65280)!==(n.red&65280)?2:0)|((t.green&255)!==(n.green&255)?4:0)|((t.green&65280)!==(n.green&65280)?8:0)|((t.blue&255)!==(n.blue&255)?16:0)|((t.blue&65280)!==(n.blue&65280)?32:0);((t.red&255)!==(t.green&255)||(t.red&255)!==(t.blue&255)||(t.red&65280)!==(t.green&65280)||(t.red&65280)!==(t.blue&65280))&&(i|=64),this.encoder.encodeSymbol(s.usedModel,i);let o=0,a=0;if(i&1&&(o=(t.red&255)-(n.red&255),this.encoder.encodeSymbol(s.differenceModels[0],be(o))),i&2&&(a=(t.red>>8)-(n.red>>8),this.encoder.encodeSymbol(s.differenceModels[1],be(a))),i&64){if(i&4){let c=(t.green&255)-Xs(o+(n.green&255));this.encoder.encodeSymbol(s.differenceModels[2],be(c))}if(i&16){o=Math.trunc((o+(t.green&255)-(n.green&255))/2);let c=(t.blue&255)-Xs(o+(n.blue&255));this.encoder.encodeSymbol(s.differenceModels[4],be(c))}if(i&8){let c=(t.green>>8)-Xs(a+(n.green>>8));this.encoder.encodeSymbol(s.differenceModels[3],be(c))}if(i&32){a=Math.trunc((a+(t.green>>8)-(n.green>>8))/2);let c=(t.blue>>8)-Xs(a+(n.blue>>8));this.encoder.encodeSymbol(s.differenceModels[5],be(c))}}this.changed||=i!==0,n.red=t.red,n.green=t.green,n.blue=t.blue}finish(){return this.changed?this.encoder.finish():new Uint8Array(0)}},wu=class{value;usedModel=new Ot(4);differenceModels=xr(2,256);constructor(t){this.value=t}},sp=class{encoder=new $t;contexts=new Array(4).fill(null);currentContext;changed=!1;constructor(t,e){this.currentContext=e,this.contexts[e]=new wu(t)}encode(t,e){let n=this.contexts[this.currentContext];e!==this.currentContext&&(this.currentContext=e,this.contexts[e]||(this.contexts[e]=new wu(n.value),n=this.contexts[e]));let s=this.contexts[this.currentContext],i=((t&255)!==(n.value&255)?1:0)|((t&65280)!==(n.value&65280)?2:0);this.encoder.encodeSymbol(s.usedModel,i),i&1&&this.encoder.encodeSymbol(s.differenceModels[0],be((t&255)-(n.value&255))),i&2&&this.encoder.encodeSymbol(s.differenceModels[1],be((t>>8)-(n.value>>8))),this.changed||=i!==0,n.value=t}finish(){return this.changed?this.encoder.finish():new Uint8Array(0)}},xu=class{values;models;constructor(t){this.values=t.slice(),this.models=xr(t.byteLength,256)}},ip=class{encoders;contexts=new Array(4).fill(null);changed;currentContext;constructor(t,e){this.encoders=Array.from({length:t.byteLength},()=>new $t),this.changed=new Array(t.byteLength).fill(!1),this.currentContext=e,this.contexts[e]=new xu(t)}encode(t,e){let n=this.contexts[this.currentContext];e!==this.currentContext&&(this.currentContext=e,this.contexts[e]||(this.contexts[e]=new xu(n.values),n=this.contexts[e]));let s=this.contexts[this.currentContext];for(let i=0;i<t.byteLength;i++){let o=t[i]-n.values[i];this.encoders[i].encodeSymbol(s.models[i],be(o)),o&&(this.changed[i]=!0,n.values[i]=t[i])}}finish(){return this.encoders.map((t,e)=>this.changed[e]?t.finish():new Uint8Array(0))}}});function ic(r){return{...r,batchType:"data",length:r.data.numRows}}var Db=p(()=>{"use strict"});var Zo=p(()=>{"use strict";Xg();Kg();tb();mb();Mb();Db()});function Cb(r,t){let e=ES(r);return Gi(t,e)}function ES(r){let t={};return t.las_pointsOffset=r.pointsOffset.toString(10),t.las_pointsFormatId=r.pointsFormatId.toString(10),t.las_pointsStructSize=r.pointsStructSize.toString(10),t.las_pointsCount=r.pointsCount.toString(10),t.las_scale=JSON.stringify(r.scale),t.las_offset=JSON.stringify(r.offset),r.maxs!==void 0&&(t.las_maxs=JSON.stringify(r.maxs)),r.mins!==void 0&&(t.las_mins=JSON.stringify(r.mins)),t.las_totalToRead=r.totalToRead.toString(10),t.las_pointsFortotalReadmatId=r.totalRead.toString(10),r.versionAsString!==void 0&&(t.las_versionAsString=r.versionAsString),r.isCompressed!==void 0&&(t.las_isCompressed=r.isCompressed.toString()),t}var Fb=p(()=>{"use strict";or()});function Ob(r,t){let e=t.vlrs.find(y=>y.userId==="lascompatible"&&y.recordId===22204);if(!e)return;if(!["1.0","1.1","1.2","1.3"].includes(r.versionAsString||"")||![1,3,4,5].includes(r.pointsFormatId))throw new Error("LASLoader: compatibility mode requires a legacy LAS point format");let n=new DataView(e.data.buffer,e.data.byteOffset,e.data.byteLength);if(n.byteLength<4)throw new Error("LASLoader: truncated LASzip compatibility VLR");let s=n.getUint16(2,!0);if(s!==3&&s!==4||n.byteLength!==(s===3?156:174))throw new Error(`LASLoader: unsupported LASzip compatibility VLR version ${s} or length`);let i=new Map,o=0;for(let y of t.extraBytes){let g=y.dataType>20?y.dataType-20:y.dataType>10?y.dataType-10:y.dataType,x=y.dataType>20?3:y.dataType>10?2:1,B=y.dataType===0?y.options:g<=2?x:g<=4?2*x:g<=6||g===9?4*x:8*x;if(y.dataType>30||!B)throw new Error("LASLoader: invalid compatibility Extra Bytes layout");i.set(y.name,{byteOffset:o,dataType:y.dataType}),o+=B}let a={1:28,3:34,4:57,5:63}[r.pointsFormatId];if(o!==r.pointsStructSize-a)throw new Error("LASLoader: compatibility descriptors do not match point record length");let c=oc(i,"LAS 1.4 scan angle",4),l=oc(i,"LAS 1.4 extended returns",1),u=oc(i,"LAS 1.4 classification",1),f=oc(i,"LAS 1.4 flags and channel",1),h=i.has("LAS 1.4 NIR band")?oc(i,"LAS 1.4 NIR band",3):void 0,m=r.pointsFormatId===1?6:r.pointsFormatId===3?h===void 0?7:8:r.pointsFormatId===4?9:10;if(r.pointsFormatId===5&&h===void 0)throw new Error("LASLoader: compatibility waveform color points require NIR");return{pointDataRecordFormat:m,version:s===3?"1.4":"1.5",scanAngleByteOffset:c,returnsByteOffset:l,classificationByteOffset:u,flagsByteOffset:f,nirByteOffset:h}}function oc(r,t,e){let n=r.get(t);if(!n||n.dataType!==e)throw new Error(`LASLoader: missing or invalid compatibility field ${t}`);return n.byteOffset}function lp(r,t,e,n,s){if(!s.classifications&&!s.returnNumbers&&!s.numberOfReturns&&!s.scanAngles&&!s.overlapFlags&&!s.scannerChannels&&!s.nir)return;let i=r.getUint8(t+n.returnsByteOffset),o=r.getUint8(t+n.flagsByteOffset);if(s.classifications&&(s.classifications[e]+=r.getUint8(t+n.classificationByteOffset)),s.returnNumbers&&(s.returnNumbers[e]+=i>>4),s.numberOfReturns&&(s.numberOfReturns[e]+=i&15),s.scanAngles){let a=s.scanAngles[e],c=Math.fround(a/Math.fround(.006)),l=Math.sign(c)*Math.floor(Math.abs(c)+.5);s.scanAngles[e]=l+r.getInt16(t+n.scanAngleByteOffset,!0)}s.overlapFlags&&(s.overlapFlags[e]=o&1),s.scannerChannels&&(s.scannerChannels[e]=o>>1&3),s.nir&&n.nirByteOffset!==void 0&&(s.nir[e]=r.getUint16(t+n.nirByteOffset,!0))}var Eb=p(()=>{"use strict"});function Nb(r){if(r.byteLength%192!==0)throw new Error(`LAS Extra Bytes VLR length ${r.byteLength} is not a multiple of 192`);let t=[],e=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let n=0;n<r.byteLength;n+=192){let s=[e.getFloat64(n+112,!0),e.getFloat64(n+120,!0),e.getFloat64(n+128,!0)],i=[e.getFloat64(n+136,!0),e.getFloat64(n+144,!0),e.getFloat64(n+152,!0)];t.push({dataType:r[n+2],options:r[n+3],name:Ub(r,n+4,32),description:Ub(r,n+160,32),scale:s[0],offset:i[0],scales:s,offsets:i,data:r.slice(n,n+192)})}return t}function Rb(r,t,e){let n=0,s=new Set,i=[];for(let o=0;o<t.length;o++){let a=t[o],c=NS(a.dataType),l=RS(a.dataType),f=PS(c)*l;if(a.dataType<1||a.dataType>30||!f)throw new Error(`Unsupported typed LAS Extra Bytes data type ${a.dataType}`);let h=`EXTRA_BYTES_${US(a.name)}`;h==="EXTRA_BYTES_"&&(h=`EXTRA_BYTES_${o}`);let m=h,y=1;for(;s.has(h);)h=`${m}_${y++}`;s.add(h);let g=a.options&8?a.scales.slice(0,l):new Array(l).fill(1),x=a.options&16?a.offsets.slice(0,l):new Array(l).fill(0),q=c!==10&&(c===7||c===8?g.some(M=>M!==1)||x.some(M=>M!==0):!!(a.options&24));i.push({name:h,value:up(c,r*l,q),size:l,scalarDataType:c,byteOffset:n,byteLength:f,outputFloat64:q,scales:g,offsets:x}),n+=f}if(n!==e)throw new Error(`LAS Extra Bytes descriptors use ${n} bytes; point records provide ${e}`);return i}function Ub(r,t,e){let n=new TextDecoder().decode(r.subarray(t,t+e)),s=n.length;for(;s>0&&n[s-1]==="\0";)s--;return n.slice(0,s).trim()}function US(r){return r.trim().replace(/[^A-Za-z0-9_]+/g,"_")}function NS(r){return r>20?r-20:r>10?r-10:r}function RS(r){return r>20?3:r>10?2:1}function PS(r){return r<=2?1:r<=4?2:r<=6||r===9?4:r===7||r===8||r===10?8:0}function kS(r,t,e){switch(e){case 1:return r.getUint8(t);case 2:return r.getInt8(t);case 3:return r.getUint16(t,!0);case 4:return r.getInt16(t,!0);case 5:return r.getUint32(t,!0);case 6:return r.getInt32(t,!0);case 7:return r.getBigUint64(t,!0);case 8:return r.getBigInt64(t,!0);case 9:return r.getFloat32(t,!0);case 10:return r.getFloat64(t,!0);default:throw new Error(`Unsupported typed LAS Extra Bytes scalar data type ${e}`)}}function up(r,t,e){if(e&&r!==10)return new Float64Array(t);switch(r){case 1:return new Uint8Array(t);case 2:return new Int8Array(t);case 3:return new Uint16Array(t);case 4:return new Int16Array(t);case 5:return new Uint32Array(t);case 6:return new Int32Array(t);case 7:return new BigUint64Array(t);case 8:return new BigInt64Array(t);case 9:return new Float32Array(t);case 10:return new Float64Array(t);default:throw new Error(`Unsupported typed LAS Extra Bytes scalar data type ${r}`)}}function fp(r,t,e,n,s){let i=kS(r,t,e.scalarDataType);e.value instanceof BigInt64Array||e.value instanceof BigUint64Array?e.value[n]=i:e.value[n]=Number(i)*e.scales[s]+e.offsets[s]}var Pb=p(()=>{"use strict"});function Js(r,t,e){return{pointDataRecordFormat:r.pointsFormatId,pointDataRecordLength:r.pointsStructSize,pointCount:e,point10ItemVersion:t.items.find(n=>n.type===6)?.version,gpsTime11ItemVersion:t.items.find(n=>n.type===7)?.version,rgb12ItemVersion:t.items.find(n=>n.type===8)?.version,byteItemVersion:t.items.find(n=>n.type===0)?.version,point14ItemVersion:t.point14ItemVersion??void 0,rgb14ItemVersion:t.rgb14ItemVersion??void 0,wavePacketItemVersion:t.wavePacketItemVersion??void 0,byte14ItemVersion:t.byte14ItemVersion??void 0}}function jb(r,t={}){let e=Hb(r);if(e.isCompressed){let s=new Uint8Array(r),i=gp(s,e);if(bp(e,i),e.pointsFormatId<=5||e.pointsFormatId>=6&&e.pointsFormatId<=10)return WS(s,e,i,t);let o=e2(r,e,i),a=e.pointsCount;return _u(o,{...e,pointsOffset:0,pointsCount:a,totalToRead:a,totalRead:a},t)}let n=e.pointsCount;return _u(r,{...e,totalToRead:n,totalRead:n},t)}function qb(r,t,e){if(t.pointDataRecordFormat<6||t.pointDataRecordFormat>8)throw new Error(`LASLoader: standalone Arrow chunk decode supports PDRF 6-8; received ${t.pointDataRecordFormat}`);let n=t.pointCount,s={pointsOffset:0,pointsFormatId:t.pointDataRecordFormat,pointsStructSize:t.pointDataRecordLength,pointsCount:n,scale:t.scale,offset:t.offset,maxs:[0,0,0],mins:[0,0,0],totalToRead:n,totalRead:n,hasColor:Xb(t.pointDataRecordFormat),versionAsString:"1.4",isCompressed:!0,headerSize:Gb,vlrCount:0},i=Du(n,s,e);if(i.waveforms||i.extraBytes||i.typedExtraBytes)throw new Error("LASLoader: standalone Arrow chunk decode only supports direct LAZ columns");let a=Gr(r,t).decodeIntoPointData(i.target,n);if(a!==n)throw new Error(`LASLoader: standalone LAZ chunk produced ${a} points; expected ${n}`);return $b(s,i,n,e,!0)}function WS(r,t,e,n){let s=t.pointsCount,i=Du(s,t,n),o=wp(r,t,e,n),a=0,c=t.pointsOffset+(e.compressor===1?0:Wt);for(let l of o)YS(r,c,l.byteLength,l.pointCount,t,e,i,a),c+=l.byteLength,a+=l.pointCount;if(a!==s)throw new Error(`LASLoader: decoded ${a} LAZ points; expected ${s}`);return $b(t,i,s,n)}function $b(r,t,e,n,s=!1){let i=s&&t.rawColors?t.rawColors:t.colors?t.colors:t.rawColors?e1(t.rawColors,e,n):null;return hp({...r,pointsOffset:0,pointsCount:e,totalRead:e},t.positions,i,t.intensities,t.classifications,t.syntheticFlags,t.keyPointFlags,t.withheldFlags,t.overlapFlags,t.gpsTimes,t.nir,t.scanAngles,t.userData,t.pointSourceIds,t.returnNumbers,t.numberOfReturns,t.scannerChannels,t.scanDirectionFlags,t.edgeOfFlightLines,t.waveforms,t.extraBytes,t.typedExtraBytes)}function YS(r,t,e,n,s,i,o,a){let c=r.subarray(t,t+e);if(c.byteLength!==e)throw new it("LASLoader: truncated LAZ chunk");let l=Gr(c,Js(s,i,n));o.target.pointOffset=a;let u=l.decodeIntoPointData(o.target,n);if(u!==n)throw new Error(`LASLoader: decoded ${u} points from a ${n}-point LAZ chunk`);vp(o,a,n)}async function*Wb(r,t={}){let e=Xo(t),n=k2(r),s=new Uint8Array(0),i=0,o=null,a=0,c=0;for(;;){let l=await n.next();if(l.done)break;let u=l.value;if(s=r1(s,Bp(u)),o||(o=P2(s,i),o&&(o.totalToRead=o.pointsCount)),!!o){if(o.isCompressed){yield*XS(s,n,o,t);return}for(let f of N2(s,i,o,a,c,e))a=f.sourcePointIndex,c=f.totalRead,s=f.pending,i=f.absoluteOffset,yield _u(f.arrayBuffer,f.header,t)}}if(!o)throw new Error("LASLoader: incomplete LAS header");if(c<o.totalToRead)throw new Error("LASLoader: truncated LAS point data")}async function*ZS(r,t,e,n,s){if(n.variableChunks){let m=await x2(r,t);yield*Zb(m,e,n,s);return}if(e.pointsFormatId<=5){yield*HS(r,t,e,n,s);return}let i={...e,totalToRead:e.pointsCount},o=Xo(s),a=Mu(o,e.pointsStructSize,Cu(s)),c=0,l=[],u=new js;u.write(r),await Qi(u,t,e.pointsOffset+Wt,"LASLoader: incomplete compressed LAZ point data"),u.skip(e.pointsOffset);let f=Fu(u.getDataView(Wt));for(;c<e.pointsCount;){let m=Math.min(n.chunkSize,e.pointsCount-c),y=Js(e,n,m),g=await B2(u,t,y);l.push(g),Ap(u,g,a.stats);let x=u.readBytes(g);s.las?.recoverMissingChunkTable&&f===e.pointsOffset&&xp(x,y);for(let B of Sp(x,y,i,a))yield B;c+=m}await Tu(u,t,e,n,f,l,s);let h=Ji(i,a);h&&(yield h)}async function*HS(r,t,e,n,s={}){let i={...e,totalToRead:e.pointsCount},o=Xo(s),a=Mu(o,e.pointsStructSize,Cu(s)),c=[],l=new js;l.write(r),await Qi(l,t,e.pointsOffset+(n.compressor===1?0:Wt),"LASLoader: incomplete compressed LAZ point data"),l.skip(e.pointsOffset);let u=n.compressor===1?0:Fu(l.getDataView(Wt)),f=0;for(;f<e.pointsCount;){let m=n.compressor===1?e.pointsCount:Math.min(n.chunkSize,e.pointsCount-f),y=Js(e,n,m),g=Gr(new Uint8Array(0),y),x=0,B=0,q=!1;for(;g.remainingPointCount>0;){let M=l.getAvailableByteLength(),b=Yb(M,x,g.requiredInputByteLength-B);if(b>x){let X=l.checkpoint();l.skip(x);let ft=b-x;Ap(l,ft,a.stats),g.feed(l.readBytes(ft)),l.restore(X),x=b}let C=o-a.batchPointCount,_=g.decodeAvailableInto(a.rawBatch,a.batchPointCount*e.pointsStructSize,C,q);if(_>0){if(n.compressor===1){let X=g.compressedByteOffset-B;l.skip(X),x-=X,B=g.compressedByteOffset,g.discardConsumedInput()}if(a.batchPointCount+=_,a.batchPointCount===o){let X=Ji(i,a);X&&(yield X)}continue}if(q)throw new it(`LASLoader: truncated legacy LAZ chunk after ${m-g.remainingPointCount} of ${m} points with ${M} bytes available`);let $=await t.next();$.done?q=!0:l.write($.value)}l.skip(g.compressedByteOffset-B),c.push(g.compressedByteOffset),f+=m}n.compressor!==1&&await Tu(l,t,e,n,u,c,s);let h=Ji(i,a);h&&(yield h)}function Yb(r,t,e){return Math.min(r,Math.max(e,t+$S))}async function*XS(r,t,e,n){let{pending:s,laszip:i}=await w2(r,t,e);if(bp(e,i),!i.variableChunks&&e.pointsFormatId<=5){yield*KS(s,t,e,i,n);return}if(!i.variableChunks&&e.pointsFormatId>=6&&e.pointsFormatId<=10){yield*JS(s,t,e,i,n);return}for await(let o of ZS(s,t,e,i,n))yield _u(o.arrayBuffer,o.header,n)}async function*KS(r,t,e,n,s){let i={...e,totalToRead:e.pointsCount},o=Du(Xo(s),e,s),a=Cu(s),c=[],l=new js;l.write(r),await Qi(l,t,e.pointsOffset+(n.compressor===1?0:Wt),"LASLoader: incomplete compressed LAZ point data"),l.skip(e.pointsOffset);let u=n.compressor===1?0:Fu(l.getDataView(Wt)),f=0;for(;f<e.pointsCount;){let m=n.compressor===1?e.pointsCount:Math.min(n.chunkSize,e.pointsCount-f),y=Js(e,n,m),g=Gr(new Uint8Array(0),y),x=0,B=0,q=!1;for(;g.remainingPointCount>0;){let M=l.getAvailableByteLength(),b=Yb(M,x,g.requiredInputByteLength-B);if(b>x){let X=l.checkpoint();l.skip(x);let ft=b-x;Ap(l,ft,a),g.feed(l.readBytes(ft)),l.restore(X),x=b}o.target.pointOffset=o.batchPointCount;let C=o.batchCapacity-o.batchPointCount,_=g.decodeAvailableIntoPointData(o.target,C,q);if(_>0){if(n.compressor===1){let X=g.compressedByteOffset-B;l.skip(X),x-=X,B=g.compressedByteOffset,g.discardConsumedInput()}if(vp(o,o.batchPointCount,_),o.batchPointCount+=_,o.batchPointCount===o.batchCapacity){let X=Lu(i,o,s);X&&(yield X)}continue}if(q)throw new it(`LASLoader: truncated legacy LAZ chunk after ${m-g.remainingPointCount} of ${m} points with ${M} bytes available`);let $=await t.next();$.done?q=!0:l.write($.value)}l.skip(g.compressedByteOffset-B),c.push(g.compressedByteOffset),f+=m}n.compressor!==1&&await Tu(l,t,e,n,u,c,s);let h=Lu(i,o,s);h&&(yield h)}async function*JS(r,t,e,n,s){let i={...e,totalToRead:e.pointsCount},o=Du(Xo(s),e,s),a=0,c=[],l=new js;l.write(r),await Qi(l,t,e.pointsOffset+Wt,"LASLoader: incomplete compressed LAZ point data"),l.skip(e.pointsOffset);let u=Fu(l.getDataView(Wt));for(;a<e.pointsCount;){let h=Math.min(n.chunkSize,e.pointsCount-a),m=Js(e,n,h),y=yield*QS(l,t,m,i,o,s,!!(s.las?.recoverMissingChunkTable&&u===e.pointsOffset));c.push(y),a+=h}await Tu(l,t,e,n,u,c,s);let f=Lu(i,o,s);f&&(yield f)}async function*QS(r,t,e,n,s,i,o){let a=hu(e);await Qi(r,t,a,"LASLoader: incomplete layered LAZ chunk header");let c=r.readBytes(a);o&&xp(c,e);let l=du(c,e),u=$d(e);u.feed(c);let f=a;for(;f<l;){if(yield*kb(u,n,s,i),r.getAvailableByteLength()===0){let m=await t.next();if(m.done)throw new it("LASLoader: incomplete layered LAZ chunk payload");r.write(m.value)}let h=Math.min(r.getAvailableByteLength(),l-f);u.feed(r.readBytes(h)),f+=h}if(u.close(),yield*kb(u,n,s,i),u.remainingPointCount!==0)throw new it(`LASLoader: layered LAZ chunk produced ${e.pointCount-u.remainingPointCount} of ${e.pointCount} points`);return l}function*kb(r,t,e,n){for(;r.remainingPointCount>0;){let s=e.batchCapacity-e.batchPointCount;e.target.pointOffset=e.batchPointCount;let i=r.readPointDataBatch(e.target,s);if(!i)return;if(vp(e,e.batchPointCount,i),e.batchPointCount+=i,e.batchPointCount===e.batchCapacity){let o=Lu(t,e,n);o&&(yield o)}}}function*t2(r,t,e,n,s={}){let i=n||gp(new Uint8Array(r),t);if(bp(t,i),t.pointsFormatId<=5||i.variableChunks){yield*Zb(new Uint8Array(r),t,i,{...s,batchSize:e});return}let o={...t,totalToRead:t.pointsCount},a=Mu(e,t.pointsStructSize),c=new Uint8Array(r),l=wp(c,t,i,s),u=t.pointsOffset+(i.compressor===1?0:Wt);for(let h of l){let m=Js(t,i,h.pointCount),y=c.subarray(u,u+h.byteLength);for(let g of Sp(y,m,o,a))yield g;u+=h.byteLength}let f=Ji(o,a);f&&(yield f)}function*Zb(r,t,e,n={}){let s=Xo(n),i={...t,totalToRead:t.pointsCount},o=Mu(s,t.pointsStructSize,Cu(n)),a=wp(r,t,e,n),c=t.pointsOffset+(e.compressor===1?0:Wt);for(let u of a){let f=r.subarray(c,c+u.byteLength);if(f.byteLength<u.byteLength)throw new it("LASLoader: truncated legacy LAZ chunk");let h=Js(t,e,u.pointCount);if(e.compressor===1)yield*Sp(f,h,i,o);else{let m=fu(f,h);C2(m.byteLength,o.stats),yield*F2(m,i,o)}c+=u.byteLength}let l=Ji(i,o);l&&(yield l)}function e2(r,t,e){let n=t.pointsCount,s=new Uint8Array(n*t.pointsStructSize),i=0;for(let o of t2(r,t,zb,e)){let a=new Uint8Array(o.arrayBuffer);s.set(a,i),i+=a.byteLength}return s}function Hb(r){let t=new DataView(r);if(r.byteLength<227||t.getUint32(0,!0)!==Vb)throw new Error("LASLoader: invalid LAS header");let e=t.getUint8(24),n=t.getUint8(25);if(e!==1||n>5)throw new Error(`LASLoader: unsupported LAS version ${e}.${n}`);let s=t.getUint16(94,!0),i=t.getUint16(6,!0),o=t.getUint32(100,!0),a=t.getUint8(104),c=a&VS,l=!!(a&zS),u=t.getUint32(107,!0),h=(e>1||n>=4?Ks(t,247):u)||u,m=t.getUint32(96,!0),y=t.getUint16(105,!0);if(n===5){if(s<393)throw new Error("LASLoader: LAS 1.5 header must be at least 393 bytes");if(c<6||c>10)throw new Error(`LASLoader: LAS 1.5 requires point data record formats 6-10; received ${c}`);if((i&16)===0)throw new Error("LASLoader: LAS 1.5 requires the WKT global encoding flag");if((i&65440)!==0)throw new Error("LASLoader: LAS 1.5 Global Encoding contains reserved bits");if((i&64)!==0&&(i&1)===0)throw new Error("LASLoader: LAS 1.5 Time Offset Flag requires GPS Time Type");let b=t.getFloat64(375,!0),C=t.getFloat64(383,!0);if(!Number.isFinite(b)||!Number.isFinite(C)||b!==0&&C!==0&&b<C)throw new Error("LASLoader: LAS 1.5 GPS time range is invalid")}let g=[t.getFloat64(131,!0),t.getFloat64(139,!0),t.getFloat64(147,!0)],x=[t.getFloat64(155,!0),t.getFloat64(163,!0),t.getFloat64(171,!0)],B=[t.getFloat64(179,!0),t.getFloat64(195,!0),t.getFloat64(211,!0)],q=[t.getFloat64(187,!0),t.getFloat64(203,!0),t.getFloat64(219,!0)],M={pointsOffset:m,pointsFormatId:c,pointsStructSize:y,pointsCount:h,scale:g,offset:x,maxs:B,mins:q,totalToRead:h,totalRead:0,hasColor:Xb(c),versionAsString:`${e}.${n}`,isCompressed:l,headerSize:s,vlrCount:o,userHeaderData:n===5&&s>393?new Uint8Array(r,393,s-393).slice():void 0};return r2(r,M)&&(M.metadata=n2(r,M)),M}function r2(r,t){let e=t.headerSize+t.vlrCount*54;return r.byteLength>=Math.max(e,t.pointsOffset)}function n2(r,t){let e=new DataView(r),s=(t.versionAsString||"1.0").split(".").map(Number),i=s[0]>1||s[0]===1&&s[1]>=4,o=s2(e,t),a=i?Ks(e,235):0,c=i?e.getUint32(243,!0):0,l=i2(e,a,c),u={fileSourceId:e.getUint16(4,!0),globalEncoding:e.getUint16(6,!0),waveformDataOffset:s[0]>1||s[0]===1&&s[1]>=3?e.getBigUint64(227,!0):void 0,projectId:f2(new Uint8Array(r,8,16)),systemIdentifier:Ho(new Uint8Array(r),26,32),generatingSoftware:Ho(new Uint8Array(r),58,32),creationDayOfYear:e.getUint16(90,!0),creationYear:e.getUint16(92,!0),headerSize:t.headerSize,userHeaderData:t.userHeaderData,vlrCount:t.vlrCount,evlrOffset:a||void 0,evlrCount:c||void 0,maxGpsTime:s[1]===5?e.getFloat64(375,!0):void 0,minGpsTime:s[1]===5?e.getFloat64(383,!0):void 0,timeOffset:s[1]===5?e.getUint16(391,!0):void 0,pointsByReturn:u2(e,i),vlrs:o,evlrs:l,extraBytes:[],waveformPacketDescriptors:[]};for(let f of o.concat(l.map(h=>({...h,data:h.data||new Uint8Array}))))o2(f,u);return u.compatibility=Ob(t,u),a2(u),u}function s2(r,t){let e=new Uint8Array(r.buffer,r.byteOffset,r.byteLength),n=[],s=t.headerSize;for(let i=0;i<t.vlrCount&&!(s+54>e.byteLength);i++){let o=r.getUint16(s+20,!0),a=s+54;if(a+o>e.byteLength)break;n.push({reserved:r.getUint16(s,!0),userId:Ho(e,s+2,16),recordId:r.getUint16(s+18,!0),description:Ho(e,s+22,32),offset:s,data:e.slice(a,a+o)}),s=a+o}return n}function i2(r,t,e){if(!t||!e||t>=r.byteLength)return[];let n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength),s=[],i=t;for(let o=0;o<e&&!(i+60>n.byteLength);o++){let a=Ks(r,i+20),c=i+60;if(a>n.byteLength-c)break;s.push({reserved:r.getUint16(i,!0),userId:Ho(n,i+2,16),recordId:r.getUint16(i+18,!0),description:Ho(n,i+28,32),offset:i,data:n.slice(c,c+a),dataOffset:c,dataLength:a}),i=c+a}return s}function o2(r,t){let e=r.data;e&&(r.userId==="LASF_Spec"&&r.recordId===4?t.extraBytes.push(...Nb(e)):r.userId==="LASF_Spec"&&r.recordId>=100&&r.recordId<=354?t.waveformPacketDescriptors.push(l2(r.recordId,e)):r.userId==="LASF_Projection"&&r.recordId===2111?t.wktMathTransform=Iu(e):r.userId==="LASF_Projection"&&r.recordId===2112?t.wkt=Iu(e):r.userId==="LASF_Projection"&&r.recordId===34735?t.geotiff={...t.geotiff,keys:h2(e)}:r.userId==="LASF_Projection"&&r.recordId===34736?t.geotiff={...t.geotiff,doubles:d2(e)}:r.userId==="LASF_Projection"&&r.recordId===34737&&(t.geotiff={...t.geotiff,ascii:Iu(e)}))}function a2(r){let t=r.geotiff,e=t?.keys;if(!t||!e||e.length<4)return;let n=e[3];if(e.length<4+n*4)return;let s=[];for(let i=0;i<n;i++){let o=4+i*4,a={keyId:e[o],tiffTagLocation:e[o+1],count:e[o+2],valueOffset:e[o+3]};a.value=c2(a,t),a.value===void 0&&delete a.value,s.push(a)}t.keyDirectory={version:e[0],keyRevision:e[1],minorRevision:e[2],entries:s}}function c2(r,t){if(r.tiffTagLocation===0)return r.valueOffset;if(r.tiffTagLocation===34735&&t.keys){let e=t.keys.slice(r.valueOffset,r.valueOffset+r.count);return e.length===r.count?Array.from(e):void 0}if(r.tiffTagLocation===34736&&t.doubles){let e=t.doubles.slice(r.valueOffset,r.valueOffset+r.count);return e.length!==r.count?void 0:r.count===1?e[0]:Array.from(e)}if(r.tiffTagLocation===34737&&t.ascii!==void 0){let e=r.valueOffset+r.count;return e>t.ascii.length?void 0:t.ascii.slice(r.valueOffset,e).replace(/\|$/,"")}}function l2(r,t){if(t.byteLength<28)throw new Error(`LASLoader: waveform descriptor VLR ${r} is truncated`);let e=new DataView(t.buffer,t.byteOffset,t.byteLength);return{recordId:r,bitsPerSample:e.getUint8(2),compressionType:e.getUint8(3),numberOfSamples:e.getUint32(4,!0),temporalSampleSpacing:e.getUint32(8,!0),digitizerGain:e.getFloat64(12,!0),digitizerOffset:e.getFloat64(20,!0)}}function u2(r,t){let e=t?15:5,n=t?255:111,s=[];for(let i=0;i<e;i++)s.push(t?Ks(r,n+i*8):r.getUint32(n+i*4,!0));return s}function Ho(r,t,e){return Iu(r.subarray(t,t+e))}function Iu(r){let t=r.length;for(;t>0&&r[t-1]===0;)t--;return new TextDecoder().decode(r.subarray(0,t)).trim()}function f2(r){let t=(n,s)=>Array.from(r.subarray(n,n+s),i=>i.toString(16).padStart(2,"0")).reverse().join(""),e=(n,s)=>Array.from(r.subarray(n,n+s),i=>i.toString(16).padStart(2,"0")).join("");return`${t(0,4)}-${t(4,2)}-${t(6,2)}-${e(8,2)}${e(10,6)}`}function h2(r){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),e=new Uint16Array(Math.floor(r.byteLength/2));for(let n=0;n<e.length;n++)e[n]=t.getUint16(n*2,!0);return e}function d2(r){let t=new DataView(r.buffer,r.byteOffset,r.byteLength),e=new Float64Array(Math.floor(r.byteLength/8));for(let n=0;n<e.length;n++)e[n]=t.getFloat64(n*8,!0);return e}function _u(r,t,e={}){let n=t.pointsCount,s=e.las?.fp64?Float64Array:Float32Array,i=new s(n*3),o=t1(e),a=t.hasColor&&o.color?new Uint8Array(n*4):null,c=o.intensity?new Uint16Array(n):null,l=o.classification?new Uint8Array(n):null,u=o.synthetic?new Uint8Array(n):null,f=o.keyPoint?new Uint8Array(n):null,h=o.withheld?new Uint8Array(n):null,m=o.overlap?new Uint8Array(n):null,y=o.gpsTime&&mp(t.pointsFormatId)>=0?new Float64Array(n):null,g=o.nir&&(yp(t.pointsFormatId)>=0||e.las?.compatibilityMode!=="raw"&&t.metadata?.compatibility?.nirByteOffset!==void 0)?new Uint16Array(n):null,x=o.scanAngle?new Int16Array(n):null,B=o.userData?new Uint8Array(n):null,q=o.pointSourceId?new Uint16Array(n):null,M=o.returnNumber?new Uint8Array(n):null,b=o.numberOfReturns?new Uint8Array(n):null,C=o.scannerChannel?new Uint8Array(n):null,_=o.scanDirectionFlag?new Uint8Array(n):null,$=o.edgeOfFlightLine?new Uint8Array(n):null,X=o.waveform&&pp(t.pointsFormatId)>=0?new Uint8Array(n*29):null,ft=Math.max(0,t.pointsStructSize-Pn(t.pointsFormatId)),dt=o.extraBytes&&e.las?.extraBytes!=="typed"&&ft?new Uint8Array(n*ft):null,Bt=o.extraBytes&&e.las?.extraBytes==="typed"?Jb(n,t):null;return m2(p2(r),t,e,{positions:i,colors:a,intensities:c,classifications:l,syntheticFlags:u,keyPointFlags:f,withheldFlags:h,overlapFlags:m,gpsTimes:y,nir:g,scanAngles:x,userData:B,pointSourceIds:q,returnNumbers:M,numberOfReturns:b,scannerChannels:C,scanDirectionFlags:_,edgeOfFlightLines:$,waveforms:X,extraBytes:dt,typedExtraBytes:Bt,pointOffset:0,sourcePointIndex:0,pointCount:n}),hp(t,i,a,c,l,u,f,h,m,y,g,x,B,q,M,b,C,_,$,X,dt,Bt)}function hp(r,t,e,n,s,i,o,a,c,l,u,f,h,m,y,g,x,B,q,M,b,C){let _={POSITION:{value:t,size:3}};if(n&&(_.intensity={value:n,size:1}),s&&(_.classification={value:s,size:1}),i&&(_.synthetic={value:i,size:1}),o&&(_.keyPoint={value:o,size:1}),a&&(_.withheld={value:a,size:1}),c&&(_.overlap={value:c,size:1}),e&&(_.COLOR_0={value:e,size:e instanceof Uint16Array?3:4}),l&&(_.GPS_TIME={value:l,size:1}),u&&(_.NIR={value:u,size:1}),f&&(_.scanAngle={value:f,size:1}),h&&(_.userData={value:h,size:1}),m&&(_.pointSourceId={value:m,size:1}),y&&(_.returnNumber={value:y,size:1}),g&&(_.numberOfReturns={value:g,size:1}),x&&(_.scannerChannel={value:x,size:1}),B&&(_.scanDirectionFlag={value:B,size:1}),q&&(_.edgeOfFlightLine={value:q,size:1}),M&&(_.WAVEFORM={value:M,size:29}),b&&(_.EXTRA_BYTES={value:b,size:b.length/Math.max(r.pointsCount,1)}),C)for(let ft of C)_[ft.name]={value:ft.value,size:ft.size};let $={};for(let[ft,dt]of Object.entries(_))!(dt.value instanceof BigInt64Array)&&!(dt.value instanceof BigUint64Array)&&($[ft]={...dt,value:dt.value});let X=Cb(r,$);return{...Zl(_,{schema:X,topology:"point-list",mode:0,boundingBox:U2(r)}),loader:"las",loaderData:r,progress:r.totalRead/r.totalToRead}}function p2(r){return ArrayBuffer.isView(r)?new DataView(r.buffer,r.byteOffset,r.byteLength):new DataView(r)}function m2(r,t,e,n){let{scale:[s,i,o],offset:[a,c,l]}=t,u=t.pointsFormatId,f=t.pointsStructSize,h=n.colors?dp(u):-1,m=h>=0?g2(r,t,n.sourcePointIndex,n.pointCount,e.las?.colorDepth):!1,y=n.intensities,g=n.classifications,x=n.syntheticFlags,B=n.keyPointFlags,q=n.withheldFlags,M=n.overlapFlags,b=n.gpsTimes,C=n.nir,_=n.scanAngles,$=n.userData,X=n.pointSourceIds,ft=n.returnNumbers,dt=n.numberOfReturns,Bt=n.scannerChannels,se=n.scanDirectionFlags,rt=n.edgeOfFlightLines,tt=n.waveforms,Ye=n.extraBytes,Ne=n.typedExtraBytes,Ze=b?mp(u):-1,xt=C?yp(u):-1;for(let Gn=0;Gn<n.pointCount;Gn++){let Qs=n.sourcePointIndex+Gn,wt=t.pointsOffset+Qs*f,pt=n.pointOffset+Gn;n.positions[pt*3]=r.getInt32(wt,!0)*s+a,n.positions[pt*3+1]=r.getInt32(wt+4,!0)*i+c,n.positions[pt*3+2]=r.getInt32(wt+8,!0)*o+l,y&&(y[pt]=r.getUint16(wt+12,!0)),g&&(g[pt]=y2(r,wt,u)),b&&Ze>=0&&(b[pt]=r.getFloat64(wt+Ze,!0)),C&&xt>=0&&(C[pt]=r.getUint16(wt+xt,!0)),_&&(_[pt]=u<=5?r.getInt8(wt+16):r.getInt16(wt+18,!0)),$&&($[pt]=r.getUint8(wt+17)),X&&(X[pt]=r.getUint16(wt+(u<=5?18:20),!0));let un=r.getUint8(wt+14),qr=r.getUint8(wt+15),fn=u<=5?qr>>5:qr;if(x&&(x[pt]=fn&1),B&&(B[pt]=fn>>1&1),q&&(q[pt]=fn>>2&1),M&&(M[pt]=u<=5?0:fn>>3&1),ft&&(ft[pt]=u<=5?un&7:un&15),dt&&(dt[pt]=u<=5?un>>3&7:un>>4),Bt&&(Bt[pt]=u<=5?0:qr>>4&3),se&&(se[pt]=u<=5?un>>6&1:qr>>6&1),rt&&(rt[pt]=u<=5?un>>7&1:qr>>7&1),tt){let vr=pp(u);if(vr>=0){let Ar=new Uint8Array(r.buffer,r.byteOffset+wt+vr,29);tt.set(Ar,pt*29)}}if(Ye){let vr=Pn(u),Ar=t.pointsStructSize-vr;Ar>0&&Ye.set(new Uint8Array(r.buffer,r.byteOffset+wt+vr,Ar),pt*Ar)}if(Ne&&M2(r,wt,u,pt,Ne),e.las?.compatibilityMode!=="raw"&&t.metadata?.compatibility&&lp(r,wt+Pn(u),pt,t.metadata.compatibility,n),h>=0&&n.colors){let vr=r.getUint16(wt+h,!0),Ar=r.getUint16(wt+h+2,!0),eo=r.getUint16(wt+h+4,!0);n.colors[pt*4]=m?vr/256:vr,n.colors[pt*4+1]=m?Ar/256:Ar,n.colors[pt*4+2]=m?eo/256:eo,n.colors[pt*4+3]=255}}}function y2(r,t,e){return e<=5?r.getUint8(t+15)&31:r.getUint8(t+16)}function Xb(r){return dp(r)>=0}function dp(r){switch(r){case 2:return 20;case 3:return 28;case 5:return 28;case 7:case 8:case 10:return 30;default:return-1}}function pp(r){switch(r){case 4:return 28;case 5:return 34;case 9:return 30;case 10:return 38;default:return-1}}function mp(r){return r===1||r===3||r===4||r===5?20:r>=6&&r<=10?22:-1}function yp(r){return r===8||r===10?36:-1}function g2(r,t,e,n,s){if(s===8)return!1;if(s===16)return!0;if(s!=="auto")return!1;let i=dp(t.pointsFormatId);if(i<0)return!1;for(let o=0;o<n;o++){let a=t.pointsOffset+(e+o)*t.pointsStructSize;if(r.getUint16(a+i,!0)>255||r.getUint16(a+i+2,!0)>255||r.getUint16(a+i+4,!0)>255)return!0}return!1}function Xo(r){let t=r.batchSize??r.core?.batchSize;return typeof t=="number"?t:zb}function gp(r,t){let e=new DataView(r.buffer,r.byteOffset,r.byteLength),n=t.headerSize||Gb,s=t.vlrCount||0;for(let i=0;i<s;i++){if(n+54>r.byteLength)throw new it("LASLoader: incomplete VLR header");let o=E2(r,n+2,16),a=e.getUint16(n+18,!0),c=e.getUint16(n+20,!0),l=n+54;if(l+c>r.byteLength)throw new it("LASLoader: incomplete VLR data");if(o===GS&&a===jS){if(c<34)throw new Error("LASLoader: malformed LASzip VLR");let u=e.getUint32(l+12,!0),f=e.getUint16(l+32,!0);if(34+f*6>c)throw new Error("LASLoader: malformed LASzip VLR item table");let m=null,y=null,g=null,x=null,B=null,q=[];for(let M=0;M<f;M++){let b=l+34+M*6,C=e.getUint16(b,!0),_=e.getUint16(b+2,!0),$=e.getUint16(b+4,!0);if(q.push({type:C,size:_,version:$}),[0,6,7,8].includes(C)){if($!==1&&$!==2)throw new Error(`LASLoader: unsupported legacy LASzip item type ${C} version ${$}`)}else if(C===9){if($!==1)throw new Error(`LASLoader: unsupported WavePacket13 item version ${$}`);g=$}else if([10,11,12,14].includes(C)){if($!==2&&$!==3&&$!==4)throw new Error(`LASLoader: unsupported LAS 1.4 item type ${C} version ${$}`);C===10?m=$:C===11||C===12?y=$:B=$}else if(C===13){if($!==3&&$!==4)throw new Error(`LASLoader: unsupported WavePacket14 item version ${$}`);x=$}}return{compressor:e.getUint16(l,!0),coder:e.getUint16(l+2,!0),chunkSize:u,variableChunks:e.getUint16(l,!0)!==1&&(u===0||u===qS),items:q,point14ItemVersion:m,rgb14ItemVersion:y,wavePacket13ItemVersion:g,wavePacketItemVersion:x,byte14ItemVersion:B}}n=l+c}throw new Error("LASLoader: compressed LAZ file does not contain a LASzip VLR")}function bp(r,t){if(![0,1,2,3,4,5,6,7,8,9,10].includes(r.pointsFormatId))throw new Error(`LASLoader: TypeScript LAZ streaming only supports point formats 0-10; received ${r.pointsFormatId}`);if(r.pointsFormatId<=5&&t.compressor!==1&&t.compressor!==2)throw new Error(`LASLoader: legacy TypeScript LAZ decoding requires LASzip compressor 1 or 2; received ${t.compressor}`);if(r.pointsFormatId>=6&&t.compressor!==3)throw new Error(`LASLoader: LAS 1.4 TypeScript LAZ decoding requires LASzip compressor 3; received ${t.compressor}`);if(t.coder!==0)throw new Error(`LASLoader: TypeScript LAZ decoding requires LASzip arithmetic coder 0; received ${t.coder}`);if(b2(r,t.items),r.pointsFormatId>=6&&!t.point14ItemVersion)throw new Error(`LASLoader: point format ${r.pointsFormatId} requires a Point14 LASzip item`);if((r.pointsFormatId===4||r.pointsFormatId===5)&&!t.wavePacket13ItemVersion)throw new Error(`LASLoader: point format ${r.pointsFormatId} requires a WavePacket13 LASzip item`);if((r.pointsFormatId===7||r.pointsFormatId===8||r.pointsFormatId===10)&&!t.rgb14ItemVersion)throw new Error(`LASLoader: point format ${r.pointsFormatId} requires an RGB14 or RGBNIR14 LASzip item`);if(r.pointsFormatId>=6&&r.pointsStructSize>Pn(r.pointsFormatId)&&!t.byte14ItemVersion)throw new Error(`LASLoader: point format ${r.pointsFormatId} with Extra Bytes requires a Byte14 LASzip item`);if((r.pointsFormatId===9||r.pointsFormatId===10)&&!t.wavePacketItemVersion)throw new Error(`LASLoader: point format ${r.pointsFormatId} requires a WavePacket14 LASzip item`)}function b2(r,t){let e=r.pointsFormatId,n=Pn(e),s=r.pointsStructSize-n;if(s<0)throw new Error(`LASLoader: point format ${e} record length ${r.pointsStructSize} is smaller than ${n}`);let i=[];switch(e){case 0:i.push({type:6,size:20});break;case 1:i.push({type:6,size:20},{type:7,size:8});break;case 2:i.push({type:6,size:20},{type:8,size:6});break;case 3:i.push({type:6,size:20},{type:7,size:8},{type:8,size:6});break;case 4:i.push({type:6,size:20},{type:7,size:8},{type:9,size:29});break;case 5:i.push({type:6,size:20},{type:7,size:8},{type:8,size:6},{type:9,size:29});break;case 6:i.push({type:10,size:30});break;case 7:i.push({type:10,size:30},{type:11,size:6});break;case 8:i.push({type:10,size:30},{type:12,size:8});break;case 9:i.push({type:10,size:30},{type:13,size:29});break;case 10:i.push({type:10,size:30},{type:12,size:8},{type:13,size:29});break;default:return}if(s>0&&i.push({type:e<=5?0:14,size:s}),t.length!==i.length)throw new Error(`LASLoader: point format ${e} has ${t.length} LASzip items; expected ${i.length}`);for(let o=0;o<i.length;o++){let a=t[o],c=i[o];if(a.type!==c.type)throw new Error(`LASLoader: LASzip item ${o} has type ${a.type}; expected ${c.type} for point format ${e}`);if(a.size!==c.size)throw new Error(`LASLoader: LASzip item ${o} has size ${a.size}; expected ${c.size} for point format ${e}`)}}async function w2(r,t,e){let n=r;for(;;){try{return{pending:n,laszip:gp(n,e)}}catch(i){if(!(i instanceof it))throw i}let s=await t.next();if(s.done)throw new it("LASLoader: incomplete LASzip VLR");n=r1(n,Bp(s.value))}}async function x2(r,t){let e=[r],n=r.byteLength;for(;;){let o=await t.next();if(o.done)break;let a=Bp(o.value);e.push(a),n+=a.byteLength}if(e.length===1)return r;let s=new Uint8Array(n),i=0;for(let o of e)s.set(o,i),i+=o.byteLength;return s}async function Tu(r,t,e,n,s,i,o){if(o.las?.recoverMissingChunkTable&&s===e.pointsOffset){if(n.variableChunks)throw new Error("LASLoader: cannot recover a missing variable-size LAZ chunk table");for(;;){if(r.getAvailableByteLength())throw new Error("LASLoader: unexpected bytes after recovered LAZ chunks");let h=await t.next();if(h.done)return;r.write(h.value)}}let a=i.reduce((h,m)=>h+m,0),c=e.pointsOffset+Wt+a,l=s===-1?c:s;if(!Number.isSafeInteger(l)||l<c)throw new Error("LASLoader: LAZ chunk table byte lengths overlap the chunk table");let u=l-c;await Qi(r,t,u,"LASLoader: incomplete LAZ chunk table"),r.skip(u);let f=await S2(r,t,e,n);if(f.length!==i.length)throw new Error(`LASLoader: LAZ chunk table contains ${f.length} chunks; decoded ${i.length}`);for(let h=0;h<f.length;h++)if(f[h].byteLength!==i[h])throw new Error(`LASLoader: LAZ chunk ${h} has ${f[h].byteLength} table bytes; decoded ${i[h]}`);s===-1&&await v2(r,t,l)}async function v2(r,t,e){let n=new Uint8Array(Wt),s=0;for(;;){let o=r.getAvailableByteLength();if(o>0){let c=r.readBytes(Math.min(o,65536));A2(n,c),s+=c.byteLength;continue}let a=await t.next();if(a.done)break;r.write(a.value)}if(s<Wt)throw new it("LASLoader: incomplete non-seekable LAZ chunk-table footer");let i=Ks(new DataView(n.buffer),0);if(!Number.isSafeInteger(i)||i!==e)throw new Error(`LASLoader: non-seekable LAZ footer points to ${i}; expected ${e}`)}function A2(r,t){if(t.byteLength>=r.byteLength){r.set(t.subarray(t.byteLength-r.byteLength));return}r.copyWithin(0,t.byteLength),r.set(t,r.byteLength-t.byteLength)}async function S2(r,t,e,n){let s=64;for(;;){let i=r.getAvailableByteLength();if(i>=8){let a=r.checkpoint();try{let c=r.readBytes(Math.min(i,s)),l=Kb(c,e,n);return r.restore(a),l}catch(c){if(r.restore(a),!(c instanceof it))throw c;if(s*=2,s<=i)continue}}let o=await t.next();if(o.done)throw new it("LASLoader: incomplete LAZ chunk table");r.write(o.value)}}async function Qi(r,t,e,n){for(;!r.hasAvailableBytes(e);){let s=await t.next();if(s.done)throw new it(n);r.write(s.value)}}async function B2(r,t,e){for(;;){let n=r.checkpoint(),s;try{s=I2(r,e)}finally{r.restore(n)}if(s!==null)return await Qi(r,t,s,"LASLoader: truncated LAZ chunk"),s;let i=await t.next();if(i.done)throw new it("LASLoader: truncated LAZ chunk");r.write(i.value)}}function I2(r,t){if(t.pointDataRecordFormat<6||t.pointDataRecordFormat>10)return null;let e=t.pointDataRecordLength-Pn(t.pointDataRecordFormat);if(e<0)throw new Error(`Invalid point record length ${t.pointDataRecordLength}`);let n=_2(t.pointDataRecordFormat)+e,s=t.pointDataRecordLength+4,i=n*4,o=s+i;if(!r.hasAvailableBytes(o))return null;r.skip(s);let a=o;for(let c=0;c<n;c++)a+=r.readUint32LE();return a}function Pn(r){switch(r){case 0:return 20;case 1:return 28;case 2:return 26;case 3:return 34;case 4:return 57;case 5:return 63;case 6:return 30;case 7:return 36;case 8:return 38;case 9:return 59;case 10:return 67;default:throw new Error(`Unsupported LAS point format ${r}`)}}function _2(r){switch(r){case 6:return 9;case 7:return 10;case 8:return 11;case 9:return 10;case 10:return 12;default:throw new Error(`Unsupported LAS 1.4 point format ${r}`)}}function wp(r,t,e,n){if(e.compressor===1)return[{pointCount:t.pointsCount,byteLength:r.byteLength-t.pointsOffset}];let s=z2(new DataView(r.buffer,r.byteOffset,r.byteLength),t.pointsOffset);return L2(r,t,e,s,n)}function L2(r,t,e,n,s){if(s.las?.recoverMissingChunkTable&&n===t.pointsOffset)return T2(r,t,e);if(!Number.isSafeInteger(n)||n<0||n+8>r.byteLength)throw new it("LASLoader: incomplete LAZ chunk table");let i=Kb(r.subarray(n),t,e),o=i.reduce((a,c)=>a+c.byteLength,0);if(t.pointsOffset+Wt+o>n)throw new Error("LASLoader: LAZ chunk table byte lengths overlap the chunk table");return i}function T2(r,t,e){if(e.variableChunks||!e.chunkSize)throw new Error("LASLoader: cannot recover a missing variable-size LAZ chunk table");let n=[],s=t.pointsOffset+Wt,i=0;for(;i<t.pointsCount;){let o=Math.min(e.chunkSize,t.pointsCount-i),a=Js(t,e,o),c=r.subarray(s),l;if(t.pointsFormatId<=5){let u=Gr(c,a),f=new Uint8Array(Math.min(o,256)*t.pointsStructSize);for(;u.remainingPointCount;)u.decodeInto(f,0,Math.min(u.remainingPointCount,256));l=u.compressedByteOffset}else xp(c,a),l=du(c,a);if(!l||s+l>r.byteLength)throw new it("LASLoader: truncated LAZ chunk during table recovery");n.push({pointCount:o,byteLength:l}),s+=l,i+=o}if(s!==r.byteLength)throw new Error("LASLoader: unexpected bytes after recovered LAZ chunks");return n}function xp(r,t){if(r.byteLength<t.pointDataRecordLength+4)throw new it("LASLoader: truncated recovered layered LAZ chunk header");let n=new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(t.pointDataRecordLength,!0);if(n!==t.pointCount)throw new Error(`LASLoader: recovered layered LAZ chunk contains ${n} points; expected ${t.pointCount}`)}function Kb(r,t,e){if(r.byteLength<8)throw new it("LASLoader: incomplete LAZ chunk table");let n=new DataView(r.buffer,r.byteOffset,r.byteLength),s=n.getUint32(0,!0),i=n.getUint32(4,!0);if(s!==0)throw new Error(`LASLoader: unsupported LAZ chunk table version ${s}`);if(i===0){if(t.pointsCount!==0)throw new Error("LASLoader: missing LAZ chunk table");return[]}let o=Wd(r.subarray(8),{chunkCount:i,pointCount:t.pointsCount,chunkSize:e.chunkSize,variable:e.variableChunks}),a=0;for(let c of o){if(c.pointCount===0||c.byteLength===0)throw new Error("LASLoader: invalid empty LAZ chunk-table entry");a+=c.pointCount}if(a!==t.pointsCount)throw new Error(`LASLoader: LAZ chunk table contains ${a} points; expected ${t.pointsCount}`);return o}function Mu(r,t,e){return e&&e.rawBatchAllocations++,{rawBatch:new Uint8Array(r*t),batchPointCount:0,totalRead:0,rawBatchAllocations:1,stats:e}}function Du(r,t,e){let n=e.las?.fp64?Float64Array:Float32Array,s=new n(r*3),i=t1(e),o=t.hasColor&&i.color&&(e.las?.colorDepth===16||e.las?.colorDepth==="auto"),a=t.hasColor&&i.color&&!o?new Uint8Array(r*4):null,c=o?new Uint16Array(r*3):null,l=i.intensity?new Uint16Array(r):null,u=i.classification?new Uint8Array(r):null,f=i.synthetic?new Uint8Array(r):null,h=i.keyPoint?new Uint8Array(r):null,m=i.withheld?new Uint8Array(r):null,y=i.overlap?new Uint8Array(r):null,g=i.gpsTime&&mp(t.pointsFormatId)>=0?new Float64Array(r):null,x=i.nir&&(yp(t.pointsFormatId)>=0||e.las?.compatibilityMode!=="raw"&&t.metadata?.compatibility?.nirByteOffset!==void 0)?new Uint16Array(r):null,B=i.scanAngle?new Int16Array(r):null,q=i.userData?new Uint8Array(r):null,M=i.pointSourceId?new Uint16Array(r):null,b=i.returnNumber?new Uint8Array(r):null,C=i.numberOfReturns?new Uint8Array(r):null,_=i.scannerChannel?new Uint8Array(r):null,$=i.scanDirectionFlag?new Uint8Array(r):null,X=i.edgeOfFlightLine?new Uint8Array(r):null,ft=i.waveform&&pp(t.pointsFormatId)>=0?new Uint8Array(r*29):null,dt=Math.max(0,t.pointsStructSize-Pn(t.pointsFormatId)),Bt=i.extraBytes&&e.las?.extraBytes!=="typed"&&dt?new Uint8Array(r*dt):null,se=i.extraBytes&&e.las?.extraBytes==="typed"?Jb(r,t):null,rt=se?.length&&dt?new Uint8Array(r*dt):null,tt=i.classification||i.returnNumber||i.numberOfReturns||i.scanAngle||i.overlap||i.scannerChannel||i.nir,Ye=e.las?.compatibilityMode==="raw"||!tt?null:t.metadata?.compatibility||null,Ne=Ye&&!Bt&&!rt?new Uint8Array(r*dt):null;return{batchCapacity:r,positions:s,colors:a,rawColors:c,intensities:l,classifications:u,syntheticFlags:f,keyPointFlags:h,withheldFlags:m,overlapFlags:y,gpsTimes:g,nir:x,scanAngles:B,userData:q,pointSourceIds:M,returnNumbers:b,numberOfReturns:C,scannerChannels:_,scanDirectionFlags:$,edgeOfFlightLines:X,waveforms:ft,extraBytes:Bt,typedExtraBytes:se,typedExtraBytesSource:rt,compatibilityLayout:Ye,compatibilityExtraBytesSource:Ne,target:{positions:s,intensities:l,classifications:u,syntheticFlags:f,keyPointFlags:h,withheldFlags:m,overlapFlags:y,gpsTimes:g,nir:x,scanAngles:B,userData:q,pointSourceIds:M,returnNumbers:b,numberOfReturns:C,scannerChannels:_,scanDirectionFlags:$,edgeOfFlightLines:X,waveforms:ft,extraBytes:Bt||rt||Ne,colors:a,rawColors:c,pointOffset:0,scale:t.scale,offset:t.offset},batchPointCount:0,totalRead:0}}function Jb(r,t){let e=t.pointsStructSize-Pn(t.pointsFormatId);return Rb(r,t.metadata?.extraBytes||[],e)}function Qb(r){return r<=2?1:r<=4?2:r<=6||r===9?4:r===7||r===8||r===10?8:0}function M2(r,t,e,n,s){let i=t+Pn(e);for(let o of s){let a=n*o.size,c=i+o.byteOffset;for(let l=0;l<o.size;l++)fp(r,c+l*Qb(o.scalarDataType),o,a+l,l)}}function D2(r,t,e,n,s){let i=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let o=0;o<n;o++){let a=e+o,c=a*t;for(let l of s){let u=a*l.size,f=Qb(l.scalarDataType);for(let h=0;h<l.size;h++)fp(i,c+l.byteOffset+h*f,l,u+h,h)}}}function vp(r,t,e){let n=r.extraBytes||r.typedExtraBytesSource||r.compatibilityExtraBytesSource;if(r.compatibilityLayout&&n&&e){let s=new DataView(n.buffer,n.byteOffset,n.byteLength),i=n.length/r.batchCapacity;for(let o=t;o<t+e;o++)lp(s,o*i,o,r.compatibilityLayout,r)}!r.typedExtraBytesSource||!r.typedExtraBytes?.length||e===0||D2(r.typedExtraBytesSource,r.typedExtraBytesSource.length/r.batchCapacity,t,e,r.typedExtraBytes)}function Cu(r){return r.las?.lazStreamingStats}function Ap(r,t,e){if(!e)return;let n=r.findBufferOffsets(t);n&&n.length>1&&(e.copiedBytes+=t,e.chunkConcatenations++)}function C2(r,t){t&&(t.copiedBytes+=r,t.decodedChunkAllocations++)}function*Sp(r,t,e,n){let s=e.pointsStructSize,i=Gr(r,t);for(;i.remainingPointCount>0;){let o=n.rawBatch.byteLength/s,a=o-n.batchPointCount,c=i.decodeInto(n.rawBatch,n.batchPointCount*s,a);if(n.batchPointCount+=c,n.batchPointCount===o){let l=Ji(e,n);l&&(yield l)}}}function*F2(r,t,e){let n=t.pointsStructSize,s=r.byteLength/n;for(let i=0;i<s;i++){let o=i*n,a=e.batchPointCount*n;if(e.rawBatch.set(r.subarray(o,o+n),a),e.batchPointCount++,e.batchPointCount===e.rawBatch.byteLength/n){let c=Ji(t,e);c&&(yield c)}}}function Ji(r,t){if(t.batchPointCount===0)return null;let e=t.batchPointCount*r.pointsStructSize,n=e===t.rawBatch.byteLength,s=n?t.rawBatch.buffer:t.rawBatch.buffer.slice(0,e);t.totalRead+=t.batchPointCount;let i={...r,pointsOffset:0,pointsCount:t.batchPointCount,totalRead:t.totalRead};return t.batchPointCount=0,n&&(t.rawBatch=new Uint8Array(t.rawBatch.byteLength),t.rawBatchAllocations++,t.stats&&t.stats.rawBatchAllocations++),{arrayBuffer:s,header:i}}function Lu(r,t,e){if(t.batchPointCount===0)return null;t.totalRead+=t.batchPointCount;let n={...r,pointsOffset:0,pointsCount:t.batchPointCount,totalRead:t.totalRead},s=t.batchPointCount,i=s===t.batchCapacity,o=i?t.positions:t.positions.subarray(0,s*3),a=t.intensities?i?t.intensities:t.intensities.subarray(0,s):null,c=t.classifications?i?t.classifications:t.classifications.subarray(0,s):null,l=t.syntheticFlags?i?t.syntheticFlags:t.syntheticFlags.subarray(0,s):null,u=t.keyPointFlags?i?t.keyPointFlags:t.keyPointFlags.subarray(0,s):null,f=t.withheldFlags?i?t.withheldFlags:t.withheldFlags.subarray(0,s):null,h=t.overlapFlags?i?t.overlapFlags:t.overlapFlags.subarray(0,s):null,m=t.colors?i?t.colors:t.colors.subarray(0,s*4):t.rawColors?e1(t.rawColors,s,e):null,y=t.gpsTimes?i?t.gpsTimes:t.gpsTimes.subarray(0,s):null,g=t.nir?i?t.nir:t.nir.subarray(0,s):null,x=t.scanAngles?i?t.scanAngles:t.scanAngles.subarray(0,s):null,B=t.userData?i?t.userData:t.userData.subarray(0,s):null,q=t.pointSourceIds?i?t.pointSourceIds:t.pointSourceIds.subarray(0,s):null,M=t.returnNumbers?i?t.returnNumbers:t.returnNumbers.subarray(0,s):null,b=t.numberOfReturns?i?t.numberOfReturns:t.numberOfReturns.subarray(0,s):null,C=t.scannerChannels?i?t.scannerChannels:t.scannerChannels.subarray(0,s):null,_=t.scanDirectionFlags?i?t.scanDirectionFlags:t.scanDirectionFlags.subarray(0,s):null,$=t.edgeOfFlightLines?i?t.edgeOfFlightLines:t.edgeOfFlightLines.subarray(0,s):null,X=t.waveforms?i?t.waveforms:t.waveforms.subarray(0,s*29):null,ft=t.extraBytes?t.extraBytes.length/t.batchCapacity:0,dt=t.extraBytes?i?t.extraBytes:t.extraBytes.subarray(0,s*ft):null,Bt=t.typedExtraBytes?t.typedExtraBytes.map(rt=>({...rt,value:i?rt.value:rt.value.subarray(0,s*rt.size)})):null,se=hp(n,o,m,a,c,l,u,f,h,y,g,x,B,q,M,b,C,_,$,X,dt,Bt);if(t.batchPointCount=0,i){let rt=e.las?.fp64?Float64Array:Float32Array;t.positions=new rt(t.positions.length),t.colors=t.colors?new Uint8Array(t.colors.length):null,t.rawColors=t.rawColors?new Uint16Array(t.rawColors.length):null,t.intensities=t.intensities?new Uint16Array(t.intensities.length):null,t.classifications=t.classifications?new Uint8Array(t.classifications.length):null,t.syntheticFlags=t.syntheticFlags?new Uint8Array(t.syntheticFlags.length):null,t.keyPointFlags=t.keyPointFlags?new Uint8Array(t.keyPointFlags.length):null,t.withheldFlags=t.withheldFlags?new Uint8Array(t.withheldFlags.length):null,t.overlapFlags=t.overlapFlags?new Uint8Array(t.overlapFlags.length):null,t.gpsTimes=t.gpsTimes?new Float64Array(t.gpsTimes.length):null,t.nir=t.nir?new Uint16Array(t.nir.length):null,t.scanAngles=t.scanAngles?new Int16Array(t.scanAngles.length):null,t.userData=t.userData?new Uint8Array(t.userData.length):null,t.pointSourceIds=t.pointSourceIds?new Uint16Array(t.pointSourceIds.length):null,t.returnNumbers=t.returnNumbers?new Uint8Array(t.returnNumbers.length):null,t.numberOfReturns=t.numberOfReturns?new Uint8Array(t.numberOfReturns.length):null,t.scannerChannels=t.scannerChannels?new Uint8Array(t.scannerChannels.length):null,t.scanDirectionFlags=t.scanDirectionFlags?new Uint8Array(t.scanDirectionFlags.length):null,t.edgeOfFlightLines=t.edgeOfFlightLines?new Uint8Array(t.edgeOfFlightLines.length):null,t.waveforms=t.waveforms?new Uint8Array(t.waveforms.length):null,t.extraBytes=t.extraBytes?new Uint8Array(t.extraBytes.length):null,t.typedExtraBytes=t.typedExtraBytes?t.typedExtraBytes.map(tt=>({...tt,value:up(tt.scalarDataType,tt.value.length,tt.outputFloat64)})):null,t.typedExtraBytesSource=t.typedExtraBytesSource?new Uint8Array(t.typedExtraBytesSource.length):null,t.target.positions=t.positions,t.target.colors=t.colors,t.target.rawColors=t.rawColors,t.target.intensities=t.intensities,t.target.classifications=t.classifications,t.target.syntheticFlags=t.syntheticFlags,t.target.keyPointFlags=t.keyPointFlags,t.target.withheldFlags=t.withheldFlags,t.target.overlapFlags=t.overlapFlags,t.target.gpsTimes=t.gpsTimes,t.target.nir=t.nir,t.target.scanAngles=t.scanAngles,t.target.userData=t.userData,t.target.pointSourceIds=t.pointSourceIds,t.target.returnNumbers=t.returnNumbers,t.target.numberOfReturns=t.numberOfReturns,t.target.scannerChannels=t.scannerChannels,t.target.scanDirectionFlags=t.scanDirectionFlags,t.target.edgeOfFlightLines=t.edgeOfFlightLines,t.target.waveforms=t.waveforms,t.compatibilityExtraBytesSource=t.compatibilityExtraBytesSource?new Uint8Array(t.compatibilityExtraBytesSource.length):null,t.target.extraBytes=t.extraBytes||t.typedExtraBytesSource||t.compatibilityExtraBytesSource}return se}function t1(r){let t=r.las?.columns;if(!t)return{intensity:!0,classification:!0,synthetic:!0,keyPoint:!0,withheld:!0,overlap:!0,color:!0,gpsTime:!0,nir:!0,scanAngle:!0,userData:!0,pointSourceId:!0,returnNumber:!0,numberOfReturns:!0,scannerChannel:!0,scanDirectionFlag:!0,edgeOfFlightLine:!0,waveform:!0,extraBytes:r.las?.extraBytes==="typed"};let e=!1,n=!1,s=!1,i=!1,o=!1,a=!1,c=!1,l=!1,u=!1,f=!1,h=!1,m=!1,y=!1,g=!1,x=!1,B=!1,q=!1,M=!1,b=!1;for(let C of t)switch(C){case"POSITION":break;case"intensity":e=!0;break;case"classification":n=!0;break;case"synthetic":s=!0;break;case"keyPoint":i=!0;break;case"withheld":o=!0;break;case"overlap":a=!0;break;case"COLOR_0":c=!0;break;case"GPS_TIME":l=!0;break;case"NIR":u=!0;break;case"scanAngle":f=!0;break;case"userData":h=!0;break;case"pointSourceId":m=!0;break;case"returnNumber":y=!0;break;case"numberOfReturns":g=!0;break;case"scannerChannel":x=!0;break;case"scanDirectionFlag":B=!0;break;case"edgeOfFlightLine":q=!0;break;case"WAVEFORM":M=!0;break;case"EXTRA_BYTES":b=!0;break;default:throw new Error(`LASLoader: unsupported column ${C}`)}return{intensity:e,classification:n,synthetic:s,keyPoint:i,withheld:o,overlap:a,color:c,gpsTime:l,nir:u,scanAngle:f,userData:h,pointSourceId:m,returnNumber:y,numberOfReturns:g,scannerChannel:x,scanDirectionFlag:B,edgeOfFlightLine:q,waveform:M,extraBytes:b}}function e1(r,t,e){let n=new Uint8Array(t*4),s=new Uint32Array(n.buffer);if(O2(r,t,e.las?.colorDepth))for(let o=0;o<t;o++){let a=o*3,c=r[a]>>8&255,l=r[a+1]>>8&255,u=r[a+2]>>8&255;s[o]=4278190080|u<<16|l<<8|c}else for(let o=0;o<t;o++){let a=o*3,c=r[a]&255,l=r[a+1]&255,u=r[a+2]&255;s[o]=4278190080|u<<16|l<<8|c}return n}function O2(r,t,e){if(e===8)return!1;if(e===16)return!0;if(e!=="auto")return!1;for(let n=0;n<t*3;n++)if(r[n]>255)return!0;return!1}function E2(r,t,e){let n=t,s=t+e;for(;n<s&&r[n]!==0;)n++;return String.fromCharCode(...r.subarray(t,n))}function U2(r){let t=r.mins||[0,0,0],e=r.maxs||[0,0,0];return[[t[0],t[1],t[2]],[e[0],e[1],e[2]]]}function*N2(r,t,e,n,s,i){for(;n<e.pointsCount&&s<e.totalToRead;){let o=R2(r,t,e,n,s,i);if(!o)return;r=o.pending,t=o.absoluteOffset,n=o.sourcePointIndex,s=o.totalRead,yield o}}function R2(r,t,e,n,s,i){let o=e.pointsStructSize,c=e.pointsOffset+n*o-t;if(c<0)throw new Error("LASLoader: invalid streaming point offset");if(c+o>r.byteLength)return null;let l=Math.floor((r.byteLength-c)/o),u=Math.min(i,l,e.pointsCount-n,e.totalToRead-s);if(u<=0)return null;n+=u,s+=u;let f={...e,pointsOffset:r.byteOffset+c,pointsCount:u,totalRead:s},h=e.pointsOffset+n*o,m=Math.max(0,Math.min(r.byteLength,h-t));return{arrayBuffer:r.buffer,header:f,pending:r.subarray(m),absoluteOffset:t+m,sourcePointIndex:n,totalRead:s}}function P2(r,t){if(t!==0||r.byteLength<227)return null;let e=new DataView(r.buffer,r.byteOffset,r.byteLength);if(e.getUint32(0,!0)!==Vb)throw new Error("LASLoader: invalid LAS header");let n=e.getUint32(96,!0);return r.byteLength<Math.max(n,255)?null:Hb(r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength))}function r1(r,t){if(r.byteLength===0)return t;let e=new Uint8Array(r.byteLength+t.byteLength);return e.set(r),e.set(t,r.byteLength),e}function Bp(r){let t=ArrayBuffer.isView(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r),e=new Uint8Array(t.byteLength);return e.set(t),e}function k2(r){if(Symbol.asyncIterator in r)return r[Symbol.asyncIterator]();let t=r[Symbol.iterator]();return{async next(){return t.next()}}}function z2(r,t){return n1(r,t)?r.byteLength<Wt?0:Ks(r,r.byteLength-Wt):Ks(r,t)}function Fu(r){return n1(r,0)?-1:Ks(r,0)}function n1(r,t){return r.byteLength>=t+8&&r.getUint32(t,!0)===4294967295&&r.getUint32(t+4,!0)===4294967295}function Ks(r,t){if(r.byteLength<t+8)return 0;let e=r.getUint32(t,!0);return r.getUint32(t+4,!0)*2**32+e}var zb,Vb,Gb,zS,VS,GS,jS,qS,Wt,$S,s1=p(()=>{"use strict";or();Zo();Fb();Eb();Pb();zb=1e3*100,Vb=1179861324,Gb=375,zS=128,VS=63,GS="laszip encoded",jS=22204,qS=4294967295,Wt=8,$S=64*1024});function i1(r,t){let e=t?.las?._chunk;return e?qb(r,e.metadata,t||{}):jb(r,t)}function Ou(r,t){let e=t?.las?.colorFormat===void 0||t.las.colorFormat==="uint8norm"?r:{...Ee(Gg(ee(r),t.las.colorFormat),"arrow-table"),loader:r.loader,loaderData:r.loaderData,progress:r.progress};return zg(t)==="arrow-table"?e:{...ee(e),loader:e.loader,loaderData:e.loaderData,progress:e.progress}}async function*G2(r,t){for await(let e of r)yield Ou(e,t)}function o1(r,t){return Ou(Po(r),t)}var V2,a1=p(()=>{"use strict";or();jg();Gs();s1();V2={...Vg,worker:!0,workerInBatches:!0,serializeWorkerResult:re,serializeWorkerBatch:re,deserializeWorkerResult:o1,deserializeWorkerBatch:o1,parse:async(r,t)=>Ou(i1(r,t),t),parseSync:(r,t)=>Ou(i1(r,t),t),parseInBatches:async function*(r,t){yield*G2(Wb(r,t),t)}}});var c1={};Re(c1,{LASLoaderWithParser:()=>V2});var l1=p(()=>{"use strict";a1()});function v1(r,t){let e=r.length,n=new Uint8Array(t),s=0,i=0,o,a,c;do if(o=r[s++],o<32){if(o++,i+o>t)throw new Error("Output buffer is not large enough");if(s+o>e)throw new Error("Invalid compressed data");do n[i++]=r[s++];while(--o)}else{if(a=o>>5,c=i-((o&31)<<8)-1,s>=e)throw new Error("Invalid compressed data");if(a===7&&(a+=r[s++],s>=e))throw new Error("Invalid compressed data");if(c-=r[s++],i+a+2>t)throw new Error("Output buffer is not large enough");if(c<0)throw new Error("Invalid compressed data");if(c>=i)throw new Error("Invalid compressed data");do n[i++]=n[c++];while(--a+2)}while(s<e);return n}var A1=p(()=>{"use strict"});function S1(r,t,e="uint8norm"){let n=[];for(let s of Object.keys(r.offset))switch(s){case"x":n.push({name:"POSITION",type:{type:"fixed-size-list",listSize:3,children:[{name:"xyz",type:"float32"}]},metadata:{attribute:"POSITION"}});break;case"y":case"z":break;case"normal_x":n.push({name:"NORMAL",type:{type:"fixed-size-list",listSize:3,children:[{name:"xyz",type:"float32"}]},metadata:{attribute:"NORMAL"}});break;case"normal_y":case"normal_z":break;case"rgb":let i=e==="float16"?"float16":e==="float32"?"float32":"uint8";n.push({name:"COLOR_0",type:{type:"fixed-size-list",listSize:3,children:[{name:"rgb",type:i}]},metadata:{attribute:"COLOR",...e==="float16"?{componentType:"float16"}:{}}});break;default:}return{fields:n,metadata:t}}var B1=p(()=>{"use strict"});function ta(r,t){let e=new TextDecoder().decode(r),n=ac(e),s={};switch(n.data){case"ascii":s=CB(n,e);break;case"binary":s=FB(n,r);break;case"binary_compressed":s=OB(n,r);break;default:throw new Error(`PCD: ${n.data} files are not supported`)}s=DB(s,t?.pcd?.colorFormat);let i=MB(n,s),o=Object.fromEntries([["topology","point-list"],["mode","0"],["boundingBox",JSON.stringify(i.boundingBox)]]),a=S1(n,o,t?.pcd?.colorFormat);return{loader:"pcd",loaderData:n,header:i,schema:a,topology:"point-list",mode:0,attributes:s}}function MB(r,t){if(typeof r.width=="number"&&typeof r.height=="number"){let e=r.width*r.height,n=on(t);if(!n)throw new Error("PCD point cloud is missing positions");return{vertexCount:e,boundingBox:n}}return{vertexCount:r.vertexCount,boundingBox:r.boundingBox}}function DB(r,t="uint8norm"){let e={POSITION:{value:new Float32Array(r.position),size:3}};return r.normal&&r.normal.length>0&&(e.NORMAL={value:new Float32Array(r.normal),size:3}),r.color&&r.color.length>0&&(e.COLOR_0=Fp(r.color,t)),r.intensity&&r.intensity.length>0&&(e.COLOR_0=Fp(r.color,t)),!e.COLOR_0&&r.label&&r.label.length>0&&(e.COLOR_0=Fp(r.label,t)),e}function Fp(r,t){return t==="float16"?{value:ti(r,255),size:3,componentType:"float16"}:t==="float32"?{value:Float32Array.from(r,e=>e/255),size:3}:{value:new Uint8Array(r),size:3}}function ac(r){let t=r.search(/[\r\n]DATA\s(\S*)\s/i),e=/[\r\n]DATA\s(\S*)\s/i.exec(r.substr(t-1)),n={};if(n.data=e&&e[1],e!==null&&(n.headerLen=(e&&e[0].length)+t),n.str=r.substr(0,n.headerLen),n.str=n.str.replace(/\#.*/gi,""),n.version=/VERSION (.*)/i.exec(n.str),n.fields=/FIELDS (.*)/i.exec(n.str),n.size=/SIZE (.*)/i.exec(n.str),n.type=/TYPE (.*)/i.exec(n.str),n.count=/COUNT (.*)/i.exec(n.str),n.width=/WIDTH (.*)/i.exec(n.str),n.height=/HEIGHT (.*)/i.exec(n.str),n.viewpoint=/VIEWPOINT (.*)/i.exec(n.str),n.points=/POINTS (.*)/i.exec(n.str),n.version!==null&&(n.version=parseFloat(n.version[1])),n.fields!==null&&(n.fields=n.fields[1].split(" ")),n.type!==null&&(n.type=n.type[1].split(" ")),n.width!==null&&(n.width=parseInt(n.width[1],10)),n.height!==null&&(n.height=parseInt(n.height[1],10)),n.viewpoint!==null&&(n.viewpoint=n.viewpoint[1]),n.points!==null&&(n.points=parseInt(n.points[1],10)),n.points===null&&typeof n.width=="number"&&typeof n.height=="number"&&(n.points=n.width*n.height),n.size!==null&&(n.size=n.size[1].split(" ").map(i=>parseInt(i,10))),n.count!==null)n.count=n.count[1].split(" ").map(i=>parseInt(i,10));else if(n.count=[],n.fields!==null)for(let i=0;i<n.fields.length;i++)n.count.push(1);n.offset={};let s=0;for(let i=0,o=n.fields.length;i<o;i++)n.data==="ascii"?n.offset[n.fields[i]]=i:(n.offset[n.fields[i]]=s,s+=n.size[i]*n.count[i]);return n.rowSize=s,n}function CB(r,t){let e=[],n=[],s=[],i=[],o=[],a=r.offset,l=t.substr(r.headerLen).split(`
|
|
29
|
+
`);for(let u=0;u<l.length;u++)if(l[u]!==""){let f=l[u].split(" ");if(a.x!==void 0&&(e.push(parseFloat(f[a.x])),e.push(parseFloat(f[a.y])),e.push(parseFloat(f[a.z]))),a.rgb!==void 0){let h=parseFloat(f[a.rgb]),m=new Float32Array([h]),y=new DataView(m.buffer,0);s.push(y.getUint8(0)),s.push(y.getUint8(1)),s.push(y.getUint8(2))}a.normal_x!==void 0&&(n.push(parseFloat(f[a.normal_x])),n.push(parseFloat(f[a.normal_y])),n.push(parseFloat(f[a.normal_z]))),a.intensity!==void 0&&i.push(parseFloat(f[a.intensity])),a.label!==void 0&&o.push(parseInt(f[a.label]))}return{position:e,normal:n,color:s}}function FB(r,t){let e=[],n=[],s=[],i=[],o=[],a=new DataView(t,r.headerLen),c=r.offset;for(let l=0,u=0;l<r.points;l++,u+=r.rowSize)c.x!==void 0&&(e.push(a.getFloat32(u+c.x,we)),e.push(a.getFloat32(u+c.y,we)),e.push(a.getFloat32(u+c.z,we))),c.rgb!==void 0&&(s.push(a.getUint8(u+c.rgb+0)),s.push(a.getUint8(u+c.rgb+1)),s.push(a.getUint8(u+c.rgb+2))),c.normal_x!==void 0&&(n.push(a.getFloat32(u+c.normal_x,we)),n.push(a.getFloat32(u+c.normal_y,we)),n.push(a.getFloat32(u+c.normal_z,we))),c.intensity!==void 0&&i.push(a.getFloat32(u+c.intensity,we)),c.label!==void 0&&o.push(a.getInt32(u+c.label,we));return{position:e,normal:n,color:s,intensity:i,label:o}}function OB(r,t){let e=[],n=[],s=[],i=[],o=[],a=new Uint32Array(t.slice(r.headerLen,r.headerLen+8)),c=a[0],l=a[1],u=v1(new Uint8Array(t,r.headerLen+8,c),l),f=new DataView(u.buffer),h=r.offset;for(let m=0;m<r.points;m++){if(h.x!==void 0&&(e.push(f.getFloat32(r.points*h.x+r.size[0]*m,we)),e.push(f.getFloat32(r.points*h.y+r.size[1]*m,we)),e.push(f.getFloat32(r.points*h.z+r.size[2]*m,we))),h.rgb!==void 0&&(s.push(f.getUint8(r.points*h.rgb+r.size[3]*m+0)),s.push(f.getUint8(r.points*h.rgb+r.size[3]*m+1)),s.push(f.getUint8(r.points*h.rgb+r.size[3]*m+2))),h.normal_x!==void 0&&(n.push(f.getFloat32(r.points*h.normal_x+r.size[4]*m,we)),n.push(f.getFloat32(r.points*h.normal_y+r.size[5]*m,we)),n.push(f.getFloat32(r.points*h.normal_z+r.size[6]*m,we))),h.intensity!==void 0){let y=r.fields.indexOf("intensity");i.push(f.getFloat32(r.points*h.intensity+r.size[y]*m,we))}if(h.label!==void 0){let y=r.fields.indexOf("label");o.push(f.getInt32(r.points*h.label+r.size[y]*m,we))}}return{position:e,normal:n,color:s,intensity:i,label:o}}var we,I1=p(()=>{"use strict";Vs();or();A1();B1();we=!0;});var _1,L1=p(()=>{"use strict";_1={name:"PCD (Point Cloud Data)",id:"pcd",module:"pointclouds",encoding:"text",format:"pcd",extensions:["pcd"],mimeTypes:["text/plain"],category:"pointcloud",text:!0,binary:!0}});async function UB(){let{PCDLoaderWithParser:r}=await Promise.resolve().then(()=>(Ep(),Op));return r}var EB,T1,M1=p(()=>{"use strict";L1();Gs();EB="5.0.0-beta.4";T1={..._1,dataType:null,batchType:null,version:EB,worker:!0,workerInBatches:!0,serializeWorkerResult:re,options:{pcd:{shape:"arrow-table",colorFormat:"uint8norm"}},preload:UB}});function D1(r,t){let e=Ee(r,"arrow-table");return t?.pcd?.shape==="mesh"?Np(e,r):{...e,loader:r.loader,loaderData:r.loaderData}}function PB(r){let t=r?.batchSize??r?.core?.batchSize;return typeof t=="number"?t:void 0}function*kB(r,t,e){let n=new TextDecoder().decode(r),s=ac(n),i=n.slice(s.headerLen).split(/\r?\n/).filter(a=>a.trim().length>0),o=e||i.length||1;for(let a=0;a<i.length;a+=o){let c=i.slice(a,a+o),l=`${C1(s,c.length)}${c.join(`
|
|
30
30
|
`)}
|
|
31
31
|
`;yield Up(ta(new TextEncoder().encode(l).buffer,t),t)}}function*zB(r,t,e){let n=new TextDecoder().decode(r),s=ac(n),i=e||s.points||1,o=new Uint8Array(r);for(let a=0;a<s.points;a+=i){let c=Math.min(i,s.points-a),l=new TextEncoder().encode(C1(s,c)),u=s.headerLen+a*s.rowSize,f=c*s.rowSize,h=new Uint8Array(l.length+f);h.set(l,0),h.set(o.subarray(u,u+f),l.length),yield Up(ta(h.buffer,t),t)}}function Up(r,t){let e=Ee(r,"arrow-table");return t?.pcd?.shape==="mesh"?Np(e,r):ic({...e,loader:r.loader,loaderData:r.loaderData})}function Np(r,t){return{...ee(r),loader:t.loader,loaderData:t.loaderData}}function C1(r,t){let e=r.str.split(/\r?\n/).filter(n=>n.trim().length>0).map(n=>/^WIDTH\s+/i.test(n)?`WIDTH ${t}`:/^HEIGHT\s+/i.test(n)?"HEIGHT 1":/^POINTS\s+/i.test(n)?`POINTS ${t}`:n);if(!e.some(n=>/^POINTS\s+/i.test(n))){let n=e.findIndex(s=>/^DATA\s+/i.test(s));e.splice(n>=0?n:e.length,0,`POINTS ${t}`)}return`${e.join(`
|
|
32
32
|
`)}
|
|
@@ -38,7 +38,7 @@ return true;`)}function cv(r){return typeof r!="bigint"?Tr(r):`${Tr(r)}n`}var h0
|
|
|
38
38
|
`)}
|
|
39
39
|
`,e);return uc(s)}function rw(r,t,e,n,s){let i=sw(r,n,s),o=new TextEncoder().encode(i),a=new Uint8Array(o.length+e);a.set(o,0);let c=o.length;for(let u of t)a.set(u,c),c+=u.length;let l=lc(qu(a),s);return uc(l)}function t_(r,t,e){let n=new DataView(r.buffer,r.byteOffset,r.byteLength),s=0;for(let i of t.properties)if(i.type==="list"){let o=ju(i.countType);if(s+o>r.length)return null;let a=e_(n,s,i.countType,e);s+=o;let c=a*ju(i.itemType);if(s+c>r.length)return null;s+=c}else{let o=ju(i.type);if(s+o>r.length)return null;s+=o}return s}function e_(r,t,e,n){switch(e){case"int8":case"char":return r.getInt8(t);case"uint8":case"uchar":return r.getUint8(t);case"int16":case"short":return r.getInt16(t,n);case"uint16":case"ushort":return r.getUint16(t,n);case"int32":case"int":return r.getInt32(t,n);case"uint32":case"uint":return r.getUint32(t,n);case"float32":case"float":return r.getFloat32(t,n);case"float64":case"double":return r.getFloat64(t,n);default:throw new Error(e)}}function sw(r,t,e){let n=["ply",`format ${r.format} ${r.version||"1.0"}`],s=e?.pointCloud?r.elements.slice(0,1):r.elements;for(let i of r.comments)n.push(`comment ${i}`);for(let i of s){n.push(`element ${i.name} ${i.name==="vertex"?t:i.count}`);for(let o of i.properties)n.push(o.type==="list"?`property list ${o.countType} ${o.itemType} ${o.name}`:`property ${o.type} ${o.name}`)}return n.push("end_header"),`${n.join(`
|
|
40
40
|
`)}
|
|
41
|
-
`}async function*r_(r,t){for(t.length>0&&(yield qu(t));;){let{value:e,done:n}=await r.next();if(n)break;yield qu($u(e))}}function Hp(r){let t=r?.batchSize;return typeof t=="number"?t:WI}function n_(r){return r.properties.reduce((t,e)=>t+ju(e.type),0)}function ju(r){switch(r){case"int8":case"uint8":case"char":case"uchar":return 1;case"int16":case"uint16":case"short":case"ushort":return 2;case"int32":case"uint32":case"int":case"uint":case"float32":case"float":return 4;case"float64":case"double":return 8;default:throw new Error(r)}}function s_(r){let t=new TextEncoder().encode(YI),e=r.length-t.length;for(let n=0;n<=e;n++){let s=!0;for(let i=0;i<t.length;i++)if(r[n+i]!==t[i]){s=!1;break}if(s){let i=n+t.length;return i===r.length||r[i]===13&&i+1===r.length?-1:(r[i]===13&&r[i+1]===10?i+=2:i<r.length&&i_(r[i])&&(i+=1),i)}}return-1}function i_(r){return r===10||r===13||r===9||r===32}function $u(r){return ArrayBuffer.isView(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r)}function qu(r){let t=new Uint8Array(r.byteLength);return t.set(r),t.buffer}function Xp(r){let t=r.reduce((s,i)=>s+i.length,0),e=new Uint8Array(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}async function o_(r,t){let e,n={comments:[],elements:[]};return await wd(r,s=>{if(s=s.trim(),s==="end_header")return!0;if(s==="")return!1;let i=s.split(/\s+/),o=i.shift();switch(s=i.join(" "),o){case"ply":break;case"format":n.format=i[0],n.version=i[1];break;case"comment":n.comments.push(s);break;case"element":e&&n.elements.push(e),e={name:i[0],count:parseInt(i[1],10),properties:[]};break;case"property":let a=a_(i,t.propertyNameMapping);e?.properties.push(a);break;default:console.log("unhandled",o,i)}return!1}),e&&n.elements.push(e),n}function a_(r,t){let e=r[0];return e==="list"?{type:e,name:r[3],countType:r[1],itemType:r[2]}:{type:e,name:r[1]}}async function c_(r,t){let e={indices:[],vertices:[],normals:[],uvs:[],colors:[]},n=0,s=0;for await(let i of r)if(i=i.trim(),i!==""){s>=t.elements[n].count&&(n++,s=0);let o=l_(t.elements[n].properties,i);u_(e,t.elements[n].name,o),s++}return e}function Yp(r,t){switch(t){case"char":case"uchar":case"short":case"ushort":case"int":case"uint":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":return parseInt(r,10);case"float":case"double":case"float32":case"float64":return parseFloat(r);default:throw new Error(t)}}function l_(r,t){let e=t.split(/\s+/),n={};for(let s=0;s<r.length;s++)if(r[s].type==="list"){let i=[],o=Yp(e.shift(),r[s].countType);for(let a=0;a<o;a++)i.push(Yp(e.shift(),r[s].itemType));n[r[s].name]=i}else n[r[s].name]=Yp(e.shift(),r[s].type);return n}function u_(r,t,e={}){switch(t){case"vertex":r.vertices.push(e.x,e.y,e.z),"nx"in e&&"ny"in e&&"nz"in e&&r.normals.push(e.nx,e.ny,e.nz),"s"in e&&"t"in e&&r.uvs.push(e.s,e.t),"red"in e&&"green"in e&&"blue"in e&&r.colors.push(e.red,e.green,e.blue);break;case"face":let n=e.vertex_indices||e.vertex_index;n.length===3?r.indices.push(n[0],n[1],n[2]):n.length===4&&(r.indices.push(n[0],n[1],n[3]),r.indices.push(n[1],n[2],n[3]));break;default:break}}var WI,YI,iw=p(()=>{"use strict";Zo();kp();Vu();Wp();WI=65536,YI="end_header"});var ow,aw=p(()=>{"use strict";ow={name:"PLY",id:"ply",module:"pointclouds",encoding:"text",format:"ply",extensions:["ply"],mimeTypes:["text/plain","application/octet-stream"],text:!0,binary:!0,tests:["ply"]}});async function h_(){let{PLYLoaderWithParser:r}=await Promise.resolve().then(()=>(Jp(),Kp));return r}var f_,cw,lw=p(()=>{"use strict";aw();Gs();f_="5.0.0-beta.2";cw={dataType:null,batchType:null,...ow,version:f_,worker:!0,workerInBatches:!0,serializeWorkerResult:re,options:{ply:{shape:"arrow-table",colorFormat:"uint8norm"}},preload:h_}});function uw(r,t){let e=Ee(r,"arrow-table");return Wu(e,t,r.loaderData)}function Qp(r,t){if(t?.ply?._useLegacyParser)return uw(V1(r,t?.ply),t);let e=G1(r,t?.ply);if(e)return Wu(e,t,zn(r,t?.ply));let n=lc(r,t?.ply);return Wu(uc(n),t,n.header)}function Wu(r,t,e){let n=e||r.loaderData||{comments:[],elements:[]},s=t?.ply?.shape==="arrow-table"?{...r,loader:"ply",loaderData:n}:{...ee(r),loader:"ply",loaderData:n},i=t?.ply?.colorFormat||"uint8norm";if(i==="uint8norm")return s;let o=s,a=m_(tm(o)?ee(o):o,i);return t?.ply?.shape==="arrow-table"?{...Ee(a,"arrow-table"),loader:"ply",loaderData:n}:a}function m_(r,t){let e=r.attributes.COLOR_0;if(!e)return r;let n=e.value instanceof Uint16Array?65535:255,s=t==="float16"?ti(e.value,n):sa(e.value,n),i={...r.attributes};for(let[o,a]of Object.entries(i))a.value===e.value&&(i[o]={...a,value:s,normalized:!1,...t==="float16"?{componentType:"float16"}:{}});return{...r,attributes:i,schema:Gi(i,r.schema.metadata)}}function tm(r){return"shape"in r&&r.shape==="arrow-table"}function fw(r,t){let e=Po(r);return t?.ply?.shape==="mesh"?{...ee(e),loader:"ply",loaderData:e.loaderData}:e}function y_(r,t){return fw(r,t)}var q8,d_,p_,hw=p(()=>{"use strict";Zo();Vs();Gs();or();Vu();Wp();iw();lw();({preload:q8,...d_}=cw);p_={...d_,parse:async(r,t)=>Qp(r,t),parseTextSync:(r,t)=>Qp(r,t),parseSync:(r,t)=>Qp(r,t),parseInBatches:async function*(r,t){let e={...t?.ply,batchSize:t?.batchSize??t?.core?.batchSize};for await(let n of nw(r,e)){let s=tm(n)?Wu(n,t):uw(n,t);yield tm(s)?ic(s):s}},serializeWorkerResult:re,deserializeWorkerResult:fw,serializeWorkerBatch:re,deserializeWorkerBatch:y_}});var Kp={};Re(Kp,{PLYLoaderWithParser:()=>p_});var Jp=p(()=>{"use strict";hw()});var I_={};Re(I_,{LASFormat:()=>Uo,LASLoader:()=>Ip,LASWorkerLoader:()=>u1,LASWriter:()=>p1,PCDFormat:()=>Qo,PCDLoader:()=>Rp,PCDWorkerLoader:()=>E1,PCDWriter:()=>N1,PLYFormat:()=>ea,PLYLoader:()=>em,PLYWorkerLoader:()=>dw,PLYWriter:()=>mw});var Uo={name:"LAS",id:"las",module:"pointclouds",encoding:"binary",format:"las",extensions:["las","laz"],mimeTypes:["application/octet-stream"],text:!1,binary:!0,tests:["LASF"]};var rA=typeof __VERSION__<"u"?__VERSION__:"latest",nA="arrow-table";var vg={...Uo,dataType:null,batchType:null,version:rA,worker:!1,options:{las:{shape:nA,fp64:!1,colorDepth:8,colorFormat:"uint8norm",columns:void 0,extraBytes:"raw",recoverMissingChunkTable:!1,compatibilityMode:"auto"}}};async function j2(){let{LASLoaderWithParser:r}=await Promise.resolve().then(()=>(l1(),c1));return r}var Ip={...vg,worker:!0,workerInBatches:!0,preload:j2},u1=Ip;Zo();or();var q2=typeof __VERSION__<"u"?__VERSION__:"latest",$2=227,W2=375,Y2=393,Uu=54,Mp=192,Z2=5e4,H2=4294967295,Dp=15,X2={0:20,1:28,2:26,3:34,4:57,5:63,6:30,7:36,8:38,9:59,10:67},p1={...Uo,dataType:null,batchType:null,version:q2,extensions:["las","laz"],options:{las:{}},encode:async(r,t)=>_p(r,t),encodeSync:_p,encodeInBatches:async function*(r,t){let e=[];for await(let n of r)e.push(n);yield _p(lB(e),t)}};function _p(r,t={}){let e=t.las?.format||"las",n=t.las?.colorDepth;if(n!==void 0&&n!=="auto"&&n!==8&&n!==16)throw new Error("LASWriter: invalid source color depth");let s=aB(r),i=g1(s,"POSITION");fB(i);let o=i.value.length/i.size;dB(s,o);let a=s.attributes.COLOR_0,c=s.attributes.intensity,l=s.attributes.classification,u=s.attributes.nir,f=tB(s,t,o),h=s.attributes.gpsTime,m=s.attributes.scanAngle,y=s.attributes.userData,g=s.attributes.pointSourceId,x=s.attributes.returnNumber,B=s.attributes.numberOfReturns,q=s.attributes.scannerChannel,M=s.attributes.scanDirectionFlag,b=s.attributes.edgeOfFlightLine,C=s.attributes.synthetic,_=s.attributes.keyPoint,$=s.attributes.withheld,X=s.attributes.overlap,ft=s.attributes.wavePacketDescriptorIndex,dt=s.attributes.wavePacketOffset,Bt=s.attributes.wavePacketSize,se=s.attributes.wavePacketReturnPoint,rt=s.attributes.wavePacketVector,tt=_B(i,o),Ye=SB(x,o),Ne=LB(s,t),Ze=TB(s,t,tt);hB(i,o,Ne,Ze);let xt=t.las?.pointDataRecordFormat??xB(t,a);pB(s,o,xt);let Gn=X2[xt];if(!Gn)throw new Error(`LASWriter: unsupported point data record format ${xt}`);let Qs=Gn+f.reduce((hn,ro)=>hn+ro.byteLength,0);if(Qs>65535)throw new Error(`LASWriter: point data record length ${Qs} exceeds the LAS limit`);iB(f);let wt=t.las?.version||(xt>=6?"1.4":"1.2"),pt=wt==="1.5"?Y2:wt==="1.4"?W2:$2;J2(wt,xt,t);let un=sB(h,o);if(wt==="1.5"&&t.las?.timeOffset&&!h)throw new Error("LASWriter: LAS 1.5 timeOffset requires a GPS time attribute");e==="laz"&&oB(wt,xt,t.las?.chunkSize),K2(wt,xt);let qr=new Uint8Array(o*Qs),fn=new DataView(qr.buffer);for(let hn=0;hn<o;hn++){let ro=hn*Qs;fn.setInt32(ro,Math.round((jr(i,hn,0)-Ze[0])/Ne[0]),!0),fn.setInt32(ro+4,Math.round((jr(i,hn,1)-Ze[1])/Ne[1]),!0),fn.setInt32(ro+8,Math.round((jr(i,hn,2)-Ze[2])/Ne[2]),!0),mB(fn,ro,hn,xt,Gn,{intensityAttribute:c,classificationAttribute:l,nirAttribute:u,colorAttribute:a,colorDepth:n,gpsTimeAttribute:h,scanAngleAttribute:m,userDataAttribute:y,pointSourceIdAttribute:g,returnNumberAttribute:x,numberOfReturnsAttribute:B,scannerChannelAttribute:q,scanDirectionFlagAttribute:M,edgeOfFlightLineAttribute:b,syntheticAttribute:C,keyPointAttribute:_,withheldAttribute:$,overlapAttribute:X,waveformDescriptorAttribute:ft,waveformOffsetAttribute:dt,waveformSizeAttribute:Bt,waveformReturnPointAttribute:se,waveformVectorAttribute:rt,extraByteFields:f})}let vr={vertexCount:o,boundingBox:tt,scale:Ne,offset:Ze,version:wt,headerLength:pt,pointDataRecordFormat:xt,pointDataRecordLength:Qs,returnCounts:Ye,maxGpsTime:un.maximum,minGpsTime:un.minimum,timeOffset:t.las?.timeOffset||0,hasGpsTime:!!h,hasWkt:!!t.las?.wkt};if(e==="laz")return Q2(qr,vr,t.las?.chunkSize,t.las?.variableChunkTable,f,t);let Ar=m1(f,t),eo=pt+Ar.byteLength,Yu=new ArrayBuffer(eo+qr.byteLength);w1(new DataView(Yu),{...vr,pointDataOffset:eo,vlrCount:y1(f,t)});let nm=new Uint8Array(Yu);return nm.set(Ar,pt),nm.set(qr,eo),Yu}function K2(r,t){let n={0:"1.0",1:"1.1",2:"1.2",3:"1.2"}[t];if(n&&r<n)throw new Error(`LASWriter: point data record format ${t} requires LAS ${n} or newer; received ${r}`);if(t>=4&&t<=5&&!["1.3","1.4","1.5"].includes(r))throw new Error(`LASWriter: point data record format ${t} requires LAS 1.3; received ${r}`);if(t>=6&&!["1.4","1.5"].includes(r))throw new Error(`LASWriter: point data record format ${t} requires LAS 1.4; received ${r}`)}function J2(r,t,e){if(r==="1.5"){if(t<6||t>10)throw new Error("LASWriter: LAS 1.5 output requires point data record format 6-10");if(!e.las?.wkt?.trim())throw new Error("LASWriter: LAS 1.5 output requires las.wkt");let n=e.las?.timeOffset??0;if(!Number.isInteger(n)||n<0||n>65535)throw new Error("LASWriter: LAS 1.5 timeOffset must be an unsigned 16-bit integer")}}function Q2(r,t,e,n=!1,s=[],i={}){let o=e||Z2,a=cp({pointDataRecordFormat:t.pointDataRecordFormat,pointDataRecordLength:t.pointDataRecordLength,chunkSize:n?H2:o}),c=m1(s,i),l=t.headerLength+c.byteLength+a.byteLength,u=[],f=[];for(let M=0;M<t.vertexCount;M+=o){let b=Math.min(o,t.vertexCount-M),C=M*t.pointDataRecordLength,_=op(r.subarray(C,C+b*t.pointDataRecordLength),{pointDataRecordFormat:t.pointDataRecordFormat,pointDataRecordLength:t.pointDataRecordLength,pointCount:b,point14ItemVersion:3,rgb14ItemVersion:3,byte14ItemVersion:3});u.push(_),f.push({pointCount:b,byteLength:_.byteLength})}let h=u.reduce((M,b)=>M+b.byteLength,0),m=ap(f,{variable:n}),y=l+8+h,g=new ArrayBuffer(y+8+m.byteLength),x=new Uint8Array(g),B=new DataView(g);w1(B,{...t,pointDataOffset:l,vlrCount:y1(s,i)+1,compressed:!0}),x.set(c,t.headerLength),x.set(a,t.headerLength+c.byteLength),Cp(B,l,y);let q=l+8;for(let M of u)x.set(M,q),q+=M.byteLength;return B.setUint32(y,0,!0),B.setUint32(y+4,f.length,!0),x.set(m,y+8),g}function tB(r,t,e){let n=t.las?.extraBytes||[],s=new Set;return n.map(i=>{if(s.has(i.attribute))throw new Error(`LASWriter: duplicate Extra Bytes attribute ${i.attribute}`);s.add(i.attribute);let o=r.attributes[i.attribute];if(!o)throw new Error(`LASWriter: Extra Bytes attribute ${i.attribute} is missing`);if(![1,3].includes(o.size))throw new Error(`LASWriter: Extra Bytes attribute ${i.attribute} must have size 1 or 3`);if(o.value.length<e*o.size)throw new Error(`LASWriter: Extra Bytes attribute ${i.attribute} is too short`);b1(i.attribute,o);let a=eB(o.value,o.size);return{...i,meshAttribute:o,dataType:a,byteLength:rB(a,o.size),componentCount:o.size}})}function eB(r,t){let e=0;if(r instanceof Uint8Array?e=1:r instanceof Int8Array?e=2:r instanceof Uint16Array?e=3:r instanceof Int16Array?e=4:r instanceof Uint32Array?e=5:r instanceof Int32Array?e=6:r instanceof BigUint64Array?e=7:r instanceof BigInt64Array?e=8:r instanceof Float32Array?e=9:r instanceof Float64Array&&(e=10),e)return e+(t===3?20:0);throw new Error("LASWriter: Extra Bytes attributes require a supported typed array")}function rB(r,t){let e=r>20?r-20:r>10?r-10:r;return(e<=2?1:e<=4?2:e<=6||e===9?4:8)*t}function nB(r){if(r.length===0)return new Uint8Array(0);let t=new Uint8Array(r.length*Mp),e=new DataView(t.buffer),n=0;for(let o of r)e.setUint8(n+2,o.dataType),kn(e,n+4,o.name||o.attribute,32),kn(e,n+160,o.description||"",32),n+=Mp;let s=new Uint8Array(Uu+t.byteLength),i=new DataView(s.buffer);return kn(i,2,"LASF_Spec",16),i.setUint16(18,4,!0),i.setUint16(20,t.byteLength,!0),kn(i,22,"Extra Bytes",32),s.set(t,Uu),s}function m1(r,t){let e=[];t.las?.wktMathTransform&&e.push(f1(2111,"WKT Math Transform",t.las.wktMathTransform)),t.las?.wkt&&e.push(f1(2112,"WKT Coordinate System",t.las.wkt));let n=nB(r);n.byteLength&&e.push(n);let s=e.reduce((a,c)=>a+c.byteLength,0),i=new Uint8Array(s),o=0;for(let a of e)i.set(a,o),o+=a.byteLength;return i}function f1(r,t,e){let n=new TextEncoder().encode(`${e}\0`);if(n.byteLength>65535)throw new Error(`LASWriter: WKT VLR ${r} exceeds the LAS VLR size limit`);let s=new Uint8Array(Uu+n.byteLength),i=new DataView(s.buffer);return kn(i,2,"LASF_Projection",16),i.setUint16(18,r,!0),i.setUint16(20,n.byteLength,!0),kn(i,22,t,32),s.set(n,Uu),s}function y1(r,t){return(t.las?.wktMathTransform?1:0)+(t.las?.wkt?1:0)+(r.length?1:0)}function sB(r,t){if(!r)return{minimum:0,maximum:0};let e=Number(r.value[0]),n=e;for(let s=1;s<t;s++){let i=Number(r.value[s*r.size]);e=Math.min(e,i),n=Math.max(n,i)}return{minimum:e,maximum:n}}function iB(r){let t=r.length*Mp;if(t>65535)throw new Error(`LASWriter: Extra Bytes VLR payload ${t} exceeds the LAS limit`)}function oB(r,t,e){if(t===1&&!["1.1","1.2","1.3","1.4","1.5"].includes(r))throw new Error(`LASWriter: LAZ PDRF 1 output requires LAS 1.1 or newer; received ${r}`);if(t>=2&&t<=3&&!["1.2","1.3","1.4","1.5"].includes(r))throw new Error(`LASWriter: LAZ PDRF ${t} output requires LAS 1.2 or newer; received ${r}`);if(t>=4&&t<=5&&!["1.3","1.4","1.5"].includes(r))throw new Error(`LASWriter: LAZ PDRF ${t} requires LAS 1.3 or newer; received ${r}`);if(t>=6&&!["1.4","1.5"].includes(r))throw new Error(`LASWriter: LAZ output requires LAS 1.4; received ${r}`);if(![0,1,2,3,4,5,6,7,8,9,10].includes(t))throw new Error(`LASWriter: LAZ output currently supports point data record formats 0-10; received ${t}`);if(e!==void 0&&(!Number.isInteger(e)||e<=0||e>4294967295))throw new Error(`LASWriter: invalid LAZ chunk size ${e}`)}function aB(r){return"shape"in r&&r.shape==="arrow-table"?ee(r):r}function cB(r){return"shape"in r&&r.shape==="arrow-table"?r:Ee(r,"arrow-table")}function lB(r){if(r.length===0)throw new Error("LASWriter: at least one input batch is required");if(r.length===1)return r[0];let t=r.map(s=>ee(cB(s))),e=t[0],n={};uB(t);for(let s of Object.keys(e.attributes)){let i=e.attributes[s],o=t.map(f=>f.attributes[s]?.value);if(o.some(f=>!f))continue;let a=o.reduce((f,h)=>f+h.length,0),c=i.value.constructor,l=new c(a),u=0;for(let f of o)l.set(f,u),u+=f.length;n[s]={...i,value:l}}return{...e,attributes:n,header:{...e.header,vertexCount:g1({...e,attributes:n},"POSITION").value.length/3}}}function uB(r){let t=Object.keys(r[0].attributes);for(let e of r.slice(1)){if(Object.keys(e.attributes).length!==t.length||t.some(s=>!e.attributes[s]))throw new Error("LASWriter: encodeInBatches requires consistent attribute names");for(let s of t){let i=r[0].attributes[s],o=e.attributes[s];if(o.size!==i.size||o.value.constructor!==i.value.constructor)throw new Error(`LASWriter: encodeInBatches requires a consistent ${s} layout`)}}}function g1(r,t){let e=r.attributes[t];if(!e)throw new Error(`LASWriter: ${t} attribute is required`);return e}function fB(r){if(r.size!==3)throw new Error("LASWriter: POSITION attribute must have size 3");if(r.value.length%r.size!==0)throw new Error("LASWriter: POSITION attribute length must be divisible by its size")}function hB(r,t,e,n){for(let s=0;s<3;s++){if(!Number.isFinite(e[s])||e[s]<=0)throw new Error("LASWriter: coordinate scale must be finite and positive");if(!Number.isFinite(n[s]))throw new Error("LASWriter: coordinate offset must be finite")}for(let s=0;s<t;s++)for(let i=0;i<3;i++){let o=r.value[s*r.size+i];if(!Number.isFinite(o))throw new Error("LASWriter: POSITION values must be finite");let a=Math.round((o-n[i])/e[i]);if(a<-2147483648||a>2147483647)throw new Error("LASWriter: encoded coordinate exceeds the signed 32-bit LAS range")}}function dB(r,t){let e=["intensity","classification","gpsTime","scanAngle","userData","pointSourceId","returnNumber","numberOfReturns","scannerChannel","scanDirectionFlag","edgeOfFlightLine","synthetic","keyPoint","withheld","overlap","nir","wavePacketDescriptorIndex","wavePacketOffset","wavePacketSize","wavePacketReturnPoint"];for(let i of e){let o=r.attributes[i];o&&Lp(i,o,t,1)}let n=r.attributes.COLOR_0;n&&Lp("COLOR_0",n,t,3,!1);let s=r.attributes.wavePacketVector;s&&Lp("wavePacketVector",s,t,3)}function pB(r,t,e){let n=e>=6?15:5,s=r.attributes.returnNumber,i=r.attributes.numberOfReturns;for(let o=0;o<t;o++){let a=cr(s,o,1),c=cr(i,o,1);if(a<1||a>n)throw new Error(`LASWriter: returnNumber must be between 1 and ${n} for point data record format ${e}`);if(c<1||c>n)throw new Error(`LASWriter: numberOfReturns must be between 1 and ${n} for point data record format ${e}`);if(a>c)throw new Error("LASWriter: returnNumber cannot exceed numberOfReturns")}}function Lp(r,t,e,n,s=!0){if(n===1?t.size!==1:t.size<n)throw new Error(`LASWriter: ${r} attribute must have size ${n}`);if(b1(r,t),s&&t.value.length<e*t.size)throw new Error(`LASWriter: ${r} attribute is too short`);if(!s&&t.value.length<t.size)throw new Error(`LASWriter: ${r} attribute is too short`)}function b1(r,t){for(let e of t.value)if(!Number.isFinite(Number(e)))throw new Error(`LASWriter: ${r} attribute must contain finite values`)}function w1(r,t){let[e,n]=t.version.split(".").map(Number);kn(r,0,"LASF",4),r.setUint8(24,e),r.setUint8(25,n),kn(r,26,"loaders.gl",32),kn(r,58,"loaders.gl",32),r.setUint16(94,t.headerLength,!0),r.setUint32(96,t.pointDataOffset,!0),r.setUint32(100,t.vlrCount||0,!0),r.setUint8(104,t.pointDataRecordFormat|(t.compressed?128:0)),r.setUint16(105,t.pointDataRecordLength,!0);let s=t.version==="1.4"||t.version==="1.5";r.setUint32(107,s?0:t.vertexCount,!0);for(let i=0;i<5;i++)r.setUint32(111+i*4,s?0:t.returnCounts[i],!0);if(t.version==="1.5"?r.setUint16(6,16|(t.hasGpsTime?1:0)|(t.timeOffset?64:0),!0):t.version==="1.4"&&t.hasWkt&&r.setUint16(6,16,!0),r.setFloat64(131,t.scale[0],!0),r.setFloat64(139,t.scale[1],!0),r.setFloat64(147,t.scale[2],!0),r.setFloat64(155,t.offset[0],!0),r.setFloat64(163,t.offset[1],!0),r.setFloat64(171,t.offset[2],!0),r.setFloat64(179,t.boundingBox[1][0],!0),r.setFloat64(187,t.boundingBox[0][0],!0),r.setFloat64(195,t.boundingBox[1][1],!0),r.setFloat64(203,t.boundingBox[0][1],!0),r.setFloat64(211,t.boundingBox[1][2],!0),r.setFloat64(219,t.boundingBox[0][2],!0),s){Cp(r,247,t.vertexCount);for(let i=0;i<Dp;i++)Cp(r,255+i*8,t.returnCounts[i])}t.version==="1.5"&&(r.setFloat64(375,t.maxGpsTime,!0),r.setFloat64(383,t.minGpsTime,!0),r.setUint16(391,t.timeOffset,!0))}function mB(r,t,e,n,s,i){if(r.setUint16(t+12,Eu(i.intensityAttribute,e),!0),n<=5){let o=cr(i.returnNumberAttribute,e,1)&7,a=cr(i.numberOfReturnsAttribute,e,1)&7;r.setUint8(t+14,o|a<<3),r.setUint8(t+15,cr(i.classificationAttribute,e)&31),r.setInt8(t+16,d1(i.scanAngleAttribute,e)),r.setUint8(t+17,cr(i.userDataAttribute,e)),r.setUint16(t+18,Eu(i.pointSourceIdAttribute,e),!0),(n===1||n===3||n>=4)&&r.setFloat64(t+20,Nu(i.gpsTimeAttribute,e),!0),(n===4||n===5)&&h1(r,t+(n===4?28:34),e,i)}else{let o=cr(i.returnNumberAttribute,e,1)&15,a=cr(i.numberOfReturnsAttribute,e,1)&15,c=cr(i.scannerChannelAttribute,e)&3,l=o|a<<4,u=(Ko(i.syntheticAttribute,e)?1:0)|(Ko(i.keyPointAttribute,e)?2:0)|(Ko(i.withheldAttribute,e)?4:0)|(Ko(i.overlapAttribute,e)?8:0)|c<<4|(Ko(i.scanDirectionFlagAttribute,e)?64:0)|(Ko(i.edgeOfFlightLineAttribute,e)?128:0);r.setUint8(t+14,l),r.setUint8(t+15,u),r.setUint8(t+16,cr(i.classificationAttribute,e)),r.setUint8(t+17,cr(i.userDataAttribute,e)),r.setInt16(t+18,d1(i.scanAngleAttribute,e),!0),r.setUint16(t+20,Eu(i.pointSourceIdAttribute,e),!0),r.setFloat64(t+22,Nu(i.gpsTimeAttribute,e),!0),(n===9||n===10)&&h1(r,t+(n===9?30:38),e,i)}bB(r,t,e,n,i.colorAttribute,i.colorDepth),(n===8||n===10)&&r.setUint16(t+36,Eu(i.nirAttribute,e),!0),yB(r,t,e,s,i.extraByteFields)}function h1(r,t,e,n){r.setUint8(t,cr(n.waveformDescriptorAttribute,e)),r.setBigUint64(t+1,AB(n.waveformOffsetAttribute,e),!0),r.setUint32(t+9,vB(n.waveformSizeAttribute,e),!0),r.setFloat32(t+13,Nu(n.waveformReturnPointAttribute,e),!0);for(let s=0;s<3;s++)r.setFloat32(t+17+s*4,jr(n.waveformVectorAttribute,e,s),!0)}function yB(r,t,e,n,s){let i=t+n;for(let o of s)for(let a=0;a<o.componentCount;a++)gB(r,i,e,a,o),i+=o.byteLength/o.componentCount}function gB(r,t,e,n,s){let i=s.meshAttribute.value[e*s.componentCount+n];switch(s.dataType>20?s.dataType-20:s.dataType>10?s.dataType-10:s.dataType){case 1:r.setUint8(t,Number(i));break;case 2:r.setInt8(t,Number(i));break;case 3:r.setUint16(t,Number(i),!0);break;case 4:r.setInt16(t,Number(i),!0);break;case 5:r.setUint32(t,Number(i),!0);break;case 6:r.setInt32(t,Number(i),!0);break;case 7:r.setBigUint64(t,BigInt(i),!0);break;case 8:r.setBigInt64(t,BigInt(i),!0);break;case 9:r.setFloat32(t,Number(i),!0);break;case 10:r.setFloat64(t,Number(i),!0);break;default:throw new Error(`LASWriter: unsupported Extra Bytes data type ${s.dataType}`)}}function bB(r,t,e,n,s,i){let o=wB(n);o<0||!s||(r.setUint16(t+o,Tp(s,e,0,i),!0),r.setUint16(t+o+2,Tp(s,e,1,i),!0),r.setUint16(t+o+4,Tp(s,e,2,i),!0))}function wB(r){switch(r){case 2:return 20;case 3:return 28;case 5:return 57;case 7:case 8:case 10:return 30;default:return-1}}function xB(r,t){return r.las?.format==="laz"||r.las?.version==="1.4"?t?7:6:t?2:0}function Cp(r,t,e){r.setUint32(t,e>>>0,!0),r.setUint32(t+4,Math.floor(e/2**32),!0)}function kn(r,t,e,n){if(/[^\x00-\x7f]/.test(e))throw new Error("LASWriter fixed-width text must be ASCII");for(let s=0;s<n;s++)r.setUint8(t+s,e.charCodeAt(s)||0)}function jr(r,t,e){return r&&r.value[t*r.size+e]||0}function Eu(r,t){return r?Math.max(0,Math.min(65535,Math.round(jr(r,t,0)))):0}function vB(r,t){return r?Math.max(0,Math.min(4294967295,Math.round(jr(r,t,0)))):0}function AB(r,t){if(!r)return 0n;let e=r.value[t*r.size];return typeof e=="bigint"?e:BigInt(Math.max(0,Math.round(Number(e))))}function cr(r,t,e=0){return r?Math.max(0,Math.min(255,Math.round(jr(r,t,0)))):e}function d1(r,t){return r?Math.max(-32768,Math.min(32767,Math.round(jr(r,t,0)))):0}function Nu(r,t){return r?jr(r,t,0):0}function Ko(r,t){return!!Nu(r,t)}function SB(r,t){let e=new Array(Dp).fill(0);for(let n=0;n<t;n++){let s=cr(r,n,1)&15;s>=1&&s<=Dp&&e[s-1]++}return e}function Tp(r,t,e,n){let s=jr(r,t,e);return r.normalized?BB(r,s):n===8?Jo(s*257):n===16?Jo(s):s<=1?Jo(s*65535):s<=255?Jo(s*257):Jo(s)}function BB(r,t){let e=IB(r.value);return Jo(t/e*65535)}function IB(r){return r instanceof Uint8Array||r instanceof Uint8ClampedArray?255:r instanceof Uint16Array?65535:1}function Jo(r){return Math.max(0,Math.min(65535,Math.round(r)))}function _B(r,t){if(t===0)return[[0,0,0],[0,0,0]];let e=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY],n=[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY];for(let s=0;s<t;s++)for(let i=0;i<3;i++){let o=jr(r,s,i);e[i]=Math.min(e[i],o),n[i]=Math.max(n[i],o)}return[e,n]}function LB(r,t){return t.las?.scale||x1(r.schema.metadata?.las_scale)||[.001,.001,.001]}function TB(r,t,e){return t.las?.offset||x1(r.schema.metadata?.las_offset)||e[0]}function x1(r){if(typeof r=="string")try{let t=JSON.parse(r);return Array.isArray(t)&&t.length===3&&t.every(e=>typeof e=="number")?[t[0],t[1],t[2]]:void 0}catch{return}}var Qo={name:"PCD (Point Cloud Data)",id:"pcd",module:"pointclouds",encoding:"text",format:"pcd",extensions:["pcd"],mimeTypes:["text/plain"],category:"pointcloud",text:!0,binary:!0};Gs();var GB=typeof __VERSION__<"u"?__VERSION__:"latest";async function jB(){let{PCDLoaderWithParser:r}=await Promise.resolve().then(()=>(Ep(),Op));return r}var Rp={...Qo,dataType:null,batchType:null,version:GB,worker:!0,workerInBatches:!0,serializeWorkerResult:re,options:{pcd:{shape:"arrow-table",colorFormat:"uint8norm"}},preload:jB},E1=Rp;or();var qB=typeof __VERSION__<"u"?__VERSION__:"latest",N1={...Qo,dataType:null,batchType:null,version:qB,options:{pcd:{}},text:!0,encode:async(r,t)=>U1(r,t),encodeSync:U1,encodeTextSync:R1};function U1(r,t){let e=R1(r,t);return new TextEncoder().encode(e).buffer}function R1(r,t){let e=ee($B(r)),n=WB(e,"POSITION"),s=e.attributes.NORMAL,i=e.attributes.COLOR_0,o=n.value.length/n.size,a=["x","y","z"],c=["4","4","4"],l=["F","F","F"],u=["1","1","1"];s&&(a.push("normal_x","normal_y","normal_z"),c.push("4","4","4"),l.push("F","F","F"),u.push("1","1","1")),i&&(a.push("rgb"),c.push("4"),l.push("F"),u.push("1"));let f=["# .PCD v0.7 - Point Cloud Data file generated by loaders.gl","VERSION 0.7",`FIELDS ${a.join(" ")}`,`SIZE ${c.join(" ")}`,`TYPE ${l.join(" ")}`,`COUNT ${u.join(" ")}`,`WIDTH ${o}`,"HEIGHT 1","VIEWPOINT 0 0 0 1 0 0 0",`POINTS ${o}`,"DATA ascii"];for(let h=0;h<o;h++){let m=[to(n,h,0),to(n,h,1),to(n,h,2)];s&&m.push(to(s,h,0),to(s,h,1),to(s,h,2)),i&&m.push(YB(i,h)),f.push(m.join(" "))}return`${f.join(`
|
|
41
|
+
`}async function*r_(r,t){for(t.length>0&&(yield qu(t));;){let{value:e,done:n}=await r.next();if(n)break;yield qu($u(e))}}function Hp(r){let t=r?.batchSize;return typeof t=="number"?t:WI}function n_(r){return r.properties.reduce((t,e)=>t+ju(e.type),0)}function ju(r){switch(r){case"int8":case"uint8":case"char":case"uchar":return 1;case"int16":case"uint16":case"short":case"ushort":return 2;case"int32":case"uint32":case"int":case"uint":case"float32":case"float":return 4;case"float64":case"double":return 8;default:throw new Error(r)}}function s_(r){let t=new TextEncoder().encode(YI),e=r.length-t.length;for(let n=0;n<=e;n++){let s=!0;for(let i=0;i<t.length;i++)if(r[n+i]!==t[i]){s=!1;break}if(s){let i=n+t.length;return i===r.length||r[i]===13&&i+1===r.length?-1:(r[i]===13&&r[i+1]===10?i+=2:i<r.length&&i_(r[i])&&(i+=1),i)}}return-1}function i_(r){return r===10||r===13||r===9||r===32}function $u(r){return ArrayBuffer.isView(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r)}function qu(r){let t=new Uint8Array(r.byteLength);return t.set(r),t.buffer}function Xp(r){let t=r.reduce((s,i)=>s+i.length,0),e=new Uint8Array(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}async function o_(r,t){let e,n={comments:[],elements:[]};return await wd(r,s=>{if(s=s.trim(),s==="end_header")return!0;if(s==="")return!1;let i=s.split(/\s+/),o=i.shift();switch(s=i.join(" "),o){case"ply":break;case"format":n.format=i[0],n.version=i[1];break;case"comment":n.comments.push(s);break;case"element":e&&n.elements.push(e),e={name:i[0],count:parseInt(i[1],10),properties:[]};break;case"property":let a=a_(i,t.propertyNameMapping);e?.properties.push(a);break;default:console.log("unhandled",o,i)}return!1}),e&&n.elements.push(e),n}function a_(r,t){let e=r[0];return e==="list"?{type:e,name:r[3],countType:r[1],itemType:r[2]}:{type:e,name:r[1]}}async function c_(r,t){let e={indices:[],vertices:[],normals:[],uvs:[],colors:[]},n=0,s=0;for await(let i of r)if(i=i.trim(),i!==""){s>=t.elements[n].count&&(n++,s=0);let o=l_(t.elements[n].properties,i);u_(e,t.elements[n].name,o),s++}return e}function Yp(r,t){switch(t){case"char":case"uchar":case"short":case"ushort":case"int":case"uint":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":return parseInt(r,10);case"float":case"double":case"float32":case"float64":return parseFloat(r);default:throw new Error(t)}}function l_(r,t){let e=t.split(/\s+/),n={};for(let s=0;s<r.length;s++)if(r[s].type==="list"){let i=[],o=Yp(e.shift(),r[s].countType);for(let a=0;a<o;a++)i.push(Yp(e.shift(),r[s].itemType));n[r[s].name]=i}else n[r[s].name]=Yp(e.shift(),r[s].type);return n}function u_(r,t,e={}){switch(t){case"vertex":r.vertices.push(e.x,e.y,e.z),"nx"in e&&"ny"in e&&"nz"in e&&r.normals.push(e.nx,e.ny,e.nz),"s"in e&&"t"in e&&r.uvs.push(e.s,e.t),"red"in e&&"green"in e&&"blue"in e&&r.colors.push(e.red,e.green,e.blue);break;case"face":let n=e.vertex_indices||e.vertex_index;n.length===3?r.indices.push(n[0],n[1],n[2]):n.length===4&&(r.indices.push(n[0],n[1],n[3]),r.indices.push(n[1],n[2],n[3]));break;default:break}}var WI,YI,iw=p(()=>{"use strict";Zo();kp();Vu();Wp();WI=65536,YI="end_header"});var ow,aw=p(()=>{"use strict";ow={name:"PLY",id:"ply",module:"pointclouds",encoding:"text",format:"ply",extensions:["ply"],mimeTypes:["text/plain","application/octet-stream"],text:!0,binary:!0,tests:["ply"]}});async function h_(){let{PLYLoaderWithParser:r}=await Promise.resolve().then(()=>(Jp(),Kp));return r}var f_,cw,lw=p(()=>{"use strict";aw();Gs();f_="5.0.0-beta.4";cw={dataType:null,batchType:null,...ow,version:f_,worker:!0,workerInBatches:!0,serializeWorkerResult:re,options:{ply:{shape:"arrow-table",colorFormat:"uint8norm"}},preload:h_}});function uw(r,t){let e=Ee(r,"arrow-table");return Wu(e,t,r.loaderData)}function Qp(r,t){if(t?.ply?._useLegacyParser)return uw(V1(r,t?.ply),t);let e=G1(r,t?.ply);if(e)return Wu(e,t,zn(r,t?.ply));let n=lc(r,t?.ply);return Wu(uc(n),t,n.header)}function Wu(r,t,e){let n=e||r.loaderData||{comments:[],elements:[]},s=t?.ply?.shape==="arrow-table"?{...r,loader:"ply",loaderData:n}:{...ee(r),loader:"ply",loaderData:n},i=t?.ply?.colorFormat||"uint8norm";if(i==="uint8norm")return s;let o=s,a=m_(tm(o)?ee(o):o,i);return t?.ply?.shape==="arrow-table"?{...Ee(a,"arrow-table"),loader:"ply",loaderData:n}:a}function m_(r,t){let e=r.attributes.COLOR_0;if(!e)return r;let n=e.value instanceof Uint16Array?65535:255,s=t==="float16"?ti(e.value,n):sa(e.value,n),i={...r.attributes};for(let[o,a]of Object.entries(i))a.value===e.value&&(i[o]={...a,value:s,normalized:!1,...t==="float16"?{componentType:"float16"}:{}});return{...r,attributes:i,schema:Gi(i,r.schema.metadata)}}function tm(r){return"shape"in r&&r.shape==="arrow-table"}function fw(r,t){let e=Po(r);return t?.ply?.shape==="mesh"?{...ee(e),loader:"ply",loaderData:e.loaderData}:e}function y_(r,t){return fw(r,t)}var q8,d_,p_,hw=p(()=>{"use strict";Zo();Vs();Gs();or();Vu();Wp();iw();lw();({preload:q8,...d_}=cw);p_={...d_,parse:async(r,t)=>Qp(r,t),parseTextSync:(r,t)=>Qp(r,t),parseSync:(r,t)=>Qp(r,t),parseInBatches:async function*(r,t){let e={...t?.ply,batchSize:t?.batchSize??t?.core?.batchSize};for await(let n of nw(r,e)){let s=tm(n)?Wu(n,t):uw(n,t);yield tm(s)?ic(s):s}},serializeWorkerResult:re,deserializeWorkerResult:fw,serializeWorkerBatch:re,deserializeWorkerBatch:y_}});var Kp={};Re(Kp,{PLYLoaderWithParser:()=>p_});var Jp=p(()=>{"use strict";hw()});var I_={};Re(I_,{LASFormat:()=>Uo,LASLoader:()=>Ip,LASWorkerLoader:()=>u1,LASWriter:()=>p1,PCDFormat:()=>Qo,PCDLoader:()=>Rp,PCDWorkerLoader:()=>E1,PCDWriter:()=>N1,PLYFormat:()=>ea,PLYLoader:()=>em,PLYWorkerLoader:()=>dw,PLYWriter:()=>mw});var Uo={name:"LAS",id:"las",module:"pointclouds",encoding:"binary",format:"las",extensions:["las","laz"],mimeTypes:["application/octet-stream"],text:!1,binary:!0,tests:["LASF"]};var rA=typeof __VERSION__<"u"?__VERSION__:"latest",nA="arrow-table";var vg={...Uo,dataType:null,batchType:null,version:rA,worker:!1,options:{las:{shape:nA,fp64:!1,colorDepth:8,colorFormat:"uint8norm",columns:void 0,extraBytes:"raw",recoverMissingChunkTable:!1,compatibilityMode:"auto"}}};async function j2(){let{LASLoaderWithParser:r}=await Promise.resolve().then(()=>(l1(),c1));return r}var Ip={...vg,worker:!0,workerInBatches:!0,preload:j2},u1=Ip;Zo();or();var q2=typeof __VERSION__<"u"?__VERSION__:"latest",$2=227,W2=375,Y2=393,Uu=54,Mp=192,Z2=5e4,H2=4294967295,Dp=15,X2={0:20,1:28,2:26,3:34,4:57,5:63,6:30,7:36,8:38,9:59,10:67},p1={...Uo,dataType:null,batchType:null,version:q2,extensions:["las","laz"],options:{las:{}},encode:async(r,t)=>_p(r,t),encodeSync:_p,encodeInBatches:async function*(r,t){let e=[];for await(let n of r)e.push(n);yield _p(lB(e),t)}};function _p(r,t={}){let e=t.las?.format||"las",n=t.las?.colorDepth;if(n!==void 0&&n!=="auto"&&n!==8&&n!==16)throw new Error("LASWriter: invalid source color depth");let s=aB(r),i=g1(s,"POSITION");fB(i);let o=i.value.length/i.size;dB(s,o);let a=s.attributes.COLOR_0,c=s.attributes.intensity,l=s.attributes.classification,u=s.attributes.nir,f=tB(s,t,o),h=s.attributes.gpsTime,m=s.attributes.scanAngle,y=s.attributes.userData,g=s.attributes.pointSourceId,x=s.attributes.returnNumber,B=s.attributes.numberOfReturns,q=s.attributes.scannerChannel,M=s.attributes.scanDirectionFlag,b=s.attributes.edgeOfFlightLine,C=s.attributes.synthetic,_=s.attributes.keyPoint,$=s.attributes.withheld,X=s.attributes.overlap,ft=s.attributes.wavePacketDescriptorIndex,dt=s.attributes.wavePacketOffset,Bt=s.attributes.wavePacketSize,se=s.attributes.wavePacketReturnPoint,rt=s.attributes.wavePacketVector,tt=_B(i,o),Ye=SB(x,o),Ne=LB(s,t),Ze=TB(s,t,tt);hB(i,o,Ne,Ze);let xt=t.las?.pointDataRecordFormat??xB(t,a);pB(s,o,xt);let Gn=X2[xt];if(!Gn)throw new Error(`LASWriter: unsupported point data record format ${xt}`);let Qs=Gn+f.reduce((hn,ro)=>hn+ro.byteLength,0);if(Qs>65535)throw new Error(`LASWriter: point data record length ${Qs} exceeds the LAS limit`);iB(f);let wt=t.las?.version||(xt>=6?"1.4":"1.2"),pt=wt==="1.5"?Y2:wt==="1.4"?W2:$2;J2(wt,xt,t);let un=sB(h,o);if(wt==="1.5"&&t.las?.timeOffset&&!h)throw new Error("LASWriter: LAS 1.5 timeOffset requires a GPS time attribute");e==="laz"&&oB(wt,xt,t.las?.chunkSize),K2(wt,xt);let qr=new Uint8Array(o*Qs),fn=new DataView(qr.buffer);for(let hn=0;hn<o;hn++){let ro=hn*Qs;fn.setInt32(ro,Math.round((jr(i,hn,0)-Ze[0])/Ne[0]),!0),fn.setInt32(ro+4,Math.round((jr(i,hn,1)-Ze[1])/Ne[1]),!0),fn.setInt32(ro+8,Math.round((jr(i,hn,2)-Ze[2])/Ne[2]),!0),mB(fn,ro,hn,xt,Gn,{intensityAttribute:c,classificationAttribute:l,nirAttribute:u,colorAttribute:a,colorDepth:n,gpsTimeAttribute:h,scanAngleAttribute:m,userDataAttribute:y,pointSourceIdAttribute:g,returnNumberAttribute:x,numberOfReturnsAttribute:B,scannerChannelAttribute:q,scanDirectionFlagAttribute:M,edgeOfFlightLineAttribute:b,syntheticAttribute:C,keyPointAttribute:_,withheldAttribute:$,overlapAttribute:X,waveformDescriptorAttribute:ft,waveformOffsetAttribute:dt,waveformSizeAttribute:Bt,waveformReturnPointAttribute:se,waveformVectorAttribute:rt,extraByteFields:f})}let vr={vertexCount:o,boundingBox:tt,scale:Ne,offset:Ze,version:wt,headerLength:pt,pointDataRecordFormat:xt,pointDataRecordLength:Qs,returnCounts:Ye,maxGpsTime:un.maximum,minGpsTime:un.minimum,timeOffset:t.las?.timeOffset||0,hasGpsTime:!!h,hasWkt:!!t.las?.wkt};if(e==="laz")return Q2(qr,vr,t.las?.chunkSize,t.las?.variableChunkTable,f,t);let Ar=m1(f,t),eo=pt+Ar.byteLength,Yu=new ArrayBuffer(eo+qr.byteLength);w1(new DataView(Yu),{...vr,pointDataOffset:eo,vlrCount:y1(f,t)});let nm=new Uint8Array(Yu);return nm.set(Ar,pt),nm.set(qr,eo),Yu}function K2(r,t){let n={0:"1.0",1:"1.1",2:"1.2",3:"1.2"}[t];if(n&&r<n)throw new Error(`LASWriter: point data record format ${t} requires LAS ${n} or newer; received ${r}`);if(t>=4&&t<=5&&!["1.3","1.4","1.5"].includes(r))throw new Error(`LASWriter: point data record format ${t} requires LAS 1.3; received ${r}`);if(t>=6&&!["1.4","1.5"].includes(r))throw new Error(`LASWriter: point data record format ${t} requires LAS 1.4; received ${r}`)}function J2(r,t,e){if(r==="1.5"){if(t<6||t>10)throw new Error("LASWriter: LAS 1.5 output requires point data record format 6-10");if(!e.las?.wkt?.trim())throw new Error("LASWriter: LAS 1.5 output requires las.wkt");let n=e.las?.timeOffset??0;if(!Number.isInteger(n)||n<0||n>65535)throw new Error("LASWriter: LAS 1.5 timeOffset must be an unsigned 16-bit integer")}}function Q2(r,t,e,n=!1,s=[],i={}){let o=e||Z2,a=cp({pointDataRecordFormat:t.pointDataRecordFormat,pointDataRecordLength:t.pointDataRecordLength,chunkSize:n?H2:o}),c=m1(s,i),l=t.headerLength+c.byteLength+a.byteLength,u=[],f=[];for(let M=0;M<t.vertexCount;M+=o){let b=Math.min(o,t.vertexCount-M),C=M*t.pointDataRecordLength,_=op(r.subarray(C,C+b*t.pointDataRecordLength),{pointDataRecordFormat:t.pointDataRecordFormat,pointDataRecordLength:t.pointDataRecordLength,pointCount:b,point14ItemVersion:3,rgb14ItemVersion:3,byte14ItemVersion:3});u.push(_),f.push({pointCount:b,byteLength:_.byteLength})}let h=u.reduce((M,b)=>M+b.byteLength,0),m=ap(f,{variable:n}),y=l+8+h,g=new ArrayBuffer(y+8+m.byteLength),x=new Uint8Array(g),B=new DataView(g);w1(B,{...t,pointDataOffset:l,vlrCount:y1(s,i)+1,compressed:!0}),x.set(c,t.headerLength),x.set(a,t.headerLength+c.byteLength),Cp(B,l,y);let q=l+8;for(let M of u)x.set(M,q),q+=M.byteLength;return B.setUint32(y,0,!0),B.setUint32(y+4,f.length,!0),x.set(m,y+8),g}function tB(r,t,e){let n=t.las?.extraBytes||[],s=new Set;return n.map(i=>{if(s.has(i.attribute))throw new Error(`LASWriter: duplicate Extra Bytes attribute ${i.attribute}`);s.add(i.attribute);let o=r.attributes[i.attribute];if(!o)throw new Error(`LASWriter: Extra Bytes attribute ${i.attribute} is missing`);if(![1,3].includes(o.size))throw new Error(`LASWriter: Extra Bytes attribute ${i.attribute} must have size 1 or 3`);if(o.value.length<e*o.size)throw new Error(`LASWriter: Extra Bytes attribute ${i.attribute} is too short`);b1(i.attribute,o);let a=eB(o.value,o.size);return{...i,meshAttribute:o,dataType:a,byteLength:rB(a,o.size),componentCount:o.size}})}function eB(r,t){let e=0;if(r instanceof Uint8Array?e=1:r instanceof Int8Array?e=2:r instanceof Uint16Array?e=3:r instanceof Int16Array?e=4:r instanceof Uint32Array?e=5:r instanceof Int32Array?e=6:r instanceof BigUint64Array?e=7:r instanceof BigInt64Array?e=8:r instanceof Float32Array?e=9:r instanceof Float64Array&&(e=10),e)return e+(t===3?20:0);throw new Error("LASWriter: Extra Bytes attributes require a supported typed array")}function rB(r,t){let e=r>20?r-20:r>10?r-10:r;return(e<=2?1:e<=4?2:e<=6||e===9?4:8)*t}function nB(r){if(r.length===0)return new Uint8Array(0);let t=new Uint8Array(r.length*Mp),e=new DataView(t.buffer),n=0;for(let o of r)e.setUint8(n+2,o.dataType),kn(e,n+4,o.name||o.attribute,32),kn(e,n+160,o.description||"",32),n+=Mp;let s=new Uint8Array(Uu+t.byteLength),i=new DataView(s.buffer);return kn(i,2,"LASF_Spec",16),i.setUint16(18,4,!0),i.setUint16(20,t.byteLength,!0),kn(i,22,"Extra Bytes",32),s.set(t,Uu),s}function m1(r,t){let e=[];t.las?.wktMathTransform&&e.push(f1(2111,"WKT Math Transform",t.las.wktMathTransform)),t.las?.wkt&&e.push(f1(2112,"WKT Coordinate System",t.las.wkt));let n=nB(r);n.byteLength&&e.push(n);let s=e.reduce((a,c)=>a+c.byteLength,0),i=new Uint8Array(s),o=0;for(let a of e)i.set(a,o),o+=a.byteLength;return i}function f1(r,t,e){let n=new TextEncoder().encode(`${e}\0`);if(n.byteLength>65535)throw new Error(`LASWriter: WKT VLR ${r} exceeds the LAS VLR size limit`);let s=new Uint8Array(Uu+n.byteLength),i=new DataView(s.buffer);return kn(i,2,"LASF_Projection",16),i.setUint16(18,r,!0),i.setUint16(20,n.byteLength,!0),kn(i,22,t,32),s.set(n,Uu),s}function y1(r,t){return(t.las?.wktMathTransform?1:0)+(t.las?.wkt?1:0)+(r.length?1:0)}function sB(r,t){if(!r)return{minimum:0,maximum:0};let e=Number(r.value[0]),n=e;for(let s=1;s<t;s++){let i=Number(r.value[s*r.size]);e=Math.min(e,i),n=Math.max(n,i)}return{minimum:e,maximum:n}}function iB(r){let t=r.length*Mp;if(t>65535)throw new Error(`LASWriter: Extra Bytes VLR payload ${t} exceeds the LAS limit`)}function oB(r,t,e){if(t===1&&!["1.1","1.2","1.3","1.4","1.5"].includes(r))throw new Error(`LASWriter: LAZ PDRF 1 output requires LAS 1.1 or newer; received ${r}`);if(t>=2&&t<=3&&!["1.2","1.3","1.4","1.5"].includes(r))throw new Error(`LASWriter: LAZ PDRF ${t} output requires LAS 1.2 or newer; received ${r}`);if(t>=4&&t<=5&&!["1.3","1.4","1.5"].includes(r))throw new Error(`LASWriter: LAZ PDRF ${t} requires LAS 1.3 or newer; received ${r}`);if(t>=6&&!["1.4","1.5"].includes(r))throw new Error(`LASWriter: LAZ output requires LAS 1.4; received ${r}`);if(![0,1,2,3,4,5,6,7,8,9,10].includes(t))throw new Error(`LASWriter: LAZ output currently supports point data record formats 0-10; received ${t}`);if(e!==void 0&&(!Number.isInteger(e)||e<=0||e>4294967295))throw new Error(`LASWriter: invalid LAZ chunk size ${e}`)}function aB(r){return"shape"in r&&r.shape==="arrow-table"?ee(r):r}function cB(r){return"shape"in r&&r.shape==="arrow-table"?r:Ee(r,"arrow-table")}function lB(r){if(r.length===0)throw new Error("LASWriter: at least one input batch is required");if(r.length===1)return r[0];let t=r.map(s=>ee(cB(s))),e=t[0],n={};uB(t);for(let s of Object.keys(e.attributes)){let i=e.attributes[s],o=t.map(f=>f.attributes[s]?.value);if(o.some(f=>!f))continue;let a=o.reduce((f,h)=>f+h.length,0),c=i.value.constructor,l=new c(a),u=0;for(let f of o)l.set(f,u),u+=f.length;n[s]={...i,value:l}}return{...e,attributes:n,header:{...e.header,vertexCount:g1({...e,attributes:n},"POSITION").value.length/3}}}function uB(r){let t=Object.keys(r[0].attributes);for(let e of r.slice(1)){if(Object.keys(e.attributes).length!==t.length||t.some(s=>!e.attributes[s]))throw new Error("LASWriter: encodeInBatches requires consistent attribute names");for(let s of t){let i=r[0].attributes[s],o=e.attributes[s];if(o.size!==i.size||o.value.constructor!==i.value.constructor)throw new Error(`LASWriter: encodeInBatches requires a consistent ${s} layout`)}}}function g1(r,t){let e=r.attributes[t];if(!e)throw new Error(`LASWriter: ${t} attribute is required`);return e}function fB(r){if(r.size!==3)throw new Error("LASWriter: POSITION attribute must have size 3");if(r.value.length%r.size!==0)throw new Error("LASWriter: POSITION attribute length must be divisible by its size")}function hB(r,t,e,n){for(let s=0;s<3;s++){if(!Number.isFinite(e[s])||e[s]<=0)throw new Error("LASWriter: coordinate scale must be finite and positive");if(!Number.isFinite(n[s]))throw new Error("LASWriter: coordinate offset must be finite")}for(let s=0;s<t;s++)for(let i=0;i<3;i++){let o=r.value[s*r.size+i];if(!Number.isFinite(o))throw new Error("LASWriter: POSITION values must be finite");let a=Math.round((o-n[i])/e[i]);if(a<-2147483648||a>2147483647)throw new Error("LASWriter: encoded coordinate exceeds the signed 32-bit LAS range")}}function dB(r,t){let e=["intensity","classification","gpsTime","scanAngle","userData","pointSourceId","returnNumber","numberOfReturns","scannerChannel","scanDirectionFlag","edgeOfFlightLine","synthetic","keyPoint","withheld","overlap","nir","wavePacketDescriptorIndex","wavePacketOffset","wavePacketSize","wavePacketReturnPoint"];for(let i of e){let o=r.attributes[i];o&&Lp(i,o,t,1)}let n=r.attributes.COLOR_0;n&&Lp("COLOR_0",n,t,3,!1);let s=r.attributes.wavePacketVector;s&&Lp("wavePacketVector",s,t,3)}function pB(r,t,e){let n=e>=6?15:5,s=r.attributes.returnNumber,i=r.attributes.numberOfReturns;for(let o=0;o<t;o++){let a=cr(s,o,1),c=cr(i,o,1);if(a<1||a>n)throw new Error(`LASWriter: returnNumber must be between 1 and ${n} for point data record format ${e}`);if(c<1||c>n)throw new Error(`LASWriter: numberOfReturns must be between 1 and ${n} for point data record format ${e}`);if(a>c)throw new Error("LASWriter: returnNumber cannot exceed numberOfReturns")}}function Lp(r,t,e,n,s=!0){if(n===1?t.size!==1:t.size<n)throw new Error(`LASWriter: ${r} attribute must have size ${n}`);if(b1(r,t),s&&t.value.length<e*t.size)throw new Error(`LASWriter: ${r} attribute is too short`);if(!s&&t.value.length<t.size)throw new Error(`LASWriter: ${r} attribute is too short`)}function b1(r,t){for(let e of t.value)if(!Number.isFinite(Number(e)))throw new Error(`LASWriter: ${r} attribute must contain finite values`)}function w1(r,t){let[e,n]=t.version.split(".").map(Number);kn(r,0,"LASF",4),r.setUint8(24,e),r.setUint8(25,n),kn(r,26,"loaders.gl",32),kn(r,58,"loaders.gl",32),r.setUint16(94,t.headerLength,!0),r.setUint32(96,t.pointDataOffset,!0),r.setUint32(100,t.vlrCount||0,!0),r.setUint8(104,t.pointDataRecordFormat|(t.compressed?128:0)),r.setUint16(105,t.pointDataRecordLength,!0);let s=t.version==="1.4"||t.version==="1.5";r.setUint32(107,s?0:t.vertexCount,!0);for(let i=0;i<5;i++)r.setUint32(111+i*4,s?0:t.returnCounts[i],!0);if(t.version==="1.5"?r.setUint16(6,16|(t.hasGpsTime?1:0)|(t.timeOffset?64:0),!0):t.version==="1.4"&&t.hasWkt&&r.setUint16(6,16,!0),r.setFloat64(131,t.scale[0],!0),r.setFloat64(139,t.scale[1],!0),r.setFloat64(147,t.scale[2],!0),r.setFloat64(155,t.offset[0],!0),r.setFloat64(163,t.offset[1],!0),r.setFloat64(171,t.offset[2],!0),r.setFloat64(179,t.boundingBox[1][0],!0),r.setFloat64(187,t.boundingBox[0][0],!0),r.setFloat64(195,t.boundingBox[1][1],!0),r.setFloat64(203,t.boundingBox[0][1],!0),r.setFloat64(211,t.boundingBox[1][2],!0),r.setFloat64(219,t.boundingBox[0][2],!0),s){Cp(r,247,t.vertexCount);for(let i=0;i<Dp;i++)Cp(r,255+i*8,t.returnCounts[i])}t.version==="1.5"&&(r.setFloat64(375,t.maxGpsTime,!0),r.setFloat64(383,t.minGpsTime,!0),r.setUint16(391,t.timeOffset,!0))}function mB(r,t,e,n,s,i){if(r.setUint16(t+12,Eu(i.intensityAttribute,e),!0),n<=5){let o=cr(i.returnNumberAttribute,e,1)&7,a=cr(i.numberOfReturnsAttribute,e,1)&7;r.setUint8(t+14,o|a<<3),r.setUint8(t+15,cr(i.classificationAttribute,e)&31),r.setInt8(t+16,d1(i.scanAngleAttribute,e)),r.setUint8(t+17,cr(i.userDataAttribute,e)),r.setUint16(t+18,Eu(i.pointSourceIdAttribute,e),!0),(n===1||n===3||n>=4)&&r.setFloat64(t+20,Nu(i.gpsTimeAttribute,e),!0),(n===4||n===5)&&h1(r,t+(n===4?28:34),e,i)}else{let o=cr(i.returnNumberAttribute,e,1)&15,a=cr(i.numberOfReturnsAttribute,e,1)&15,c=cr(i.scannerChannelAttribute,e)&3,l=o|a<<4,u=(Ko(i.syntheticAttribute,e)?1:0)|(Ko(i.keyPointAttribute,e)?2:0)|(Ko(i.withheldAttribute,e)?4:0)|(Ko(i.overlapAttribute,e)?8:0)|c<<4|(Ko(i.scanDirectionFlagAttribute,e)?64:0)|(Ko(i.edgeOfFlightLineAttribute,e)?128:0);r.setUint8(t+14,l),r.setUint8(t+15,u),r.setUint8(t+16,cr(i.classificationAttribute,e)),r.setUint8(t+17,cr(i.userDataAttribute,e)),r.setInt16(t+18,d1(i.scanAngleAttribute,e),!0),r.setUint16(t+20,Eu(i.pointSourceIdAttribute,e),!0),r.setFloat64(t+22,Nu(i.gpsTimeAttribute,e),!0),(n===9||n===10)&&h1(r,t+(n===9?30:38),e,i)}bB(r,t,e,n,i.colorAttribute,i.colorDepth),(n===8||n===10)&&r.setUint16(t+36,Eu(i.nirAttribute,e),!0),yB(r,t,e,s,i.extraByteFields)}function h1(r,t,e,n){r.setUint8(t,cr(n.waveformDescriptorAttribute,e)),r.setBigUint64(t+1,AB(n.waveformOffsetAttribute,e),!0),r.setUint32(t+9,vB(n.waveformSizeAttribute,e),!0),r.setFloat32(t+13,Nu(n.waveformReturnPointAttribute,e),!0);for(let s=0;s<3;s++)r.setFloat32(t+17+s*4,jr(n.waveformVectorAttribute,e,s),!0)}function yB(r,t,e,n,s){let i=t+n;for(let o of s)for(let a=0;a<o.componentCount;a++)gB(r,i,e,a,o),i+=o.byteLength/o.componentCount}function gB(r,t,e,n,s){let i=s.meshAttribute.value[e*s.componentCount+n];switch(s.dataType>20?s.dataType-20:s.dataType>10?s.dataType-10:s.dataType){case 1:r.setUint8(t,Number(i));break;case 2:r.setInt8(t,Number(i));break;case 3:r.setUint16(t,Number(i),!0);break;case 4:r.setInt16(t,Number(i),!0);break;case 5:r.setUint32(t,Number(i),!0);break;case 6:r.setInt32(t,Number(i),!0);break;case 7:r.setBigUint64(t,BigInt(i),!0);break;case 8:r.setBigInt64(t,BigInt(i),!0);break;case 9:r.setFloat32(t,Number(i),!0);break;case 10:r.setFloat64(t,Number(i),!0);break;default:throw new Error(`LASWriter: unsupported Extra Bytes data type ${s.dataType}`)}}function bB(r,t,e,n,s,i){let o=wB(n);o<0||!s||(r.setUint16(t+o,Tp(s,e,0,i),!0),r.setUint16(t+o+2,Tp(s,e,1,i),!0),r.setUint16(t+o+4,Tp(s,e,2,i),!0))}function wB(r){switch(r){case 2:return 20;case 3:return 28;case 5:return 57;case 7:case 8:case 10:return 30;default:return-1}}function xB(r,t){return r.las?.format==="laz"||r.las?.version==="1.4"?t?7:6:t?2:0}function Cp(r,t,e){r.setUint32(t,e>>>0,!0),r.setUint32(t+4,Math.floor(e/2**32),!0)}function kn(r,t,e,n){if(/[^\x00-\x7f]/.test(e))throw new Error("LASWriter fixed-width text must be ASCII");for(let s=0;s<n;s++)r.setUint8(t+s,e.charCodeAt(s)||0)}function jr(r,t,e){return r&&r.value[t*r.size+e]||0}function Eu(r,t){return r?Math.max(0,Math.min(65535,Math.round(jr(r,t,0)))):0}function vB(r,t){return r?Math.max(0,Math.min(4294967295,Math.round(jr(r,t,0)))):0}function AB(r,t){if(!r)return 0n;let e=r.value[t*r.size];return typeof e=="bigint"?e:BigInt(Math.max(0,Math.round(Number(e))))}function cr(r,t,e=0){return r?Math.max(0,Math.min(255,Math.round(jr(r,t,0)))):e}function d1(r,t){return r?Math.max(-32768,Math.min(32767,Math.round(jr(r,t,0)))):0}function Nu(r,t){return r?jr(r,t,0):0}function Ko(r,t){return!!Nu(r,t)}function SB(r,t){let e=new Array(Dp).fill(0);for(let n=0;n<t;n++){let s=cr(r,n,1)&15;s>=1&&s<=Dp&&e[s-1]++}return e}function Tp(r,t,e,n){let s=jr(r,t,e);return r.normalized?BB(r,s):n===8?Jo(s*257):n===16?Jo(s):s<=1?Jo(s*65535):s<=255?Jo(s*257):Jo(s)}function BB(r,t){let e=IB(r.value);return Jo(t/e*65535)}function IB(r){return r instanceof Uint8Array||r instanceof Uint8ClampedArray?255:r instanceof Uint16Array?65535:1}function Jo(r){return Math.max(0,Math.min(65535,Math.round(r)))}function _B(r,t){if(t===0)return[[0,0,0],[0,0,0]];let e=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY],n=[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY];for(let s=0;s<t;s++)for(let i=0;i<3;i++){let o=jr(r,s,i);e[i]=Math.min(e[i],o),n[i]=Math.max(n[i],o)}return[e,n]}function LB(r,t){return t.las?.scale||x1(r.schema.metadata?.las_scale)||[.001,.001,.001]}function TB(r,t,e){return t.las?.offset||x1(r.schema.metadata?.las_offset)||e[0]}function x1(r){if(typeof r=="string")try{let t=JSON.parse(r);return Array.isArray(t)&&t.length===3&&t.every(e=>typeof e=="number")?[t[0],t[1],t[2]]:void 0}catch{return}}var Qo={name:"PCD (Point Cloud Data)",id:"pcd",module:"pointclouds",encoding:"text",format:"pcd",extensions:["pcd"],mimeTypes:["text/plain"],category:"pointcloud",text:!0,binary:!0};Gs();var GB=typeof __VERSION__<"u"?__VERSION__:"latest";async function jB(){let{PCDLoaderWithParser:r}=await Promise.resolve().then(()=>(Ep(),Op));return r}var Rp={...Qo,dataType:null,batchType:null,version:GB,worker:!0,workerInBatches:!0,serializeWorkerResult:re,options:{pcd:{shape:"arrow-table",colorFormat:"uint8norm"}},preload:jB},E1=Rp;or();var qB=typeof __VERSION__<"u"?__VERSION__:"latest",N1={...Qo,dataType:null,batchType:null,version:qB,options:{pcd:{}},text:!0,encode:async(r,t)=>U1(r,t),encodeSync:U1,encodeTextSync:R1};function U1(r,t){let e=R1(r,t);return new TextEncoder().encode(e).buffer}function R1(r,t){let e=ee($B(r)),n=WB(e,"POSITION"),s=e.attributes.NORMAL,i=e.attributes.COLOR_0,o=n.value.length/n.size,a=["x","y","z"],c=["4","4","4"],l=["F","F","F"],u=["1","1","1"];s&&(a.push("normal_x","normal_y","normal_z"),c.push("4","4","4"),l.push("F","F","F"),u.push("1","1","1")),i&&(a.push("rgb"),c.push("4"),l.push("F"),u.push("1"));let f=["# .PCD v0.7 - Point Cloud Data file generated by loaders.gl","VERSION 0.7",`FIELDS ${a.join(" ")}`,`SIZE ${c.join(" ")}`,`TYPE ${l.join(" ")}`,`COUNT ${u.join(" ")}`,`WIDTH ${o}`,"HEIGHT 1","VIEWPOINT 0 0 0 1 0 0 0",`POINTS ${o}`,"DATA ascii"];for(let h=0;h<o;h++){let m=[to(n,h,0),to(n,h,1),to(n,h,2)];s&&m.push(to(s,h,0),to(s,h,1),to(s,h,2)),i&&m.push(YB(i,h)),f.push(m.join(" "))}return`${f.join(`
|
|
42
42
|
`)}
|
|
43
43
|
`}function $B(r){return"shape"in r&&r.shape==="arrow-table"?r:Ee(r,"arrow-table")}function WB(r,t){let e=r.attributes[t];if(!e)throw new Error(`PCDWriter: ${t} attribute is required`);return e}function to(r,t,e){return r.value[t*r.size+e]||0}function YB(r,t){let e=new Uint8Array(4);return e[0]=Pp(r,t,0),e[1]=Pp(r,t,1),e[2]=Pp(r,t,2),new DataView(e.buffer).getFloat32(0,!0)}function Pp(r,t,e){let n=to(r,t,e),s=r.normalized||n<=1?n*255:n;return Math.max(0,Math.min(255,Math.round(s)))}var ea={name:"PLY",id:"ply",module:"pointclouds",encoding:"text",format:"ply",extensions:["ply"],mimeTypes:["text/plain","application/octet-stream"],text:!0,binary:!0,tests:["ply"]};Gs();var g_=typeof __VERSION__<"u"?__VERSION__:"latest";async function b_(){let{PLYLoaderWithParser:r}=await Promise.resolve().then(()=>(Jp(),Kp));return r}var em={dataType:null,batchType:null,...ea,version:g_,worker:!0,workerInBatches:!0,serializeWorkerResult:re,options:{ply:{shape:"arrow-table",colorFormat:"uint8norm"}},preload:b_},dw=em;or();var w_=typeof __VERSION__<"u"?__VERSION__:"latest",mw={...ea,dataType:null,batchType:null,version:w_,options:{ply:{}},text:!0,encode:async(r,t)=>pw(r,t),encodeSync:pw,encodeTextSync:yw};function pw(r,t){let e=yw(r,t);return new TextEncoder().encode(e).buffer}function yw(r,t){let e=ee(x_(r)),n=v_(e,"POSITION"),s=e.attributes.NORMAL,i=e.attributes.TEXCOORD_0,o=e.attributes.COLOR_0,a=S_(e),c=n.value.length/n.size,l=B_(e,c),u=A_(c,l.length/3,!!s,!!i,!!o,a),f=[];for(let h=0;h<c;h++){let m=[ln(n,h,0),ln(n,h,1),ln(n,h,2)];s&&m.push(ln(s,h,0),ln(s,h,1),ln(s,h,2)),i&&m.push(ln(i,h,0),ln(i,h,1)),o&&m.push(rm(o,h,0),rm(o,h,1),rm(o,h,2));for(let[,y]of a)m.push(ln(y,h,0));f.push(m.join(" "))}for(let h=0;h<l.length;h+=3)f.push(`3 ${l[h]} ${l[h+1]} ${l[h+2]}`);return`${u.concat(f).join(`
|
|
44
44
|
`)}
|