/g,">"),n+=`${e}`}}t+='
'+`${o}`+`${i}`+`${n}`+"
"}hexOutput.innerHTML=t,hexOutput.style.transform=`translateY(${n*lineHeight}px)`,-1!==currentFind.lastFoundOffset&&highlightFindResult(currentFind.lastFoundOffset,currentFind.queryBytes.length),isRendering=!1}}function handlePointerMoveHighlight(e){if(!isRendering){e=e.target.closest(".hex-val, .ascii-char");if(e&&e.dataset.offset){var t=parseInt(e.dataset.offset,10);if(t!==currentHighlightOffset){clearHighlight(),currentHighlightOffset=t;var n=parseInt(e.dataset.size||"1",10),i=Array.from(hexOutput.querySelectorAll(`.hex-val[data-offset="${t}"]`)),r=[];for(let e=0;ee?.classList.add("highlight")),r.forEach(e=>e?.classList.add("highlight"))}}else-1!==currentHighlightOffset&&clearHighlight()}}function findHexSpanForOffset(e){var t;for(t of hexOutput.querySelectorAll(".hex-val[data-offset]")){var n=parseInt(t.dataset.offset,10),i=parseInt(t.dataset.size||"1",10);if(n<=e&&ee.classList.remove("highlight")),currentHighlightOffset=-1)}function handleGoto(){if(currentBytes){var e=gotoOffsetInput.value.trim();if(e){let n=parseInt(e,16);isNaN(n)||n<0||n>=currentBytes.length?(findStatus.textContent=`Invalid offset: ${e}. Max: `+(currentBytes.length-1).toString(16).toUpperCase(),findStatus.style.color="var(--color-error)"):(e=Math.floor(n/BYTES_PER_LINE)*lineHeight-containerHeight/3,clearFindState(),findStatus.textContent="Jumped to offset 0x"+n.toString(16).toUpperCase(),findStatus.style.color="var(--color-address)",outputContainer.scrollTop=Math.max(0,e),setTimeout(()=>{clearHighlight();let e=findHexSpanForOffset(n),t=hexOutput.querySelector(`.ascii-char[data-offset="${n}"]`);e?.classList.add("highlight"),t?.classList.add("highlight"),setTimeout(()=>{e?.classList.remove("highlight"),t?.classList.remove("highlight"),currentHighlightOffset!==n&&clearHighlight()},1500)},100))}}}function clearFindState(){currentFind.queryBytes=null,currentFind.lastFoundOffset=-1,currentFind.type=null,findStatus.textContent="",clearFoundHighlight()}function clearFoundHighlight(){hexOutput.querySelectorAll(".found").forEach(e=>e.classList.remove("found"))}function handleFind(n,i){if(currentBytes){var r,a=("hex"===n?findHexInput:findAsciiInput).value;if(a){let t=currentFind.lastFoundOffset;if(currentFind.type!==n||!arraysEqual(currentFind.queryBytes,parseQuery(a,n))){if(clearFindState(),currentFind.type=n,currentFind.queryBytes=parseQuery(a,n),!currentFind.queryBytes||0===currentFind.queryBytes.length)return findStatus.textContent="Invalid find query format.",findStatus.style.color="var(--color-error)",void(currentFind.type=null);t="next"===i?-1:currentBytes.length}if(currentFind.queryBytes){console.log(`Finding ${n} '${a}', direction: ${i}, startOffset: `+t);let e=findBytes(currentFind.queryBytes,t,i);-1!==e?(currentFind.lastFoundOffset=e,findStatus.textContent="Found at offset 0x"+e.toString(16).toUpperCase(),findStatus.style.color="var(--color-address)",r=(n=Math.floor(e/BYTES_PER_LINE))*lineHeight-containerHeight/3,outputContainer.scrollTop=Math.max(0,r),r=Math.floor(outputContainer.scrollTop/lineHeight),Math.abs(r-n)>visibleLines/2||(renderVisibleChunk(!0),setTimeout(()=>highlightFindResult(e,currentFind.queryBytes.length),50))):(findStatus.textContent=`"${a}" not found ${"next"===i?"after":"before"} offset 0x`+(-1===t?0:t.toString(16).toUpperCase()),findStatus.style.color="var(--color-address)",currentFind.lastFoundOffset="next"===i?currentBytes.length:-1)}}else clearFindState(),findStatus.textContent="Find query is empty.",findStatus.style.color="var(--color-address)"}}function parseQuery(e,t){if("hex"!==t)return(new TextEncoder).encode(e);var n=e.replace(/\s+/g,"");if(!/^[0-9a-fA-F]*$/.test(n)||n.length%2!=0)return null;var i=[];for(let e=0;e=i?0:e;t<=i-r;t++){let e=0;for(;e{"system"===themeSelector.value&&applyTheme("system")})}function applyTheme(e){var t=document.documentElement;"system"===e?(t.removeAttribute("data-theme"),localStorage.removeItem("theme")):(t.setAttribute("data-theme",e),localStorage.setItem("theme",e)),themeSelector.value=e}function formatFileSize(e){var t;return 0===e?"0 Bytes":(t=Math.floor(Math.log(e)/Math.log(1024)),parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB","TB"][t])}function debounce(t,n){let i;return function(...e){clearTimeout(i),i=setTimeout(()=>{clearTimeout(i),t(...e)},n)}}function arraysEqual(t,n){if(t!==n){if(null==t||null==n)return!1;if(t.length!==n.length)return!1;for(let e=0;e{initTheme(),initEventListeners(),calculateMetrics(),updateUIState()}),window.addEventListener("resize",debounce(handleResize,150))