/g,">")).replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,(function(e){let t="json-number";return/^"/.test(e)?t=/:$/.test(e)?"json-key":"json-string":/true|false/.test(e)?t="json-boolean":/null/.test(e)&&(t="json-null"),''+e+""}))}(t.formattedText);const i=document.createElement("div");i.className="preview-info",i.innerHTML=`\n
${t.fileName}
\n ${f(t.blob.size)}
\n `;const a=document.createElement("div");a.className="preview-actions",a.innerHTML=`\n \n \n \n `,o.appendChild(s),o.appendChild(i),o.appendChild(a),e.previewContainer.appendChild(o),o.querySelector('.preview-btn[title="Download"]').addEventListener("click",(function(){p(t.blob,t.fileName)})),o.querySelector('.preview-btn[title="Copy to Clipboard"]').addEventListener("click",(function(){navigator.clipboard.writeText(t.formattedText).then((()=>{m(`Copied ${t.fileName} to clipboard`,"success")})).catch((()=>{m("Failed to copy to clipboard","error")}))})),o.querySelector('.preview-btn[title="Collapse/Expand"]').addEventListener("click",(function(){s.classList.toggle("collapsed");const e=this.querySelector("i");s.classList.contains("collapsed")?(e.classList.remove("fa-compress-alt"),e.classList.add("fa-expand-alt")):(e.classList.remove("fa-expand-alt"),e.classList.add("fa-compress-alt"))}))}function p(e,t,n="application/json"){const o=URL.createObjectURL(e),s=document.createElement("a");s.href=o,s.download=t,document.body.appendChild(s),s.click(),setTimeout((()=>{document.body.removeChild(s),URL.revokeObjectURL(o)}),100)}function f(e){if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(1))+" "+["Bytes","KB","MB"][t]}function m(t,n){e.statusMessage&&(e.statusMessage.textContent=t,e.statusMessage.className="status-message "+n,setTimeout((()=>{e.statusMessage.className="status-message",e.statusMessage.textContent=""}),5e3))}["dragenter","dragover","dragleave","drop"].forEach((t=>{e.dropzone.addEventListener(t,o,!1)})),["dragenter","dragover"].forEach((t=>{e.dropzone.addEventListener(t,s,!1)})),["dragleave","drop"].forEach((t=>{e.dropzone.addEventListener(t,i,!1)})),e.dropzone.addEventListener("drop",(function(e){const t=e.dataTransfer.files;t.length>0&&a(t)}),!1),e.dropzone.addEventListener("click",(()=>e.fileInput.click())),e.fileInput.addEventListener("change",(function(){this.files.length>0&&a(this.files)})),e.jsonTextInput.addEventListener("input",(function(){this.value.trim()||t.length>0?e.formatBtn.disabled=!1:e.formatBtn.disabled=!0})),e.formatBtn.addEventListener("click",(async function(){if(0!==t.length||e.jsonTextInput.value.trim()){e.formatBtn.disabled=!0,e.formatBtn.innerHTML=' Processing...',e.progressContainer.style.display="block",e.progressFill.style.width="0%",e.progressText.textContent=`Processing 0 of ${t.length+(e.jsonTextInput.value.trim()?1:0)} items`;try{if(n=[],e.jsonTextInput.value.trim()){const t=e.jsonTextInput.value.trim(),o=await r(t,"input.json");n.push(o)}for(let o=0;o Format JSON',e.progressContainer.style.display="none"}}else m("No JSON data to format","error")})),e.downloadAllBtn.addEventListener("click",(function(){if(0!==n.length)if(e.progressContainer.style.display="block",e.progressFill.style.width="0%",e.progressText.textContent=`Preparing download 0 of ${n.length} files`,n.length>1){const t=new JSZip,o=t.folder("formatted_json");n.forEach(((t,s)=>{o.file(t.fileName,t.blob);const i=Math.round((s+1)/n.length*100);e.progressFill.style.width=`${i}%`,e.progressText.textContent=`Preparing download ${s+1} of ${n.length} files`})),t.generateAsync({type:"blob"}).then((function(t){p(t,"formatted_json.zip","application/zip"),e.progressContainer.style.display="none"}))}else p(n[0].blob,n[0].fileName),e.progressContainer.style.display="none";else m("No formatted JSON to download","error")}))}))