@ddunigma/node 3.0.2 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -1,7 +1,7 @@
1
- import {pbkdf2,pbkdf2Sync,createHash,randomBytes,createCipheriv,createDecipheriv}from'crypto';import {deflateRaw,inflateRaw,brotliCompress,brotliDecompress,deflateRawSync,inflateRawSync,constants,brotliCompressSync,brotliDecompressSync}from'zlib';import {promisify}from'util';var Te=Object.defineProperty;var _e=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var _=(n,e)=>()=>(n&&(e=n(n=0)),e);var R=(n,e)=>{for(var t in e)Te(n,t,{get:e[t],enumerable:true});};var Be={};R(Be,{NodeAdapter:()=>V});function Se(n){return (n??"SHA-256").toLowerCase().replace("-","")}function Ce(n){return n===void 0||!Number.isFinite(n)||n<=0?Ae:Math.max(gt,Math.floor(n))}function Ee(n){return n===void 0?Buffer.from(bt,"utf-8"):typeof n=="string"?Buffer.from(n,"utf-8"):Buffer.from(n.buffer,n.byteOffset,n.byteLength)}var mt,be,pt,we,yt,Ae,gt,bt,V,Pe=_(()=>{mt=promisify(deflateRaw),be=promisify(inflateRaw),pt=promisify(brotliCompress),we=promisify(brotliDecompress),yt=promisify(pbkdf2),Ae=21e4,gt=1e4,bt="ddunigma:pbkdf2:v1";V=class{supportsSyncCrypto=true;supportsSyncCompression=true;supportsBrotli=true;runtime="node";async deriveKey(e,t){if(t?.algorithm==="pbkdf2"){let r=await yt(e,Ee(t.salt),Ce(t.iterations),32,Se(t.hash));return new Uint8Array(r)}return this.deriveKeySync(e,t)}deriveKeySync(e,t){return t?.algorithm==="pbkdf2"?new Uint8Array(pbkdf2Sync(e,Ee(t.salt),Ce(t.iterations),32,Se(t.hash))):new Uint8Array(createHash("sha256").update(e).digest())}async encrypt(e,t){return this.encryptSync(e,t)}encryptSync(e,t){let r=randomBytes(12),o=createCipheriv("aes-256-gcm",t,r),s=Buffer.concat([o.update(e),o.final()]),i=o.getAuthTag(),a=new Uint8Array(28+s.length);return a.set(r,0),a.set(i,12),a.set(s,28),a}async decrypt(e,t){return this.decryptSync(e,t)}decryptSync(e,t){if(e.length<28)throw new Error("[Ddu64 decrypt] Invalid encrypted data: too short");let r=e.subarray(0,12),o=e.subarray(12,28),s=e.subarray(28),i=createDecipheriv("aes-256-gcm",t,r);i.setAuthTag(o);let a=Buffer.concat([i.update(s),i.final()]);return new Uint8Array(a)}randomBytes(e){return new Uint8Array(randomBytes(e))}async deflate(e,t){let r={};t!==void 0&&(r.level=t);let o=await mt(Buffer.from(e),r);return new Uint8Array(o)}deflateSync(e,t){let r={};return t!==void 0&&(r.level=t),new Uint8Array(deflateRawSync(Buffer.from(e),r))}async inflate(e,t){if(t===void 0||t===Number.POSITIVE_INFINITY){let o=await be(Buffer.from(e));return new Uint8Array(o)}let r={maxOutputLength:t};try{let o=await be(Buffer.from(e),r);return new Uint8Array(o)}catch(o){let s=o,i=String(s?.message??"").toLowerCase();throw String(s?.code??"")==="ERR_BUFFER_TOO_LARGE"||i.includes("output length")||i.includes("buffer too large")?new Error(`[Ddu64 inflate] Decompressed data exceeds limit. Limit: ${t} bytes`,{cause:o}):o}}inflateSync(e,t){if(t===void 0||t===Number.POSITIVE_INFINITY)return new Uint8Array(inflateRawSync(Buffer.from(e)));try{return new Uint8Array(inflateRawSync(Buffer.from(e),{maxOutputLength:t}))}catch(r){let o=r,s=String(o?.message??"").toLowerCase();throw String(o?.code??"")==="ERR_BUFFER_TOO_LARGE"||s.includes("output length")||s.includes("buffer too large")?new Error(`[Ddu64 inflate] Decompressed data exceeds limit. Limit: ${t} bytes`,{cause:r}):r}}async brotliCompress(e,t){let r={};t!==void 0&&(r.params={[constants.BROTLI_PARAM_QUALITY]:Math.max(0,Math.min(11,t))});let o=await pt(Buffer.from(e),r);return new Uint8Array(o)}brotliCompressSync(e,t){let r={};return t!==void 0&&(r.params={[constants.BROTLI_PARAM_QUALITY]:Math.max(0,Math.min(11,t))}),new Uint8Array(brotliCompressSync(Buffer.from(e),r))}async brotliDecompress(e,t){if(t===void 0||t===Number.POSITIVE_INFINITY){let r=await we(Buffer.from(e));return new Uint8Array(r)}try{let r=await we(Buffer.from(e),{maxOutputLength:t});return new Uint8Array(r)}catch(r){let o=r,s=String(o?.message??"").toLowerCase();throw String(o?.code??"")==="ERR_BUFFER_TOO_LARGE"||s.includes("output length")||s.includes("buffer too large")||s.includes("cannot create a buffer larger")?new Error(`[Ddu64 brotli] Decompressed data exceeds limit. Limit: ${t} bytes`,{cause:r}):r}}brotliDecompressSync(e,t){if(t===void 0||t===Number.POSITIVE_INFINITY)return new Uint8Array(brotliDecompressSync(Buffer.from(e)));try{return new Uint8Array(brotliDecompressSync(Buffer.from(e),{maxOutputLength:t}))}catch(r){let o=r,s=String(o?.message??"").toLowerCase();throw String(o?.code??"")==="ERR_BUFFER_TOO_LARGE"||s.includes("output length")||s.includes("buffer too large")||s.includes("cannot create a buffer larger")?new Error(`[Ddu64 brotli] Decompressed data exceeds limit. Limit: ${t} bytes`,{cause:r}):r}}};});var De={};R(De,{BrowserAdapter:()=>G});function At(n){return n===void 0||!Number.isFinite(n)||n<=0?21e4:Math.max(1e4,Math.floor(n))}function St(n){return n===void 0?new TextEncoder().encode(wt):typeof n=="string"?new TextEncoder().encode(n):n}var wt,G,Ue=_(()=>{wt="ddunigma:pbkdf2:v1";G=class{supportsSyncCrypto=false;supportsSyncCompression=false;supportsBrotli=false;runtime="browser";async deriveKey(e,t){let o=new TextEncoder().encode(e);if(t?.algorithm==="pbkdf2"){let i=await crypto.subtle.importKey("raw",o,"PBKDF2",false,["deriveBits"]),a=await crypto.subtle.deriveBits({name:"PBKDF2",salt:St(t.salt),iterations:At(t.iterations),hash:t.hash??"SHA-256"},i,256);return new Uint8Array(a)}let s=await crypto.subtle.digest("SHA-256",o);return new Uint8Array(s)}async encrypt(e,t){let r=crypto.getRandomValues(new Uint8Array(12)),o=await crypto.subtle.importKey("raw",t,{name:"AES-GCM"},false,["encrypt"]),s=await crypto.subtle.encrypt({name:"AES-GCM",iv:r,tagLength:128},o,e),i=new Uint8Array(s),a=i.slice(0,i.length-16),c=i.slice(i.length-16),l=new Uint8Array(28+a.length);return l.set(r,0),l.set(c,12),l.set(a,28),l}async decrypt(e,t){if(e.length<28)throw new Error("[Ddu64 decrypt] Encrypted data is invalid. Payload must be at least 28 bytes (12 IV + 16 authTag + ciphertext).");let r=e.slice(0,12),o=e.slice(12,28),s=e.slice(28),i=new Uint8Array(s.length+16);i.set(s,0),i.set(o,s.length);let a=await crypto.subtle.importKey("raw",t,{name:"AES-GCM"},false,["decrypt"]);try{let c=await crypto.subtle.decrypt({name:"AES-GCM",iv:r,tagLength:128},a,i);return new Uint8Array(c)}catch{throw new Error("[Ddu64 decrypt] Decryption failed: data tampering or incorrect key.")}}randomBytes(e){return crypto.getRandomValues(new Uint8Array(e))}async deflate(e,t){if(typeof CompressionStream>"u")throw new Error("[Ddu64 compress] Deflate compression is unsupported in the current runtime. CompressionStream API is not available.");let r=this.getDeflateFormat(),o=new CompressionStream(r),s=o.writable.getWriter(),i=o.readable.getReader();s.write(e),s.close();let a=[],c=0;for(;;){let{done:h,value:f}=await i.read();if(h)break;a.push(f),c+=f.length;}let l=new Uint8Array(c),d=0;for(let h of a)l.set(h,d),d+=h.length;return l}async inflate(e,t){if(typeof DecompressionStream>"u")throw new Error("[Ddu64 decompress] Deflate decompression is unsupported in the current runtime. DecompressionStream API is not available.");let r=this.getDeflateFormat(),o=new DecompressionStream(r),s=o.writable.getWriter(),i=o.readable.getReader();s.write(e),s.close();let a=[],c=0;for(;;){let{done:h,value:f}=await i.read();if(h)break;if(c+=f.length,t!==void 0&&c>t)throw new Error(`[Ddu64 decompress] Decompressed size exceeds limit. Estimated ${c}+ bytes exceeds maximum of ${t} bytes.`);a.push(f);}let l=new Uint8Array(c),d=0;for(let h of a)l.set(h,d),d+=h.length;return l}getDeflateFormat(){return "deflate-raw"}};});var ke={};R(ke,{detectRuntime:()=>ve,getAdapter:()=>Ct});function ve(){if(typeof globalThis.process<"u"&&globalThis.process?.versions?.node)return "node";if(globalThis.Deno?.version?.deno)return "deno";if(globalThis.Bun?.version)return "bun";if(typeof globalThis.crypto<"u"&&globalThis.crypto?.subtle)return "browser";throw new Error("[ddunigma] No suitable crypto provider found. Detected runtime lacks both Node.js crypto module and Web Crypto API (SubtleCrypto).")}async function Ct(){switch(ve()){case "node":{let{NodeAdapter:e}=await Promise.resolve().then(()=>(Pe(),Be));return new e}case "deno":case "bun":case "browser":case "edge":{let{BrowserAdapter:e}=await Promise.resolve().then(()=>(Ue(),De));return new e}default:throw new Error("[ddunigma] No suitable crypto provider found. Detected runtime lacks both Node.js crypto module and Web Crypto API (SubtleCrypto).")}}var Le=_(()=>{});function Q(n,e){let{bitLength:t,usePowerOfTwo:r,charsetSize:o}=e,s=n.length;if(s===0)return {indices:[],paddingBits:0};let i=s*8,a=Math.ceil(i/t),c=r?a:a*2,l=new Array(c),d=0,h=0,f=0;if(r){let p=(1<<t)-1;for(let g=0;g<s;g++)for(h=h<<8|n[g],f+=8;f>=t;)f-=t,l[d++]=h>>f&p,h&=(1<<f)-1;}else for(let p=0;p<s;p++)for(h=h<<8|n[p],f+=8;f>=t;){f-=t;let g=h>>f,m=g/o|0;l[d++]=m,l[d++]=g-m*o,h&=(1<<f)-1;}let u=0;if(f>0){u=t-f;let p=h<<u;if(r)l[d++]=p;else {let g=p/o|0;l[d++]=g,l[d++]=p-g*o;}}return l.length=d,{indices:l,paddingBits:u}}function J(n,e,t){let{bitLength:r,usePowerOfTwo:o,charsetSize:s}=t,i=n.length;if(i===0)return new Uint8Array(0);let a=o?1:2,c=Math.ceil(i/a),l=r<31?1<<r:Math.pow(2,r),d=Math.ceil((c*r-e)/8),h=new Uint8Array(d+1),f=0,u=0,p=0;if(o)for(let g=0;g<i;g+=a){let m=n[g];if(m<0||m>=s)throw new Error(`[BitPack decode] Invalid index ${m} at position ${g}`);for(u=u<<r|m,p+=r,g+a>=i&&e>0&&(u>>=e,p-=e);p>=8;)p-=8,h[f++]=u>>p&255,u&=(1<<p)-1;}else for(let g=0;g<i;g+=a){let m=n[g],y=n[g+1];if(m<0||m>=s)throw new Error(`[BitPack decode] Invalid index ${m} at position ${g}`);if(y===void 0||y<0||y>=s)throw new Error(`[BitPack decode] Invalid index ${y} at position ${g+1}`);let b=m*s+y;if(b>=l)throw new Error(`[BitPack decode] Value ${b} exceeds range at position ${g}`);for(u=u<<r|b,p+=r,g+a>=i&&e>0&&(u>>=e,p-=e);p>=8;)p-=8,h[f++]=u>>p&255,u&=(1<<p)-1;}return h.subarray(0,f)}function Re(n,e){return n<=1?0:e?Math.floor(Math.log2(n)):Math.ceil(Math.log2(n))}function Ie(n){return n>0&&(n&n-1)===0}function ee(n){let e=Ie(n);return {bitLength:Re(n,e),usePowerOfTwo:e,charsetSize:n}}var C="ELYSIA",E="GRISEO";function I(n,e,t){let r=n.length,o=e.length,s={cleanedInput:n,paddingBits:0,isEncrypted:false,pipelineVersion:2};if(r<o)return s;let a=Math.max(0,t-1).toString().length;for(let c=Math.min(a,r);c>=1;c--){let l=r-c,d=true;for(let b=l;b<r;b++){let X=n.charCodeAt(b);if(X<48||X>57){d=false;break}}if(!d)continue;let h=n.substring(l),f=parseInt(h,10);if(Number.isNaN(f)||f<0||f>=t||h!==f.toString())continue;let u=l,p=false,g,m=2;u>=2&&n.substring(u-2,u)==="V3"&&(m=3,u-=2),u>=3&&n.substring(u-3,u)==="ENC"&&(p=true,u-=3),u>=C.length&&n.substring(u-C.length,u)===C?(g="deflate",u-=C.length):u>=E.length&&n.substring(u-E.length,u)===E&&(g="brotli",u-=E.length);let y=u-o;if(y>=0&&n.substring(y,u)===e)return {cleanedInput:n.substring(0,y),paddingBits:f,compressionAlgorithm:g,isEncrypted:p,pipelineVersion:m}}if(n.endsWith(e)){let c=0,l=r;for(;l>=o&&n.substring(l-o,l)===e;)c++,l-=o;if(c>0){let d=c*2;if(d<t)return {cleanedInput:n.substring(0,l),paddingBits:d,isEncrypted:false,pipelineVersion:2}}}return s}function M(n){let e=n.lastIndexOf("CHK");if(e===-1)return {data:n,checksum:null};let t=n.slice(e+3);return t.length!==8||!/^[0-9a-f]+$/i.test(t)?{data:n,checksum:null}:{data:n.slice(0,e),checksum:t.toLowerCase()}}function te(n){let{paddingBits:e,compressionAlgorithm:t,isEncrypted:r,paddingChar:o,useRepeatPadding:s,pipelineVersion:i=2}=n;if(e===0&&!t&&!r&&i===2)return "";if(s&&!t&&!r&&i===2&&e>0&&e%2===0){let c=e>>1;return o.repeat(c)}return o+(t==="deflate"?C:t==="brotli"?E:"")+(r?"ENC":"")+(i===3?"V3":"")+e.toString()}var Me=(()=>{let n=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let r=0;r<8;r++)t=t>>>1^(t&1?3988292384:0);n[e]=t;}return n})();function B(n){let e=4294967295;for(let t=0;t<n.length;t++)e=e>>>8^Me[(e^n[t])&255];return ((e^4294967295)>>>0).toString(16).padStart(8,"0")}function re(n){return n.length===0?n:n.replaceAll("+","-").replaceAll("/","_").replaceAll("=",".")}function O(n){return n.length===0?n:n.replaceAll("-","+").replaceAll("_","/").replaceAll(".","=")}function ne(n,e,t){if(e<=0||n.length<=e)return n;let r=Math.ceil(n.length/e),o=new Array(r*2-1),s=0;for(let i=0;i<n.length;i+=e)o[s++]=n.slice(i,i+e),i+e<n.length&&(o[s++]=t);return o.join("")}function N(n,e){if(n.length===0)return n;let t=n.replace(/[\r\n]/g,""),r=e&&e!==`
1
+ import {pbkdf2,pbkdf2Sync,createHash,randomBytes,createCipheriv,createDecipheriv}from'crypto';import {deflateRaw,inflateRaw,brotliCompress,brotliDecompress,deflateRawSync,inflateRawSync,constants,brotliCompressSync,brotliDecompressSync}from'zlib';import {promisify}from'util';var Te=Object.defineProperty;var _e=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var _=(n,e)=>()=>(n&&(e=n(n=0)),e);var R=(n,e)=>{for(var t in e)Te(n,t,{get:e[t],enumerable:true});};var Be={};R(Be,{NodeAdapter:()=>V});function Se(n){return (n??"SHA-256").toLowerCase().replace("-","")}function Ce(n){return n===void 0||!Number.isFinite(n)||n<=0?Ae:Math.max(gt,Math.floor(n))}function Ee(n){return n===void 0?Buffer.from(bt,"utf-8"):typeof n=="string"?Buffer.from(n,"utf-8"):Buffer.from(n.buffer,n.byteOffset,n.byteLength)}var mt,be,pt,we,yt,Ae,gt,bt,V,Pe=_(()=>{mt=promisify(deflateRaw),be=promisify(inflateRaw),pt=promisify(brotliCompress),we=promisify(brotliDecompress),yt=promisify(pbkdf2),Ae=21e4,gt=1e4,bt="ddunigma:pbkdf2:v1";V=class{supportsSyncCrypto=true;supportsSyncCompression=true;supportsBrotli=true;runtime="node";async deriveKey(e,t){if(t?.algorithm==="pbkdf2"){let r=await yt(e,Ee(t.salt),Ce(t.iterations),32,Se(t.hash));return new Uint8Array(r)}return this.deriveKeySync(e,t)}deriveKeySync(e,t){return t?.algorithm==="pbkdf2"?new Uint8Array(pbkdf2Sync(e,Ee(t.salt),Ce(t.iterations),32,Se(t.hash))):new Uint8Array(createHash("sha256").update(e).digest())}async encrypt(e,t){return this.encryptSync(e,t)}encryptSync(e,t){let r=randomBytes(12),o=createCipheriv("aes-256-gcm",t,r),s=Buffer.concat([o.update(e),o.final()]),i=o.getAuthTag(),a=new Uint8Array(28+s.length);return a.set(r,0),a.set(i,12),a.set(s,28),a}async decrypt(e,t){return this.decryptSync(e,t)}decryptSync(e,t){if(e.length<28)throw new Error("[Ddu64 decrypt] Invalid encrypted data: too short");let r=e.subarray(0,12),o=e.subarray(12,28),s=e.subarray(28),i=createDecipheriv("aes-256-gcm",t,r);i.setAuthTag(o);let a=Buffer.concat([i.update(s),i.final()]);return new Uint8Array(a)}randomBytes(e){return new Uint8Array(randomBytes(e))}async deflate(e,t){let r={};t!==void 0&&(r.level=t);let o=await mt(Buffer.from(e),r);return new Uint8Array(o)}deflateSync(e,t){let r={};return t!==void 0&&(r.level=t),new Uint8Array(deflateRawSync(Buffer.from(e),r))}async inflate(e,t){if(t===void 0||t===Number.POSITIVE_INFINITY){let o=await be(Buffer.from(e));return new Uint8Array(o)}let r={maxOutputLength:t};try{let o=await be(Buffer.from(e),r);return new Uint8Array(o)}catch(o){let s=o,i=String(s?.message??"").toLowerCase();throw String(s?.code??"")==="ERR_BUFFER_TOO_LARGE"||i.includes("output length")||i.includes("buffer too large")?new Error(`[Ddu64 inflate] Decompressed data exceeds limit. Limit: ${t} bytes`,{cause:o}):o}}inflateSync(e,t){if(t===void 0||t===Number.POSITIVE_INFINITY)return new Uint8Array(inflateRawSync(Buffer.from(e)));try{return new Uint8Array(inflateRawSync(Buffer.from(e),{maxOutputLength:t}))}catch(r){let o=r,s=String(o?.message??"").toLowerCase();throw String(o?.code??"")==="ERR_BUFFER_TOO_LARGE"||s.includes("output length")||s.includes("buffer too large")?new Error(`[Ddu64 inflate] Decompressed data exceeds limit. Limit: ${t} bytes`,{cause:r}):r}}async brotliCompress(e,t){let r={};t!==void 0&&(r.params={[constants.BROTLI_PARAM_QUALITY]:Math.max(0,Math.min(11,t))});let o=await pt(Buffer.from(e),r);return new Uint8Array(o)}brotliCompressSync(e,t){let r={};return t!==void 0&&(r.params={[constants.BROTLI_PARAM_QUALITY]:Math.max(0,Math.min(11,t))}),new Uint8Array(brotliCompressSync(Buffer.from(e),r))}async brotliDecompress(e,t){if(t===void 0||t===Number.POSITIVE_INFINITY){let r=await we(Buffer.from(e));return new Uint8Array(r)}try{let r=await we(Buffer.from(e),{maxOutputLength:t});return new Uint8Array(r)}catch(r){let o=r,s=String(o?.message??"").toLowerCase();throw String(o?.code??"")==="ERR_BUFFER_TOO_LARGE"||s.includes("output length")||s.includes("buffer too large")||s.includes("cannot create a buffer larger")?new Error(`[Ddu64 brotli] Decompressed data exceeds limit. Limit: ${t} bytes`,{cause:r}):r}}brotliDecompressSync(e,t){if(t===void 0||t===Number.POSITIVE_INFINITY)return new Uint8Array(brotliDecompressSync(Buffer.from(e)));try{return new Uint8Array(brotliDecompressSync(Buffer.from(e),{maxOutputLength:t}))}catch(r){let o=r,s=String(o?.message??"").toLowerCase();throw String(o?.code??"")==="ERR_BUFFER_TOO_LARGE"||s.includes("output length")||s.includes("buffer too large")||s.includes("cannot create a buffer larger")?new Error(`[Ddu64 brotli] Decompressed data exceeds limit. Limit: ${t} bytes`,{cause:r}):r}}};});var De={};R(De,{BrowserAdapter:()=>j});function At(n){return n===void 0||!Number.isFinite(n)||n<=0?21e4:Math.max(1e4,Math.floor(n))}function St(n){return n===void 0?new TextEncoder().encode(wt):typeof n=="string"?new TextEncoder().encode(n):n}var wt,j,Ue=_(()=>{wt="ddunigma:pbkdf2:v1";j=class{supportsSyncCrypto=false;supportsSyncCompression=false;supportsBrotli=false;runtime="browser";async deriveKey(e,t){let o=new TextEncoder().encode(e);if(t?.algorithm==="pbkdf2"){let i=await crypto.subtle.importKey("raw",o,"PBKDF2",false,["deriveBits"]),a=await crypto.subtle.deriveBits({name:"PBKDF2",salt:St(t.salt),iterations:At(t.iterations),hash:t.hash??"SHA-256"},i,256);return new Uint8Array(a)}let s=await crypto.subtle.digest("SHA-256",o);return new Uint8Array(s)}async encrypt(e,t){let r=crypto.getRandomValues(new Uint8Array(12)),o=await crypto.subtle.importKey("raw",t,{name:"AES-GCM"},false,["encrypt"]),s=await crypto.subtle.encrypt({name:"AES-GCM",iv:r,tagLength:128},o,e),i=new Uint8Array(s),a=i.slice(0,i.length-16),c=i.slice(i.length-16),l=new Uint8Array(28+a.length);return l.set(r,0),l.set(c,12),l.set(a,28),l}async decrypt(e,t){if(e.length<28)throw new Error("[Ddu64 decrypt] Encrypted data is invalid. Payload must be at least 28 bytes (12 IV + 16 authTag + ciphertext).");let r=e.slice(0,12),o=e.slice(12,28),s=e.slice(28),i=new Uint8Array(s.length+16);i.set(s,0),i.set(o,s.length);let a=await crypto.subtle.importKey("raw",t,{name:"AES-GCM"},false,["decrypt"]);try{let c=await crypto.subtle.decrypt({name:"AES-GCM",iv:r,tagLength:128},a,i);return new Uint8Array(c)}catch{throw new Error("[Ddu64 decrypt] Decryption failed: data tampering or incorrect key.")}}randomBytes(e){return crypto.getRandomValues(new Uint8Array(e))}async deflate(e,t){if(typeof CompressionStream>"u")throw new Error("[Ddu64 compress] Deflate compression is unsupported in the current runtime. CompressionStream API is not available.");let r=this.getDeflateFormat(),o=new CompressionStream(r),s=o.writable.getWriter(),i=o.readable.getReader();s.write(e),s.close();let a=[],c=0;for(;;){let{done:h,value:f}=await i.read();if(h)break;a.push(f),c+=f.length;}let l=new Uint8Array(c),d=0;for(let h of a)l.set(h,d),d+=h.length;return l}async inflate(e,t){if(typeof DecompressionStream>"u")throw new Error("[Ddu64 decompress] Deflate decompression is unsupported in the current runtime. DecompressionStream API is not available.");let r=this.getDeflateFormat(),o=new DecompressionStream(r),s=o.writable.getWriter(),i=o.readable.getReader();s.write(e),s.close();let a=[],c=0;for(;;){let{done:h,value:f}=await i.read();if(h)break;if(c+=f.length,t!==void 0&&c>t)throw new Error(`[Ddu64 decompress] Decompressed size exceeds limit. Estimated ${c}+ bytes exceeds maximum of ${t} bytes.`);a.push(f);}let l=new Uint8Array(c),d=0;for(let h of a)l.set(h,d),d+=h.length;return l}getDeflateFormat(){return "deflate-raw"}};});var ke={};R(ke,{detectRuntime:()=>ve,getAdapter:()=>Ct});function ve(){if(typeof globalThis.process<"u"&&globalThis.process?.versions?.node)return "node";if(globalThis.Deno?.version?.deno)return "deno";if(globalThis.Bun?.version)return "bun";if(typeof globalThis.crypto<"u"&&globalThis.crypto?.subtle)return "browser";throw new Error("[ddunigma] No suitable crypto provider found. Detected runtime lacks both Node.js crypto module and Web Crypto API (SubtleCrypto).")}async function Ct(){switch(ve()){case "node":{let{NodeAdapter:e}=await Promise.resolve().then(()=>(Pe(),Be));return new e}case "deno":case "bun":case "browser":case "edge":{let{BrowserAdapter:e}=await Promise.resolve().then(()=>(Ue(),De));return new e}default:throw new Error("[ddunigma] No suitable crypto provider found. Detected runtime lacks both Node.js crypto module and Web Crypto API (SubtleCrypto).")}}var Le=_(()=>{});function Q(n,e){let{bitLength:t,usePowerOfTwo:r,charsetSize:o}=e,s=n.length;if(s===0)return {indices:[],paddingBits:0};let i=s*8,a=Math.ceil(i/t),c=r?a:a*2,l=new Array(c),d=0,h=0,f=0;if(r){let p=(1<<t)-1;for(let g=0;g<s;g++)for(h=h<<8|n[g],f+=8;f>=t;)f-=t,l[d++]=h>>f&p,h&=(1<<f)-1;}else for(let p=0;p<s;p++)for(h=h<<8|n[p],f+=8;f>=t;){f-=t;let g=h>>f,m=g/o|0;l[d++]=m,l[d++]=g-m*o,h&=(1<<f)-1;}let u=0;if(f>0){u=t-f;let p=h<<u;if(r)l[d++]=p;else {let g=p/o|0;l[d++]=g,l[d++]=p-g*o;}}return l.length=d,{indices:l,paddingBits:u}}function J(n,e,t){let{bitLength:r,usePowerOfTwo:o,charsetSize:s}=t,i=n.length;if(i===0)return new Uint8Array(0);let a=o?1:2,c=Math.ceil(i/a),l=r<31?1<<r:Math.pow(2,r),d=Math.ceil((c*r-e)/8),h=new Uint8Array(d+1),f=0,u=0,p=0;if(o)for(let g=0;g<i;g+=a){let m=n[g];if(m<0||m>=s)throw new Error(`[BitPack decode] Invalid index ${m} at position ${g}`);for(u=u<<r|m,p+=r,g+a>=i&&e>0&&(u>>=e,p-=e);p>=8;)p-=8,h[f++]=u>>p&255,u&=(1<<p)-1;}else for(let g=0;g<i;g+=a){let m=n[g],y=n[g+1];if(m<0||m>=s)throw new Error(`[BitPack decode] Invalid index ${m} at position ${g}`);if(y===void 0||y<0||y>=s)throw new Error(`[BitPack decode] Invalid index ${y} at position ${g+1}`);let b=m*s+y;if(b>=l)throw new Error(`[BitPack decode] Value ${b} exceeds range at position ${g}`);for(u=u<<r|b,p+=r,g+a>=i&&e>0&&(u>>=e,p-=e);p>=8;)p-=8,h[f++]=u>>p&255,u&=(1<<p)-1;}return h.subarray(0,f)}function Re(n,e){return n<=1?0:e?Math.floor(Math.log2(n)):Math.ceil(Math.log2(n))}function Ie(n){return n>0&&(n&n-1)===0}function ee(n){let e=Ie(n);return {bitLength:Re(n,e),usePowerOfTwo:e,charsetSize:n}}var C="ELYSIA",E="GRISEO";function I(n,e,t){let r=n.length,o=e.length,s={cleanedInput:n,paddingBits:0,isEncrypted:false,pipelineVersion:2};if(r<o)return s;let a=Math.max(0,t-1).toString().length;for(let c=Math.min(a,r);c>=1;c--){let l=r-c,d=true;for(let b=l;b<r;b++){let X=n.charCodeAt(b);if(X<48||X>57){d=false;break}}if(!d)continue;let h=n.substring(l),f=parseInt(h,10);if(Number.isNaN(f)||f<0||f>=t||h!==f.toString())continue;let u=l,p=false,g,m=2;u>=2&&n.substring(u-2,u)==="V3"&&(m=3,u-=2),u>=3&&n.substring(u-3,u)==="ENC"&&(p=true,u-=3),u>=C.length&&n.substring(u-C.length,u)===C?(g="deflate",u-=C.length):u>=E.length&&n.substring(u-E.length,u)===E&&(g="brotli",u-=E.length);let y=u-o;if(y>=0&&n.substring(y,u)===e)return {cleanedInput:n.substring(0,y),paddingBits:f,compressionAlgorithm:g,isEncrypted:p,pipelineVersion:m}}if(n.endsWith(e)){let c=0,l=r;for(;l>=o&&n.substring(l-o,l)===e;)c++,l-=o;if(c>0){let d=c*2;if(d<t)return {cleanedInput:n.substring(0,l),paddingBits:d,isEncrypted:false,pipelineVersion:2}}}return s}function M(n){let e=n.lastIndexOf("CHK");if(e===-1)return {data:n,checksum:null};let t=n.slice(e+3);return t.length!==8||!/^[0-9a-f]+$/i.test(t)?{data:n,checksum:null}:{data:n.slice(0,e),checksum:t.toLowerCase()}}function te(n){let{paddingBits:e,compressionAlgorithm:t,isEncrypted:r,paddingChar:o,useRepeatPadding:s,pipelineVersion:i=2}=n;if(e===0&&!t&&!r&&i===2)return "";if(s&&!t&&!r&&i===2&&e>0&&e%2===0){let c=e>>1;return o.repeat(c)}return o+(t==="deflate"?C:t==="brotli"?E:"")+(r?"ENC":"")+(i===3?"V3":"")+e.toString()}var Me=(()=>{let n=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let r=0;r<8;r++)t=t>>>1^(t&1?3988292384:0);n[e]=t;}return n})();function B(n){let e=4294967295;for(let t=0;t<n.length;t++)e=e>>>8^Me[(e^n[t])&255];return ((e^4294967295)>>>0).toString(16).padStart(8,"0")}function re(n){return n.length===0?n:n.replaceAll("+","-").replaceAll("/","_").replaceAll("=",".")}function O(n){return n.length===0?n:n.replaceAll("-","+").replaceAll("_","/").replaceAll(".","=")}function ne(n,e,t){if(e<=0||n.length<=e)return n;let r=Math.ceil(n.length/e),o=new Array(r*2-1),s=0;for(let i=0;i<n.length;i+=e)o[s++]=n.slice(i,i+e),i+e<n.length&&(o[s++]=t);return o.join("")}function N(n,e){if(n.length===0)return n;let t=n.replace(/[\r\n]/g,""),r=e&&e!==`
2
2
  `&&e!==`\r
3
3
  `&&e!=="\r"?e:"";return r.length>0&&t.includes(r)&&(t=t.replaceAll(r,"")),t}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 Ne(n,e){let t=n.charCodeAt(0);if(t<44032||t>55203)return n;let r=t-(t-44032)%28,o=Oe[e]??0;return String.fromCharCode(r+o)}function D(n,e){let t=new Array(n.length*e.length),r=0;for(let o of n)for(let s of e)t[r++]=Ne(o,s);return t}function U(n,e){let r=n===void 0||!Number.isFinite(n)?6:Math.floor(n);return Math.min(e==="brotli"?11:9,Math.max(0,r))}var Ke=new TextEncoder,We=new TextDecoder;function v(n){return Ke.encode(n)}function K(n){return We.decode(n)}var W=(r=>(r.DDU="ddu",r.DDU_V1="ddu_v1",r.ONECHARSET="oneCharSet",r))(W||{}),z={dduSetSymbol:"ddu",usePowerOfTwo:true,requiredLength:64,bitLength:6};var ze={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},He={symbol:"ddu_v1",charSet:["\uB70C","\uB568","\uC774","\uC6B0","\uC57C","!","?","."],maxRequiredLength:8,bitLength:3,paddingChar:"\uBB50",useRepeatPadding:true},Fe={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 k(n){switch(n){case "ddu":return ze;case "ddu_v1":return He;case "oneCharSet":return Fe;default:return}}var $e=65536,Ye=["-","_","."];function oe(n,e,t,r){let o=(s,i,a,c,l)=>{if(qe(a,t?.usePowerOfTwo)&&a>0){let f=Math.floor(Math.log2(a)),u=1<<f;return {charSet:s.length===u?s:s.slice(0,u),padding:i,requiredLength:u,bitLength:f,isPredefined:c,useRepeatPadding:l}}return {charSet:s.length===a?s:s.slice(0,a),padding:i,requiredLength:a,bitLength:a>0?Math.ceil(Math.log2(a)):0,isPredefined:c,useRepeatPadding:l}};try{let s=n??t?.dduChar,i=e??t?.paddingChar;if(s){if(!i)throw new Error("[Ddu64 Constructor] paddingChar is required when dduChar is provided.");let d=typeof s=="string"?[...s]:[...s],h=t?.codaChar,f=h?!0:t?.useRepeatPadding??!1;if(h&&h.length>0&&(d=D(d,h)),r&&new Set(d).size!==d.length){let g=d.filter((m,y)=>d.indexOf(m)!==y);throw new Error(`[Ddu64 Constructor] Character set contains duplicate characters: [${[...new Set(g)].join(", ")}]`)}let u=t?.requiredLength??d.length;if(d.length<u)throw new Error("[Ddu64 Constructor] Insufficient characters.");return o(d,i,u,!1,f)}let a=t?.dduSetSymbol??z.dduSetSymbol??"ddu",c=Ve(a),l=c.codaChar?D(c.charSet,c.codaChar):c.charSet;return o(l,c.paddingChar,c.maxRequiredLength,!0,c.useRepeatPadding)}catch(s){if(r)throw s;return H(t)}}function se(n,e,t){let r=[n,null];for(let s of r){let i=s?{...s}:H(t);try{let a=i.charSet,c=i.requiredLength,l=Array.from(new Set(a));if(l.length!==a.length){if(e){let f=a.filter((u,p)=>a.indexOf(u)!==p);throw new Error(`[Ddu64 normalizeCharSet] Character set contains duplicate characters: [${[...new Set(f)].join(", ")}]`)}a=l,i.isPredefined||(c=a.length);}if(a.length<c)throw new Error(`[Ddu64 normalizeCharSet] Insufficient characters. Required: ${c}, Has: ${a.length}`);if(c<2)throw new Error("[Ddu64 normalizeCharSet] At least 2 unique characters required.");if(a.length===0)throw new Error("[Ddu64 normalizeCharSet] Empty charset.");if(a.find(f=>f.length!==1)){if(e)throw new Error("[Ddu64 normalizeCharSet] Multi-character symbols are not supported.");continue}if(a.length>$e){if(e)throw new Error("[Ddu64 normalizeCharSet] Charset size exceeds maximum supported size of 65536.");continue}if(i.padding.length!==1)throw new Error(`[Ddu64 normalizeCharSet] Padding length mismatch. Expected 1, got ${i.padding.length}`);if(a.includes(i.padding)){if(e)throw new Error(`[Ddu64 normalizeCharSet] Padding character "${i.padding}" conflicts with charset.`);a=a.filter(f=>f!==i.padding);}for(let f of a)if(f.includes(`
4
4
  `)||f.includes("\r"))throw new Error("[Ddu64 normalizeCharSet] Newline and carriage return characters are reserved.");if(i.padding.includes(`
5
- `)||i.padding.includes("\r"))throw new Error("[Ddu64 normalizeCharSet] Newline and carriage return characters are reserved.");return {charSet:a.length===c?a:a.slice(0,c),padding:i.padding,isPredefined:i.isPredefined}}catch(a){if(e)throw a}}let o=H(t);return {charSet:o.charSet.slice(0,o.requiredLength),padding:o.padding,isPredefined:true}}function ie(n,e,t){for(let r of Ye){for(let o of n)if(o.includes(r)){let s=`[Ddu64 Constructor] URL-Safe mode conflict: charset character "${o}" contains "${r}".`;if(t)throw new Error(s);return false}if(e.includes(r)){let o=`[Ddu64 Constructor] URL-Safe mode conflict: padding character "${e}" contains "${r}".`;if(t)throw new Error(o);return false}}return true}function ae(n,e,t){if(t>256)return;let r=Math.min(n.length,t),o=n.slice(0,r),s=new Set;for(let a=0;a<o.length;a++)s.add(o[a]);s.add(e);for(let a=0;a<o.length;a++){let c=o[a];for(let h=0;h<o.length;h++){let f=c+o[h];if(s.has(f))throw new Error(`Combination conflict: "${c}" + "${o[h]}"`);s.add(f);}let l=c+e;if(s.has(l))throw new Error(`Combination conflict: "${c}" + padding`);s.add(l);let d=e+c;if(s.has(d))throw new Error(`Combination conflict: padding + "${c}"`);s.add(d);}let i=e+e;if(s.has(i))throw new Error("Combination conflict: double padding");s.add(i);}function qe(n,e){return e!==void 0?e?n>0:false:n>0&&(n&n-1)===0}function Ve(n){let e=k(n);if(!e)throw new Error(`CharSet with symbol ${n} not found`);return e}function H(n){let e=n?.dduSetSymbol??z.dduSetSymbol??"oneCharSet",t=k(e)??k("oneCharSet");if(!t)throw new Error("Critical: No fallback CharSet available");return {charSet:t.codaChar?D(t.charSet,t.codaChar):t.charSet,padding:t.paddingChar,requiredLength:t.maxRequiredLength,bitLength:t.bitLength,isPredefined:true,useRepeatPadding:t.useRepeatPadding}}function Ge(){let n=1;return typeof globalThis.navigator<"u"&&globalThis.navigator.hardwareConcurrency?n=globalThis.navigator.hardwareConcurrency:typeof globalThis.process<"u"&&globalThis.process.versions?.node&&(typeof globalThis.process.availableParallelism=="function"?n=globalThis.process.availableParallelism():n=4),Math.max(1,Math.min(64,n-1))}function je(){try{let{Worker:n}=_e("worker_threads"),e=new URL("./nodeWorker.js",import.meta.url).pathname,t=new n(e);return {postMessage(r){t.postMessage(r);},async terminate(){await t.terminate();},onMessage(r){t.on("message",r);},onError(r){t.on("error",r);}}}catch{return null}}function Ze(){try{if(typeof globalThis.Worker>"u")return null;let n=new URL("./webWorker.js",import.meta.url),e=new globalThis.Worker(n,{type:"module"});return {postMessage(t){e.postMessage(t);},async terminate(){e.terminate();},onMessage(t){e.addEventListener("message",r=>{t(r.data);});},onError(t){e.addEventListener("error",r=>{t(new Error(r.message||"Worker error"));});}}}catch{return null}}var $=class{poolSize;workers=[];pendingTasks=new Map;nextTaskId=0;roundRobinIndex=0;initialized=false;terminated=false;constructor(e){this.poolSize=e??Ge();}async encode(e,t){return await this.dispatch("encode",e,t)}async decode(e,t){return await this.dispatch("decode",e,t)}setPoolSize(e){if(!Number.isInteger(e))throw new Error(`[WorkerPool] Pool size must be an integer. Got: ${e}. Valid range: [1, 64]`);if(e<1||e>64)throw new Error(`[WorkerPool] Pool size must be between 1 and 64. Got: ${e}`);let t=this.poolSize;this.poolSize=e,this.initialized&&t!==e&&(this.terminateWorkers(),this.initialized=false);}async terminate(){this.terminated=true,await this.terminateWorkers();for(let[,e]of this.pendingTasks)e.reject(new Error("[WorkerPool] Pool terminated"));this.pendingTasks.clear();}async dispatch(e,t,r){if(this.terminated)throw new Error("[WorkerPool] Pool has been terminated");if(this.ensureInitialized(),this.workers.length===0)throw new Error("[WorkerPool] No workers available. Workers may not be supported in this runtime.");let o=this.nextTaskId++,s=this.roundRobinIndex%this.workers.length;this.roundRobinIndex=(this.roundRobinIndex+1)%this.workers.length;let i=this.workers[s];return new Promise((a,c)=>{this.pendingTasks.set(o,{resolve:a,reject:c});let l={id:o,type:e,data:t,config:r};i.postMessage(l);})}ensureInitialized(){if(this.initialized)return;let e=typeof globalThis.process<"u"&&!!globalThis.process.versions?.node;for(let t=0;t<this.poolSize;t++){let r=e?je():Ze();if(!r)break;r.onMessage(o=>{let s=this.pendingTasks.get(o.id);s&&(this.pendingTasks.delete(o.id),o.type==="error"?s.reject(new Error(o.error??"Worker error")):s.resolve(o.result));}),r.onError(o=>{console.error("[WorkerPool] Worker error:",o.message);}),this.workers.push(r);}this.initialized=true;}async terminateWorkers(){let e=this.workers.map(t=>t.terminate());await Promise.all(e),this.workers=[];}},F=null;function Xe(){return F||(F=new $),F}function ce(n){Xe().setPoolSize(n);}function le(n){if(n.length===0)throw new Error("[Ddu64 obfuscation] Alphabet must not be empty.");if(n.length>11172)throw new Error(`[Ddu64 obfuscation] Alphabet size (${n.length}) exceeds available Hangul syllables (11172).`);let e=Math.floor(11172/n.length),t=new Map;for(let r=0;r<n.length;r++)t.set(n[r],r);return {alphabet:n,syllablesPerChar:e,charToIndex:t}}function de(n,e,t){let r=44032+n*t.syllablesPerChar,o=e%t.syllablesPerChar;return r+o}function ue(n,e){if(n<44032||n>55203)return -1;let t=n-44032,r=Math.floor(t/e.syllablesPerChar);return r>=e.alphabet.length?-1:r}var L=class{config;constructor(e){this.config=le(e);}obfuscate(e){if(e.length===0)return "";let t=new Array(e.length);for(let r=0;r<e.length;r++){let o=e[r],s=this.config.charToIndex.get(o);if(s===void 0)throw new Error(`[Ddu64 obfuscation] Character "${o}" (U+${o.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase()}) not found in obfuscation alphabet.`);let i=de(s,r,this.config);t[r]=String.fromCharCode(i);}return t.join("")}deobfuscate(e){if(e.length===0)return "";let t=new Array(e.length);for(let r=0;r<e.length;r++){let o=e.charCodeAt(r),s=ue(o,this.config);if(s===-1)throw new Error(`[Ddu64 obfuscation] Invalid syllable at position ${r}: U+${o.toString(16).padStart(4,"0").toUpperCase()} is not in the mapped range.`);t[r]=this.config.alphabet[s];}return t.join("")}};var S=null,Y=false,A=false,w=null,q=class{exports;_ready=true;constructor(e){this.exports=e;}get ready(){return this._ready}encode(e,t){let{exports:r}=this;if(e.length===0)return {indices:new Uint16Array(0),paddingBits:0};let o=r.alloc(e.length);new Uint8Array(r.memory.buffer).set(e,o);let i=1<<t,a=1;try{let c=r.encode(o,e.length,t,i,a),l=r.get_result_ptr(),d=new Uint16Array(r.memory.buffer,l,c),h=new Uint16Array(c);return h.set(d),{indices:h,paddingBits:r.get_padding_bits()}}finally{r.dealloc(o,e.length);}}decode(e,t,r){let{exports:o}=this;if(e.length===0)return new Uint8Array(0);let s=e.length*2,i=o.alloc(s);new Uint16Array(o.memory.buffer,i,e.length).set(e);let c=1<<t,l=1;try{let d=o.decode(i,e.length,t,c,l,r);if(d===4294967295)throw new Error("[WasmCodec decode] Invalid index in input");let h=o.get_result_ptr(),f=new Uint8Array(o.memory.buffer,h,d),u=new Uint8Array(d);return u.set(f),u}finally{o.dealloc(i,s);}}};async function Qe(){try{if(typeof globalThis.process<"u"&&globalThis.process.versions?.node){let{readFile:n}=await import('fs/promises'),{fileURLToPath:e}=await import('url'),{dirname:t,join:r}=await import('path'),o=t(e(import.meta.url)),s=r(o,"wasm","codec.wasm");try{let i=await n(s);return i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)}catch{let i=r(o,"codec.wasm");try{let a=await n(i);return a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength)}catch{let a=r(o,"..","wasm","codec.wasm");try{let c=await n(a);return c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength)}catch{return null}}}}if(typeof fetch=="function"){let n=await fetch(new URL("./wasm/codec.wasm",import.meta.url));return n.ok?await n.arrayBuffer():null}return null}catch{return null}}async function Je(n){try{if(n.byteLength<16)return null;let e=new Uint8Array(n,0,4);if(e[0]!==0||e[1]!==97||e[2]!==115||e[3]!==109)return null;let t;try{t=await WebAssembly.compile(n);}catch{return null}let o=(await WebAssembly.instantiate(t,{})).exports;return typeof o.alloc!="function"||typeof o.dealloc!="function"||typeof o.encode!="function"||typeof o.decode!="function"||typeof o.get_result_ptr!="function"||typeof o.get_result_len!="function"||typeof o.get_padding_bits!="function"||!o.memory?null:o}catch{return null}}async function he(){try{if(S)return !0;if(A)return !1;let n=await Qe();if(!n)return A=!0,!1;let e=await Je(n);return e?(S=new q(e),!0):(A=!0,!1)}catch{return A=true,false}}function et(n,e){let t;return {promise:new Promise((s,i)=>{t=setTimeout(()=>i(new Error(e)),n);}),clear:()=>clearTimeout(t)}}async function tt(){if(S)return;if(w)return w;let n=et(1e4,"[Ddu64 wasm] WASM initialization timed out (10s)"),e=async()=>{try{if(!await he())throw new Error("[Ddu64 wasm] WASM initialization failed")}finally{n.clear();}};return w=Promise.race([e(),n.promise]).finally(()=>{w=null,Y=true;}),w}function rt(){if(S)return S;if(A)return null;if(!Y&&!w){Y=true;let n;w=new Promise(e=>{n=setTimeout(()=>{A=true,e();},5e3),he().then(t=>{t||(A=true);}).catch(()=>{A=true;}).finally(()=>{n!==void 0&&clearTimeout(n),e();});}).finally(()=>{w=null;});}return null}function x(){return S}function fe(n){if(!Number.isFinite(n))throw new Error(`[Ddu64 config] wasmThreshold must be a finite number, got ${n}`);return Math.max(1024,Math.min(1048576,Math.round(n)))}var Bt=8,Pt=64*1024*1024,Dt=64*1024*1024,j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",xe="=",Ut=Object.fromEntries([...j].map((n,e)=>[n,e])),T=class{dduChar;paddingChar;bitLength;usePowerOfTwo;effectiveBitLength;dduBinaryLookup=new Map;isPredefinedCharSet;defaultCompress;defaultMaxDecodedBytes;defaultMaxDecompressedBytes;urlSafe;encryptionKey;keyDerivation;encryptionKeyHash;defaultChecksum;defaultChunkSize;defaultChunkSeparator;defaultCompressionLevel;defaultCompressionAlgorithm;useRepeatPadding;bitPackConfig;wasmThreshold;canUseNativeBase64;nativeDecodeMap;adapter;defaultObfuscate;_obfuscationLayer;constructor(e,t,r){let o=r?.throwOnError??r?.useBuildErrorReturn??false;r?.adapter?this.adapter=r.adapter:this.adapter=void 0;let s=oe(e,t,r,o),i=se(s,o,r);this.dduChar=i.charSet,this.paddingChar=i.padding,this.isPredefinedCharSet=i.isPredefined,this.defaultCompress=r?.compress??false,this.defaultMaxDecodedBytes=this.normalizeLimit(r?.maxDecodedBytes,Pt,o,"maxDecodedBytes"),this.defaultMaxDecompressedBytes=this.normalizeLimit(r?.maxDecompressedBytes,Dt,o,"maxDecompressedBytes");let a=this.dduChar.length;this.usePowerOfTwo=a>0&&(a&a-1)===0;let c=Math.ceil(Math.log2(a));this.bitLength=this.usePowerOfTwo?Math.floor(Math.log2(a)):c,this.effectiveBitLength=this.usePowerOfTwo?this.bitLength:c;for(let d=0;d<a;d++)this.dduBinaryLookup.set(this.dduChar[d],d);this.isPredefinedCharSet||ae(this.dduChar,this.paddingChar,a);let l=r?.urlSafe??false;if(this.urlSafe=l?ie(this.dduChar,this.paddingChar,o):false,this.encryptionKey=r?.encryptionKey,this.keyDerivation=r?.keyDerivation,this.encryptionKey&&this.adapter?.deriveKeySync&&(this.encryptionKeyHash=this.adapter.deriveKeySync(this.encryptionKey,this.keyDerivation)),this.defaultChecksum=r?.checksum??false,this.defaultChunkSize=r?.chunkSize,this.defaultChunkSeparator=r?.chunkSeparator??`
6
- `,this.defaultCompressionAlgorithm=r?.compressionAlgorithm??"deflate",this.defaultCompressionLevel=U(r?.compressionLevel,this.defaultCompressionAlgorithm),this.useRepeatPadding=r?.useRepeatPadding??s.useRepeatPadding??false,this.defaultObfuscate=r?.obfuscate??false,this.defaultObfuscate&&!this.encryptionKey)throw new Error("[Ddu64 obfuscation] Obfuscation requires encryption to be enabled.");if(this.bitPackConfig=ee(a),this.wasmThreshold=fe(r?.wasmThreshold??4096),this.canUseNativeBase64=this.usePowerOfTwo&&this.dduChar.length===64,this.canUseNativeBase64){this.nativeDecodeMap=new Map;for(let d=0;d<j.length;d++){let h=this.dduChar[d];this.nativeDecodeMap.set(h,j[d]);}}}encode(e,t){return this.encodeInternal(e,t).encoded}decode(e,t){let r=this.decodeToUint8Array(e,t);return K(r)}decodeToUint8Array(e,t){let r=t?.checksum??this.defaultChecksum,o=t?.compress!==false,s=t?.encrypt!==false,i=e;this.reportProgress(t,{processedBytes:0,totalBytes:e.length,percent:0,stage:"start"});let a=t?.chunkSeparator??this.defaultChunkSeparator;i=N(i,a),this.urlSafe&&(i=O(i));let c=null;if(r){let y=M(i);c=y.checksum,i=y.data;}this.shouldObfuscate(t)&&(i=this.getObfuscationLayer().deobfuscate(i));let{cleanedInput:l,paddingBits:d,compressionAlgorithm:h,isEncrypted:f,pipelineVersion:u}=I(i,this.paddingChar,this.effectiveBitLength);if(f&&s&&!this.encryptionKey)throw new Error("[Ddu64 decode] Encrypted payload requires an encryptionKey");this.assertEncodedInputAligned(l);let p=this.normalizeLimit(t?.maxDecodedBytes,this.defaultMaxDecodedBytes,true,"maxDecodedBytes"),g=this.estimateDecodedBytes(l.length,d);if(g>p)throw new Error(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${g} bytes, Limit: ${p} bytes`);this.reportProgress(t,{processedBytes:l.length,totalBytes:e.length,percent:30,stage:"decode"});let m=this.decodeChars(l,d);if(u===3&&f&&this.encryptionKey&&s&&(this.reportProgress(t,{processedBytes:m.length,totalBytes:m.length,percent:55,stage:"decrypt"}),m=this.decryptSync(m)),h&&o&&(u===2||!f||s)){let y=this.normalizeLimit(t?.maxDecompressedBytes,this.defaultMaxDecompressedBytes,true,"maxDecompressedBytes");this.reportProgress(t,{processedBytes:m.length,totalBytes:m.length,percent:70,stage:"decompress"}),m=this.decompressSync(m,h,y);}if(c&&(u===2||!f||s)){this.reportProgress(t,{processedBytes:m.length,totalBytes:m.length,percent:85,stage:"checksum"});let y=B(m);if(y!==c)throw new Error(`[Ddu64 decode] Checksum mismatch. Expected: ${c}, Got: ${y}`)}return u===2&&f&&this.encryptionKey&&s&&(this.reportProgress(t,{processedBytes:m.length,totalBytes:m.length,percent:90,stage:"decrypt"}),m=this.decryptSync(m)),this.reportProgress(t,{processedBytes:m.length,totalBytes:m.length,percent:100,stage:"done"}),m}async encodeAsync(e,t){let r=await this.getAdapterAsync(),o=t?.compress??this.defaultCompress,s=t?.checksum??this.defaultChecksum,i=(t?.encrypt??true)&&!!this.encryptionKey,a=t?.chunkSize??this.defaultChunkSize,c=t?.chunkSeparator??this.defaultChunkSeparator,l=typeof e=="string"?v(e):e;this.reportProgress(t,{processedBytes:0,totalBytes:l.length,percent:0,stage:"start"});let d="";s&&(d=B(l));let h;if(o){let p=t?.compressionAlgorithm??this.defaultCompressionAlgorithm,g=U(t?.compressionLevel??this.defaultCompressionLevel,p);this.reportProgress(t,{processedBytes:l.length,totalBytes:l.length,percent:20,stage:"compress"});let m;if(p==="brotli"){if(!r.brotliCompress)throw new Error("[Ddu64 compress] Brotli compression is unavailable in the current runtime.");m=await r.brotliCompress(l,g);}else m=await r.deflate(l,g);m.length<l.length&&(l=m,h=p);}let f=false;if(i){let p=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:l.length,totalBytes:l.length,percent:45,stage:"encrypt"}),l=await r.encrypt(l,p),f=true;}this.reportProgress(t,{processedBytes:l.length,totalBytes:l.length,percent:70,stage:"encode"});let u=this.encodeBytes(l,h,f,t);return u=this.applyPostEncoding(u,t,d,s,a,c),this.reportProgress(t,{processedBytes:l.length,totalBytes:l.length,percent:100,stage:"done"}),u}async decodeAsync(e,t){let r=await this.decodeToUint8ArrayAsync(e,t);return K(r)}async decodeToUint8ArrayAsync(e,t){let r=await this.getAdapterAsync(),o=t?.checksum??this.defaultChecksum,s=t?.compress!==false,i=t?.encrypt!==false,a=e;this.reportProgress(t,{processedBytes:0,totalBytes:e.length,percent:0,stage:"start"});let c=t?.chunkSeparator??this.defaultChunkSeparator;a=N(a,c),this.urlSafe&&(a=O(a));let l=null;if(o){let b=M(a);l=b.checksum,a=b.data;}this.shouldObfuscate(t)&&(a=this.getObfuscationLayer().deobfuscate(a));let{cleanedInput:d,paddingBits:h,compressionAlgorithm:f,isEncrypted:u,pipelineVersion:p}=I(a,this.paddingChar,this.effectiveBitLength);if(u&&i&&!this.encryptionKey)throw new Error("[Ddu64 decode] Encrypted payload requires an encryptionKey");this.assertEncodedInputAligned(d);let g=this.normalizeLimit(t?.maxDecodedBytes,this.defaultMaxDecodedBytes,true,"maxDecodedBytes"),m=this.estimateDecodedBytes(d.length,h);if(m>g)throw new Error(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${m} bytes, Limit: ${g} bytes`);this.reportProgress(t,{processedBytes:d.length,totalBytes:e.length,percent:30,stage:"decode"});let y=this.decodeChars(d,h);if(p===3&&u&&this.encryptionKey&&i){let b=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:55,stage:"decrypt"}),y=await r.decrypt(y,b);}if(f&&s&&(p===2||!u||i)){let b=this.normalizeLimit(t?.maxDecompressedBytes,this.defaultMaxDecompressedBytes,true,"maxDecompressedBytes");if(f==="brotli"){if(!r.brotliDecompress)throw new Error("[Ddu64 decompress] Brotli decompression is unavailable in the current runtime.");this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:70,stage:"decompress"}),y=await r.brotliDecompress(y,b);}else this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:70,stage:"decompress"}),y=await r.inflate(y,b);}if(l&&(p===2||!u||i)){this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:85,stage:"checksum"});let b=B(y);if(b!==l)throw new Error(`[Ddu64 decode] Checksum mismatch. Expected: ${l}, Got: ${b}`)}if(p===2&&u&&this.encryptionKey&&i){let b=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:90,stage:"decrypt"}),y=await r.decrypt(y,b);}return this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:100,stage:"done"}),y}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,defaultChunkSize:this.defaultChunkSize,defaultChunkSeparator:this.defaultChunkSeparator,defaultCompressionLevel:this.defaultCompressionLevel,defaultCompressionAlgorithm:this.defaultCompressionAlgorithm}}getStats(e,t){let o=(typeof e=="string"?v(e):e).length,{encoded:s,compressedSize:i}=this.encodeInternal(e,t),a=s.length,c=o>0?a/o:0,d=(t?.compress??this.defaultCompress)&&i!==void 0&&o>0?i/o:void 0;return {originalSize:o,encodedSize:a,compressedSize:i,compressionRatio:d,expansionRatio:c,charsetSize:this.dduChar.length,bitLength:this.bitLength}}static setWorkerPoolSize(e){ce(e);}encodeInternal(e,t){let r=t?.compress??this.defaultCompress,o=t?.checksum??this.defaultChecksum,s=(t?.encrypt??true)&&!!this.encryptionKey,i=t?.chunkSize??this.defaultChunkSize,a=t?.chunkSeparator??this.defaultChunkSeparator,c=typeof e=="string"?v(e):e;this.reportProgress(t,{processedBytes:0,totalBytes:c.length,percent:0,stage:"start"});let l="";o&&(l=B(c));let d,h;if(r){let p=t?.compressionAlgorithm??this.defaultCompressionAlgorithm,g=U(t?.compressionLevel??this.defaultCompressionLevel,p);this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:20,stage:"compress"});let m=this.compressSync(c,p,g);h=m.length,m.length<c.length&&(c=m,d=p);}let f=false;s&&(this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:45,stage:"encrypt"}),c=this.encryptSync(c),f=true),this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:70,stage:"encode"});let u=this.encodeBytes(c,d,f,t);return u=this.applyPostEncoding(u,t,l,o,i,a),this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:100,stage:"done"}),{encoded:u,compressedSize:h}}applyPostEncoding(e,t,r,o,s,i){let a=e;return this.shouldObfuscate(t)&&(a=this.getObfuscationLayer().obfuscate(a)),o&&r&&(a=a+"CHK"+r),this.urlSafe&&(a=re(a)),s&&s>0&&(a=ne(a,s,i)),a}encodeBytes(e,t,r,o){if(e.length===0)return "";let s=this.encodeBytesWithNativeBase64(e),i,a;if(s)i=s.indices,a=s.paddingBits;else {let d=this.shouldUseWasm(e.length)?x():null;if(d?.ready&&this.usePowerOfTwo){let h=d.encode(e,this.bitLength);i=h.indices,a=h.paddingBits;}else {let h=Q(e,this.bitPackConfig);i=h.indices,a=h.paddingBits;}}let c=new Array(i.length);for(let d=0;d<i.length;d++)c[d]=this.dduChar[i[d]];let l=o?.omitFooter?"":te({paddingBits:a,compressionAlgorithm:t,isEncrypted:!!r,paddingChar:this.paddingChar,useRepeatPadding:this.useRepeatPadding&&!t&&!r,pipelineVersion:r?3:2});return c.join("")+l}decodeChars(e,t){let r=e.length;if(r===0)return new Uint8Array(0);let o=this.decodeCharsWithNativeBase64(e,t);if(o)return o;let s=r>=this.wasmThreshold||r>=4096?new Uint16Array(r):new Array(r);for(let a=0;a<r;a++){let c=e[a],l=this.dduBinaryLookup.get(c);if(l===void 0)throw new Error(`[Ddu64 decode] Invalid character "${c}" at ${a}`);s[a]=l;}let i=this.shouldUseWasm(r)?x():null;if(i?.ready&&this.usePowerOfTwo){let a=s instanceof Uint16Array?s:Uint16Array.from(s);return i.decode(a,this.bitLength,t)}return J(s,t,this.bitPackConfig)}encodeBytesWithNativeBase64(e){if(!this.canUseNativeBase64)return null;let t=this.bytesToBase64(e);if(t===null)return null;let r=0,o=t.length;for(;o>0&&t[o-1]===xe;)r++,o--;let s=o>=4096?new Uint16Array(o):new Array(o);for(let i=0;i<o;i++)s[i]=Ut[t[i]];return {indices:s,paddingBits:r===2?4:r===1?2:0}}decodeCharsWithNativeBase64(e,t){if(!this.canUseNativeBase64||!this.nativeDecodeMap)return null;let r=t===4?2:t===2?1:t===0?0:-1;if(r<0)return null;let o=new Array(e.length+r);for(let s=0;s<e.length;s++){let i=this.nativeDecodeMap.get(e[s]);if(i===void 0)return null;o[s]=i;}for(let s=0;s<r;s++)o[e.length+s]=xe;return this.base64ToBytes(o.join(""))}bytesToBase64(e){let t=e.toBase64;if(typeof t=="function")return t.call(e);let r=globalThis.Buffer;return r?.from?r.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"):null}base64ToBytes(e){let t=Uint8Array;if(typeof t.fromBase64=="function")return t.fromBase64(e);let r=globalThis.Buffer;if(r?.from){let o=r.from(e,"base64");return new Uint8Array(o.buffer,o.byteOffset,o.byteLength)}return null}shouldUseWasm(e){return e>=this.wasmThreshold}reportProgress(e,t){e?.onProgress?.(t);}requireSyncAdapter(){if(!this.adapter)throw new Error("[Ddu64 adapter] No platform adapter available. Use encodeAsync()/decodeAsync() in browser environments, or provide an adapter via options.adapter.");return this.adapter}encryptSync(e){let t=this.requireSyncAdapter();if(!t.encryptSync)throw new Error("[Ddu64 encrypt] Sync encryption unavailable. Use encodeAsync() in browser environments.");if(!this.encryptionKeyHash){if(!t.deriveKeySync)throw new Error("[Ddu64 encrypt] Sync key derivation unavailable. Use encodeAsync() in browser environments.");this.encryptionKeyHash=t.deriveKeySync(this.encryptionKey,this.keyDerivation);}return t.encryptSync(e,this.encryptionKeyHash)}decryptSync(e){let t=this.requireSyncAdapter();if(!t.decryptSync)throw new Error("[Ddu64 decrypt] Sync decryption unavailable. Use decodeAsync() in browser environments.");if(!this.encryptionKeyHash){if(!t.deriveKeySync)throw new Error("[Ddu64 decrypt] Sync key derivation unavailable. Use decodeAsync() in browser environments.");this.encryptionKeyHash=t.deriveKeySync(this.encryptionKey,this.keyDerivation);}return t.decryptSync(e,this.encryptionKeyHash)}compressSync(e,t,r){let o=this.requireSyncAdapter();if(t==="brotli"){if(!o.brotliCompressSync)throw new Error("[Ddu64 compress] Brotli compression is unavailable in the current runtime.");return o.brotliCompressSync(e,r)}if(!o.deflateSync)throw new Error("[Ddu64 compress] Sync compression unavailable. Use encodeAsync() in browser environments.");return o.deflateSync(e,r)}decompressSync(e,t,r){let o=this.requireSyncAdapter();if(t==="brotli"){if(!o.brotliDecompressSync)throw new Error("[Ddu64 decompress] Brotli decompression is unavailable in the current runtime.");return o.brotliDecompressSync(e,r)}if(!o.inflateSync)throw new Error("[Ddu64 decompress] Sync decompression unavailable. Use decodeAsync() in browser environments.");return o.inflateSync(e,r)}async getAdapterAsync(){if(this.adapter)return this.adapter;let{getAdapter:e}=await Promise.resolve().then(()=>(Le(),ke));return this.adapter=await e(),this.adapter}async getKeyHashAsync(e){return this.encryptionKeyHash?this.encryptionKeyHash:(this.encryptionKeyHash=await e.deriveKey(this.encryptionKey,this.keyDerivation),this.encryptionKeyHash)}getObfuscationLayer(){if(!this._obfuscationLayer){let e=new Set(this.dduChar);e.add(this.paddingChar);let t="ELYSIAGRONCV01234567";for(let o of t)e.add(o);let r=[...e];this._obfuscationLayer=new L(r);}return this._obfuscationLayer}shouldObfuscate(e){let t=e?.obfuscate??this.defaultObfuscate;if(t&&!this.encryptionKey)throw new Error("[Ddu64 obfuscation] Obfuscation requires encryption to be enabled.");return t}normalizeLimit(e,t,r,o){if(e===void 0)return t;if(e===Number.POSITIVE_INFINITY)return Number.POSITIVE_INFINITY;if(!Number.isFinite(e)||e<=0){if(r)throw new Error(`[Ddu64 options] Invalid ${o}. Must be a positive finite number or Infinity.`);return t}return Math.floor(e)}estimateDecodedBytes(e,t){if(e===0)return 0;if(t<0||t>=this.effectiveBitLength)throw new Error(`[Ddu64 decode] Invalid padding bits: ${t}`);let r=this.usePowerOfTwo?1:2,s=Math.ceil(e/r)*this.effectiveBitLength-t;if(s<0)throw new Error("[Ddu64 decode] Invalid decoded bit length");return Math.ceil(s/Bt)}assertEncodedInputAligned(e){if(!this.usePowerOfTwo&&e.length%2!==0)throw new Error(`[Ddu64 decode] Invalid encoded length for variable charset. Expected multiple of 2, got ${e.length}`)}};var Z=class n{chars=[];constructor(){}static create(){return new n}static fromUnicodeRange(e,t){return new n().addUnicodeRange(e,t)}static fromString(e){return new n().addString(e)}static base64(){return new n().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")}static base32(){return new n().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567")}static uppercase(){return n.fromUnicodeRange(65,90)}static lowercase(){return n.fromUnicodeRange(97,122)}static digits(){return n.fromUnicodeRange(48,57)}static hangulJamo(){return new n().addUnicodeRange(4352,4370).addUnicodeRange(4449,4469).addUnicodeRange(4520,4546)}addUnicodeRange(e,t){for(let r=e;r<=t;r++)this.chars.push(String.fromCodePoint(r));return this}addString(e){return typeof e=="string"?this.chars.push(...e):this.chars.push(...e),this}add(...e){return this.chars.push(...e),this}excludeConfusing(){let e=new Set(["0","O","o","1","l","I","i","|","L"]);return this.chars=this.chars.filter(t=>!e.has(t)),this}exclude(...e){let t=new Set(e);return this.chars=this.chars.filter(r=>!t.has(r)),this}excludeUrlUnsafe(){let e=new Set(["+","/","=","?","&","#","%"," "]);return this.chars=this.chars.filter(t=>!e.has(t)),this}unique(){return this.chars=[...new Set(this.chars)],this}shuffle(e){let t=e!==void 0?this.seededRandom(e):Math.random;for(let r=this.chars.length-1;r>0;r--){let o=Math.floor(t()*(r+1));[this.chars[r],this.chars[o]]=[this.chars[o],this.chars[r]];}return this}seededRandom(e){let t=e|0||1;return ()=>(t^=t<<13,t^=t>>17,t^=t<<5,(t>>>0)/4294967296)}limit(e){return this.chars=this.chars.slice(0,e),this}limitToPowerOfTwo(){let e=this.chars.length;if(e===0)return this;let t=1<<Math.floor(Math.log2(e));return this.chars=this.chars.slice(0,t),this}sort(){return this.chars.sort(),this}reverse(){return this.chars.reverse(),this}get length(){return this.chars.length}buildString(){return this.chars.join("")}build(){return [...this.chars]}buildWithPadding(e){let t=[...this.chars],r=e;if(!r){let o=["=",".","_","-","~","!"];for(let s of o)if(!t.includes(s)){r=s;break}if(!r)throw new Error("Cannot find suitable padding character")}return {charset:t,padding:r}}};export{Z as CharsetBuilder,T as Ddu64,T as Ddu64Core,W as DduSetSymbol,rt as getWasmCodec,x as getWasmCodecSync,tt as preloadWasm};//# sourceMappingURL=core.js.map
5
+ `)||i.padding.includes("\r"))throw new Error("[Ddu64 normalizeCharSet] Newline and carriage return characters are reserved.");return {charSet:a.length===c?a:a.slice(0,c),padding:i.padding,isPredefined:i.isPredefined}}catch(a){if(e)throw a}}let o=H(t);return {charSet:o.charSet.slice(0,o.requiredLength),padding:o.padding,isPredefined:true}}function ie(n,e,t){for(let r of Ye){for(let o of n)if(o.includes(r)){let s=`[Ddu64 Constructor] URL-Safe mode conflict: charset character "${o}" contains "${r}".`;if(t)throw new Error(s);return false}if(e.includes(r)){let o=`[Ddu64 Constructor] URL-Safe mode conflict: padding character "${e}" contains "${r}".`;if(t)throw new Error(o);return false}}return true}function ae(n,e,t){if(t>256)return;let r=Math.min(n.length,t),o=n.slice(0,r),s=new Set;for(let a=0;a<o.length;a++)s.add(o[a]);s.add(e);for(let a=0;a<o.length;a++){let c=o[a];for(let h=0;h<o.length;h++){let f=c+o[h];if(s.has(f))throw new Error(`Combination conflict: "${c}" + "${o[h]}"`);s.add(f);}let l=c+e;if(s.has(l))throw new Error(`Combination conflict: "${c}" + padding`);s.add(l);let d=e+c;if(s.has(d))throw new Error(`Combination conflict: padding + "${c}"`);s.add(d);}let i=e+e;if(s.has(i))throw new Error("Combination conflict: double padding");s.add(i);}function qe(n,e){return e!==void 0?e?n>0:false:n>0&&(n&n-1)===0}function Ve(n){let e=k(n);if(!e)throw new Error(`CharSet with symbol ${n} not found`);return e}function H(n){let e=n?.dduSetSymbol??z.dduSetSymbol??"oneCharSet",t=k(e)??k("oneCharSet");if(!t)throw new Error("Critical: No fallback CharSet available");return {charSet:t.codaChar?D(t.charSet,t.codaChar):t.charSet,padding:t.paddingChar,requiredLength:t.maxRequiredLength,bitLength:t.bitLength,isPredefined:true,useRepeatPadding:t.useRepeatPadding}}function je(){let n=1;return typeof globalThis.navigator<"u"&&globalThis.navigator.hardwareConcurrency?n=globalThis.navigator.hardwareConcurrency:typeof globalThis.process<"u"&&globalThis.process.versions?.node&&(typeof globalThis.process.availableParallelism=="function"?n=globalThis.process.availableParallelism():n=4),Math.max(1,Math.min(64,n-1))}function Ge(){try{let{Worker:n}=_e("worker_threads"),e=new URL("./nodeWorker.js",import.meta.url).pathname,t=new n(e);return {postMessage(r){t.postMessage(r);},async terminate(){await t.terminate();},onMessage(r){t.on("message",r);},onError(r){t.on("error",r);}}}catch{return null}}function Ze(){try{if(typeof globalThis.Worker>"u")return null;let n=new URL("./webWorker.js",import.meta.url),e=new globalThis.Worker(n,{type:"module"});return {postMessage(t){e.postMessage(t);},async terminate(){e.terminate();},onMessage(t){e.addEventListener("message",r=>{t(r.data);});},onError(t){e.addEventListener("error",r=>{t(new Error(r.message||"Worker error"));});}}}catch{return null}}var $=class{poolSize;workers=[];pendingTasks=new Map;nextTaskId=0;roundRobinIndex=0;initialized=false;terminated=false;constructor(e){this.poolSize=e??je();}async encode(e,t){return await this.dispatch("encode",e,t)}async decode(e,t){return await this.dispatch("decode",e,t)}setPoolSize(e){if(!Number.isInteger(e))throw new Error(`[WorkerPool] Pool size must be an integer. Got: ${e}. Valid range: [1, 64]`);if(e<1||e>64)throw new Error(`[WorkerPool] Pool size must be between 1 and 64. Got: ${e}`);let t=this.poolSize;this.poolSize=e,this.initialized&&t!==e&&(this.terminateWorkers(),this.initialized=false);}async terminate(){this.terminated=true,await this.terminateWorkers();for(let[,e]of this.pendingTasks)e.reject(new Error("[WorkerPool] Pool terminated"));this.pendingTasks.clear();}async dispatch(e,t,r){if(this.terminated)throw new Error("[WorkerPool] Pool has been terminated");if(this.ensureInitialized(),this.workers.length===0)throw new Error("[WorkerPool] No workers available. Workers may not be supported in this runtime.");let o=this.nextTaskId++,s=this.roundRobinIndex%this.workers.length;this.roundRobinIndex=(this.roundRobinIndex+1)%this.workers.length;let i=this.workers[s];return new Promise((a,c)=>{this.pendingTasks.set(o,{resolve:a,reject:c});let l={id:o,type:e,data:t,config:r};i.postMessage(l);})}ensureInitialized(){if(this.initialized)return;let e=typeof globalThis.process<"u"&&!!globalThis.process.versions?.node;for(let t=0;t<this.poolSize;t++){let r=e?Ge():Ze();if(!r)break;r.onMessage(o=>{let s=this.pendingTasks.get(o.id);s&&(this.pendingTasks.delete(o.id),o.type==="error"?s.reject(new Error(o.error??"Worker error")):s.resolve(o.result));}),r.onError(o=>{console.error("[WorkerPool] Worker error:",o.message);}),this.workers.push(r);}this.initialized=true;}async terminateWorkers(){let e=this.workers.map(t=>t.terminate());await Promise.all(e),this.workers=[];}},F=null;function Xe(){return F||(F=new $),F}function ce(n){Xe().setPoolSize(n);}function le(n){if(n.length===0)throw new Error("[Ddu64 obfuscation] Alphabet must not be empty.");if(n.length>11172)throw new Error(`[Ddu64 obfuscation] Alphabet size (${n.length}) exceeds available Hangul syllables (11172).`);let e=Math.floor(11172/n.length),t=new Map;for(let r=0;r<n.length;r++)t.set(n[r],r);return {alphabet:n,syllablesPerChar:e,charToIndex:t}}function de(n,e,t){let r=44032+n*t.syllablesPerChar,o=e%t.syllablesPerChar;return r+o}function ue(n,e){if(n<44032||n>55203)return -1;let t=n-44032,r=Math.floor(t/e.syllablesPerChar);return r>=e.alphabet.length?-1:r}var L=class{config;constructor(e){this.config=le(e);}obfuscate(e){if(e.length===0)return "";let t=new Array(e.length);for(let r=0;r<e.length;r++){let o=e[r],s=this.config.charToIndex.get(o);if(s===void 0)throw new Error(`[Ddu64 obfuscation] Character "${o}" (U+${o.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase()}) not found in obfuscation alphabet.`);let i=de(s,r,this.config);t[r]=String.fromCharCode(i);}return t.join("")}deobfuscate(e){if(e.length===0)return "";let t=new Array(e.length);for(let r=0;r<e.length;r++){let o=e.charCodeAt(r),s=ue(o,this.config);if(s===-1)throw new Error(`[Ddu64 obfuscation] Invalid syllable at position ${r}: U+${o.toString(16).padStart(4,"0").toUpperCase()} is not in the mapped range.`);t[r]=this.config.alphabet[s];}return t.join("")}};var S=null,Y=false,A=false,w=null,q=class{exports;_ready=true;constructor(e){this.exports=e;}get ready(){return this._ready}encode(e,t){let{exports:r}=this;if(e.length===0)return {indices:new Uint16Array(0),paddingBits:0};let o=r.alloc(e.length);new Uint8Array(r.memory.buffer).set(e,o);let i=1<<t,a=1;try{let c=r.encode(o,e.length,t,i,a),l=r.get_result_ptr(),d=new Uint16Array(r.memory.buffer,l,c),h=new Uint16Array(c);return h.set(d),{indices:h,paddingBits:r.get_padding_bits()}}finally{r.dealloc(o,e.length);}}decode(e,t,r){let{exports:o}=this;if(e.length===0)return new Uint8Array(0);let s=e.length*2,i=o.alloc(s);new Uint16Array(o.memory.buffer,i,e.length).set(e);let c=1<<t,l=1;try{let d=o.decode(i,e.length,t,c,l,r);if(d===4294967295)throw new Error("[WasmCodec decode] Invalid index in input");let h=o.get_result_ptr(),f=new Uint8Array(o.memory.buffer,h,d),u=new Uint8Array(d);return u.set(f),u}finally{o.dealloc(i,s);}}};async function Qe(){try{if(typeof globalThis.process<"u"&&globalThis.process.versions?.node){let{readFile:n}=await import('fs/promises'),{fileURLToPath:e}=await import('url'),{dirname:t,join:r}=await import('path'),o=t(e(import.meta.url)),s=r(o,"wasm","codec.wasm");try{let i=await n(s);return i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)}catch{let i=r(o,"codec.wasm");try{let a=await n(i);return a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength)}catch{let a=r(o,"..","wasm","codec.wasm");try{let c=await n(a);return c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength)}catch{return null}}}}if(typeof fetch=="function"){let n=await fetch(new URL("./wasm/codec.wasm",import.meta.url));return n.ok?await n.arrayBuffer():null}return null}catch{return null}}async function Je(n){try{if(n.byteLength<16)return null;let e=new Uint8Array(n,0,4);if(e[0]!==0||e[1]!==97||e[2]!==115||e[3]!==109)return null;let t;try{t=await WebAssembly.compile(n);}catch{return null}let o=(await WebAssembly.instantiate(t,{})).exports;return typeof o.alloc!="function"||typeof o.dealloc!="function"||typeof o.encode!="function"||typeof o.decode!="function"||typeof o.get_result_ptr!="function"||typeof o.get_result_len!="function"||typeof o.get_padding_bits!="function"||!o.memory?null:o}catch{return null}}async function he(){try{if(S)return !0;if(A)return !1;let n=await Qe();if(!n)return A=!0,!1;let e=await Je(n);return e?(S=new q(e),!0):(A=!0,!1)}catch{return A=true,false}}function et(n,e){let t;return {promise:new Promise((s,i)=>{t=setTimeout(()=>i(new Error(e)),n);}),clear:()=>clearTimeout(t)}}async function tt(){if(S)return;if(w)return w;let n=et(1e4,"[Ddu64 wasm] WASM initialization timed out (10s)"),e=async()=>{try{if(!await he())throw new Error("[Ddu64 wasm] WASM initialization failed")}finally{n.clear();}};return w=Promise.race([e(),n.promise]).finally(()=>{w=null,Y=true;}),w}function rt(){if(S)return S;if(A)return null;if(!Y&&!w){Y=true;let n;w=new Promise(e=>{n=setTimeout(()=>{A=true,e();},5e3),he().then(t=>{t||(A=true);}).catch(()=>{A=true;}).finally(()=>{n!==void 0&&clearTimeout(n),e();});}).finally(()=>{w=null;});}return null}function x(){return S}function fe(n){if(!Number.isFinite(n))throw new Error(`[Ddu64 config] wasmThreshold must be a finite number, got ${n}`);return Math.max(1024,Math.min(1048576,Math.round(n)))}var Bt=8,Pt=64*1024*1024,Dt=64*1024*1024,G="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",xe="=",Ut=Object.fromEntries([...G].map((n,e)=>[n,e])),T=class{dduChar;paddingChar;bitLength;usePowerOfTwo;effectiveBitLength;dduBinaryLookup=new Map;isPredefinedCharSet;defaultCompress;defaultMaxDecodedBytes;defaultMaxDecompressedBytes;urlSafe;encryptionKey;keyDerivation;encryptionKeyHash;defaultChecksum;defaultChunkSize;defaultChunkSeparator;defaultCompressionLevel;defaultCompressionAlgorithm;useRepeatPadding;bitPackConfig;wasmThreshold;canUseNativeBase64;nativeDecodeMap;adapter;defaultObfuscate;_obfuscationLayer;constructor(e,t,r){e!=null&&typeof e=="object"&&!Array.isArray(e)&&(r=e,e=void 0,t=void 0);let o=r?.throwOnError??r?.useBuildErrorReturn??false;r?.adapter?this.adapter=r.adapter:this.adapter=void 0;let s=oe(e,t,r,o),i=se(s,o,r);this.dduChar=i.charSet,this.paddingChar=i.padding,this.isPredefinedCharSet=i.isPredefined,this.defaultCompress=r?.compress??false,this.defaultMaxDecodedBytes=this.normalizeLimit(r?.maxDecodedBytes,Pt,o,"maxDecodedBytes"),this.defaultMaxDecompressedBytes=this.normalizeLimit(r?.maxDecompressedBytes,Dt,o,"maxDecompressedBytes");let a=this.dduChar.length;this.usePowerOfTwo=a>0&&(a&a-1)===0;let c=Math.ceil(Math.log2(a));this.bitLength=this.usePowerOfTwo?Math.floor(Math.log2(a)):c,this.effectiveBitLength=this.usePowerOfTwo?this.bitLength:c;for(let d=0;d<a;d++)this.dduBinaryLookup.set(this.dduChar[d],d);this.isPredefinedCharSet||ae(this.dduChar,this.paddingChar,a);let l=r?.urlSafe??false;if(this.urlSafe=l?ie(this.dduChar,this.paddingChar,o):false,this.encryptionKey=r?.encryptionKey,this.keyDerivation=r?.keyDerivation,this.encryptionKey&&this.adapter?.deriveKeySync&&(this.encryptionKeyHash=this.adapter.deriveKeySync(this.encryptionKey,this.keyDerivation)),this.defaultChecksum=r?.checksum??false,this.defaultChunkSize=r?.chunkSize,this.defaultChunkSeparator=r?.chunkSeparator??`
6
+ `,this.defaultCompressionAlgorithm=r?.compressionAlgorithm??"deflate",this.defaultCompressionLevel=U(r?.compressionLevel,this.defaultCompressionAlgorithm),this.useRepeatPadding=r?.useRepeatPadding??s.useRepeatPadding??false,this.defaultObfuscate=r?.obfuscate??false,this.defaultObfuscate&&!this.encryptionKey)throw new Error("[Ddu64 obfuscation] Obfuscation requires encryption to be enabled.");if(this.bitPackConfig=ee(a),this.wasmThreshold=fe(r?.wasmThreshold??4096),this.canUseNativeBase64=this.usePowerOfTwo&&this.dduChar.length===64,this.canUseNativeBase64){this.nativeDecodeMap=new Map;for(let d=0;d<G.length;d++){let h=this.dduChar[d];this.nativeDecodeMap.set(h,G[d]);}}}encode(e,t){return this.encodeInternal(e,t).encoded}decode(e,t){let r=this.decodeToUint8Array(e,t);return K(r)}decodeToUint8Array(e,t){let r=t?.checksum??this.defaultChecksum,o=t?.compress!==false,s=t?.encrypt!==false,i=e;this.reportProgress(t,{processedBytes:0,totalBytes:e.length,percent:0,stage:"start"});let a=t?.chunkSeparator??this.defaultChunkSeparator;i=N(i,a),this.urlSafe&&(i=O(i));let c=null;if(r){let y=M(i);c=y.checksum,i=y.data;}this.shouldObfuscate(t)&&(i=this.getObfuscationLayer().deobfuscate(i));let{cleanedInput:l,paddingBits:d,compressionAlgorithm:h,isEncrypted:f,pipelineVersion:u}=I(i,this.paddingChar,this.effectiveBitLength);if(f&&s&&!this.encryptionKey)throw new Error("[Ddu64 decode] Encrypted payload requires an encryptionKey");this.assertEncodedInputAligned(l);let p=this.normalizeLimit(t?.maxDecodedBytes,this.defaultMaxDecodedBytes,true,"maxDecodedBytes"),g=this.estimateDecodedBytes(l.length,d);if(g>p)throw new Error(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${g} bytes, Limit: ${p} bytes`);this.reportProgress(t,{processedBytes:l.length,totalBytes:e.length,percent:30,stage:"decode"});let m=this.decodeChars(l,d);if(u===3&&f&&this.encryptionKey&&s&&(this.reportProgress(t,{processedBytes:m.length,totalBytes:m.length,percent:55,stage:"decrypt"}),m=this.decryptSync(m)),h&&o&&(u===2||!f||s)){let y=this.normalizeLimit(t?.maxDecompressedBytes,this.defaultMaxDecompressedBytes,true,"maxDecompressedBytes");this.reportProgress(t,{processedBytes:m.length,totalBytes:m.length,percent:70,stage:"decompress"}),m=this.decompressSync(m,h,y);}if(c&&(u===2||!f||s)){this.reportProgress(t,{processedBytes:m.length,totalBytes:m.length,percent:85,stage:"checksum"});let y=B(m);if(y!==c)throw new Error(`[Ddu64 decode] Checksum mismatch. Expected: ${c}, Got: ${y}`)}return u===2&&f&&this.encryptionKey&&s&&(this.reportProgress(t,{processedBytes:m.length,totalBytes:m.length,percent:90,stage:"decrypt"}),m=this.decryptSync(m)),this.reportProgress(t,{processedBytes:m.length,totalBytes:m.length,percent:100,stage:"done"}),m}async encodeAsync(e,t){let r=await this.getAdapterAsync(),o=t?.compress??this.defaultCompress,s=t?.checksum??this.defaultChecksum,i=(t?.encrypt??true)&&!!this.encryptionKey,a=t?.chunkSize??this.defaultChunkSize,c=t?.chunkSeparator??this.defaultChunkSeparator,l=typeof e=="string"?v(e):e;this.reportProgress(t,{processedBytes:0,totalBytes:l.length,percent:0,stage:"start"});let d="";s&&(d=B(l));let h;if(o){let p=t?.compressionAlgorithm??this.defaultCompressionAlgorithm,g=U(t?.compressionLevel??this.defaultCompressionLevel,p);this.reportProgress(t,{processedBytes:l.length,totalBytes:l.length,percent:20,stage:"compress"});let m;if(p==="brotli"){if(!r.brotliCompress)throw new Error("[Ddu64 compress] Brotli compression is unavailable in the current runtime.");m=await r.brotliCompress(l,g);}else m=await r.deflate(l,g);m.length<l.length&&(l=m,h=p);}let f=false;if(i){let p=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:l.length,totalBytes:l.length,percent:45,stage:"encrypt"}),l=await r.encrypt(l,p),f=true;}this.reportProgress(t,{processedBytes:l.length,totalBytes:l.length,percent:70,stage:"encode"});let u=this.encodeBytes(l,h,f,t);return u=this.applyPostEncoding(u,t,d,s,a,c),this.reportProgress(t,{processedBytes:l.length,totalBytes:l.length,percent:100,stage:"done"}),u}async decodeAsync(e,t){let r=await this.decodeToUint8ArrayAsync(e,t);return K(r)}async decodeToUint8ArrayAsync(e,t){let r=await this.getAdapterAsync(),o=t?.checksum??this.defaultChecksum,s=t?.compress!==false,i=t?.encrypt!==false,a=e;this.reportProgress(t,{processedBytes:0,totalBytes:e.length,percent:0,stage:"start"});let c=t?.chunkSeparator??this.defaultChunkSeparator;a=N(a,c),this.urlSafe&&(a=O(a));let l=null;if(o){let b=M(a);l=b.checksum,a=b.data;}this.shouldObfuscate(t)&&(a=this.getObfuscationLayer().deobfuscate(a));let{cleanedInput:d,paddingBits:h,compressionAlgorithm:f,isEncrypted:u,pipelineVersion:p}=I(a,this.paddingChar,this.effectiveBitLength);if(u&&i&&!this.encryptionKey)throw new Error("[Ddu64 decode] Encrypted payload requires an encryptionKey");this.assertEncodedInputAligned(d);let g=this.normalizeLimit(t?.maxDecodedBytes,this.defaultMaxDecodedBytes,true,"maxDecodedBytes"),m=this.estimateDecodedBytes(d.length,h);if(m>g)throw new Error(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${m} bytes, Limit: ${g} bytes`);this.reportProgress(t,{processedBytes:d.length,totalBytes:e.length,percent:30,stage:"decode"});let y=this.decodeChars(d,h);if(p===3&&u&&this.encryptionKey&&i){let b=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:55,stage:"decrypt"}),y=await r.decrypt(y,b);}if(f&&s&&(p===2||!u||i)){let b=this.normalizeLimit(t?.maxDecompressedBytes,this.defaultMaxDecompressedBytes,true,"maxDecompressedBytes");if(f==="brotli"){if(!r.brotliDecompress)throw new Error("[Ddu64 decompress] Brotli decompression is unavailable in the current runtime.");this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:70,stage:"decompress"}),y=await r.brotliDecompress(y,b);}else this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:70,stage:"decompress"}),y=await r.inflate(y,b);}if(l&&(p===2||!u||i)){this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:85,stage:"checksum"});let b=B(y);if(b!==l)throw new Error(`[Ddu64 decode] Checksum mismatch. Expected: ${l}, Got: ${b}`)}if(p===2&&u&&this.encryptionKey&&i){let b=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:90,stage:"decrypt"}),y=await r.decrypt(y,b);}return this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:100,stage:"done"}),y}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,defaultChunkSize:this.defaultChunkSize,defaultChunkSeparator:this.defaultChunkSeparator,defaultCompressionLevel:this.defaultCompressionLevel,defaultCompressionAlgorithm:this.defaultCompressionAlgorithm}}getStats(e,t){let o=(typeof e=="string"?v(e):e).length,{encoded:s,compressedSize:i}=this.encodeInternal(e,t),a=s.length,c=o>0?a/o:0,d=(t?.compress??this.defaultCompress)&&i!==void 0&&o>0?i/o:void 0;return {originalSize:o,encodedSize:a,compressedSize:i,compressionRatio:d,expansionRatio:c,charsetSize:this.dduChar.length,bitLength:this.bitLength}}static setWorkerPoolSize(e){ce(e);}encodeInternal(e,t){let r=t?.compress??this.defaultCompress,o=t?.checksum??this.defaultChecksum,s=(t?.encrypt??true)&&!!this.encryptionKey,i=t?.chunkSize??this.defaultChunkSize,a=t?.chunkSeparator??this.defaultChunkSeparator,c=typeof e=="string"?v(e):e;this.reportProgress(t,{processedBytes:0,totalBytes:c.length,percent:0,stage:"start"});let l="";o&&(l=B(c));let d,h;if(r){let p=t?.compressionAlgorithm??this.defaultCompressionAlgorithm,g=U(t?.compressionLevel??this.defaultCompressionLevel,p);this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:20,stage:"compress"});let m=this.compressSync(c,p,g);h=m.length,m.length<c.length&&(c=m,d=p);}let f=false;s&&(this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:45,stage:"encrypt"}),c=this.encryptSync(c),f=true),this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:70,stage:"encode"});let u=this.encodeBytes(c,d,f,t);return u=this.applyPostEncoding(u,t,l,o,i,a),this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:100,stage:"done"}),{encoded:u,compressedSize:h}}applyPostEncoding(e,t,r,o,s,i){let a=e;return this.shouldObfuscate(t)&&(a=this.getObfuscationLayer().obfuscate(a)),o&&r&&(a=a+"CHK"+r),this.urlSafe&&(a=re(a)),s&&s>0&&(a=ne(a,s,i)),a}encodeBytes(e,t,r,o){if(e.length===0)return "";let s=this.encodeBytesWithNativeBase64(e),i,a;if(s)i=s.indices,a=s.paddingBits;else {let d=this.shouldUseWasm(e.length)?x():null;if(d?.ready&&this.usePowerOfTwo){let h=d.encode(e,this.bitLength);i=h.indices,a=h.paddingBits;}else {let h=Q(e,this.bitPackConfig);i=h.indices,a=h.paddingBits;}}let c=new Array(i.length);for(let d=0;d<i.length;d++)c[d]=this.dduChar[i[d]];let l=o?.omitFooter?"":te({paddingBits:a,compressionAlgorithm:t,isEncrypted:!!r,paddingChar:this.paddingChar,useRepeatPadding:this.useRepeatPadding&&!t&&!r,pipelineVersion:r?3:2});return c.join("")+l}decodeChars(e,t){let r=e.length;if(r===0)return new Uint8Array(0);let o=this.decodeCharsWithNativeBase64(e,t);if(o)return o;let s=r>=this.wasmThreshold||r>=4096?new Uint16Array(r):new Array(r);for(let a=0;a<r;a++){let c=e[a],l=this.dduBinaryLookup.get(c);if(l===void 0)throw new Error(`[Ddu64 decode] Invalid character "${c}" at ${a}`);s[a]=l;}let i=this.shouldUseWasm(r)?x():null;if(i?.ready&&this.usePowerOfTwo){let a=s instanceof Uint16Array?s:Uint16Array.from(s);return i.decode(a,this.bitLength,t)}return J(s,t,this.bitPackConfig)}encodeBytesWithNativeBase64(e){if(!this.canUseNativeBase64)return null;let t=this.bytesToBase64(e);if(t===null)return null;let r=0,o=t.length;for(;o>0&&t[o-1]===xe;)r++,o--;let s=o>=4096?new Uint16Array(o):new Array(o);for(let i=0;i<o;i++)s[i]=Ut[t[i]];return {indices:s,paddingBits:r===2?4:r===1?2:0}}decodeCharsWithNativeBase64(e,t){if(!this.canUseNativeBase64||!this.nativeDecodeMap)return null;let r=t===4?2:t===2?1:t===0?0:-1;if(r<0)return null;let o=new Array(e.length+r);for(let s=0;s<e.length;s++){let i=this.nativeDecodeMap.get(e[s]);if(i===void 0)return null;o[s]=i;}for(let s=0;s<r;s++)o[e.length+s]=xe;return this.base64ToBytes(o.join(""))}bytesToBase64(e){let t=e.toBase64;if(typeof t=="function")return t.call(e);let r=globalThis.Buffer;return r?.from?r.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"):null}base64ToBytes(e){let t=Uint8Array;if(typeof t.fromBase64=="function")return t.fromBase64(e);let r=globalThis.Buffer;if(r?.from){let o=r.from(e,"base64");return new Uint8Array(o.buffer,o.byteOffset,o.byteLength)}return null}shouldUseWasm(e){return e>=this.wasmThreshold}reportProgress(e,t){e?.onProgress?.(t);}requireSyncAdapter(){if(!this.adapter)throw new Error("[Ddu64 adapter] No platform adapter available. Use encodeAsync()/decodeAsync() in browser environments, or provide an adapter via options.adapter.");return this.adapter}encryptSync(e){let t=this.requireSyncAdapter();if(!t.encryptSync)throw new Error("[Ddu64 encrypt] Sync encryption unavailable. Use encodeAsync() in browser environments.");if(!this.encryptionKeyHash){if(!t.deriveKeySync)throw new Error("[Ddu64 encrypt] Sync key derivation unavailable. Use encodeAsync() in browser environments.");this.encryptionKeyHash=t.deriveKeySync(this.encryptionKey,this.keyDerivation);}return t.encryptSync(e,this.encryptionKeyHash)}decryptSync(e){let t=this.requireSyncAdapter();if(!t.decryptSync)throw new Error("[Ddu64 decrypt] Sync decryption unavailable. Use decodeAsync() in browser environments.");if(!this.encryptionKeyHash){if(!t.deriveKeySync)throw new Error("[Ddu64 decrypt] Sync key derivation unavailable. Use decodeAsync() in browser environments.");this.encryptionKeyHash=t.deriveKeySync(this.encryptionKey,this.keyDerivation);}return t.decryptSync(e,this.encryptionKeyHash)}compressSync(e,t,r){let o=this.requireSyncAdapter();if(t==="brotli"){if(!o.brotliCompressSync)throw new Error("[Ddu64 compress] Brotli compression is unavailable in the current runtime.");return o.brotliCompressSync(e,r)}if(!o.deflateSync)throw new Error("[Ddu64 compress] Sync compression unavailable. Use encodeAsync() in browser environments.");return o.deflateSync(e,r)}decompressSync(e,t,r){let o=this.requireSyncAdapter();if(t==="brotli"){if(!o.brotliDecompressSync)throw new Error("[Ddu64 decompress] Brotli decompression is unavailable in the current runtime.");return o.brotliDecompressSync(e,r)}if(!o.inflateSync)throw new Error("[Ddu64 decompress] Sync decompression unavailable. Use decodeAsync() in browser environments.");return o.inflateSync(e,r)}async getAdapterAsync(){if(this.adapter)return this.adapter;let{getAdapter:e}=await Promise.resolve().then(()=>(Le(),ke));return this.adapter=await e(),this.adapter}async getKeyHashAsync(e){return this.encryptionKeyHash?this.encryptionKeyHash:(this.encryptionKeyHash=await e.deriveKey(this.encryptionKey,this.keyDerivation),this.encryptionKeyHash)}getObfuscationLayer(){if(!this._obfuscationLayer){let e=new Set(this.dduChar);e.add(this.paddingChar);let t="ELYSIAGRONCV01234567";for(let o of t)e.add(o);let r=[...e];this._obfuscationLayer=new L(r);}return this._obfuscationLayer}shouldObfuscate(e){let t=e?.obfuscate??this.defaultObfuscate;if(t&&!this.encryptionKey)throw new Error("[Ddu64 obfuscation] Obfuscation requires encryption to be enabled.");return t}normalizeLimit(e,t,r,o){if(e===void 0)return t;if(e===Number.POSITIVE_INFINITY)return Number.POSITIVE_INFINITY;if(!Number.isFinite(e)||e<=0){if(r)throw new Error(`[Ddu64 options] Invalid ${o}. Must be a positive finite number or Infinity.`);return t}return Math.floor(e)}estimateDecodedBytes(e,t){if(e===0)return 0;if(t<0||t>=this.effectiveBitLength)throw new Error(`[Ddu64 decode] Invalid padding bits: ${t}`);let r=this.usePowerOfTwo?1:2,s=Math.ceil(e/r)*this.effectiveBitLength-t;if(s<0)throw new Error("[Ddu64 decode] Invalid decoded bit length");return Math.ceil(s/Bt)}assertEncodedInputAligned(e){if(!this.usePowerOfTwo&&e.length%2!==0)throw new Error(`[Ddu64 decode] Invalid encoded length for variable charset. Expected multiple of 2, got ${e.length}`)}};var Z=class n{chars=[];constructor(){}static create(){return new n}static fromUnicodeRange(e,t){return new n().addUnicodeRange(e,t)}static fromString(e){return new n().addString(e)}static base64(){return new n().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")}static base32(){return new n().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567")}static uppercase(){return n.fromUnicodeRange(65,90)}static lowercase(){return n.fromUnicodeRange(97,122)}static digits(){return n.fromUnicodeRange(48,57)}static hangulJamo(){return new n().addUnicodeRange(4352,4370).addUnicodeRange(4449,4469).addUnicodeRange(4520,4546)}addUnicodeRange(e,t){for(let r=e;r<=t;r++)this.chars.push(String.fromCodePoint(r));return this}addString(e){return typeof e=="string"?this.chars.push(...e):this.chars.push(...e),this}add(...e){return this.chars.push(...e),this}excludeConfusing(){let e=new Set(["0","O","o","1","l","I","i","|","L"]);return this.chars=this.chars.filter(t=>!e.has(t)),this}exclude(...e){let t=new Set(e);return this.chars=this.chars.filter(r=>!t.has(r)),this}excludeUrlUnsafe(){let e=new Set(["+","/","=","?","&","#","%"," "]);return this.chars=this.chars.filter(t=>!e.has(t)),this}unique(){return this.chars=[...new Set(this.chars)],this}shuffle(e){let t=e!==void 0?this.seededRandom(e):Math.random;for(let r=this.chars.length-1;r>0;r--){let o=Math.floor(t()*(r+1));[this.chars[r],this.chars[o]]=[this.chars[o],this.chars[r]];}return this}seededRandom(e){let t=e|0||1;return ()=>(t^=t<<13,t^=t>>17,t^=t<<5,(t>>>0)/4294967296)}limit(e){return this.chars=this.chars.slice(0,e),this}limitToPowerOfTwo(){let e=this.chars.length;if(e===0)return this;let t=1<<Math.floor(Math.log2(e));return this.chars=this.chars.slice(0,t),this}sort(){return this.chars.sort(),this}reverse(){return this.chars.reverse(),this}get length(){return this.chars.length}buildString(){return this.chars.join("")}build(){return [...this.chars]}buildWithPadding(e){let t=[...this.chars],r=e;if(!r){let o=["=",".","_","-","~","!"];for(let s of o)if(!t.includes(s)){r=s;break}if(!r)throw new Error("Cannot find suitable padding character")}return {charset:t,padding:r}}};export{Z as CharsetBuilder,T as Ddu64,T as Ddu64Core,W as DduSetSymbol,rt as getWasmCodec,x as getWasmCodecSync,tt as preloadWasm};//# sourceMappingURL=core.js.map
7
7
  //# sourceMappingURL=core.js.map
package/dist/index.cjs CHANGED
@@ -2,6 +2,6 @@
2
2
  `&&e!==`\r
3
3
  `&&e!=="\r"?e:"";return r.length>0&&t.includes(r)&&(t=t.replaceAll(r,"")),t}var $e={"":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 qe(n,e){let t=n.charCodeAt(0);if(t<44032||t>55203)return n;let r=t-(t-44032)%28,o=$e[e]??0;return String.fromCharCode(r+o)}function T(n,e){let t=new Array(n.length*e.length),r=0;for(let o of n)for(let s of e)t[r++]=qe(o,s);return t}function R(n,e){let r=n===void 0||!Number.isFinite(n)?6:Math.floor(n);return Math.min(e==="brotli"?11:9,Math.max(0,r))}var Ye=new TextEncoder,Ve=new TextDecoder;function _(n){return Ye.encode(n)}function V(n){return Ve.decode(n)}var j=(r=>(r.DDU="ddu",r.DDU_V1="ddu_v1",r.ONECHARSET="oneCharSet",r))(j||{}),G={dduSetSymbol:"ddu",usePowerOfTwo:true,requiredLength:64,bitLength:6};var je={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},Ge={symbol:"ddu_v1",charSet:["\uB70C","\uB568","\uC774","\uC6B0","\uC57C","!","?","."],maxRequiredLength:8,bitLength:3,paddingChar:"\uBB50",useRepeatPadding:true},Ze={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 I(n){switch(n){case "ddu":return je;case "ddu_v1":return Ge;case "oneCharSet":return Ze;default:return}}var Xe=65536,Qe=["-","_","."];function me(n,e,t,r){let o=(s,i,a,c,d)=>{if(Je(a,t?.usePowerOfTwo)&&a>0){let f=Math.floor(Math.log2(a)),u=1<<f;return {charSet:s.length===u?s:s.slice(0,u),padding:i,requiredLength:u,bitLength:f,isPredefined:c,useRepeatPadding:d}}return {charSet:s.length===a?s:s.slice(0,a),padding:i,requiredLength:a,bitLength:a>0?Math.ceil(Math.log2(a)):0,isPredefined:c,useRepeatPadding:d}};try{let s=n??t?.dduChar,i=e??t?.paddingChar;if(s){if(!i)throw new Error("[Ddu64 Constructor] paddingChar is required when dduChar is provided.");let l=typeof s=="string"?[...s]:[...s],h=t?.codaChar,f=h?!0:t?.useRepeatPadding??!1;if(h&&h.length>0&&(l=T(l,h)),r&&new Set(l).size!==l.length){let g=l.filter((p,y)=>l.indexOf(p)!==y);throw new Error(`[Ddu64 Constructor] Character set contains duplicate characters: [${[...new Set(g)].join(", ")}]`)}let u=t?.requiredLength??l.length;if(l.length<u)throw new Error("[Ddu64 Constructor] Insufficient characters.");return o(l,i,u,!1,f)}let a=t?.dduSetSymbol??G.dduSetSymbol??"ddu",c=et(a),d=c.codaChar?T(c.charSet,c.codaChar):c.charSet;return o(d,c.paddingChar,c.maxRequiredLength,!0,c.useRepeatPadding)}catch(s){if(r)throw s;return Z(t)}}function pe(n,e,t){let r=[n,null];for(let s of r){let i=s?{...s}:Z(t);try{let a=i.charSet,c=i.requiredLength,d=Array.from(new Set(a));if(d.length!==a.length){if(e){let f=a.filter((u,m)=>a.indexOf(u)!==m);throw new Error(`[Ddu64 normalizeCharSet] Character set contains duplicate characters: [${[...new Set(f)].join(", ")}]`)}a=d,i.isPredefined||(c=a.length);}if(a.length<c)throw new Error(`[Ddu64 normalizeCharSet] Insufficient characters. Required: ${c}, Has: ${a.length}`);if(c<2)throw new Error("[Ddu64 normalizeCharSet] At least 2 unique characters required.");if(a.length===0)throw new Error("[Ddu64 normalizeCharSet] Empty charset.");if(a.find(f=>f.length!==1)){if(e)throw new Error("[Ddu64 normalizeCharSet] Multi-character symbols are not supported.");continue}if(a.length>Xe){if(e)throw new Error("[Ddu64 normalizeCharSet] Charset size exceeds maximum supported size of 65536.");continue}if(i.padding.length!==1)throw new Error(`[Ddu64 normalizeCharSet] Padding length mismatch. Expected 1, got ${i.padding.length}`);if(a.includes(i.padding)){if(e)throw new Error(`[Ddu64 normalizeCharSet] Padding character "${i.padding}" conflicts with charset.`);a=a.filter(f=>f!==i.padding);}for(let f of a)if(f.includes(`
4
4
  `)||f.includes("\r"))throw new Error("[Ddu64 normalizeCharSet] Newline and carriage return characters are reserved.");if(i.padding.includes(`
5
- `)||i.padding.includes("\r"))throw new Error("[Ddu64 normalizeCharSet] Newline and carriage return characters are reserved.");return {charSet:a.length===c?a:a.slice(0,c),padding:i.padding,isPredefined:i.isPredefined}}catch(a){if(e)throw a}}let o=Z(t);return {charSet:o.charSet.slice(0,o.requiredLength),padding:o.padding,isPredefined:true}}function ye(n,e,t){for(let r of Qe){for(let o of n)if(o.includes(r)){let s=`[Ddu64 Constructor] URL-Safe mode conflict: charset character "${o}" contains "${r}".`;if(t)throw new Error(s);return false}if(e.includes(r)){let o=`[Ddu64 Constructor] URL-Safe mode conflict: padding character "${e}" contains "${r}".`;if(t)throw new Error(o);return false}}return true}function ge(n,e,t){if(t>256)return;let r=Math.min(n.length,t),o=n.slice(0,r),s=new Set;for(let a=0;a<o.length;a++)s.add(o[a]);s.add(e);for(let a=0;a<o.length;a++){let c=o[a];for(let h=0;h<o.length;h++){let f=c+o[h];if(s.has(f))throw new Error(`Combination conflict: "${c}" + "${o[h]}"`);s.add(f);}let d=c+e;if(s.has(d))throw new Error(`Combination conflict: "${c}" + padding`);s.add(d);let l=e+c;if(s.has(l))throw new Error(`Combination conflict: padding + "${c}"`);s.add(l);}let i=e+e;if(s.has(i))throw new Error("Combination conflict: double padding");s.add(i);}function Je(n,e){return e!==void 0?e?n>0:false:n>0&&(n&n-1)===0}function et(n){let e=I(n);if(!e)throw new Error(`CharSet with symbol ${n} not found`);return e}function Z(n){let e=n?.dduSetSymbol??G.dduSetSymbol??"oneCharSet",t=I(e)??I("oneCharSet");if(!t)throw new Error("Critical: No fallback CharSet available");return {charSet:t.codaChar?T(t.charSet,t.codaChar):t.charSet,padding:t.paddingChar,requiredLength:t.maxRequiredLength,bitLength:t.bitLength,isPredefined:true,useRepeatPadding:t.useRepeatPadding}}function tt(){let n=1;return typeof globalThis.navigator<"u"&&globalThis.navigator.hardwareConcurrency?n=globalThis.navigator.hardwareConcurrency:typeof globalThis.process<"u"&&globalThis.process.versions?.node&&(typeof globalThis.process.availableParallelism=="function"?n=globalThis.process.availableParallelism():n=4),Math.max(1,Math.min(64,n-1))}function rt(){try{let{Worker:n}=We("worker_threads"),e=new URL("./nodeWorker.js",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname,t=new n(e);return {postMessage(r){t.postMessage(r);},async terminate(){await t.terminate();},onMessage(r){t.on("message",r);},onError(r){t.on("error",r);}}}catch{return null}}function nt(){try{if(typeof globalThis.Worker>"u")return null;let n=new URL("./webWorker.js",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),e=new globalThis.Worker(n,{type:"module"});return {postMessage(t){e.postMessage(t);},async terminate(){e.terminate();},onMessage(t){e.addEventListener("message",r=>{t(r.data);});},onError(t){e.addEventListener("error",r=>{t(new Error(r.message||"Worker error"));});}}}catch{return null}}var Q=class{poolSize;workers=[];pendingTasks=new Map;nextTaskId=0;roundRobinIndex=0;initialized=false;terminated=false;constructor(e){this.poolSize=e??tt();}async encode(e,t){return await this.dispatch("encode",e,t)}async decode(e,t){return await this.dispatch("decode",e,t)}setPoolSize(e){if(!Number.isInteger(e))throw new Error(`[WorkerPool] Pool size must be an integer. Got: ${e}. Valid range: [1, 64]`);if(e<1||e>64)throw new Error(`[WorkerPool] Pool size must be between 1 and 64. Got: ${e}`);let t=this.poolSize;this.poolSize=e,this.initialized&&t!==e&&(this.terminateWorkers(),this.initialized=false);}async terminate(){this.terminated=true,await this.terminateWorkers();for(let[,e]of this.pendingTasks)e.reject(new Error("[WorkerPool] Pool terminated"));this.pendingTasks.clear();}async dispatch(e,t,r){if(this.terminated)throw new Error("[WorkerPool] Pool has been terminated");if(this.ensureInitialized(),this.workers.length===0)throw new Error("[WorkerPool] No workers available. Workers may not be supported in this runtime.");let o=this.nextTaskId++,s=this.roundRobinIndex%this.workers.length;this.roundRobinIndex=(this.roundRobinIndex+1)%this.workers.length;let i=this.workers[s];return new Promise((a,c)=>{this.pendingTasks.set(o,{resolve:a,reject:c});let d={id:o,type:e,data:t,config:r};i.postMessage(d);})}ensureInitialized(){if(this.initialized)return;let e=typeof globalThis.process<"u"&&!!globalThis.process.versions?.node;for(let t=0;t<this.poolSize;t++){let r=e?rt():nt();if(!r)break;r.onMessage(o=>{let s=this.pendingTasks.get(o.id);s&&(this.pendingTasks.delete(o.id),o.type==="error"?s.reject(new Error(o.error??"Worker error")):s.resolve(o.result));}),r.onError(o=>{console.error("[WorkerPool] Worker error:",o.message);}),this.workers.push(r);}this.initialized=true;}async terminateWorkers(){let e=this.workers.map(t=>t.terminate());await Promise.all(e),this.workers=[];}},X=null;function ot(){return X||(X=new Q),X}function J(n){ot().setPoolSize(n);}function be(n){if(n.length===0)throw new Error("[Ddu64 obfuscation] Alphabet must not be empty.");if(n.length>11172)throw new Error(`[Ddu64 obfuscation] Alphabet size (${n.length}) exceeds available Hangul syllables (11172).`);let e=Math.floor(11172/n.length),t=new Map;for(let r=0;r<n.length;r++)t.set(n[r],r);return {alphabet:n,syllablesPerChar:e,charToIndex:t}}function we(n,e,t){let r=44032+n*t.syllablesPerChar,o=e%t.syllablesPerChar;return r+o}function Ae(n,e){if(n<44032||n>55203)return -1;let t=n-44032,r=Math.floor(t/e.syllablesPerChar);return r>=e.alphabet.length?-1:r}var C=class{config;constructor(e){this.config=be(e);}obfuscate(e){if(e.length===0)return "";let t=new Array(e.length);for(let r=0;r<e.length;r++){let o=e[r],s=this.config.charToIndex.get(o);if(s===void 0)throw new Error(`[Ddu64 obfuscation] Character "${o}" (U+${o.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase()}) not found in obfuscation alphabet.`);let i=we(s,r,this.config);t[r]=String.fromCharCode(i);}return t.join("")}deobfuscate(e){if(e.length===0)return "";let t=new Array(e.length);for(let r=0;r<e.length;r++){let o=e.charCodeAt(r),s=Ae(o,this.config);if(s===-1)throw new Error(`[Ddu64 obfuscation] Invalid syllable at position ${r}: U+${o.toString(16).padStart(4,"0").toUpperCase()} is not in the mapped range.`);t[r]=this.config.alphabet[s];}return t.join("")}};function st(n,e){let t=new Set(n);t.add(e);let r=[...t];return new C(r)}var E=null,ee=false,A=false,w=null,te=class{exports;_ready=true;constructor(e){this.exports=e;}get ready(){return this._ready}encode(e,t){let{exports:r}=this;if(e.length===0)return {indices:new Uint16Array(0),paddingBits:0};let o=r.alloc(e.length);new Uint8Array(r.memory.buffer).set(e,o);let i=1<<t,a=1;try{let c=r.encode(o,e.length,t,i,a),d=r.get_result_ptr(),l=new Uint16Array(r.memory.buffer,d,c),h=new Uint16Array(c);return h.set(l),{indices:h,paddingBits:r.get_padding_bits()}}finally{r.dealloc(o,e.length);}}decode(e,t,r){let{exports:o}=this;if(e.length===0)return new Uint8Array(0);let s=e.length*2,i=o.alloc(s);new Uint16Array(o.memory.buffer,i,e.length).set(e);let c=1<<t,d=1;try{let l=o.decode(i,e.length,t,c,d,r);if(l===4294967295)throw new Error("[WasmCodec decode] Invalid index in input");let h=o.get_result_ptr(),f=new Uint8Array(o.memory.buffer,h,l),u=new Uint8Array(l);return u.set(f),u}finally{o.dealloc(i,s);}}};async function it(){try{if(typeof globalThis.process<"u"&&globalThis.process.versions?.node){let{readFile:n}=await import('fs/promises'),{fileURLToPath:e}=await import('url'),{dirname:t,join:r}=await import('path'),o=t(e((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))),s=r(o,"wasm","codec.wasm");try{let i=await n(s);return i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)}catch{let i=r(o,"codec.wasm");try{let a=await n(i);return a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength)}catch{let a=r(o,"..","wasm","codec.wasm");try{let c=await n(a);return c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength)}catch{return null}}}}if(typeof fetch=="function"){let n=await fetch(new URL("./wasm/codec.wasm",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));return n.ok?await n.arrayBuffer():null}return null}catch{return null}}async function at(n){try{if(n.byteLength<16)return null;let e=new Uint8Array(n,0,4);if(e[0]!==0||e[1]!==97||e[2]!==115||e[3]!==109)return null;let t;try{t=await WebAssembly.compile(n);}catch{return null}let o=(await WebAssembly.instantiate(t,{})).exports;return typeof o.alloc!="function"||typeof o.dealloc!="function"||typeof o.encode!="function"||typeof o.decode!="function"||typeof o.get_result_ptr!="function"||typeof o.get_result_len!="function"||typeof o.get_padding_bits!="function"||!o.memory?null:o}catch{return null}}async function Se(){try{if(E)return !0;if(A)return !1;let n=await it();if(!n)return A=!0,!1;let e=await at(n);return e?(E=new te(e),!0):(A=!0,!1)}catch{return A=true,false}}function ct(n,e){let t;return {promise:new Promise((s,i)=>{t=setTimeout(()=>i(new Error(e)),n);}),clear:()=>clearTimeout(t)}}async function dt(){if(E)return;if(w)return w;let n=ct(1e4,"[Ddu64 wasm] WASM initialization timed out (10s)"),e=async()=>{try{if(!await Se())throw new Error("[Ddu64 wasm] WASM initialization failed")}finally{n.clear();}};return w=Promise.race([e(),n.promise]).finally(()=>{w=null,ee=true;}),w}function lt(){if(E)return E;if(A)return null;if(!ee&&!w){ee=true;let n;w=new Promise(e=>{n=setTimeout(()=>{A=true,e();},5e3),Se().then(t=>{t||(A=true);}).catch(()=>{A=true;}).finally(()=>{n!==void 0&&clearTimeout(n),e();});}).finally(()=>{w=null;});}return null}function O(){return E}function Ce(n){if(!Number.isFinite(n))throw new Error(`[Ddu64 config] wasmThreshold must be a finite number, got ${n}`);return Math.max(1024,Math.min(1048576,Math.round(n)))}var xt=8,Tt=64*1024*1024,Rt=64*1024*1024,se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Me="=",_t=Object.fromEntries([...se].map((n,e)=>[n,e])),v=class{dduChar;paddingChar;bitLength;usePowerOfTwo;effectiveBitLength;dduBinaryLookup=new Map;isPredefinedCharSet;defaultCompress;defaultMaxDecodedBytes;defaultMaxDecompressedBytes;urlSafe;encryptionKey;keyDerivation;encryptionKeyHash;defaultChecksum;defaultChunkSize;defaultChunkSeparator;defaultCompressionLevel;defaultCompressionAlgorithm;useRepeatPadding;bitPackConfig;wasmThreshold;canUseNativeBase64;nativeDecodeMap;adapter;defaultObfuscate;_obfuscationLayer;constructor(e,t,r){let o=r?.throwOnError??r?.useBuildErrorReturn??false;r?.adapter?this.adapter=r.adapter:this.adapter=void 0;let s=me(e,t,r,o),i=pe(s,o,r);this.dduChar=i.charSet,this.paddingChar=i.padding,this.isPredefinedCharSet=i.isPredefined,this.defaultCompress=r?.compress??false,this.defaultMaxDecodedBytes=this.normalizeLimit(r?.maxDecodedBytes,Tt,o,"maxDecodedBytes"),this.defaultMaxDecompressedBytes=this.normalizeLimit(r?.maxDecompressedBytes,Rt,o,"maxDecompressedBytes");let a=this.dduChar.length;this.usePowerOfTwo=a>0&&(a&a-1)===0;let c=Math.ceil(Math.log2(a));this.bitLength=this.usePowerOfTwo?Math.floor(Math.log2(a)):c,this.effectiveBitLength=this.usePowerOfTwo?this.bitLength:c;for(let l=0;l<a;l++)this.dduBinaryLookup.set(this.dduChar[l],l);this.isPredefinedCharSet||ge(this.dduChar,this.paddingChar,a);let d=r?.urlSafe??false;if(this.urlSafe=d?ye(this.dduChar,this.paddingChar,o):false,this.encryptionKey=r?.encryptionKey,this.keyDerivation=r?.keyDerivation,this.encryptionKey&&this.adapter?.deriveKeySync&&(this.encryptionKeyHash=this.adapter.deriveKeySync(this.encryptionKey,this.keyDerivation)),this.defaultChecksum=r?.checksum??false,this.defaultChunkSize=r?.chunkSize,this.defaultChunkSeparator=r?.chunkSeparator??`
6
- `,this.defaultCompressionAlgorithm=r?.compressionAlgorithm??"deflate",this.defaultCompressionLevel=R(r?.compressionLevel,this.defaultCompressionAlgorithm),this.useRepeatPadding=r?.useRepeatPadding??s.useRepeatPadding??false,this.defaultObfuscate=r?.obfuscate??false,this.defaultObfuscate&&!this.encryptionKey)throw new Error("[Ddu64 obfuscation] Obfuscation requires encryption to be enabled.");if(this.bitPackConfig=de(a),this.wasmThreshold=Ce(r?.wasmThreshold??4096),this.canUseNativeBase64=this.usePowerOfTwo&&this.dduChar.length===64,this.canUseNativeBase64){this.nativeDecodeMap=new Map;for(let l=0;l<se.length;l++){let h=this.dduChar[l];this.nativeDecodeMap.set(h,se[l]);}}}encode(e,t){return this.encodeInternal(e,t).encoded}decode(e,t){let r=this.decodeToUint8Array(e,t);return V(r)}decodeToUint8Array(e,t){let r=t?.checksum??this.defaultChecksum,o=t?.compress!==false,s=t?.encrypt!==false,i=e;this.reportProgress(t,{processedBytes:0,totalBytes:e.length,percent:0,stage:"start"});let a=t?.chunkSeparator??this.defaultChunkSeparator;i=Y(i,a),this.urlSafe&&(i=q(i));let c=null;if(r){let y=F(i);c=y.checksum,i=y.data;}this.shouldObfuscate(t)&&(i=this.getObfuscationLayer().deobfuscate(i));let{cleanedInput:d,paddingBits:l,compressionAlgorithm:h,isEncrypted:f,pipelineVersion:u}=H(i,this.paddingChar,this.effectiveBitLength);if(f&&s&&!this.encryptionKey)throw new Error("[Ddu64 decode] Encrypted payload requires an encryptionKey");this.assertEncodedInputAligned(d);let m=this.normalizeLimit(t?.maxDecodedBytes,this.defaultMaxDecodedBytes,true,"maxDecodedBytes"),g=this.estimateDecodedBytes(d.length,l);if(g>m)throw new Error(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${g} bytes, Limit: ${m} bytes`);this.reportProgress(t,{processedBytes:d.length,totalBytes:e.length,percent:30,stage:"decode"});let p=this.decodeChars(d,l);if(u===3&&f&&this.encryptionKey&&s&&(this.reportProgress(t,{processedBytes:p.length,totalBytes:p.length,percent:55,stage:"decrypt"}),p=this.decryptSync(p)),h&&o&&(u===2||!f||s)){let y=this.normalizeLimit(t?.maxDecompressedBytes,this.defaultMaxDecompressedBytes,true,"maxDecompressedBytes");this.reportProgress(t,{processedBytes:p.length,totalBytes:p.length,percent:70,stage:"decompress"}),p=this.decompressSync(p,h,y);}if(c&&(u===2||!f||s)){this.reportProgress(t,{processedBytes:p.length,totalBytes:p.length,percent:85,stage:"checksum"});let y=U(p);if(y!==c)throw new Error(`[Ddu64 decode] Checksum mismatch. Expected: ${c}, Got: ${y}`)}return u===2&&f&&this.encryptionKey&&s&&(this.reportProgress(t,{processedBytes:p.length,totalBytes:p.length,percent:90,stage:"decrypt"}),p=this.decryptSync(p)),this.reportProgress(t,{processedBytes:p.length,totalBytes:p.length,percent:100,stage:"done"}),p}async encodeAsync(e,t){let r=await this.getAdapterAsync(),o=t?.compress??this.defaultCompress,s=t?.checksum??this.defaultChecksum,i=(t?.encrypt??true)&&!!this.encryptionKey,a=t?.chunkSize??this.defaultChunkSize,c=t?.chunkSeparator??this.defaultChunkSeparator,d=typeof e=="string"?_(e):e;this.reportProgress(t,{processedBytes:0,totalBytes:d.length,percent:0,stage:"start"});let l="";s&&(l=U(d));let h;if(o){let m=t?.compressionAlgorithm??this.defaultCompressionAlgorithm,g=R(t?.compressionLevel??this.defaultCompressionLevel,m);this.reportProgress(t,{processedBytes:d.length,totalBytes:d.length,percent:20,stage:"compress"});let p;if(m==="brotli"){if(!r.brotliCompress)throw new Error("[Ddu64 compress] Brotli compression is unavailable in the current runtime.");p=await r.brotliCompress(d,g);}else p=await r.deflate(d,g);p.length<d.length&&(d=p,h=m);}let f=false;if(i){let m=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:d.length,totalBytes:d.length,percent:45,stage:"encrypt"}),d=await r.encrypt(d,m),f=true;}this.reportProgress(t,{processedBytes:d.length,totalBytes:d.length,percent:70,stage:"encode"});let u=this.encodeBytes(d,h,f,t);return u=this.applyPostEncoding(u,t,l,s,a,c),this.reportProgress(t,{processedBytes:d.length,totalBytes:d.length,percent:100,stage:"done"}),u}async decodeAsync(e,t){let r=await this.decodeToUint8ArrayAsync(e,t);return V(r)}async decodeToUint8ArrayAsync(e,t){let r=await this.getAdapterAsync(),o=t?.checksum??this.defaultChecksum,s=t?.compress!==false,i=t?.encrypt!==false,a=e;this.reportProgress(t,{processedBytes:0,totalBytes:e.length,percent:0,stage:"start"});let c=t?.chunkSeparator??this.defaultChunkSeparator;a=Y(a,c),this.urlSafe&&(a=q(a));let d=null;if(o){let b=F(a);d=b.checksum,a=b.data;}this.shouldObfuscate(t)&&(a=this.getObfuscationLayer().deobfuscate(a));let{cleanedInput:l,paddingBits:h,compressionAlgorithm:f,isEncrypted:u,pipelineVersion:m}=H(a,this.paddingChar,this.effectiveBitLength);if(u&&i&&!this.encryptionKey)throw new Error("[Ddu64 decode] Encrypted payload requires an encryptionKey");this.assertEncodedInputAligned(l);let g=this.normalizeLimit(t?.maxDecodedBytes,this.defaultMaxDecodedBytes,true,"maxDecodedBytes"),p=this.estimateDecodedBytes(l.length,h);if(p>g)throw new Error(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${p} bytes, Limit: ${g} bytes`);this.reportProgress(t,{processedBytes:l.length,totalBytes:e.length,percent:30,stage:"decode"});let y=this.decodeChars(l,h);if(m===3&&u&&this.encryptionKey&&i){let b=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:55,stage:"decrypt"}),y=await r.decrypt(y,b);}if(f&&s&&(m===2||!u||i)){let b=this.normalizeLimit(t?.maxDecompressedBytes,this.defaultMaxDecompressedBytes,true,"maxDecompressedBytes");if(f==="brotli"){if(!r.brotliDecompress)throw new Error("[Ddu64 decompress] Brotli decompression is unavailable in the current runtime.");this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:70,stage:"decompress"}),y=await r.brotliDecompress(y,b);}else this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:70,stage:"decompress"}),y=await r.inflate(y,b);}if(d&&(m===2||!u||i)){this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:85,stage:"checksum"});let b=U(y);if(b!==d)throw new Error(`[Ddu64 decode] Checksum mismatch. Expected: ${d}, Got: ${b}`)}if(m===2&&u&&this.encryptionKey&&i){let b=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:90,stage:"decrypt"}),y=await r.decrypt(y,b);}return this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:100,stage:"done"}),y}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,defaultChunkSize:this.defaultChunkSize,defaultChunkSeparator:this.defaultChunkSeparator,defaultCompressionLevel:this.defaultCompressionLevel,defaultCompressionAlgorithm:this.defaultCompressionAlgorithm}}getStats(e,t){let o=(typeof e=="string"?_(e):e).length,{encoded:s,compressedSize:i}=this.encodeInternal(e,t),a=s.length,c=o>0?a/o:0,l=(t?.compress??this.defaultCompress)&&i!==void 0&&o>0?i/o:void 0;return {originalSize:o,encodedSize:a,compressedSize:i,compressionRatio:l,expansionRatio:c,charsetSize:this.dduChar.length,bitLength:this.bitLength}}static setWorkerPoolSize(e){J(e);}encodeInternal(e,t){let r=t?.compress??this.defaultCompress,o=t?.checksum??this.defaultChecksum,s=(t?.encrypt??true)&&!!this.encryptionKey,i=t?.chunkSize??this.defaultChunkSize,a=t?.chunkSeparator??this.defaultChunkSeparator,c=typeof e=="string"?_(e):e;this.reportProgress(t,{processedBytes:0,totalBytes:c.length,percent:0,stage:"start"});let d="";o&&(d=U(c));let l,h;if(r){let m=t?.compressionAlgorithm??this.defaultCompressionAlgorithm,g=R(t?.compressionLevel??this.defaultCompressionLevel,m);this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:20,stage:"compress"});let p=this.compressSync(c,m,g);h=p.length,p.length<c.length&&(c=p,l=m);}let f=false;s&&(this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:45,stage:"encrypt"}),c=this.encryptSync(c),f=true),this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:70,stage:"encode"});let u=this.encodeBytes(c,l,f,t);return u=this.applyPostEncoding(u,t,d,o,i,a),this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:100,stage:"done"}),{encoded:u,compressedSize:h}}applyPostEncoding(e,t,r,o,s,i){let a=e;return this.shouldObfuscate(t)&&(a=this.getObfuscationLayer().obfuscate(a)),o&&r&&(a=a+"CHK"+r),this.urlSafe&&(a=he(a)),s&&s>0&&(a=fe(a,s,i)),a}encodeBytes(e,t,r,o){if(e.length===0)return "";let s=this.encodeBytesWithNativeBase64(e),i,a;if(s)i=s.indices,a=s.paddingBits;else {let l=this.shouldUseWasm(e.length)?O():null;if(l?.ready&&this.usePowerOfTwo){let h=l.encode(e,this.bitLength);i=h.indices,a=h.paddingBits;}else {let h=ae(e,this.bitPackConfig);i=h.indices,a=h.paddingBits;}}let c=new Array(i.length);for(let l=0;l<i.length;l++)c[l]=this.dduChar[i[l]];let d=o?.omitFooter?"":ue({paddingBits:a,compressionAlgorithm:t,isEncrypted:!!r,paddingChar:this.paddingChar,useRepeatPadding:this.useRepeatPadding&&!t&&!r,pipelineVersion:r?3:2});return c.join("")+d}decodeChars(e,t){let r=e.length;if(r===0)return new Uint8Array(0);let o=this.decodeCharsWithNativeBase64(e,t);if(o)return o;let s=r>=this.wasmThreshold||r>=4096?new Uint16Array(r):new Array(r);for(let a=0;a<r;a++){let c=e[a],d=this.dduBinaryLookup.get(c);if(d===void 0)throw new Error(`[Ddu64 decode] Invalid character "${c}" at ${a}`);s[a]=d;}let i=this.shouldUseWasm(r)?O():null;if(i?.ready&&this.usePowerOfTwo){let a=s instanceof Uint16Array?s:Uint16Array.from(s);return i.decode(a,this.bitLength,t)}return ce(s,t,this.bitPackConfig)}encodeBytesWithNativeBase64(e){if(!this.canUseNativeBase64)return null;let t=this.bytesToBase64(e);if(t===null)return null;let r=0,o=t.length;for(;o>0&&t[o-1]===Me;)r++,o--;let s=o>=4096?new Uint16Array(o):new Array(o);for(let i=0;i<o;i++)s[i]=_t[t[i]];return {indices:s,paddingBits:r===2?4:r===1?2:0}}decodeCharsWithNativeBase64(e,t){if(!this.canUseNativeBase64||!this.nativeDecodeMap)return null;let r=t===4?2:t===2?1:t===0?0:-1;if(r<0)return null;let o=new Array(e.length+r);for(let s=0;s<e.length;s++){let i=this.nativeDecodeMap.get(e[s]);if(i===void 0)return null;o[s]=i;}for(let s=0;s<r;s++)o[e.length+s]=Me;return this.base64ToBytes(o.join(""))}bytesToBase64(e){let t=e.toBase64;if(typeof t=="function")return t.call(e);let r=globalThis.Buffer;return r?.from?r.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"):null}base64ToBytes(e){let t=Uint8Array;if(typeof t.fromBase64=="function")return t.fromBase64(e);let r=globalThis.Buffer;if(r?.from){let o=r.from(e,"base64");return new Uint8Array(o.buffer,o.byteOffset,o.byteLength)}return null}shouldUseWasm(e){return e>=this.wasmThreshold}reportProgress(e,t){e?.onProgress?.(t);}requireSyncAdapter(){if(!this.adapter)throw new Error("[Ddu64 adapter] No platform adapter available. Use encodeAsync()/decodeAsync() in browser environments, or provide an adapter via options.adapter.");return this.adapter}encryptSync(e){let t=this.requireSyncAdapter();if(!t.encryptSync)throw new Error("[Ddu64 encrypt] Sync encryption unavailable. Use encodeAsync() in browser environments.");if(!this.encryptionKeyHash){if(!t.deriveKeySync)throw new Error("[Ddu64 encrypt] Sync key derivation unavailable. Use encodeAsync() in browser environments.");this.encryptionKeyHash=t.deriveKeySync(this.encryptionKey,this.keyDerivation);}return t.encryptSync(e,this.encryptionKeyHash)}decryptSync(e){let t=this.requireSyncAdapter();if(!t.decryptSync)throw new Error("[Ddu64 decrypt] Sync decryption unavailable. Use decodeAsync() in browser environments.");if(!this.encryptionKeyHash){if(!t.deriveKeySync)throw new Error("[Ddu64 decrypt] Sync key derivation unavailable. Use decodeAsync() in browser environments.");this.encryptionKeyHash=t.deriveKeySync(this.encryptionKey,this.keyDerivation);}return t.decryptSync(e,this.encryptionKeyHash)}compressSync(e,t,r){let o=this.requireSyncAdapter();if(t==="brotli"){if(!o.brotliCompressSync)throw new Error("[Ddu64 compress] Brotli compression is unavailable in the current runtime.");return o.brotliCompressSync(e,r)}if(!o.deflateSync)throw new Error("[Ddu64 compress] Sync compression unavailable. Use encodeAsync() in browser environments.");return o.deflateSync(e,r)}decompressSync(e,t,r){let o=this.requireSyncAdapter();if(t==="brotli"){if(!o.brotliDecompressSync)throw new Error("[Ddu64 decompress] Brotli decompression is unavailable in the current runtime.");return o.brotliDecompressSync(e,r)}if(!o.inflateSync)throw new Error("[Ddu64 decompress] Sync decompression unavailable. Use decodeAsync() in browser environments.");return o.inflateSync(e,r)}async getAdapterAsync(){if(this.adapter)return this.adapter;let{getAdapter:e}=await Promise.resolve().then(()=>(oe(),Oe));return this.adapter=await e(),this.adapter}async getKeyHashAsync(e){return this.encryptionKeyHash?this.encryptionKeyHash:(this.encryptionKeyHash=await e.deriveKey(this.encryptionKey,this.keyDerivation),this.encryptionKeyHash)}getObfuscationLayer(){if(!this._obfuscationLayer){let e=new Set(this.dduChar);e.add(this.paddingChar);let t="ELYSIAGRONCV01234567";for(let o of t)e.add(o);let r=[...e];this._obfuscationLayer=new C(r);}return this._obfuscationLayer}shouldObfuscate(e){let t=e?.obfuscate??this.defaultObfuscate;if(t&&!this.encryptionKey)throw new Error("[Ddu64 obfuscation] Obfuscation requires encryption to be enabled.");return t}normalizeLimit(e,t,r,o){if(e===void 0)return t;if(e===Number.POSITIVE_INFINITY)return Number.POSITIVE_INFINITY;if(!Number.isFinite(e)||e<=0){if(r)throw new Error(`[Ddu64 options] Invalid ${o}. Must be a positive finite number or Infinity.`);return t}return Math.floor(e)}estimateDecodedBytes(e,t){if(e===0)return 0;if(t<0||t>=this.effectiveBitLength)throw new Error(`[Ddu64 decode] Invalid padding bits: ${t}`);let r=this.usePowerOfTwo?1:2,s=Math.ceil(e/r)*this.effectiveBitLength-t;if(s<0)throw new Error("[Ddu64 decode] Invalid decoded bit length");return Math.ceil(s/xt)}assertEncodedInputAligned(e){if(!this.usePowerOfTwo&&e.length%2!==0)throw new Error(`[Ddu64 decode] Invalid encoded length for variable charset. Expected multiple of 2, got ${e.length}`)}};M();var K=class extends v{constructor(e,t,r){let o={...r,adapter:r?.adapter??new exports.NodeAdapter};super(e,t,o);}decodeToBuffer(e,t){let r=this.decodeToUint8Array(e,t);return Buffer.from(r.buffer,r.byteOffset,r.byteLength)}async decodeToBufferAsync(e,t){let r=await this.decodeToUint8ArrayAsync(e,t);return Buffer.from(r.buffer,r.byteOffset,r.byteLength)}};var ie=class n{chars=[];constructor(){}static create(){return new n}static fromUnicodeRange(e,t){return new n().addUnicodeRange(e,t)}static fromString(e){return new n().addString(e)}static base64(){return new n().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")}static base32(){return new n().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567")}static uppercase(){return n.fromUnicodeRange(65,90)}static lowercase(){return n.fromUnicodeRange(97,122)}static digits(){return n.fromUnicodeRange(48,57)}static hangulJamo(){return new n().addUnicodeRange(4352,4370).addUnicodeRange(4449,4469).addUnicodeRange(4520,4546)}addUnicodeRange(e,t){for(let r=e;r<=t;r++)this.chars.push(String.fromCodePoint(r));return this}addString(e){return typeof e=="string"?this.chars.push(...e):this.chars.push(...e),this}add(...e){return this.chars.push(...e),this}excludeConfusing(){let e=new Set(["0","O","o","1","l","I","i","|","L"]);return this.chars=this.chars.filter(t=>!e.has(t)),this}exclude(...e){let t=new Set(e);return this.chars=this.chars.filter(r=>!t.has(r)),this}excludeUrlUnsafe(){let e=new Set(["+","/","=","?","&","#","%"," "]);return this.chars=this.chars.filter(t=>!e.has(t)),this}unique(){return this.chars=[...new Set(this.chars)],this}shuffle(e){let t=e!==void 0?this.seededRandom(e):Math.random;for(let r=this.chars.length-1;r>0;r--){let o=Math.floor(t()*(r+1));[this.chars[r],this.chars[o]]=[this.chars[o],this.chars[r]];}return this}seededRandom(e){let t=e|0||1;return ()=>(t^=t<<13,t^=t>>17,t^=t<<5,(t>>>0)/4294967296)}limit(e){return this.chars=this.chars.slice(0,e),this}limitToPowerOfTwo(){let e=this.chars.length;if(e===0)return this;let t=1<<Math.floor(Math.log2(e));return this.chars=this.chars.slice(0,t),this}sort(){return this.chars.sort(),this}reverse(){return this.chars.reverse(),this}get length(){return this.chars.length}buildString(){return this.chars.join("")}build(){return [...this.chars]}buildWithPadding(e){let t=[...this.chars],r=e;if(!r){let o=["=",".","_","-","~","!"];for(let s of o)if(!t.includes(s)){r=s;break}if(!r)throw new Error("Cannot find suitable padding character")}return {charset:t,padding:r}}};function It(n,e){let t=n.getCharSetInfo(),r=e?.compress??t.defaultCompress,o=(e?.encrypt??true)&&t.hasEncryptionKey,s=r?e?.compressionAlgorithm??t.defaultCompressionAlgorithm:void 0,i=t.paddingChar,a=!r&&!o,c=false,d=[],l=0,h=null;return new TransformStream({async transform(f,u){if(a){if(!c){let b=x(i,{compressionAlgorithm:void 0,encrypted:false});u.enqueue(b),c=true;}let m;h&&h.length>0?(m=new Uint8Array(h.length+f.length),m.set(h,0),m.set(f,h.length)):m=f;let g=t.bitLength,p=Ne(g,8)/8,y=Math.floor(m.length/p)*p;if(y>0){let b=m.subarray(0,y),L=await n.encodeAsync(b,{compress:false,encrypt:false,checksum:false,chunkSize:void 0,chunkSeparator:void 0,omitFooter:true});u.enqueue(L);}y<m.length?h=m.slice(y):h=null;}else d.push(f),l+=f.length;},async flush(f){try{if(a){if(!c){let u=x(i,{compressionAlgorithm:void 0,encrypted:!1});f.enqueue(u);}if(h&&h.length>0){let u=await n.encodeAsync(h,{compress:!1,encrypt:!1,checksum:!1,chunkSize:void 0,chunkSeparator:void 0});f.enqueue(u);}h=null;}else {let u=x(i,{compressionAlgorithm:s,encrypted:o});if(f.enqueue(u),l>0){let m=new Uint8Array(l),g=0;for(let y of d)m.set(y,g),g+=y.length;let p=await n.encodeAsync(m,{...e,compress:r,encrypt:o,checksum:!1,chunkSize:void 0,chunkSeparator:void 0});f.enqueue(p);}d=[],l=0;}}catch(u){f.error(u instanceof Error?u:new Error(String(u)));}}})}function Ot(n,e){let t=n.getCharSetInfo(),r=t.paddingChar,o=$(r),s="",i=false,a=null,c=false;return new TransformStream({async transform(d,l){if(s+=d,!i&&s.length>=o){if(!s.startsWith(r)){l.error(new Error("[WebStreams decode] Invalid or missing stream header"));return}if(a=le(s,r),a===null){l.error(new Error("[WebStreams decode] Invalid or missing stream header"));return}if(a.encrypted&&!t.hasEncryptionKey){l.error(new Error("[WebStreams decode] Encrypted stream requires an encryptionKey"));return}i=true,c=!a.compressionAlgorithm&&!a.encrypted,s=s.slice(o);}if(i&&c&&s.length>0){let h=t.bitLength,f=Ne(h,8)/h,u=Math.floor(s.length/f)*f;if(u>0){let m=s.slice(0,u);s=s.slice(u);try{let g=await n.decodeToUint8ArrayAsync(m,{compress:!1,encrypt:!1,checksum:!1,chunkSize:void 0,chunkSeparator:void 0});g.length>0&&l.enqueue(g);}catch{s=m+s;}}}},async flush(d){try{if(!i){if(s.length===0)return;d.error(new Error("[WebStreams decode] Incomplete stream header"));return}if(s.length===0)return;let l=a.compressionAlgorithm,h=a.encrypted,f=await n.decodeToUint8ArrayAsync(s,{...e,compress:!!l,compressionAlgorithm:l,encrypt:h,checksum:!1,chunkSize:void 0,chunkSeparator:void 0});f.length>0&&d.enqueue(f),s="";}catch(l){d.error(l instanceof Error?l:new Error(String(l)));}}})}function Ne(n,e){return n*e/Mt(n,e)}function Mt(n,e){for(;e!==0;){let t=e;e=n%e,n=t;}return n}M();re();oe();exports.CharsetBuilder=ie;exports.Ddu64=K;exports.Ddu64Core=v;exports.Ddu64Node=K;exports.DduSetSymbol=j;exports.HangulObfuscationLayer=C;exports.createObfuscationLayer=st;exports.createReadableDecodeStream=Ot;exports.createReadableEncodeStream=It;exports.detectRuntime=ne;exports.getAdapter=Ie;exports.getWasmCodec=lt;exports.getWasmCodecSync=O;exports.preloadWasm=dt;exports.setWorkerPoolSize=J;//# sourceMappingURL=index.cjs.map
5
+ `)||i.padding.includes("\r"))throw new Error("[Ddu64 normalizeCharSet] Newline and carriage return characters are reserved.");return {charSet:a.length===c?a:a.slice(0,c),padding:i.padding,isPredefined:i.isPredefined}}catch(a){if(e)throw a}}let o=Z(t);return {charSet:o.charSet.slice(0,o.requiredLength),padding:o.padding,isPredefined:true}}function ye(n,e,t){for(let r of Qe){for(let o of n)if(o.includes(r)){let s=`[Ddu64 Constructor] URL-Safe mode conflict: charset character "${o}" contains "${r}".`;if(t)throw new Error(s);return false}if(e.includes(r)){let o=`[Ddu64 Constructor] URL-Safe mode conflict: padding character "${e}" contains "${r}".`;if(t)throw new Error(o);return false}}return true}function ge(n,e,t){if(t>256)return;let r=Math.min(n.length,t),o=n.slice(0,r),s=new Set;for(let a=0;a<o.length;a++)s.add(o[a]);s.add(e);for(let a=0;a<o.length;a++){let c=o[a];for(let h=0;h<o.length;h++){let f=c+o[h];if(s.has(f))throw new Error(`Combination conflict: "${c}" + "${o[h]}"`);s.add(f);}let d=c+e;if(s.has(d))throw new Error(`Combination conflict: "${c}" + padding`);s.add(d);let l=e+c;if(s.has(l))throw new Error(`Combination conflict: padding + "${c}"`);s.add(l);}let i=e+e;if(s.has(i))throw new Error("Combination conflict: double padding");s.add(i);}function Je(n,e){return e!==void 0?e?n>0:false:n>0&&(n&n-1)===0}function et(n){let e=I(n);if(!e)throw new Error(`CharSet with symbol ${n} not found`);return e}function Z(n){let e=n?.dduSetSymbol??G.dduSetSymbol??"oneCharSet",t=I(e)??I("oneCharSet");if(!t)throw new Error("Critical: No fallback CharSet available");return {charSet:t.codaChar?T(t.charSet,t.codaChar):t.charSet,padding:t.paddingChar,requiredLength:t.maxRequiredLength,bitLength:t.bitLength,isPredefined:true,useRepeatPadding:t.useRepeatPadding}}function tt(){let n=1;return typeof globalThis.navigator<"u"&&globalThis.navigator.hardwareConcurrency?n=globalThis.navigator.hardwareConcurrency:typeof globalThis.process<"u"&&globalThis.process.versions?.node&&(typeof globalThis.process.availableParallelism=="function"?n=globalThis.process.availableParallelism():n=4),Math.max(1,Math.min(64,n-1))}function rt(){try{let{Worker:n}=We("worker_threads"),e=new URL("./nodeWorker.js",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname,t=new n(e);return {postMessage(r){t.postMessage(r);},async terminate(){await t.terminate();},onMessage(r){t.on("message",r);},onError(r){t.on("error",r);}}}catch{return null}}function nt(){try{if(typeof globalThis.Worker>"u")return null;let n=new URL("./webWorker.js",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),e=new globalThis.Worker(n,{type:"module"});return {postMessage(t){e.postMessage(t);},async terminate(){e.terminate();},onMessage(t){e.addEventListener("message",r=>{t(r.data);});},onError(t){e.addEventListener("error",r=>{t(new Error(r.message||"Worker error"));});}}}catch{return null}}var Q=class{poolSize;workers=[];pendingTasks=new Map;nextTaskId=0;roundRobinIndex=0;initialized=false;terminated=false;constructor(e){this.poolSize=e??tt();}async encode(e,t){return await this.dispatch("encode",e,t)}async decode(e,t){return await this.dispatch("decode",e,t)}setPoolSize(e){if(!Number.isInteger(e))throw new Error(`[WorkerPool] Pool size must be an integer. Got: ${e}. Valid range: [1, 64]`);if(e<1||e>64)throw new Error(`[WorkerPool] Pool size must be between 1 and 64. Got: ${e}`);let t=this.poolSize;this.poolSize=e,this.initialized&&t!==e&&(this.terminateWorkers(),this.initialized=false);}async terminate(){this.terminated=true,await this.terminateWorkers();for(let[,e]of this.pendingTasks)e.reject(new Error("[WorkerPool] Pool terminated"));this.pendingTasks.clear();}async dispatch(e,t,r){if(this.terminated)throw new Error("[WorkerPool] Pool has been terminated");if(this.ensureInitialized(),this.workers.length===0)throw new Error("[WorkerPool] No workers available. Workers may not be supported in this runtime.");let o=this.nextTaskId++,s=this.roundRobinIndex%this.workers.length;this.roundRobinIndex=(this.roundRobinIndex+1)%this.workers.length;let i=this.workers[s];return new Promise((a,c)=>{this.pendingTasks.set(o,{resolve:a,reject:c});let d={id:o,type:e,data:t,config:r};i.postMessage(d);})}ensureInitialized(){if(this.initialized)return;let e=typeof globalThis.process<"u"&&!!globalThis.process.versions?.node;for(let t=0;t<this.poolSize;t++){let r=e?rt():nt();if(!r)break;r.onMessage(o=>{let s=this.pendingTasks.get(o.id);s&&(this.pendingTasks.delete(o.id),o.type==="error"?s.reject(new Error(o.error??"Worker error")):s.resolve(o.result));}),r.onError(o=>{console.error("[WorkerPool] Worker error:",o.message);}),this.workers.push(r);}this.initialized=true;}async terminateWorkers(){let e=this.workers.map(t=>t.terminate());await Promise.all(e),this.workers=[];}},X=null;function ot(){return X||(X=new Q),X}function J(n){ot().setPoolSize(n);}function be(n){if(n.length===0)throw new Error("[Ddu64 obfuscation] Alphabet must not be empty.");if(n.length>11172)throw new Error(`[Ddu64 obfuscation] Alphabet size (${n.length}) exceeds available Hangul syllables (11172).`);let e=Math.floor(11172/n.length),t=new Map;for(let r=0;r<n.length;r++)t.set(n[r],r);return {alphabet:n,syllablesPerChar:e,charToIndex:t}}function we(n,e,t){let r=44032+n*t.syllablesPerChar,o=e%t.syllablesPerChar;return r+o}function Ae(n,e){if(n<44032||n>55203)return -1;let t=n-44032,r=Math.floor(t/e.syllablesPerChar);return r>=e.alphabet.length?-1:r}var C=class{config;constructor(e){this.config=be(e);}obfuscate(e){if(e.length===0)return "";let t=new Array(e.length);for(let r=0;r<e.length;r++){let o=e[r],s=this.config.charToIndex.get(o);if(s===void 0)throw new Error(`[Ddu64 obfuscation] Character "${o}" (U+${o.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase()}) not found in obfuscation alphabet.`);let i=we(s,r,this.config);t[r]=String.fromCharCode(i);}return t.join("")}deobfuscate(e){if(e.length===0)return "";let t=new Array(e.length);for(let r=0;r<e.length;r++){let o=e.charCodeAt(r),s=Ae(o,this.config);if(s===-1)throw new Error(`[Ddu64 obfuscation] Invalid syllable at position ${r}: U+${o.toString(16).padStart(4,"0").toUpperCase()} is not in the mapped range.`);t[r]=this.config.alphabet[s];}return t.join("")}};function st(n,e){let t=new Set(n);t.add(e);let r=[...t];return new C(r)}var E=null,ee=false,A=false,w=null,te=class{exports;_ready=true;constructor(e){this.exports=e;}get ready(){return this._ready}encode(e,t){let{exports:r}=this;if(e.length===0)return {indices:new Uint16Array(0),paddingBits:0};let o=r.alloc(e.length);new Uint8Array(r.memory.buffer).set(e,o);let i=1<<t,a=1;try{let c=r.encode(o,e.length,t,i,a),d=r.get_result_ptr(),l=new Uint16Array(r.memory.buffer,d,c),h=new Uint16Array(c);return h.set(l),{indices:h,paddingBits:r.get_padding_bits()}}finally{r.dealloc(o,e.length);}}decode(e,t,r){let{exports:o}=this;if(e.length===0)return new Uint8Array(0);let s=e.length*2,i=o.alloc(s);new Uint16Array(o.memory.buffer,i,e.length).set(e);let c=1<<t,d=1;try{let l=o.decode(i,e.length,t,c,d,r);if(l===4294967295)throw new Error("[WasmCodec decode] Invalid index in input");let h=o.get_result_ptr(),f=new Uint8Array(o.memory.buffer,h,l),u=new Uint8Array(l);return u.set(f),u}finally{o.dealloc(i,s);}}};async function it(){try{if(typeof globalThis.process<"u"&&globalThis.process.versions?.node){let{readFile:n}=await import('fs/promises'),{fileURLToPath:e}=await import('url'),{dirname:t,join:r}=await import('path'),o=t(e((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))),s=r(o,"wasm","codec.wasm");try{let i=await n(s);return i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)}catch{let i=r(o,"codec.wasm");try{let a=await n(i);return a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength)}catch{let a=r(o,"..","wasm","codec.wasm");try{let c=await n(a);return c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength)}catch{return null}}}}if(typeof fetch=="function"){let n=await fetch(new URL("./wasm/codec.wasm",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));return n.ok?await n.arrayBuffer():null}return null}catch{return null}}async function at(n){try{if(n.byteLength<16)return null;let e=new Uint8Array(n,0,4);if(e[0]!==0||e[1]!==97||e[2]!==115||e[3]!==109)return null;let t;try{t=await WebAssembly.compile(n);}catch{return null}let o=(await WebAssembly.instantiate(t,{})).exports;return typeof o.alloc!="function"||typeof o.dealloc!="function"||typeof o.encode!="function"||typeof o.decode!="function"||typeof o.get_result_ptr!="function"||typeof o.get_result_len!="function"||typeof o.get_padding_bits!="function"||!o.memory?null:o}catch{return null}}async function Se(){try{if(E)return !0;if(A)return !1;let n=await it();if(!n)return A=!0,!1;let e=await at(n);return e?(E=new te(e),!0):(A=!0,!1)}catch{return A=true,false}}function ct(n,e){let t;return {promise:new Promise((s,i)=>{t=setTimeout(()=>i(new Error(e)),n);}),clear:()=>clearTimeout(t)}}async function dt(){if(E)return;if(w)return w;let n=ct(1e4,"[Ddu64 wasm] WASM initialization timed out (10s)"),e=async()=>{try{if(!await Se())throw new Error("[Ddu64 wasm] WASM initialization failed")}finally{n.clear();}};return w=Promise.race([e(),n.promise]).finally(()=>{w=null,ee=true;}),w}function lt(){if(E)return E;if(A)return null;if(!ee&&!w){ee=true;let n;w=new Promise(e=>{n=setTimeout(()=>{A=true,e();},5e3),Se().then(t=>{t||(A=true);}).catch(()=>{A=true;}).finally(()=>{n!==void 0&&clearTimeout(n),e();});}).finally(()=>{w=null;});}return null}function O(){return E}function Ce(n){if(!Number.isFinite(n))throw new Error(`[Ddu64 config] wasmThreshold must be a finite number, got ${n}`);return Math.max(1024,Math.min(1048576,Math.round(n)))}var xt=8,Tt=64*1024*1024,Rt=64*1024*1024,se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Me="=",_t=Object.fromEntries([...se].map((n,e)=>[n,e])),v=class{dduChar;paddingChar;bitLength;usePowerOfTwo;effectiveBitLength;dduBinaryLookup=new Map;isPredefinedCharSet;defaultCompress;defaultMaxDecodedBytes;defaultMaxDecompressedBytes;urlSafe;encryptionKey;keyDerivation;encryptionKeyHash;defaultChecksum;defaultChunkSize;defaultChunkSeparator;defaultCompressionLevel;defaultCompressionAlgorithm;useRepeatPadding;bitPackConfig;wasmThreshold;canUseNativeBase64;nativeDecodeMap;adapter;defaultObfuscate;_obfuscationLayer;constructor(e,t,r){e!=null&&typeof e=="object"&&!Array.isArray(e)&&(r=e,e=void 0,t=void 0);let o=r?.throwOnError??r?.useBuildErrorReturn??false;r?.adapter?this.adapter=r.adapter:this.adapter=void 0;let s=me(e,t,r,o),i=pe(s,o,r);this.dduChar=i.charSet,this.paddingChar=i.padding,this.isPredefinedCharSet=i.isPredefined,this.defaultCompress=r?.compress??false,this.defaultMaxDecodedBytes=this.normalizeLimit(r?.maxDecodedBytes,Tt,o,"maxDecodedBytes"),this.defaultMaxDecompressedBytes=this.normalizeLimit(r?.maxDecompressedBytes,Rt,o,"maxDecompressedBytes");let a=this.dduChar.length;this.usePowerOfTwo=a>0&&(a&a-1)===0;let c=Math.ceil(Math.log2(a));this.bitLength=this.usePowerOfTwo?Math.floor(Math.log2(a)):c,this.effectiveBitLength=this.usePowerOfTwo?this.bitLength:c;for(let l=0;l<a;l++)this.dduBinaryLookup.set(this.dduChar[l],l);this.isPredefinedCharSet||ge(this.dduChar,this.paddingChar,a);let d=r?.urlSafe??false;if(this.urlSafe=d?ye(this.dduChar,this.paddingChar,o):false,this.encryptionKey=r?.encryptionKey,this.keyDerivation=r?.keyDerivation,this.encryptionKey&&this.adapter?.deriveKeySync&&(this.encryptionKeyHash=this.adapter.deriveKeySync(this.encryptionKey,this.keyDerivation)),this.defaultChecksum=r?.checksum??false,this.defaultChunkSize=r?.chunkSize,this.defaultChunkSeparator=r?.chunkSeparator??`
6
+ `,this.defaultCompressionAlgorithm=r?.compressionAlgorithm??"deflate",this.defaultCompressionLevel=R(r?.compressionLevel,this.defaultCompressionAlgorithm),this.useRepeatPadding=r?.useRepeatPadding??s.useRepeatPadding??false,this.defaultObfuscate=r?.obfuscate??false,this.defaultObfuscate&&!this.encryptionKey)throw new Error("[Ddu64 obfuscation] Obfuscation requires encryption to be enabled.");if(this.bitPackConfig=de(a),this.wasmThreshold=Ce(r?.wasmThreshold??4096),this.canUseNativeBase64=this.usePowerOfTwo&&this.dduChar.length===64,this.canUseNativeBase64){this.nativeDecodeMap=new Map;for(let l=0;l<se.length;l++){let h=this.dduChar[l];this.nativeDecodeMap.set(h,se[l]);}}}encode(e,t){return this.encodeInternal(e,t).encoded}decode(e,t){let r=this.decodeToUint8Array(e,t);return V(r)}decodeToUint8Array(e,t){let r=t?.checksum??this.defaultChecksum,o=t?.compress!==false,s=t?.encrypt!==false,i=e;this.reportProgress(t,{processedBytes:0,totalBytes:e.length,percent:0,stage:"start"});let a=t?.chunkSeparator??this.defaultChunkSeparator;i=Y(i,a),this.urlSafe&&(i=q(i));let c=null;if(r){let y=F(i);c=y.checksum,i=y.data;}this.shouldObfuscate(t)&&(i=this.getObfuscationLayer().deobfuscate(i));let{cleanedInput:d,paddingBits:l,compressionAlgorithm:h,isEncrypted:f,pipelineVersion:u}=H(i,this.paddingChar,this.effectiveBitLength);if(f&&s&&!this.encryptionKey)throw new Error("[Ddu64 decode] Encrypted payload requires an encryptionKey");this.assertEncodedInputAligned(d);let m=this.normalizeLimit(t?.maxDecodedBytes,this.defaultMaxDecodedBytes,true,"maxDecodedBytes"),g=this.estimateDecodedBytes(d.length,l);if(g>m)throw new Error(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${g} bytes, Limit: ${m} bytes`);this.reportProgress(t,{processedBytes:d.length,totalBytes:e.length,percent:30,stage:"decode"});let p=this.decodeChars(d,l);if(u===3&&f&&this.encryptionKey&&s&&(this.reportProgress(t,{processedBytes:p.length,totalBytes:p.length,percent:55,stage:"decrypt"}),p=this.decryptSync(p)),h&&o&&(u===2||!f||s)){let y=this.normalizeLimit(t?.maxDecompressedBytes,this.defaultMaxDecompressedBytes,true,"maxDecompressedBytes");this.reportProgress(t,{processedBytes:p.length,totalBytes:p.length,percent:70,stage:"decompress"}),p=this.decompressSync(p,h,y);}if(c&&(u===2||!f||s)){this.reportProgress(t,{processedBytes:p.length,totalBytes:p.length,percent:85,stage:"checksum"});let y=U(p);if(y!==c)throw new Error(`[Ddu64 decode] Checksum mismatch. Expected: ${c}, Got: ${y}`)}return u===2&&f&&this.encryptionKey&&s&&(this.reportProgress(t,{processedBytes:p.length,totalBytes:p.length,percent:90,stage:"decrypt"}),p=this.decryptSync(p)),this.reportProgress(t,{processedBytes:p.length,totalBytes:p.length,percent:100,stage:"done"}),p}async encodeAsync(e,t){let r=await this.getAdapterAsync(),o=t?.compress??this.defaultCompress,s=t?.checksum??this.defaultChecksum,i=(t?.encrypt??true)&&!!this.encryptionKey,a=t?.chunkSize??this.defaultChunkSize,c=t?.chunkSeparator??this.defaultChunkSeparator,d=typeof e=="string"?_(e):e;this.reportProgress(t,{processedBytes:0,totalBytes:d.length,percent:0,stage:"start"});let l="";s&&(l=U(d));let h;if(o){let m=t?.compressionAlgorithm??this.defaultCompressionAlgorithm,g=R(t?.compressionLevel??this.defaultCompressionLevel,m);this.reportProgress(t,{processedBytes:d.length,totalBytes:d.length,percent:20,stage:"compress"});let p;if(m==="brotli"){if(!r.brotliCompress)throw new Error("[Ddu64 compress] Brotli compression is unavailable in the current runtime.");p=await r.brotliCompress(d,g);}else p=await r.deflate(d,g);p.length<d.length&&(d=p,h=m);}let f=false;if(i){let m=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:d.length,totalBytes:d.length,percent:45,stage:"encrypt"}),d=await r.encrypt(d,m),f=true;}this.reportProgress(t,{processedBytes:d.length,totalBytes:d.length,percent:70,stage:"encode"});let u=this.encodeBytes(d,h,f,t);return u=this.applyPostEncoding(u,t,l,s,a,c),this.reportProgress(t,{processedBytes:d.length,totalBytes:d.length,percent:100,stage:"done"}),u}async decodeAsync(e,t){let r=await this.decodeToUint8ArrayAsync(e,t);return V(r)}async decodeToUint8ArrayAsync(e,t){let r=await this.getAdapterAsync(),o=t?.checksum??this.defaultChecksum,s=t?.compress!==false,i=t?.encrypt!==false,a=e;this.reportProgress(t,{processedBytes:0,totalBytes:e.length,percent:0,stage:"start"});let c=t?.chunkSeparator??this.defaultChunkSeparator;a=Y(a,c),this.urlSafe&&(a=q(a));let d=null;if(o){let b=F(a);d=b.checksum,a=b.data;}this.shouldObfuscate(t)&&(a=this.getObfuscationLayer().deobfuscate(a));let{cleanedInput:l,paddingBits:h,compressionAlgorithm:f,isEncrypted:u,pipelineVersion:m}=H(a,this.paddingChar,this.effectiveBitLength);if(u&&i&&!this.encryptionKey)throw new Error("[Ddu64 decode] Encrypted payload requires an encryptionKey");this.assertEncodedInputAligned(l);let g=this.normalizeLimit(t?.maxDecodedBytes,this.defaultMaxDecodedBytes,true,"maxDecodedBytes"),p=this.estimateDecodedBytes(l.length,h);if(p>g)throw new Error(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${p} bytes, Limit: ${g} bytes`);this.reportProgress(t,{processedBytes:l.length,totalBytes:e.length,percent:30,stage:"decode"});let y=this.decodeChars(l,h);if(m===3&&u&&this.encryptionKey&&i){let b=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:55,stage:"decrypt"}),y=await r.decrypt(y,b);}if(f&&s&&(m===2||!u||i)){let b=this.normalizeLimit(t?.maxDecompressedBytes,this.defaultMaxDecompressedBytes,true,"maxDecompressedBytes");if(f==="brotli"){if(!r.brotliDecompress)throw new Error("[Ddu64 decompress] Brotli decompression is unavailable in the current runtime.");this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:70,stage:"decompress"}),y=await r.brotliDecompress(y,b);}else this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:70,stage:"decompress"}),y=await r.inflate(y,b);}if(d&&(m===2||!u||i)){this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:85,stage:"checksum"});let b=U(y);if(b!==d)throw new Error(`[Ddu64 decode] Checksum mismatch. Expected: ${d}, Got: ${b}`)}if(m===2&&u&&this.encryptionKey&&i){let b=await this.getKeyHashAsync(r);this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:90,stage:"decrypt"}),y=await r.decrypt(y,b);}return this.reportProgress(t,{processedBytes:y.length,totalBytes:y.length,percent:100,stage:"done"}),y}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,defaultChunkSize:this.defaultChunkSize,defaultChunkSeparator:this.defaultChunkSeparator,defaultCompressionLevel:this.defaultCompressionLevel,defaultCompressionAlgorithm:this.defaultCompressionAlgorithm}}getStats(e,t){let o=(typeof e=="string"?_(e):e).length,{encoded:s,compressedSize:i}=this.encodeInternal(e,t),a=s.length,c=o>0?a/o:0,l=(t?.compress??this.defaultCompress)&&i!==void 0&&o>0?i/o:void 0;return {originalSize:o,encodedSize:a,compressedSize:i,compressionRatio:l,expansionRatio:c,charsetSize:this.dduChar.length,bitLength:this.bitLength}}static setWorkerPoolSize(e){J(e);}encodeInternal(e,t){let r=t?.compress??this.defaultCompress,o=t?.checksum??this.defaultChecksum,s=(t?.encrypt??true)&&!!this.encryptionKey,i=t?.chunkSize??this.defaultChunkSize,a=t?.chunkSeparator??this.defaultChunkSeparator,c=typeof e=="string"?_(e):e;this.reportProgress(t,{processedBytes:0,totalBytes:c.length,percent:0,stage:"start"});let d="";o&&(d=U(c));let l,h;if(r){let m=t?.compressionAlgorithm??this.defaultCompressionAlgorithm,g=R(t?.compressionLevel??this.defaultCompressionLevel,m);this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:20,stage:"compress"});let p=this.compressSync(c,m,g);h=p.length,p.length<c.length&&(c=p,l=m);}let f=false;s&&(this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:45,stage:"encrypt"}),c=this.encryptSync(c),f=true),this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:70,stage:"encode"});let u=this.encodeBytes(c,l,f,t);return u=this.applyPostEncoding(u,t,d,o,i,a),this.reportProgress(t,{processedBytes:c.length,totalBytes:c.length,percent:100,stage:"done"}),{encoded:u,compressedSize:h}}applyPostEncoding(e,t,r,o,s,i){let a=e;return this.shouldObfuscate(t)&&(a=this.getObfuscationLayer().obfuscate(a)),o&&r&&(a=a+"CHK"+r),this.urlSafe&&(a=he(a)),s&&s>0&&(a=fe(a,s,i)),a}encodeBytes(e,t,r,o){if(e.length===0)return "";let s=this.encodeBytesWithNativeBase64(e),i,a;if(s)i=s.indices,a=s.paddingBits;else {let l=this.shouldUseWasm(e.length)?O():null;if(l?.ready&&this.usePowerOfTwo){let h=l.encode(e,this.bitLength);i=h.indices,a=h.paddingBits;}else {let h=ae(e,this.bitPackConfig);i=h.indices,a=h.paddingBits;}}let c=new Array(i.length);for(let l=0;l<i.length;l++)c[l]=this.dduChar[i[l]];let d=o?.omitFooter?"":ue({paddingBits:a,compressionAlgorithm:t,isEncrypted:!!r,paddingChar:this.paddingChar,useRepeatPadding:this.useRepeatPadding&&!t&&!r,pipelineVersion:r?3:2});return c.join("")+d}decodeChars(e,t){let r=e.length;if(r===0)return new Uint8Array(0);let o=this.decodeCharsWithNativeBase64(e,t);if(o)return o;let s=r>=this.wasmThreshold||r>=4096?new Uint16Array(r):new Array(r);for(let a=0;a<r;a++){let c=e[a],d=this.dduBinaryLookup.get(c);if(d===void 0)throw new Error(`[Ddu64 decode] Invalid character "${c}" at ${a}`);s[a]=d;}let i=this.shouldUseWasm(r)?O():null;if(i?.ready&&this.usePowerOfTwo){let a=s instanceof Uint16Array?s:Uint16Array.from(s);return i.decode(a,this.bitLength,t)}return ce(s,t,this.bitPackConfig)}encodeBytesWithNativeBase64(e){if(!this.canUseNativeBase64)return null;let t=this.bytesToBase64(e);if(t===null)return null;let r=0,o=t.length;for(;o>0&&t[o-1]===Me;)r++,o--;let s=o>=4096?new Uint16Array(o):new Array(o);for(let i=0;i<o;i++)s[i]=_t[t[i]];return {indices:s,paddingBits:r===2?4:r===1?2:0}}decodeCharsWithNativeBase64(e,t){if(!this.canUseNativeBase64||!this.nativeDecodeMap)return null;let r=t===4?2:t===2?1:t===0?0:-1;if(r<0)return null;let o=new Array(e.length+r);for(let s=0;s<e.length;s++){let i=this.nativeDecodeMap.get(e[s]);if(i===void 0)return null;o[s]=i;}for(let s=0;s<r;s++)o[e.length+s]=Me;return this.base64ToBytes(o.join(""))}bytesToBase64(e){let t=e.toBase64;if(typeof t=="function")return t.call(e);let r=globalThis.Buffer;return r?.from?r.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"):null}base64ToBytes(e){let t=Uint8Array;if(typeof t.fromBase64=="function")return t.fromBase64(e);let r=globalThis.Buffer;if(r?.from){let o=r.from(e,"base64");return new Uint8Array(o.buffer,o.byteOffset,o.byteLength)}return null}shouldUseWasm(e){return e>=this.wasmThreshold}reportProgress(e,t){e?.onProgress?.(t);}requireSyncAdapter(){if(!this.adapter)throw new Error("[Ddu64 adapter] No platform adapter available. Use encodeAsync()/decodeAsync() in browser environments, or provide an adapter via options.adapter.");return this.adapter}encryptSync(e){let t=this.requireSyncAdapter();if(!t.encryptSync)throw new Error("[Ddu64 encrypt] Sync encryption unavailable. Use encodeAsync() in browser environments.");if(!this.encryptionKeyHash){if(!t.deriveKeySync)throw new Error("[Ddu64 encrypt] Sync key derivation unavailable. Use encodeAsync() in browser environments.");this.encryptionKeyHash=t.deriveKeySync(this.encryptionKey,this.keyDerivation);}return t.encryptSync(e,this.encryptionKeyHash)}decryptSync(e){let t=this.requireSyncAdapter();if(!t.decryptSync)throw new Error("[Ddu64 decrypt] Sync decryption unavailable. Use decodeAsync() in browser environments.");if(!this.encryptionKeyHash){if(!t.deriveKeySync)throw new Error("[Ddu64 decrypt] Sync key derivation unavailable. Use decodeAsync() in browser environments.");this.encryptionKeyHash=t.deriveKeySync(this.encryptionKey,this.keyDerivation);}return t.decryptSync(e,this.encryptionKeyHash)}compressSync(e,t,r){let o=this.requireSyncAdapter();if(t==="brotli"){if(!o.brotliCompressSync)throw new Error("[Ddu64 compress] Brotli compression is unavailable in the current runtime.");return o.brotliCompressSync(e,r)}if(!o.deflateSync)throw new Error("[Ddu64 compress] Sync compression unavailable. Use encodeAsync() in browser environments.");return o.deflateSync(e,r)}decompressSync(e,t,r){let o=this.requireSyncAdapter();if(t==="brotli"){if(!o.brotliDecompressSync)throw new Error("[Ddu64 decompress] Brotli decompression is unavailable in the current runtime.");return o.brotliDecompressSync(e,r)}if(!o.inflateSync)throw new Error("[Ddu64 decompress] Sync decompression unavailable. Use decodeAsync() in browser environments.");return o.inflateSync(e,r)}async getAdapterAsync(){if(this.adapter)return this.adapter;let{getAdapter:e}=await Promise.resolve().then(()=>(oe(),Oe));return this.adapter=await e(),this.adapter}async getKeyHashAsync(e){return this.encryptionKeyHash?this.encryptionKeyHash:(this.encryptionKeyHash=await e.deriveKey(this.encryptionKey,this.keyDerivation),this.encryptionKeyHash)}getObfuscationLayer(){if(!this._obfuscationLayer){let e=new Set(this.dduChar);e.add(this.paddingChar);let t="ELYSIAGRONCV01234567";for(let o of t)e.add(o);let r=[...e];this._obfuscationLayer=new C(r);}return this._obfuscationLayer}shouldObfuscate(e){let t=e?.obfuscate??this.defaultObfuscate;if(t&&!this.encryptionKey)throw new Error("[Ddu64 obfuscation] Obfuscation requires encryption to be enabled.");return t}normalizeLimit(e,t,r,o){if(e===void 0)return t;if(e===Number.POSITIVE_INFINITY)return Number.POSITIVE_INFINITY;if(!Number.isFinite(e)||e<=0){if(r)throw new Error(`[Ddu64 options] Invalid ${o}. Must be a positive finite number or Infinity.`);return t}return Math.floor(e)}estimateDecodedBytes(e,t){if(e===0)return 0;if(t<0||t>=this.effectiveBitLength)throw new Error(`[Ddu64 decode] Invalid padding bits: ${t}`);let r=this.usePowerOfTwo?1:2,s=Math.ceil(e/r)*this.effectiveBitLength-t;if(s<0)throw new Error("[Ddu64 decode] Invalid decoded bit length");return Math.ceil(s/xt)}assertEncodedInputAligned(e){if(!this.usePowerOfTwo&&e.length%2!==0)throw new Error(`[Ddu64 decode] Invalid encoded length for variable charset. Expected multiple of 2, got ${e.length}`)}};M();var K=class extends v{constructor(e,t,r){e!=null&&typeof e=="object"&&!Array.isArray(e)&&(r=e,e=void 0,t=void 0);let o={...r,adapter:r?.adapter??new exports.NodeAdapter};super(e,t,o);}decodeToBuffer(e,t){let r=this.decodeToUint8Array(e,t);return Buffer.from(r.buffer,r.byteOffset,r.byteLength)}async decodeToBufferAsync(e,t){let r=await this.decodeToUint8ArrayAsync(e,t);return Buffer.from(r.buffer,r.byteOffset,r.byteLength)}};var ie=class n{chars=[];constructor(){}static create(){return new n}static fromUnicodeRange(e,t){return new n().addUnicodeRange(e,t)}static fromString(e){return new n().addString(e)}static base64(){return new n().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")}static base32(){return new n().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567")}static uppercase(){return n.fromUnicodeRange(65,90)}static lowercase(){return n.fromUnicodeRange(97,122)}static digits(){return n.fromUnicodeRange(48,57)}static hangulJamo(){return new n().addUnicodeRange(4352,4370).addUnicodeRange(4449,4469).addUnicodeRange(4520,4546)}addUnicodeRange(e,t){for(let r=e;r<=t;r++)this.chars.push(String.fromCodePoint(r));return this}addString(e){return typeof e=="string"?this.chars.push(...e):this.chars.push(...e),this}add(...e){return this.chars.push(...e),this}excludeConfusing(){let e=new Set(["0","O","o","1","l","I","i","|","L"]);return this.chars=this.chars.filter(t=>!e.has(t)),this}exclude(...e){let t=new Set(e);return this.chars=this.chars.filter(r=>!t.has(r)),this}excludeUrlUnsafe(){let e=new Set(["+","/","=","?","&","#","%"," "]);return this.chars=this.chars.filter(t=>!e.has(t)),this}unique(){return this.chars=[...new Set(this.chars)],this}shuffle(e){let t=e!==void 0?this.seededRandom(e):Math.random;for(let r=this.chars.length-1;r>0;r--){let o=Math.floor(t()*(r+1));[this.chars[r],this.chars[o]]=[this.chars[o],this.chars[r]];}return this}seededRandom(e){let t=e|0||1;return ()=>(t^=t<<13,t^=t>>17,t^=t<<5,(t>>>0)/4294967296)}limit(e){return this.chars=this.chars.slice(0,e),this}limitToPowerOfTwo(){let e=this.chars.length;if(e===0)return this;let t=1<<Math.floor(Math.log2(e));return this.chars=this.chars.slice(0,t),this}sort(){return this.chars.sort(),this}reverse(){return this.chars.reverse(),this}get length(){return this.chars.length}buildString(){return this.chars.join("")}build(){return [...this.chars]}buildWithPadding(e){let t=[...this.chars],r=e;if(!r){let o=["=",".","_","-","~","!"];for(let s of o)if(!t.includes(s)){r=s;break}if(!r)throw new Error("Cannot find suitable padding character")}return {charset:t,padding:r}}};function It(n,e){let t=n.getCharSetInfo(),r=e?.compress??t.defaultCompress,o=(e?.encrypt??true)&&t.hasEncryptionKey,s=r?e?.compressionAlgorithm??t.defaultCompressionAlgorithm:void 0,i=t.paddingChar,a=!r&&!o,c=false,d=[],l=0,h=null;return new TransformStream({async transform(f,u){if(a){if(!c){let b=x(i,{compressionAlgorithm:void 0,encrypted:false});u.enqueue(b),c=true;}let m;h&&h.length>0?(m=new Uint8Array(h.length+f.length),m.set(h,0),m.set(f,h.length)):m=f;let g=t.bitLength,p=Ne(g,8)/8,y=Math.floor(m.length/p)*p;if(y>0){let b=m.subarray(0,y),L=await n.encodeAsync(b,{compress:false,encrypt:false,checksum:false,chunkSize:void 0,chunkSeparator:void 0,omitFooter:true});u.enqueue(L);}y<m.length?h=m.slice(y):h=null;}else d.push(f),l+=f.length;},async flush(f){try{if(a){if(!c){let u=x(i,{compressionAlgorithm:void 0,encrypted:!1});f.enqueue(u);}if(h&&h.length>0){let u=await n.encodeAsync(h,{compress:!1,encrypt:!1,checksum:!1,chunkSize:void 0,chunkSeparator:void 0});f.enqueue(u);}h=null;}else {let u=x(i,{compressionAlgorithm:s,encrypted:o});if(f.enqueue(u),l>0){let m=new Uint8Array(l),g=0;for(let y of d)m.set(y,g),g+=y.length;let p=await n.encodeAsync(m,{...e,compress:r,encrypt:o,checksum:!1,chunkSize:void 0,chunkSeparator:void 0});f.enqueue(p);}d=[],l=0;}}catch(u){f.error(u instanceof Error?u:new Error(String(u)));}}})}function Ot(n,e){let t=n.getCharSetInfo(),r=t.paddingChar,o=$(r),s="",i=false,a=null,c=false;return new TransformStream({async transform(d,l){if(s+=d,!i&&s.length>=o){if(!s.startsWith(r)){l.error(new Error("[WebStreams decode] Invalid or missing stream header"));return}if(a=le(s,r),a===null){l.error(new Error("[WebStreams decode] Invalid or missing stream header"));return}if(a.encrypted&&!t.hasEncryptionKey){l.error(new Error("[WebStreams decode] Encrypted stream requires an encryptionKey"));return}i=true,c=!a.compressionAlgorithm&&!a.encrypted,s=s.slice(o);}if(i&&c&&s.length>0){let h=t.bitLength,f=Ne(h,8)/h,u=Math.floor(s.length/f)*f;if(u>0){let m=s.slice(0,u);s=s.slice(u);try{let g=await n.decodeToUint8ArrayAsync(m,{compress:!1,encrypt:!1,checksum:!1,chunkSize:void 0,chunkSeparator:void 0});g.length>0&&l.enqueue(g);}catch{s=m+s;}}}},async flush(d){try{if(!i){if(s.length===0)return;d.error(new Error("[WebStreams decode] Incomplete stream header"));return}if(s.length===0)return;let l=a.compressionAlgorithm,h=a.encrypted,f=await n.decodeToUint8ArrayAsync(s,{...e,compress:!!l,compressionAlgorithm:l,encrypt:h,checksum:!1,chunkSize:void 0,chunkSeparator:void 0});f.length>0&&d.enqueue(f),s="";}catch(l){d.error(l instanceof Error?l:new Error(String(l)));}}})}function Ne(n,e){return n*e/Mt(n,e)}function Mt(n,e){for(;e!==0;){let t=e;e=n%e,n=t;}return n}M();re();oe();exports.CharsetBuilder=ie;exports.Ddu64=K;exports.Ddu64Core=v;exports.Ddu64Node=K;exports.DduSetSymbol=j;exports.HangulObfuscationLayer=C;exports.createObfuscationLayer=st;exports.createReadableDecodeStream=Ot;exports.createReadableEncodeStream=It;exports.detectRuntime=ne;exports.getAdapter=Ie;exports.getWasmCodec=lt;exports.getWasmCodecSync=O;exports.preloadWasm=dt;exports.setWorkerPoolSize=J;//# sourceMappingURL=index.cjs.map
7
7
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as Ddu64Core, a as DduConstructorOptions, b as DduOptions, P as PlatformAdapter, K as KeyDerivationOptions } from './core-BccIjoLZ.cjs';
2
- export { C as CharSetConfig, c as CharSetInfo, d as CharsetBuilder, e as DduEncodeStats, f as DduProgressInfo, g as DduSetSymbol, E as EncoderConfig, h as KeyDerivationAlgorithm, O as ObfuscationLayer, T as TestVector, W as WasmCodec, i as WorkerPool, j as getWasmCodec, k as getWasmCodecSync, p as preloadWasm } from './core-BccIjoLZ.cjs';
1
+ import { D as Ddu64Core, a as DduConstructorOptions, b as DduOptions, P as PlatformAdapter, K as KeyDerivationOptions } from './core-BpDwIO11.cjs';
2
+ export { C as CharSetConfig, c as CharSetInfo, d as CharsetBuilder, e as DduEncodeStats, f as DduProgressInfo, g as DduSetSymbol, E as EncoderConfig, h as KeyDerivationAlgorithm, O as ObfuscationLayer, T as TestVector, W as WasmCodec, i as WorkerPool, j as getWasmCodec, k as getWasmCodecSync, p as preloadWasm } from './core-BpDwIO11.cjs';
3
3
  export { BrowserAdapter, HangulObfuscationLayer, createObfuscationLayer, createReadableDecodeStream, createReadableEncodeStream, detectRuntime, getAdapter } from './browser.cjs';
4
4
 
5
5
  /**
@@ -29,7 +29,7 @@ export { BrowserAdapter, HangulObfuscationLayer, createObfuscationLayer, createR
29
29
  * ```
30
30
  */
31
31
  declare class Ddu64Node extends Ddu64Core {
32
- constructor(dduChar?: string[] | string, paddingChar?: string, dduOptions?: DduConstructorOptions);
32
+ constructor(dduChar?: string[] | string | DduConstructorOptions, paddingChar?: string, dduOptions?: DduConstructorOptions);
33
33
  /**
34
34
  * 인코딩된 문자열을 Node.js Buffer로 디코딩합니다.
35
35
  *
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as Ddu64Core, a as DduConstructorOptions, b as DduOptions, P as PlatformAdapter, K as KeyDerivationOptions } from './core-BccIjoLZ.js';
2
- export { C as CharSetConfig, c as CharSetInfo, d as CharsetBuilder, e as DduEncodeStats, f as DduProgressInfo, g as DduSetSymbol, E as EncoderConfig, h as KeyDerivationAlgorithm, O as ObfuscationLayer, T as TestVector, W as WasmCodec, i as WorkerPool, j as getWasmCodec, k as getWasmCodecSync, p as preloadWasm } from './core-BccIjoLZ.js';
1
+ import { D as Ddu64Core, a as DduConstructorOptions, b as DduOptions, P as PlatformAdapter, K as KeyDerivationOptions } from './core-BpDwIO11.js';
2
+ export { C as CharSetConfig, c as CharSetInfo, d as CharsetBuilder, e as DduEncodeStats, f as DduProgressInfo, g as DduSetSymbol, E as EncoderConfig, h as KeyDerivationAlgorithm, O as ObfuscationLayer, T as TestVector, W as WasmCodec, i as WorkerPool, j as getWasmCodec, k as getWasmCodecSync, p as preloadWasm } from './core-BpDwIO11.js';
3
3
  export { BrowserAdapter, HangulObfuscationLayer, createObfuscationLayer, createReadableDecodeStream, createReadableEncodeStream, detectRuntime, getAdapter } from './browser.js';
4
4
 
5
5
  /**
@@ -29,7 +29,7 @@ export { BrowserAdapter, HangulObfuscationLayer, createObfuscationLayer, createR
29
29
  * ```
30
30
  */
31
31
  declare class Ddu64Node extends Ddu64Core {
32
- constructor(dduChar?: string[] | string, paddingChar?: string, dduOptions?: DduConstructorOptions);
32
+ constructor(dduChar?: string[] | string | DduConstructorOptions, paddingChar?: string, dduOptions?: DduConstructorOptions);
33
33
  /**
34
34
  * 인코딩된 문자열을 Node.js Buffer로 디코딩합니다.
35
35
  *