@ddunigma/node
Version:
9 lines • 50.1 kB
JavaScript
'use strict';var chunkZTGECGM2_cjs=require('./chunk-ZTGECGM2.cjs'),chunkBCUBYE76_cjs=require('./chunk-BCUBYE76.cjs');var Ae=(n=>(n.DDU="ddu",n.DDU_V1="ddu_v1",n.ONECHARSET="oneCharSet",n))(Ae||{}),de={dduSetSymbol:"ddu",usePowerOfTwo:true,requiredLength:64};function Se(e,r,t){return e!=null&&typeof e=="object"&&!Array.isArray(e)?{dduChar:void 0,paddingChar:void 0,dduOptions:e}:{dduChar:e,paddingChar:r,dduOptions:t}}chunkBCUBYE76_cjs.a(Se,"resolveConstructorArgs");function Pe(e,r){return e<=1?0:r?Math.floor(Math.log2(e)):Math.ceil(Math.log2(e))}chunkBCUBYE76_cjs.a(Pe,"calculateBitLength");function we(e){return e>0&&(e&e-1)===0}chunkBCUBYE76_cjs.a(we,"isPowerOfTwo");function De(e){return e<31?1<<e:Math.pow(2,e)}chunkBCUBYE76_cjs.a(De,"maxValueForBitLength");var Tr=(()=>{let e=new Uint32Array(256);for(let r=0;r<256;r++){let t=r;for(let n=0;n<8;n++)t=t>>>1^(t&1?3988292384:0);e[r]=t;}return e})();function U(e){let r=4294967295;for(let t=0;t<e.length;t++)r=r>>>8^Tr[(r^e[t])&255];return ((r^4294967295)>>>0).toString(16).padStart(8,"0")}chunkBCUBYE76_cjs.a(U,"calculateCRC32");function ce(e,r){let t=Math.max(e.length,r.length),n=e.length^r.length;for(let o=0;o<t;o++){let a=o<e.length?e.charCodeAt(o):0,s=o<r.length?r.charCodeAt(o):0;n|=a^s;}return n===0}chunkBCUBYE76_cjs.a(ce,"constantTimeEquals");var Ee=["-","_","."];function ke(e){return e.length===0?e:e.replaceAll("+","-").replaceAll("/","_").replaceAll("=",".")}chunkBCUBYE76_cjs.a(ke,"toUrlSafe");function xe(e){return e.length===0?e:e.replaceAll("-","+").replaceAll("_","/").replaceAll(".","=")}chunkBCUBYE76_cjs.a(xe,"fromUrlSafe");function ve(e,r,t){if(r<=0||e.length<=r)return e;let n=Math.ceil(e.length/r),o=new Array(n*2-1),a=0;for(let s=0;s<e.length;s+=r)o[a++]=e.slice(s,s+r),s+r<e.length&&(o[a++]=t);return o.join("")}chunkBCUBYE76_cjs.a(ve,"splitIntoChunks");function Ue(e,r){if(e.length===0)return e;let t=r&&r!==`
`&&r!==`\r
`&&r!=="\r"?r:"",n=e.includes(`
`)||e.includes("\r"),o=t.length>0&&e.includes(t);if(!n&&!o)return e;let a=n?e.replace(/[\r\n]/g,""):e;return o&&(a=a.replaceAll(t,"")),a}chunkBCUBYE76_cjs.a(Ue,"removeChunks");var Oe={"":0,\u3131:1,\u3132:2,\u3133:3,\u3134:4,\u3135:5,\u3136:6,\u3137:7,\u3139:8,\u313A:9,\u313B:10,\u313C:11,\u313D:12,\u313E:13,\u313F:14,\u3140:15,\u3141:16,\u3142:17,\u3144:18,\u3145:19,\u3146:20,\u3147:21,\u3148:22,\u314A:23,\u314B:24,\u314C:25,\u314D:26,\u314E:27};function Be(e){return Object.prototype.hasOwnProperty.call(Oe,e)}chunkBCUBYE76_cjs.a(Be,"isKnownCodaChar");function Mr(e,r){let t=e.charCodeAt(0);if(t<44032||t>55203)return e;let n=t-(t-44032)%28,o=Oe[r]??0;return String.fromCharCode(n+o)}chunkBCUBYE76_cjs.a(Mr,"combineCoda");function Y(e,r){let t=new Array(e.length*r.length),n=0;for(let o of e)for(let a of r)t[n++]=Mr(o,a);return t}chunkBCUBYE76_cjs.a(Y,"buildCodaCharset");function X(e,r){let n=e===void 0||!Number.isFinite(e)?6:Math.floor(e);return Math.min(r==="brotli"?11:9,Math.max(0,n))}chunkBCUBYE76_cjs.a(X,"normalizeCompressionLevel");var Kr=new TextEncoder,_r=new TextDecoder;function K(e){return Kr.encode(e)}chunkBCUBYE76_cjs.a(K,"stringToBytes");function ue(e){return _r.decode(e)}chunkBCUBYE76_cjs.a(ue,"bytesToString");var Nr={symbol:"ddu",charSet:["\uB70C","\uB568","\uC774","\uC6B0","\uC57C","\uB4C0","\uB31C","\uB3A8"],codaChar:["","\u3131","\u3132","\u3137","\u3148","\u3147","\u3145","\u3146"],maxRequiredLength:64,bitLength:6,paddingChar:"\uBB50",useRepeatPadding:true},zr={symbol:"ddu_v1",charSet:["\uB70C","\uB568","\uC774","\uC6B0","\uC57C","!","?","."],maxRequiredLength:8,bitLength:6,paddingChar:"\uBB50",useRepeatPadding:true,usePowerOfTwo:false,encodingProfile:{bitLength:6,usePowerOfTwo:false,bitsPerPadChar:2}},$r={symbol:"oneCharSet",charSet:["A","s","q","r","0","z","3","t","y","1","5","2","4","E","B","C","Q","F","R","T","U","W","V","X","Y","Z","b","a","c","d","D","G","L","H","I","-","J","K","M","O","N","f","e","h","g","P","i","S","k","l","m","u","j","v","n","o","p","9","w","6","7","8","x","_"],paddingChar:"=",maxRequiredLength:64,bitLength:6};function Z(e){switch(e){case "ddu":return Nr;case "ddu_v1":return zr;case "oneCharSet":return $r;default:return}}chunkBCUBYE76_cjs.a(Z,"getCharSet");var Fr=65536;function Le(e,r,t,n){let o=chunkBCUBYE76_cjs.a((a,s,c,d,u)=>{if(Vr(c,t?.usePowerOfTwo)&&c>0){let h=Math.floor(Math.log2(c)),f=1<<h;return {charSet:a.length===f?a:a.slice(0,f),padding:s,requiredLength:f,bitLength:h,isPredefined:d,useRepeatPadding:u}}return {charSet:a.length===c?a:a.slice(0,c),padding:s,requiredLength:c,bitLength:c>0?Math.ceil(Math.log2(c)):0,isPredefined:d,useRepeatPadding:u}},"buildMeta");try{let a=e??t?.dduChar,s=r??t?.paddingChar;if(a){if(!s)throw new Error("[Ddu64 Constructor] paddingChar is required when dduChar is provided.");let h=typeof a=="string"?[...a]:[...a],f=t?.codaChar,m=f?!0:t?.useRepeatPadding??!1;if(f&&f.length>0){if(n){let g=f.filter(P=>!Be(P));if(g.length>0)throw new Error(`[Ddu64 Constructor] Unknown coda character(s): [${g.join(", ")}]. Coda must be empty ("") or a Hangul jongseong jamo (\u3131, \u3132, \u3133, \u2026 \u314E). Unknown coda collapses to no-coda and can create duplicate symbols.`)}h=Y(h,f);}if(n&&new Set(h).size!==h.length){let P=h.filter((C,S)=>h.indexOf(C)!==S);throw new Error(`[Ddu64 Constructor] Character set contains duplicate characters: [${[...new Set(P)].join(", ")}]`)}let y=t?.requiredLength??h.length;if(h.length<y)throw new Error("[Ddu64 Constructor] Insufficient characters.");return o(h,s,y,!1,m)}let c=t?.dduSetSymbol??de.dduSetSymbol??"ddu",d=Hr(c),u=d.codaChar?Y(d.charSet,d.codaChar):d.charSet,l=o(u,d.paddingChar,d.maxRequiredLength,!0,d.useRepeatPadding),p=d.encodingProfile;return p?(l.encodingProfile=p,l.bitLength=p.bitLength,l.usePowerOfTwo=p.usePowerOfTwo,l.bitsPerPadChar=p.bitsPerPadChar):(l.bitsPerPadChar=d.bitsPerPadChar,l.usePowerOfTwo=d.usePowerOfTwo,d.usePowerOfTwo===!1&&(l.bitLength=d.bitLength)),l}catch(a){if(n)throw a;return le(t)}}chunkBCUBYE76_cjs.a(Le,"resolveInitialCharSet");function Re(e,r,t){let n=[e,null];for(let a of n){let s=a?{...a}:le(t);try{let c=s.charSet,d=s.requiredLength,u=Array.from(new Set(c));if(u.length!==c.length){if(r){let h=c.filter((f,m)=>c.indexOf(f)!==m);throw new Error(`[Ddu64 normalizeCharSet] Character set contains duplicate characters: [${[...new Set(h)].join(", ")}]`)}c=u,s.isPredefined||(d=c.length);}if(c.length<d)throw new Error(`[Ddu64 normalizeCharSet] Insufficient characters. Required: ${d}, Has: ${c.length}`);if(d<2)throw new Error("[Ddu64 normalizeCharSet] At least 2 unique characters required.");if(c.length===0)throw new Error("[Ddu64 normalizeCharSet] Empty charset.");if(c.find(h=>h.length!==1)){if(r)throw new Error("[Ddu64 normalizeCharSet] Multi-character symbols are not supported.");continue}if(c.length>Fr){if(r)throw new Error("[Ddu64 normalizeCharSet] Charset size exceeds maximum supported size of 65536.");continue}if(s.padding.length!==1)throw new Error(`[Ddu64 normalizeCharSet] Padding length mismatch. Expected 1, got ${s.padding.length}`);if(c.includes(s.padding)){if(r)throw new Error(`[Ddu64 normalizeCharSet] Padding character "${s.padding}" conflicts with charset.`);c=c.filter(h=>h!==s.padding);}for(let h of c){if(h.includes(`
`)||h.includes("\r"))throw new Error("[Ddu64 normalizeCharSet] Newline and carriage return characters are reserved.");if(Ie(h))throw new Error(`[Ddu64 normalizeCharSet] Lone surrogate code unit (U+${h.charCodeAt(0).toString(16).toUpperCase()}) is not allowed; it corrupts on UTF-8/URL/JSON boundaries.`)}if(s.padding.includes(`
`)||s.padding.includes("\r"))throw new Error("[Ddu64 normalizeCharSet] Newline and carriage return characters are reserved.");if(Ie(s.padding))throw new Error("[Ddu64 normalizeCharSet] Padding character must not be a lone surrogate code unit.");return {charSet:c.length===d?c:c.slice(0,d),padding:s.padding,isPredefined:s.isPredefined}}catch(c){if(r)throw c}}let o=le(t);return {charSet:o.charSet.slice(0,o.requiredLength),padding:o.padding,isPredefined:true}}chunkBCUBYE76_cjs.a(Re,"normalizeCharSet");function Te(e,r,t){for(let n of Ee){for(let o of e)if(o.includes(n)){let a=`[Ddu64 Constructor] URL-Safe mode conflict: charset character "${o}" contains "${n}".`;if(t)throw new Error(a);return false}if(r.includes(n)){let o=`[Ddu64 Constructor] URL-Safe mode conflict: padding character "${r}" contains "${n}".`;if(t)throw new Error(o);return false}}return true}chunkBCUBYE76_cjs.a(Te,"isUrlSafeCompatible");function Ie(e){if(e.length!==1)return false;let r=e.charCodeAt(0);return r>=55296&&r<=57343}chunkBCUBYE76_cjs.a(Ie,"isLoneSurrogate");function Vr(e,r){return r!==void 0?r?e>0:false:e>0&&(e&e-1)===0}chunkBCUBYE76_cjs.a(Vr,"shouldUsePowerOfTwo");function Hr(e){let r=Z(e);if(!r)throw new Error(`CharSet with symbol ${e} not found`);return r}chunkBCUBYE76_cjs.a(Hr,"getCharSetOrThrow");function le(e){let r=e?.dduSetSymbol??de.dduSetSymbol??"oneCharSet",t=Z(r)??Z("oneCharSet");if(!t)throw new Error("Critical: No fallback CharSet available");return {charSet:t.codaChar?Y(t.charSet,t.codaChar):t.charSet,padding:t.paddingChar,requiredLength:t.maxRequiredLength,bitLength:t.encodingProfile?.bitLength??t.bitLength,isPredefined:true,useRepeatPadding:t.useRepeatPadding,bitsPerPadChar:t.encodingProfile?.bitsPerPadChar??t.bitsPerPadChar,usePowerOfTwo:t.encodingProfile?.usePowerOfTwo??t.usePowerOfTwo,encodingProfile:t.encodingProfile}}chunkBCUBYE76_cjs.a(le,"getFallbackCharSet");var qr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Me(e,r,t,n){return t&&n===6&&r==="="&&e.join("")===qr}chunkBCUBYE76_cjs.a(Me,"canUseNativeBase64FastPath");function Ke(e){let r=Gr(e);if(r===null)return null;let t=0,n=r.length;for(;n>0&&r[n-1]==="=";)t++,n--;return {payload:r.slice(0,n),paddingBits:t===2?4:t===1?2:0}}chunkBCUBYE76_cjs.a(Ke,"encodeNativeBase64");function _e(e,r,t){let n=r===4?2:r===2?1:r===0?0:-1;if(n<0)return null;for(let o=0;o<e.length;o++)if(!t(e.charCodeAt(o)))return null;return jr(e+"=".repeat(n))}chunkBCUBYE76_cjs.a(_e,"decodeNativeBase64");function Gr(e){let r=e.toBase64;if(typeof r=="function")return r.call(e);let t=globalThis.Buffer;return t?.from?t.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"):null}chunkBCUBYE76_cjs.a(Gr,"bytesToBase64");function jr(e){let r=Uint8Array;if(typeof r.fromBase64=="function")return r.fromBase64(e);let t=globalThis.Buffer;if(t?.from){let n=t.from(e,"base64");return new Uint8Array(n)}return null}chunkBCUBYE76_cjs.a(jr,"base64ToBytes");function J(e,r){if(!e)throw new chunkZTGECGM2_cjs.m("[Ddu64 adapter] No platform adapter available. Use encodeAsync()/decodeAsync() in browser environments, or provide an adapter via options.adapter.",r);return e}chunkBCUBYE76_cjs.a(J,"requireSyncAdapter");function Ne(e,r,t){let n=J(e.adapter,"encode");if(!n.encryptSync)throw new chunkZTGECGM2_cjs.m("[Ddu64 encrypt] Sync encryption unavailable. Use encodeAsync() in browser environments.","encode");let o=Ve(e,n,"encrypt","encode");return n.encryptSync(r,o,t)}chunkBCUBYE76_cjs.a(Ne,"encryptSyncWithAdapter");function ze(e,r,t){let n=J(e.adapter,"decode");if(!n.decryptSync)throw new chunkZTGECGM2_cjs.m("[Ddu64 decrypt] Sync decryption unavailable. Use decodeAsync() in browser environments.","decode");let o=Ve(e,n,"decrypt","decode");return n.decryptSync(r,o,t)}chunkBCUBYE76_cjs.a(ze,"decryptSyncWithAdapter");function $e(e,r,t,n){let o=J(e,"encode");if(t==="brotli"){if(!o.brotliCompressSync)throw new chunkZTGECGM2_cjs.m("[Ddu64 compress] Brotli compression is unavailable in the current runtime.","encode");return o.brotliCompressSync(r,n)}if(!o.deflateSync)throw new chunkZTGECGM2_cjs.m("[Ddu64 compress] Sync compression unavailable. Use encodeAsync() in browser environments.","encode");return o.deflateSync(r,n)}chunkBCUBYE76_cjs.a($e,"compressSyncWithAdapter");function Fe(e,r,t,n){let o=J(e,"decode");if(t==="brotli"){if(!o.brotliDecompressSync)throw new chunkZTGECGM2_cjs.m("[Ddu64 decompress] Brotli decompression is unavailable in the current runtime.","decode");return o.brotliDecompressSync(r,n)}if(!o.inflateSync)throw new chunkZTGECGM2_cjs.m("[Ddu64 decompress] Sync decompression unavailable. Use decodeAsync() in browser environments.","decode");return o.inflateSync(r,n)}chunkBCUBYE76_cjs.a(Fe,"decompressSyncWithAdapter");function Ve(e,r,t,n){if(e.encryptionKeyHash)return e.encryptionKeyHash;if(!r.deriveKeySync){let a=t==="encrypt"?"encodeAsync":"decodeAsync";throw new chunkZTGECGM2_cjs.m(`[Ddu64 ${t}] Sync key derivation unavailable. Use ${a}() in browser environments.`,n)}let o=r.deriveKeySync(e.encryptionKey,e.keyDerivation);return e.setEncryptionKeyHash(o),o}chunkBCUBYE76_cjs.a(Ve,"getSyncKeyHash");function Q(e,r){throw chunkZTGECGM2_cjs.p(e)?e:new r(chunkZTGECGM2_cjs.q(e),e)}chunkBCUBYE76_cjs.a(Q,"rethrowTyped");function He(e,r,t){try{return Ne(e,r,t)}catch(n){Q(n,chunkZTGECGM2_cjs.g);}}chunkBCUBYE76_cjs.a(He,"runEncryptSync");function qe(e,r,t){try{return ze(e,r,t)}catch(n){Q(n,chunkZTGECGM2_cjs.h);}}chunkBCUBYE76_cjs.a(qe,"runDecryptSync");function fe(e,r,t,n){try{return $e(e,r,t,n)}catch(o){Q(o,chunkZTGECGM2_cjs.e);}}chunkBCUBYE76_cjs.a(fe,"runCompressSync");function Ge(e,r,t,n){try{return Fe(e,r,t,n)}catch(o){Q(o,chunkZTGECGM2_cjs.f);}}chunkBCUBYE76_cjs.a(Ge,"runDecompressSync");async function je(e,r,t){try{let n=ee(e.adapter,"encode"),o=await Xe(e,n);return await n.encrypt(r,o,t)}catch(n){throw re(n,"encode","encrypt")}}chunkBCUBYE76_cjs.a(je,"encryptAsyncWithAdapter");async function We(e,r,t){try{let n=ee(e.adapter,"decode"),o=await Xe(e,n);return await n.decrypt(r,o,t)}catch(n){throw re(n,"decode","decrypt")}}chunkBCUBYE76_cjs.a(We,"decryptAsyncWithAdapter");async function he(e,r,t,n){try{let o=ee(e,"encode");if(t==="brotli"){if(!o.brotliCompress)throw new chunkZTGECGM2_cjs.m("[Ddu64 compress] Brotli compression is unavailable in the current runtime.","encode");return await o.brotliCompress(r,n)}return await o.deflate(r,n)}catch(o){throw re(o,"encode","compress")}}chunkBCUBYE76_cjs.a(he,"compressAsyncWithAdapter");async function Ye(e,r,t,n){try{let o=ee(e,"decode");if(t==="brotli"){if(!o.brotliDecompress)throw new chunkZTGECGM2_cjs.m("[Ddu64 decompress] Brotli decompression is unavailable in the current runtime.","decode");return await o.brotliDecompress(r,n)}return await o.inflate(r,n)}catch(o){throw re(o,"decode","decompress")}}chunkBCUBYE76_cjs.a(Ye,"decompressAsyncWithAdapter");function ee(e,r){if(!e)throw new chunkZTGECGM2_cjs.m("[Ddu64 adapter] No platform adapter available. Use @ddunigma/node or @ddunigma/node/browser, or provide an adapter via options.adapter.",r);return e}chunkBCUBYE76_cjs.a(ee,"requireAsyncAdapter");async function Xe(e,r){if(e.encryptionKeyHash)return e.encryptionKeyHash;if(e.encryptionKeyHashPromise)return e.encryptionKeyHashPromise;let t=r.deriveKey(e.encryptionKey,e.keyDerivation).then(n=>(e.setEncryptionKeyHash(n),n)).finally(()=>{e.encryptionKeyHashPromise=void 0;});return e.encryptionKeyHashPromise=t,t}chunkBCUBYE76_cjs.a(Xe,"getAsyncKeyHash");function re(e,r,t){if(chunkZTGECGM2_cjs.p(e))return e;let n=chunkZTGECGM2_cjs.q(e);switch(t){case "compress":return new chunkZTGECGM2_cjs.e(n,e);case "decompress":return new chunkZTGECGM2_cjs.f(n,e);case "encrypt":return new chunkZTGECGM2_cjs.g(n,e);case "decrypt":return new chunkZTGECGM2_cjs.h(n,e)}}chunkBCUBYE76_cjs.a(re,"toAsyncGatewayError");var Ze=new Map;function Je(e,r=false){let t=r?e.join(""):void 0;if(t!==void 0){let u=Ze.get(t);if(u)return u}let n=new Uint16Array(e.length),o=65535,a=0;for(let u=0;u<e.length;u++){let l=e[u].charCodeAt(0);n[u]=l,l>a&&(a=l),l<o&&(o=l);}let s=e.length>0?o:0,c=new Int32Array(a-s+1);c.fill(-1);for(let u=0;u<e.length;u++)c[n[u]-s]=u;let d={charCodeLookup:c,charCodes:n,lookupOffset:s};return t!==void 0&&Ze.set(t,d),d}chunkBCUBYE76_cjs.a(Je,"buildCharsetLookupTables");function _(e,r,t){let n=r-t;return n>=0&&n<e.length?e[n]:-1}chunkBCUBYE76_cjs.a(_,"lookupCharIndex");var Qe=8;function er(e,r,t,n){return Math.ceil(e/(n?1:2))*t-r}chunkBCUBYE76_cjs.a(er,"decodedBitCount");function x(e,r,t,n){if(e===void 0)return r;if(e===Number.POSITIVE_INFINITY)return Number.POSITIVE_INFINITY;if(!Number.isFinite(e)||e<=0){if(t)throw new chunkZTGECGM2_cjs.k(`[Ddu64 options] Invalid ${n}. Must be a positive finite number or Infinity.`);return r}return Math.floor(e)}chunkBCUBYE76_cjs.a(x,"normalizeLimit");function rr(e,r,t,n){if(e===0)return 0;if(r<0||r>=t)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid padding bits: ${r}`);let o=er(e,r,t,n);if(o<0)throw new chunkZTGECGM2_cjs.d("[Ddu64 decode] Invalid decoded bit length");return Math.ceil(o/Qe)}chunkBCUBYE76_cjs.a(rr,"estimateDecodedBytes");function tr(e,r){if(!r&&e.length%2!==0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid encoded length for variable charset. Expected multiple of 2, got ${e.length}`)}chunkBCUBYE76_cjs.a(tr,"assertEncodedInputAligned");function nr(e,r,t,n){if(e.length===0)return;let o=er(e.length,r,t,n);if(o<0||o%Qe!==0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid encoded bit length. Expected a whole number of bytes, got ${o} bits.`)}chunkBCUBYE76_cjs.a(nr,"assertDecodedBitLength");function or(e,r,t,n,o,a){if(r===0)return;if(e.length===0)throw new chunkZTGECGM2_cjs.d("[Ddu64 decode] Invalid padding bits without payload");let s=(1<<r)-1,c;if(t){let d=e[e.length-1],u=_(n,d.charCodeAt(0),a);if(u<0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid character "${d}" at ${e.length-1}`);c=u;}else {let d=e[e.length-2],u=e[e.length-1],l=_(n,d.charCodeAt(0),a),p=_(n,u.charCodeAt(0),a);if(l<0||p<0)throw new chunkZTGECGM2_cjs.d("[Ddu64 decode] Invalid character in final encoded chunk");c=l*o+p;}if((c&s)!==0)throw new chunkZTGECGM2_cjs.d("[Ddu64 decode] Invalid non-zero padding bits in final symbol")}chunkBCUBYE76_cjs.a(or,"assertCanonicalPadding");var N="DDS1",z="ELYSIA",$="GRISEO";var Wr=new TextEncoder;function O(e,r,t){let n=t-r.length;if(n<0)return false;for(let o=0;o<r.length;o++)if(e.charCodeAt(n+o)!==r.charCodeAt(o))return false;return true}chunkBCUBYE76_cjs.a(O,"endsWithAt");function ir(e,r,t,n=2){let o=e.length,a=r.length,s={cleanedInput:e,paddingBits:0,isEncrypted:false,pipelineVersion:2};if(a===0||o<a)return s;let d=Math.max(0,t-1).toString().length;for(let u=Math.min(d,o);u>=1;u--){let l=o-u,p=true;for(let C=l;C<o;C++){let S=e.charCodeAt(C);if(S<48||S>57){p=false;break}}if(!p||u>1&&e.charCodeAt(l)===48)continue;let h=0;for(let C=l;C<o;C++)h=h*10+(e.charCodeAt(C)-48);if(h>=t)continue;let f=l,m=false,y,g=2;f>=2&&O(e,"V4",f)?(g=4,f-=2):f>=2&&O(e,"V3",f)&&(g=3,f-=2),f>=3&&O(e,"ENC",f)&&(m=true,f-=3),f>=z.length&&O(e,z,f)?(y="deflate",f-=z.length):f>=$.length&&O(e,$,f)&&(y="brotli",f-=$.length);let P=f-a;if(P>=0&&O(e,r,f))return {cleanedInput:e.substring(0,P),paddingBits:h,compressionAlgorithm:y,isEncrypted:m,pipelineVersion:g}}if(O(e,r,o)){let u=0,l=o;for(;l>=a&&O(e,r,l);)u++,l-=a;if(u>0){let p=u*n;if(p<t)return {cleanedInput:e.substring(0,l),paddingBits:p,isEncrypted:false,pipelineVersion:2}}}return s}chunkBCUBYE76_cjs.a(ir,"parseFooter");function Yr(e){let r=e.lastIndexOf("CHK");if(r===-1)return {data:e,checksum:null};let t=e.slice(r+3);return t.length!==8||!/^[0-9a-f]+$/i.test(t)?{data:e,checksum:null}:{data:e.slice(0,r),checksum:t.toLowerCase()}}chunkBCUBYE76_cjs.a(Yr,"extractChecksum");var Xr=/^[0-9a-f]{8}$/i;function ar(e){let r=e.length;if(r>=11){let n=e.charCodeAt(r-11),o=e.charCodeAt(r-10),a=e[r-9];if(n===67&&o===75&&(a==="P"||a==="O")){let s=e.slice(r-8);if(Xr.test(s))return {data:e.slice(0,r-11),checksum:s.toLowerCase(),scope:a==="P"?"plaintext":"output"}}}let t=Yr(e);return {data:t.data,checksum:t.checksum,scope:null}}chunkBCUBYE76_cjs.a(ar,"extractScopedChecksum");function Zr(e){return e.length*2+N.length+2}chunkBCUBYE76_cjs.a(Zr,"getStreamHeaderLength");function $t(e,r){let t=r.compressionAlgorithm==="brotli"?"B":r.compressionAlgorithm==="deflate"?"D":"N",n=r.encrypted?"1":"0";return `${e}${N}${t}${n}${e}`}chunkBCUBYE76_cjs.a($t,"buildStreamHeader");function Ft(e,r){let t=Zr(r);if(e.length<t||!e.startsWith(r))return null;let n=r.length;if(e.slice(n,n+N.length)!==N)throw new Error("[wireFormat] Invalid stream header magic");let a=e[n+N.length],s=e[n+N.length+1];if(e.slice(t-r.length,t)!==r)throw new Error("[wireFormat] Invalid stream header terminator");let d=a==="B"?"brotli":a==="D"?"deflate":a==="N"?void 0:null;if(d===null)throw new Error("[wireFormat] Invalid stream header compression flag");if(s!=="0"&&s!=="1")throw new Error("[wireFormat] Invalid stream header encryption flag");return {compressionAlgorithm:d,encrypted:s==="1"}}chunkBCUBYE76_cjs.a(Ft,"parseStreamHeader");function sr(e){let{paddingBits:r,compressionAlgorithm:t,isEncrypted:n,paddingChar:o,useRepeatPadding:a,bitsPerPadChar:s=2,pipelineVersion:c=2}=e;if(!n&&c!==2)throw new Error("[wireFormat] Pipeline version markers require encryption");if(r===0&&!t&&!n&&c===2)return "";if(a&&!t&&!n&&c===2&&r>0&&r%s===0){let u=r/s;return o.repeat(u)}return o+(t==="deflate"?z:t==="brotli"?$:"")+(n?"ENC":"")+(c===4?"V4":c===3?"V3":"")+r.toString()}chunkBCUBYE76_cjs.a(sr,"buildFooter");function te(e){return Wr.encode(`ddunigma:wire:v4;enc=1;compress=${e.compressionAlgorithm??"none"}`)}chunkBCUBYE76_cjs.a(te,"buildEncryptionAAD");function dr(e,r,t){let n=r?.checksum??t.defaultChecksum,o=r?.compress!==false,a=r?.encrypt!==false,s=e;t.reportDecodeStart(e.length);let c=x(r?.maxEncodedChars,t.defaultMaxEncodedChars,true,"maxEncodedChars");if(e.length>c)throw new chunkZTGECGM2_cjs.l(`[Ddu64 decode] Encoded input exceeds limit. Length: ${e.length}, Limit: ${c} characters`,"decode");let d=r?.chunkSeparator??t.defaultChunkSeparator;s=Ue(s,d),t.urlSafe&&(s=xe(s));let u=null,l=null;if(n){let B=ar(s);if(u=B.checksum,l=B.scope,s=B.data,!u)throw new chunkZTGECGM2_cjs.i("[Ddu64 checksum] Checksum verification requested, but no checksum marker was found.")}t.shouldObfuscate(r)&&(s=t.deobfuscate(s));let{cleanedInput:p,paddingBits:h,compressionAlgorithm:f,isEncrypted:m,pipelineVersion:y}=ir(s,t.paddingChar,t.bitLength,t.bitsPerPadChar);if((r?.requireEncryption??t.defaultRequireEncryption)&&a&&!m)throw new chunkZTGECGM2_cjs.h("[Ddu64 decode] Encryption is required, but the payload has no authenticated encryption footer.");if(m&&a&&!t.encryptionKey)throw new chunkZTGECGM2_cjs.h("[Ddu64 decode] Encrypted payload requires an encryptionKey");let P=m&&y===4?te({compressionAlgorithm:f}):void 0;tr(p,t.usePowerOfTwo),or(p,h,t.usePowerOfTwo,t.dduCharCodeLookup,t.charSetSize,t.dduCharCodeLookupOffset),nr(p,h,t.bitLength,t.usePowerOfTwo);let C=x(r?.maxDecodedBytes,t.defaultMaxDecodedBytes,true,"maxDecodedBytes"),S=rr(p.length,h,t.bitLength,t.usePowerOfTwo);if(S>C)throw new chunkZTGECGM2_cjs.l(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${S} bytes, Limit: ${C} bytes`,"decode");return t.reportBitpackDecode(p.length,e.length),{decoded:t.decodeChars(p,h),extractedChecksum:u,extractedChecksumScope:l,compressionAlgorithm:f,isEncrypted:m,pipelineVersion:y,encryptionAAD:P,allowInternalDecompress:o,allowInternalDecrypt:a}}chunkBCUBYE76_cjs.a(dr,"runDecodePrelude");function cr(e){return e.omitFooter?"":sr({paddingBits:e.paddingBits,compressionAlgorithm:e.compressionAlgorithm,isEncrypted:e.isEncrypted,paddingChar:e.paddingChar,useRepeatPadding:e.useRepeatPadding&&!e.compressionAlgorithm&&!e.isEncrypted,bitsPerPadChar:e.bitsPerPadChar,pipelineVersion:e.isEncrypted?e.pipelineVersion:2})}chunkBCUBYE76_cjs.a(cr,"buildEncodeFooter");function ur(e){let r=e.encoded;if(e.shouldObfuscate(e.options)&&(r=e.getObfuscationLayer().obfuscate(r)),e.shouldChecksum&&e.checksum){let t=e.checksumScope==="plaintext"?"P":"O";r=r+"CK"+t+e.checksum;}return e.urlSafe&&(r=ke(r)),e.chunkSize&&e.chunkSize>0&&(e.assertSafeChunkSeparator(r,e.chunkSeparator),r=ve(r,e.chunkSize,e.chunkSeparator)),r}chunkBCUBYE76_cjs.a(ur,"applyPostEncoding");var pe=8192;function lr(e,r,t){let n=e.length;if(n===0)return {payload:"",paddingBits:0};let o=Math.ceil(n*8/r),a=Math.min(o,pe),s=new Uint16Array(a),c=[],d=0,u=0;if(r===6){let l=0;for(;l+2<n;l+=3){let h=e[l],f=e[l+1],m=e[l+2];s[d++]=t[h>>>2],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0),s[d++]=t[(h&3)<<4|f>>>4],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0),s[d++]=t[(f&15)<<2|m>>>6],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0),s[d++]=t[m&63],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0);}let p=n-l;if(p===1){let h=e[l];s[d++]=t[h>>>2],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0),s[d++]=t[(h&3)<<4],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0),u=4;}else if(p===2){let h=e[l],f=e[l+1];s[d++]=t[h>>>2],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0),s[d++]=t[(h&3)<<4|f>>>4],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0),s[d++]=t[(f&15)<<2],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0),u=2;}}else if(r===8)for(let l=0;l<n;l++)s[d++]=t[e[l]],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0);else {let l=(1<<r)-1,p=0,h=0;for(let f=0;f<n;f++)for(p=p<<8|e[f],h+=8;h>=r;)h-=r,s[d++]=t[p>>h&l],d===a&&(c.push(String.fromCharCode.apply(null,s)),d=0),p&=(1<<h)-1;h>0&&(u=r-h,s[d++]=t[p<<u&l]);}return d>0&&c.push(String.fromCharCode.apply(null,s.subarray(0,d))),{payload:c.length===1?c[0]:c.join(""),paddingBits:u}}chunkBCUBYE76_cjs.a(lr,"packPow2ToString");function fr(e,r,t,n,o){let a=e.length;if(a===0)return new Uint8Array(0);let s=Math.ceil((a*t-r)/8),c=new Uint8Array(s+1),d=0,u=n.length;if(t===6){let f=a-a%4;f===a&&r>0&&(f-=4);let m=0;for(;m<f;m+=4){let C=e.charCodeAt(m)-o,S=C>=0&&C<u?n[C]:-1;if(S<0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid character "${e[m]}" at ${m}`);let D=e.charCodeAt(m+1)-o,B=D>=0&&D<u?n[D]:-1;if(B<0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid character "${e[m+1]}" at ${m+1}`);let ne=e.charCodeAt(m+2)-o,oe=ne>=0&&ne<u?n[ne]:-1;if(oe<0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid character "${e[m+2]}" at ${m+2}`);let ie=e.charCodeAt(m+3)-o,ge=ie>=0&&ie<u?n[ie]:-1;if(ge<0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid character "${e[m+3]}" at ${m+3}`);c[d++]=S<<2|B>>>4,c[d++]=(B&15)<<4|oe>>>2,c[d++]=(oe&3)<<6|ge;}let y=0,g=0,P=a-1;for(;m<a;m++){let S=e.charCodeAt(m)-o,D=S>=0&&S<u?n[S]:-1;if(D<0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid character "${e[m]}" at ${m}`);for(y=y<<6|D,g+=6,m===P&&r>0&&(y>>=r,g-=r);g>=8;)g-=8,c[d++]=y>>g&255,y&=(1<<g)-1;}return c.subarray(0,d)}if(t===8&&r===0){for(let f=0;f<a;f++){let y=e.charCodeAt(f)-o,g=y>=0&&y<u?n[y]:-1;if(g<0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid character "${e[f]}" at ${f}`);c[d++]=g;}return c.subarray(0,d)}let l=0,p=0,h=a-1;for(let f=0;f<a;f++){let y=e.charCodeAt(f)-o,g=y>=0&&y<u?n[y]:-1;if(g<0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid character "${e[f]}" at ${f}`);for(l=l<<t|g,p+=t,f===h&&r>0&&(l>>=r,p-=r);p>=8;)p-=8,c[d++]=l>>p&255,l&=(1<<p)-1;}return c.subarray(0,d)}chunkBCUBYE76_cjs.a(fr,"unpackPow2FromString");function hr(e,r,t,n){let o=e.length;if(o===0)return {payload:"",paddingBits:0};let a=[],s=new Uint16Array(pe),c=0,d=0,u=0,l=0,p=chunkBCUBYE76_cjs.a(h=>{s[c++]=h,c===pe&&(a.push(String.fromCharCode.apply(null,s)),c=0);},"pushCode");for(let h=0;h<o;h++)for(d=d<<8|e[h],u+=8;u>=r;){u-=r;let f=d>>u,m=f/t|0;p(n[m]),p(n[f-m*t]),d&=(1<<u)-1;}if(u>0){l=r-u;let h=d<<l,f=h/t|0;p(n[f]),p(n[h-f*t]);}return c>0&&a.push(String.fromCharCode.apply(null,s.subarray(0,c))),{payload:a.length===1?a[0]:a.join(""),paddingBits:l}}chunkBCUBYE76_cjs.a(hr,"packNonPow2ToString");function pr(e,r,t,n,o,a){let s=e.length;if(s===0)return new Uint8Array(0);let c=Math.ceil(s/2),d=Math.ceil((c*t-r)/8),u=new Uint8Array(d+1),l=0,p=De(t),h=o.length,f=0,m=0;for(let y=0;y<s;y+=2){let g=e.charCodeAt(y)-a,P=g>=0&&g<h?o[g]:-1;if(P<0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid character "${e[y]}" at ${y}`);if(y+1>=s)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Truncated symbol pair at ${y+1}`);let C=e.charCodeAt(y+1)-a,S=C>=0&&C<h?o[C]:-1;if(S<0)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Invalid character "${e[y+1]}" at ${y+1}`);let D=P*n+S;if(D>=p)throw new chunkZTGECGM2_cjs.d(`[Ddu64 decode] Value ${D} exceeds range at position ${y}`);for(f=f<<t|D,m+=t,y+2>=s&&r>0&&(f>>=r,m-=r);m>=8;)m-=8,u[l++]=f>>m&255,f&=(1<<m)-1;}return u.subarray(0,l)}chunkBCUBYE76_cjs.a(pr,"unpackNonPow2FromString");function mr(e,r,t,n,o){if(e.length===0)return "";let a=o.canUseNativeBase64?Ke(e):null,s,c;if(a)s=a.paddingBits,c=a.payload;else if(o.bitPackConfig.usePowerOfTwo){let u=lr(e,o.bitPackConfig.bitLength,o.dduCharCodes);s=u.paddingBits,c=u.payload;}else {let u=hr(e,o.bitPackConfig.bitLength,o.bitPackConfig.charsetSize,o.dduCharCodes);s=u.paddingBits,c=u.payload;}let d=cr({paddingBits:s,compressionAlgorithm:r,isEncrypted:t,paddingChar:o.paddingChar,useRepeatPadding:o.useRepeatPadding,bitsPerPadChar:o.bitsPerPadChar,pipelineVersion:o.encryptedPipelineVersion,omitFooter:n?.omitFooter});return c+d}chunkBCUBYE76_cjs.a(mr,"encodePayload");function yr(e,r,t){if(e.length===0)return new Uint8Array(0);let o=t.canUseNativeBase64?_e(e,r,a=>_(t.dduCharCodeLookup,a,t.dduCharCodeLookupOffset)>=0):null;return o||(t.bitPackConfig.usePowerOfTwo?fr(e,r,t.bitPackConfig.bitLength,t.dduCharCodeLookup,t.dduCharCodeLookupOffset):pr(e,r,t.bitPackConfig.bitLength,t.bitPackConfig.charsetSize,t.dduCharCodeLookup,t.dduCharCodeLookupOffset))}chunkBCUBYE76_cjs.a(yr,"decodePayload");function gr(e,r){let t=new Set(e);t.add(r);let n=z+$+"ENC"+"V3"+"V4";for(let o of n)t.add(o);for(let o of "0123456789")t.add(o);return [...t]}chunkBCUBYE76_cjs.a(gr,"buildObfuscationAlphabet");function k(e,r="construct"){if(e===void 0)return;if(typeof e!="object"||e===null||Array.isArray(e))throw new chunkZTGECGM2_cjs.k("[Ddu64 options] Options must be an object.",r);let t=e;E(e.compress,"compress",r),E(t.encrypt,"encrypt",r),E(e.checksum,"checksum",r),E(t.omitFooter,"omitFooter",r),E(e.obfuscate,"obfuscate",r),E(e.requireEncryption,"requireEncryption",r),e.compressionLevel!==void 0&&(typeof e.compressionLevel!="number"||!Number.isFinite(e.compressionLevel))&&A(r,"compressionLevel must be a finite number"),e.onProgress!==void 0&&typeof e.onProgress!="function"&&A(r,"onProgress must be a function"),e.compressionAlgorithm!==void 0&&e.compressionAlgorithm!=="deflate"&&e.compressionAlgorithm!=="brotli"&&A(r,`compressionAlgorithm must be "deflate" or "brotli", got ${String(e.compressionAlgorithm)}`),e.checksumScope!==void 0&&e.checksumScope!=="plaintext"&&e.checksumScope!=="output"&&A(r,`checksumScope must be "plaintext" or "output", got ${String(e.checksumScope)}`),e.chunkSize!==void 0&&(!Number.isSafeInteger(e.chunkSize)||e.chunkSize<0)&&A(r,"chunkSize must be a non-negative safe integer (0 disables chunking)"),e.chunkSeparator!==void 0&&typeof e.chunkSeparator!="string"&&A(r,"chunkSeparator must be a string"),e.chunkSize!==void 0&&e.chunkSize>0&&e.chunkSeparator===""&&A(r,"chunkSeparator must not be empty when chunkSize is enabled"),V(e.maxDecodedBytes,"maxDecodedBytes",r),V(e.maxEncodedChars,"maxEncodedChars",r),V(e.maxDecompressedBytes,"maxDecompressedBytes",r),"maxBufferedBytes"in e&&V(e.maxBufferedBytes,"maxBufferedBytes",r),"maxBufferedChars"in e&&V(e.maxBufferedChars,"maxBufferedChars",r);let n=e;E(n.throwOnError,"throwOnError",r),E(n.urlSafe,"urlSafe",r),E(n.useRepeatPadding,"useRepeatPadding",r),E(n.usePowerOfTwo,"usePowerOfTwo",r),n.encryptionKey!==void 0&&(typeof n.encryptionKey!="string"||n.encryptionKey.length===0)&&A(r,"encryptionKey must be a non-empty string"),n.dduChar!==void 0&&typeof n.dduChar!="string"&&!(Array.isArray(n.dduChar)&&n.dduChar.every(a=>typeof a=="string"))&&A(r,"dduChar must be a string or string array"),n.paddingChar!==void 0&&typeof n.paddingChar!="string"&&A(r,"paddingChar must be a string"),n.codaChar!==void 0&&!(Array.isArray(n.codaChar)&&n.codaChar.every(a=>typeof a=="string"))&&A(r,"codaChar must be a string array"),n.requiredLength!==void 0&&(!Number.isSafeInteger(n.requiredLength)||n.requiredLength<=0)&&A(r,"requiredLength must be a positive safe integer"),n.adapter!==void 0&&(typeof n.adapter!="object"||n.adapter===null)&&A(r,"adapter must be an object");let o="keyDerivation"in e?e.keyDerivation:void 0;o!==void 0&&((typeof o!="object"||o===null)&&A(r,"keyDerivation must be an object"),o.algorithm!==void 0&&o.algorithm!=="sha256"&&o.algorithm!=="pbkdf2"&&A(r,`keyDerivation.algorithm must be "sha256" or "pbkdf2", got ${String(o.algorithm)}`),o.hash!==void 0&&o.hash!=="SHA-256"&&o.hash!=="SHA-384"&&o.hash!=="SHA-512"&&A(r,`Unsupported PBKDF2 hash: ${String(o.hash)}`),o.iterations!==void 0&&(!Number.isFinite(o.iterations)||o.iterations<=0)&&A(r,"keyDerivation.iterations must be a positive finite number"),o.salt!==void 0&&typeof o.salt!="string"&&!Cr(o.salt)&&A(r,"keyDerivation.salt must be a string or Uint8Array"));}chunkBCUBYE76_cjs.a(k,"validateRuntimeOptions");function H(e,r="encode"){if(typeof e!="string"&&!Cr(e))throw new chunkZTGECGM2_cjs.k("[Ddu64 input] Encode input must be a string or Uint8Array.",r)}chunkBCUBYE76_cjs.a(H,"validateEncodeInput");function q(e,r="decode"){if(typeof e!="string")throw new chunkZTGECGM2_cjs.k("[Ddu64 input] Decode input must be a string.",r)}chunkBCUBYE76_cjs.a(q,"validateDecodeInput");function Cr(e){return ArrayBuffer.isView(e)&&Object.prototype.toString.call(e)==="[object Uint8Array]"}chunkBCUBYE76_cjs.a(Cr,"isUint8Array");function E(e,r,t){e!==void 0&&typeof e!="boolean"&&A(t,`${r} must be a boolean`);}chunkBCUBYE76_cjs.a(E,"validateBoolean");function V(e,r,t){e!==void 0&&e!==Number.POSITIVE_INFINITY&&(!Number.isSafeInteger(e)||e<=0)&&A(t,`${r} must be a positive safe integer or Infinity`);}chunkBCUBYE76_cjs.a(V,"validatePositiveLimit");function A(e,r){throw new chunkZTGECGM2_cjs.k(`[Ddu64 options] Invalid ${r}.`,e)}chunkBCUBYE76_cjs.a(A,"invalid");function br(e,r,t){let n=e.decoded,o=e.extractedChecksumScope??r?.checksumScope??"plaintext";return o==="output"&&Dr(e,t),n=tt(e,t,n),n=nt(e,r,t,n),o==="plaintext"&&Er(e,t,n),n=ot(e,t,n),xr(t,n),n}chunkBCUBYE76_cjs.a(br,"runSyncDecodePipeline");async function Ar(e,r,t){let n=e.decoded,o=e.extractedChecksumScope??r?.checksumScope??"plaintext";if(o==="output"&&Dr(e,t),Sr(e,t)&&(v(t,n.length,55,"decrypt"),n=await t.decrypt(n,e.encryptionAAD)),wr(e)){let a=kr(r,t);v(t,n.length,70,"decompress"),n=await t.decompress(n,e.compressionAlgorithm,a);}return o==="plaintext"&&Er(e,t,n),Pr(e,t)&&(v(t,n.length,90,"decrypt"),n=await t.decrypt(n,e.encryptionAAD)),xr(t,n),n}chunkBCUBYE76_cjs.a(Ar,"runAsyncDecodePipeline");function tt(e,r,t){return Sr(e,r)?(v(r,t.length,55,"decrypt"),r.decrypt(t,e.encryptionAAD)):t}chunkBCUBYE76_cjs.a(tt,"runPreDecompressDecrypt");function nt(e,r,t,n){if(!wr(e))return n;let o=kr(r,t);return v(t,n.length,70,"decompress"),t.decompress(n,e.compressionAlgorithm,o)}chunkBCUBYE76_cjs.a(nt,"runDecompress");function ot(e,r,t){return Pr(e,r)?(v(r,t.length,90,"decrypt"),r.decrypt(t,e.encryptionAAD)):t}chunkBCUBYE76_cjs.a(ot,"runPostChecksumDecrypt");function Sr(e,r){return (e.pipelineVersion===3||e.pipelineVersion===4)&&e.isEncrypted&&!!r.encryptionKey&&e.allowInternalDecrypt}chunkBCUBYE76_cjs.a(Sr,"shouldRunPreDecompressDecrypt");function Pr(e,r){return e.pipelineVersion===2&&e.isEncrypted&&!!r.encryptionKey&&e.allowInternalDecrypt}chunkBCUBYE76_cjs.a(Pr,"shouldRunPostChecksumDecrypt");function wr(e){return !!e.compressionAlgorithm&&e.allowInternalDecompress&&(e.pipelineVersion===2||!e.isEncrypted||e.allowInternalDecrypt)}chunkBCUBYE76_cjs.a(wr,"shouldDecompress");function Dr(e,r){if(!e.extractedChecksum)return;v(r,e.decoded.length,85,"checksum");let t=U(e.decoded);if(!ce(t,e.extractedChecksum))throw new chunkZTGECGM2_cjs.i(`[Ddu64 decode] Checksum mismatch. Expected: ${e.extractedChecksum}, Got: ${t}`)}chunkBCUBYE76_cjs.a(Dr,"verifyWireChecksum");function Er(e,r,t){if(!e.extractedChecksum||!(e.pipelineVersion===2||!e.isEncrypted||e.allowInternalDecrypt))return;v(r,t.length,85,"checksum");let n=U(t);if(!ce(n,e.extractedChecksum))throw new chunkZTGECGM2_cjs.i(`[Ddu64 decode] Checksum mismatch. Expected: ${e.extractedChecksum}, Got: ${n}`)}chunkBCUBYE76_cjs.a(Er,"verifyDecodedChecksum");function kr(e,r){return x(e?.maxDecompressedBytes,r.defaultMaxDecompressedBytes,true,"maxDecompressedBytes")}chunkBCUBYE76_cjs.a(kr,"getMaxDecompressedBytes");function v(e,r,t,n){e.reportProgress({processedBytes:r,totalBytes:r,percent:t,stage:n});}chunkBCUBYE76_cjs.a(v,"reportStage");function xr(e,r){v(e,r.length,100,"done");}chunkBCUBYE76_cjs.a(xr,"reportDone");function me(e,r,t){let n=Ur(r,t),o=typeof e=="string"?K(e):e;Or(t,o.length);let a="";n.shouldChecksum&&n.checksumScope==="plaintext"&&(a=U(o));let s,c;if(n.shouldCompress){let{algo:u,level:l}=vr(r,t);Br(t,o.length);let p=t.compress(o,u,l);p.length<o.length&&(c=p.length,o=p,s=u);}let d=false;return n.shouldEncrypt&&(Ir(t,o.length),o=t.encrypt(o,t.getEncryptionAAD(s)),d=true),n.shouldChecksum&&n.checksumScope==="output"&&(a=U(o)),{encoded:t.finalize(o,s,d,a,n.shouldChecksum,n.checksumScope,n.chunkSize,n.chunkSeparator),compressedSize:c}}chunkBCUBYE76_cjs.a(me,"runSyncEncodePipeline");async function ye(e,r,t){let n=Ur(r,t),o=typeof e=="string"?K(e):e;Or(t,o.length);let a="";n.shouldChecksum&&n.checksumScope==="plaintext"&&(a=U(o));let s,c;if(n.shouldCompress){let{algo:u,level:l}=vr(r,t);Br(t,o.length);let p=await t.compress(o,u,l);p.length<o.length&&(c=p.length,o=p,s=u);}let d=false;return n.shouldEncrypt&&(Ir(t,o.length),o=await t.encrypt(o,t.getEncryptionAAD(s)),d=true),n.shouldChecksum&&n.checksumScope==="output"&&(a=U(o)),{encoded:t.finalize(o,s,d,a,n.shouldChecksum,n.checksumScope,n.chunkSize,n.chunkSeparator),compressedSize:c}}chunkBCUBYE76_cjs.a(ye,"runAsyncEncodePipeline");function vr(e,r){let t=e?.compressionAlgorithm??r.defaultCompressionAlgorithm,n=X(e?.compressionLevel??r.defaultCompressionLevel,t);return {algo:t,level:n}}chunkBCUBYE76_cjs.a(vr,"resolveCompressionParams");function Ur(e,r){return {shouldCompress:e?.compress??r.defaultCompress,shouldChecksum:e?.checksum??r.defaultChecksum,checksumScope:e?.checksumScope??r.defaultChecksumScope,shouldEncrypt:(e?.encrypt??true)&&r.hasEncryptionKey,chunkSize:e?.chunkSize??r.defaultChunkSize,chunkSeparator:e?.chunkSeparator??r.defaultChunkSeparator}}chunkBCUBYE76_cjs.a(Ur,"resolveEncodeSettings");function Or(e,r){e.reportProgress({processedBytes:0,totalBytes:r,percent:0,stage:"start"});}chunkBCUBYE76_cjs.a(Or,"reportStart");function Br(e,r){e.reportProgress({processedBytes:r,totalBytes:r,percent:20,stage:"compress"});}chunkBCUBYE76_cjs.a(Br,"reportCompress");function Ir(e,r){e.reportProgress({processedBytes:r,totalBytes:r,percent:45,stage:"encrypt"});}chunkBCUBYE76_cjs.a(Ir,"reportEncrypt");var it=64*1024*1024,at=64*1024*1024,st=256*1024*1024,Lr=28,Rr=class{static{chunkBCUBYE76_cjs.a(this,"Ddu64Core");}dduChar;dduCharCodes;paddingChar;bitLength;usePowerOfTwo;dduCharCodeLookup;dduCharCodeLookupOffset;defaultCompress;defaultMaxDecodedBytes;defaultMaxEncodedChars;defaultMaxDecompressedBytes;urlSafe;encryptionKey;keyDerivation;encryptionKeyHash;syncGatewayContext;defaultChecksum;defaultChecksumScope;defaultChunkSize;defaultChunkSeparator;defaultCompressionLevel;defaultCompressionAlgorithm;useRepeatPadding;bitsPerPadChar;bitPackConfig;canUseNativeBase64;payloadCodecContext;adapter;adapterFactory;obfuscationLayerFactory;defaultObfuscate;defaultOnProgress;defaultRequireEncryption;obfuscationLayer;constructor(r,t,n){let o=Se(r,t,n);r=o.dduChar,t=o.paddingChar,n=o.dduOptions,k(n);let a=n?.throwOnError??true;this.adapter=n?.adapter,this.adapterFactory=n?.adapterFactory,this.obfuscationLayerFactory=n?.obfuscationLayerFactory;let s,c;try{s=Le(r,t,n,a),c=Re(s,a,n);}catch(y){throw chunkZTGECGM2_cjs.p(y)?y:new chunkZTGECGM2_cjs.j(chunkZTGECGM2_cjs.q(y),y)}this.dduChar=c.charSet,this.paddingChar=c.padding;let d=c.isPredefined;this.defaultCompress=n?.compress??false,this.defaultMaxDecodedBytes=x(n?.maxDecodedBytes,it,a,"maxDecodedBytes"),this.defaultMaxDecompressedBytes=x(n?.maxDecompressedBytes,at,a,"maxDecompressedBytes"),this.defaultMaxEncodedChars=x(n?.maxEncodedChars,this.defaultMaxDecodedBytes===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(st,this.defaultMaxDecodedBytes*4),a,"maxEncodedChars");let u=this.dduChar.length,l=we(u),p=n?.usePowerOfTwo,h=s.encodingProfile;this.usePowerOfTwo=h?.usePowerOfTwo??s.usePowerOfTwo??(p!==void 0?p&&l:l);let f=h?.bitLength??(s.isPredefined&&s.usePowerOfTwo!==void 0?s.bitLength:void 0);this.bitLength=f??Pe(u,this.usePowerOfTwo);let m=Je(this.dduChar,d);this.dduCharCodeLookup=m.charCodeLookup,this.dduCharCodeLookupOffset=m.lookupOffset,this.dduCharCodes=m.charCodes,this.urlSafe=dt(this.dduChar,this.paddingChar,n?.urlSafe??false,a),this.encryptionKey=n?.encryptionKey,this.keyDerivation=n?.keyDerivation,this.defaultChecksum=n?.checksum??false,this.defaultChecksumScope=n?.checksumScope??"output",this.defaultChunkSize=n?.chunkSize,this.defaultChunkSeparator=n?.chunkSeparator??`
`,this.defaultCompressionAlgorithm=n?.compressionAlgorithm??"deflate",this.defaultCompressionLevel=X(n?.compressionLevel,this.defaultCompressionAlgorithm),this.useRepeatPadding=n?.useRepeatPadding??s.useRepeatPadding??false,this.bitsPerPadChar=h?.bitsPerPadChar??s.bitsPerPadChar??2,this.defaultObfuscate=n?.obfuscate??false,this.defaultOnProgress=n?.onProgress,this.defaultRequireEncryption=n?.requireEncryption??this.encryptionKey!==void 0,this.bitPackConfig={bitLength:this.bitLength,usePowerOfTwo:this.usePowerOfTwo,charsetSize:u},this.canUseNativeBase64=Me(this.dduChar,this.paddingChar,this.usePowerOfTwo,this.bitLength),this.payloadCodecContext={bitPackConfig:this.bitPackConfig,canUseNativeBase64:this.canUseNativeBase64,dduCharCodes:this.dduCharCodes,dduCharCodeLookup:this.dduCharCodeLookup,dduCharCodeLookupOffset:this.dduCharCodeLookupOffset,paddingChar:this.paddingChar,useRepeatPadding:this.useRepeatPadding,bitsPerPadChar:this.bitsPerPadChar,encryptedPipelineVersion:4};}encode(r,t){try{return k(t,"encode"),H(r),this.encodeInternal(r,t).encoded}catch(n){throw chunkZTGECGM2_cjs.r(n,"encode")}}decode(r,t){try{k(t,"decode"),q(r);let n=this.decodeToUint8Array(r,t);return ue(n)}catch(n){throw chunkZTGECGM2_cjs.r(n,"decode")}}decodeToUint8Array(r,t){try{return k(t,"decode"),q(r),this.decodeToUint8ArrayInternal(r,t)}catch(n){throw chunkZTGECGM2_cjs.r(n,"decode")}}decodeToUint8ArrayInternal(r,t){let n=this.decodePrelude(r,t);return br(n,t,{...this.buildDecodeBaseContext(t),decrypt:chunkBCUBYE76_cjs.a((o,a)=>qe(this.getSyncGatewayContext(),o,a),"decrypt"),decompress:chunkBCUBYE76_cjs.a((o,a,s)=>Ge(this.getAdapter(),o,a,s),"decompress")})}async encodeAsync(r,t){try{return k(t,"encode"),H(r),await this.encodeAsyncInternal(r,t)}catch(n){throw chunkZTGECGM2_cjs.r(n,"encode")}}async encodeAsyncInternal(r,t){return (await ye(r,t,{...this.buildEncodeBaseContext(t),compress:chunkBCUBYE76_cjs.a((o,a,s)=>he(this.getAdapter(),o,a,s),"compress"),encrypt:chunkBCUBYE76_cjs.a((o,a)=>je(this.getSyncGatewayContext(),o,a),"encrypt")})).encoded}async decodeAsync(r,t){try{k(t,"decode"),q(r);let n=await this.decodeToUint8ArrayAsync(r,t);return ue(n)}catch(n){throw chunkZTGECGM2_cjs.r(n,"decode")}}async decodeToUint8ArrayAsync(r,t){try{return k(t,"decode"),q(r),await this.decodeToUint8ArrayAsyncInternal(r,t)}catch(n){throw chunkZTGECGM2_cjs.r(n,"decode")}}async decodeToUint8ArrayAsyncInternal(r,t){let n=this.decodePrelude(r,t);return Ar(n,t,{...this.buildDecodeBaseContext(t),decrypt:chunkBCUBYE76_cjs.a((o,a)=>We(this.getSyncGatewayContext(),o,a),"decrypt"),decompress:chunkBCUBYE76_cjs.a((o,a,s)=>Ye(this.getAdapter(),o,a,s),"decompress")})}buildDecodeBaseContext(r){return {encryptionKey:this.encryptionKey,defaultMaxDecompressedBytes:this.defaultMaxDecompressedBytes,reportProgress:chunkBCUBYE76_cjs.a(t=>this.reportProgress(r,t),"reportProgress")}}getCharSetInfo(){return {charSet:[...this.dduChar],paddingChar:this.paddingChar,bitLength:this.bitLength,usePowerOfTwo:this.usePowerOfTwo,encoding:"utf-8",defaultCompress:this.defaultCompress,defaultMaxDecodedBytes:this.defaultMaxDecodedBytes,defaultMaxDecompressedBytes:this.defaultMaxDecompressedBytes,urlSafe:this.urlSafe,hasEncryptionKey:!!this.encryptionKey,defaultChecksum:this.defaultChecksum,defaultChecksumScope:this.defaultChecksumScope,defaultObfuscate:this.defaultObfuscate,defaultRequireEncryption:this.defaultRequireEncryption,defaultChunkSize:this.defaultChunkSize,defaultChunkSeparator:this.defaultChunkSeparator,defaultCompressionLevel:this.defaultCompressionLevel,defaultCompressionAlgorithm:this.defaultCompressionAlgorithm}}getStats(r,t){k(t,"encode"),H(r);let n=typeof r=="string"?K(r):r,{encoded:o,compressedSize:a}=this.encodeStatsInternal(n,t);return this.buildEncodeStats(n.length,o.length,a,t)}async getStatsAsync(r,t){k(t,"encode"),H(r);let n=typeof r=="string"?K(r):r,{encoded:o,compressedSize:a}=await this.encodeStatsAsyncInternal(n,t);return this.buildEncodeStats(n.length,o.length,a,t)}buildEncodeStats(r,t,n,o){let a=r>0?t/r:0,c=(o?.compress??this.defaultCompress)&&n!==void 0&&r>0?n/r:void 0;return {originalSize:r,encodedSize:t,compressedSize:n,compressionRatio:c,expansionRatio:a,charsetSize:this.dduChar.length,bitLength:this.bitLength}}encodeInternal(r,t){return me(r,t,{...this.buildEncodeBaseContext(t),compress:chunkBCUBYE76_cjs.a((n,o,a)=>fe(this.getAdapter(),n,o,a),"compress"),encrypt:chunkBCUBYE76_cjs.a((n,o)=>He(this.getSyncGatewayContext(),n,o),"encrypt")})}encodeStatsInternal(r,t){return me(r,t,{...this.buildEncodeBaseContext(t),compress:chunkBCUBYE76_cjs.a((n,o,a)=>fe(this.getAdapter(),n,o,a),"compress"),encrypt:chunkBCUBYE76_cjs.a(n=>new Uint8Array(n.length+Lr),"encrypt")})}async encodeStatsAsyncInternal(r,t){return ye(r,t,{...this.buildEncodeBaseContext(t),compress:chunkBCUBYE76_cjs.a((n,o,a)=>he(this.getAdapter(),n,o,a),"compress"),encrypt:chunkBCUBYE76_cjs.a(async n=>new Uint8Array(n.length+Lr),"encrypt")})}buildEncodeBaseContext(r){return {defaultCompress:this.defaultCompress,defaultChecksum:this.defaultChecksum,defaultChecksumScope:this.defaultChecksumScope,defaultChunkSize:this.defaultChunkSize,defaultChunkSeparator:this.defaultChunkSeparator,defaultCompressionLevel:this.defaultCompressionLevel,defaultCompressionAlgorithm:this.defaultCompressionAlgorithm,hasEncryptionKey:!!this.encryptionKey,reportProgress:chunkBCUBYE76_cjs.a(t=>this.reportProgress(r,t),"reportProgress"),getEncryptionAAD:chunkBCUBYE76_cjs.a(t=>te({compressionAlgorithm:t}),"getEncryptionAAD"),finalize:chunkBCUBYE76_cjs.a((t,n,o,a,s,c,d,u)=>this.finalizeEncode(t,n,o,a,s,c,d,u,r),"finalize")}}finalizeEncode(r,t,n,o,a,s,c,d,u){this.reportProgress(u,{processedBytes:r.length,totalBytes:r.length,percent:70,stage:"encode"});let l=mr(r,t,n,u,this.getPayloadCodecContext());return l=this.applyPostEncoding(l,u,o,a,s,c,d),this.reportProgress(u,{processedBytes:r.length,totalBytes:r.length,percent:100,stage:"done"}),l}applyPostEncoding(r,t,n,o,a,s,c){return ur({encoded:r,options:t,checksum:n,shouldChecksum:o,checksumScope:a,chunkSize:s,chunkSeparator:c,urlSafe:this.urlSafe,shouldObfuscate:chunkBCUBYE76_cjs.a(d=>this.shouldObfuscate(d),"shouldObfuscate"),getObfuscationLayer:chunkBCUBYE76_cjs.a(()=>this.getObfuscationLayer(),"getObfuscationLayer"),assertSafeChunkSeparator:chunkBCUBYE76_cjs.a((d,u)=>this.assertSafeChunkSeparator(d,u),"assertSafeChunkSeparator")})}decodePrelude(r,t){return dr(r,t,{defaultChecksum:this.defaultChecksum,defaultChunkSeparator:this.defaultChunkSeparator,defaultMaxDecodedBytes:this.defaultMaxDecodedBytes,defaultMaxEncodedChars:this.defaultMaxEncodedChars,urlSafe:this.urlSafe,paddingChar:this.paddingChar,bitLength:this.bitLength,bitsPerPadChar:this.bitsPerPadChar,usePowerOfTwo:this.usePowerOfTwo,dduCharCodeLookup:this.dduCharCodeLookup,dduCharCodeLookupOffset:this.dduCharCodeLookupOffset,charSetSize:this.dduChar.length,encryptionKey:this.encryptionKey,defaultRequireEncryption:this.defaultRequireEncryption,shouldObfuscate:chunkBCUBYE76_cjs.a(n=>this.shouldObfuscate(n),"shouldObfuscate"),deobfuscate:chunkBCUBYE76_cjs.a(n=>this.getObfuscationLayer().deobfuscate(n),"deobfuscate"),decodeChars:chunkBCUBYE76_cjs.a((n,o)=>yr(n,o,this.getPayloadCodecContext()),"decodeChars"),reportDecodeStart:chunkBCUBYE76_cjs.a(n=>{this.reportProgress(t,{processedBytes:0,totalBytes:n,percent:0,stage:"start"});},"reportDecodeStart"),reportBitpackDecode:chunkBCUBYE76_cjs.a((n,o)=>{this.reportProgress(t,{processedBytes:n,totalBytes:o,percent:30,stage:"decode"});},"reportBitpackDecode")})}getPayloadCodecContext(){return this.payloadCodecContext}reportProgress(r,t){(r?.onProgress??this.defaultOnProgress)?.(t);}getAdapter(){return this.adapter===void 0&&this.adapterFactory!==void 0&&(this.adapter=this.adapterFactory()),this.adapter}getSyncGatewayContext(){if(!this.syncGatewayContext){let r={adapter:this.getAdapter(),encryptionKey:this.encryptionKey,keyDerivation:this.keyDerivation,encryptionKeyHash:this.encryptionKeyHash,setEncryptionKeyHash:chunkBCUBYE76_cjs.a(t=>{this.encryptionKeyHash=t,r.encryptionKeyHash=t;},"setEncryptionKeyHash")};this.syncGatewayContext=r;}return this.syncGatewayContext}getObfuscationLayer(){if(!this.obfuscationLayer){if(!this.obfuscationLayerFactory)throw new chunkZTGECGM2_cjs.n("[Ddu64 obfuscation] No obfuscation layer is wired. Use Ddu64Node/Ddu64Browser (batteries-included), or inject `obfuscationLayerFactory` when constructing Ddu64Core directly.");this.obfuscationLayer=this.obfuscationLayerFactory(gr(this.dduChar,this.paddingChar));}return this.obfuscationLayer}shouldObfuscate(r){return r?.obfuscate??this.defaultObfuscate}assertSafeChunkSeparator(r,t){if(!(t.length===0||this.isLineBreakSeparator(t))&&r.includes(t))throw new chunkZTGECGM2_cjs.c(`[Ddu64 chunking] Unsafe chunkSeparator "${t}" appears in encoded output. Use a separator that cannot be produced by the charset, footer, checksum, or URL-safe output.`)}isLineBreakSeparator(r){return r===`
`||r===`\r
`||r==="\r"}};function dt(e,r,t,n){try{return t?Te(e,r,n):!1}catch(o){throw chunkZTGECGM2_cjs.p(o)?o:new chunkZTGECGM2_cjs.j(chunkZTGECGM2_cjs.q(o),o)}}chunkBCUBYE76_cjs.a(dt,"validateFinal