0xf1da6e2d…0013sent to0x3e399623…4ab0·#25,629,347·view on Etherscan
N const SVG_NS="http://www.w3.org/2000/svg",WIDTH=1500,HEIGHT=2e3;class Random{constructor(e){this.seed=this.hashToSeed(e)}hashToSeed(e){const t=e.startsWith("0x")?e.slice(2):e;let n=0;for(let e=0;e<t.length;e++)n=(n<<5)-n+t.charCodeAt(e),n>>>=0;return n}next(){this.seed+=1831565813;let e=this.seed;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}decimal(e=0,t=1){return e+this.next()*(t-e)}int(e,t){return Math.floor(this.decimal(e,t+1))}bool(e=.5){return this.next()<e}}function generateHash(){const e=new Uint8Array(32);return crypto.getRandomValues(e),"0x"+Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")}function getSeedOverride(){if("undefined"!=typeof location&&location.search){const e=new URLSearchParams(location.search).get("seed");if(e)return e}return null}let rng,IS_LIGHT,OUTER_BG,STROKE_SCALE,OPACITY_SCALE,STROKE_MIN_SCALE,STEP_LENGTH,DEPTH_OPACITY_MIN,TEXTURE2_SATURATION,ANGLE_MULTIPLIER,FLOW_SCALE,Z_MIN,REVEAL_WINDOW_MS,REVEAL_PATH_MS,HASH=getSeedOverride()||window.__ANGEL_HASH__||generateHash();function getTheme(e){let t=window.__MUGEN_THEME__;if("undefined"!=typeof location&&location.search){const e=new URLSearchParams(location.search).get("theme");e&&(t=e)}if("light"===t||"dark"===t)return t;const n=e.startsWith("0x")?e.slice(2):e;return parseInt(n.slice(2,4),16)<77?"light":"dark"}function getFlatMode(){return!!window.__ANGEL_FLAT__||!("undefined"==typeof location||!location.search)&&"1"===new URLSearchParams(location.search).get("flat")}const IS_FLAT=getFlatMode(),IS_DESKTOP="function"==typeof window.matchMedia&&window.matchMedia("(hover: hover) and (pointer: fine)").matches;function getAngleMultiplier(e){const t=e.startsWith("0x")?e.slice(2):e;return[2,3,4,5][parseInt(t.slice(0,2),16)%4]}function deriveState(e){rng=new Random(e),IS_LIGHT="light"===getTheme(e),OUTER_BG=IS_LIGHT?"#fff":"#000",STROKE_SCALE=IS_LIGHT?rng.bool(.5)?1.2:1.5:rng.bool(.5)?1:1.3,OPACITY_SCALE=IS_LIGHT?1.5:1,STROKE_MIN_SCALE=rng.decimal(.1,.8),STEP_LENGTH=rng.bool(.5)?20:30,DEPTH_OPACITY_MIN=rng.bool(.5)?.3:.4,TEXTURE2_SATURATION=rng.decimal(10,70),ANGLE_MULTIPLIER=getAngleMultiplier(e),FLOW_SCALE=(()=>{const e=.001,t=rng.next(),n=.535;return e+.004*(t<n?Math.sqrt(t*n):1-Math.sqrt((1-t)*(1-n)))})(),Z_MIN=rng.decimal(.01,.62),REVEAL_WINDOW_MS=20===STEP_LENGTH?2400:1800,REVEAL_PATH_MS=20===STEP_LENGTH?400:200}deriveState(HASH);let noiseSeed=0;function noise(e,t){const n=Math.floor(e),o=Math.floor(t),r=e-n,s=t-o,a=r*r*(3-2*r),i=s*s*(3-2*s),c=(e,t)=>{const n=43758.5453*Math.sin(127.1*e+311.7*t+noiseSeed);return n-Math.floor(n)},l=c(n,o),d=c(n+1,o),u=c(n,o+1);return l+a*(d-l)+i*(u-l)+a*i*(l-d-u+c(n+1,o+1))}let angleOffset=0;function getAngle(e,t){return noise(e*FLOW_SCALE,t*FLOW_SCALE)*Math.PI*ANGLE_MULTIPLIER+angleOffset}const VANISHING_POINT={x:750,y:1e3},Z_MAX=.98;function applyPerspective(e,t){return e.map(e=>{const n=e.x-VANISHING_POINT.x,o=e.y-VANISHING_POINT.y;return{x:VANISHING_POINT.x+n*t,y:VANISHING_POINT.y+o*t}})}function createPath(e,t,n){const o=document.createElementNS(SVG_NS,"path");let r=`M ${e[0].x} ${e[0].y}`;for(let t=1;t<e.length;t++)r+=` L ${e[t].x} ${e[t].y}`;return o.setAttribute("d",r),o.setAttribute("fill","none"),o.setAttribute("stroke",`rgba(255,255,255,${n})`),o.setAttribute("stroke-width",t),o.setAttribute("stroke-linecap","round"),o}function flowLine(e,t,n,o=3,r=[]){const s=[];let a=e,i=t;for(let e=0;e<n;e++){s.push({x:a,y:i});let t=getAngle(a,i);if(t+=rng.decimal(-.65,.65),a+=Math.cos(t)*STEP_LENGTH,i+=Math.sin(t)*STEP_LENGTH,a<0||a>1500||i<0||i>2e3)break;if(o>0&&e>5&&rng.bool(.03)){const e=t+rng.decimal(-.5,.5),s=Math.floor(n*rng.decimal(.4,.7));flowLine(a+Math.cos(e)*STEP_LENGTH,i+Math.sin(e)*STEP_LENGTH,s,o-1,r)}}return s.length>1&&r.push(s),r}function createSVG(){const e=document.createElementNS(SVG_NS,"svg");return e.setAttribute("width","100%"),e.setAttribute("height","100%"),e.setAttribute("viewBox","0 0 1500 2000"),e.setAttribute("preserveAspectRatio","xMidYMid meet"),e.style.background=OUTER_BG,e}function buildDensityMap(e,t=100){const n=Math.ceil(1500/t),o=Math.ceil(2e3/t),r=Array(n*o).fill(0);for(const s of e)for(const e of s){const s=Math.floor(e.x/t),a=Math.floor(e.y/t);s>=0&&s<n&&a>=0&&a<o&&r[a*n+s]++}return{density:r,cols:n,rows:o,cellSize:t}}function pathInDenseArea(e,t,n){const{density:o,cols:r,rows:s,cellSize:a}=t;let i=0;for(const t of e){const e=Math.floor(t.x/a),c=Math.floor(t.y/a);e>=0&&e<r&&c>=0&&c<s&&o[c*r+e]>n&&i++}return i>.8*e.length}const FRAME_MARGIN=30,BACK_INSET_X=450,BACK_INSET_Y=600;function handDrawnEdge(e,t,n=24,o=1.2){const r=[];for(let s=0;s<=n;s++){const a=s/n,i=e.x+(t.x-e.x)*a+rng.decimal(-o,o),c=e.y+(t.y-e.y)*a+rng.decimal(-o,o);r.push({x:i,y:c})}return r}function addRoom(e){const t={x:30,y:30},n={x:1470,y:30},o={x:1470,y:1970},r={x:30,y:1970},s={x:450,y:600},a={x:1050,y:600},i={x:1050,y:1400},c={x:450,y:1400},l=[[t,n],[n,o],[o,r],[r,t],[s,a],[a,i],[i,c],[c,s],[t,s],[n,a],[o,i],[r,c]];for(const[t,n]of l){const o=handDrawnEdge(t,n),r=rng.decimal(.4,1.2),s=rng.decimal(.6,1);e.appendChild(createPath(o,r,s))}}function scribblePoints(e,t){const n=rng.int(2,5);let o=e,r=t;const s=[{x:o,y:r}];for(let e=0;e<n;e++){const e=rng.decimal(3,8),t=rng.decimal(0,2*Math.PI);o+=Math.cos(t)*e,r+=Math.sin(t)*e,s.push({x:o,y:r})}return s}function bezierScratchPoints(e,t){const n=rng.decimal(5,20),o=rng.decimal(0,2*Math.PI),r=e+Math.cos(o)*n,s=t+Math.sin(o)*n,a=e+rng.decimal(-8,8),i=t+rng.decimal(-8,8),c=r+rng.decimal(-8,8),l=s+rng.decimal(-8,8),d=[];for(let n=0;n<=10;n++){const o=n/10,u=1-o;d.push({x:u*u*u*e+3*u*u*o*a+3*u*o*o*c+o*o*o*r,y:u*u*u*t+3*u*u*o*i+3*u*o*o*l+o*o*o*s})}return d}function loopScribblePoints(e,t){const n=rng.decimal(2,6),o=rng.int(4,8),r=[];for(let s=0;s<=o;s++){const a=s/o;r.push({x:e+Math.cos(a*Math.PI*4)*n+rng.decimal(-1,1),y:t+Math.sin(a*Math.PI*4)*n*.5+a*n*2+rng.decimal(-1,1)})}return r}function addScratches(e){for(let t=0;t<140;t++){const t=rng.decimal(0,1500),n=rng.decimal(0,2e3),o=rng.decimal(.05,.35),r=rng.decimal(.15,.5),s=rng.int(0,2);let a;a=0===s?scribblePoints(t,n):1===s?bezierScratchPoints(t,n):loopScribblePoints(t,n),e.appendChild(createPath(a,r,o))}}function getDefs(e){let t=e.querySelector("defs");return t||(t=document.createElementNS(SVG_NS,"defs"),e.insertBefore(t,e.firstChild)),t}function addGrain(e,t){const n=getDefs(e),o=document.createElementNS(SVG_NS,"filter");o.setAttribute("id","grain"),o.setAttribute("x","0%"),o.setAttribute("y","0%"),o.setAttribute("width","100%"),o.setAttribute("height","100%");const r=document.createElementNS(SVG_NS,"feTurbulence");r.setAttribute("type","fractalNoise"),r.setAttribute("baseFrequency","0.95"),r.setAttribute("numOctaves","10"),r.setAttribute("seed",String(rng.int(1,1e3))),r.setAttribute("result","noise"),o.appendChild(r);const s=document.createElementNS(SVG_NS,"feColorMatrix");s.setAttribute("in","noise"),s.setAttribute("type","saturate"),s.setAttribute("values","0"),o.appendChild(s),n.appendChild(o);const a=document.createElementNS(SVG_NS,"rect");a.setAttribute("x",0),a.setAttribute("y",0),a.setAttribute("width",1500),a.setAttribute("height",2e3),a.setAttribute("filter","url(#grain)"),a.setAttribute("opacity","0.3"),a.style.mixBlendMode="screen",a.style.pointerEvents="none",a.classList.add("s-overlay"),t.appendChild(a)}function addLightFlipFilter(e){const t=getDefs(e),n=document.createElementNS(SVG_NS,"filter");n.setAttribute("id","lightFlip"),n.setAttribute("x","0%"),n.setAttribute("y","0%"),n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.setAttribute("color-interpolation-filters","sRGB");const o=document.createElementNS(SVG_NS,"feComponentTransfer");for(const e of["feFuncR","feFuncG","feFuncB"]){const t=document.createElementNS(SVG_NS,e);t.setAttribute("type","table"),t.setAttribute("tableValues","1 0"),o.appendChild(t)}n.appendChild(o);const r=document.createElementNS(SVG_NS,"feColorMatrix");r.setAttribute("type","hueRotate"),r.setAttribute("values","180"),n.appendChild(r);const s=(1/.7).toFixed(3),a=(-.2/.7).toFixed(3),i=document.createElementNS(SVG_NS,"feComponentTransfer");for(const e of["feFuncR","feFuncG","feFuncB"]){const t=document.createElementNS(SVG_NS,e);t.setAttribute("type","linear"),t.setAttribute("slope",s),t.setAttribute("intercept",a),i.appendChild(t)}n.appendChild(i),t.appendChild(n)}const SCALE_FACTOR=1.5;function bakeTexture(e,t,n){const o=document.createElement("canvas");o.width=1500,o.height=2e3;const r=o.getContext("2d");r.fillStyle=e;for(let e=0;e<2e3;e+=t)for(let o=0;o<1500;o+=t){const t=1.5*rng.decimal(-.3,.3),s=1.5*rng.decimal(-.3,.3),a=Math.max(0,n());r.beginPath(),r.ellipse(o+t,e+s,a/2,a/2,0,0,2*Math.PI),r.fill()}return o.toDataURL("image/png")}function addTextureLayer(e,t,n){const o=document.createElementNS(SVG_NS,"image");o.setAttributeNS("http://www.w3.org/1999/xlink","href",t),o.setAttribute("href",t),o.setAttribute("x",0),o.setAttribute("y",0),o.setAttribute("width",1500),o.setAttribute("height",2e3),o.style.mixBlendMode=n,o.style.pointerEvents="none",o.classList.add("s-overlay"),e.appendChild(o)}function applyTexture(e){addTextureLayer(e,bakeTexture("hsl(30, 100%, 40%)",12,()=>1.5*(1+rng.decimal(-1,.5))),"color-dodge")}function applyTexture2(e){addTextureLayer(e,bakeTexture(`hsl(30, ${TEXTURE2_SATURATION}%, 80%)`,6,()=>1.5*(3+.15*rng.decimal())),"color-burn")}const REVEAL_OVERLAY_MS=0,REVEAL_EASE="cubic-bezier(0.33, 1, 0.68, 1)";function revealDrawing(e){const t=e.querySelectorAll("path"),n=e.querySelectorAll(".s-overlay");t.forEach(e=>{const t=e.getTotalLength();e.style.transition="none",e.style.strokeDasharray=`${t}`,e.style.strokeDashoffset=`${t}`,e.style.opacity="0"});const o=[];n.forEach(e=>{o.push(e.getAttribute("opacity")||"1"),e.style.transition="none",e.style.opacity="0"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{const e=t.length||1;t.forEach((t,n)=>{const o=REVEAL_WINDOW_MS*n/e;t.style.transition=`stroke-dashoffset ${REVEAL_PATH_MS}ms ${REVEAL_EASE} ${o}ms, opacity ${REVEAL_PATH_MS}ms ${REVEAL_EASE} ${o}ms`,t.style.strokeDashoffset="0",t.style.opacity="1"}),n.forEach((e,t)=>{e.style.transition=`opacity 0ms ease ${REVEAL_WINDOW_MS}ms`,e.style.opacity=o[t]})})})}function addBackground(e){const t=document.createElementNS(SVG_NS,"rect");t.setAttribute("x",0),t.setAttribute("y",0),t.setAttribute("width",1500),t.setAttribute("height",2e3),t.setAttribute("fill","#000"),e.appendChild(t)}function init(){const e=createSVG();document.body.appendChild(e);const t=document.createElementNS(SVG_NS,"g");IS_LIGHT&&(addLightFlipFilter(e),t.setAttribute("filter","url(#lightFlip)")),e.appendChild(t),addBackground(t),addRoom(t);const n=200,o=[];for(let e=0;e<4;e++){noiseSeed=rng.decimal(0,1e4),angleOffset=rng.decimal(0,2*Math.PI);const e=[];for(let t=n;t<1300;t+=100)for(let o=n;o<1800;o+=100){const n=flowLine(t+rng.decimal(-5,5),o+rng.decimal(-5,5),rng.int(40,120));e.push(...n)}const t=buildDensityMap(e),r=[...t.density].sort((e,t)=>e-t),s=r[Math.floor(.75*r.length)];for(const n of e)if(n.length>1&&pathInDenseArea(n,t,s)){const e=rng.decimal(STROKE_MIN_SCALE,1)*STROKE_SCALE,t=rng.decimal(.4,1)*OPACITY_SCALE,r=rng.decimal(Z_MIN,.98);o.push({points:n,strokeWidth:e,opacity:t,z:r})}}o.sort((e,t)=>e.z-t.z);for(const e of o){const n=applyPerspective(e.points,e.z),o=e.strokeWidth*e.z,r=e.opacity*(DEPTH_OPACITY_MIN+(1-DEPTH_OPACITY_MIN)*((e.z-Z_MIN)/(.98-Z_MIN)));t.appendChild(createPath(n,o,r))}addScratches(t),IS_FLAT||(addGrain(e,t),applyTexture(t),applyTexture2(t)),revealDrawing(e)}function rasterizeSVG(){return new Promise((e,t)=>{const n=document.querySelector("svg");if(!n)return t(new Error("No SVG to rasterize"));const o=n.cloneNode(!0);o.setAttribute("width",1500),o.setAttribute("height",2e3);const r=(new XMLSerializer).serializeToString(o),s=new Blob(['<?xml version="1.0" encoding="UTF-8"?>\n',r],{type:"image/svg+xml;charset=utf-8"}),a=URL.createObjectURL(s),i=new Image;i.onload=()=>{const n=document.createElement("canvas");n.width=1500,n.height=2e3;const o=n.getContext("2d");o.fillStyle=OUTER_BG,o.fillRect(0,0,1500,2e3),o.drawImage(i,0,0,1500,2e3),n.toBlob(n=>{if(URL.revokeObjectURL(a),!n)return t(new Error("Canvas toBlob returned null"));e(n)},"image/png")},i.onerror=e=>{URL.revokeObjectURL(a),t(e)},i.src=a})}function saveScreenshot(){rasterizeSVG().then(e=>{const t=document.createElement("a");t.download=`mugen-${HASH.slice(2,10)}.png`,t.href=URL.createObjectURL(e),t.click(),URL.revokeObjectURL(t.href)}).catch(e=>console.error("Failed to save screenshot",e))}function createCopyIndicator(){const e=document.createElement("div");return e.style.position="fixed",e.style.left="50%",e.style.top="50%",e.style.transform="translate(-50%, -50%)",e.style.padding="8px 16px",e.style.borderRadius="3px",e.style.fontFamily="system-ui, sans-serif",e.style.fontSize="12px",e.style.letterSpacing="0.08em",e.style.textTransform="uppercase",e.style.pointerEvents="none",e.style.opacity="0",e.style.transition="opacity 200ms ease",e.style.zIndex="9999",document.body.appendChild(e),e}const copyIndicator=createCopyIndicator();let copyIndicatorTimeout=null;function showCopyIndicator(e,t){clearTimeout(copyIndicatorTimeout),copyIndicator.textContent=e,copyIndicator.style.color=t?"#f66":IS_LIGHT?"#000":"#fff",copyIndicator.style.background=t?"rgba(255,0,0,0.12)":IS_LIGHT?"rgba(0,0,0,0.08)":"rgba(255,255,255,0.12)",copyIndicator.style.opacity="1",copyIndicatorTimeout=setTimeout(()=>{copyIndicator.style.opacity="0"},900)}function copyScreenshot(){if(!navigator.clipboard||!navigator.clipboard.write)return showCopyIndicator("Copy unsupported",!0),void console.error("Clipboard write API unavailable (needs HTTPS or localhost)");document.hasFocus()||window.focus(),navigator.clipboard.write([new ClipboardItem({"image/png":rasterizeSVG()})]).then(()=>{showCopyIndicator("Copied",!1)}).catch(e=>{showCopyIndicator("NotAllowedError"===e.name&&/focus/i.test(e.message)?"Click page, then retry":"Copy failed",!0),console.error("Failed to copy image to clipboard",e)})}function createContextMenu(){const e=document.createElement("div");e.style.position="fixed",e.style.display="none",e.style.zIndex="10000",e.style.background=IS_LIGHT?"#fff":"#1a1a1a",e.style.color=IS_LIGHT?"#000":"#fff",e.style.border="1px solid "+(IS_LIGHT?"rgba(0,0,0,0.15)":"rgba(255,255,255,0.15)"),e.style.borderRadius="6px",e.style.boxShadow="0 4px 16px rgba(0,0,0,0.3)",e.style.padding="4px",e.style.fontFamily="system-ui, sans-serif",e.style.fontSize="13px",e.style.minWidth="160px",e.style.userSelect="none",e.style.cursor="default";const t=[{label:"Copy Image",action:copyScreenshot},{label:"Save Image As…",action:saveScreenshot}];for(const{label:n,action:o}of t){const t=document.createElement("div");t.textContent=n,t.style.padding="7px 12px",t.style.borderRadius="4px",t.style.cursor="pointer",t.addEventListener("mouseenter",()=>{t.style.background=IS_LIGHT?"rgba(0,0,0,0.08)":"rgba(255,255,255,0.14)"}),t.addEventListener("mouseleave",()=>{t.style.background="transparent"}),t.addEventListener("click",e=>{e.stopPropagation(),hideContextMenu(),o()}),e.appendChild(t)}return document.body.appendChild(e),e}const contextMenu=createContextMenu();function hideContextMenu(){contextMenu.style.display="none"}function showContextMenu(e,t){contextMenu.style.left="0px",contextMenu.style.top="0px",contextMenu.style.display="block";const n=contextMenu.getBoundingClientRect(),o=window.innerWidth-n.width-4,r=window.innerHeight-n.height-4;contextMenu.style.left=`${Math.max(0,Math.min(e,o))}px`,contextMenu.style.top=`${Math.max(0,Math.min(t,r))}px`}document.addEventListener("keydown",e=>{(!e.target||"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName)&&("s"!==e.key&&"S"!==e.key||(e.preventDefault(),saveScreenshot()),"Escape"===e.key&&hideContextMenu())}),document.addEventListener("contextmenu",e=>{e.preventDefault(),showContextMenu(e.clientX,e.clientY)}),document.addEventListener("click",e=>{"block"!==contextMenu.style.display||contextMenu.contains(e.target)||hideContextMenu()});const REFRESH_INTERVAL_MS=3e5;function regenerate(){const e=document.querySelector("svg");e&&e.remove(),init()}function createRefreshIndicator(){const e=document.createElement("div");return e.style.position="fixed",e.style.right="14px",e.style.bottom="14px",e.style.width="5px",e.style.height="5px",e.style.borderRadius="50%",e.style.background=IS_LIGHT?"#000":"#fff",e.style.opacity="0",e.style.pointerEvents="none",document.body.appendChild(e),e}const refreshDot=createRefreshIndicator();function armRefreshIndicator(){refreshDot.style.transition="none",refreshDot.style.opacity="0",requestAnimationFrame(()=>{requestAnimationFrame(()=>{refreshDot.style.transition="opacity 300000ms linear",refreshDot.style.opacity="0.2"})})}function loadSeed(e){const t=e.trim();if(!t)return;if("data:"===location.protocol){HASH=t,deriveState(HASH),regenerate(),armRefreshIndicator();const e=document.getElementById("seed-input");return void(e&&(e.value=HASH))}const n=new URL(location.href);n.searchParams.set("seed",t),location.href=n.toString()}document.addEventListener("dblclick",()=>{loadSeed(generateHash())}),document.body.style.cursor="pointer",armRefreshIndicator(),setInterval(()=>{regenerate(),armRefreshIndicator()},3e5);const REGISTRY_ADDRESS="0xff91edfbd3ec3867dd9a68b8bbfde09f002daceb",PUBLIC_RPC_URL="https://ethereum-rpc.publicnode.com";function hexToBytes(e){const t=e.startsWith("0x")?e.slice(2):e,n=new Uint8Array(t.length/2);for(let e=0;e<n.length;e++)n[e]=parseInt(t.substr(2*e,2),16);return n}function bytesToHex(e){return Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")}function padHexWord(e){return e.padStart(64,"0")}function readUintAt(e,t){return Number(BigInt("0x"+bytesToHex(e.slice(t,t+32))))}function readAddressAt(e,t){return"0x"+bytesToHex(e.slice(t+12,t+32))}function encodeSavedSeedsCountCalldata(){return"0xd1fc0fc7"}function encodeGetSavedSeedsCalldata(e,t){return"0x7909fe9f"+padHexWord(e.toString(16))+padHexWord(t.toString(16))}function decodeSavedSeeds(e){const t=hexToBytes(e);if(0===t.length)return[];const n=readUintAt(t,0),o=readUintAt(t,32),r=readUintAt(t,64),s=readUintAt(t,n),a=[];for(let e=0;e<s;e++)a.push(readAddressAt(t,n+32+32*e));const i=o+32,c=readUintAt(t,o),l=[];for(let e=0;e<c;e++){const n=i+readUintAt(t,i+32*e),o=readUintAt(t,n);l.push((new TextDecoder).decode(t.slice(n+32,n+32+o)))}const d=readUintAt(t,r),u=[];for(let e=0;e<d;e++)u.push(readUintAt(t,r+32+32*e));const p=[],y=Math.min(a.length,l.length,u.length);for(let e=0;e<y;e++)p.push({saver:a[e],seed:l[e],timestamp:u[e]});return p}async function rpcCall(e,t){const n=await fetch(PUBLIC_RPC_URL,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:e,params:t})}),o=await n.json();if(o.error)throw new Error(o.error.message||"RPC error");return o.result}async function fetchSavedSeedsTotal(){const e=await rpcCall("eth_call",[{to:REGISTRY_ADDRESS,data:encodeSavedSeedsCountCalldata()},"latest"]);return Number(BigInt(e))}async function fetchSavedSeedsPage(e,t){return decodeSavedSeeds(await rpcCall("eth_call",[{to:REGISTRY_ADDRESS,data:encodeGetSavedSeedsCalldata(e,t)},"latest"]))}function createSeedControls(){const e=IS_LIGHT?"#000":"#fff",t=IS_LIGHT?"rgba(0,0,0,0.06)":"rgba(255,255,255,0.08)",n=IS_LIGHT?"rgba(0,0,0,0.18)":"rgba(255,255,255,0.18)",o=document.createElement("div");o.style.position="fixed",o.style.left="14px",o.style.bottom="14px",o.style.zIndex="9998",o.style.opacity="0",o.style.transition="opacity 200ms ease",o.style.cursor="default";const r=e=>e.stopPropagation();["click","dblclick","mousedown","contextmenu"].forEach(e=>{o.addEventListener(e,r)});const s=o=>{o.style.fontFamily="system-ui, sans-serif",o.style.fontSize="11px",o.style.color=e,o.style.background=t,o.style.border=`1px solid ${n}`,o.style.borderRadius="4px",o.style.padding="5px 8px",o.style.cursor="pointer"},a=document.createElement("div");a.style.display="flex",a.style.alignItems="center",a.style.gap="5px";const i=document.createElement("input");i.id="seed-input",i.type="text",i.value=HASH,i.placeholder="seed…",i.spellcheck=!1,i.autocomplete="off",i.style.width="104px",i.style.fontFamily="ui-monospace, monospace",i.style.fontSize="11px",i.style.color=e,i.style.background=t,i.style.border=`1px solid ${n}`,i.style.borderRadius="4px",i.style.padding="5px 8px",i.style.outline="none";const c=document.createElement("button");c.textContent="View",s(c);const l=document.createElement("button");l.textContent="Copy seed",s(l);const d=document.createElement("button");d.textContent="Saved ▾",s(d);const u=document.createElement("div");u.style.position="absolute",u.style.left="0",u.style.bottom="100%",u.style.marginBottom="6px",u.style.display="none",u.style.flexDirection="column",u.style.gap="2px",u.style.maxHeight="180px",u.style.overflowY="auto",u.style.minWidth="220px",u.style.padding="6px",u.style.borderRadius="6px",u.style.background=IS_LIGHT?"#fff":"#1a1a1a",u.style.border=`1px solid ${n}`,u.style.boxShadow="0 4px 16px rgba(0,0,0,0.3)",u.style.fontFamily="ui-monospace, monospace",u.style.fontSize="10.5px";const p=(t,n)=>{u.textContent="";const o=document.createElement("div");o.textContent=t,o.style.padding="4px 6px",o.style.color=n?"#f66":e,n||(o.style.opacity="0.6"),u.appendChild(o)};i.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),loadSeed(i.value))}),c.addEventListener("click",()=>loadSeed(i.value)),l.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(HASH),showCopyIndicator("Seed copied",!1)}catch(e){showCopyIndicator("Copy failed",!0),console.error("Failed to copy seed",e)}});let y=0,f=null;const h=t=>{const n=document.createElement("div");return n.textContent=`${t.saver.slice(0,6)}…${t.saver.slice(-4)} ${t.seed.slice(0,12)}…`,n.style.padding="4px 6px",n.style.borderRadius="4px",n.style.cursor="pointer",n.style.color=e,n.style.whiteSpace="nowrap",n.addEventListener("mouseenter",()=>{n.style.background=IS_LIGHT?"rgba(0,0,0,0.08)":"rgba(255,255,255,0.14)"}),n.addEventListener("mouseleave",()=>{n.style.background="transparent"}),n.addEventListener("click",()=>loadSeed(t.seed)),n},m=()=>{f&&(f.remove(),f=null)};async function S(t){try{if(t){const e=await fetchSavedSeedsTotal();if(u.textContent="",f=null,0===e)return void p("No saved seeds yet",!1);y=e}else f&&(f.textContent="Loading…");const n=y>25?y-25:0,o=y-n,r=await fetchSavedSeedsPage(n,o);y=n,m();for(const e of r.slice().reverse())u.appendChild(h(e));y>0&&(m(),f=document.createElement("div"),f.textContent="Load more…",f.style.padding="4px 6px",f.style.marginTop="2px",f.style.borderRadius="4px",f.style.cursor="pointer",f.style.color=e,f.style.opacity="0.7",f.style.textAlign="center",f.addEventListener("mouseenter",()=>{f.style.background=IS_LIGHT?"rgba(0,0,0,0.08)":"rgba(255,255,255,0.14)"}),f.addEventListener("mouseleave",()=>{f.style.background="transparent"}),f.addEventListener("click",()=>S(!1)),u.appendChild(f))}catch(e){p("Failed to load",!0),console.error("Failed to fetch saved seeds",e)}}d.addEventListener("click",()=>{if(!("none"===u.style.display))return u.style.display="none",void E();u.style.display="flex",x(),p("Loading…",!1),S(!0)});const g=document.createElement("div");g.textContent="Double click for new seed",g.style.marginBottom="6px",g.style.opacity="0.6",g.style.pointerEvents="none",g.style.fontFamily="system-ui, sans-serif",g.style.fontSize="11px",g.style.letterSpacing="0.02em",g.style.color=e;const x=()=>{o.style.opacity="1"},E=()=>{document.activeElement!==i&&"none"===u.style.display&&(o.style.opacity="0")};document.addEventListener("mousemove",x),document.addEventListener("mouseleave",E),i.addEventListener("focus",x),i.addEventListener("blur",E),document.addEventListener("click",e=>{"none"===u.style.display||o.contains(e.target)||(u.style.display="none",E())}),a.appendChild(i),a.appendChild(c),a.appendChild(l),a.appendChild(d),o.appendChild(u),o.appendChild(g),o.appendChild(a),document.body.appendChild(o),"function"==typeof window.__seedControlsExtend&&window.__seedControlsExtend({row1:a,savedToggleBtn:d,buttonStyle:s,input:i})}IS_DESKTOP&&createSeedControls(),init();