balloc 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/jp/balloc.cjs CHANGED
@@ -213,19 +213,38 @@ var Balloc = class {
213
213
  this.recyclePush(oldBlockSize, dataAddress);
214
214
  }
215
215
  /**
216
- * メモリブロックを解放します。
217
- *
218
- * ブロックのヘッダーはクッキーをゼロに設定することで無効化され、
219
- * そのアドレスは後で再利用するために登録されます。ブロックが `dataBus` の
220
- * 正確なトップにある場合を除き、データ領域も再利用システムに戻されます。
221
- * トップにある場合は、`dataPointer` が単に巻き戻され、再利用リストに
222
- * エントリを作成せずに領域が破棄されます。
223
- *
224
- * @param {number} handler - 解放するブロックのハンドル。
225
- * @returns {void}
226
- * @throws {Error} ハンドルが無効、破損している場合、またはブロックが
227
- * withView() によって借用されている場合。
228
- */
216
+ * ブロックのアドレスとハンドルを維持したまま、使用中の要素を格納できる
217
+ * 最小の2のべき乗の容量まで縮小します。
218
+ *
219
+ * ブロックが dataBus のトップにある場合、dataPointer を後退させます。
220
+ * それ以外の場合、解放された末尾領域を2のべき乗の領域に分割し、
221
+ * 各領域を再利用リストに戻します。
222
+ *
223
+ * @param {number} handler - 縮小するブロックのハンドル。
224
+ * @returns {void}
225
+ * @throws {Error} ハンドルが無効または破損している場合、あるいは
226
+ * withView() によってブロックが借用されている場合。
227
+ */
228
+ shrink(handler) {
229
+ const meta = this.extractMetadata(handler, this.metadata);
230
+ this.assertNotBorrowed(meta.headerAddress);
231
+ const newCapacity = Math.max(1, 32 - Math.clz32(Math.max(2, meta.occupied) - 1));
232
+ if (newCapacity >= meta.capacityExponent) return;
233
+ const oldBlockSize = meta.byteCapacity;
234
+ const newBlockSize = 2 ** newCapacity * this.wordSize;
235
+ const oldEnd = meta.dataAddress + oldBlockSize;
236
+ this.controlAdapter.setUint8(meta.headerAddress + CAPACITY_OFFSET, newCapacity);
237
+ if (oldEnd === this.dataPointer) {
238
+ this.dataPointer = meta.dataAddress + newBlockSize;
239
+ return;
240
+ }
241
+ let address = meta.dataAddress + newBlockSize;
242
+ for (let exponent = newCapacity; exponent < meta.capacityExponent; exponent++) {
243
+ const segmentSize = 2 ** exponent * this.wordSize;
244
+ this.recyclePush(segmentSize, address);
245
+ address += segmentSize;
246
+ }
247
+ }
229
248
  free(handler) {
230
249
  const generation = handler / ROTATE_32BITS & CLAMP_11BITS;
231
250
  const headerAddress = handler >>> 0;
@@ -396,7 +415,6 @@ var Balloc = class {
396
415
  * 要素は、最後尾の占有要素の直後の最初の空き位置に書き込まれます。
397
416
  * ブロックの占有数は、その容量内に空きスペースが存在する場合にのみインクリメントされます。
398
417
  *
399
- * @param {number} handler - ブロックのハンドル。
400
418
  * @param {number} value - 挿入する値。
401
419
  * @returns {boolean} 値が挿入された場合は `true`、ブロックに利用可能な
402
420
  * スペースがない場合は `false`。
@@ -732,23 +750,36 @@ var Balloc = class {
732
750
  * サブビューにも適用されます。
733
751
  *
734
752
  * @param {number} handler - ブロックのハンドル。
735
- * @param {Function} callback - 共有された TypedArray を受け取る関数。
753
+ * @param {...(number|Function)} args - 1つ以上のブロックハンドルと、その後に続くコールバック。
736
754
  * @returns {*} コールバックによって生成された戻り値。
737
- * @throws {TypeError} コールバックが関数ではない場合。
738
- * @throws {Error} ハンドルが無効であるか、すでに借用されている場合。
755
+ * @throws {TypeError} ハンドルが指定されていない場合、またはコールバックが関数ではない場合。
756
+ * @throws {Error} いずれかのハンドルが無効、重複、または借用中の場合。
739
757
  */
740
- withView(handler, callback) {
758
+ withView(...args) {
759
+ if (args.length < 2) throw new TypeError("At least one handler and one callback are required");
760
+ const callback = args.pop();
741
761
  if (typeof callback !== "function") throw new TypeError("callback must be a function");
742
- const meta = this.extractMetadata(handler, this.metadata);
743
- const flagsAddress = meta.headerAddress + FLAGS_OFFSET;
744
- const flags = this.controlBus[flagsAddress];
745
- if (flags & VIEW_LOCK) throw new Error("Block is already borrowed");
746
- this.controlBus[flagsAddress] = flags | VIEW_LOCK;
762
+ const handlers = args;
763
+ const metadata = handlers.map((handler) => this.extractMetadata(handler, {}));
764
+ const headers = metadata.map((meta) => meta.headerAddress);
765
+ if (new Set(headers).size !== headers.length) throw new Error("Duplicate handler");
766
+ const flags = headers.map((header) => this.controlBus[header + FLAGS_OFFSET]);
767
+ if (flags.some((flag) => flag & VIEW_LOCK)) throw new Error("Block is already borrowed");
768
+ let acquiredCount = 0;
747
769
  try {
748
- const rawAddress = meta.dataAddress >>> this.wordShift;
749
- return callback(this.auxiliary.subarray(rawAddress, rawAddress + meta.occupied));
770
+ for (const header of headers) {
771
+ this.controlBus[header + FLAGS_OFFSET] |= VIEW_LOCK;
772
+ acquiredCount++;
773
+ }
774
+ const views = metadata.map((meta) => {
775
+ const rawAddress = meta.dataAddress >>> this.wordShift;
776
+ return this.auxiliary.subarray(rawAddress, rawAddress + meta.occupied);
777
+ });
778
+ return callback(...views);
750
779
  } finally {
751
- this.controlBus[flagsAddress] &= ~VIEW_LOCK;
780
+ for (let i = 0; i < acquiredCount; i++) {
781
+ this.controlBus[headers[i] + FLAGS_OFFSET] &= ~VIEW_LOCK;
782
+ }
752
783
  }
753
784
  }
754
785
  // ======== スロット単位の容量 (CAPACITY IN SLOTS) ==========
package/src/jp/balloc.js CHANGED
@@ -1,2 +1,2 @@
1
- var BallocModule=(()=>{var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target2,value)=>__defProp(target2,"name",{value,configurable:!0});var __export=(target2,all)=>{for(var name in all)__defProp(target2,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var balloc_exports={};__export(balloc_exports,{default:()=>Balloc});var decoder;try{decoder=new TextDecoder}catch{}var src,srcEnd,position=0;var EMPTY_ARRAY=[],LEGACY_RECORD_INLINE_ID=105,RECORD_DEFINITIONS_ID=57342,RECORD_INLINE_ID=57343,BUNDLED_STRINGS_ID=57337;var PACKED_REFERENCE_TAG_ID=6,STOP_CODE={},maxArraySize=11281e4,maxMapSize=1681e4;var strings=EMPTY_ARRAY,stringPosition=0,currentDecoder={},currentStructures,srcString,srcStringStart=0,srcStringEnd=0,bundledStrings,referenceMap,currentExtensions=[],currentExtensionRanges=[],packedValues,dataView,restoreMapsAsObject,defaultOptions={useRecords:!1,mapsAsObjects:!0},sequentialMode=!1,inlineObjectReadThreshold=2;try{new Function("")}catch{inlineObjectReadThreshold=1/0}var Decoder=class _Decoder{static{__name(this,"Decoder")}constructor(options){if(options&&((options.keyMap||options._keyMap)&&!options.useRecords&&(options.useRecords=!1,options.mapsAsObjects=!0),options.useRecords===!1&&options.mapsAsObjects===void 0&&(options.mapsAsObjects=!0),options.getStructures&&(options.getShared=options.getStructures),options.getShared&&!options.structures&&((options.structures=[]).uninitialized=!0),options.keyMap)){this.mapKey=new Map;for(let[k,v]of Object.entries(options.keyMap))this.mapKey.set(v,k)}Object.assign(this,options)}decodeKey(key){return this.keyMap&&this.mapKey.get(key)||key}encodeKey(key){return this.keyMap&&this.keyMap.hasOwnProperty(key)?this.keyMap[key]:key}encodeKeys(rec){if(!this._keyMap)return rec;let map=new Map;for(let[k,v]of Object.entries(rec))map.set(this._keyMap.hasOwnProperty(k)?this._keyMap[k]:k,v);return map}decodeKeys(map){if(!this._keyMap||map.constructor.name!="Map")return map;if(!this._mapKey){this._mapKey=new Map;for(let[k,v]of Object.entries(this._keyMap))this._mapKey.set(v,k)}let res={};return map.forEach((v,k)=>res[safeKey(this._mapKey.has(k)?this._mapKey.get(k):k)]=v),res}mapDecode(source,end){let res=this.decode(source);return this._keyMap&&res.constructor.name==="Array"?res.map(r=>this.decodeKeys(r)):res}decode(source,end){if(src)return saveState(()=>(clearSource(),this?this.decode(source,end):_Decoder.prototype.decode.call(defaultOptions,source,end)));srcEnd=end>-1?end:source.length,position=0,stringPosition=0,srcStringEnd=0,srcString=null,strings=EMPTY_ARRAY,bundledStrings=null,src=source;try{dataView=source.dataView||(source.dataView=new DataView(source.buffer,source.byteOffset,source.byteLength))}catch(error){throw src=null,source instanceof Uint8Array?error:new Error("Source must be a Uint8Array or Buffer but was a "+(source&&typeof source=="object"?source.constructor.name:typeof source))}if(this instanceof _Decoder){if(currentDecoder=this,packedValues=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues),this.structures)return currentStructures=this.structures,checkedRead();(!currentStructures||currentStructures.length>0)&&(currentStructures=[])}else currentDecoder=defaultOptions,(!currentStructures||currentStructures.length>0)&&(currentStructures=[]),packedValues=null;return checkedRead()}decodeMultiple(source,forEach){let values,lastPosition=0;try{let size=source.length;sequentialMode=!0;let value=this?this.decode(source,size):defaultDecoder.decode(source,size);if(forEach){if(forEach(value)===!1)return;for(;position<size;)if(lastPosition=position,forEach(checkedRead())===!1)return}else{for(values=[value];position<size;)lastPosition=position,values.push(checkedRead());return values}}catch(error){throw error.lastPosition=lastPosition,error.values=values,error}finally{sequentialMode=!1,clearSource()}}};function checkedRead(){try{let result=read();if(bundledStrings){if(position>=bundledStrings.postBundlePosition){let error=new Error("Unexpected bundle position");throw error.incomplete=!0,error}position=bundledStrings.postBundlePosition,bundledStrings=null}if(position==srcEnd)currentStructures=null,src=null,referenceMap&&(referenceMap=null);else if(position>srcEnd){let error=new Error("Unexpected end of CBOR data");throw error.incomplete=!0,error}else if(!sequentialMode)throw new Error("Data read, but end of buffer not reached");return result}catch(error){throw clearSource(),(error instanceof RangeError||error.message.startsWith("Unexpected end of buffer"))&&(error.incomplete=!0),error}}__name(checkedRead,"checkedRead");function endOfCBORError(){let error=new Error("Unexpected end of CBOR data");return error.incomplete=!0,error}__name(endOfCBORError,"endOfCBORError");function read(){if(!(position<srcEnd))throw endOfCBORError();let token=src[position++],majorType=token>>5;if(token=token&31,token>23)switch(token){case 24:if(position>=srcEnd)throw endOfCBORError();token=src[position++];break;case 25:if(majorType==7)return getFloat16();token=dataView.getUint16(position),position+=2;break;case 26:if(majorType==7){let value=dataView.getFloat32(position);if(currentDecoder.useFloat32>2){let multiplier=mult10[(src[position]&127)<<1|src[position+1]>>7];return position+=4,(multiplier*value+(value>0?.5:-.5)>>0)/multiplier}return position+=4,value}if(token=dataView.getUint32(position),position+=4,majorType===1)return-1-token;break;case 27:if(majorType==7){let value=dataView.getFloat64(position);return position+=8,value}if(majorType>1){if(dataView.getUint32(position)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");token=dataView.getUint32(position+4)}else currentDecoder.int64AsNumber?(token=dataView.getUint32(position)*4294967296,token+=dataView.getUint32(position+4)):token=dataView.getBigUint64(position);position+=8;break;case 31:switch(majorType){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let array=[],value,i=0;for(;(value=read())!=STOP_CODE;){if(i>=maxArraySize)throw new Error(`Array length exceeds ${maxArraySize}`);array[i++]=value}return majorType==4?array:majorType==3?array.join(""):Buffer.concat(array);case 5:let key;if(currentDecoder.mapsAsObjects){let object={},i2=0;if(currentDecoder.keyMap)for(;(key=read())!=STOP_CODE;){if(i2++>=maxMapSize)throw new Error(`Property count exceeds ${maxMapSize}`);object[safeKey(currentDecoder.decodeKey(key))]=read()}else for(;(key=read())!=STOP_CODE;){if(i2++>=maxMapSize)throw new Error(`Property count exceeds ${maxMapSize}`);object[safeKey(key)]=read()}return object}else{restoreMapsAsObject&&(currentDecoder.mapsAsObjects=!0,restoreMapsAsObject=!1);let map=new Map;if(currentDecoder.keyMap){let i2=0;for(;(key=read())!=STOP_CODE;){if(i2++>=maxMapSize)throw new Error(`Map size exceeds ${maxMapSize}`);map.set(currentDecoder.decodeKey(key),read())}}else{let i2=0;for(;(key=read())!=STOP_CODE;){if(i2++>=maxMapSize)throw new Error(`Map size exceeds ${maxMapSize}`);map.set(key,read())}}return map}case 7:return STOP_CODE;default:throw new Error("Invalid major type for indefinite length "+majorType)}default:throw new Error("Unknown token "+token)}switch(majorType){case 0:return token;case 1:return~token;case 2:return readBin(token);case 3:if(srcStringEnd>=position)return srcString.slice(position-srcStringStart,(position+=token)-srcStringStart);if(srcStringEnd==0&&srcEnd<140&&token<32){let string=token<16?shortStringInJS(token):longStringInJS(token);if(string!=null)return string}return readFixedString(token);case 4:if(token>=maxArraySize)throw new Error(`Array length exceeds ${maxArraySize}`);if(token>srcEnd-position)throw endOfCBORError();let array=new Array(token);for(let i=0;i<token;i++)array[i]=read();return array;case 5:if(token>=maxMapSize)throw new Error(`Map size exceeds ${maxArraySize}`);if(token>(srcEnd-position)/2)throw endOfCBORError();if(currentDecoder.mapsAsObjects){let object={};if(currentDecoder.keyMap)for(let i=0;i<token;i++)object[safeKey(currentDecoder.decodeKey(read()))]=read();else for(let i=0;i<token;i++)object[safeKey(read())]=read();return object}else{restoreMapsAsObject&&(currentDecoder.mapsAsObjects=!0,restoreMapsAsObject=!1);let map=new Map;if(currentDecoder.keyMap)for(let i=0;i<token;i++)map.set(currentDecoder.decodeKey(read()),read());else for(let i=0;i<token;i++)map.set(read(),read());return map}case 6:if(token>=BUNDLED_STRINGS_ID){let structure=currentStructures[token&8191];if(structure)return structure.read||(structure.read=createStructureReader(structure)),structure.read();if(token<65536){if(token==RECORD_INLINE_ID){let length=readJustLength(),id=read(),structure2=read();recordDefinition(id,structure2);let object={};if(currentDecoder.keyMap)for(let i=2;i<length;i++){let key=currentDecoder.decodeKey(structure2[i-2]);object[safeKey(key)]=read()}else for(let i=2;i<length;i++){let key=structure2[i-2];object[safeKey(key)]=read()}return object}else if(token==RECORD_DEFINITIONS_ID){let length=readJustLength(),id=read();for(let i=2;i<length;i++)recordDefinition(id++,read());return read()}else if(token==BUNDLED_STRINGS_ID)return readBundleExt();if(currentDecoder.getShared&&(loadShared(),structure=currentStructures[token&8191],structure))return structure.read||(structure.read=createStructureReader(structure)),structure.read()}}let extension=currentExtensions[token];if(extension)return extension.handlesRead?extension(read):extension(read());{let input=read();for(let i=0;i<currentExtensionRanges.length;i++){let value=currentExtensionRanges[i](token,input);if(value!==void 0)return value}return new Tag(input,token)}case 7:switch(token){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;default:let packedValue=(packedValues||getPackedValues())[token];if(packedValue!==void 0)return packedValue;throw new Error("Unknown token "+token)}default:throw isNaN(token)?endOfCBORError():new Error("Unknown CBOR token "+token)}}__name(read,"read");var validName=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function createStructureReader(structure){if(!structure)throw new Error("Structure is required in record definition");function readObject(){let length=src[position++];if(length=length&31,length>23)switch(length){case 24:length=src[position++];break;case 25:length=dataView.getUint16(position),position+=2;break;case 26:length=dataView.getUint32(position),position+=4;break;default:throw new Error("Expected array header, but got "+src[position-1])}let compiledReader=this.compiledReader;for(;compiledReader;){if(compiledReader.propertyCount===length)return compiledReader(read);compiledReader=compiledReader.next}if(this.slowReads++>=inlineObjectReadThreshold){let array=this.length==length?this:this.slice(0,length);return compiledReader=currentDecoder.keyMap?new Function("r","return {"+array.map(k=>currentDecoder.decodeKey(k)).map(k=>validName.test(k)?safeKey(k)+":r()":"["+JSON.stringify(k)+"]:r()").join(",")+"}"):new Function("r","return {"+array.map(key=>validName.test(key)?safeKey(key)+":r()":"["+JSON.stringify(key)+"]:r()").join(",")+"}"),this.compiledReader&&(compiledReader.next=this.compiledReader),compiledReader.propertyCount=length,this.compiledReader=compiledReader,compiledReader(read)}let object={};if(currentDecoder.keyMap)for(let i=0;i<length;i++)object[safeKey(currentDecoder.decodeKey(this[i]))]=read();else for(let i=0;i<length;i++)object[safeKey(this[i])]=read();return object}return __name(readObject,"readObject"),structure.slowReads=0,readObject}__name(createStructureReader,"createStructureReader");function safeKey(key){if(typeof key=="string")return key==="__proto__"?"__proto_":key;if(typeof key=="number"||typeof key=="boolean"||typeof key=="bigint")return key.toString();if(key==null)return key+"";throw new Error("Invalid property name type "+typeof key)}__name(safeKey,"safeKey");var readFixedString=readStringJS;function readStringJS(length){let result;if(length<16&&(result=shortStringInJS(length)))return result;if(length>64&&decoder)return decoder.decode(src.subarray(position,position+=length));let end=position+length,units=[];for(result="";position<end;){let byte1=src[position++];if((byte1&128)===0)units.push(byte1);else if((byte1&224)===192)if(byte1<194||position>=end||(src[position]&192)!==128)units.push(65533);else{let byte2=src[position++]&63;units.push((byte1&31)<<6|byte2)}else if((byte1&240)===224){let byte2=position<end?src[position]:0;if(position>=end||(byte2&192)!==128||byte1===224&&byte2<160||byte1===237&&byte2>=160)units.push(65533);else if(position++,position>=end||(src[position]&192)!==128)units.push(65533);else{let byte3=src[position++]&63;units.push((byte1&31)<<12|(byte2&63)<<6|byte3)}}else if((byte1&248)===240){let byte2=position<end?src[position]:0;if(byte1>244||position>=end||(byte2&192)!==128||byte1===240&&byte2<144||byte1===244&&byte2>=144)units.push(65533);else if(position++,position>=end||(src[position]&192)!==128)units.push(65533);else{let byte3=src[position++]&63;if(position>=end||(src[position]&192)!==128)units.push(65533);else{let byte4=src[position++]&63,unit=(byte1&7)<<18|(byte2&63)<<12|byte3<<6|byte4;unit-=65536,units.push(unit>>>10&1023|55296),units.push(56320|unit&1023)}}}else units.push(65533);units.length>=4096&&(result+=fromCharCode.apply(String,units),units.length=0)}return units.length>0&&(result+=fromCharCode.apply(String,units)),result}__name(readStringJS,"readStringJS");var fromCharCode=String.fromCharCode;function longStringInJS(length){let start=position,bytes=new Array(length);for(let i=0;i<length;i++){let byte=src[position++];if((byte&128)>0){position=start;return}bytes[i]=byte}return fromCharCode.apply(String,bytes)}__name(longStringInJS,"longStringInJS");function shortStringInJS(length){if(length<4)if(length<2){if(length===0)return"";{let a=src[position++];if((a&128)>1){position-=1;return}return fromCharCode(a)}}else{let a=src[position++],b=src[position++];if((a&128)>0||(b&128)>0){position-=2;return}if(length<3)return fromCharCode(a,b);let c=src[position++];if((c&128)>0){position-=3;return}return fromCharCode(a,b,c)}else{let a=src[position++],b=src[position++],c=src[position++],d=src[position++];if((a&128)>0||(b&128)>0||(c&128)>0||(d&128)>0){position-=4;return}if(length<6){if(length===4)return fromCharCode(a,b,c,d);{let e=src[position++];if((e&128)>0){position-=5;return}return fromCharCode(a,b,c,d,e)}}else if(length<8){let e=src[position++],f=src[position++];if((e&128)>0||(f&128)>0){position-=6;return}if(length<7)return fromCharCode(a,b,c,d,e,f);let g=src[position++];if((g&128)>0){position-=7;return}return fromCharCode(a,b,c,d,e,f,g)}else{let e=src[position++],f=src[position++],g=src[position++],h=src[position++];if((e&128)>0||(f&128)>0||(g&128)>0||(h&128)>0){position-=8;return}if(length<10){if(length===8)return fromCharCode(a,b,c,d,e,f,g,h);{let i=src[position++];if((i&128)>0){position-=9;return}return fromCharCode(a,b,c,d,e,f,g,h,i)}}else if(length<12){let i=src[position++],j=src[position++];if((i&128)>0||(j&128)>0){position-=10;return}if(length<11)return fromCharCode(a,b,c,d,e,f,g,h,i,j);let k=src[position++];if((k&128)>0){position-=11;return}return fromCharCode(a,b,c,d,e,f,g,h,i,j,k)}else{let i=src[position++],j=src[position++],k=src[position++],l=src[position++];if((i&128)>0||(j&128)>0||(k&128)>0||(l&128)>0){position-=12;return}if(length<14){if(length===12)return fromCharCode(a,b,c,d,e,f,g,h,i,j,k,l);{let m=src[position++];if((m&128)>0){position-=13;return}return fromCharCode(a,b,c,d,e,f,g,h,i,j,k,l,m)}}else{let m=src[position++],n=src[position++];if((m&128)>0||(n&128)>0){position-=14;return}if(length<15)return fromCharCode(a,b,c,d,e,f,g,h,i,j,k,l,m,n);let o=src[position++];if((o&128)>0){position-=15;return}return fromCharCode(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)}}}}}__name(shortStringInJS,"shortStringInJS");function readBin(length){return currentDecoder.copyBuffers?Uint8Array.prototype.slice.call(src,position,position+=length):src.subarray(position,position+=length)}__name(readBin,"readBin");var f32Array=new Float32Array(1),u8Array=new Uint8Array(f32Array.buffer,0,4);function getFloat16(){let byte0=src[position++],byte1=src[position++],exponent=(byte0&127)>>2;if(exponent===31)return byte1||byte0&3?NaN:byte0&128?-1/0:1/0;if(exponent===0){let abs=((byte0&3)<<8|byte1)/16777216;return byte0&128?-abs:abs}return u8Array[3]=byte0&128|(exponent>>1)+56,u8Array[2]=(byte0&7)<<5|byte1>>3,u8Array[1]=byte1<<5,u8Array[0]=0,f32Array[0]}__name(getFloat16,"getFloat16");var keyCache=new Array(4096);var Tag=class{static{__name(this,"Tag")}constructor(value,tag){this.value=value,this.tag=tag}};currentExtensions[0]=dateString=>new Date(dateString);currentExtensions[1]=epochSec=>new Date(Math.round(epochSec*1e3));currentExtensions[2]=buffer=>{let value=BigInt(0);for(let i=0,l=buffer.byteLength;i<l;i++)value=BigInt(buffer[i])+(value<<BigInt(8));return value};currentExtensions[3]=buffer=>BigInt(-1)-currentExtensions[2](buffer);currentExtensions[4]=fraction=>+(fraction[1]+"e"+fraction[0]);currentExtensions[5]=fraction=>fraction[1]*Math.exp(fraction[0]*Math.log(2));var recordDefinition=__name((id,structure)=>{id=id-57344;let existingStructure=currentStructures[id];existingStructure&&existingStructure.isShared&&((currentStructures.restoreStructures||(currentStructures.restoreStructures=[]))[id]=existingStructure),currentStructures[id]=structure,structure.read=createStructureReader(structure)},"recordDefinition");currentExtensions[LEGACY_RECORD_INLINE_ID]=data=>{let length=data.length,structure=data[1];recordDefinition(data[0],structure);let object={};for(let i=2;i<length;i++){let key=structure[i-2];object[safeKey(key)]=data[i]}return object};currentExtensions[14]=value=>bundledStrings?bundledStrings[0].slice(bundledStrings.position0,bundledStrings.position0+=value):new Tag(value,14);currentExtensions[15]=value=>bundledStrings?bundledStrings[1].slice(bundledStrings.position1,bundledStrings.position1+=value):new Tag(value,15);var glbl={Error,RegExp};currentExtensions[27]=data=>(glbl[data[0]]||Error)(data[1],data[2]);var packedTable=__name(read2=>{if(src[position++]!=132){let error=new Error("Packed values structure must be followed by a 4 element array");throw src.length<position&&(error.incomplete=!0),error}let newPackedValues=read2();if(!newPackedValues||!newPackedValues.length){let error=new Error("Packed values structure must be followed by a 4 element array");throw error.incomplete=!0,error}return packedValues=packedValues?newPackedValues.concat(packedValues.slice(newPackedValues.length)):newPackedValues,packedValues.prefixes=read2(),packedValues.suffixes=read2(),read2()},"packedTable");packedTable.handlesRead=!0;currentExtensions[51]=packedTable;currentExtensions[PACKED_REFERENCE_TAG_ID]=data=>{if(!packedValues)if(currentDecoder.getShared)loadShared();else return new Tag(data,PACKED_REFERENCE_TAG_ID);if(typeof data=="number")return packedValues[16+(data>=0?2*data:-2*data-1)];let error=new Error("No support for non-integer packed references yet");throw data===void 0&&(error.incomplete=!0),error};currentExtensions[28]=read2=>{referenceMap||(referenceMap=new Map,referenceMap.id=0);let id=referenceMap.id++,startingPosition=position,token=src[position],target2;token>>5==4?target2=[]:target2={};let refEntry={target:target2};referenceMap.set(id,refEntry);let targetProperties=read2();return refEntry.used?(Object.getPrototypeOf(target2)!==Object.getPrototypeOf(targetProperties)&&(position=startingPosition,target2=targetProperties,referenceMap.set(id,{target:target2}),targetProperties=read2()),Object.assign(target2,targetProperties)):(refEntry.target=targetProperties,targetProperties)};currentExtensions[28].handlesRead=!0;currentExtensions[29]=id=>{let refEntry=referenceMap.get(id);return refEntry.used=!0,refEntry.target};currentExtensions[258]=array=>new Set(array);(currentExtensions[259]=read2=>(currentDecoder.mapsAsObjects&&(currentDecoder.mapsAsObjects=!1,restoreMapsAsObject=!0),read2())).handlesRead=!0;function combine(a,b){return typeof a=="string"?a+b:a instanceof Array?a.concat(b):Object.assign({},a,b)}__name(combine,"combine");function getPackedValues(){if(!packedValues)if(currentDecoder.getShared)loadShared();else throw new Error("No packed values available");return packedValues}__name(getPackedValues,"getPackedValues");var SHARED_DATA_TAG_ID=1399353956;currentExtensionRanges.push((tag,input)=>{if(tag>=225&&tag<=255)return combine(getPackedValues().prefixes[tag-224],input);if(tag>=28704&&tag<=32767)return combine(getPackedValues().prefixes[tag-28672],input);if(tag>=1879052288&&tag<=2147483647)return combine(getPackedValues().prefixes[tag-1879048192],input);if(tag>=216&&tag<=223)return combine(input,getPackedValues().suffixes[tag-216]);if(tag>=27647&&tag<=28671)return combine(input,getPackedValues().suffixes[tag-27639]);if(tag>=1811940352&&tag<=1879048191)return combine(input,getPackedValues().suffixes[tag-1811939328]);if(tag==SHARED_DATA_TAG_ID)return{packedValues,structures:currentStructures.slice(0),version:input};if(tag==55799)return input});var isLittleEndianMachine=new Uint8Array(new Uint16Array([1]).buffer)[0]==1,typedArrays=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array],typedArrayTags=[64,68,69,70,71,72,77,78,79,85,86];for(let i=0;i<typedArrays.length;i++)registerTypedArray(typedArrays[i],typedArrayTags[i]);function registerTypedArray(TypedArray,tag){let dvMethod="get"+TypedArray.name.slice(0,-5),bytesPerElement;typeof TypedArray=="function"?bytesPerElement=TypedArray.BYTES_PER_ELEMENT:TypedArray=null;for(let littleEndian=0;littleEndian<2;littleEndian++){if(!littleEndian&&bytesPerElement==1)continue;let sizeShift=bytesPerElement==2?1:bytesPerElement==4?2:bytesPerElement==8?3:0;currentExtensions[littleEndian?tag:tag-4]=bytesPerElement==1||littleEndian==isLittleEndianMachine?buffer=>{if(!TypedArray)throw new Error("Could not find typed array for code "+tag);return!currentDecoder.copyBuffers&&(bytesPerElement===1||bytesPerElement===2&&!(buffer.byteOffset&1)||bytesPerElement===4&&!(buffer.byteOffset&3)||bytesPerElement===8&&!(buffer.byteOffset&7))?new TypedArray(buffer.buffer,buffer.byteOffset,buffer.byteLength>>sizeShift):new TypedArray(Uint8Array.prototype.slice.call(buffer,0).buffer)}:buffer=>{if(!TypedArray)throw new Error("Could not find typed array for code "+tag);let dv=new DataView(buffer.buffer,buffer.byteOffset,buffer.byteLength),elements=buffer.length>>sizeShift,ta=new TypedArray(elements),method=dv[dvMethod];for(let i=0;i<elements;i++)ta[i]=method.call(dv,i<<sizeShift,littleEndian);return ta}}}__name(registerTypedArray,"registerTypedArray");function readBundleExt(){let length=readJustLength(),bundlePosition=position+read();for(let i=2;i<length;i++){let bundleLength=readJustLength();position+=bundleLength}let dataPosition=position;return position=bundlePosition,bundledStrings=[readStringJS(readJustLength()),readStringJS(readJustLength())],bundledStrings.position0=0,bundledStrings.position1=0,bundledStrings.postBundlePosition=position,position=dataPosition,read()}__name(readBundleExt,"readBundleExt");function readJustLength(){if(!(position<srcEnd))throw endOfCBORError();let token=src[position++]&31;if(token>23)switch(token){case 24:if(position>=srcEnd)throw endOfCBORError();token=src[position++];break;case 25:token=dataView.getUint16(position),position+=2;break;case 26:token=dataView.getUint32(position),position+=4;break}return token}__name(readJustLength,"readJustLength");function loadShared(){if(currentDecoder.getShared){let sharedData=saveState(()=>(src=null,currentDecoder.getShared()))||{},updatedStructures=sharedData.structures||[];currentDecoder.sharedVersion=sharedData.version,packedValues=currentDecoder.sharedValues=sharedData.packedValues,currentStructures===!0?currentDecoder.structures=currentStructures=updatedStructures:currentStructures.splice.apply(currentStructures,[0,updatedStructures.length].concat(updatedStructures))}}__name(loadShared,"loadShared");function saveState(callback){let savedSrcEnd=srcEnd,savedPosition=position,savedStringPosition=stringPosition,savedSrcStringStart=srcStringStart,savedSrcStringEnd=srcStringEnd,savedSrcString=srcString,savedStrings=strings,savedReferenceMap=referenceMap,savedBundledStrings=bundledStrings,savedSrc=new Uint8Array(src.slice(0,srcEnd)),savedStructures=currentStructures,savedDecoder=currentDecoder,savedSequentialMode=sequentialMode,value=callback();return srcEnd=savedSrcEnd,position=savedPosition,stringPosition=savedStringPosition,srcStringStart=savedSrcStringStart,srcStringEnd=savedSrcStringEnd,srcString=savedSrcString,strings=savedStrings,referenceMap=savedReferenceMap,bundledStrings=savedBundledStrings,src=savedSrc,sequentialMode=savedSequentialMode,currentStructures=savedStructures,currentDecoder=savedDecoder,dataView=new DataView(src.buffer,src.byteOffset,src.byteLength),value}__name(saveState,"saveState");function clearSource(){src=null,referenceMap=null,currentStructures=null}__name(clearSource,"clearSource");var mult10=new Array(147);for(let i=0;i<256;i++)mult10[i]=+("1e"+Math.floor(45.15-i*.30103));var defaultDecoder=new Decoder({useRecords:!1}),decode=defaultDecoder.decode,decodeMultiple=defaultDecoder.decodeMultiple,FLOAT32_OPTIONS={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};var textEncoder;try{textEncoder=new TextEncoder}catch{}var extensions,extensionClasses,Buffer2=typeof globalThis=="object"&&globalThis.Buffer,hasNodeBuffer=typeof Buffer2<"u",ByteArrayAllocate=hasNodeBuffer?Buffer2.allocUnsafeSlow:Uint8Array,ByteArray=hasNodeBuffer?Buffer2:Uint8Array,MAX_STRUCTURES=256,MAX_BUFFER_SIZE=hasNodeBuffer?4294967296:2144337920;var throwOnIterable,target,targetView,position2=0,safeEnd,bundledStrings2=null,MAX_BUNDLE_SIZE=61440,hasNonLatin=/[\u0080-\uFFFF]/,RECORD_SYMBOL=Symbol("record-id"),Encoder=class extends Decoder{static{__name(this,"Encoder")}constructor(options){super(options),this.offset=0;let typeBuffer,start,sharedStructures,hasSharedUpdate,structures,referenceMap2;options=options||{};let encodeUtf8=ByteArray.prototype.utf8Write?function(string,position3){return target.utf8Write(string,position3,target.byteLength-position3)}:textEncoder&&textEncoder.encodeInto?function(string,position3){return textEncoder.encodeInto(string,target.subarray(position3)).written}:!1,encoder=this,hasSharedStructures=options.structures||options.saveStructures,maxSharedStructures=options.maxSharedStructures;if(maxSharedStructures==null&&(maxSharedStructures=hasSharedStructures?128:0),maxSharedStructures>8190)throw new Error("Maximum maxSharedStructure is 8190");let isSequential=options.sequential;isSequential&&(maxSharedStructures=0),this.structures||(this.structures=[]),this.saveStructures&&(this.saveShared=this.saveStructures);let samplingPackedValues,packedObjectMap2,sharedValues=options.sharedValues,sharedPackedObjectMap2;if(sharedValues){sharedPackedObjectMap2=Object.create(null);for(let i=0,l=sharedValues.length;i<l;i++)sharedPackedObjectMap2[sharedValues[i]]=i}let recordIdsToRemove=[],transitionsCount=0,serializationsSinceTransitionRebuild=0;this.mapEncode=function(value,encodeOptions){return this._keyMap&&!this._mapped&&value.constructor.name==="Array"&&(value=value.map(r=>this.encodeKeys(r))),this.encode(value,encodeOptions)},this.encode=function(value,encodeOptions){if(target||(target=new ByteArrayAllocate(8192),targetView=new DataView(target.buffer,0,8192),position2=0),safeEnd=target.length-10,safeEnd-position2<2048?(target=new ByteArrayAllocate(target.length),targetView=new DataView(target.buffer,0,target.length),safeEnd=target.length-10,position2=0):encodeOptions===REUSE_BUFFER_MODE&&(position2=position2+7&2147483640),start=position2,encoder.useSelfDescribedHeader&&(targetView.setUint32(position2,3654940416),position2+=3),referenceMap2=encoder.structuredClone?new Map:null,encoder.bundleStrings&&typeof value!="string"?(bundledStrings2=[],bundledStrings2.size=1/0):bundledStrings2=null,sharedStructures=encoder.structures,sharedStructures){if(sharedStructures.uninitialized){let sharedData=encoder.getShared()||{};encoder.structures=sharedStructures=sharedData.structures||[],encoder.sharedVersion=sharedData.version;let sharedValues2=encoder.sharedValues=sharedData.packedValues;if(sharedValues2){sharedPackedObjectMap2={};for(let i=0,l=sharedValues2.length;i<l;i++)sharedPackedObjectMap2[sharedValues2[i]]=i}}let sharedStructuresLength=sharedStructures.length;if(sharedStructuresLength>maxSharedStructures&&!isSequential&&(sharedStructuresLength=maxSharedStructures),!sharedStructures.transitions){sharedStructures.transitions=Object.create(null);for(let i=0;i<sharedStructuresLength;i++){let keys=sharedStructures[i];if(!keys)continue;let nextTransition,transition=sharedStructures.transitions;for(let j=0,l=keys.length;j<l;j++){transition[RECORD_SYMBOL]===void 0&&(transition[RECORD_SYMBOL]=i);let key=keys[j];nextTransition=transition[key],nextTransition||(nextTransition=transition[key]=Object.create(null)),transition=nextTransition}transition[RECORD_SYMBOL]=i|1048576}}isSequential||(sharedStructures.nextId=sharedStructuresLength)}if(hasSharedUpdate&&(hasSharedUpdate=!1),structures=sharedStructures||[],packedObjectMap2=sharedPackedObjectMap2,options.pack){let packedValues2=new Map;if(packedValues2.values=[],packedValues2.encoder=encoder,packedValues2.maxValues=options.maxPrivatePackedValues||(sharedPackedObjectMap2?16:1/0),packedValues2.objectMap=sharedPackedObjectMap2||!1,packedValues2.samplingPackedValues=samplingPackedValues,findRepetitiveStrings(value,packedValues2),packedValues2.values.length>0){target[position2++]=216,target[position2++]=51,writeArrayHeader(4);let valuesArray=packedValues2.values;encode2(valuesArray),writeArrayHeader(0),writeArrayHeader(0),packedObjectMap2=Object.create(sharedPackedObjectMap2||null);for(let i=0,l=valuesArray.length;i<l;i++)packedObjectMap2[valuesArray[i]]=i}}throwOnIterable=encodeOptions&THROW_ON_ITERABLE;try{if(throwOnIterable)return;if(encode2(value),bundledStrings2&&writeBundles(start,encode2),encoder.offset=position2,referenceMap2&&referenceMap2.idsToInsert){position2+=referenceMap2.idsToInsert.length*2,position2>safeEnd&&makeRoom(position2),encoder.offset=position2;let serialized=insertIds(target.subarray(start,position2),referenceMap2.idsToInsert);return referenceMap2=null,serialized}return encodeOptions&REUSE_BUFFER_MODE?(target.start=start,target.end=position2,target):target.subarray(start,position2)}finally{if(sharedStructures){if(serializationsSinceTransitionRebuild<10&&serializationsSinceTransitionRebuild++,sharedStructures.length>maxSharedStructures&&(sharedStructures.length=maxSharedStructures),transitionsCount>1e4)sharedStructures.transitions=null,serializationsSinceTransitionRebuild=0,transitionsCount=0,recordIdsToRemove.length>0&&(recordIdsToRemove=[]);else if(recordIdsToRemove.length>0&&!isSequential){for(let i=0,l=recordIdsToRemove.length;i<l;i++)recordIdsToRemove[i][RECORD_SYMBOL]=void 0;recordIdsToRemove=[]}}if(hasSharedUpdate&&encoder.saveShared){encoder.structures.length>maxSharedStructures&&(encoder.structures=encoder.structures.slice(0,maxSharedStructures));let returnBuffer=target.subarray(start,position2);return encoder.updateSharedData()===!1?encoder.encode(value):returnBuffer}encodeOptions&RESET_BUFFER_MODE&&(position2=start)}},this.findCommonStringsToPack=()=>(samplingPackedValues=new Map,sharedPackedObjectMap2||(sharedPackedObjectMap2=Object.create(null)),options2=>{let threshold=options2&&options2.threshold||4,position3=this.pack?options2.maxPrivatePackedValues||16:0;sharedValues||(sharedValues=this.sharedValues=[]);for(let[key,status]of samplingPackedValues)status.count>threshold&&(sharedPackedObjectMap2[key]=position3++,sharedValues.push(key),hasSharedUpdate=!0);for(;this.saveShared&&this.updateSharedData()===!1;);samplingPackedValues=null});let encode2=__name(value=>{position2>safeEnd&&(target=makeRoom(position2));var type=typeof value,length;if(type==="string"){if(packedObjectMap2){let packedPosition=packedObjectMap2[value];if(packedPosition>=0){packedPosition<16?target[position2++]=packedPosition+224:(target[position2++]=198,packedPosition&1?encode2(15-packedPosition>>1):encode2(packedPosition-16>>1));return}else if(samplingPackedValues&&!options.pack){let status=samplingPackedValues.get(value);status?status.count++:samplingPackedValues.set(value,{count:1})}}let strLength=value.length;if(bundledStrings2&&strLength>=4&&strLength<1024){if((bundledStrings2.size+=strLength)>MAX_BUNDLE_SIZE){let extStart,maxBytes2=(bundledStrings2[0]?bundledStrings2[0].length*3+bundledStrings2[1].length:0)+10;position2+maxBytes2>safeEnd&&(target=makeRoom(position2+maxBytes2)),target[position2++]=217,target[position2++]=223,target[position2++]=249,target[position2++]=bundledStrings2.position?132:130,target[position2++]=26,extStart=position2-start,position2+=4,bundledStrings2.position&&writeBundles(start,encode2),bundledStrings2=["",""],bundledStrings2.size=0,bundledStrings2.position=extStart}let twoByte=hasNonLatin.test(value);bundledStrings2[twoByte?0:1]+=value,target[position2++]=twoByte?206:207,encode2(strLength);return}let headerSize;strLength<32?headerSize=1:strLength<256?headerSize=2:strLength<65536?headerSize=3:headerSize=5;let maxBytes=strLength*3;if(position2+maxBytes>safeEnd&&(target=makeRoom(position2+maxBytes)),strLength<64||!encodeUtf8){let i,c1,c2,strPosition=position2+headerSize;for(i=0;i<strLength;i++)c1=value.charCodeAt(i),c1<128?target[strPosition++]=c1:c1<2048?(target[strPosition++]=c1>>6|192,target[strPosition++]=c1&63|128):(c1&64512)===55296&&((c2=value.charCodeAt(i+1))&64512)===56320?(c1=65536+((c1&1023)<<10)+(c2&1023),i++,target[strPosition++]=c1>>18|240,target[strPosition++]=c1>>12&63|128,target[strPosition++]=c1>>6&63|128,target[strPosition++]=c1&63|128):(target[strPosition++]=c1>>12|224,target[strPosition++]=c1>>6&63|128,target[strPosition++]=c1&63|128);length=strPosition-position2-headerSize}else length=encodeUtf8(value,position2+headerSize,maxBytes);length<24?target[position2++]=96|length:length<256?(headerSize<2&&target.copyWithin(position2+2,position2+1,position2+1+length),target[position2++]=120,target[position2++]=length):length<65536?(headerSize<3&&target.copyWithin(position2+3,position2+2,position2+2+length),target[position2++]=121,target[position2++]=length>>8,target[position2++]=length&255):(headerSize<5&&target.copyWithin(position2+5,position2+3,position2+3+length),target[position2++]=122,targetView.setUint32(position2,length),position2+=4),position2+=length}else if(type==="number")if(!this.alwaysUseFloat&&value>>>0===value)value<24?target[position2++]=value:value<256?(target[position2++]=24,target[position2++]=value):value<65536?(target[position2++]=25,target[position2++]=value>>8,target[position2++]=value&255):(target[position2++]=26,targetView.setUint32(position2,value),position2+=4);else if(!this.alwaysUseFloat&&value>>0===value)value>=-24?target[position2++]=31-value:value>=-256?(target[position2++]=56,target[position2++]=~value):value>=-65536?(target[position2++]=57,targetView.setUint16(position2,~value),position2+=2):(target[position2++]=58,targetView.setUint32(position2,~value),position2+=4);else if(!this.alwaysUseFloat&&value<0&&value>=-4294967296&&Math.floor(value)===value)target[position2++]=58,targetView.setUint32(position2,-1-value),position2+=4;else{let useFloat32;if((useFloat32=this.useFloat32)>0&&value<4294967296&&value>=-2147483648){target[position2++]=250,targetView.setFloat32(position2,value);let xShifted;if(useFloat32<4||(xShifted=value*mult10[(target[position2]&127)<<1|target[position2+1]>>7])>>0===xShifted){position2+=4;return}else position2--}target[position2++]=251,targetView.setFloat64(position2,value),position2+=8}else if(type==="object")if(!value)target[position2++]=246;else{if(referenceMap2){let referee=referenceMap2.get(value);if(referee){if(target[position2++]=216,target[position2++]=29,target[position2++]=25,!referee.references){let idsToInsert=referenceMap2.idsToInsert||(referenceMap2.idsToInsert=[]);referee.references=[],idsToInsert.push(referee)}referee.references.push(position2-start),position2+=2;return}else referenceMap2.set(value,{offset:position2-start})}let constructor=value.constructor;if(constructor===Object)this.skipFunction===!0&&(value=Object.fromEntries([...Object.keys(value).filter(x=>typeof value[x]!="function").map(x=>[x,value[x]])])),writeObject(value);else if(constructor===Array){length=value.length,length<24?target[position2++]=128|length:writeArrayHeader(length);for(let i=0;i<length;i++)encode2(value[i])}else if(constructor===Map)if((this.mapsAsObjects?this.useTag259ForMaps!==!1:this.useTag259ForMaps)&&(target[position2++]=217,target[position2++]=1,target[position2++]=3),length=value.size,length<24?target[position2++]=160|length:length<256?(target[position2++]=184,target[position2++]=length):length<65536?(target[position2++]=185,target[position2++]=length>>8,target[position2++]=length&255):(target[position2++]=186,targetView.setUint32(position2,length),position2+=4),encoder.keyMap)for(let[key,entryValue]of value)encode2(encoder.encodeKey(key)),encode2(entryValue);else for(let[key,entryValue]of value)encode2(key),encode2(entryValue);else{for(let i=0,l=extensions.length;i<l;i++){let extensionClass=extensionClasses[i];if(value instanceof extensionClass){let extension=extensions[i],tag=extension.tag;tag==null&&(tag=extension.getTag&&extension.getTag.call(this,value)),tag<24?target[position2++]=192|tag:tag<256?(target[position2++]=216,target[position2++]=tag):tag<65536?(target[position2++]=217,target[position2++]=tag>>8,target[position2++]=tag&255):tag>-1&&(target[position2++]=218,targetView.setUint32(position2,tag),position2+=4),extension.encode.call(this,value,encode2,makeRoom);return}}if(value[Symbol.iterator]){if(throwOnIterable){let error=new Error("Iterable should be serialized as iterator");throw error.iteratorNotHandled=!0,error}target[position2++]=159;for(let entry of value)encode2(entry);target[position2++]=255;return}if(value[Symbol.asyncIterator]||isBlob(value)){let error=new Error("Iterable/blob should be serialized as iterator");throw error.iteratorNotHandled=!0,error}if(this.useToJSON&&value.toJSON){let json=value.toJSON();if(json!==value)return encode2(json)}writeObject(value)}}else if(type==="boolean")target[position2++]=value?245:244;else if(type==="bigint"){if(value<BigInt(1)<<BigInt(64)&&value>=0)target[position2++]=27,targetView.setBigUint64(position2,value);else if(value>-(BigInt(1)<<BigInt(64))&&value<0)target[position2++]=59,targetView.setBigUint64(position2,-value-BigInt(1));else if(this.largeBigIntToFloat)target[position2++]=251,targetView.setFloat64(position2,Number(value));else{value>=BigInt(0)?target[position2++]=194:(target[position2++]=195,value=BigInt(-1)-value);let bytes=[];for(;value;)bytes.push(Number(value&BigInt(255))),value>>=BigInt(8);writeBuffer(new Uint8Array(bytes.reverse()),makeRoom);return}position2+=8}else if(type==="undefined")target[position2++]=247;else throw new Error("Unknown type: "+type)},"encode"),writeObject=this.useRecords===!1?this.variableMapSize?object=>{let keys=Object.keys(object),vals=Object.values(object),length=keys.length;length<24?target[position2++]=160|length:length<256?(target[position2++]=184,target[position2++]=length):length<65536?(target[position2++]=185,target[position2++]=length>>8,target[position2++]=length&255):(target[position2++]=186,targetView.setUint32(position2,length),position2+=4);let key;if(encoder.keyMap)for(let i=0;i<length;i++)encode2(encoder.encodeKey(keys[i])),encode2(vals[i]);else for(let i=0;i<length;i++)encode2(keys[i]),encode2(vals[i])}:object=>{target[position2++]=185;let objectOffset=position2-start;position2+=2;let size=0;if(encoder.keyMap)for(let key in object)(typeof object.hasOwnProperty!="function"||object.hasOwnProperty(key))&&(encode2(encoder.encodeKey(key)),encode2(object[key]),size++);else for(let key in object)(typeof object.hasOwnProperty!="function"||object.hasOwnProperty(key))&&(encode2(key),encode2(object[key]),size++);target[objectOffset+++start]=size>>8,target[objectOffset+start]=size&255}:(object,skipValues)=>{let nextTransition,transition=structures.transitions||(structures.transitions=Object.create(null)),newTransitions=0,length=0,parentRecordId,keys;if(this.keyMap){keys=Object.keys(object).map(k=>this.encodeKey(k)),length=keys.length;for(let i=0;i<length;i++){let key=keys[i];nextTransition=transition[key],nextTransition||(nextTransition=transition[key]=Object.create(null),newTransitions++),transition=nextTransition}}else for(let key in object)(typeof object.hasOwnProperty!="function"||object.hasOwnProperty(key))&&(nextTransition=transition[key],nextTransition||(transition[RECORD_SYMBOL]&1048576&&(parentRecordId=transition[RECORD_SYMBOL]&65535),nextTransition=transition[key]=Object.create(null),newTransitions++),transition=nextTransition,length++);let recordId=transition[RECORD_SYMBOL];if(recordId!==void 0)recordId&=65535,target[position2++]=217,target[position2++]=recordId>>8|224,target[position2++]=recordId&255;else if(keys||(keys=transition.__keys__||(transition.__keys__=Object.keys(object))),parentRecordId===void 0?(recordId=structures.nextId++,recordId||(recordId=0,structures.nextId=1),recordId>=MAX_STRUCTURES&&(structures.nextId=(recordId=maxSharedStructures)+1)):recordId=parentRecordId,structures[recordId]=keys,recordId<maxSharedStructures){target[position2++]=217,target[position2++]=recordId>>8|224,target[position2++]=recordId&255,transition=structures.transitions;for(let i=0;i<length;i++)(transition[RECORD_SYMBOL]===void 0||transition[RECORD_SYMBOL]&1048576)&&(transition[RECORD_SYMBOL]=recordId),transition=transition[keys[i]];transition[RECORD_SYMBOL]=recordId|1048576,hasSharedUpdate=!0}else{if(transition[RECORD_SYMBOL]=recordId,targetView.setUint32(position2,3655335680),position2+=3,newTransitions&&(transitionsCount+=serializationsSinceTransitionRebuild*newTransitions),recordIdsToRemove.length>=MAX_STRUCTURES-maxSharedStructures&&(recordIdsToRemove.shift()[RECORD_SYMBOL]=void 0),recordIdsToRemove.push(transition),writeArrayHeader(length+2),encode2(57344+recordId),encode2(keys),skipValues)return;for(let key in object)(typeof object.hasOwnProperty!="function"||object.hasOwnProperty(key))&&encode2(object[key]);return}if(length<24?target[position2++]=128|length:writeArrayHeader(length),!skipValues)for(let key in object)(typeof object.hasOwnProperty!="function"||object.hasOwnProperty(key))&&encode2(object[key])},makeRoom=__name(end=>{let newSize;if(end>16777216){if(end-start>MAX_BUFFER_SIZE)throw new Error("Encoded buffer would be larger than maximum buffer size");newSize=Math.min(MAX_BUFFER_SIZE,Math.round(Math.max((end-start)*(end>67108864?1.25:2),4194304)/4096)*4096)}else newSize=(Math.max(end-start<<2,target.length-1)>>12)+1<<12;let newBuffer=new ByteArrayAllocate(newSize);return targetView=new DataView(newBuffer.buffer,0,newSize),target.copy?target.copy(newBuffer,0,start,end):newBuffer.set(target.slice(start,end)),position2-=start,start=0,safeEnd=newBuffer.length-10,target=newBuffer},"makeRoom"),chunkThreshold=100,continuedChunkThreshold=1e3;this.encodeAsIterable=function(value,options2){return startEncoding(value,options2,encodeObjectAsIterable)},this.encodeAsAsyncIterable=function(value,options2){return startEncoding(value,options2,encodeObjectAsAsyncIterable)};function*encodeObjectAsIterable(object,iterateProperties,finalIterable){let constructor=object.constructor;if(constructor===Object){let useRecords=encoder.useRecords!==!1;useRecords?writeObject(object,!0):writeEntityLength(Object.keys(object).length,160);for(let key in object){let value=object[key];useRecords||encode2(key),value&&typeof value=="object"?iterateProperties[key]?yield*encodeObjectAsIterable(value,iterateProperties[key]):yield*tryEncode(value,iterateProperties,key):encode2(value)}}else if(constructor===Array){let length=object.length;writeArrayHeader(length);for(let i=0;i<length;i++){let value=object[i];value&&(typeof value=="object"||position2-start>chunkThreshold)?iterateProperties.element?yield*encodeObjectAsIterable(value,iterateProperties.element):yield*tryEncode(value,iterateProperties,"element"):encode2(value)}}else if(object[Symbol.iterator]&&!object.buffer){target[position2++]=159;for(let value of object)value&&(typeof value=="object"||position2-start>chunkThreshold)?iterateProperties.element?yield*encodeObjectAsIterable(value,iterateProperties.element):yield*tryEncode(value,iterateProperties,"element"):encode2(value);target[position2++]=255}else isBlob(object)?(writeEntityLength(object.size,64),yield target.subarray(start,position2),yield object,restartEncoding()):object[Symbol.asyncIterator]?(target[position2++]=159,yield target.subarray(start,position2),yield object,restartEncoding(),target[position2++]=255):encode2(object);finalIterable&&position2>start?yield target.subarray(start,position2):position2-start>chunkThreshold&&(yield target.subarray(start,position2),restartEncoding())}__name(encodeObjectAsIterable,"encodeObjectAsIterable");function*tryEncode(value,iterateProperties,key){let restart=position2-start;try{encode2(value),position2-start>chunkThreshold&&(yield target.subarray(start,position2),restartEncoding())}catch(error){if(error.iteratorNotHandled)iterateProperties[key]={},position2=start+restart,yield*encodeObjectAsIterable.call(this,value,iterateProperties[key]);else throw error}}__name(tryEncode,"tryEncode");function restartEncoding(){chunkThreshold=continuedChunkThreshold,encoder.encode(null,THROW_ON_ITERABLE)}__name(restartEncoding,"restartEncoding");function startEncoding(value,options2,encodeIterable){return options2&&options2.chunkThreshold?chunkThreshold=continuedChunkThreshold=options2.chunkThreshold:chunkThreshold=100,value&&typeof value=="object"?(encoder.encode(null,THROW_ON_ITERABLE),encodeIterable(value,encoder.iterateProperties||(encoder.iterateProperties={}),!0)):[encoder.encode(value)]}__name(startEncoding,"startEncoding");async function*encodeObjectAsAsyncIterable(value,iterateProperties){for(let encodedValue of encodeObjectAsIterable(value,iterateProperties,!0)){let constructor=encodedValue.constructor;if(constructor===ByteArray||constructor===Uint8Array)yield encodedValue;else if(isBlob(encodedValue)){let reader=encodedValue.stream().getReader(),next;for(;!(next=await reader.read()).done;)yield next.value}else if(encodedValue[Symbol.asyncIterator])for await(let asyncValue of encodedValue)restartEncoding(),asyncValue?yield*encodeObjectAsAsyncIterable(asyncValue,iterateProperties.async||(iterateProperties.async={})):yield encoder.encode(asyncValue);else yield encodedValue}}__name(encodeObjectAsAsyncIterable,"encodeObjectAsAsyncIterable")}useBuffer(buffer){target=buffer,targetView=new DataView(target.buffer,target.byteOffset,target.byteLength),position2=0}clearSharedData(){this.structures&&(this.structures=[]),this.sharedValues&&(this.sharedValues=void 0)}updateSharedData(){let lastVersion=this.sharedVersion||0;this.sharedVersion=lastVersion+1;let structuresCopy=this.structures.slice(0),sharedData=new SharedData(structuresCopy,this.sharedValues,this.sharedVersion),saveResults=this.saveShared(sharedData,existingShared=>(existingShared&&existingShared.version||0)==lastVersion);return saveResults===!1?(sharedData=this.getShared()||{},this.structures=sharedData.structures||[],this.sharedValues=sharedData.packedValues,this.sharedVersion=sharedData.version,this.structures.nextId=this.structures.length):structuresCopy.forEach((structure,i)=>this.structures[i]=structure),saveResults}};function writeEntityLength(length,majorValue){length<24?target[position2++]=majorValue|length:length<256?(target[position2++]=majorValue|24,target[position2++]=length):length<65536?(target[position2++]=majorValue|25,target[position2++]=length>>8,target[position2++]=length&255):(target[position2++]=majorValue|26,targetView.setUint32(position2,length),position2+=4)}__name(writeEntityLength,"writeEntityLength");var SharedData=class{static{__name(this,"SharedData")}constructor(structures,values,version){this.structures=structures,this.packedValues=values,this.version=version}};function writeArrayHeader(length){length<24?target[position2++]=128|length:length<256?(target[position2++]=152,target[position2++]=length):length<65536?(target[position2++]=153,target[position2++]=length>>8,target[position2++]=length&255):(target[position2++]=154,targetView.setUint32(position2,length),position2+=4)}__name(writeArrayHeader,"writeArrayHeader");var BlobConstructor=typeof Blob>"u"?function(){}:Blob;function isBlob(object){if(object instanceof BlobConstructor)return!0;let tag=object[Symbol.toStringTag];return tag==="Blob"||tag==="File"}__name(isBlob,"isBlob");function findRepetitiveStrings(value,packedValues2){switch(typeof value){case"string":if(value.length>3){if(packedValues2.objectMap[value]>-1||packedValues2.values.length>=packedValues2.maxValues)return;let packedStatus=packedValues2.get(value);if(packedStatus)++packedStatus.count==2&&packedValues2.values.push(value);else if(packedValues2.set(value,{count:1}),packedValues2.samplingPackedValues){let status=packedValues2.samplingPackedValues.get(value);status?status.count++:packedValues2.samplingPackedValues.set(value,{count:1})}}break;case"object":if(value)if(value instanceof Array)for(let i=0,l=value.length;i<l;i++)findRepetitiveStrings(value[i],packedValues2);else{let includeKeys=!packedValues2.encoder.useRecords;for(var key in value)value.hasOwnProperty(key)&&(includeKeys&&findRepetitiveStrings(key,packedValues2),findRepetitiveStrings(value[key],packedValues2))}break;case"function":console.log(value)}}__name(findRepetitiveStrings,"findRepetitiveStrings");var isLittleEndianMachine2=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;extensionClasses=[Date,Set,Error,RegExp,Tag,ArrayBuffer,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?function(){}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?function(){}:BigInt64Array,Float32Array,Float64Array,SharedData];extensions=[{tag:1,encode(date,encode2){let seconds=date.getTime()/1e3;(this.useTimestamp32||date.getMilliseconds()===0)&&seconds>=0&&seconds<4294967296?(target[position2++]=26,targetView.setUint32(position2,seconds),position2+=4):(target[position2++]=251,targetView.setFloat64(position2,seconds),position2+=8)}},{tag:258,encode(set,encode2){let array=Array.from(set);encode2(array)}},{tag:27,encode(error,encode2){encode2([error.name,error.message])}},{tag:27,encode(regex,encode2){encode2(["RegExp",regex.source,regex.flags])}},{getTag(tag){return tag.tag},encode(tag,encode2){encode2(tag.value)}},{encode(arrayBuffer,encode2,makeRoom){writeBuffer(arrayBuffer,makeRoom)}},{getTag(typedArray){if(typedArray.constructor===Uint8Array&&(this.tagUint8Array||hasNodeBuffer&&this.tagUint8Array!==!1))return 64},encode(typedArray,encode2,makeRoom){writeBuffer(typedArray,makeRoom)}},typedArrayEncoder(68,1),typedArrayEncoder(69,2),typedArrayEncoder(70,4),typedArrayEncoder(71,8),typedArrayEncoder(72,1),typedArrayEncoder(77,2),typedArrayEncoder(78,4),typedArrayEncoder(79,8),typedArrayEncoder(85,4),typedArrayEncoder(86,8),{encode(sharedData,encode2){let packedValues2=sharedData.packedValues||[],sharedStructures=sharedData.structures||[];if(packedValues2.values.length>0){target[position2++]=216,target[position2++]=51,writeArrayHeader(4);let valuesArray=packedValues2.values;encode2(valuesArray),writeArrayHeader(0),writeArrayHeader(0),packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let i=0,l=valuesArray.length;i<l;i++)packedObjectMap[valuesArray[i]]=i}if(sharedStructures){targetView.setUint32(position2,3655335424),position2+=3;let definitions=sharedStructures.slice(0);definitions.unshift(57344),definitions.push(new Tag(sharedData.version,1399353956)),encode2(definitions)}else encode2(new Tag(sharedData.version,1399353956))}}];function typedArrayEncoder(tag,size){return!isLittleEndianMachine2&&size>1&&(tag-=4),{tag,encode:__name(function(typedArray,encode2){let length=typedArray.byteLength,offset=typedArray.byteOffset||0,buffer=typedArray.buffer||typedArray;encode2(hasNodeBuffer?Buffer2.from(buffer,offset,length):new Uint8Array(buffer,offset,length))},"writeExtBuffer")}}__name(typedArrayEncoder,"typedArrayEncoder");function writeBuffer(buffer,makeRoom){let length=buffer.byteLength;length<24?target[position2++]=64+length:length<256?(target[position2++]=88,target[position2++]=length):length<65536?(target[position2++]=89,target[position2++]=length>>8,target[position2++]=length&255):(target[position2++]=90,targetView.setUint32(position2,length),position2+=4),position2+length>=target.length&&makeRoom(position2+length),target.set(buffer.buffer?buffer:new Uint8Array(buffer),position2),position2+=length}__name(writeBuffer,"writeBuffer");function insertIds(serialized,idsToInsert){let nextId,distanceToMove=idsToInsert.length*2,lastEnd=serialized.length-distanceToMove;idsToInsert.sort((a,b)=>a.offset>b.offset?1:-1);for(let id=0;id<idsToInsert.length;id++){let referee=idsToInsert[id];referee.id=id;for(let position3 of referee.references)serialized[position3++]=id>>8,serialized[position3]=id&255}for(;nextId=idsToInsert.pop();){let offset=nextId.offset;serialized.copyWithin(offset+distanceToMove,offset,lastEnd),distanceToMove-=2;let position3=offset+distanceToMove;serialized[position3++]=216,serialized[position3++]=28,lastEnd=offset}return serialized}__name(insertIds,"insertIds");function writeBundles(start,encode2){targetView.setUint32(bundledStrings2.position+start,position2-bundledStrings2.position-start+1);let writeStrings=bundledStrings2;bundledStrings2=null,encode2(writeStrings[0]),encode2(writeStrings[1])}__name(writeBundles,"writeBundles");var defaultEncoder=new Encoder({useRecords:!1}),encode=defaultEncoder.encode,encodeAsIterable=defaultEncoder.encodeAsIterable,encodeAsAsyncIterable=defaultEncoder.encodeAsAsyncIterable,{NEVER,ALWAYS,DECIMAL_ROUND,DECIMAL_FIT}=FLOAT32_OPTIONS,REUSE_BUFFER_MODE=512,RESET_BUFFER_MODE=1024,THROW_ON_ITERABLE=2048;var UNKNOWN=4294967295,BUCKET_MAPPING=Object.freeze({"8u":{type:"Uint8",bits:8},"16u":{type:"Uint16",bits:16},"32u":{type:"Uint32",bits:32},"64u":{type:"BigUint64",bits:64},"8i":{type:"Int8",bits:8},"16i":{type:"Int16",bits:16},"32i":{type:"Int32",bits:32},"64i":{type:"BigInt64",bits:64},"16f":{type:"Float16",bits:16},"32f":{type:"Float32",bits:32},"64f":{type:"Float64",bits:64}}),IS_LITTLE_ENDIAN=new Uint8Array(new Uint16Array([1]).buffer)[0]===1,HEADER_SIZE=16,ADDRESS_OFFSET=0,OCCUPIED_OFFSET=4,CAPACITY_OFFSET=8,COOKIE_OFFSET=9,FLAGS_OFFSET=10,VIEW_LOCK=1,ROTATE_32BITS=4294967296,CLAMP_11BITS=2047,isTypedArray=__name(val=>ArrayBuffer.isView(val)&&!(val instanceof DataView),"isTypedArray"),Balloc=class{static{__name(this,"Balloc")}constructor(size=65535,bucketSize="32u",metadataSize=1024){if(!Number.isSafeInteger(size)||size<2||size>2147483648)throw new RangeError(`Parameter size must be in range [2, 0x80000000] but size is ${size}`);if(!BUCKET_MAPPING[bucketSize])throw new RangeError(`bucketSize must be in ([ 8 || 16 || 32 || 64][ u || i ]) || ([ 16 || 32 || 64][ f ]) but I found ${bucketSize}`);if(!Number.isSafeInteger(metadataSize)||metadataSize<HEADER_SIZE||metadataSize>2147483648)throw new RangeError(`Parameter metadataSize must be in range [HEADER_SIZE, 0x80000000] but metadataSize is ${metadataSize}`);this.wordType=bucketSize,this.bucketType=BUCKET_MAPPING[bucketSize].type,this.bucketSize=BUCKET_MAPPING[bucketSize].bits>>>0,this.bucketArray=globalThis[`${this.bucketType}Array`],this.wordSize=this.bucketSize>>>3,this.wordShift=this.bucketSize>>>4,this.size=Math.max(1<<32-Math.clz32(size-1)>>>0,this.wordSize),this.headerSize=1<<32-Math.clz32(metadataSize-1)>>>0,this.dataPointer=0,this.controlPointer=0,this.echoPointer=0,this.generation=0,this.dataBus=new Uint8Array(this.size),this.controlBus=new Uint8Array(this.headerSize),this.dataAdapter=new DataView(this.dataBus.buffer),this.controlAdapter=new DataView(this.controlBus.buffer),this.auxiliary=new globalThis[`${this.bucketType}Array`](this.dataBus.buffer),this.writer=this.dataAdapter[`set${this.bucketType}`].bind(this.dataAdapter),this.reader=this.dataAdapter[`get${this.bucketType}`].bind(this.dataAdapter),this.recycle=new Map,this.metadata={generation:0,headerAddress:0,dataAddress:0,capacityExponent:0,byteCapacity:0,occupied:0}}alloc(size=16){if(!Number.isSafeInteger(size)||size<2||size>2147483648)throw new RangeError(`Parameter size must be in range [2, 0x80000000] but size is ${size}`);let capacity=32-Math.clz32(size-1),blockSize=(1<<capacity>>>0)*this.wordSize,dataAddress=this.recyclePop(blockSize);if(dataAddress===UNKNOWN){for(;this.dataPointer+blockSize>this.size;)this.grow();dataAddress=this.dataPointer,this.dataPointer+=blockSize}let headerAddress=0;return this.echoPointer>this.controlPointer?(this.echoPointer-=4,headerAddress=this.controlAdapter.getUint32(this.echoPointer,IS_LITTLE_ENDIAN)):(this.controlPointer+HEADER_SIZE>this.controlAdapter.byteLength&&this.headerGrow(),headerAddress=this.controlPointer,this.controlPointer+=HEADER_SIZE,this.echoPointer+=HEADER_SIZE),this.controlAdapter.setUint32(headerAddress+ADDRESS_OFFSET,dataAddress,IS_LITTLE_ENDIAN),this.controlAdapter.setUint32(headerAddress+OCCUPIED_OFFSET,0,IS_LITTLE_ENDIAN),this.controlAdapter.setUint8(headerAddress+CAPACITY_OFFSET,capacity),this.controlAdapter.setUint8(headerAddress+COOKIE_OFFSET,this.bakeCookie(headerAddress,++this.generation)),this.controlBus[headerAddress+FLAGS_OFFSET]=0,(this.generation&CLAMP_11BITS)*ROTATE_32BITS+headerAddress}realloc(handler){let generation=handler/ROTATE_32BITS&CLAMP_11BITS,headerAddress=handler>>>0,dataAddress=this.controlAdapter.getUint32(headerAddress+ADDRESS_OFFSET,IS_LITTLE_ENDIAN),occupied=this.controlAdapter.getUint32(headerAddress+OCCUPIED_OFFSET,IS_LITTLE_ENDIAN),capacity=this.controlAdapter.getUint8(headerAddress+CAPACITY_OFFSET);if(this.controlAdapter.getUint8(headerAddress+COOKIE_OFFSET)!==this.bakeCookie(headerAddress,generation))throw new Error("Invalid or corrupted handle");if(this.assertNotBorrowed(headerAddress),capacity>=31)throw new AggregateError([new Error("Can\xB4t reallocate handler."),new RangeError("Capacity has reached its limit.")],"Internal Error.");let newCapacity=capacity+1,newBlockSize=(1<<newCapacity>>>0)*this.wordSize,oldBlockSize=(1<<capacity>>>0)*this.wordSize;if(dataAddress+oldBlockSize===this.dataPointer){for(;dataAddress+newBlockSize>this.size;)this.grow();this.controlAdapter.setUint8(headerAddress+CAPACITY_OFFSET,newCapacity),this.dataPointer=dataAddress+newBlockSize;return}let newAddress=this.recyclePop(newBlockSize);if(newAddress===UNKNOWN){for(;this.dataPointer+newBlockSize>this.size;)this.grow();newAddress=this.dataPointer,this.dataPointer+=newBlockSize}this.dataBus.copyWithin(newAddress,dataAddress,dataAddress+occupied*this.wordSize),this.controlAdapter.setUint32(headerAddress+ADDRESS_OFFSET,newAddress,IS_LITTLE_ENDIAN),this.controlAdapter.setUint8(headerAddress+CAPACITY_OFFSET,newCapacity),this.recyclePush(oldBlockSize,dataAddress)}free(handler){let generation=handler/ROTATE_32BITS&CLAMP_11BITS,headerAddress=handler>>>0,dataAddress=this.controlAdapter.getUint32(headerAddress+ADDRESS_OFFSET,IS_LITTLE_ENDIAN),capacity=this.controlAdapter.getUint8(headerAddress+CAPACITY_OFFSET);if(this.controlAdapter.getUint8(headerAddress+COOKIE_OFFSET)!==this.bakeCookie(headerAddress,generation))throw new Error("Invalid or corrupted handle");this.assertNotBorrowed(headerAddress);let blockSize=(1<<capacity>>>0)*this.wordSize;this.controlAdapter.setUint8(headerAddress+COOKIE_OFFSET,0),this.echoPointer+4<=this.controlBus.byteLength&&(this.controlAdapter.setUint32(this.echoPointer,headerAddress,IS_LITTLE_ENDIAN),this.echoPointer+=4),dataAddress+blockSize===this.dataPointer?this.dataPointer=dataAddress:this.recyclePush(blockSize,dataAddress)}recyclePush(capacity,address){if(this.recycle.has(capacity)){let page=this.recycle.get(capacity),count=page[0];if(count===page.length-1){let newBuffer=page.buffer.transfer(page.buffer.byteLength*2);page=new Uint32Array(newBuffer),this.recycle.set(capacity,page)}page[count+1]=address,page[0]=count+1}else this.recycle.set(capacity,new Uint32Array([1,address]))}recyclePop(capacity){if(!this.recycle.has(capacity))return UNKNOWN;let page=this.recycle.get(capacity),count=page[0];if(count===0)return UNKNOWN;let address=page[count];return page[0]=count-1,address}gc(){this.assertNoActiveViews();let newDataBus=new Uint8Array(this.dataBus.buffer.byteLength);this.recycle.clear(),this.dataPointer=0;for(let i=0;i<this.controlPointer;i+=HEADER_SIZE){if(this.controlBus[i+COOKIE_OFFSET]===0)continue;let start=this.controlAdapter.getUint32(i+ADDRESS_OFFSET,IS_LITTLE_ENDIAN),size=(1<<this.controlBus[i+CAPACITY_OFFSET]>>>0)*this.wordSize,end=start+size;newDataBus.set(this.dataBus.subarray(start,end),this.dataPointer),this.controlAdapter.setUint32(i+ADDRESS_OFFSET,this.dataPointer,IS_LITTLE_ENDIAN),this.dataPointer+=size}this.dataBus=newDataBus,this.dataAdapter=new DataView(this.dataBus.buffer),this.auxiliary=new globalThis[`${this.bucketType}Array`](this.dataBus.buffer),this.writer=this.dataAdapter[`set${this.bucketType}`].bind(this.dataAdapter),this.reader=this.dataAdapter[`get${this.bucketType}`].bind(this.dataAdapter)}grow(){if(this.assertNoActiveViews(),this.size>2147483648)throw new RangeError("Data bus capacity exceeded");let newSize=this.size*2>>>0,newBuffer=this.dataBus.buffer.transfer(newSize);this.size=newSize,this.dataBus=new Uint8Array(newBuffer),this.dataAdapter=new DataView(newBuffer),this.writer=this.dataAdapter[`set${this.bucketType}`].bind(this.dataAdapter),this.reader=this.dataAdapter[`get${this.bucketType}`].bind(this.dataAdapter),this.auxiliary=new this.bucketArray(newBuffer)}headerGrow(){if(this.controlBus.byteLength>2147483648)throw new RangeError("Control bus capacity exceeded");let newSize=this.controlBus.byteLength*2>>>0,newBuffer=this.controlBus.buffer.transfer(newSize);this.controlBus=new Uint8Array(newBuffer),this.controlAdapter=new DataView(newBuffer)}push(handler,value){let meta=this.extractMetadata(handler,this.metadata);return this.assertNotBorrowed(meta.headerAddress),(meta.occupied+1)*this.wordSize>meta.byteCapacity?!1:(this.writer(meta.dataAddress+meta.occupied*this.wordSize,value,IS_LITTLE_ENDIAN),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,meta.occupied+1,IS_LITTLE_ENDIAN),!0)}pop(handler){let meta=this.extractMetadata(handler,this.metadata);if(this.assertNotBorrowed(meta.headerAddress),meta.occupied!==0)return this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,meta.occupied-1,IS_LITTLE_ENDIAN),this.reader(meta.dataAddress+(meta.occupied-1)*this.wordSize,IS_LITTLE_ENDIAN)}peek(handler){let meta=this.extractMetadata(handler,this.metadata);if(meta.occupied!==0)return this.reader(meta.dataAddress+(meta.occupied-1)*this.wordSize,IS_LITTLE_ENDIAN)}nudge(handler,value){let meta=this.extractMetadata(handler,this.metadata);return this.assertNotBorrowed(meta.headerAddress),(meta.occupied+1)*this.wordSize>meta.byteCapacity?!1:(this.dataBus.copyWithin(meta.dataAddress+this.wordSize,meta.dataAddress,meta.dataAddress+meta.occupied*this.wordSize),this.writer(meta.dataAddress,value,IS_LITTLE_ENDIAN),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,meta.occupied+1,IS_LITTLE_ENDIAN),!0)}pull(handler){let meta=this.extractMetadata(handler,this.metadata);if(this.assertNotBorrowed(meta.headerAddress),meta.occupied===0)return;let result=this.reader(meta.dataAddress,IS_LITTLE_ENDIAN);return this.dataBus.copyWithin(meta.dataAddress,meta.dataAddress+this.wordSize,meta.dataAddress+meta.occupied*this.wordSize),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,meta.occupied-1,IS_LITTLE_ENDIAN),result}head(handler){let meta=this.extractMetadata(handler,this.metadata);if(meta.occupied!==0)return this.reader(meta.dataAddress,IS_LITTLE_ENDIAN)}has(handler,value){let meta=this.extractMetadata(handler,this.metadata);if(meta.occupied===0)return!1;let rawAddres=meta.dataAddress>>>this.wordShift;return this.auxiliary.subarray(rawAddres,rawAddres+meta.occupied).includes(value)}indexOf(handler,searchElement,fromIndex=0){let meta=this.extractMetadata(handler,this.metadata);if(meta.occupied===0)return-1;let rawAddres=meta.dataAddress>>>this.wordShift;return this.auxiliary.subarray(rawAddres,rawAddres+meta.occupied).indexOf(searchElement,fromIndex)}lastIndexOf(handler,searchElement,fromIndex=-1){let meta=this.extractMetadata(handler,this.metadata);if(meta.occupied===0)return-1;let rawAddres=meta.dataAddress>>>this.wordShift;return this.auxiliary.subarray(rawAddres,rawAddres+meta.occupied).lastIndexOf(searchElement,fromIndex)}get(handler,index){let meta=this.extractMetadata(handler,this.metadata);if(!(index<0||index>=meta.occupied))return this.reader(meta.dataAddress+index*this.wordSize,IS_LITTLE_ENDIAN)}set(handler,index,value){let meta=this.extractMetadata(handler,this.metadata);return this.assertNotBorrowed(meta.headerAddress),index<0||index>=meta.occupied?!1:(this.writer(meta.dataAddress+index*this.wordSize,value,IS_LITTLE_ENDIAN),!0)}clear(handler,value=0){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let slots=meta.byteCapacity/this.wordSize,rawAddress=meta.dataAddress>>>this.wordShift;this.auxiliary.fill(value,rawAddress,rawAddress+slots),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,0,IS_LITTLE_ENDIAN)}fill(handler,value,start=0,end=null){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let slots=meta.byteCapacity/this.wordSize,lastIndex=end??slots;if(start>lastIndex)throw new RangeError(`start ${start} must be less or equal than end ${lastIndex}.`);if(start<0||start>slots)throw new RangeError(`start ${start} out of range [0, ${slots}].`);if(lastIndex<0||lastIndex>slots)throw new RangeError(`end ${lastIndex} out of range [0, ${slots}].`);let rawAddress=meta.dataAddress>>>this.wordShift;this.auxiliary.fill(value,rawAddress+start,rawAddress+lastIndex),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,lastIndex,IS_LITTLE_ENDIAN)}fillAll(handler,value){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let rawAddress=meta.dataAddress>>>this.wordShift,capacityElements=meta.byteCapacity/this.wordSize;this.auxiliary.fill(value,rawAddress,rawAddress+capacityElements),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,capacityElements,IS_LITTLE_ENDIAN)}put(handler,data){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let rawAddress=meta.dataAddress>>>this.wordShift,length=Math.min(1<<meta.capacityExponent>>>0,data.length);if(Array.isArray(data))this.auxiliary.set(data.slice(0,length),rawAddress);else if(isTypedArray(data))this.auxiliary.set(data.subarray(0,length),rawAddress);else{let actual=data?.constructor?.name??(data===null?"null":typeof data);throw new TypeError(`data must be Array or TypedArray, but ${actual} was given.`)}this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,Math.max(length,meta.occupied),IS_LITTLE_ENDIAN)}pick(handler){let meta=this.extractMetadata(handler,this.metadata),rawAddress=meta.dataAddress>>>this.wordShift;return meta.occupied===0?this.auxiliary.slice(rawAddress,rawAddress):this.auxiliary.slice(rawAddress,rawAddress+meta.occupied)}withView(handler,callback){if(typeof callback!="function")throw new TypeError("callback must be a function");let meta=this.extractMetadata(handler,this.metadata),flagsAddress=meta.headerAddress+FLAGS_OFFSET,flags=this.controlBus[flagsAddress];if(flags&VIEW_LOCK)throw new Error("Block is already borrowed");this.controlBus[flagsAddress]=flags|VIEW_LOCK;try{let rawAddress=meta.dataAddress>>>this.wordShift;return callback(this.auxiliary.subarray(rawAddress,rawAddress+meta.occupied))}finally{this.controlBus[flagsAddress]&=~VIEW_LOCK}}byteSize(handler){return this.extractMetadata(handler,this.metadata).byteCapacity}occupied(handler){return this.extractMetadata(handler,this.metadata).occupied}length(handler){return 1<<this.extractMetadata(handler,this.metadata).capacityExponent>>>0}isFull(handler){let meta=this.extractMetadata(handler,this.metadata);return(1<<meta.capacityExponent>>>0)-meta.occupied===0}copy(source,destination,slots=UNKNOWN){let metaA={},metaB={};this.extractMetadata(source,metaA),this.extractMetadata(destination,metaB),this.assertNotBorrowed(metaB.headerAddress);let maxSlotsDest=Math.floor(metaB.byteCapacity/this.wordSize),slotsToCopy=Math.min(metaA.occupied,maxSlotsDest,slots),newOccupied=Math.max(metaB.occupied,slotsToCopy);return this.controlAdapter.setUint32(metaB.headerAddress+OCCUPIED_OFFSET,newOccupied,IS_LITTLE_ENDIAN),this.dataBus.copyWithin(metaB.dataAddress,metaA.dataAddress,metaA.dataAddress+slotsToCopy*this.wordSize)}copyWithin(handler,target2,start,length){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let slots=Math.floor(meta.byteCapacity/this.wordSize);target2=Math.trunc(target2),start=Math.trunc(start),length=Math.trunc(length),target2<0&&(target2+=slots),start<0&&(start+=slots),target2=Math.max(0,Math.min(target2,slots)),start=Math.max(0,Math.min(start,slots));let maxRead=Math.max(0,meta.occupied-start),maxWrite=slots-target2;if(length=Math.max(0,Math.min(length,maxRead,maxWrite)),length===0)return this.dataBus;let targetAddress=meta.dataAddress+target2*this.wordSize,sourceAddress=meta.dataAddress+start*this.wordSize,newOccupied=Math.max(meta.occupied,target2+length);return this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,newOccupied,IS_LITTLE_ENDIAN),this.dataBus.copyWithin(targetAddress,sourceAddress,sourceAddress+length*this.wordSize)}append(target2,source){let metaTarget={},metaSource={};this.extractMetadata(target2,metaTarget),this.extractMetadata(source,metaSource),this.assertNotBorrowed(metaTarget.headerAddress);let available=metaTarget.byteCapacity/this.wordSize-metaTarget.occupied,count=Math.min(available,metaSource.occupied);if(count===0)return 0;let targetAddress=metaTarget.dataAddress+metaTarget.occupied*this.wordSize,sourceAddress=metaSource.dataAddress;return this.dataBus.copyWithin(targetAddress,sourceAddress,sourceAddress+count*this.wordSize),this.controlAdapter.setUint32(metaTarget.headerAddress+OCCUPIED_OFFSET,metaTarget.occupied+count,IS_LITTLE_ENDIAN),count}clone(handler){let meta=this.extractMetadata(handler,this.metadata),cloned=this.alloc(meta.byteCapacity/this.wordSize),cloneMeta={};return this.extractMetadata(cloned,cloneMeta),this.dataBus.copyWithin(cloneMeta.dataAddress,meta.dataAddress,meta.dataAddress+meta.byteCapacity),this.controlAdapter.setUint32(cloneMeta.headerAddress+OCCUPIED_OFFSET,meta.occupied,IS_LITTLE_ENDIAN),cloned}swap(source,target2){let metaA={},metaB={};this.extractMetadata(source,metaA),this.extractMetadata(target2,metaB),this.assertNotBorrowed(metaA.headerAddress),this.assertNotBorrowed(metaB.headerAddress),this.controlAdapter.setUint32(metaA.headerAddress+ADDRESS_OFFSET,metaB.dataAddress,IS_LITTLE_ENDIAN),this.controlAdapter.setUint32(metaB.headerAddress+ADDRESS_OFFSET,metaA.dataAddress,IS_LITTLE_ENDIAN),this.controlAdapter.setUint8(metaA.headerAddress+CAPACITY_OFFSET,metaB.capacityExponent),this.controlAdapter.setUint8(metaB.headerAddress+CAPACITY_OFFSET,metaA.capacityExponent),this.controlAdapter.setUint32(metaA.headerAddress+OCCUPIED_OFFSET,metaB.occupied,IS_LITTLE_ENDIAN),this.controlAdapter.setUint32(metaB.headerAddress+OCCUPIED_OFFSET,metaA.occupied,IS_LITTLE_ENDIAN)}dump(handler){let meta=this.extractMetadata(handler,this.metadata),capacity=meta.capacityExponent,capacityElements=2**capacity;if(!Number.isInteger(capacity)||capacity<1||capacity>31||meta.occupied>capacityElements)throw new Error("Cannot serialize a block with invalid metadata");let payload=this.pick(handler);if(payload.length!==meta.occupied||payload.constructor!==this.bucketArray)throw new Error("Cannot serialize a block with an invalid payload");return encode({v:1,wordType:this.wordType,capacity,occupied:meta.occupied,le:IS_LITTLE_ENDIAN,payload})}load(serialized){if(!(serialized instanceof ArrayBuffer)&&!(serialized instanceof Uint8Array))throw new TypeError("serialized must be an ArrayBuffer or Uint8Array");let envelope=decode(serialized);if(!envelope||typeof envelope!="object"||Array.isArray(envelope))throw new TypeError("Invalid serialized block envelope");if(envelope.v!==1)throw new Error(`Unsupported serialized block version: ${envelope.v}`);if(envelope.wordType!==this.wordType)throw new Error(`Can't load data, ${this.wordType} expected but ${envelope.wordType} found.`);if(!Number.isInteger(envelope.capacity)||envelope.capacity<1||envelope.capacity>31)throw new RangeError("Invalid serialized block capacity");let capacityElements=2**envelope.capacity;if(!Number.isSafeInteger(envelope.occupied)||envelope.occupied<0||envelope.occupied>capacityElements)throw new RangeError("Invalid serialized block occupancy");if(typeof envelope.le!="boolean")throw new TypeError("Invalid serialized endianness flag");let payload=envelope.payload;if(!isTypedArray(payload)||payload.constructor!==this.bucketArray||payload.length!==envelope.occupied)throw new TypeError(`Invalid payload: expected ${this.bucketType}Array with ${envelope.occupied} elements`);if(payload.BYTES_PER_ELEMENT!==this.wordSize||payload.byteLength!==envelope.occupied*this.wordSize)throw new TypeError("Serialized payload has an invalid element size");let handler=this.alloc(capacityElements),meta=this.extractMetadata(handler,this.metadata);return this.put(handler,payload),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,envelope.occupied,IS_LITTLE_ENDIAN),handler}assertNotBorrowed(headerAddress){if(this.controlBus[headerAddress+FLAGS_OFFSET]&VIEW_LOCK)throw new Error("Block is borrowed")}assertNoActiveViews(){for(let i=0;i<this.controlPointer;i+=HEADER_SIZE)if(this.controlBus[i+COOKIE_OFFSET]!==0&&this.controlBus[i+FLAGS_OFFSET]&VIEW_LOCK)throw new Error("Cannot remap memory while a block is borrowed")}extractMetadata(handler,out){if(out.generation=handler/ROTATE_32BITS&CLAMP_11BITS,out.headerAddress=handler>>>0,this.controlAdapter.getUint8(out.headerAddress+COOKIE_OFFSET)!==this.bakeCookie(out.headerAddress,out.generation))throw new Error("Invalid or corrupted handle");return out.dataAddress=this.controlAdapter.getUint32(out.headerAddress+ADDRESS_OFFSET,IS_LITTLE_ENDIAN),out.capacityExponent=this.controlAdapter.getUint8(out.headerAddress+CAPACITY_OFFSET),out.byteCapacity=(1<<out.capacityExponent>>>0)*this.wordSize,out.occupied=this.controlAdapter.getUint32(out.headerAddress+OCCUPIED_OFFSET,IS_LITTLE_ENDIAN),out}bakeCookie(addr,gen){return(addr^gen&2047*2654435761)&255||1}recycleCount(){let count=0;for(let[,page]of this.recycle)count+=page[0];return count}get recycleBytes(){let total=0;for(let[capacity,page]of this.recycle)total+=page[0]*capacity;return total}get allocatedBytes(){return this.dataPointer-this.recycleBytes}get unallocatedBytes(){return this.size-this.dataPointer}get fragmentationRatio(){return this.dataPointer===0?0:this.recycleBytes/this.dataPointer}};return __toCommonJS(balloc_exports);})();
1
+ var BallocModule=(()=>{var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target2,value)=>__defProp(target2,"name",{value,configurable:!0});var __export=(target2,all)=>{for(var name in all)__defProp(target2,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var balloc_exports={};__export(balloc_exports,{default:()=>Balloc});var decoder;try{decoder=new TextDecoder}catch{}var src,srcEnd,position=0;var EMPTY_ARRAY=[],LEGACY_RECORD_INLINE_ID=105,RECORD_DEFINITIONS_ID=57342,RECORD_INLINE_ID=57343,BUNDLED_STRINGS_ID=57337;var PACKED_REFERENCE_TAG_ID=6,STOP_CODE={},maxArraySize=11281e4,maxMapSize=1681e4;var strings=EMPTY_ARRAY,stringPosition=0,currentDecoder={},currentStructures,srcString,srcStringStart=0,srcStringEnd=0,bundledStrings,referenceMap,currentExtensions=[],currentExtensionRanges=[],packedValues,dataView,restoreMapsAsObject,defaultOptions={useRecords:!1,mapsAsObjects:!0},sequentialMode=!1,inlineObjectReadThreshold=2;try{new Function("")}catch{inlineObjectReadThreshold=1/0}var Decoder=class _Decoder{static{__name(this,"Decoder")}constructor(options){if(options&&((options.keyMap||options._keyMap)&&!options.useRecords&&(options.useRecords=!1,options.mapsAsObjects=!0),options.useRecords===!1&&options.mapsAsObjects===void 0&&(options.mapsAsObjects=!0),options.getStructures&&(options.getShared=options.getStructures),options.getShared&&!options.structures&&((options.structures=[]).uninitialized=!0),options.keyMap)){this.mapKey=new Map;for(let[k,v]of Object.entries(options.keyMap))this.mapKey.set(v,k)}Object.assign(this,options)}decodeKey(key){return this.keyMap&&this.mapKey.get(key)||key}encodeKey(key){return this.keyMap&&this.keyMap.hasOwnProperty(key)?this.keyMap[key]:key}encodeKeys(rec){if(!this._keyMap)return rec;let map=new Map;for(let[k,v]of Object.entries(rec))map.set(this._keyMap.hasOwnProperty(k)?this._keyMap[k]:k,v);return map}decodeKeys(map){if(!this._keyMap||map.constructor.name!="Map")return map;if(!this._mapKey){this._mapKey=new Map;for(let[k,v]of Object.entries(this._keyMap))this._mapKey.set(v,k)}let res={};return map.forEach((v,k)=>res[safeKey(this._mapKey.has(k)?this._mapKey.get(k):k)]=v),res}mapDecode(source,end){let res=this.decode(source);return this._keyMap&&res.constructor.name==="Array"?res.map(r=>this.decodeKeys(r)):res}decode(source,end){if(src)return saveState(()=>(clearSource(),this?this.decode(source,end):_Decoder.prototype.decode.call(defaultOptions,source,end)));srcEnd=end>-1?end:source.length,position=0,stringPosition=0,srcStringEnd=0,srcString=null,strings=EMPTY_ARRAY,bundledStrings=null,src=source;try{dataView=source.dataView||(source.dataView=new DataView(source.buffer,source.byteOffset,source.byteLength))}catch(error){throw src=null,source instanceof Uint8Array?error:new Error("Source must be a Uint8Array or Buffer but was a "+(source&&typeof source=="object"?source.constructor.name:typeof source))}if(this instanceof _Decoder){if(currentDecoder=this,packedValues=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues),this.structures)return currentStructures=this.structures,checkedRead();(!currentStructures||currentStructures.length>0)&&(currentStructures=[])}else currentDecoder=defaultOptions,(!currentStructures||currentStructures.length>0)&&(currentStructures=[]),packedValues=null;return checkedRead()}decodeMultiple(source,forEach){let values,lastPosition=0;try{let size=source.length;sequentialMode=!0;let value=this?this.decode(source,size):defaultDecoder.decode(source,size);if(forEach){if(forEach(value)===!1)return;for(;position<size;)if(lastPosition=position,forEach(checkedRead())===!1)return}else{for(values=[value];position<size;)lastPosition=position,values.push(checkedRead());return values}}catch(error){throw error.lastPosition=lastPosition,error.values=values,error}finally{sequentialMode=!1,clearSource()}}};function checkedRead(){try{let result=read();if(bundledStrings){if(position>=bundledStrings.postBundlePosition){let error=new Error("Unexpected bundle position");throw error.incomplete=!0,error}position=bundledStrings.postBundlePosition,bundledStrings=null}if(position==srcEnd)currentStructures=null,src=null,referenceMap&&(referenceMap=null);else if(position>srcEnd){let error=new Error("Unexpected end of CBOR data");throw error.incomplete=!0,error}else if(!sequentialMode)throw new Error("Data read, but end of buffer not reached");return result}catch(error){throw clearSource(),(error instanceof RangeError||error.message.startsWith("Unexpected end of buffer"))&&(error.incomplete=!0),error}}__name(checkedRead,"checkedRead");function endOfCBORError(){let error=new Error("Unexpected end of CBOR data");return error.incomplete=!0,error}__name(endOfCBORError,"endOfCBORError");function read(){if(!(position<srcEnd))throw endOfCBORError();let token=src[position++],majorType=token>>5;if(token=token&31,token>23)switch(token){case 24:if(position>=srcEnd)throw endOfCBORError();token=src[position++];break;case 25:if(majorType==7)return getFloat16();token=dataView.getUint16(position),position+=2;break;case 26:if(majorType==7){let value=dataView.getFloat32(position);if(currentDecoder.useFloat32>2){let multiplier=mult10[(src[position]&127)<<1|src[position+1]>>7];return position+=4,(multiplier*value+(value>0?.5:-.5)>>0)/multiplier}return position+=4,value}if(token=dataView.getUint32(position),position+=4,majorType===1)return-1-token;break;case 27:if(majorType==7){let value=dataView.getFloat64(position);return position+=8,value}if(majorType>1){if(dataView.getUint32(position)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");token=dataView.getUint32(position+4)}else currentDecoder.int64AsNumber?(token=dataView.getUint32(position)*4294967296,token+=dataView.getUint32(position+4)):token=dataView.getBigUint64(position);position+=8;break;case 31:switch(majorType){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let array=[],value,i=0;for(;(value=read())!=STOP_CODE;){if(i>=maxArraySize)throw new Error(`Array length exceeds ${maxArraySize}`);array[i++]=value}return majorType==4?array:majorType==3?array.join(""):Buffer.concat(array);case 5:let key;if(currentDecoder.mapsAsObjects){let object={},i2=0;if(currentDecoder.keyMap)for(;(key=read())!=STOP_CODE;){if(i2++>=maxMapSize)throw new Error(`Property count exceeds ${maxMapSize}`);object[safeKey(currentDecoder.decodeKey(key))]=read()}else for(;(key=read())!=STOP_CODE;){if(i2++>=maxMapSize)throw new Error(`Property count exceeds ${maxMapSize}`);object[safeKey(key)]=read()}return object}else{restoreMapsAsObject&&(currentDecoder.mapsAsObjects=!0,restoreMapsAsObject=!1);let map=new Map;if(currentDecoder.keyMap){let i2=0;for(;(key=read())!=STOP_CODE;){if(i2++>=maxMapSize)throw new Error(`Map size exceeds ${maxMapSize}`);map.set(currentDecoder.decodeKey(key),read())}}else{let i2=0;for(;(key=read())!=STOP_CODE;){if(i2++>=maxMapSize)throw new Error(`Map size exceeds ${maxMapSize}`);map.set(key,read())}}return map}case 7:return STOP_CODE;default:throw new Error("Invalid major type for indefinite length "+majorType)}default:throw new Error("Unknown token "+token)}switch(majorType){case 0:return token;case 1:return~token;case 2:return readBin(token);case 3:if(srcStringEnd>=position)return srcString.slice(position-srcStringStart,(position+=token)-srcStringStart);if(srcStringEnd==0&&srcEnd<140&&token<32){let string=token<16?shortStringInJS(token):longStringInJS(token);if(string!=null)return string}return readFixedString(token);case 4:if(token>=maxArraySize)throw new Error(`Array length exceeds ${maxArraySize}`);if(token>srcEnd-position)throw endOfCBORError();let array=new Array(token);for(let i=0;i<token;i++)array[i]=read();return array;case 5:if(token>=maxMapSize)throw new Error(`Map size exceeds ${maxArraySize}`);if(token>(srcEnd-position)/2)throw endOfCBORError();if(currentDecoder.mapsAsObjects){let object={};if(currentDecoder.keyMap)for(let i=0;i<token;i++)object[safeKey(currentDecoder.decodeKey(read()))]=read();else for(let i=0;i<token;i++)object[safeKey(read())]=read();return object}else{restoreMapsAsObject&&(currentDecoder.mapsAsObjects=!0,restoreMapsAsObject=!1);let map=new Map;if(currentDecoder.keyMap)for(let i=0;i<token;i++)map.set(currentDecoder.decodeKey(read()),read());else for(let i=0;i<token;i++)map.set(read(),read());return map}case 6:if(token>=BUNDLED_STRINGS_ID){let structure=currentStructures[token&8191];if(structure)return structure.read||(structure.read=createStructureReader(structure)),structure.read();if(token<65536){if(token==RECORD_INLINE_ID){let length=readJustLength(),id=read(),structure2=read();recordDefinition(id,structure2);let object={};if(currentDecoder.keyMap)for(let i=2;i<length;i++){let key=currentDecoder.decodeKey(structure2[i-2]);object[safeKey(key)]=read()}else for(let i=2;i<length;i++){let key=structure2[i-2];object[safeKey(key)]=read()}return object}else if(token==RECORD_DEFINITIONS_ID){let length=readJustLength(),id=read();for(let i=2;i<length;i++)recordDefinition(id++,read());return read()}else if(token==BUNDLED_STRINGS_ID)return readBundleExt();if(currentDecoder.getShared&&(loadShared(),structure=currentStructures[token&8191],structure))return structure.read||(structure.read=createStructureReader(structure)),structure.read()}}let extension=currentExtensions[token];if(extension)return extension.handlesRead?extension(read):extension(read());{let input=read();for(let i=0;i<currentExtensionRanges.length;i++){let value=currentExtensionRanges[i](token,input);if(value!==void 0)return value}return new Tag(input,token)}case 7:switch(token){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;default:let packedValue=(packedValues||getPackedValues())[token];if(packedValue!==void 0)return packedValue;throw new Error("Unknown token "+token)}default:throw isNaN(token)?endOfCBORError():new Error("Unknown CBOR token "+token)}}__name(read,"read");var validName=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function createStructureReader(structure){if(!structure)throw new Error("Structure is required in record definition");function readObject(){let length=src[position++];if(length=length&31,length>23)switch(length){case 24:length=src[position++];break;case 25:length=dataView.getUint16(position),position+=2;break;case 26:length=dataView.getUint32(position),position+=4;break;default:throw new Error("Expected array header, but got "+src[position-1])}let compiledReader=this.compiledReader;for(;compiledReader;){if(compiledReader.propertyCount===length)return compiledReader(read);compiledReader=compiledReader.next}if(this.slowReads++>=inlineObjectReadThreshold){let array=this.length==length?this:this.slice(0,length);return compiledReader=currentDecoder.keyMap?new Function("r","return {"+array.map(k=>currentDecoder.decodeKey(k)).map(k=>validName.test(k)?safeKey(k)+":r()":"["+JSON.stringify(k)+"]:r()").join(",")+"}"):new Function("r","return {"+array.map(key=>validName.test(key)?safeKey(key)+":r()":"["+JSON.stringify(key)+"]:r()").join(",")+"}"),this.compiledReader&&(compiledReader.next=this.compiledReader),compiledReader.propertyCount=length,this.compiledReader=compiledReader,compiledReader(read)}let object={};if(currentDecoder.keyMap)for(let i=0;i<length;i++)object[safeKey(currentDecoder.decodeKey(this[i]))]=read();else for(let i=0;i<length;i++)object[safeKey(this[i])]=read();return object}return __name(readObject,"readObject"),structure.slowReads=0,readObject}__name(createStructureReader,"createStructureReader");function safeKey(key){if(typeof key=="string")return key==="__proto__"?"__proto_":key;if(typeof key=="number"||typeof key=="boolean"||typeof key=="bigint")return key.toString();if(key==null)return key+"";throw new Error("Invalid property name type "+typeof key)}__name(safeKey,"safeKey");var readFixedString=readStringJS;function readStringJS(length){let result;if(length<16&&(result=shortStringInJS(length)))return result;if(length>64&&decoder)return decoder.decode(src.subarray(position,position+=length));let end=position+length,units=[];for(result="";position<end;){let byte1=src[position++];if((byte1&128)===0)units.push(byte1);else if((byte1&224)===192)if(byte1<194||position>=end||(src[position]&192)!==128)units.push(65533);else{let byte2=src[position++]&63;units.push((byte1&31)<<6|byte2)}else if((byte1&240)===224){let byte2=position<end?src[position]:0;if(position>=end||(byte2&192)!==128||byte1===224&&byte2<160||byte1===237&&byte2>=160)units.push(65533);else if(position++,position>=end||(src[position]&192)!==128)units.push(65533);else{let byte3=src[position++]&63;units.push((byte1&31)<<12|(byte2&63)<<6|byte3)}}else if((byte1&248)===240){let byte2=position<end?src[position]:0;if(byte1>244||position>=end||(byte2&192)!==128||byte1===240&&byte2<144||byte1===244&&byte2>=144)units.push(65533);else if(position++,position>=end||(src[position]&192)!==128)units.push(65533);else{let byte3=src[position++]&63;if(position>=end||(src[position]&192)!==128)units.push(65533);else{let byte4=src[position++]&63,unit=(byte1&7)<<18|(byte2&63)<<12|byte3<<6|byte4;unit-=65536,units.push(unit>>>10&1023|55296),units.push(56320|unit&1023)}}}else units.push(65533);units.length>=4096&&(result+=fromCharCode.apply(String,units),units.length=0)}return units.length>0&&(result+=fromCharCode.apply(String,units)),result}__name(readStringJS,"readStringJS");var fromCharCode=String.fromCharCode;function longStringInJS(length){let start=position,bytes=new Array(length);for(let i=0;i<length;i++){let byte=src[position++];if((byte&128)>0){position=start;return}bytes[i]=byte}return fromCharCode.apply(String,bytes)}__name(longStringInJS,"longStringInJS");function shortStringInJS(length){if(length<4)if(length<2){if(length===0)return"";{let a=src[position++];if((a&128)>1){position-=1;return}return fromCharCode(a)}}else{let a=src[position++],b=src[position++];if((a&128)>0||(b&128)>0){position-=2;return}if(length<3)return fromCharCode(a,b);let c=src[position++];if((c&128)>0){position-=3;return}return fromCharCode(a,b,c)}else{let a=src[position++],b=src[position++],c=src[position++],d=src[position++];if((a&128)>0||(b&128)>0||(c&128)>0||(d&128)>0){position-=4;return}if(length<6){if(length===4)return fromCharCode(a,b,c,d);{let e=src[position++];if((e&128)>0){position-=5;return}return fromCharCode(a,b,c,d,e)}}else if(length<8){let e=src[position++],f=src[position++];if((e&128)>0||(f&128)>0){position-=6;return}if(length<7)return fromCharCode(a,b,c,d,e,f);let g=src[position++];if((g&128)>0){position-=7;return}return fromCharCode(a,b,c,d,e,f,g)}else{let e=src[position++],f=src[position++],g=src[position++],h=src[position++];if((e&128)>0||(f&128)>0||(g&128)>0||(h&128)>0){position-=8;return}if(length<10){if(length===8)return fromCharCode(a,b,c,d,e,f,g,h);{let i=src[position++];if((i&128)>0){position-=9;return}return fromCharCode(a,b,c,d,e,f,g,h,i)}}else if(length<12){let i=src[position++],j=src[position++];if((i&128)>0||(j&128)>0){position-=10;return}if(length<11)return fromCharCode(a,b,c,d,e,f,g,h,i,j);let k=src[position++];if((k&128)>0){position-=11;return}return fromCharCode(a,b,c,d,e,f,g,h,i,j,k)}else{let i=src[position++],j=src[position++],k=src[position++],l=src[position++];if((i&128)>0||(j&128)>0||(k&128)>0||(l&128)>0){position-=12;return}if(length<14){if(length===12)return fromCharCode(a,b,c,d,e,f,g,h,i,j,k,l);{let m=src[position++];if((m&128)>0){position-=13;return}return fromCharCode(a,b,c,d,e,f,g,h,i,j,k,l,m)}}else{let m=src[position++],n=src[position++];if((m&128)>0||(n&128)>0){position-=14;return}if(length<15)return fromCharCode(a,b,c,d,e,f,g,h,i,j,k,l,m,n);let o=src[position++];if((o&128)>0){position-=15;return}return fromCharCode(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)}}}}}__name(shortStringInJS,"shortStringInJS");function readBin(length){return currentDecoder.copyBuffers?Uint8Array.prototype.slice.call(src,position,position+=length):src.subarray(position,position+=length)}__name(readBin,"readBin");var f32Array=new Float32Array(1),u8Array=new Uint8Array(f32Array.buffer,0,4);function getFloat16(){let byte0=src[position++],byte1=src[position++],exponent=(byte0&127)>>2;if(exponent===31)return byte1||byte0&3?NaN:byte0&128?-1/0:1/0;if(exponent===0){let abs=((byte0&3)<<8|byte1)/16777216;return byte0&128?-abs:abs}return u8Array[3]=byte0&128|(exponent>>1)+56,u8Array[2]=(byte0&7)<<5|byte1>>3,u8Array[1]=byte1<<5,u8Array[0]=0,f32Array[0]}__name(getFloat16,"getFloat16");var keyCache=new Array(4096);var Tag=class{static{__name(this,"Tag")}constructor(value,tag){this.value=value,this.tag=tag}};currentExtensions[0]=dateString=>new Date(dateString);currentExtensions[1]=epochSec=>new Date(Math.round(epochSec*1e3));currentExtensions[2]=buffer=>{let value=BigInt(0);for(let i=0,l=buffer.byteLength;i<l;i++)value=BigInt(buffer[i])+(value<<BigInt(8));return value};currentExtensions[3]=buffer=>BigInt(-1)-currentExtensions[2](buffer);currentExtensions[4]=fraction=>+(fraction[1]+"e"+fraction[0]);currentExtensions[5]=fraction=>fraction[1]*Math.exp(fraction[0]*Math.log(2));var recordDefinition=__name((id,structure)=>{id=id-57344;let existingStructure=currentStructures[id];existingStructure&&existingStructure.isShared&&((currentStructures.restoreStructures||(currentStructures.restoreStructures=[]))[id]=existingStructure),currentStructures[id]=structure,structure.read=createStructureReader(structure)},"recordDefinition");currentExtensions[LEGACY_RECORD_INLINE_ID]=data=>{let length=data.length,structure=data[1];recordDefinition(data[0],structure);let object={};for(let i=2;i<length;i++){let key=structure[i-2];object[safeKey(key)]=data[i]}return object};currentExtensions[14]=value=>bundledStrings?bundledStrings[0].slice(bundledStrings.position0,bundledStrings.position0+=value):new Tag(value,14);currentExtensions[15]=value=>bundledStrings?bundledStrings[1].slice(bundledStrings.position1,bundledStrings.position1+=value):new Tag(value,15);var glbl={Error,RegExp};currentExtensions[27]=data=>(glbl[data[0]]||Error)(data[1],data[2]);var packedTable=__name(read2=>{if(src[position++]!=132){let error=new Error("Packed values structure must be followed by a 4 element array");throw src.length<position&&(error.incomplete=!0),error}let newPackedValues=read2();if(!newPackedValues||!newPackedValues.length){let error=new Error("Packed values structure must be followed by a 4 element array");throw error.incomplete=!0,error}return packedValues=packedValues?newPackedValues.concat(packedValues.slice(newPackedValues.length)):newPackedValues,packedValues.prefixes=read2(),packedValues.suffixes=read2(),read2()},"packedTable");packedTable.handlesRead=!0;currentExtensions[51]=packedTable;currentExtensions[PACKED_REFERENCE_TAG_ID]=data=>{if(!packedValues)if(currentDecoder.getShared)loadShared();else return new Tag(data,PACKED_REFERENCE_TAG_ID);if(typeof data=="number")return packedValues[16+(data>=0?2*data:-2*data-1)];let error=new Error("No support for non-integer packed references yet");throw data===void 0&&(error.incomplete=!0),error};currentExtensions[28]=read2=>{referenceMap||(referenceMap=new Map,referenceMap.id=0);let id=referenceMap.id++,startingPosition=position,token=src[position],target2;token>>5==4?target2=[]:target2={};let refEntry={target:target2};referenceMap.set(id,refEntry);let targetProperties=read2();return refEntry.used?(Object.getPrototypeOf(target2)!==Object.getPrototypeOf(targetProperties)&&(position=startingPosition,target2=targetProperties,referenceMap.set(id,{target:target2}),targetProperties=read2()),Object.assign(target2,targetProperties)):(refEntry.target=targetProperties,targetProperties)};currentExtensions[28].handlesRead=!0;currentExtensions[29]=id=>{let refEntry=referenceMap.get(id);return refEntry.used=!0,refEntry.target};currentExtensions[258]=array=>new Set(array);(currentExtensions[259]=read2=>(currentDecoder.mapsAsObjects&&(currentDecoder.mapsAsObjects=!1,restoreMapsAsObject=!0),read2())).handlesRead=!0;function combine(a,b){return typeof a=="string"?a+b:a instanceof Array?a.concat(b):Object.assign({},a,b)}__name(combine,"combine");function getPackedValues(){if(!packedValues)if(currentDecoder.getShared)loadShared();else throw new Error("No packed values available");return packedValues}__name(getPackedValues,"getPackedValues");var SHARED_DATA_TAG_ID=1399353956;currentExtensionRanges.push((tag,input)=>{if(tag>=225&&tag<=255)return combine(getPackedValues().prefixes[tag-224],input);if(tag>=28704&&tag<=32767)return combine(getPackedValues().prefixes[tag-28672],input);if(tag>=1879052288&&tag<=2147483647)return combine(getPackedValues().prefixes[tag-1879048192],input);if(tag>=216&&tag<=223)return combine(input,getPackedValues().suffixes[tag-216]);if(tag>=27647&&tag<=28671)return combine(input,getPackedValues().suffixes[tag-27639]);if(tag>=1811940352&&tag<=1879048191)return combine(input,getPackedValues().suffixes[tag-1811939328]);if(tag==SHARED_DATA_TAG_ID)return{packedValues,structures:currentStructures.slice(0),version:input};if(tag==55799)return input});var isLittleEndianMachine=new Uint8Array(new Uint16Array([1]).buffer)[0]==1,typedArrays=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array],typedArrayTags=[64,68,69,70,71,72,77,78,79,85,86];for(let i=0;i<typedArrays.length;i++)registerTypedArray(typedArrays[i],typedArrayTags[i]);function registerTypedArray(TypedArray,tag){let dvMethod="get"+TypedArray.name.slice(0,-5),bytesPerElement;typeof TypedArray=="function"?bytesPerElement=TypedArray.BYTES_PER_ELEMENT:TypedArray=null;for(let littleEndian=0;littleEndian<2;littleEndian++){if(!littleEndian&&bytesPerElement==1)continue;let sizeShift=bytesPerElement==2?1:bytesPerElement==4?2:bytesPerElement==8?3:0;currentExtensions[littleEndian?tag:tag-4]=bytesPerElement==1||littleEndian==isLittleEndianMachine?buffer=>{if(!TypedArray)throw new Error("Could not find typed array for code "+tag);return!currentDecoder.copyBuffers&&(bytesPerElement===1||bytesPerElement===2&&!(buffer.byteOffset&1)||bytesPerElement===4&&!(buffer.byteOffset&3)||bytesPerElement===8&&!(buffer.byteOffset&7))?new TypedArray(buffer.buffer,buffer.byteOffset,buffer.byteLength>>sizeShift):new TypedArray(Uint8Array.prototype.slice.call(buffer,0).buffer)}:buffer=>{if(!TypedArray)throw new Error("Could not find typed array for code "+tag);let dv=new DataView(buffer.buffer,buffer.byteOffset,buffer.byteLength),elements=buffer.length>>sizeShift,ta=new TypedArray(elements),method=dv[dvMethod];for(let i=0;i<elements;i++)ta[i]=method.call(dv,i<<sizeShift,littleEndian);return ta}}}__name(registerTypedArray,"registerTypedArray");function readBundleExt(){let length=readJustLength(),bundlePosition=position+read();for(let i=2;i<length;i++){let bundleLength=readJustLength();position+=bundleLength}let dataPosition=position;return position=bundlePosition,bundledStrings=[readStringJS(readJustLength()),readStringJS(readJustLength())],bundledStrings.position0=0,bundledStrings.position1=0,bundledStrings.postBundlePosition=position,position=dataPosition,read()}__name(readBundleExt,"readBundleExt");function readJustLength(){if(!(position<srcEnd))throw endOfCBORError();let token=src[position++]&31;if(token>23)switch(token){case 24:if(position>=srcEnd)throw endOfCBORError();token=src[position++];break;case 25:token=dataView.getUint16(position),position+=2;break;case 26:token=dataView.getUint32(position),position+=4;break}return token}__name(readJustLength,"readJustLength");function loadShared(){if(currentDecoder.getShared){let sharedData=saveState(()=>(src=null,currentDecoder.getShared()))||{},updatedStructures=sharedData.structures||[];currentDecoder.sharedVersion=sharedData.version,packedValues=currentDecoder.sharedValues=sharedData.packedValues,currentStructures===!0?currentDecoder.structures=currentStructures=updatedStructures:currentStructures.splice.apply(currentStructures,[0,updatedStructures.length].concat(updatedStructures))}}__name(loadShared,"loadShared");function saveState(callback){let savedSrcEnd=srcEnd,savedPosition=position,savedStringPosition=stringPosition,savedSrcStringStart=srcStringStart,savedSrcStringEnd=srcStringEnd,savedSrcString=srcString,savedStrings=strings,savedReferenceMap=referenceMap,savedBundledStrings=bundledStrings,savedSrc=new Uint8Array(src.slice(0,srcEnd)),savedStructures=currentStructures,savedDecoder=currentDecoder,savedSequentialMode=sequentialMode,value=callback();return srcEnd=savedSrcEnd,position=savedPosition,stringPosition=savedStringPosition,srcStringStart=savedSrcStringStart,srcStringEnd=savedSrcStringEnd,srcString=savedSrcString,strings=savedStrings,referenceMap=savedReferenceMap,bundledStrings=savedBundledStrings,src=savedSrc,sequentialMode=savedSequentialMode,currentStructures=savedStructures,currentDecoder=savedDecoder,dataView=new DataView(src.buffer,src.byteOffset,src.byteLength),value}__name(saveState,"saveState");function clearSource(){src=null,referenceMap=null,currentStructures=null}__name(clearSource,"clearSource");var mult10=new Array(147);for(let i=0;i<256;i++)mult10[i]=+("1e"+Math.floor(45.15-i*.30103));var defaultDecoder=new Decoder({useRecords:!1}),decode=defaultDecoder.decode,decodeMultiple=defaultDecoder.decodeMultiple,FLOAT32_OPTIONS={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};var textEncoder;try{textEncoder=new TextEncoder}catch{}var extensions,extensionClasses,Buffer2=typeof globalThis=="object"&&globalThis.Buffer,hasNodeBuffer=typeof Buffer2<"u",ByteArrayAllocate=hasNodeBuffer?Buffer2.allocUnsafeSlow:Uint8Array,ByteArray=hasNodeBuffer?Buffer2:Uint8Array,MAX_STRUCTURES=256,MAX_BUFFER_SIZE=hasNodeBuffer?4294967296:2144337920;var throwOnIterable,target,targetView,position2=0,safeEnd,bundledStrings2=null,MAX_BUNDLE_SIZE=61440,hasNonLatin=/[\u0080-\uFFFF]/,RECORD_SYMBOL=Symbol("record-id"),Encoder=class extends Decoder{static{__name(this,"Encoder")}constructor(options){super(options),this.offset=0;let typeBuffer,start,sharedStructures,hasSharedUpdate,structures,referenceMap2;options=options||{};let encodeUtf8=ByteArray.prototype.utf8Write?function(string,position3){return target.utf8Write(string,position3,target.byteLength-position3)}:textEncoder&&textEncoder.encodeInto?function(string,position3){return textEncoder.encodeInto(string,target.subarray(position3)).written}:!1,encoder=this,hasSharedStructures=options.structures||options.saveStructures,maxSharedStructures=options.maxSharedStructures;if(maxSharedStructures==null&&(maxSharedStructures=hasSharedStructures?128:0),maxSharedStructures>8190)throw new Error("Maximum maxSharedStructure is 8190");let isSequential=options.sequential;isSequential&&(maxSharedStructures=0),this.structures||(this.structures=[]),this.saveStructures&&(this.saveShared=this.saveStructures);let samplingPackedValues,packedObjectMap2,sharedValues=options.sharedValues,sharedPackedObjectMap2;if(sharedValues){sharedPackedObjectMap2=Object.create(null);for(let i=0,l=sharedValues.length;i<l;i++)sharedPackedObjectMap2[sharedValues[i]]=i}let recordIdsToRemove=[],transitionsCount=0,serializationsSinceTransitionRebuild=0;this.mapEncode=function(value,encodeOptions){return this._keyMap&&!this._mapped&&value.constructor.name==="Array"&&(value=value.map(r=>this.encodeKeys(r))),this.encode(value,encodeOptions)},this.encode=function(value,encodeOptions){if(target||(target=new ByteArrayAllocate(8192),targetView=new DataView(target.buffer,0,8192),position2=0),safeEnd=target.length-10,safeEnd-position2<2048?(target=new ByteArrayAllocate(target.length),targetView=new DataView(target.buffer,0,target.length),safeEnd=target.length-10,position2=0):encodeOptions===REUSE_BUFFER_MODE&&(position2=position2+7&2147483640),start=position2,encoder.useSelfDescribedHeader&&(targetView.setUint32(position2,3654940416),position2+=3),referenceMap2=encoder.structuredClone?new Map:null,encoder.bundleStrings&&typeof value!="string"?(bundledStrings2=[],bundledStrings2.size=1/0):bundledStrings2=null,sharedStructures=encoder.structures,sharedStructures){if(sharedStructures.uninitialized){let sharedData=encoder.getShared()||{};encoder.structures=sharedStructures=sharedData.structures||[],encoder.sharedVersion=sharedData.version;let sharedValues2=encoder.sharedValues=sharedData.packedValues;if(sharedValues2){sharedPackedObjectMap2={};for(let i=0,l=sharedValues2.length;i<l;i++)sharedPackedObjectMap2[sharedValues2[i]]=i}}let sharedStructuresLength=sharedStructures.length;if(sharedStructuresLength>maxSharedStructures&&!isSequential&&(sharedStructuresLength=maxSharedStructures),!sharedStructures.transitions){sharedStructures.transitions=Object.create(null);for(let i=0;i<sharedStructuresLength;i++){let keys=sharedStructures[i];if(!keys)continue;let nextTransition,transition=sharedStructures.transitions;for(let j=0,l=keys.length;j<l;j++){transition[RECORD_SYMBOL]===void 0&&(transition[RECORD_SYMBOL]=i);let key=keys[j];nextTransition=transition[key],nextTransition||(nextTransition=transition[key]=Object.create(null)),transition=nextTransition}transition[RECORD_SYMBOL]=i|1048576}}isSequential||(sharedStructures.nextId=sharedStructuresLength)}if(hasSharedUpdate&&(hasSharedUpdate=!1),structures=sharedStructures||[],packedObjectMap2=sharedPackedObjectMap2,options.pack){let packedValues2=new Map;if(packedValues2.values=[],packedValues2.encoder=encoder,packedValues2.maxValues=options.maxPrivatePackedValues||(sharedPackedObjectMap2?16:1/0),packedValues2.objectMap=sharedPackedObjectMap2||!1,packedValues2.samplingPackedValues=samplingPackedValues,findRepetitiveStrings(value,packedValues2),packedValues2.values.length>0){target[position2++]=216,target[position2++]=51,writeArrayHeader(4);let valuesArray=packedValues2.values;encode2(valuesArray),writeArrayHeader(0),writeArrayHeader(0),packedObjectMap2=Object.create(sharedPackedObjectMap2||null);for(let i=0,l=valuesArray.length;i<l;i++)packedObjectMap2[valuesArray[i]]=i}}throwOnIterable=encodeOptions&THROW_ON_ITERABLE;try{if(throwOnIterable)return;if(encode2(value),bundledStrings2&&writeBundles(start,encode2),encoder.offset=position2,referenceMap2&&referenceMap2.idsToInsert){position2+=referenceMap2.idsToInsert.length*2,position2>safeEnd&&makeRoom(position2),encoder.offset=position2;let serialized=insertIds(target.subarray(start,position2),referenceMap2.idsToInsert);return referenceMap2=null,serialized}return encodeOptions&REUSE_BUFFER_MODE?(target.start=start,target.end=position2,target):target.subarray(start,position2)}finally{if(sharedStructures){if(serializationsSinceTransitionRebuild<10&&serializationsSinceTransitionRebuild++,sharedStructures.length>maxSharedStructures&&(sharedStructures.length=maxSharedStructures),transitionsCount>1e4)sharedStructures.transitions=null,serializationsSinceTransitionRebuild=0,transitionsCount=0,recordIdsToRemove.length>0&&(recordIdsToRemove=[]);else if(recordIdsToRemove.length>0&&!isSequential){for(let i=0,l=recordIdsToRemove.length;i<l;i++)recordIdsToRemove[i][RECORD_SYMBOL]=void 0;recordIdsToRemove=[]}}if(hasSharedUpdate&&encoder.saveShared){encoder.structures.length>maxSharedStructures&&(encoder.structures=encoder.structures.slice(0,maxSharedStructures));let returnBuffer=target.subarray(start,position2);return encoder.updateSharedData()===!1?encoder.encode(value):returnBuffer}encodeOptions&RESET_BUFFER_MODE&&(position2=start)}},this.findCommonStringsToPack=()=>(samplingPackedValues=new Map,sharedPackedObjectMap2||(sharedPackedObjectMap2=Object.create(null)),options2=>{let threshold=options2&&options2.threshold||4,position3=this.pack?options2.maxPrivatePackedValues||16:0;sharedValues||(sharedValues=this.sharedValues=[]);for(let[key,status]of samplingPackedValues)status.count>threshold&&(sharedPackedObjectMap2[key]=position3++,sharedValues.push(key),hasSharedUpdate=!0);for(;this.saveShared&&this.updateSharedData()===!1;);samplingPackedValues=null});let encode2=__name(value=>{position2>safeEnd&&(target=makeRoom(position2));var type=typeof value,length;if(type==="string"){if(packedObjectMap2){let packedPosition=packedObjectMap2[value];if(packedPosition>=0){packedPosition<16?target[position2++]=packedPosition+224:(target[position2++]=198,packedPosition&1?encode2(15-packedPosition>>1):encode2(packedPosition-16>>1));return}else if(samplingPackedValues&&!options.pack){let status=samplingPackedValues.get(value);status?status.count++:samplingPackedValues.set(value,{count:1})}}let strLength=value.length;if(bundledStrings2&&strLength>=4&&strLength<1024){if((bundledStrings2.size+=strLength)>MAX_BUNDLE_SIZE){let extStart,maxBytes2=(bundledStrings2[0]?bundledStrings2[0].length*3+bundledStrings2[1].length:0)+10;position2+maxBytes2>safeEnd&&(target=makeRoom(position2+maxBytes2)),target[position2++]=217,target[position2++]=223,target[position2++]=249,target[position2++]=bundledStrings2.position?132:130,target[position2++]=26,extStart=position2-start,position2+=4,bundledStrings2.position&&writeBundles(start,encode2),bundledStrings2=["",""],bundledStrings2.size=0,bundledStrings2.position=extStart}let twoByte=hasNonLatin.test(value);bundledStrings2[twoByte?0:1]+=value,target[position2++]=twoByte?206:207,encode2(strLength);return}let headerSize;strLength<32?headerSize=1:strLength<256?headerSize=2:strLength<65536?headerSize=3:headerSize=5;let maxBytes=strLength*3;if(position2+maxBytes>safeEnd&&(target=makeRoom(position2+maxBytes)),strLength<64||!encodeUtf8){let i,c1,c2,strPosition=position2+headerSize;for(i=0;i<strLength;i++)c1=value.charCodeAt(i),c1<128?target[strPosition++]=c1:c1<2048?(target[strPosition++]=c1>>6|192,target[strPosition++]=c1&63|128):(c1&64512)===55296&&((c2=value.charCodeAt(i+1))&64512)===56320?(c1=65536+((c1&1023)<<10)+(c2&1023),i++,target[strPosition++]=c1>>18|240,target[strPosition++]=c1>>12&63|128,target[strPosition++]=c1>>6&63|128,target[strPosition++]=c1&63|128):(target[strPosition++]=c1>>12|224,target[strPosition++]=c1>>6&63|128,target[strPosition++]=c1&63|128);length=strPosition-position2-headerSize}else length=encodeUtf8(value,position2+headerSize,maxBytes);length<24?target[position2++]=96|length:length<256?(headerSize<2&&target.copyWithin(position2+2,position2+1,position2+1+length),target[position2++]=120,target[position2++]=length):length<65536?(headerSize<3&&target.copyWithin(position2+3,position2+2,position2+2+length),target[position2++]=121,target[position2++]=length>>8,target[position2++]=length&255):(headerSize<5&&target.copyWithin(position2+5,position2+3,position2+3+length),target[position2++]=122,targetView.setUint32(position2,length),position2+=4),position2+=length}else if(type==="number")if(!this.alwaysUseFloat&&value>>>0===value)value<24?target[position2++]=value:value<256?(target[position2++]=24,target[position2++]=value):value<65536?(target[position2++]=25,target[position2++]=value>>8,target[position2++]=value&255):(target[position2++]=26,targetView.setUint32(position2,value),position2+=4);else if(!this.alwaysUseFloat&&value>>0===value)value>=-24?target[position2++]=31-value:value>=-256?(target[position2++]=56,target[position2++]=~value):value>=-65536?(target[position2++]=57,targetView.setUint16(position2,~value),position2+=2):(target[position2++]=58,targetView.setUint32(position2,~value),position2+=4);else if(!this.alwaysUseFloat&&value<0&&value>=-4294967296&&Math.floor(value)===value)target[position2++]=58,targetView.setUint32(position2,-1-value),position2+=4;else{let useFloat32;if((useFloat32=this.useFloat32)>0&&value<4294967296&&value>=-2147483648){target[position2++]=250,targetView.setFloat32(position2,value);let xShifted;if(useFloat32<4||(xShifted=value*mult10[(target[position2]&127)<<1|target[position2+1]>>7])>>0===xShifted){position2+=4;return}else position2--}target[position2++]=251,targetView.setFloat64(position2,value),position2+=8}else if(type==="object")if(!value)target[position2++]=246;else{if(referenceMap2){let referee=referenceMap2.get(value);if(referee){if(target[position2++]=216,target[position2++]=29,target[position2++]=25,!referee.references){let idsToInsert=referenceMap2.idsToInsert||(referenceMap2.idsToInsert=[]);referee.references=[],idsToInsert.push(referee)}referee.references.push(position2-start),position2+=2;return}else referenceMap2.set(value,{offset:position2-start})}let constructor=value.constructor;if(constructor===Object)this.skipFunction===!0&&(value=Object.fromEntries([...Object.keys(value).filter(x=>typeof value[x]!="function").map(x=>[x,value[x]])])),writeObject(value);else if(constructor===Array){length=value.length,length<24?target[position2++]=128|length:writeArrayHeader(length);for(let i=0;i<length;i++)encode2(value[i])}else if(constructor===Map)if((this.mapsAsObjects?this.useTag259ForMaps!==!1:this.useTag259ForMaps)&&(target[position2++]=217,target[position2++]=1,target[position2++]=3),length=value.size,length<24?target[position2++]=160|length:length<256?(target[position2++]=184,target[position2++]=length):length<65536?(target[position2++]=185,target[position2++]=length>>8,target[position2++]=length&255):(target[position2++]=186,targetView.setUint32(position2,length),position2+=4),encoder.keyMap)for(let[key,entryValue]of value)encode2(encoder.encodeKey(key)),encode2(entryValue);else for(let[key,entryValue]of value)encode2(key),encode2(entryValue);else{for(let i=0,l=extensions.length;i<l;i++){let extensionClass=extensionClasses[i];if(value instanceof extensionClass){let extension=extensions[i],tag=extension.tag;tag==null&&(tag=extension.getTag&&extension.getTag.call(this,value)),tag<24?target[position2++]=192|tag:tag<256?(target[position2++]=216,target[position2++]=tag):tag<65536?(target[position2++]=217,target[position2++]=tag>>8,target[position2++]=tag&255):tag>-1&&(target[position2++]=218,targetView.setUint32(position2,tag),position2+=4),extension.encode.call(this,value,encode2,makeRoom);return}}if(value[Symbol.iterator]){if(throwOnIterable){let error=new Error("Iterable should be serialized as iterator");throw error.iteratorNotHandled=!0,error}target[position2++]=159;for(let entry of value)encode2(entry);target[position2++]=255;return}if(value[Symbol.asyncIterator]||isBlob(value)){let error=new Error("Iterable/blob should be serialized as iterator");throw error.iteratorNotHandled=!0,error}if(this.useToJSON&&value.toJSON){let json=value.toJSON();if(json!==value)return encode2(json)}writeObject(value)}}else if(type==="boolean")target[position2++]=value?245:244;else if(type==="bigint"){if(value<BigInt(1)<<BigInt(64)&&value>=0)target[position2++]=27,targetView.setBigUint64(position2,value);else if(value>-(BigInt(1)<<BigInt(64))&&value<0)target[position2++]=59,targetView.setBigUint64(position2,-value-BigInt(1));else if(this.largeBigIntToFloat)target[position2++]=251,targetView.setFloat64(position2,Number(value));else{value>=BigInt(0)?target[position2++]=194:(target[position2++]=195,value=BigInt(-1)-value);let bytes=[];for(;value;)bytes.push(Number(value&BigInt(255))),value>>=BigInt(8);writeBuffer(new Uint8Array(bytes.reverse()),makeRoom);return}position2+=8}else if(type==="undefined")target[position2++]=247;else throw new Error("Unknown type: "+type)},"encode"),writeObject=this.useRecords===!1?this.variableMapSize?object=>{let keys=Object.keys(object),vals=Object.values(object),length=keys.length;length<24?target[position2++]=160|length:length<256?(target[position2++]=184,target[position2++]=length):length<65536?(target[position2++]=185,target[position2++]=length>>8,target[position2++]=length&255):(target[position2++]=186,targetView.setUint32(position2,length),position2+=4);let key;if(encoder.keyMap)for(let i=0;i<length;i++)encode2(encoder.encodeKey(keys[i])),encode2(vals[i]);else for(let i=0;i<length;i++)encode2(keys[i]),encode2(vals[i])}:object=>{target[position2++]=185;let objectOffset=position2-start;position2+=2;let size=0;if(encoder.keyMap)for(let key in object)(typeof object.hasOwnProperty!="function"||object.hasOwnProperty(key))&&(encode2(encoder.encodeKey(key)),encode2(object[key]),size++);else for(let key in object)(typeof object.hasOwnProperty!="function"||object.hasOwnProperty(key))&&(encode2(key),encode2(object[key]),size++);target[objectOffset+++start]=size>>8,target[objectOffset+start]=size&255}:(object,skipValues)=>{let nextTransition,transition=structures.transitions||(structures.transitions=Object.create(null)),newTransitions=0,length=0,parentRecordId,keys;if(this.keyMap){keys=Object.keys(object).map(k=>this.encodeKey(k)),length=keys.length;for(let i=0;i<length;i++){let key=keys[i];nextTransition=transition[key],nextTransition||(nextTransition=transition[key]=Object.create(null),newTransitions++),transition=nextTransition}}else for(let key in object)(typeof object.hasOwnProperty!="function"||object.hasOwnProperty(key))&&(nextTransition=transition[key],nextTransition||(transition[RECORD_SYMBOL]&1048576&&(parentRecordId=transition[RECORD_SYMBOL]&65535),nextTransition=transition[key]=Object.create(null),newTransitions++),transition=nextTransition,length++);let recordId=transition[RECORD_SYMBOL];if(recordId!==void 0)recordId&=65535,target[position2++]=217,target[position2++]=recordId>>8|224,target[position2++]=recordId&255;else if(keys||(keys=transition.__keys__||(transition.__keys__=Object.keys(object))),parentRecordId===void 0?(recordId=structures.nextId++,recordId||(recordId=0,structures.nextId=1),recordId>=MAX_STRUCTURES&&(structures.nextId=(recordId=maxSharedStructures)+1)):recordId=parentRecordId,structures[recordId]=keys,recordId<maxSharedStructures){target[position2++]=217,target[position2++]=recordId>>8|224,target[position2++]=recordId&255,transition=structures.transitions;for(let i=0;i<length;i++)(transition[RECORD_SYMBOL]===void 0||transition[RECORD_SYMBOL]&1048576)&&(transition[RECORD_SYMBOL]=recordId),transition=transition[keys[i]];transition[RECORD_SYMBOL]=recordId|1048576,hasSharedUpdate=!0}else{if(transition[RECORD_SYMBOL]=recordId,targetView.setUint32(position2,3655335680),position2+=3,newTransitions&&(transitionsCount+=serializationsSinceTransitionRebuild*newTransitions),recordIdsToRemove.length>=MAX_STRUCTURES-maxSharedStructures&&(recordIdsToRemove.shift()[RECORD_SYMBOL]=void 0),recordIdsToRemove.push(transition),writeArrayHeader(length+2),encode2(57344+recordId),encode2(keys),skipValues)return;for(let key in object)(typeof object.hasOwnProperty!="function"||object.hasOwnProperty(key))&&encode2(object[key]);return}if(length<24?target[position2++]=128|length:writeArrayHeader(length),!skipValues)for(let key in object)(typeof object.hasOwnProperty!="function"||object.hasOwnProperty(key))&&encode2(object[key])},makeRoom=__name(end=>{let newSize;if(end>16777216){if(end-start>MAX_BUFFER_SIZE)throw new Error("Encoded buffer would be larger than maximum buffer size");newSize=Math.min(MAX_BUFFER_SIZE,Math.round(Math.max((end-start)*(end>67108864?1.25:2),4194304)/4096)*4096)}else newSize=(Math.max(end-start<<2,target.length-1)>>12)+1<<12;let newBuffer=new ByteArrayAllocate(newSize);return targetView=new DataView(newBuffer.buffer,0,newSize),target.copy?target.copy(newBuffer,0,start,end):newBuffer.set(target.slice(start,end)),position2-=start,start=0,safeEnd=newBuffer.length-10,target=newBuffer},"makeRoom"),chunkThreshold=100,continuedChunkThreshold=1e3;this.encodeAsIterable=function(value,options2){return startEncoding(value,options2,encodeObjectAsIterable)},this.encodeAsAsyncIterable=function(value,options2){return startEncoding(value,options2,encodeObjectAsAsyncIterable)};function*encodeObjectAsIterable(object,iterateProperties,finalIterable){let constructor=object.constructor;if(constructor===Object){let useRecords=encoder.useRecords!==!1;useRecords?writeObject(object,!0):writeEntityLength(Object.keys(object).length,160);for(let key in object){let value=object[key];useRecords||encode2(key),value&&typeof value=="object"?iterateProperties[key]?yield*encodeObjectAsIterable(value,iterateProperties[key]):yield*tryEncode(value,iterateProperties,key):encode2(value)}}else if(constructor===Array){let length=object.length;writeArrayHeader(length);for(let i=0;i<length;i++){let value=object[i];value&&(typeof value=="object"||position2-start>chunkThreshold)?iterateProperties.element?yield*encodeObjectAsIterable(value,iterateProperties.element):yield*tryEncode(value,iterateProperties,"element"):encode2(value)}}else if(object[Symbol.iterator]&&!object.buffer){target[position2++]=159;for(let value of object)value&&(typeof value=="object"||position2-start>chunkThreshold)?iterateProperties.element?yield*encodeObjectAsIterable(value,iterateProperties.element):yield*tryEncode(value,iterateProperties,"element"):encode2(value);target[position2++]=255}else isBlob(object)?(writeEntityLength(object.size,64),yield target.subarray(start,position2),yield object,restartEncoding()):object[Symbol.asyncIterator]?(target[position2++]=159,yield target.subarray(start,position2),yield object,restartEncoding(),target[position2++]=255):encode2(object);finalIterable&&position2>start?yield target.subarray(start,position2):position2-start>chunkThreshold&&(yield target.subarray(start,position2),restartEncoding())}__name(encodeObjectAsIterable,"encodeObjectAsIterable");function*tryEncode(value,iterateProperties,key){let restart=position2-start;try{encode2(value),position2-start>chunkThreshold&&(yield target.subarray(start,position2),restartEncoding())}catch(error){if(error.iteratorNotHandled)iterateProperties[key]={},position2=start+restart,yield*encodeObjectAsIterable.call(this,value,iterateProperties[key]);else throw error}}__name(tryEncode,"tryEncode");function restartEncoding(){chunkThreshold=continuedChunkThreshold,encoder.encode(null,THROW_ON_ITERABLE)}__name(restartEncoding,"restartEncoding");function startEncoding(value,options2,encodeIterable){return options2&&options2.chunkThreshold?chunkThreshold=continuedChunkThreshold=options2.chunkThreshold:chunkThreshold=100,value&&typeof value=="object"?(encoder.encode(null,THROW_ON_ITERABLE),encodeIterable(value,encoder.iterateProperties||(encoder.iterateProperties={}),!0)):[encoder.encode(value)]}__name(startEncoding,"startEncoding");async function*encodeObjectAsAsyncIterable(value,iterateProperties){for(let encodedValue of encodeObjectAsIterable(value,iterateProperties,!0)){let constructor=encodedValue.constructor;if(constructor===ByteArray||constructor===Uint8Array)yield encodedValue;else if(isBlob(encodedValue)){let reader=encodedValue.stream().getReader(),next;for(;!(next=await reader.read()).done;)yield next.value}else if(encodedValue[Symbol.asyncIterator])for await(let asyncValue of encodedValue)restartEncoding(),asyncValue?yield*encodeObjectAsAsyncIterable(asyncValue,iterateProperties.async||(iterateProperties.async={})):yield encoder.encode(asyncValue);else yield encodedValue}}__name(encodeObjectAsAsyncIterable,"encodeObjectAsAsyncIterable")}useBuffer(buffer){target=buffer,targetView=new DataView(target.buffer,target.byteOffset,target.byteLength),position2=0}clearSharedData(){this.structures&&(this.structures=[]),this.sharedValues&&(this.sharedValues=void 0)}updateSharedData(){let lastVersion=this.sharedVersion||0;this.sharedVersion=lastVersion+1;let structuresCopy=this.structures.slice(0),sharedData=new SharedData(structuresCopy,this.sharedValues,this.sharedVersion),saveResults=this.saveShared(sharedData,existingShared=>(existingShared&&existingShared.version||0)==lastVersion);return saveResults===!1?(sharedData=this.getShared()||{},this.structures=sharedData.structures||[],this.sharedValues=sharedData.packedValues,this.sharedVersion=sharedData.version,this.structures.nextId=this.structures.length):structuresCopy.forEach((structure,i)=>this.structures[i]=structure),saveResults}};function writeEntityLength(length,majorValue){length<24?target[position2++]=majorValue|length:length<256?(target[position2++]=majorValue|24,target[position2++]=length):length<65536?(target[position2++]=majorValue|25,target[position2++]=length>>8,target[position2++]=length&255):(target[position2++]=majorValue|26,targetView.setUint32(position2,length),position2+=4)}__name(writeEntityLength,"writeEntityLength");var SharedData=class{static{__name(this,"SharedData")}constructor(structures,values,version){this.structures=structures,this.packedValues=values,this.version=version}};function writeArrayHeader(length){length<24?target[position2++]=128|length:length<256?(target[position2++]=152,target[position2++]=length):length<65536?(target[position2++]=153,target[position2++]=length>>8,target[position2++]=length&255):(target[position2++]=154,targetView.setUint32(position2,length),position2+=4)}__name(writeArrayHeader,"writeArrayHeader");var BlobConstructor=typeof Blob>"u"?function(){}:Blob;function isBlob(object){if(object instanceof BlobConstructor)return!0;let tag=object[Symbol.toStringTag];return tag==="Blob"||tag==="File"}__name(isBlob,"isBlob");function findRepetitiveStrings(value,packedValues2){switch(typeof value){case"string":if(value.length>3){if(packedValues2.objectMap[value]>-1||packedValues2.values.length>=packedValues2.maxValues)return;let packedStatus=packedValues2.get(value);if(packedStatus)++packedStatus.count==2&&packedValues2.values.push(value);else if(packedValues2.set(value,{count:1}),packedValues2.samplingPackedValues){let status=packedValues2.samplingPackedValues.get(value);status?status.count++:packedValues2.samplingPackedValues.set(value,{count:1})}}break;case"object":if(value)if(value instanceof Array)for(let i=0,l=value.length;i<l;i++)findRepetitiveStrings(value[i],packedValues2);else{let includeKeys=!packedValues2.encoder.useRecords;for(var key in value)value.hasOwnProperty(key)&&(includeKeys&&findRepetitiveStrings(key,packedValues2),findRepetitiveStrings(value[key],packedValues2))}break;case"function":console.log(value)}}__name(findRepetitiveStrings,"findRepetitiveStrings");var isLittleEndianMachine2=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;extensionClasses=[Date,Set,Error,RegExp,Tag,ArrayBuffer,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?function(){}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?function(){}:BigInt64Array,Float32Array,Float64Array,SharedData];extensions=[{tag:1,encode(date,encode2){let seconds=date.getTime()/1e3;(this.useTimestamp32||date.getMilliseconds()===0)&&seconds>=0&&seconds<4294967296?(target[position2++]=26,targetView.setUint32(position2,seconds),position2+=4):(target[position2++]=251,targetView.setFloat64(position2,seconds),position2+=8)}},{tag:258,encode(set,encode2){let array=Array.from(set);encode2(array)}},{tag:27,encode(error,encode2){encode2([error.name,error.message])}},{tag:27,encode(regex,encode2){encode2(["RegExp",regex.source,regex.flags])}},{getTag(tag){return tag.tag},encode(tag,encode2){encode2(tag.value)}},{encode(arrayBuffer,encode2,makeRoom){writeBuffer(arrayBuffer,makeRoom)}},{getTag(typedArray){if(typedArray.constructor===Uint8Array&&(this.tagUint8Array||hasNodeBuffer&&this.tagUint8Array!==!1))return 64},encode(typedArray,encode2,makeRoom){writeBuffer(typedArray,makeRoom)}},typedArrayEncoder(68,1),typedArrayEncoder(69,2),typedArrayEncoder(70,4),typedArrayEncoder(71,8),typedArrayEncoder(72,1),typedArrayEncoder(77,2),typedArrayEncoder(78,4),typedArrayEncoder(79,8),typedArrayEncoder(85,4),typedArrayEncoder(86,8),{encode(sharedData,encode2){let packedValues2=sharedData.packedValues||[],sharedStructures=sharedData.structures||[];if(packedValues2.values.length>0){target[position2++]=216,target[position2++]=51,writeArrayHeader(4);let valuesArray=packedValues2.values;encode2(valuesArray),writeArrayHeader(0),writeArrayHeader(0),packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let i=0,l=valuesArray.length;i<l;i++)packedObjectMap[valuesArray[i]]=i}if(sharedStructures){targetView.setUint32(position2,3655335424),position2+=3;let definitions=sharedStructures.slice(0);definitions.unshift(57344),definitions.push(new Tag(sharedData.version,1399353956)),encode2(definitions)}else encode2(new Tag(sharedData.version,1399353956))}}];function typedArrayEncoder(tag,size){return!isLittleEndianMachine2&&size>1&&(tag-=4),{tag,encode:__name(function(typedArray,encode2){let length=typedArray.byteLength,offset=typedArray.byteOffset||0,buffer=typedArray.buffer||typedArray;encode2(hasNodeBuffer?Buffer2.from(buffer,offset,length):new Uint8Array(buffer,offset,length))},"writeExtBuffer")}}__name(typedArrayEncoder,"typedArrayEncoder");function writeBuffer(buffer,makeRoom){let length=buffer.byteLength;length<24?target[position2++]=64+length:length<256?(target[position2++]=88,target[position2++]=length):length<65536?(target[position2++]=89,target[position2++]=length>>8,target[position2++]=length&255):(target[position2++]=90,targetView.setUint32(position2,length),position2+=4),position2+length>=target.length&&makeRoom(position2+length),target.set(buffer.buffer?buffer:new Uint8Array(buffer),position2),position2+=length}__name(writeBuffer,"writeBuffer");function insertIds(serialized,idsToInsert){let nextId,distanceToMove=idsToInsert.length*2,lastEnd=serialized.length-distanceToMove;idsToInsert.sort((a,b)=>a.offset>b.offset?1:-1);for(let id=0;id<idsToInsert.length;id++){let referee=idsToInsert[id];referee.id=id;for(let position3 of referee.references)serialized[position3++]=id>>8,serialized[position3]=id&255}for(;nextId=idsToInsert.pop();){let offset=nextId.offset;serialized.copyWithin(offset+distanceToMove,offset,lastEnd),distanceToMove-=2;let position3=offset+distanceToMove;serialized[position3++]=216,serialized[position3++]=28,lastEnd=offset}return serialized}__name(insertIds,"insertIds");function writeBundles(start,encode2){targetView.setUint32(bundledStrings2.position+start,position2-bundledStrings2.position-start+1);let writeStrings=bundledStrings2;bundledStrings2=null,encode2(writeStrings[0]),encode2(writeStrings[1])}__name(writeBundles,"writeBundles");var defaultEncoder=new Encoder({useRecords:!1}),encode=defaultEncoder.encode,encodeAsIterable=defaultEncoder.encodeAsIterable,encodeAsAsyncIterable=defaultEncoder.encodeAsAsyncIterable,{NEVER,ALWAYS,DECIMAL_ROUND,DECIMAL_FIT}=FLOAT32_OPTIONS,REUSE_BUFFER_MODE=512,RESET_BUFFER_MODE=1024,THROW_ON_ITERABLE=2048;var UNKNOWN=4294967295,BUCKET_MAPPING=Object.freeze({"8u":{type:"Uint8",bits:8},"16u":{type:"Uint16",bits:16},"32u":{type:"Uint32",bits:32},"64u":{type:"BigUint64",bits:64},"8i":{type:"Int8",bits:8},"16i":{type:"Int16",bits:16},"32i":{type:"Int32",bits:32},"64i":{type:"BigInt64",bits:64},"16f":{type:"Float16",bits:16},"32f":{type:"Float32",bits:32},"64f":{type:"Float64",bits:64}}),IS_LITTLE_ENDIAN=new Uint8Array(new Uint16Array([1]).buffer)[0]===1,HEADER_SIZE=16,ADDRESS_OFFSET=0,OCCUPIED_OFFSET=4,CAPACITY_OFFSET=8,COOKIE_OFFSET=9,FLAGS_OFFSET=10,VIEW_LOCK=1,ROTATE_32BITS=4294967296,CLAMP_11BITS=2047,isTypedArray=__name(val=>ArrayBuffer.isView(val)&&!(val instanceof DataView),"isTypedArray"),Balloc=class{static{__name(this,"Balloc")}constructor(size=65535,bucketSize="32u",metadataSize=1024){if(!Number.isSafeInteger(size)||size<2||size>2147483648)throw new RangeError(`Parameter size must be in range [2, 0x80000000] but size is ${size}`);if(!BUCKET_MAPPING[bucketSize])throw new RangeError(`bucketSize must be in ([ 8 || 16 || 32 || 64][ u || i ]) || ([ 16 || 32 || 64][ f ]) but I found ${bucketSize}`);if(!Number.isSafeInteger(metadataSize)||metadataSize<HEADER_SIZE||metadataSize>2147483648)throw new RangeError(`Parameter metadataSize must be in range [HEADER_SIZE, 0x80000000] but metadataSize is ${metadataSize}`);this.wordType=bucketSize,this.bucketType=BUCKET_MAPPING[bucketSize].type,this.bucketSize=BUCKET_MAPPING[bucketSize].bits>>>0,this.bucketArray=globalThis[`${this.bucketType}Array`],this.wordSize=this.bucketSize>>>3,this.wordShift=this.bucketSize>>>4,this.size=Math.max(1<<32-Math.clz32(size-1)>>>0,this.wordSize),this.headerSize=1<<32-Math.clz32(metadataSize-1)>>>0,this.dataPointer=0,this.controlPointer=0,this.echoPointer=0,this.generation=0,this.dataBus=new Uint8Array(this.size),this.controlBus=new Uint8Array(this.headerSize),this.dataAdapter=new DataView(this.dataBus.buffer),this.controlAdapter=new DataView(this.controlBus.buffer),this.auxiliary=new globalThis[`${this.bucketType}Array`](this.dataBus.buffer),this.writer=this.dataAdapter[`set${this.bucketType}`].bind(this.dataAdapter),this.reader=this.dataAdapter[`get${this.bucketType}`].bind(this.dataAdapter),this.recycle=new Map,this.metadata={generation:0,headerAddress:0,dataAddress:0,capacityExponent:0,byteCapacity:0,occupied:0}}alloc(size=16){if(!Number.isSafeInteger(size)||size<2||size>2147483648)throw new RangeError(`Parameter size must be in range [2, 0x80000000] but size is ${size}`);let capacity=32-Math.clz32(size-1),blockSize=(1<<capacity>>>0)*this.wordSize,dataAddress=this.recyclePop(blockSize);if(dataAddress===UNKNOWN){for(;this.dataPointer+blockSize>this.size;)this.grow();dataAddress=this.dataPointer,this.dataPointer+=blockSize}let headerAddress=0;return this.echoPointer>this.controlPointer?(this.echoPointer-=4,headerAddress=this.controlAdapter.getUint32(this.echoPointer,IS_LITTLE_ENDIAN)):(this.controlPointer+HEADER_SIZE>this.controlAdapter.byteLength&&this.headerGrow(),headerAddress=this.controlPointer,this.controlPointer+=HEADER_SIZE,this.echoPointer+=HEADER_SIZE),this.controlAdapter.setUint32(headerAddress+ADDRESS_OFFSET,dataAddress,IS_LITTLE_ENDIAN),this.controlAdapter.setUint32(headerAddress+OCCUPIED_OFFSET,0,IS_LITTLE_ENDIAN),this.controlAdapter.setUint8(headerAddress+CAPACITY_OFFSET,capacity),this.controlAdapter.setUint8(headerAddress+COOKIE_OFFSET,this.bakeCookie(headerAddress,++this.generation)),this.controlBus[headerAddress+FLAGS_OFFSET]=0,(this.generation&CLAMP_11BITS)*ROTATE_32BITS+headerAddress}realloc(handler){let generation=handler/ROTATE_32BITS&CLAMP_11BITS,headerAddress=handler>>>0,dataAddress=this.controlAdapter.getUint32(headerAddress+ADDRESS_OFFSET,IS_LITTLE_ENDIAN),occupied=this.controlAdapter.getUint32(headerAddress+OCCUPIED_OFFSET,IS_LITTLE_ENDIAN),capacity=this.controlAdapter.getUint8(headerAddress+CAPACITY_OFFSET);if(this.controlAdapter.getUint8(headerAddress+COOKIE_OFFSET)!==this.bakeCookie(headerAddress,generation))throw new Error("Invalid or corrupted handle");if(this.assertNotBorrowed(headerAddress),capacity>=31)throw new AggregateError([new Error("Can\xB4t reallocate handler."),new RangeError("Capacity has reached its limit.")],"Internal Error.");let newCapacity=capacity+1,newBlockSize=(1<<newCapacity>>>0)*this.wordSize,oldBlockSize=(1<<capacity>>>0)*this.wordSize;if(dataAddress+oldBlockSize===this.dataPointer){for(;dataAddress+newBlockSize>this.size;)this.grow();this.controlAdapter.setUint8(headerAddress+CAPACITY_OFFSET,newCapacity),this.dataPointer=dataAddress+newBlockSize;return}let newAddress=this.recyclePop(newBlockSize);if(newAddress===UNKNOWN){for(;this.dataPointer+newBlockSize>this.size;)this.grow();newAddress=this.dataPointer,this.dataPointer+=newBlockSize}this.dataBus.copyWithin(newAddress,dataAddress,dataAddress+occupied*this.wordSize),this.controlAdapter.setUint32(headerAddress+ADDRESS_OFFSET,newAddress,IS_LITTLE_ENDIAN),this.controlAdapter.setUint8(headerAddress+CAPACITY_OFFSET,newCapacity),this.recyclePush(oldBlockSize,dataAddress)}shrink(handler){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let newCapacity=Math.max(1,32-Math.clz32(Math.max(2,meta.occupied)-1));if(newCapacity>=meta.capacityExponent)return;let oldBlockSize=meta.byteCapacity,newBlockSize=2**newCapacity*this.wordSize,oldEnd=meta.dataAddress+oldBlockSize;if(this.controlAdapter.setUint8(meta.headerAddress+CAPACITY_OFFSET,newCapacity),oldEnd===this.dataPointer){this.dataPointer=meta.dataAddress+newBlockSize;return}let address=meta.dataAddress+newBlockSize;for(let exponent=newCapacity;exponent<meta.capacityExponent;exponent++){let segmentSize=2**exponent*this.wordSize;this.recyclePush(segmentSize,address),address+=segmentSize}}free(handler){let generation=handler/ROTATE_32BITS&CLAMP_11BITS,headerAddress=handler>>>0,dataAddress=this.controlAdapter.getUint32(headerAddress+ADDRESS_OFFSET,IS_LITTLE_ENDIAN),capacity=this.controlAdapter.getUint8(headerAddress+CAPACITY_OFFSET);if(this.controlAdapter.getUint8(headerAddress+COOKIE_OFFSET)!==this.bakeCookie(headerAddress,generation))throw new Error("Invalid or corrupted handle");this.assertNotBorrowed(headerAddress);let blockSize=(1<<capacity>>>0)*this.wordSize;this.controlAdapter.setUint8(headerAddress+COOKIE_OFFSET,0),this.echoPointer+4<=this.controlBus.byteLength&&(this.controlAdapter.setUint32(this.echoPointer,headerAddress,IS_LITTLE_ENDIAN),this.echoPointer+=4),dataAddress+blockSize===this.dataPointer?this.dataPointer=dataAddress:this.recyclePush(blockSize,dataAddress)}recyclePush(capacity,address){if(this.recycle.has(capacity)){let page=this.recycle.get(capacity),count=page[0];if(count===page.length-1){let newBuffer=page.buffer.transfer(page.buffer.byteLength*2);page=new Uint32Array(newBuffer),this.recycle.set(capacity,page)}page[count+1]=address,page[0]=count+1}else this.recycle.set(capacity,new Uint32Array([1,address]))}recyclePop(capacity){if(!this.recycle.has(capacity))return UNKNOWN;let page=this.recycle.get(capacity),count=page[0];if(count===0)return UNKNOWN;let address=page[count];return page[0]=count-1,address}gc(){this.assertNoActiveViews();let newDataBus=new Uint8Array(this.dataBus.buffer.byteLength);this.recycle.clear(),this.dataPointer=0;for(let i=0;i<this.controlPointer;i+=HEADER_SIZE){if(this.controlBus[i+COOKIE_OFFSET]===0)continue;let start=this.controlAdapter.getUint32(i+ADDRESS_OFFSET,IS_LITTLE_ENDIAN),size=(1<<this.controlBus[i+CAPACITY_OFFSET]>>>0)*this.wordSize,end=start+size;newDataBus.set(this.dataBus.subarray(start,end),this.dataPointer),this.controlAdapter.setUint32(i+ADDRESS_OFFSET,this.dataPointer,IS_LITTLE_ENDIAN),this.dataPointer+=size}this.dataBus=newDataBus,this.dataAdapter=new DataView(this.dataBus.buffer),this.auxiliary=new globalThis[`${this.bucketType}Array`](this.dataBus.buffer),this.writer=this.dataAdapter[`set${this.bucketType}`].bind(this.dataAdapter),this.reader=this.dataAdapter[`get${this.bucketType}`].bind(this.dataAdapter)}grow(){if(this.assertNoActiveViews(),this.size>2147483648)throw new RangeError("Data bus capacity exceeded");let newSize=this.size*2>>>0,newBuffer=this.dataBus.buffer.transfer(newSize);this.size=newSize,this.dataBus=new Uint8Array(newBuffer),this.dataAdapter=new DataView(newBuffer),this.writer=this.dataAdapter[`set${this.bucketType}`].bind(this.dataAdapter),this.reader=this.dataAdapter[`get${this.bucketType}`].bind(this.dataAdapter),this.auxiliary=new this.bucketArray(newBuffer)}headerGrow(){if(this.controlBus.byteLength>2147483648)throw new RangeError("Control bus capacity exceeded");let newSize=this.controlBus.byteLength*2>>>0,newBuffer=this.controlBus.buffer.transfer(newSize);this.controlBus=new Uint8Array(newBuffer),this.controlAdapter=new DataView(newBuffer)}push(handler,value){let meta=this.extractMetadata(handler,this.metadata);return this.assertNotBorrowed(meta.headerAddress),(meta.occupied+1)*this.wordSize>meta.byteCapacity?!1:(this.writer(meta.dataAddress+meta.occupied*this.wordSize,value,IS_LITTLE_ENDIAN),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,meta.occupied+1,IS_LITTLE_ENDIAN),!0)}pop(handler){let meta=this.extractMetadata(handler,this.metadata);if(this.assertNotBorrowed(meta.headerAddress),meta.occupied!==0)return this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,meta.occupied-1,IS_LITTLE_ENDIAN),this.reader(meta.dataAddress+(meta.occupied-1)*this.wordSize,IS_LITTLE_ENDIAN)}peek(handler){let meta=this.extractMetadata(handler,this.metadata);if(meta.occupied!==0)return this.reader(meta.dataAddress+(meta.occupied-1)*this.wordSize,IS_LITTLE_ENDIAN)}nudge(handler,value){let meta=this.extractMetadata(handler,this.metadata);return this.assertNotBorrowed(meta.headerAddress),(meta.occupied+1)*this.wordSize>meta.byteCapacity?!1:(this.dataBus.copyWithin(meta.dataAddress+this.wordSize,meta.dataAddress,meta.dataAddress+meta.occupied*this.wordSize),this.writer(meta.dataAddress,value,IS_LITTLE_ENDIAN),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,meta.occupied+1,IS_LITTLE_ENDIAN),!0)}pull(handler){let meta=this.extractMetadata(handler,this.metadata);if(this.assertNotBorrowed(meta.headerAddress),meta.occupied===0)return;let result=this.reader(meta.dataAddress,IS_LITTLE_ENDIAN);return this.dataBus.copyWithin(meta.dataAddress,meta.dataAddress+this.wordSize,meta.dataAddress+meta.occupied*this.wordSize),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,meta.occupied-1,IS_LITTLE_ENDIAN),result}head(handler){let meta=this.extractMetadata(handler,this.metadata);if(meta.occupied!==0)return this.reader(meta.dataAddress,IS_LITTLE_ENDIAN)}has(handler,value){let meta=this.extractMetadata(handler,this.metadata);if(meta.occupied===0)return!1;let rawAddres=meta.dataAddress>>>this.wordShift;return this.auxiliary.subarray(rawAddres,rawAddres+meta.occupied).includes(value)}indexOf(handler,searchElement,fromIndex=0){let meta=this.extractMetadata(handler,this.metadata);if(meta.occupied===0)return-1;let rawAddres=meta.dataAddress>>>this.wordShift;return this.auxiliary.subarray(rawAddres,rawAddres+meta.occupied).indexOf(searchElement,fromIndex)}lastIndexOf(handler,searchElement,fromIndex=-1){let meta=this.extractMetadata(handler,this.metadata);if(meta.occupied===0)return-1;let rawAddres=meta.dataAddress>>>this.wordShift;return this.auxiliary.subarray(rawAddres,rawAddres+meta.occupied).lastIndexOf(searchElement,fromIndex)}get(handler,index){let meta=this.extractMetadata(handler,this.metadata);if(!(index<0||index>=meta.occupied))return this.reader(meta.dataAddress+index*this.wordSize,IS_LITTLE_ENDIAN)}set(handler,index,value){let meta=this.extractMetadata(handler,this.metadata);return this.assertNotBorrowed(meta.headerAddress),index<0||index>=meta.occupied?!1:(this.writer(meta.dataAddress+index*this.wordSize,value,IS_LITTLE_ENDIAN),!0)}clear(handler,value=0){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let slots=meta.byteCapacity/this.wordSize,rawAddress=meta.dataAddress>>>this.wordShift;this.auxiliary.fill(value,rawAddress,rawAddress+slots),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,0,IS_LITTLE_ENDIAN)}fill(handler,value,start=0,end=null){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let slots=meta.byteCapacity/this.wordSize,lastIndex=end??slots;if(start>lastIndex)throw new RangeError(`start ${start} must be less or equal than end ${lastIndex}.`);if(start<0||start>slots)throw new RangeError(`start ${start} out of range [0, ${slots}].`);if(lastIndex<0||lastIndex>slots)throw new RangeError(`end ${lastIndex} out of range [0, ${slots}].`);let rawAddress=meta.dataAddress>>>this.wordShift;this.auxiliary.fill(value,rawAddress+start,rawAddress+lastIndex),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,lastIndex,IS_LITTLE_ENDIAN)}fillAll(handler,value){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let rawAddress=meta.dataAddress>>>this.wordShift,capacityElements=meta.byteCapacity/this.wordSize;this.auxiliary.fill(value,rawAddress,rawAddress+capacityElements),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,capacityElements,IS_LITTLE_ENDIAN)}put(handler,data){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let rawAddress=meta.dataAddress>>>this.wordShift,length=Math.min(1<<meta.capacityExponent>>>0,data.length);if(Array.isArray(data))this.auxiliary.set(data.slice(0,length),rawAddress);else if(isTypedArray(data))this.auxiliary.set(data.subarray(0,length),rawAddress);else{let actual=data?.constructor?.name??(data===null?"null":typeof data);throw new TypeError(`data must be Array or TypedArray, but ${actual} was given.`)}this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,Math.max(length,meta.occupied),IS_LITTLE_ENDIAN)}pick(handler){let meta=this.extractMetadata(handler,this.metadata),rawAddress=meta.dataAddress>>>this.wordShift;return meta.occupied===0?this.auxiliary.slice(rawAddress,rawAddress):this.auxiliary.slice(rawAddress,rawAddress+meta.occupied)}withView(...args){if(args.length<2)throw new TypeError("At least one handler and one callback are required");let callback=args.pop();if(typeof callback!="function")throw new TypeError("callback must be a function");let metadata=args.map(handler=>this.extractMetadata(handler,{})),headers=metadata.map(meta=>meta.headerAddress);if(new Set(headers).size!==headers.length)throw new Error("Duplicate handler");if(headers.map(header=>this.controlBus[header+FLAGS_OFFSET]).some(flag=>flag&VIEW_LOCK))throw new Error("Block is already borrowed");let acquiredCount=0;try{for(let header of headers)this.controlBus[header+FLAGS_OFFSET]|=VIEW_LOCK,acquiredCount++;let views=metadata.map(meta=>{let rawAddress=meta.dataAddress>>>this.wordShift;return this.auxiliary.subarray(rawAddress,rawAddress+meta.occupied)});return callback(...views)}finally{for(let i=0;i<acquiredCount;i++)this.controlBus[headers[i]+FLAGS_OFFSET]&=~VIEW_LOCK}}byteSize(handler){return this.extractMetadata(handler,this.metadata).byteCapacity}occupied(handler){return this.extractMetadata(handler,this.metadata).occupied}length(handler){return 1<<this.extractMetadata(handler,this.metadata).capacityExponent>>>0}isFull(handler){let meta=this.extractMetadata(handler,this.metadata);return(1<<meta.capacityExponent>>>0)-meta.occupied===0}copy(source,destination,slots=UNKNOWN){let metaA={},metaB={};this.extractMetadata(source,metaA),this.extractMetadata(destination,metaB),this.assertNotBorrowed(metaB.headerAddress);let maxSlotsDest=Math.floor(metaB.byteCapacity/this.wordSize),slotsToCopy=Math.min(metaA.occupied,maxSlotsDest,slots),newOccupied=Math.max(metaB.occupied,slotsToCopy);return this.controlAdapter.setUint32(metaB.headerAddress+OCCUPIED_OFFSET,newOccupied,IS_LITTLE_ENDIAN),this.dataBus.copyWithin(metaB.dataAddress,metaA.dataAddress,metaA.dataAddress+slotsToCopy*this.wordSize)}copyWithin(handler,target2,start,length){let meta=this.extractMetadata(handler,this.metadata);this.assertNotBorrowed(meta.headerAddress);let slots=Math.floor(meta.byteCapacity/this.wordSize);target2=Math.trunc(target2),start=Math.trunc(start),length=Math.trunc(length),target2<0&&(target2+=slots),start<0&&(start+=slots),target2=Math.max(0,Math.min(target2,slots)),start=Math.max(0,Math.min(start,slots));let maxRead=Math.max(0,meta.occupied-start),maxWrite=slots-target2;if(length=Math.max(0,Math.min(length,maxRead,maxWrite)),length===0)return this.dataBus;let targetAddress=meta.dataAddress+target2*this.wordSize,sourceAddress=meta.dataAddress+start*this.wordSize,newOccupied=Math.max(meta.occupied,target2+length);return this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,newOccupied,IS_LITTLE_ENDIAN),this.dataBus.copyWithin(targetAddress,sourceAddress,sourceAddress+length*this.wordSize)}append(target2,source){let metaTarget={},metaSource={};this.extractMetadata(target2,metaTarget),this.extractMetadata(source,metaSource),this.assertNotBorrowed(metaTarget.headerAddress);let available=metaTarget.byteCapacity/this.wordSize-metaTarget.occupied,count=Math.min(available,metaSource.occupied);if(count===0)return 0;let targetAddress=metaTarget.dataAddress+metaTarget.occupied*this.wordSize,sourceAddress=metaSource.dataAddress;return this.dataBus.copyWithin(targetAddress,sourceAddress,sourceAddress+count*this.wordSize),this.controlAdapter.setUint32(metaTarget.headerAddress+OCCUPIED_OFFSET,metaTarget.occupied+count,IS_LITTLE_ENDIAN),count}clone(handler){let meta=this.extractMetadata(handler,this.metadata),cloned=this.alloc(meta.byteCapacity/this.wordSize),cloneMeta={};return this.extractMetadata(cloned,cloneMeta),this.dataBus.copyWithin(cloneMeta.dataAddress,meta.dataAddress,meta.dataAddress+meta.byteCapacity),this.controlAdapter.setUint32(cloneMeta.headerAddress+OCCUPIED_OFFSET,meta.occupied,IS_LITTLE_ENDIAN),cloned}swap(source,target2){let metaA={},metaB={};this.extractMetadata(source,metaA),this.extractMetadata(target2,metaB),this.assertNotBorrowed(metaA.headerAddress),this.assertNotBorrowed(metaB.headerAddress),this.controlAdapter.setUint32(metaA.headerAddress+ADDRESS_OFFSET,metaB.dataAddress,IS_LITTLE_ENDIAN),this.controlAdapter.setUint32(metaB.headerAddress+ADDRESS_OFFSET,metaA.dataAddress,IS_LITTLE_ENDIAN),this.controlAdapter.setUint8(metaA.headerAddress+CAPACITY_OFFSET,metaB.capacityExponent),this.controlAdapter.setUint8(metaB.headerAddress+CAPACITY_OFFSET,metaA.capacityExponent),this.controlAdapter.setUint32(metaA.headerAddress+OCCUPIED_OFFSET,metaB.occupied,IS_LITTLE_ENDIAN),this.controlAdapter.setUint32(metaB.headerAddress+OCCUPIED_OFFSET,metaA.occupied,IS_LITTLE_ENDIAN)}dump(handler){let meta=this.extractMetadata(handler,this.metadata),capacity=meta.capacityExponent,capacityElements=2**capacity;if(!Number.isInteger(capacity)||capacity<1||capacity>31||meta.occupied>capacityElements)throw new Error("Cannot serialize a block with invalid metadata");let payload=this.pick(handler);if(payload.length!==meta.occupied||payload.constructor!==this.bucketArray)throw new Error("Cannot serialize a block with an invalid payload");return encode({v:1,wordType:this.wordType,capacity,occupied:meta.occupied,le:IS_LITTLE_ENDIAN,payload})}load(serialized){if(!(serialized instanceof ArrayBuffer)&&!(serialized instanceof Uint8Array))throw new TypeError("serialized must be an ArrayBuffer or Uint8Array");let envelope=decode(serialized);if(!envelope||typeof envelope!="object"||Array.isArray(envelope))throw new TypeError("Invalid serialized block envelope");if(envelope.v!==1)throw new Error(`Unsupported serialized block version: ${envelope.v}`);if(envelope.wordType!==this.wordType)throw new Error(`Can't load data, ${this.wordType} expected but ${envelope.wordType} found.`);if(!Number.isInteger(envelope.capacity)||envelope.capacity<1||envelope.capacity>31)throw new RangeError("Invalid serialized block capacity");let capacityElements=2**envelope.capacity;if(!Number.isSafeInteger(envelope.occupied)||envelope.occupied<0||envelope.occupied>capacityElements)throw new RangeError("Invalid serialized block occupancy");if(typeof envelope.le!="boolean")throw new TypeError("Invalid serialized endianness flag");let payload=envelope.payload;if(!isTypedArray(payload)||payload.constructor!==this.bucketArray||payload.length!==envelope.occupied)throw new TypeError(`Invalid payload: expected ${this.bucketType}Array with ${envelope.occupied} elements`);if(payload.BYTES_PER_ELEMENT!==this.wordSize||payload.byteLength!==envelope.occupied*this.wordSize)throw new TypeError("Serialized payload has an invalid element size");let handler=this.alloc(capacityElements),meta=this.extractMetadata(handler,this.metadata);return this.put(handler,payload),this.controlAdapter.setUint32(meta.headerAddress+OCCUPIED_OFFSET,envelope.occupied,IS_LITTLE_ENDIAN),handler}assertNotBorrowed(headerAddress){if(this.controlBus[headerAddress+FLAGS_OFFSET]&VIEW_LOCK)throw new Error("Block is borrowed")}assertNoActiveViews(){for(let i=0;i<this.controlPointer;i+=HEADER_SIZE)if(this.controlBus[i+COOKIE_OFFSET]!==0&&this.controlBus[i+FLAGS_OFFSET]&VIEW_LOCK)throw new Error("Cannot remap memory while a block is borrowed")}extractMetadata(handler,out){if(out.generation=handler/ROTATE_32BITS&CLAMP_11BITS,out.headerAddress=handler>>>0,this.controlAdapter.getUint8(out.headerAddress+COOKIE_OFFSET)!==this.bakeCookie(out.headerAddress,out.generation))throw new Error("Invalid or corrupted handle");return out.dataAddress=this.controlAdapter.getUint32(out.headerAddress+ADDRESS_OFFSET,IS_LITTLE_ENDIAN),out.capacityExponent=this.controlAdapter.getUint8(out.headerAddress+CAPACITY_OFFSET),out.byteCapacity=(1<<out.capacityExponent>>>0)*this.wordSize,out.occupied=this.controlAdapter.getUint32(out.headerAddress+OCCUPIED_OFFSET,IS_LITTLE_ENDIAN),out}bakeCookie(addr,gen){return(addr^gen&2047*2654435761)&255||1}recycleCount(){let count=0;for(let[,page]of this.recycle)count+=page[0];return count}get recycleBytes(){let total=0;for(let[capacity,page]of this.recycle)total+=page[0]*capacity;return total}get allocatedBytes(){return this.dataPointer-this.recycleBytes}get unallocatedBytes(){return this.size-this.dataPointer}get fragmentationRatio(){return this.dataPointer===0?0:this.recycleBytes/this.dataPointer}};return __toCommonJS(balloc_exports);})();
2
2
  if (typeof window !== "undefined") { window.Balloc = BallocModule.default || BallocModule; }