(()=>{"use strict";class e{alphabet;#e;constructor(e){this.alphabet=e,this.#e=BigInt(e.length)}encode(e){if(0===e.length)return"";let t=0n;for(let n=0;n<e.length;n++)t=t<<8n|BigInt(e[n]);const n=[];if(0n===t)return this.alphabet[0];for(;t>0n;){const e=Number(t%this.#e);n.push(this.alphabet[e]),t/=this.#e}return n.reverse().join("")}decode(e){if(0===e.length)return new Uint8Array(0);let t=0n;for(let n=0;n<e.length;n++){const r=this.alphabet.indexOf(e[n]);if(-1===r)throw new Error(`Invalid character at position ${n}: ${e[n]}`);t=t*this.#e+BigInt(r)}if(0n===t)return new Uint8Array([0]);let n=t,r=0;for(;n>0n;)n>>=8n,r++;const s=new Uint8Array(r);for(let e=r-1;e>=0;e--)s[e]=Number(0xffn&t),t>>=8n;return s}}const t=self;t.addEventListener("message",(n=>{const r=n.data;switch(r.type){case"encode":return t.postMessage(new e(r.alphabet).encode(r.buffer));case"decode":return t.postMessage(new e(r.alphabet).decode(r.data))}}))})();