screeps-client 0.3.3 → 0.3.4

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.
@@ -0,0 +1,24 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePanel-CBhC-97J.js","assets/vendor-codemirror-D3PB7yT8.js","assets/vendor-pixi-CXkRT4gi.js","assets/MapViewer-TlyktL4n.js"])))=>i.map(i=>d[i]);
2
+ var mo=Object.defineProperty;var yo=(r,e,t)=>e in r?mo(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var _=(r,e,t)=>yo(r,typeof e!="symbol"?e+"":e,t);import{k as os,j as A,i as vr,v as ls,w as xe,$ as vo,u as Ce,l as N,p as be,f as k,F as pe,S as X,h as he,r as Ie,D as bo,a as Tt,d as wo,b as wn,m as Li,s as Cr,q as xo,o as as}from"./vendor-codemirror-D3PB7yT8.js";import{a as Re,G as K,A as cs,P as rr,R as ds,N as $o,S as Zt,B as _o,c as yt,T as qt,b as So,C as ko,_ as us}from"./vendor-pixi-CXkRT4gi.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))i(n);new MutationObserver(n=>{for(const s of n)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function t(n){const s={};return n.integrity&&(s.integrity=n.integrity),n.referrerPolicy&&(s.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?s.credentials="include":n.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function i(n){if(n.ep)return;n.ep=!0;const s=t(n);fetch(n.href,s)}})();const Co=["allowfullscreen","async","alpha","autofocus","autoplay","checked","controls","default","disabled","formnovalidate","hidden","indeterminate","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","seamless","selected","adauctionheaders","browsingtopics","credentialless","defaultchecked","defaultmuted","defaultselected","defer","disablepictureinpicture","disableremoteplayback","preservespitch","shadowrootclonable","shadowrootcustomelementregistry","shadowrootdelegatesfocus","shadowrootserializable","sharedstoragewritable"],To=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline","adAuctionHeaders","allowFullscreen","browsingTopics","defaultChecked","defaultMuted","defaultSelected","disablePictureInPicture","disableRemotePlayback","preservesPitch","shadowRootClonable","shadowRootCustomElementRegistry","shadowRootDelegatesFocus","shadowRootSerializable","sharedStorageWritable",...Co]),Mo=new Set(["innerHTML","textContent","innerText","children"]),Eo=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),Po=Object.assign(Object.create(null),{class:"className",novalidate:{$:"noValidate",FORM:1},formnovalidate:{$:"formNoValidate",BUTTON:1,INPUT:1},ismap:{$:"isMap",IMG:1},nomodule:{$:"noModule",SCRIPT:1},playsinline:{$:"playsInline",VIDEO:1},readonly:{$:"readOnly",INPUT:1,TEXTAREA:1},adauctionheaders:{$:"adAuctionHeaders",IFRAME:1},allowfullscreen:{$:"allowFullscreen",IFRAME:1},browsingtopics:{$:"browsingTopics",IMG:1},defaultchecked:{$:"defaultChecked",INPUT:1},defaultmuted:{$:"defaultMuted",AUDIO:1,VIDEO:1},defaultselected:{$:"defaultSelected",OPTION:1},disablepictureinpicture:{$:"disablePictureInPicture",VIDEO:1},disableremoteplayback:{$:"disableRemotePlayback",AUDIO:1,VIDEO:1},preservespitch:{$:"preservesPitch",AUDIO:1,VIDEO:1},shadowrootclonable:{$:"shadowRootClonable",TEMPLATE:1},shadowrootdelegatesfocus:{$:"shadowRootDelegatesFocus",TEMPLATE:1},shadowrootserializable:{$:"shadowRootSerializable",TEMPLATE:1},sharedstoragewritable:{$:"sharedStorageWritable",IFRAME:1,IMG:1}});function Ro(r,e){const t=Po[r];return typeof t=="object"?t[e]?t.$:void 0:t}const Oo=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),Lo=new Set(["altGlyph","altGlyphDef","altGlyphItem","animate","animateColor","animateMotion","animateTransform","circle","clipPath","color-profile","cursor","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","font","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignObject","g","glyph","glyphRef","hkern","image","line","linearGradient","marker","mask","metadata","missing-glyph","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tref","tspan","use","view","vkern"]),Ao={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},re=r=>vr(()=>r());function Io(r,e,t){let i=t.length,n=e.length,s=i,o=0,l=0,a=e[n-1].nextSibling,c=null;for(;o<n||l<s;){if(e[o]===t[l]){o++,l++;continue}for(;e[n-1]===t[s-1];)n--,s--;if(n===o){const d=s<i?l?t[l-1].nextSibling:t[s-l]:a;for(;l<s;)r.insertBefore(t[l++],d)}else if(s===l)for(;o<n;)(!c||!c.has(e[o]))&&e[o].remove(),o++;else if(e[o]===t[s-1]&&t[l]===e[n-1]){const d=e[--n].nextSibling;r.insertBefore(t[l++],e[o++].nextSibling),r.insertBefore(t[--s],d),e[n]=t[s]}else{if(!c){c=new Map;let f=l;for(;f<s;)c.set(t[f],f++)}const d=c.get(e[o]);if(d!=null)if(l<d&&d<s){let f=o,p=1,h;for(;++f<n&&f<s&&!((h=c.get(e[f]))==null||h!==d+p);)p++;if(p>d-l){const u=e[o];for(;l<d;)r.insertBefore(t[l++],u)}else r.replaceChild(t[l++],e[o++])}else o++;else e[o++].remove()}}}const xn="_$DX_DELEGATE";function No(r,e,t,i={}){if(!e)throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");let n;return os(s=>{n=s,e===document?r():v(e,r(),e.firstChild?null:void 0,t)},i.owner),()=>{n(),e.textContent=""}}function E(r,e,t,i){let n;const s=()=>{if(ft())throw new Error("Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.");const l=document.createElement("template");return l.innerHTML=r,l.content.firstChild},o=()=>(n||(n=s())).cloneNode(!0);return o.cloneNode=o,o}function Se(r,e=window.document){const t=e[xn]||(e[xn]=new Set);for(let i=0,n=r.length;i<n;i++){const s=r[i];t.has(s)||(t.add(s),e.addEventListener(s,Uo))}}function ve(r,e,t){ft(r)||(t==null?r.removeAttribute(e):r.setAttribute(e,t))}function Go(r,e,t,i){ft(r)||(i==null?r.removeAttributeNS(e,t):r.setAttributeNS(e,t,i))}function Do(r,e,t){ft(r)||(t?r.setAttribute(e,""):r.removeAttribute(e))}function zo(r,e){ft(r)||(e==null?r.removeAttribute("class"):r.className=e)}function at(r,e,t,i){if(i)Array.isArray(t)?(r[`$$${e}`]=t[0],r[`$$${e}Data`]=t[1]):r[`$$${e}`]=t;else if(Array.isArray(t)){const n=t[0];r.addEventListener(e,t[0]=s=>n.call(r,t[1],s))}else r.addEventListener(e,t,typeof t!="function"&&t)}function Bo(r,e,t={}){const i=Object.keys(e||{}),n=Object.keys(t);let s,o;for(s=0,o=n.length;s<o;s++){const l=n[s];!l||l==="undefined"||e[l]||($n(r,l,!1),delete t[l])}for(s=0,o=i.length;s<o;s++){const l=i[s],a=!!e[l];!l||l==="undefined"||t[l]===a||!a||($n(r,l,!0),t[l]=a)}return t}function V(r,e,t){if(!e)return t?ve(r,"style"):e;const i=r.style;if(typeof e=="string")return i.cssText=e;typeof t=="string"&&(i.cssText=t=void 0),t||(t={}),e||(e={});let n,s;for(s in t)e[s]==null&&i.removeProperty(s),delete t[s];for(s in e)n=e[s],n!==t[s]&&(i.setProperty(s,n),t[s]=n);return t}function D(r,e,t){t!=null?r.style.setProperty(e,t):r.style.removeProperty(e)}function hs(r,e={},t,i){const n={};return i||A(()=>n.children=br(r,e.children,n.children)),A(()=>typeof e.ref=="function"&&hr(e.ref,r)),A(()=>Ho(r,e,t,!0,n,!0)),n}function hr(r,e,t){return xe(()=>r(e,t))}function v(r,e,t,i){if(t!==void 0&&!i&&(i=[]),typeof e!="function")return br(r,e,i,t);A(n=>br(r,e(),n,t),i)}function Ho(r,e,t,i,n={},s=!1){e||(e={});for(const o in n)if(!(o in e)){if(o==="children")continue;n[o]=_n(r,o,null,n[o],t,s,e)}for(const o in e){if(o==="children")continue;const l=e[o];n[o]=_n(r,o,l,n[o],t,s,e)}}function Fo(r){let e,t,i=ft();if(!i||!(e=Ce.registry.get(t=Xo()))){if(i)throw Ce.done=!0,new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${t}
3
+ `);return r()}return Ce.completed&&Ce.completed.add(e),Ce.registry.delete(t),e}function ft(r){return!!Ce.context&&!Ce.done&&(!r||r.isConnected)}function Wo(r){return r.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function $n(r,e,t){const i=e.trim().split(/\s+/);for(let n=0,s=i.length;n<s;n++)r.classList.toggle(i[n],t)}function _n(r,e,t,i,n,s,o){let l,a,c,d,f;if(e==="style")return V(r,t,i);if(e==="classList")return Bo(r,t,i);if(t===i)return i;if(e==="ref")s||t(r);else if(e.slice(0,3)==="on:"){const p=e.slice(3);i&&r.removeEventListener(p,i,typeof i!="function"&&i),t&&r.addEventListener(p,t,typeof t!="function"&&t)}else if(e.slice(0,10)==="oncapture:"){const p=e.slice(10);i&&r.removeEventListener(p,i,!0),t&&r.addEventListener(p,t,!0)}else if(e.slice(0,2)==="on"){const p=e.slice(2).toLowerCase(),h=Oo.has(p);if(!h&&i){const u=Array.isArray(i)?i[0]:i;r.removeEventListener(p,u)}(h||t)&&(at(r,p,t,h),h&&Se([p]))}else if(e.slice(0,5)==="attr:")ve(r,e.slice(5),t);else if(e.slice(0,5)==="bool:")Do(r,e.slice(5),t);else if((f=e.slice(0,5)==="prop:")||(c=Mo.has(e))||!n&&((d=Ro(e,r.tagName))||(a=To.has(e)))||(l=r.nodeName.includes("-")||"is"in o)){if(f)e=e.slice(5),a=!0;else if(ft(r))return t;e==="class"||e==="className"?zo(r,t):l&&!a&&!c?r[Wo(e)]=t:r[d||e]=t}else{const p=n&&e.indexOf(":")>-1&&Ao[e.split(":")[0]];p?Go(r,p,e,t):ve(r,Eo[e]||e,t)}return t}function Uo(r){if(Ce.registry&&Ce.events&&Ce.events.find(([a,c])=>c===r))return;let e=r.target;const t=`$$${r.type}`,i=r.target,n=r.currentTarget,s=a=>Object.defineProperty(r,"target",{configurable:!0,value:a}),o=()=>{const a=e[t];if(a&&!e.disabled){const c=e[`${t}Data`];if(c!==void 0?a.call(e,c,r):a.call(e,r),r.cancelBubble)return}return e.host&&typeof e.host!="string"&&!e.host._$host&&e.contains(r.target)&&s(e.host),!0},l=()=>{for(;o()&&(e=e._$host||e.parentNode||e.host););};if(Object.defineProperty(r,"currentTarget",{configurable:!0,get(){return e||document}}),Ce.registry&&!Ce.done&&(Ce.done=_$HY.done=!0),r.composedPath){const a=r.composedPath();s(a[0]);for(let c=0;c<a.length-2&&(e=a[c],!!o());c++){if(e._$host){e=e._$host,l();break}if(e.parentNode===n)break}}else l();s(i)}function br(r,e,t,i,n){const s=ft(r);if(s){!t&&(t=[...r.childNodes]);let a=[];for(let c=0;c<t.length;c++){const d=t[c];d.nodeType===8&&d.data.slice(0,2)==="!$"?d.remove():a.push(d)}t=a}for(;typeof t=="function";)t=t();if(e===t)return t;const o=typeof e,l=i!==void 0;if(r=l&&t[0]&&t[0].parentNode||r,o==="string"||o==="number"){if(s||o==="number"&&(e=e.toString(),e===t))return t;if(l){let a=t[0];a&&a.nodeType===3?a.data!==e&&(a.data=e):a=document.createTextNode(e),t=Rt(r,t,i,a)}else t!==""&&typeof t=="string"?t=r.firstChild.data=e:t=r.textContent=e}else if(e==null||o==="boolean"){if(s)return t;t=Rt(r,t,i)}else{if(o==="function")return A(()=>{let a=e();for(;typeof a=="function";)a=a();t=br(r,a,t,i)}),()=>t;if(Array.isArray(e)){const a=[],c=t&&Array.isArray(t);if(Ai(a,e,t,n))return A(()=>t=br(r,a,t,i,!0)),()=>t;if(s){if(!a.length)return t;if(i===void 0)return t=[...r.childNodes];let d=a[0];if(d.parentNode!==r)return t;const f=[d];for(;(d=d.nextSibling)!==i;)f.push(d);return t=f}if(a.length===0){if(t=Rt(r,t,i),l)return t}else c?t.length===0?Sn(r,a,i):Io(r,t,a):(t&&Rt(r),Sn(r,a));t=a}else if(e.nodeType){if(s&&e.parentNode)return t=l?[e]:e;if(Array.isArray(t)){if(l)return t=Rt(r,t,i,e);Rt(r,t,null,e)}else t==null||t===""||!r.firstChild?r.appendChild(e):r.replaceChild(e,r.firstChild);t=e}else console.warn("Unrecognized value. Skipped inserting",e)}return t}function Ai(r,e,t,i){let n=!1;for(let s=0,o=e.length;s<o;s++){let l=e[s],a=t&&t[r.length],c;if(!(l==null||l===!0||l===!1))if((c=typeof l)=="object"&&l.nodeType)r.push(l);else if(Array.isArray(l))n=Ai(r,l,a)||n;else if(c==="function")if(i){for(;typeof l=="function";)l=l();n=Ai(r,Array.isArray(l)?l:[l],Array.isArray(a)?a:[a])||n}else r.push(l),n=!0;else{const d=String(l);a&&a.nodeType===3&&a.data===d?r.push(a):r.push(document.createTextNode(d))}}return n}function Sn(r,e,t=null){for(let i=0,n=e.length;i<n;i++)r.insertBefore(e[i],t)}function Rt(r,e,t,i){if(t===void 0)return r.textContent="";const n=i||document.createTextNode("");if(e.length){let s=!1;for(let o=e.length-1;o>=0;o--){const l=e[o];if(n!==l){const a=l.parentNode===r;!s&&!o?a?r.replaceChild(n,l):r.insertBefore(n,t):a&&l.remove()}else s=!0}}else r.insertBefore(n,t);return[n]}function Xo(){return Ce.getNextContextId()}const Yo="http://www.w3.org/2000/svg";function qo(r,e=!1,t=void 0){return e?document.createElementNS(Yo,r):document.createElement(r,{is:t})}function jo(r,e){const t=vr(r);return vr(()=>{const i=t();switch(typeof i){case"function":return Object.assign(i,{[vo]:!0}),xe(()=>i(e));case"string":const n=Lo.has(i),s=Ce.context?Fo():qo(i,n,xe(()=>e.is));return hs(s,e,n),s}})}function fs(r){const[,e]=ls(r,["component"]);return jo(()=>r.component,e)}async function ps(r,e){const t=r.slice(3),i=Uint8Array.from(atob(t),f=>f.charCodeAt(0)),n=new DecompressionStream(e),s=n.writable.getWriter();await s.write(i),await s.close();const o=n.readable.getReader(),l=[];try{for(;;){const{done:f,value:p}=await o.read();if(f)break;l.push(p)}}catch(f){throw o.cancel(),f}let a=0;for(const f of l)a+=f.length;const c=new Uint8Array(a);let d=0;for(const f of l)c.set(f,d),d+=f.length;return JSON.parse(new TextDecoder().decode(c))}function Vo(r){return ps(r,"gzip")}function Zo(r){return ps(r,"deflate")}class tt{constructor(e){_(this,"fn");this.fn=e}static create(e){return e===!0?new tt(console.debug.bind(console)):typeof e=="function"?new tt(e):new tt(null)}child(e){if(!this.fn)return this;const t=this.fn;return new tt((...i)=>t(`[screeps:${e}]`,...i))}log(...e){var t;(t=this.fn)==null||t.call(this,...e)}}function Ko(r){return{signin:(e,t)=>r.request("POST","/api/auth/signin",{email:e,password:t}),me:()=>r.request("GET","/api/auth/me"),queryToken:e=>r.request("GET","/api/auth/query-token",{token:e}),steamTicket:(e,t)=>r.request("POST","/api/auth/steam-ticket",{ticket:e,...t!=null?{useNativeAuth:t}:{}}),modInfo:()=>r.request("GET","/api/authmod")}}function Jo(r){return{list:()=>r.request("GET","/api/game/power-creeps/list"),create:(e,t)=>r.request("POST","/api/game/power-creeps/create",{name:e,className:t}),delete:e=>r.request("POST","/api/game/power-creeps/delete",{id:e}),cancelDelete:e=>r.request("POST","/api/game/power-creeps/cancel-delete",{id:e}),upgrade:(e,t)=>r.request("POST","/api/game/power-creeps/upgrade",{id:e,powers:t}),rename:(e,t)=>r.request("POST","/api/game/power-creeps/rename",{id:e,name:t}),experimentation:()=>r.request("POST","/api/game/power-creeps/experimentation")}}function _e(r,e){return e&&(r.shard=e),r}function Qo(r){return{roomTerrain:(e,t)=>r.request("GET","/api/game/room-terrain",_e({room:e,encoded:1},t)),roomObjects:(e,t)=>r.request("GET","/api/game/room-objects",_e({room:e},t)),roomStatus:(e,t)=>r.request("GET","/api/game/room-status",_e({room:e},t)),roomOverview:(e,t=8,i)=>r.request("GET","/api/game/room-overview",_e({room:e,interval:t},i)),time:e=>r.request("GET","/api/game/time",_e({},e)),worldSize:e=>r.request("GET","/api/game/world-size",_e({},e)),mapStats:(e,t,i)=>r.request("POST","/api/game/map-stats",_e({rooms:e,statName:t},i)),roomsTerrain:(e,t)=>{const i=new URLSearchParams({encoded:"true"});return t&&i.set("shard",t),r.request("POST",`/api/game/rooms?${i}`,{rooms:e})},createFlag:(e,t,i,n,s,o,l)=>r.request("POST","/api/game/create-flag",_e({room:e,x:t,y:i,name:n,color:s,secondaryColor:o},l)),genUniqueFlagName:()=>r.request("POST","/api/game/gen-unique-flag-name"),checkUniqueFlagName:e=>r.request("POST","/api/game/check-unique-flag-name",{name:e}),changeFlagColor:(e,t,i,n)=>r.request("POST","/api/game/change-flag-color",{room:e,name:t,color:i,secondaryColor:n}),removeFlag:(e,t)=>r.request("POST","/api/game/remove-flag",{room:e,name:t}),genUniqueObjectName:(e,t)=>r.request("POST","/api/game/gen-unique-object-name",_e({type:e},t)),checkUniqueObjectName:(e,t,i)=>r.request("POST","/api/game/check-unique-object-name",_e({type:e,name:t},i)),placeSpawn:(e,t,i,n,s)=>r.request("POST","/api/game/place-spawn",_e({room:e,x:t,y:i,...n?{name:n}:{}},s)),createConstruction:(e,t,i,n,s,o)=>r.request("POST","/api/game/create-construction",_e({room:e,x:t,y:i,structureType:n,...s?{name:s}:{}},o)),removeConstructionSite:(e,t,i)=>r.request("POST","/api/game/add-object-intent",_e({_id:"room",room:e,name:"removeConstructionSite",intent:t.map(n=>({id:n,roomName:e}))},i)),addObjectIntent:(e,t,i,n)=>r.request("POST","/api/game/add-object-intent",{_id:e,room:t,name:i,intent:n}),addGlobalIntent:(e,t)=>r.request("POST","/api/game/add-global-intent",{name:e,intent:t}),setNotifyWhenAttacked:(e,t)=>r.request("POST","/api/game/set-notify-when-attacked",{_id:e,enabled:t}),createInvader:(e,t,i,n,s,o)=>r.request("POST","/api/game/create-invader",{room:e,x:t,y:i,size:n,type:s,...o!=null?{boosted:o}:{}}),removeInvader:e=>r.request("POST","/api/game/remove-invader",{_id:e}),tick:()=>r.request("GET","/api/game/tick"),powerCreeps:Jo(r),market:{ordersIndex:e=>r.request("GET","/api/game/market/orders-index",_e({},e)),myOrders:()=>r.request("GET","/api/game/market/my-orders"),orders:(e,t)=>r.request("GET","/api/game/market/orders",_e({resourceType:e},t)),stats:(e,t)=>r.request("GET","/api/game/market/stats",_e({resourceType:e},t))},shards:{info:()=>r.request("GET","/api/game/shards/info")}}}function el(r){return{send:(e,t)=>r.request("POST","/api/user/messages/send",{respondent:e,text:t}),list:e=>r.request("GET","/api/user/messages/list",{respondent:e}),index:()=>r.request("GET","/api/user/messages/index"),markRead:e=>r.request("POST","/api/user/messages/mark-read",{id:e}),unreadCount:()=>r.request("GET","/api/user/messages/unread-count")}}function Ot(r,e){return e&&(r.shard=e),r}function tl(r){return{branches:()=>r.request("GET","/api/user/branches"),code:{get:e=>r.request("GET","/api/user/code",e?{branch:e}:{}),set:(e,t)=>r.request("POST","/api/user/code",{branch:e,modules:t,_hash:Date.now()})},memory:{get:(e,t)=>r.request("GET","/api/user/memory",Ot({path:e},t)),set:(e,t,i)=>r.request("POST","/api/user/memory",Ot({path:e,value:t},i)),segment:{get:(e,t)=>r.request("GET","/api/user/memory-segment",Ot({segment:e},t)),set:(e,t,i)=>r.request("POST","/api/user/memory-segment",Ot({segment:e,data:t},i))}},console:(e,t)=>r.request("POST","/api/user/console",Ot({expression:e},t)),stats:e=>r.request("GET","/api/user/stats",{interval:e}),rooms:e=>r.request("GET","/api/user/rooms",{id:e}),overview:(e,t)=>r.request("GET","/api/user/overview",{interval:e,statName:t}),worldStatus:()=>r.request("GET","/api/user/world-status"),worldStartRoom:e=>r.request("GET","/api/user/world-start-room",Ot({},e)),find:e=>r.request("GET","/api/user/find",e),moneyHistory:e=>r.request("GET","/api/user/money-history",e!=null?{page:e}:{}),respawn:()=>r.request("POST","/api/user/respawn"),respawnProhibitedRooms:()=>r.request("GET","/api/user/respawn-prohibited-rooms"),badge:e=>r.request("POST","/api/user/badge",{badge:e}),setActiveBranch:(e,t)=>r.request("POST","/api/user/set-active-branch",{activeName:e,branch:t}),cloneBranch:(e,t,i)=>r.request("POST","/api/user/clone-branch",{newName:e,...t?{branch:t}:{},...i!=null?{defaultModules:i}:{}}),deleteBranch:e=>r.request("POST","/api/user/delete-branch",{branch:e}),notifyPrefs:e=>r.request("POST","/api/user/notify-prefs",e),tutorialDone:()=>r.request("POST","/api/user/tutorial-done"),email:e=>r.request("POST","/api/user/email",{email:e}),setSteamVisible:e=>r.request("POST","/api/user/set-steam-visible",{visible:e}),password:(e,t)=>r.request("POST","/api/user/password",{password:e,...t!=null?{oldPassword:t}:{}}),messages:el(r)}}function rl(r){return{list:(e=10,t="world",i=0,n)=>r.request("GET","/api/leaderboard/list",{limit:e,mode:t,offset:i,season:n}),find:(e,t="world",i="")=>r.request("GET","/api/leaderboard/find",{username:e,mode:t,season:i}),seasons:()=>r.request("GET","/api/leaderboard/seasons")}}function il(r){return{pvp:(e=100)=>r.request("GET","/api/experimental/pvp",{interval:e}),nukes:()=>r.request("GET","/api/experimental/nukes")}}function nl(r){return{checkEmail:e=>r.request("GET","/api/register/check-email",{email:e}),checkUsername:e=>r.request("GET","/api/register/check-username",{username:e}),setUsername:(e,t)=>r.request("POST","/api/register/set-username",{username:e,...t!=null?{email:t}:{}}),submit:(e,t,i,n)=>r.request("POST","/api/register/submit",{username:e,email:t,password:i,...n!=null?{modules:n}:{}})}}class sl extends EventTarget{constructor(t){super();_(this,"baseUrl");_(this,"authStrategy");_(this,"logger");_(this,"serverPassword");_(this,"token",null);_(this,"rateLimits",new Map);_(this,"authenticating",!1);_(this,"auth");_(this,"register");_(this,"game");_(this,"user");_(this,"leaderboard");_(this,"experimental");this.baseUrl=t.url.endsWith("/")?t.url:`${t.url}/`,this.authStrategy=t.auth,this.logger=t.logger??tt.create(),this.serverPassword=t.serverPassword??null,this.auth=Ko(this),this.register=nl(this),this.game=Qo(this),this.user=tl(this),this.leaderboard=rl(this),this.experimental=il(this)}emit(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i}))}on(t,i){const n=s=>i(s.detail);return this.addEventListener(t,n),{dispose:()=>{this.removeEventListener(t,n)}}}async authenticate(){this.logger.log("authenticate"),this.authenticating=!0;try{this.token=await this.authStrategy.authenticate(this),this.logger.log("authenticated")}finally{this.authenticating=!1}}setToken(t){this.token=t}async request(t,i,n,s=!1){this.logger.log(t,i);const o=new URL(i.startsWith("/")?i.slice(1):i,this.baseUrl),l={};this.token&&(l["X-Token"]=this.token,l["X-Username"]=this.token),this.serverPassword&&(l["X-Server-Password"]=this.serverPassword);const a={method:t,headers:l};if(t==="GET"&&n)for(const[p,h]of Object.entries(n))h!=null&&o.searchParams.set(p,String(h));else n&&(l["Content-Type"]="application/json",a.body=JSON.stringify(n));const c=await fetch(o.toString(),a),d=c.headers.get("x-token");if(d&&(this.token=d,this.emit("http:tokenRefresh",{token:d})),this.updateRateLimit(i,c),c.status===401&&!s&&!this.authenticating)return await this.authenticate(),this.request(t,i,n,!0);if(!c.ok){let p="";try{p=await c.text()}catch{}const h=new Error(`HTTP ${c.status}: ${p}`);throw this.emit("http:error",{method:t,path:i,status:c.status,error:h}),h}this.emit("http:success",{method:t,path:i,status:c.status});const f=await c.json();if(typeof f.error=="string"){const p=new Error(`Screeps API error: ${f.error}`);throw this.emit("http:error",{method:t,path:i,status:c.status,error:p}),p}return typeof f.data=="string"&&f.data.startsWith("gz:")&&(f.data=await Vo(f.data)),f}updateRateLimit(t,i){const n=i.headers.get("x-ratelimit-limit"),s=i.headers.get("x-ratelimit-remaining"),o=i.headers.get("x-ratelimit-reset");n&&s&&o&&this.rateLimits.set(t,{limit:parseInt(n,10),remaining:parseInt(s,10),reset:parseInt(o,10)})}}async function ol(r){let e=typeof r=="string"?r:r.data;if(e.startsWith("gz:")&&(e=JSON.stringify(await Zo(e))),e.startsWith("[")){const[n,s]=JSON.parse(e);return{kind:"channel",message:{channel:n,data:s}}}const[t,...i]=e.split(" ");switch(t){case"auth":return{kind:"server",command:{type:"auth",status:i[0],token:i[1]}};case"time":return{kind:"server",command:{type:"time",time:parseInt(i[0],10)}};case"protocol":return{kind:"server",command:{type:"protocol",protocol:parseInt(i[0],10)}};case"package":return{kind:"server",command:{type:"package",package:parseInt(i[0],10)}};default:throw new Error(`Unknown server command: ${t}`)}}class ll{constructor(e){_(this,"wsUrl");_(this,"WS");_(this,"logger");_(this,"ws",null);_(this,"token",null);_(this,"authed",!1);_(this,"_connected",!1);_(this,"reconnecting",!1);_(this,"authSub",null);_(this,"queue",[]);_(this,"subs",new Map);_(this,"listeners",new Map);_(this,"MAX_RETRIES",10);_(this,"MAX_DELAY_MS",6e4);_(this,"_intentionalClose",!1);const t=e.url.replace(/^http/,"ws").replace(/\/$/,"");this.wsUrl=`${t}/socket/websocket`,this.WS=e.WebSocket??globalThis.WebSocket,this.logger=e.logger??tt.create()}get isConnected(){return this._connected}setToken(e){this.token=e}connect(e){var t;return this.logger.log("connect",this.wsUrl),this.reconnecting||(this._intentionalClose=!1),this.token=e,(t=this.authSub)==null||t.dispose(),this.authSub=null,new Promise((i,n)=>{this.ws=new this.WS(this.wsUrl),this.ws.onopen=()=>{this.logger.log("WebSocket opened"),this._connected=!0,this.reconnecting=!1,this.rawSend(`auth ${this.token}`),this.authSub=this.once("auth",s=>{const o=s;if(o.status==="ok"){for(this.logger.log("auth ok"),this.authed=!0,o.token&&(this.token=o.token,this.emit("socket:tokenRefresh",{token:o.token}));this.queue.length;)this.rawSend(this.queue.shift());this.emit("connected",{}),i()}else this.logger.log("auth failed"),n(new Error("WebSocket auth failed"))})},this.ws.onclose=()=>{var s;this.logger.log("WebSocket closed"),this._connected=!1,this.authed=!1,(s=this.authSub)==null||s.dispose(),this.authSub=null,this.emit("disconnected",{willReconnect:this.reconnecting}),this.scheduleReconnect()},this.ws.onerror=s=>{this._connected||n(s)},this.ws.onmessage=s=>{this.handleMessage(s).catch(o=>{const l=typeof s.data=="string"?s.data.slice(0,200):"(binary)";this.logger.log("message parse error",o instanceof Error?o.stack??o.message:String(o),"raw:",l),this.emit("socket:error",o instanceof Error?o:new Error(String(o)))})}})}disconnect(){var e;this.logger.log("disconnect"),this._intentionalClose=!0,this.reconnecting=!1,(e=this.ws)==null||e.close(),this.ws=null,this._connected=!1,this.authed=!1,this.queue.length=0}activeSubs(){return Array.from(this.subs.entries()).map(([e,t])=>`${e}(${t})`).join(", ")||"(none)"}subscribe(e){const t=this.subs.get(e)??0;return this.subs.set(e,t+1),t===0?(this.logger.log("subscribe",e,"active:",this.activeSubs()),this.sendOrQueue(`subscribe ${e}`)):this.logger.log("subscribe",e,`(refs: ${t+1})`,"active:",this.activeSubs()),{dispose:()=>this.doUnsubscribe(e)}}on(e,t){let i=this.listeners.get(e);return i||(i=new Set,this.listeners.set(e,i)),i.add(t),{dispose:()=>{var n;(n=this.listeners.get(e))==null||n.delete(t)}}}once(e,t){const i=this.on(e,n=>{i.dispose(),t(n)});return i}doUnsubscribe(e){const t=this.subs.get(e)??0;t<=1?(this.subs.delete(e),this.authed&&this.rawSend(`unsubscribe ${e}`),this.logger.log("unsubscribe",e,"active:",this.activeSubs())):(this.subs.set(e,t-1),this.logger.log("unsubscribe",e,`(refs: ${t-1})`,"active:",this.activeSubs()))}rawSend(e){var t;(t=this.ws)==null||t.send(e)}sendOrQueue(e){this.authed?this.rawSend(e):this.queue.push(e)}emit(e,t){var i;(i=this.listeners.get(e))==null||i.forEach(n=>{try{n(t)}catch(s){this.logger.log("listener error on channel",e,s instanceof Error?s.stack??s.message:String(s))}})}async handleMessage(e){const t=await ol(e);t.kind==="server"?this.emit(t.command.type,t.command):this.emit(t.message.channel,t.message.data)}async scheduleReconnect(){var t;if(this.reconnecting||this._intentionalClose)return;if(!this.token){this.reconnecting=!1;return}this.reconnecting=!0;let e=0;for(;e<this.MAX_RETRIES&&this.reconnecting&&!this._intentionalClose;){const i=Math.min(Math.pow(2,e)*100,this.MAX_DELAY_MS);if(this.logger.log(`reconnect attempt ${e+1}/${this.MAX_RETRIES} in ${i}ms`),await new Promise(n=>setTimeout(n,i)),!this.reconnecting||this._intentionalClose)return;try{if(await this.connect(this.token),this._intentionalClose){(t=this.ws)==null||t.close(),this.ws=null;return}for(const n of this.subs.keys())this.rawSend(`subscribe ${n}`);return}catch{e++}}this.reconnecting=!1,e>=this.MAX_RETRIES&&!this._intentionalClose&&this.emit("socket:error",new Error(`WebSocket reconnection failed after ${this.MAX_RETRIES} retries`))}}class al{constructor(e,t){_(this,"memory",new Map);_(this,"storage");_(this,"namespace");this.namespace=e,this.storage=t}memKey(e){return`${this.namespace}/${e}`}get(e){const t=this.memory.get(this.memKey(e));if(t){if(t.expires!==void 0&&Date.now()>t.expires){this.memory.delete(this.memKey(e));return}return t.data}}set(e,t,i){this.memory.set(this.memKey(e),{data:t,expires:i!==void 0?Date.now()+i:void 0})}delete(e){this.memory.delete(this.memKey(e))}async getPersistent(e){return this.storage?this.storage.get(`${this.namespace}/${e}`):null}async setPersistent(e,t){this.storage&&await this.storage.set(`${this.namespace}/${e}`,t)}async deletePersistent(e){this.storage&&await this.storage.delete(`${this.namespace}/${e}`)}clearMemory(){this.memory.clear()}async clearPersistent(){this.storage&&await this.storage.clear()}async clearAll(){this.clearMemory(),await this.clearPersistent()}}class Qt extends EventTarget{constructor(t){super();_(this,"logger");this.logger=t??tt.create()}emit(t,i){this.dispatchEvent(new CustomEvent(t,{detail:i}))}on(t,i){this.logger.log(`on "${t}"`);const n=s=>i(s.detail);return this.addEventListener(t,n),{dispose:()=>{this.logger.log(`off "${t}"`),this.removeEventListener(t,n)}}}}var Fe=(r=>(r[r.Plain=0]="Plain",r[r.Wall=1]="Wall",r[r.Swamp=2]="Swamp",r))(Fe||{});class Ft{constructor(e){_(this,"raw");this.raw=e}static fromEncodedString(e){const t=new Uint8Array(2500);for(let i=0;i<2500;i++){const n=parseInt(e[i],10);t[i]=n===3?1:n}return new Ft(t)}get(e,t){return this.raw[t*50+e]}}class cl extends Qt{constructor(t,i,n,s){super(s);_(this,"http");_(this,"socket");_(this,"cache");_(this,"roomObjects",new Map);_(this,"roomUsers",new Map);_(this,"roomSubCount",new Map);_(this,"lastFlagsString",new Map);this.http=t,this.socket=i,this.cache=n}parseFlagsString(t,i){if(!t||t.length===0)return[];const n=[],s=t.split("|");for(const o of s){const l=o.split("~");if(l.length!==5)continue;const[a,c,d,f,p]=l,h=parseInt(c,10),u=parseInt(d,10),g=parseInt(f,10),$=parseInt(p,10);isNaN(h)||isNaN(u)||isNaN(g)||isNaN($)||n.push({_id:a,type:"flag",room:i,name:a,x:g,y:$,color:h,secondaryColor:u})}return n}async terrain(t,i){const n=`terrain/${i}/${t}`,s=this.cache.get(n);if(s)return this.logger.log("terrain",t,i,"(memory cache hit)"),s;const o=await this.cache.getPersistent(n);if(o){this.logger.log("terrain",t,i,"(persistent cache hit)");const d=new Ft(o);return this.cache.set(n,d),d}this.logger.log("terrain",t,i,"(fetching)");const a=(await this.http.game.roomTerrain(t,i??void 0)).terrain[0];if(!a)throw new Error(`No terrain data for room ${t} shard ${i}`);const c=Ft.fromEncodedString(a.terrain);return this.cache.set(n,c),await this.cache.setPersistent(n,c.raw),this.emit("room:terrainavailable",{room:t,shard:i,terrain:c}),c}async terrainBulk(t,i){const n=new Map,s=[];for(const a of t){const c=this.cache.get(`terrain/${i}/${a}`);c?n.set(a,c):s.push(a)}if(s.length===0)return n;const o=[];if(await Promise.all(s.map(async a=>{const c=`terrain/${i}/${a}`,d=await this.cache.getPersistent(c);if(d){const f=new Ft(d);this.cache.set(c,f),n.set(a,f)}else o.push(a)})),o.length===0)return n;this.logger.log("terrainBulk",`fetching ${o.length} rooms`,i);const l=await this.http.game.roomsTerrain(o,i??void 0);return await Promise.all(l.rooms.map(async a=>{const c=Ft.fromEncodedString(a.terrain),d=`terrain/${i}/${a.room}`;this.cache.set(d,c),await this.cache.setPersistent(d,c.raw),this.emit("room:terrainavailable",{room:a.room,shard:i,terrain:c}),n.set(a.room,c)})),n}objects(t,i){const n=this.roomObjects.get(`${t}/${i}`);return n?{...n}:null}async fetchObjects(t,i){const n=`${t}/${i}`,s=await this.http.game.roomObjects(t,i??void 0),o={};for(const a of s.objects)a&&typeof a=="object"&&"_id"in a&&(o[a._id]=a);this.roomObjects.set(n,o);const l=this.roomUsers.get(n);this.emit("room:update",{room:t,shard:i,gameTime:void 0,objects:o,diff:o,visual:"",users:l})}activeRooms(){return Array.from(this.roomSubCount.entries()).map(([t,i])=>`${t}(${i})`).join(", ")||"(none)"}subscribe(t,i){const n=`${t}/${i}`,s=this.roomSubCount.get(n)??0;this.roomSubCount.set(n,s+1),this.logger.log("subscribe",t,i,`(refs: ${s+1})`,"active:",this.activeRooms());const o=i?`room:${i}/${t}`:`room:${t}`,l=i?`err@room:${i}/${t}`:`err@room:${t}`,a=this.socket.subscribe(o),c=this.socket.on(l,f=>{const p=typeof f=="string"?f:JSON.stringify(f);this.logger.log("room error",t,i,p),this.emit("room:error",{room:t,shard:i,message:p})}),d=this.socket.on(o,f=>{const p=f,h={...this.roomObjects.get(n)??{}};if(p.objects==null)p.objects===null&&this.logger.log("room update has null objects field",t,i,`gameTime: ${p.gameTime}`);else for(const[$,m]of Object.entries(p.objects))m===null?delete h[$]:h[$]?h[$]={...h[$],...m}:h[$]=m;const u={...p.objects??{}};if("flags"in p){const $=p.flags??"",m=this.lastFlagsString.get(n)??"";if($!==m){this.lastFlagsString.set(n,$);const S=this.parseFlagsString($,t),M=new Map;for(const b of S)M.set(b.name,b);for(const b in h){const y=h[b];(y==null?void 0:y.type)==="flag"&&!M.has(b)&&(delete h[b],u[b]=null,this.logger.log(`[flag:room] removed ${b} @ ${t}`))}for(const[b,y]of M){const T=h[b];(!T||T.x!==y.x||T.y!==y.y||T.color!==y.color||T.secondaryColor!==y.secondaryColor)&&(h[b]=y,u[b]=y,this.logger.log(`[flag:room] ${T?"changed":"added"} ${b} @ ${t} (${y.x},${y.y})`))}}}if(p.users){const $=this.roomUsers.get(n)??{};this.roomUsers.set(n,{...$,...p.users})}this.roomObjects.set(n,h);const g=this.roomUsers.get(n);this.emit("room:update",{room:t,shard:i,gameTime:p.gameTime,objects:h,diff:u,visual:p.visual??"",users:g})});return{dispose:()=>{a.dispose(),d.dispose(),c.dispose();const f=(this.roomSubCount.get(n)??1)-1;f<=0?(this.roomSubCount.delete(n),this.roomObjects.delete(n),this.roomUsers.delete(n),this.lastFlagsString.delete(n),this.logger.log("unsubscribe",t,i,"(last ref)","active:",this.activeRooms())):(this.roomSubCount.set(n,f),this.logger.log("unsubscribe",t,i,`(refs: ${f})`,"active:",this.activeRooms()))}}}}class dl extends Qt{constructor(t,i,n,s,o=100){super(s);_(this,"http");_(this,"socket");_(this,"cache");_(this,"console",[]);_(this,"maxConsoleSize");_(this,"_cpu",null);_(this,"_userInfo",null);_(this,"_userId",null);_(this,"_worldStatus",null);_(this,"_mePromise",null);this.http=t,this.socket=i,this.cache=n,this.maxConsoleSize=o}get cpu(){return this._cpu}get userInfo(){return this._userInfo}get userId(){return this._userId}get worldStatusValue(){return this._worldStatus}async me(){const t=this.cache.get("user/me");return t?(this._userId=t._id,this._userInfo=t,t):this._mePromise?this._mePromise:(this.logger.log("fetch me"),this._mePromise=this.http.auth.me().then(i=>{const n=i;return this._userId=n._id,this._userInfo=n,this.cache.set("user/me",n,6e4),this.emit("user:me",n),n}).finally(()=>{this._mePromise=null}),this._mePromise)}async refreshMe(){return this.logger.log("refresh me"),this.cache.delete("user/me"),this.me()}async worldStatus(){const t=this.cache.get("user/worldStatus");if(t)return this._worldStatus=t,t;this.logger.log("fetch world status");const i=await this.http.user.worldStatus();return this._worldStatus=i.status,this.cache.set("user/worldStatus",i.status,6e4),this.emit("user:worldStatus",{status:i.status}),i.status}async refreshWorldStatus(){return this.logger.log("refresh world status"),this.cache.delete("user/worldStatus"),this.worldStatus()}subscribe(t){this.logger.log("subscribe",t);let i=null,n=null,s=!1;return(async()=>{try{const l=this._userId??(await this.me())._id;if(s)return;const a=`user:${l}/${t}`;i=this.socket.subscribe(a),n=this.socket.on(a,c=>{var d,f,p;if(t==="cpu")this._cpu=c,this.emit("user:cpu",this._cpu);else if(t==="console"){const h=c,u={log:((d=h.messages)==null?void 0:d.log)??[],results:((f=h.messages)==null?void 0:f.results)??[],error:((p=h.messages)==null?void 0:p.error)??[]};h.error&&u.error.push(h.error),this.console.push(u),this.console.length>this.maxConsoleSize&&this.console.splice(0,this.console.length-this.maxConsoleSize),this.emit("user:console",{messages:u})}else t==="code"&&this.emit("user:code",c)})}catch(l){s||this.dispatchEvent(new ErrorEvent("error",{error:l instanceof Error?l:new Error(String(l))}))}})(),{dispose:()=>{this.logger.log("unsubscribe",t),s=!0,i==null||i.dispose(),n==null||n.dispose()}}}subscribeUserStream(){this.logger.log("subscribe user stream");let t=null,i=null,n=!1;return(async()=>{try{const o=this._userId??(await this.me())._id;if(n)return;const l=`user:${o}`;t=this.socket.subscribe(l),i=this.socket.on(l,a=>{const c=a;if(c&&typeof c=="object"&&"flags"in c){const d=c.flags;if(d&&typeof d=="object")for(const[f,p]of Object.entries(d)){const h=p;if(h&&typeof h=="object"){const u=h.room??"unknown",g=h.x??"?",$=h.y??"?";this.logger.log(`[flag:user] ${f} @ ${u} (${g},${$})`)}}}this.emit("user:stream",c)})}catch(o){n||this.dispatchEvent(new ErrorEvent("error",{error:o instanceof Error?o:new Error(String(o))}))}})(),{dispose:()=>{this.logger.log("unsubscribe user stream"),n=!0,t==null||t.dispose(),i==null||i.dispose()}}}}class ul extends Qt{constructor(t,i,n,s){super(s);_(this,"http");_(this,"cache");_(this,"socketSubs",[]);_(this,"_version",null);_(this,"_shards",null);this.http=t,this.cache=n,this.socketSubs.push(i.on("connected",()=>{this.emit("server:connected",{})})),this.socketSubs.push(i.on("disconnected",o=>{const l=o;this.emit("server:disconnected",{willReconnect:l.willReconnect})})),this.socketSubs.push(i.on("socket:error",o=>{this.emit("server:error",{error:o instanceof Error?o:new Error(String(o))})}))}get versionInfo(){return this._version}get isPrivateServer(){var t,i;return this._version?(((i=(t=this._version.serverData)==null?void 0:t.shards)==null?void 0:i.length)??0)===0:null}get shardList(){return this._shards}destroy(){for(const t of this.socketSubs)t.dispose();this.socketSubs.length=0}async version(){const t=this.cache.get("server/version");if(t)return t;const i=await this.http.request("GET","/api/version");return this._version=i,this.cache.set("server/version",i,5*6e4),this.emit("server:version",i),i}async refreshVersion(){return this.cache.delete("server/version"),this.version()}async shards(){const t=this.cache.get("server/shards");if(t)return t;const i=await this.http.request("GET","/api/game/shards/info");return this._shards=i.shards,this.cache.set("server/shards",i.shards,5*6e4),this.emit("server:shards",i.shards),i.shards}async refreshShards(){return this.cache.delete("server/shards"),this.shards()}async worldInfo(t){const n=`server/world/${t??"default"}`,s=this.cache.get(n);if(s)return s;const o={};t&&(o.shard=t);const l=await this.http.request("GET","/api/game/world-size",o),{width:a,height:c}=l;this.logger.log(`worldInfo shard=${t??"none"} — raw size: ${a}x${c}`);let d=-a,f=-1,p=-c,h=-1;try{const $=(await this.http.request("POST","/api/game/map-stats",{rooms:["W0N0","E0N0","W0S0","E0S0"],statName:"owner0",...o})).stats??{},m=["W0N0","E0N0","W0S0","E0S0"].filter(S=>S in $);this.logger.log(`worldInfo corner probe — found: [${m.length?m.join(", "):"none"}]`),("E0N0"in $||"E0S0"in $)&&(d=-Math.ceil(a/2),f=Math.floor(a/2)-1),("W0S0"in $||"E0S0"in $)&&(p=-Math.ceil(c/2),h=Math.floor(c/2)-1)}catch(g){this.logger.log("worldInfo corner probe failed — keeping W/N defaults:",g)}this.logger.log(`worldInfo computed bounds — x: [${d}, ${f}] y: [${p}, ${h}]`);const u={shard:t??null,width:a,height:c,minX:d,maxX:f,minY:p,maxY:h};return this.cache.set(n,u,10*6e4),u}invalidateWorldInfo(t){this.cache.delete(`server/world/${t??"default"}`)}}class hl{constructor(e){_(this,"memory",new Map);_(this,"adapter");_(this,"maxEntries");_(this,"namespace");_(this,"accessSeq",0);this.adapter=e.adapter,this.maxEntries=e.maxEntries,this.namespace=e.namespace}key(e,t){return`${t??"_"}/${e}`}adapterKey(e){return`map2/${e}`}tick(){return++this.accessSeq}serialize(e){const t={data:e.data,lastSeen:e.lastSeen,lastAccess:e.lastAccess};return new TextEncoder().encode(JSON.stringify(t))}deserialize(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}getMemory(e,t){const i=this.memory.get(this.key(e,t));return i?(i.lastAccess=this.tick(),i.data):null}async get(e,t){const i=this.getMemory(e,t);if(i)return i;if(!this.adapter)return null;const n=this.key(e,t),s=await this.adapter.get(this.adapterKey(n));if(!s)return null;const o=this.deserialize(s);return o?(this.memory.set(n,{data:o.data,lastSeen:o.lastSeen,lastAccess:this.tick()}),o.data):null}async put(e,t,i){const n=this.key(e,t),s={data:i,lastSeen:Date.now(),lastAccess:this.tick()};this.memory.set(n,s),await this.pruneIfNeeded(),this.adapter&&await this.adapter.set(this.adapterKey(n),this.serialize(s))}async pruneIfNeeded(){if(this.memory.size<=this.maxEntries)return;const t=[...this.memory.entries()].sort((i,n)=>i[1].lastAccess-n[1].lastAccess).slice(0,this.memory.size-this.maxEntries);for(const[i]of t)this.memory.delete(i),this.adapter&&await this.adapter.delete(this.adapterKey(i))}}function kn(r){const e=Object.keys(r).sort(),t={};for(const i of e){const n=r[i];t[i]=n?[...n].sort((s,o)=>s[0]-o[0]||s[1]-o[1]):null}return JSON.stringify(t)}class fl extends Qt{constructor(t,i,n={},s){super(s);_(this,"socket");_(this,"storage");_(this,"maxSubscriptions");_(this,"active",new Map);_(this,"waitlist",[]);_(this,"keyStates",new Map);_(this,"warnedAboutWaitlist",!1);this.socket=t,this.storage=i,this.maxSubscriptions=n.maxSubscriptions??500,this.socket.on("connected",()=>this.onReconnect())}map2data(t,i){return this.storage.getMemory(t,i)}subscribeMap2(t,i){const n=`${t}/${i}`,s=this.active.get(n);if(s){s.refCount++,this.logger.log("subscribeMap2",t,i,`(active, refs: ${s.refCount})`);const a=this.getOrCreateKeyState(n,"active");return this.emitWarmStart(t,i),this.makeSubscription(t,i,n,a)}const o=this.waitlist.find(a=>a.key===n);if(o){o.refCount++,this.logger.log("subscribeMap2",t,i,`(pending, refs: ${o.refCount})`);const a=this.getOrCreateKeyState(n,"pending");return this.emitWarmStart(t,i),this.makeSubscription(t,i,n,a)}if(this.active.size<this.maxSubscriptions){this.activateKey(t,i,n,1),this.logger.log("subscribeMap2",t,i,"(new active)");const a=this.getOrCreateKeyState(n,"active");return this.emit("room:map2state",{room:t,shard:i,status:"active"}),this.emitWarmStart(t,i),this.makeSubscription(t,i,n,a)}this.waitlist.push({key:n,room:t,shard:i,refCount:1}),this.logger.log("subscribeMap2",t,i,"(new pending)");const l=this.getOrCreateKeyState(n,"pending");return this.emit("room:map2state",{room:t,shard:i,status:"pending"}),this.emitWarmStart(t,i),this.warnedAboutWaitlist||(this.logger.log(`subscription limit (${this.maxSubscriptions}) reached — `,"some rooms are on a waitlist and will be promoted as slots free up."),this.warnedAboutWaitlist=!0),this.makeSubscription(t,i,n,l)}activateKey(t,i,n,s){const o=i?`roomMap2:${i}/${t}`:`roomMap2:${t}`,l=this.socket.subscribe(o),a=this.storage.getMemory(t,i),c={room:t,shard:i,refCount:s,socketSub:l,listenerSub:void 0,lastHash:a?kn(a):null};c.listenerSub=this.socket.on(o,d=>{const f=d,p=kn(f);c.lastHash!==p&&(c.lastHash=p,this.storage.put(t,i,f),this.emit("room:map2update",{room:t,shard:i,data:f,source:"live"}))}),this.active.set(n,c)}promoteNext(){const t=this.waitlist.shift();if(!t)return;this.activateKey(t.room,t.shard,t.key,t.refCount),this.logger.log("promoteNext",t.room,t.shard,"(promoted from waitlist)");const i=this.keyStates.get(t.key);i&&(i.status="active",i.statusHandlers.forEach(n=>n("active"))),this.emit("room:map2state",{room:t.room,shard:t.shard,status:"active"})}getOrCreateKeyState(t,i){let n=this.keyStates.get(t);return n||(n={status:i,statusHandlers:new Set},this.keyStates.set(t,n)),n}makeSubscription(t,i,n,s){let o=!1;return{status:()=>s.status,cachedData:()=>this.storage.getMemory(t,i),onStatusChange:l=>(s.statusHandlers.add(l),{dispose:()=>{s.statusHandlers.delete(l)}}),dispose:()=>{o||(o=!0,this.disposeSubscription(t,i,n))}}}disposeSubscription(t,i,n){const s=this.waitlist.findIndex(l=>l.key===n);if(s>=0){const l=this.waitlist[s];l.refCount--,this.logger.log("unsubscribeMap2",t,i,`(pending, refs: ${l.refCount})`),l.refCount<=0&&(this.waitlist.splice(s,1),this.keyStates.delete(n),this.logger.log("unsubscribeMap2",t,i,"(removed from waitlist)"));return}const o=this.active.get(n);o&&(o.refCount--,this.logger.log("unsubscribeMap2",t,i,`(active, refs: ${o.refCount})`),o.refCount<=0&&(o.socketSub.dispose(),o.listenerSub.dispose(),this.active.delete(n),this.keyStates.delete(n),this.logger.log("unsubscribeMap2",t,i,"(deactivated, promoting next)"),this.promoteNext()))}emitWarmStart(t,i){const n=`${t}/${i}`,s=this.storage.getMemory(t,i);s?queueMicrotask(()=>{this.isSubscribed(n)&&this.emit("room:map2update",{room:t,shard:i,data:s,source:"cache"})}):this.storage.get(t,i).then(o=>{o&&this.isSubscribed(n)&&this.emit("room:map2update",{room:t,shard:i,data:o,source:"cache"})})}onReconnect(){this.logger.log("onReconnect —",this.active.size,"active,",this.waitlist.length,"pending");for(const t of this.active.values())t.lastHash=null,this.emit("room:map2state",{room:t.room,shard:t.shard,status:"active"});for(const t of this.waitlist)this.emit("room:map2state",{room:t.room,shard:t.shard,status:"pending"})}isSubscribed(t){return this.active.has(t)||this.waitlist.some(i=>i.key===t)}}class pl extends Qt{constructor(t,i=100,n=500,s){super(s);_(this,"http");_(this,"debounceMs");_(this,"minIntervalMs");_(this,"pending",new Map);_(this,"timer",null);_(this,"lastFlushTime",0);this.http=t,this.debounceMs=i,this.minIntervalMs=n}request(t,i,n){if(t.length===0)return;const s=JSON.stringify([i,n??"shard0"]);let o=this.pending.get(s);o||(o={rooms:new Set,statName:i,shard:n??"shard0"},this.pending.set(s,o));for(const d of t)o.rooms.add(d);this.timer&&clearTimeout(this.timer);const a=Date.now()-this.lastFlushTime,c=Math.max(this.debounceMs,this.minIntervalMs-a);this.timer=setTimeout(()=>this.flush(),c)}async flush(){const t=new Map(this.pending);this.pending.clear(),this.timer=null,this.lastFlushTime=Date.now();for(const[,i]of t){const n=[...i.rooms];try{const s=await this.http.request("POST","/api/game/map-stats",{rooms:n,statName:i.statName,shard:i.shard}),o=s.users??{};for(const[l,a]of Object.entries(s.stats)){const c=this.buildData(a,o);this.emit("mapStats:room",{room:l,shard:i.shard==="shard0"?null:i.shard,stat:c})}for(const l of n)s.stats[l]||this.emit("mapStats:room",{room:l,shard:i.shard==="shard0"?null:i.shard,stat:{}})}catch(s){this.logger.log("mapStats fetch failed:",s)}}}buildData(t,i){var l,a,c;let n,s;for(let d=0;d<3;d++){const f=`minerals${d}`,p=t[f];if(p){n=p.type,s=p.density;break}}const o=(l=t.own)==null?void 0:l.user;return{own:t.own,mineral:n,density:s,username:o?(a=i[o])==null?void 0:a.username:void 0,safeMode:t.safeMode,badge:o?(c=i[o])==null?void 0:c.badge:void 0,status:t.status}}}class gl extends Qt{constructor(t=50,i){super(i);_(this,"_history",[]);_(this,"_index",-1);_(this,"maxHistory");this.maxHistory=t}navigateTo(t,i){this._history=this._history.slice(0,this._index+1),this._history.push({room:t,shard:i}),this._history.length>this.maxHistory?this._history.shift():this._index++,this.emit("navigation:change",this.current())}back(){return this.canBack()?(this._index--,this.emit("navigation:change",this.current()),!0):!1}forward(){return this.canForward()?(this._index++,this.emit("navigation:change",this.current()),!0):!1}canBack(){return this._index>0}canForward(){return this._index<this._history.length-1}current(){var t,i;return{room:((t=this._history[this._index])==null?void 0:t.room)??null,shard:((i=this._history[this._index])==null?void 0:i.shard)??null,index:this._index,history:[...this._history]}}}class ml{constructor(e){_(this,"http");_(this,"socket");_(this,"stores");_(this,"cache");_(this,"logger");_(this,"tokenRefreshIntervalMs");_(this,"tokenSyncSubs",[]);_(this,"tokenRefreshTimer",null);_(this,"lastHttpActivity",0);_(this,"refreshInFlight",!1);var n,s,o;let t;try{t=new URL(e.url).hostname}catch{throw new TypeError(`ScreepsClient: invalid url "${e.url}"`)}this.logger=tt.create(e.debug),this.logger.log(`[screeps:client] init ${e.url}`),this.cache=new al(t,e.storage??null),this.http=new sl({url:e.url,auth:e.auth,logger:this.logger.child("http"),serverPassword:e.serverPassword}),this.socket=new ll({url:e.url,WebSocket:e.WebSocket,logger:this.logger.child("socket")});const i=new hl({adapter:e.storage??null,namespace:t,maxEntries:((n=e.map2)==null?void 0:n.maxCacheEntries)??1e4});this.stores={room:new cl(this.http,this.socket,this.cache,this.logger.child("room")),user:new dl(this.http,this.socket,this.cache,this.logger.child("user")),server:new ul(this.http,this.socket,this.cache,this.logger.child("server")),map:new fl(this.socket,i,{maxSubscriptions:((s=e.map2)==null?void 0:s.maxSubscriptions)??500},this.logger.child("map")),mapStats:new pl(this.http,100,500,this.logger.child("mapStats")),navigation:new gl(50,this.logger.child("navigation"))},this.tokenRefreshIntervalMs=e.tokenRefresh===!1?null:((o=e.tokenRefresh)==null?void 0:o.intervalMs)??3e4,this.wireTokenSync()}wireTokenSync(){this.tokenSyncSubs.push(this.http.on("http:tokenRefresh",({token:e})=>{this.socket.setToken(e)})),this.tokenSyncSubs.push(this.socket.on("socket:tokenRefresh",e=>{const t=e;this.http.setToken(t.token)})),this.tokenSyncSubs.push(this.http.on("http:success",()=>{this.lastHttpActivity=Date.now()}))}get isConnected(){return this.socket.isConnected}async connect(){this.logger.log("[screeps:client] connect"),await this.http.authenticate(),await this.socket.connect(this.http.token),await Promise.all([this.stores.user.me(),this.stores.user.worldStatus(),this.stores.server.version()]),this.startTokenRefresh()}disconnect(){this.logger.log("[screeps:client] disconnect"),this.stopTokenRefresh(),this.socket.disconnect()}startTokenRefresh(){if(this.tokenRefreshIntervalMs===null||this.tokenRefreshTimer!==null)return;const e=this.tokenRefreshIntervalMs;this.lastHttpActivity=Date.now();const t=Math.max(1e3,Math.floor(e/2));this.tokenRefreshTimer=setInterval(()=>{Date.now()-this.lastHttpActivity<e||this.refreshTokenNow()},t)}stopTokenRefresh(){this.tokenRefreshTimer!==null&&(clearInterval(this.tokenRefreshTimer),this.tokenRefreshTimer=null)}async refreshTokenNow(){if(!this.refreshInFlight){this.refreshInFlight=!0;try{this.logger.log("[screeps:client] token refresh (idle)"),await this.stores.user.refreshWorldStatus()}catch(e){this.logger.log("[screeps:client] token refresh failed",e)}finally{this.refreshInFlight=!1}}}async clearCache(){this.logger.log("[screeps:client] clearCache"),await this.cache.clearAll()}}class yl{constructor(e){_(this,"token");this.token=e.token}async authenticate(e){return this.token}}class vl{constructor(e){_(this,"email");_(this,"password");this.email=e.email,this.password=e.password}async authenticate(e){return(await e.auth.signin(this.email,this.password)).token}}class bl{async authenticate(e){return"guest"}}const wl=1,qe="data";class xl{constructor(e){_(this,"namespace");_(this,"db",null);_(this,"openPromise",null);this.namespace=e}get dbName(){return`screeps:${this.namespace}`}open(){return this.db?Promise.resolve(this.db):this.openPromise?this.openPromise:(this.openPromise=new Promise((e,t)=>{const i=indexedDB.open(this.dbName,wl);i.onupgradeneeded=()=>{i.result.createObjectStore(qe)},i.onsuccess=()=>{this.db=i.result,this.openPromise=null,e(i.result)},i.onerror=()=>t(i.error),i.onblocked=()=>t(new Error(`IndexedDB open blocked: ${this.dbName}`))}),this.openPromise)}async get(e){const t=await this.open();return new Promise((i,n)=>{const o=t.transaction(qe,"readonly").objectStore(qe).get(e);o.onsuccess=()=>i(o.result??null),o.onerror=()=>n(o.error)})}async set(e,t){const i=await this.open();return new Promise((n,s)=>{const l=i.transaction(qe,"readwrite").objectStore(qe).put(t,e);l.onsuccess=()=>n(),l.onerror=()=>s(l.error)})}async delete(e){const t=await this.open();return new Promise((i,n)=>{const o=t.transaction(qe,"readwrite").objectStore(qe).delete(e);o.onsuccess=()=>i(),o.onerror=()=>n(o.error)})}async clear(){const e=await this.open();return new Promise((t,i)=>{const s=e.transaction(qe,"readwrite").objectStore(qe).clear();s.onsuccess=()=>t(),s.onerror=()=>i(s.error)})}}class un{constructor(){_(this,"subs",[])}add(e){this.subs.push(e)}dispose(){for(const e of this.subs)e.dispose();this.subs.length=0}}const $l=5*6e4;function gs(r,e){try{return`screeps:${r}:${new URL(e).hostname}`}catch{return`screeps:${r}:${e}`}}function ms(r){if(typeof sessionStorage>"u")return null;try{const e=sessionStorage.getItem(r);if(!e)return null;const t=JSON.parse(e);return Date.now()>t.expires?(sessionStorage.removeItem(r),null):t.data}catch{return null}}function ys(r,e){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(r,JSON.stringify({data:e,expires:Date.now()+$l}))}catch{}}function Tr(r){return r.endsWith("/")?r:`${r}/`}async function _l(r){const e=gs("version",r),t=ms(e);if(t)return t;const i=await fetch(`${Tr(r)}api/version`);if(!i.ok)throw new Error(`HTTP ${i.status}`);const n=await i.json();return ys(e,n),n}async function Sl(r){const e=gs("authmod",r),t=ms(e);if(t)return t;const i=await fetch(`${Tr(r)}api/authmod`);if(!i.ok)return null;const n=await i.json();return n.ok?(ys(e,n),n):null}async function kl(r,e){const t=new URLSearchParams({username:e}),i=await fetch(`${Tr(r)}api/register/check-username?${t}`);if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}async function Cl(r,e){const t=new URLSearchParams({email:e}),i=await fetch(`${Tr(r)}api/register/check-email?${t}`);if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}async function Tl(r,e,t,i){const n=await fetch(`${Tr(r)}api/register/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,email:t,password:i})});if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}function Ml(r,e){return r.serverData.features.find(t=>t.name===e)}function vs(r){return Ml(r,"screepsmod-auth")}const di={1:{calc(r=0){let e=0,t=0;r>0&&(e=r*30/100),r<0&&(t=-r*30/100),this.path1=`M 50 ${100-e} L ${t} 50 H ${100-t} Z`,this.path2=`M ${t} 50 H ${100-t} L 50 ${e} Z`}},2:{calc(r=0){let e=0,t=0;r>0&&(e=r*30/100),r<0&&(t=-r*30/100),this.path1=`M ${e} ${t} L 50 50 L ${100-e} ${t} V -1 H -1 Z`,this.path2=`M ${e} ${100-t} L 50 50 L ${100-e} ${100-t} V 101 H -1 Z`}},3:{calc(r=0){const e=Math.PI/4+Math.PI/4*(r+100)/200,t=-Math.PI/2,i=Math.PI/2+Math.PI/3,n=Math.PI/2-Math.PI/3;this.path1=`M 50 50 L ${50+100*Math.cos(t-e/2)} ${50+100*Math.sin(t-e/2)} L ${50+100*Math.cos(t+e/2)} ${50+100*Math.sin(t+e/2)} Z`,this.path2=`M 50 50 L ${50+100*Math.cos(i-e/2)} ${50+100*Math.sin(i-e/2)} L ${50+100*Math.cos(i+e/2)} ${50+100*Math.sin(i+e/2)} Z M 50 50 L ${50+100*Math.cos(n-e/2)} ${50+100*Math.sin(n-e/2)} L ${50+100*Math.cos(n+e/2)} ${50+100*Math.sin(n+e/2)}`},flip:"rotate180"},4:{calc(r=0){r+=100;const e=50-r*30/200,t=50+r*30/200;this.path1=`M 0 ${t} H 100 V 100 H 0 Z`,this.path2=r>0?`M 0 ${e} H 100 V ${t} H 0 Z`:""},flip:"rotate90"},5:{calc(r=0){r+=100;const e=50-r*10/200-10,t=50+r*10/200+10;this.path1=`M ${e} 0 H ${t} V 100 H ${e} Z`,this.path2=`M 0 ${e} H 100 V ${t} H 0 Z`},flip:"rotate45"},6:{calc(r=0){const e=5+(r+100)*8/200,t=50,i=20,n=80;this.path1=`M ${t-e} 0 H ${t+e} V 100 H ${t-e}`,this.path2=`M ${i-e} 0 H ${i+e} V 100 H ${i-e} Z M ${n-e} 0 H ${n+e} V 100 H ${n-e} Z`},flip:"rotate90"},7:{calc(r=0){const e=20+r*10/100;this.path1="M 0 50 Q 25 30 50 50 T 100 50 V 100 H 0 Z",this.path2=`M 0 ${50-e} Q 25 ${30-e} 50 ${50-e} T 100 ${50-e} V ${50+e} Q 75 ${70+e} 50 ${50+e} T 0 ${50+e} Z`},flip:"rotate90"},8:{calc(r=0){const e=r*20/100;this.path1="M 0 50 H 100 V 100 H 0 Z",this.path2=`M 0 50 Q 50 ${e} 100 50 Q 50 ${100-e} 0 50 Z`},flip:"rotate90"},9:{calc(r=0){let e=0,t=50;const i=70;r>0&&(e+=r/100*20),r<0&&(t+=r/100*30),this.path1=`M 50 ${e} L 100 ${e+i} V 101 H 0 V ${e+i} Z`,this.path2=`M 50 ${e+t} L 100 ${e+t+i} V 101 H 0 V ${e+t+i} Z`},flip:"rotate180"},10:{calc(r=0){let e=30,t=7;r>0&&(e+=r*50/100),r<0&&(t-=r*20/100),this.path1=`M ${50+t+e} ${50-e} A ${e} ${e} 0 0 0 ${50+t+e} ${50+e} H 101 V ${50-e} Z`,this.path2=`M ${50-t-e} ${50-e} A ${e} ${e} 0 0 1 ${50-t-e} ${50+e} H -1 V ${50-e} Z`},flip:"rotate90"},11:{calc(r=0){let e=30,t=30;const i=50-50*Math.cos(Math.PI/4),n=50-50*Math.sin(Math.PI/4);r>0&&(e+=r*25/100,t+=r*25/100),r<0&&(t-=r*50/100),this.path1=`M ${i} ${n} Q ${e} 50 ${i} ${100-n} H 0 V ${n} Z M ${100-i} ${n} Q ${100-e} 50 ${100-i} ${100-n} H 100 V ${n} Z`,this.path2=`M ${i} ${n} Q 50 ${t} ${100-i} ${n} V 0 H ${i} Z M ${i} ${100-n} Q 50 ${100-t} ${100-i} ${100-n} V 100 H ${i} Z`},flip:"rotate90"},12:{calc(r=0){let e=30,t=35;r>0&&(e+=r*30/100),r<0&&(t+=r*15/100),this.path1=`M 0 ${e} H 100 V 100 H 0 Z`,this.path2=`M 0 ${e} H ${t} V 100 H 0 Z M 100 ${e} H ${100-t} V 100 H 100 Z`},flip:"rotate180"},13:{calc(r=0){let e=30,t=0;r>0&&(e+=r*50/100),r<0&&(t-=r*20/100),this.path1="M 0 0 H 50 V 100 H 0 Z",this.path2=`M ${50-e} ${50-t-e} A ${e} ${e} 0 0 0 ${50+e} ${50-e-t} V 0 H ${50-e} Z`},flip:"rotate180"},14:{calc(r=0){let e=Math.PI/4;const t=0;e+=r*Math.PI/4/100,this.path1=`M 50 0 Q 50 ${50+t} ${50+50*Math.cos(e)} ${50+50*Math.sin(e)} H 100 V 0 H 50 Z`,this.path2=`M 50 0 Q 50 ${50+t} ${50-50*Math.cos(e)} ${50+50*Math.sin(e)} H 0 V 0 H 50 Z`},flip:"rotate180"},15:{calc(r=0){const e=13+r*6/100,t=80,i=45,n=10;this.path1=`M ${50-t-e} ${100+n} A ${t+e} ${t+e} 0 0 1 ${50+t+e} ${100+n} H ${50+t-e} A ${t-e} ${t-e} 0 1 0 ${50-t+e} ${100+n}`,this.path2=`M ${50-i-e} ${100+n} A ${i+e} ${i+e} 0 0 1 ${50+i+e} ${100+n} H ${50+i-e} A ${i-e} ${i-e} 0 1 0 ${50-i+e} ${100+n}`},flip:"rotate180"},16:{calc(r=0){let e=30*Math.PI/180,t=25;r>0&&(e+=30*Math.PI/180*r/100),r<0&&(t+=r*25/100),this.path1="";for(let i=0;i<3;i++){const n=i*Math.PI*2/3+e/2-Math.PI/2,s=i*Math.PI*2/3-e/2-Math.PI/2;this.path1+=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos(s)} ${50+t*Math.sin(s)} A ${t} ${t} 0 0 1 ${50+t*Math.cos(n)} ${50+t*Math.sin(n)} Z`}this.path2="";for(let i=0;i<3;i++){const n=i*Math.PI*2/3+e/2+Math.PI/2,s=i*Math.PI*2/3-e/2+Math.PI/2;this.path2+=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos(s)} ${50+t*Math.sin(s)} A ${t} ${t} 0 0 1 ${50+t*Math.cos(n)} ${50+t*Math.sin(n)} Z`}}},17:{calc(r=0){let e=35,t=45;r>0&&(e+=r*20/100),r<0&&(t-=r*30/100),this.path1=`M 50 45 L ${50-e} ${t+45} H ${50+e} Z`,this.path2=`M 50 0 L ${50-e} ${t} H ${50+e} Z`}},18:{calc(r=0){let e=90*Math.PI/180,t=10;r>0&&(e-=60/180*Math.PI*r/100),r<0&&(t-=r*15/100),this.path1="",this.path2="";for(let i=0;i<3;i++){const n=Math.PI*2/3*i+e/2-Math.PI/2,s=Math.PI*2/3*i-e/2-Math.PI/2,o=`M ${50+100*Math.cos(n)} ${50+100*Math.sin(n)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos((n+s)/2)} ${50+t*Math.sin((n+s)/2)} Z`;i?this.path2+=o:this.path1+=o}},flip:"rotate180"},19:{calc(r=0){let e=20,t=60;t+=r*20/100,e+=r*20/100,this.path1=`M 50 -10 L ${50-t} 100 H ${50+t} Z`,this.path2="",e>0&&(this.path2=`M 50 0 L ${50-e} 100 H ${50+e} Z`)},flip:"rotate180"},20:{calc(r=0){let e=10,t=20;r>0&&(e+=r*20/100),r<0&&(t+=r*40/100),this.path1=`M 0 ${50-t} H ${50-e} V 100 H 0 Z`,this.path2=`M ${50+e} 0 V ${50+t} H 100 V 0 Z`},flip:"rotate90"},21:{calc(r=0){let e=40,t=50;r>0&&(e-=r*20/100),r<0&&(t+=r*20/100),this.path1=`M 50 ${t} Q ${50+e} 0 50 0 T 50 ${t} Z M 50 ${100-t} Q ${50+e} 100 50 100 T 50 ${100-t} Z`,this.path2=`M ${t} 50 Q 0 ${50+e} 0 50 T ${t} 50 Z M ${100-t} 50 Q 100 ${50+e} 100 50 T ${100-t} 50 Z`},flip:"rotate45"},22:{calc(r=0){let e=20;e+=r*10/100,this.path1=`M ${50-e} ${50-e} H ${50+e} V ${50+e} H ${50-e} Z`,this.path2="";for(let t=-4;t<4;t++)for(let i=-4;i<4;i++){const n=(t+i)%2;this.path2+=`M ${50-e-e*2*t} ${50-e-e*2*(i+n)} h ${-e*2} v ${e*2} h ${e*2} Z`}},flip:"rotate45"},23:{calc(r=0){let e=17,t=25;r>0&&(e+=r*35/100),r<0&&(t-=r*23/100),this.path1="";for(let i=-4;i<=4;i++)this.path1+=`M ${50-e*i*2} ${50-t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`;this.path2="";for(let i=-4;i<=4;i++)this.path2+=`M ${50-e*i*2} ${50+t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`},flip:"rotate90"},24:{calc(r=0){let e=50,t=45;r>0&&(e+=r*60/100),r<0&&(t+=r*30/100),this.path1=`M 0 ${t} L 50 70 L 100 ${t} V 100 H 0 Z`,this.path2=`M 50 0 L ${50+e} 100 H 100 V ${t} L 50 70 L 0 ${t} V 100 H ${50-e} Z`},flip:"rotate180"}};function ui(r){const e=Math.round(r).toString(16);return e.length<2?"0"+e:e}function st(r,e,t){const i=(1-Math.abs(2*t-1))*e,n=r/60,s=i*(1-Math.abs(n%2-1));let o=0,l=0,a=0;!Number.isNaN(r)&&r!==null&&r!==void 0&&(n>=0&&n<1?(o=i,l=s,a=0):n>=1&&n<2?(o=s,l=i,a=0):n>=2&&n<3?(o=0,l=i,a=s):n>=3&&n<4?(o=0,l=s,a=i):n>=4&&n<5?(o=s,l=0,a=i):n>=5&&n<6&&(o=i,l=0,a=s));const c=t-i/2,d=(o+c)*255,f=(l+c)*255,p=(a+c)*255;return"#"+ui(d)+ui(f)+ui(p)}function El(){const r=[];let e=0;r.push({index:e++,rgb:st(0,0,.8)});for(let t=0;t<19;t++)r.push({index:e++,rgb:st(t*360/19,.6,.8)});r.push({index:e++,rgb:st(0,0,.5)});for(let t=0;t<19;t++)r.push({index:e++,rgb:st(t*360/19,.7,.5)});r.push({index:e++,rgb:st(0,0,.3)});for(let t=0;t<19;t++)r.push({index:e++,rgb:st(t*360/19,.4,.3)});r.push({index:e++,rgb:st(0,0,.1)});for(let t=0;t<19;t++)r.push({index:e++,rgb:st(t*360/19,.5,.1)});return r}const fr=El();function hi(r){if(typeof r=="string")return r;if(typeof r=="number"){const e=fr[r];return e?e.rgb:"#000000"}return"#000000"}function si(r){const e=hi(r.color1),t=hi(r.color2),i=hi(r.color3),n=r.param??0;if(typeof r.type=="number"){const d=di[r.type];d&&d.calc(n)}let s=0;if(r.flip&&typeof r.type=="number"){const d=di[r.type];(d==null?void 0:d.flip)==="rotate180"&&(s=180),(d==null?void 0:d.flip)==="rotate90"&&(s=90),(d==null?void 0:d.flip)==="rotate45"&&(s=45)}let o,l;if(typeof r.type=="number"){const d=di[r.type];o=(d==null?void 0:d.path1)??"",l=(d==null?void 0:d.path2)??""}else o=r.type.path1,l=r.type.path2;const a=50;let c='<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 100 100" shape-rendering="geometricPrecision">';return c+=`<defs><clipPath id="clip"><circle cx="50" cy="50" r="${a}"/></clipPath></defs>`,c+=`<g transform="rotate(${s} 50 50)">`,c+=`<rect x="0" y="0" width="100" height="100" fill="${e}" clip-path="url(#clip)"/>`,o&&(c+=`<path d="${o}" fill="${t}" clip-path="url(#clip)"/>`),l&&(c+=`<path d="${l}" fill="${i}" clip-path="url(#clip)"/>`),c+='<circle cx="50" cy="50" r="47.5" fill="transparent" stroke="#000" stroke-width="5"/>',c+="</g></svg>",c}const[Pl,Cn]=N([]);let Rl=0;function fe(r,e="success",t=4e3){const i=Rl++;Cn(n=>[...n,{id:i,message:r,type:e,duration:t}]),setTimeout(()=>{Cn(n=>n.filter(s=>s.id!==i))},t)}const Ol=!1;function oi(){return typeof window>"u"?!1:window.location.pathname.startsWith("/client")}function Ll(){return Ol}function hn(){return window.location.origin}function Al(){return"0.3.4"}function Il(){return typeof window>"u"?null:window.__SCREEPS_CLIENT_EMBEDDED__??null}function li(){return"/".replace(/\/$/,"")}function Pt(r){const e=`[${r}]`;return{log:()=>{},warn:()=>{},error:(...t)=>console.error(e,...t)}}const ye={room:"screeps:room",shard:"screeps:shard",sidebarWidth:"screeps:sidebarWidth",consoleHeight:"screeps:consoleHeight",consoleWeights:"screeps:consoleWeights",mapZoom:"screeps:mapZoom",widescreenMode:"screeps:settings:widescreenMode",showCreepLabels:"screeps:settings:showCreepLabels",showMapRoomNames:"screeps:settings:showMapRoomNames",showUnclaimableRooms:"screeps:settings:showUnclaimableRooms",terrainEffects:"screeps:settings:terrainEffects"},Pe={url:"screeps:url",token:"screeps:token",serverPassword:"screeps:serverPassword"};function fi(r){return localStorage.getItem(r)}function Tn(r,e){localStorage.setItem(r,e)}function Nl(r){localStorage.removeItem(r)}function Rr(r,e){const t=localStorage.getItem(r);if(t===null)return e;const i=Number(t);return Number.isFinite(i)&&i!==0?i:e}function pi(r,e){localStorage.setItem(r,String(e))}function Gl(r,e){const t=localStorage.getItem(r);if(t===null)return e;try{return JSON.parse(t)}catch{return e}}function Dl(r,e){localStorage.setItem(r,JSON.stringify(e))}function Hr(r){return sessionStorage.getItem(r)}function Or(r,e){sessionStorage.setItem(r,e)}function pr(r){sessionStorage.removeItem(r)}async function zl(){if(localStorage.clear(),indexedDB.databases){const r=await indexedDB.databases();await Promise.all(r.map(e=>e.name?new Promise(t=>{const i=indexedDB.deleteDatabase(e.name);i.onsuccess=()=>t(),i.onerror=()=>t(),i.onblocked=()=>t()}):Promise.resolve()))}if("caches"in window){const r=await caches.keys();await Promise.all(r.map(e=>caches.delete(e)))}}const{log:We}=Pt("client"),[ae,Fr]=N(null),[_t,Dt]=N("idle"),[Mn,Wr]=N(null),[Ae,Ii]=N(null),[bs,Ni]=N(null),[ut,Ur]=N(null),[Zr,ws]=N(null),[Ke,xs]=N(!1),[gi,$s]=N(null),[Bl,_s]=N({}),[Mt,Ss]=N(null);let Xr=-1,Gi=-1;const zt=[],Hl=5;function Fl(r){if(r===void 0)return;const e=Date.now();if(Xr>=0&&r>Xr){const t=e-Gi;if(t>0){zt.push(t),zt.length>Hl&&zt.shift();const i=zt.reduce((n,s)=>n+s,0)/zt.length;ws(Math.round(i))}}Xr=r,Gi=e}function Wl(){Xr=-1,Gi=-1,zt.length=0,ws(null)}const Ul=()=>{var e,t;const r=bs();return r?(((t=(e=r.serverData)==null?void 0:e.shards)==null?void 0:t.length)??0)===0:null};async function wt(r){oi()&&(r={...r,url:hn()}),We(`connecting to ${r.url} (auth: ${r.auth})`),Dt("connecting"),Wr(null);try{let e;if(r.auth==="guest")e=new bl,xs(!0);else if(r.auth==="password"){if(!r.email||!r.password)throw new Error("Email and password are required");e=new vl({email:r.email,password:r.password})}else{if(!r.token)throw new Error("Token is required");e=new yl({token:r.token})}const t=new ml({url:r.url,auth:e,storage:r.storage??new xl("screeps-client"),debug:!1,serverPassword:r.serverPassword});t.http.on("http:tokenRefresh",({token:i})=>{We("token refreshed"),Or(Pe.token,i)}),t.http.on("http:error",({method:i,path:n,error:s})=>{We("http error:",i,n,s.message),fe(`Request failed: ${i} ${n} — ${s.message}`,"error",6e3)}),t.stores.server.on("server:disconnected",i=>{We(`server disconnected (willReconnect: ${i.willReconnect})`),i.willReconnect||(Dt("idle"),Fr(null),Ii(null),Ni(null))}),t.stores.server.on("server:error",i=>{We("server error:",i.error.message),Wr(i.error.message),Dt("error")}),t.stores.user.on("user:me",i=>{We(`user: ${i.username} (id: ${i._id})`),Ii(i)}),t.stores.server.on("server:version",i=>{We(`server version: ${i.package??"unknown"}`),Ni(i)}),t.stores.user.on("user:stream",i=>{if(i&&typeof i=="object"&&"flags"in i){const n=i.flags;n&&typeof n=="object"&&_s(n)}}),t.stores.user.on("user:worldStatus",({status:i})=>{We(`world status: ${i}`),Ss(i)}),await t.connect(),t.stores.user.subscribeUserStream(),Fr(t),Dt("connected"),We(`connected to ${r.url}`),t.stores.server.worldInfo().then(i=>{$s(i),We(`world: ${i.width}x${i.height} x[${i.minX},${i.maxX}] y[${i.minY},${i.maxY}]`)}).catch(()=>{}),Or(Pe.url,r.url),t.http.token&&Or(Pe.token,t.http.token),r.serverPassword?Or(Pe.serverPassword,r.serverPassword):pr(Pe.serverPassword)}catch(e){const t=e instanceof Error?e.message:String(e);throw Wr(t),Dt("error"),Fr(null),e}}async function Xl(){const r=oi()?hn():Hr(Pe.url),e=Hr(Pe.token);if(!r||!e)return;const t=Hr(Pe.serverPassword)??void 0;try{e==="guest"?await wt({url:r,auth:"guest",storage:null,serverPassword:t}):await wt({url:r,auth:"token",token:e,serverPassword:t})}catch{pr(Pe.token)}}function Yl(){const r=ae();r&&r.disconnect(),Fr(null),Dt("idle"),Wr(null),Ii(null),Ni(null),Ur(null),xs(!1),$s(null),_s({}),Ss(null),Wl(),pr(Pe.token),pr(Pe.url),pr(Pe.serverPassword)}/**
4
+ * @license lucide-solid v0.513.0 - ISC
5
+ *
6
+ * This source code is licensed under the ISC license.
7
+ * See the LICENSE file in the root directory of this source tree.
8
+ */var ql={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"},Lt=ql,jl=E("<svg>"),En=r=>r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Vl=r=>r.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,i)=>i?i.toUpperCase():t.toLowerCase()),Zl=r=>{const e=Vl(r);return e.charAt(0).toUpperCase()+e.slice(1)},Kl=(...r)=>r.filter((e,t,i)=>!!e&&e.trim()!==""&&i.indexOf(e)===t).join(" ").trim(),Jl=r=>{const[e,t]=ls(r,["color","size","strokeWidth","children","class","name","iconNode","absoluteStrokeWidth"]);return(()=>{var i=jl();return hs(i,be(Lt,{get width(){return e.size??Lt.width},get height(){return e.size??Lt.height},get stroke(){return e.color??Lt.stroke},get"stroke-width"(){return re(()=>!!e.absoluteStrokeWidth)()?Number(e.strokeWidth??Lt["stroke-width"])*24/Number(e.size):Number(e.strokeWidth??Lt["stroke-width"])},get class(){return Kl("lucide","lucide-icon",...e.name!=null?[`lucide-${En(Zl(e.name))}`,`lucide-${En(e.name)}`]:[],e.class!=null?e.class:"")}},t),!0,!0),v(i,k(pe,{get each(){return e.iconNode},children:([n,s])=>k(fs,be({component:n},s))})),i})()},$e=Jl,Ql=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]],ea=r=>k($e,be(r,{iconNode:Ql,name:"bell-off"})),ta=ea,ra=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],ia=r=>k($e,be(r,{iconNode:ra,name:"bell"})),na=ia,sa=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],oa=r=>k($e,be(r,{iconNode:sa,name:"check"})),la=oa,aa=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],ca=r=>k($e,be(r,{iconNode:aa,name:"chevron-right"})),da=ca,ua=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],ha=r=>k($e,be(r,{iconNode:ua,name:"chevron-left"})),fa=ha,pa=[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]],ga=r=>k($e,be(r,{iconNode:pa,name:"code-xml"})),ma=ga,ya=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],va=r=>k($e,be(r,{iconNode:ya,name:"eye"})),ba=va,wa=[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]],xa=r=>k($e,be(r,{iconNode:wa,name:"flag"})),ks=xa,$a=[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]],_a=r=>k($e,be(r,{iconNode:$a,name:"hammer"})),Sa=_a,ka=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],Ca=r=>k($e,be(r,{iconNode:ka,name:"layout-grid"})),Ta=Ca,Ma=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],Ea=r=>k($e,be(r,{iconNode:Ma,name:"log-out"})),Pa=Ea,Ra=[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]],Oa=r=>k($e,be(r,{iconNode:Ra,name:"map"})),La=Oa,Aa=[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m19 9 3 3-3 3",key:"1mg7y2"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}],["path",{d:"m9 5 3-3 3 3",key:"l8vdw6"}]],Ia=r=>k($e,be(r,{iconNode:Aa,name:"move"})),Na=Ia,Ga=[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]],Da=r=>k($e,be(r,{iconNode:Ga,name:"pause"})),za=Da,Ba=[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]],Ha=r=>k($e,be(r,{iconNode:Ba,name:"play"})),Fa=Ha,Wa=[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],Ua=r=>k($e,be(r,{iconNode:Wa,name:"settings"})),Xa=Ua,Ya=[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]],qa=r=>k($e,be(r,{iconNode:Ya,name:"trash-2"})),Yr=qa,ja=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Va=r=>k($e,be(r,{iconNode:ja,name:"x"})),ai=Va,Za=E("<span style=font-size:11px;display:inline-flex;align-items:center;gap:3px>"),Ka=E('<div style="color:#3fb950;font-size:14px;text-align:center;padding:8px 0">Account created! Logging you in…'),Ja=E("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Username</span></div><input type=text name=username autocomplete=username>"),Qa=E("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Email</span></div><input type=email name=email autocomplete=email>"),ec=E("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Password</span><input type=password name=new-password autocomplete=new-password>"),tc=E("<span style=font-size:11px;color:#f85149>Passwords don't match"),rc=E("<label style=display:flex;flex-direction:column;gap:4px><div style=display:flex;align-items:baseline;gap:8px><span style=font-size:12px;color:#8b949e>Confirm Password</span></div><input type=password name=confirm-password autocomplete=new-password>"),ic=E("<button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>"),nc=E('<button type=button style="padding:8px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:12px;cursor:pointer">Back to Login'),sc=E("<form style=display:flex;flex-direction:column;gap:16px><h2 style=margin:0;font-size:20px>Create Account"),Cs=E("<div style=color:#f85149;font-size:13px>"),oc=E('<div style="width:360px;padding:16px 20px;border-radius:8px;background:#161b22;border:1px solid #30363d;color:#c9d1d9;font-size:13px;line-height:1.6">'),lc=E("<button type=button style=background:none;border:none;color:#58a6ff;font-size:12px;cursor:pointer;padding:0>Create account"),ac=E('<div style=display:flex;gap:8px><button type=button style="flex:1;padding:8px;border-radius:6px;border:1px solid #30363d;color:#fff;cursor:pointer">Password</button><button type=button style="flex:1;padding:8px;border-radius:6px;border:1px solid #30363d;color:#fff;cursor:pointer">Token'),cc=E("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Server URL</span><input type=url name=url autocomplete=url inputmode=url>"),dc=E("<div style=color:#8b949e;font-size:12px;margin-top:-8px>"),uc=E("<div style=display:flex;align-items:center;gap:8px;color:#484f58;font-size:12px><div style=flex:1;height:1px;background:#30363d></div>or<div style=flex:1;height:1px;background:#30363d>"),hc=E("<button type=button style=padding:10px;border-radius:6px;border:none;background:#1b2838;color:#c7d5e0;font-weight:600>Login with Steam"),fc=E('<button type=button style="padding:8px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:12px">Connect as Guest (read-only)'),pc=E('<form style=display:flex;flex-direction:column;gap:16px><div style=display:flex;align-items:baseline;justify-content:space-between><h2 style=margin:0;font-size:20px>Connect to Screeps</h2></div><label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Server Password <span style=color:#484f58>(optional)</span></span><input type=password name=server-password autocomplete=off data-1p-ignore data-lpignore=true placeholder="Leave empty if not required"></label><button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>'),gc=E('<div style="width:360px;padding:12px 20px;border-radius:8px;background:#161b22;border:1px solid #30363d"><div style=font-size:11px;color:#484f58;margin-bottom:8px;text-transform:uppercase;letter-spacing:0.05em>Server Mods</div><div style=display:flex;flex-wrap:wrap;gap:6px>'),mc=E('<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16px;width:100%;height:100%;overflow:auto;padding:24px 0;box-sizing:border-box"><div style="display:flex;flex-direction:column;gap:16px;width:360px;padding:32px;border-radius:8px;background:#161b22;border:1px solid #30363d">'),yc=E("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Email or Username</span><input type=text id=username name=username autocomplete=username>"),vc=E("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Password</span><input type=password id=password name=password autocomplete=current-password>"),bc=E("<label style=display:flex;flex-direction:column;gap:4px><span style=font-size:12px;color:#8b949e>Auth Token</span><input type=password name=token autocomplete=off>"),wc=E('<span style="font-size:11px;padding:2px 8px;border-radius:12px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-family:monospace">');const Je={padding:"8px 12px","border-radius":"6px",border:"1px solid #30363d",background:"#0d1117",color:"#c9d1d9"};function xc(r){const[e,t]=N(null),[i,n]=N(null),[s,o]=N(null);return he(()=>{const l=r();t(null),n(null),o(null);let a=!1;const c=setTimeout(async()=>{try{const d=await _l(l);if(a)return;if(t(d),o(null),vs(d)){const f=await Sl(l);a||n(f)}}catch{a||(o("Could not reach server"),t(null))}},400);Ie(()=>{a=!0,clearTimeout(c)})}),{serverVersion:e,authModInfo:i,serverError:s}}function Pn(r,e,t){const[i,n]=N("idle");return he(()=>{const s=e();if(!s){n("idle");return}n("checking");let o=!1;const l=setTimeout(async()=>{try{const a=await t(r(),s);o||n(a.error?"taken":"available")}catch{o||n("error")}},500);Ie(()=>{o=!0,clearTimeout(l)})}),i}function Rn(r){const e={idle:null,checking:{children:"Checking…",color:"#8b949e"},available:{children:[k(la,{size:12})," Available"],color:"#3fb950"},taken:{children:[k(ai,{size:12})," Already taken"],color:"#f85149"},error:{children:"Could not verify",color:"#d29922"}},t=()=>e[r.state];return k(X,{get when(){return t()},get children(){var i=Za();return v(i,()=>t().children),A(n=>D(i,"color",t().color)),i}})}function $c(r){const[e,t]=N(""),[i,n]=N(""),[s,o]=N(""),[l,a]=N(""),[c,d]=N(!1),[f,p]=N(null),[h,u]=N(!1),g=Pn(()=>r.url,e,kl),$=Pn(()=>r.url,i,Cl),m=()=>l()!==""&&s()!==l(),S=()=>!c()&&e()!==""&&i()!==""&&s().length>=4&&s()===l()&&g()!=="taken"&&g()!=="checking"&&$()!=="taken"&&$()!=="checking",M=async b=>{if(b.preventDefault(),!!S()){d(!0),p(null);try{const y=await Tl(r.url,e(),i(),s());if(y.error){p(y.error);return}u(!0),setTimeout(()=>r.onSuccess(i(),s()),1500)}catch(y){p(y instanceof Error?y.message:"Registration failed")}finally{d(!1)}}};return(()=>{var b=sc();return b.firstChild,b.addEventListener("submit",M),v(b,k(X,{get when(){return h()},get children(){return Ka()}}),null),v(b,k(X,{get when(){return!h()},get children(){return[(()=>{var y=Ja(),T=y.firstChild;T.firstChild;var P=T.nextSibling;return v(T,k(Rn,{get state(){return g()}}),null),P.$$input=x=>t(x.currentTarget.value),A(x=>{var C=Je,I=c();return x.e=V(P,C,x.e),I!==x.t&&(P.disabled=x.t=I),x},{e:void 0,t:void 0}),A(()=>P.value=e()),y})(),(()=>{var y=Qa(),T=y.firstChild;T.firstChild;var P=T.nextSibling;return v(T,k(Rn,{get state(){return $()}}),null),P.$$input=x=>n(x.currentTarget.value),A(x=>{var C=Je,I=c();return x.e=V(P,C,x.e),I!==x.t&&(P.disabled=x.t=I),x},{e:void 0,t:void 0}),A(()=>P.value=i()),y})(),(()=>{var y=ec(),T=y.firstChild,P=T.nextSibling;return P.$$input=x=>o(x.currentTarget.value),A(x=>{var C=Je,I=c();return x.e=V(P,C,x.e),I!==x.t&&(P.disabled=x.t=I),x},{e:void 0,t:void 0}),A(()=>P.value=s()),y})(),(()=>{var y=rc(),T=y.firstChild;T.firstChild;var P=T.nextSibling;return v(T,k(X,{get when(){return m()},get children(){return tc()}}),null),P.$$input=x=>a(x.currentTarget.value),A(x=>{var C={...Je,border:m()?"1px solid #f85149":"1px solid #30363d"},I=c();return x.e=V(P,C,x.e),I!==x.t&&(P.disabled=x.t=I),x},{e:void 0,t:void 0}),A(()=>P.value=l()),y})(),re(()=>re(()=>!!f())()&&(()=>{var y=Cs();return v(y,f),y})()),(()=>{var y=ic();return v(y,()=>c()?"Creating account…":"Create Account"),A(T=>{var P=!S(),x=S()?"pointer":"not-allowed",C=S()?1:.5;return P!==T.e&&(y.disabled=T.e=P),x!==T.t&&D(y,"cursor",T.t=x),C!==T.a&&D(y,"opacity",T.a=C),T},{e:void 0,t:void 0,a:void 0}),y})(),(()=>{var y=nc();return y.$$click=()=>r.onCancel(),y})()]}}),null),b})()}function _c(){const r=oi(),e=Ll(),[t,i]=N("login"),[n,s]=N("password"),[o,l]=N(r?hn():window.location.origin),[a,c]=N(""),[d,f]=N(""),[p,h]=N(""),[u,g]=N(""),{serverVersion:$,authModInfo:m,serverError:S}=xc(o),M=()=>{var G,R;return((R=(G=$())==null?void 0:G.serverData)==null?void 0:R.welcomeText)??null},b=()=>{var G,R;return(((R=(G=$())==null?void 0:G.serverData)==null?void 0:R.features)??[]).filter(L=>L.name!=="auth"&&L.version!=null)},y=()=>{var R,L;const G=$();return G?((L=(R=vs(G))==null?void 0:R.authTypes)==null?void 0:L.includes("steam"))??!0:!0},T=()=>{var G,R,L;return((G=m())==null?void 0:G.allowRegistration)===!0||(((L=(R=$())==null?void 0:R.serverData)==null?void 0:L.features)??[]).some(H=>H.name==="official-like")},P=()=>{const G=o().replace(/\/$/,""),R=window.open(`${G}/api/auth/steam`,"screeps-steam-auth","width=800,height=600,left=200,top=100"),L=U=>{try{const F=JSON.parse(U.data);F.token&&(z(),wt({url:G,auth:"token",token:F.token,serverPassword:u()||void 0,storage:null}))}catch{}},H=setInterval(()=>{R!=null&&R.closed&&z()},500),z=()=>{clearInterval(H),window.removeEventListener("message",L)};window.addEventListener("message",L),Ie(z)},x=async G=>{G.preventDefault(),await wt({url:o(),auth:n(),email:a()||void 0,password:d()||void 0,token:p()||void 0,serverPassword:u()||void 0,storage:null})},C=async G=>{G.preventDefault(),await wt({url:o(),auth:"guest",serverPassword:u()||void 0,storage:null})},I=async(G,R)=>{try{await wt({url:o(),auth:"password",email:G,password:R,serverPassword:u()||void 0,storage:null})}catch{i("login"),s("password"),c(G),f(R)}},O=()=>_t()==="connecting";return(()=>{var G=mc(),R=G.firstChild;return v(G,k(X,{get when(){return M()},get children(){var L=oc();return A(()=>L.innerHTML=M()),L}}),R),v(R,k(X,{get when(){return t()==="register"},get children(){return k($c,{get url(){return o()},get serverPassword(){return u()},onSuccess:I,onCancel:()=>i("login")})}}),null),v(R,k(X,{get when(){return t()==="login"},get children(){var L=pc(),H=L.firstChild;H.firstChild;var z=H.nextSibling,U=z.firstChild,F=U.firstChild;F.nextSibling;var Y=U.nextSibling,Z=z.nextSibling;return L.addEventListener("submit",x),v(H,k(X,{get when(){return T()},get children(){var W=lc();return W.$$click=()=>i("register"),W}}),null),v(L,k(X,{when:!r,get children(){var W=ac(),j=W.firstChild,J=j.nextSibling;return j.$$click=()=>s("password"),J.$$click=()=>s("token"),A(Q=>{var q=n()==="password"?"#238636":"transparent",ue=n()==="token"?"#238636":"transparent";return q!==Q.e&&D(j,"background",Q.e=q),ue!==Q.t&&D(J,"background",Q.t=ue),Q},{e:void 0,t:void 0}),W}}),z),v(L,k(X,{when:!r,get children(){return[(()=>{var W=cc(),j=W.firstChild,J=j.nextSibling;return J.$$input=Q=>l(Q.currentTarget.value),A(Q=>V(J,Je,Q)),A(()=>J.value=o()),W})(),k(X,{get when(){return S()},get children(){var W=dc();return v(W,S),W}})]}}),z),v(L,(()=>{var W=re(()=>n()==="password");return()=>W()?[(()=>{var j=yc(),J=j.firstChild,Q=J.nextSibling;return Q.$$input=q=>c(q.currentTarget.value),A(q=>V(Q,Je,q)),A(()=>Q.value=a()),j})(),(()=>{var j=vc(),J=j.firstChild,Q=J.nextSibling;return Q.$$input=q=>f(q.currentTarget.value),A(q=>V(Q,Je,q)),A(()=>Q.value=d()),j})()]:(()=>{var j=bc(),J=j.firstChild,Q=J.nextSibling;return Q.$$input=q=>h(q.currentTarget.value),A(q=>V(Q,Je,q)),A(()=>Q.value=p()),j})()})(),z),Y.$$input=W=>g(W.currentTarget.value),v(L,(()=>{var W=re(()=>!!Mn());return()=>W()&&(()=>{var j=Cs();return v(j,Mn),j})()})(),Z),v(Z,()=>O()?"Connecting…":"Connect"),v(L,k(X,{get when(){return y()},get children(){return[(()=>{var W=uc(),j=W.firstChild,J=j.nextSibling;return J.nextSibling,W})(),(()=>{var W=hc();return W.$$click=P,A(j=>{var J=O(),Q=O()?"not-allowed":"pointer",q=O()?.6:1;return J!==j.e&&(W.disabled=j.e=J),Q!==j.t&&D(W,"cursor",j.t=Q),q!==j.a&&D(W,"opacity",j.a=q),j},{e:void 0,t:void 0,a:void 0}),W})()]}}),null),v(L,k(X,{when:!r||e,get children(){var W=fc();return W.addEventListener("mouseleave",j=>{j.currentTarget.style.borderColor="#30363d"}),W.addEventListener("mouseenter",j=>{O()||(j.currentTarget.style.borderColor="#8b949e")}),W.$$click=C,A(j=>{var J=O(),Q=O()?"not-allowed":"pointer",q=O()?.6:1;return J!==j.e&&(W.disabled=j.e=J),Q!==j.t&&D(W,"cursor",j.t=Q),q!==j.a&&D(W,"opacity",j.a=q),j},{e:void 0,t:void 0,a:void 0}),W}}),null),A(W=>{var j=Je,J=O(),Q=O()?"not-allowed":"pointer",q=O()?.6:1;return W.e=V(Y,j,W.e),J!==W.t&&(Z.disabled=W.t=J),Q!==W.a&&D(Z,"cursor",W.a=Q),q!==W.o&&D(Z,"opacity",W.o=q),W},{e:void 0,t:void 0,a:void 0,o:void 0}),A(()=>Y.value=u()),L}}),null),v(G,k(X,{get when(){return b().length>0},get children(){var L=gc(),H=L.firstChild,z=H.nextSibling;return v(z,k(pe,{get each(){return b()},children:U=>(()=>{var F=wc();return v(F,()=>U.name,null),v(F,(()=>{var Y=re(()=>!!U.version);return()=>Y()?` ${U.version}`:""})(),null),F})()})),L}}),null),G})()}Se(["input","click"]);var Sc=E('<span style="padding:2px 8px;border-radius:4px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-size:11px;font-weight:600;letter-spacing:0.05em;text-transform:uppercase">Guest'),kc=E('<div style="display:flex;align-items:center;gap:12px;padding:8px 16px;border-bottom:1px solid #30363d;font-size:13px"><div style=display:flex;align-items:center;gap:6px><span style=width:8px;height:8px;border-radius:50%;display:inline-block></span><span style=color:#8b949e>');function Cc(){const r=()=>{switch(_t()){case"connected":return"#238636";case"connecting":return"#d29922";case"error":return"#f85149";default:return"#8b949e"}};return(()=>{var e=kc(),t=e.firstChild,i=t.firstChild,n=i.nextSibling;return v(n,(()=>{var s=re(()=>_t()==="connected");return()=>s()?"Online":_t()})()),v(e,k(X,{get when(){return Ke()},get children(){return Sc()}}),null),A(s=>D(i,"background-color",r())),e})()}class Tc{constructor(e){_(this,"container");_(this,"hoverGraphics");_(this,"pendingGraphics");_(this,"selectionContainer");_(this,"selectionGraphics",new Map);_(this,"selectionTypes",new Map);_(this,"selectionVisuals",new Map);_(this,"ticker",null);_(this,"tickerCallback",null);this.container=new Re,this.container.label="hoverHighlight",this.container.eventMode="none",this.hoverGraphics=new K,this.hoverGraphics.eventMode="none",this.container.addChild(this.hoverGraphics),this.pendingGraphics=new K,this.pendingGraphics.eventMode="none",this.container.addChild(this.pendingGraphics),this.selectionContainer=new Re,this.selectionContainer.eventMode="none",this.container.addChild(this.selectionContainer),e&&(this.ticker=e,this.tickerCallback=()=>this.trackCreepRings(),e.add(this.tickerCallback))}setHoveredTile(e,t){if(this.hoverGraphics.clear(),e===null||t===null)return;const i=e*w,n=t*w;this.hoverGraphics.rect(i,n,w,w),this.hoverGraphics.stroke({width:1,color:16777215,alpha:.35}),this.hoverGraphics.rect(i,n,w,w),this.hoverGraphics.fill({color:16777215,alpha:.06})}setSelectedObjects(e){this.selectionContainer.removeChildren();for(const t of this.selectionGraphics.values())t.destroy();this.selectionGraphics.clear(),this.selectionTypes.clear(),this.selectionVisuals.clear();for(const{id:t,type:i,visual:n}of e){const s=new K;s.eventMode="none",this.selectionContainer.addChild(s),this.selectionGraphics.set(t,s),this.selectionTypes.set(t,i),this.selectionVisuals.set(t,n),i==="creep"?this.drawCreepRing(s,n.x,n.y):this.drawStructureBox(s,n.x,n.y)}}clearSelection(){this.selectionContainer.removeChildren();for(const e of this.selectionGraphics.values())e.destroy();this.selectionGraphics.clear(),this.selectionTypes.clear(),this.selectionVisuals.clear()}setPendingTile(e,t){if(this.pendingGraphics.clear(),e===null||t===null)return;const i=e*w,n=t*w,s=i+w/2,o=n+w/2,l=w*.35;this.pendingGraphics.moveTo(s-l,o),this.pendingGraphics.lineTo(s+l,o),this.pendingGraphics.moveTo(s,o-l),this.pendingGraphics.lineTo(s,o+l),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.9}),this.pendingGraphics.rect(i+1,n+1,w-2,w-2),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.6})}clearPendingTile(){this.pendingGraphics.clear()}drawCreepRing(e,t,i){e.clear();const n=t+w/2,s=i+w/2,o=w*.48;e.circle(n,s,o),e.stroke({width:1.5,color:16777215,alpha:.9})}drawStructureBox(e,t,i){e.clear();const n=1;e.rect(t+n,i+n,w-n*2,w-n*2),e.stroke({width:1.5,color:16777215,alpha:.9}),e.rect(t+n,i+n,w-n*2,w-n*2),e.fill({color:16777215,alpha:.04})}trackCreepRings(){for(const[e,t]of this.selectionGraphics){if(this.selectionTypes.get(e)!=="creep")continue;const i=this.selectionVisuals.get(e);!i||i.destroyed||this.drawCreepRing(t,i.x,i.y)}}destroy(){this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null,this.clearSelection(),this.clearPendingTile(),this.pendingGraphics.destroy(),this.hoverGraphics.destroy(),this.container.destroy()}}const w=12,Ee=50*w,ge=48,ir=128;class fn{constructor(e,t){_(this,"app");_(this,"world");_(this,"hoverLayer");_(this,"destroyed",!1);_(this,"canDrag",!1);_(this,"container");_(this,"resizeObserver",null);_(this,"bounceRaf",null);_(this,"wheelTimeout",null);_(this,"navOverlay");_(this,"lastMouseX",0);_(this,"lastMouseY",0);_(this,"onHoverTile",null);_(this,"onClickTile",null);this.app=e,this.container=t,this.world=new Re,this.app.stage.addChild(this.world),this.hoverLayer=new Tc(e.ticker),this.world.addChild(this.hoverLayer.container),this.navOverlay=new Re,this.world.addChild(this.navOverlay),this.setupCamera(),this.centerView(),this.clampView(),this.setupResizeObserver()}bringNavOverlayToTop(){this.hoverLayer.container.parent===this.world&&(this.world.removeChild(this.hoverLayer.container),this.world.addChild(this.hoverLayer.container)),this.navOverlay.parent===this.world&&(this.world.removeChild(this.navOverlay),this.world.addChild(this.navOverlay))}static async create(e){const t=new cs;return await t.init({background:"#0d1117",antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0}),e.appendChild(t.canvas),new fn(t,e)}getMinScale(){const t=this.container.clientWidth,i=this.container.clientHeight;return Math.min(t,i)/(Ee+64)}clampView(e=!1){const t=this.world.scale.x,i=Ee*t,n=this.container.clientWidth,s=this.container.clientHeight,o=e?ir:0;if(i<=n){const l=n/2-i/2;e?this.world.x=Math.min(l+ir,Math.max(l-ir,this.world.x)):this.world.x=l}else{const l=n-i-ge-o,a=ge+o;this.world.x=Math.min(a,Math.max(l,this.world.x))}if(i<=s){const l=s/2-i/2;e?this.world.y=Math.min(l+ir,Math.max(l-ir,this.world.y)):this.world.y=l}else{const l=s-i-ge-o,a=ge+o;this.world.y=Math.min(a,Math.max(l,this.world.y))}this.canDrag=!0}getTargetPosition(){const e=this.world.scale.x,t=Ee*e,i=this.container.clientWidth,n=this.container.clientHeight;let s=null,o=null;if(t<=i)s=i/2-t/2;else{const l=i-t-ge,a=ge;this.world.x<l?s=l:this.world.x>a&&(s=a)}if(t<=n)o=n/2-t/2;else{const l=n-t-ge,a=ge;this.world.y<l?o=l:this.world.y>a&&(o=a)}return s===null&&o===null?null:{x:s??this.world.x,y:o??this.world.y}}springBack(){const e=this.getTargetPosition(),t=this.getTargetScale();if(!e&&t===null)return;const i=this.world.x,n=this.world.y,s=this.world.scale.x,o=performance.now(),l=300,a=this.container.clientWidth/2,c=this.container.clientHeight/2,d=(a-i)/s,f=(c-n)/s,p=h=>{const u=h-o,g=Math.min(1,u/l),$=1-Math.pow(1-g,3);if(t!==null){const m=s+(t-s)*$;this.world.scale.set(m),this.world.x=a-d*m,this.world.y=c-f*m}e&&t===null&&(this.world.x=i+(e.x-i)*$,this.world.y=n+(e.y-n)*$),g<1?this.bounceRaf=requestAnimationFrame(p):(this.bounceRaf=null,this.clampView())};this.cancelBounce(),this.bounceRaf=requestAnimationFrame(p)}cancelBounce(){this.bounceRaf!==null&&(cancelAnimationFrame(this.bounceRaf),this.bounceRaf=null)}cancelWheelTimeout(){this.wheelTimeout!==null&&(clearTimeout(this.wheelTimeout),this.wheelTimeout=null)}getTargetScale(){const e=this.getMinScale(),t=5;return this.world.scale.x<e?e:this.world.scale.x>t?t:null}setupCamera(){let e=!1,t=new rr(0,0),i=new rr(0,0);const n=this.app.canvas,s=4;n.style.touchAction="none",n.style.userSelect="none";const o=new Map;let l=!1,a=0,c=0,d=0,f=0;n.addEventListener("contextmenu",h=>{h.preventDefault()}),n.addEventListener("pointerdown",h=>{if(this.cancelBounce(),this.cancelWheelTimeout(),o.set(h.pointerId,{x:h.clientX,y:h.clientY}),n.setPointerCapture(h.pointerId),o.size>=2){e=!1,l=!0;const u=[...o.values()],g=n.getBoundingClientRect(),$=(u[0].x+u[1].x)/2-g.left,m=(u[0].y+u[1].y)/2-g.top;d=Math.hypot(u[1].x-u[0].x,u[1].y-u[0].y),f=this.world.scale.x,a=($-this.world.x)/f,c=(m-this.world.y)/f}else l=!1,e=this.canDrag,t=new rr(h.clientX,h.clientY),i=new rr(h.clientX,h.clientY)}),n.addEventListener("pointermove",h=>{var m;const u=n.getBoundingClientRect();if(this.lastMouseX=h.clientX-u.left,this.lastMouseY=h.clientY-u.top,o.has(h.pointerId)&&o.set(h.pointerId,{x:h.clientX,y:h.clientY}),l&&o.size===2){const S=[...o.values()],M=(S[0].x+S[1].x)/2-u.left,b=(S[0].y+S[1].y)/2-u.top,y=Math.hypot(S[1].x-S[0].x,S[1].y-S[0].y),T=this.getMinScale(),P=5,x=.6;let C=f*(y/d);C<T&&(C=T+(C-T)*x),C>P&&(C=P+(C-P)*x),this.cancelBounce(),this.world.scale.set(C),this.world.x=M-a*C,this.world.y=b-c*C,this.clampView(!0);return}if(!l){const S=this.screenToTile(this.lastMouseX,this.lastMouseY);this.hoverLayer.setHoveredTile((S==null?void 0:S.tx)??null,(S==null?void 0:S.ty)??null),(m=this.onHoverTile)==null||m.call(this,(S==null?void 0:S.tx)??null,(S==null?void 0:S.ty)??null)}if(!e||!this.canDrag)return;const g=h.clientX-t.x,$=h.clientY-t.y;this.world.x+=g,this.world.y+=$,t=new rr(h.clientX,h.clientY),this.clampView(!0)});const p=h=>{var m;if(n.releasePointerCapture(h.pointerId),o.delete(h.pointerId),l){o.size<2&&(l=!1,e=!1,this.springBack());return}e=!1;const u=h.clientX-i.x,g=h.clientY-i.y;if(Math.sqrt(u*u+g*g)<s){const S=n.getBoundingClientRect(),M=h.clientX-S.left,b=h.clientY-S.top,y=this.screenToTile(M,b);y&&((m=this.onClickTile)==null||m.call(this,y.tx,y.ty,h.ctrlKey||h.metaKey))}this.springBack()};n.addEventListener("pointerup",p),n.addEventListener("pointercancel",p),n.addEventListener("pointerleave",()=>{var h;this.hoverLayer.setHoveredTile(null,null),(h=this.onHoverTile)==null||h.call(this,null,null)}),n.addEventListener("wheel",h=>{h.preventDefault();const u=h.deltaY>0?.9:1.1,g=this.getMinScale(),$=5;let m=this.world.scale.x*u;const S=.6;m<g&&(m=g+(m-g)*S),m>$&&(m=$+(m-$)*S);const M=n.getBoundingClientRect(),b=h.clientX-M.left,y=h.clientY-M.top;if(this.cancelBounce(),m<g){const T=this.container.clientWidth/2,P=this.container.clientHeight/2,x=(T-this.world.x)/this.world.scale.x,C=(P-this.world.y)/this.world.scale.y;this.world.scale.set(m),this.world.x=T-x*m,this.world.y=P-C*m}else{const T=(b-this.world.x)/this.world.scale.x,P=(y-this.world.y)/this.world.scale.y;this.world.scale.set(m),this.world.x=b-T*m,this.world.y=y-P*m}this.clampView(),this.cancelWheelTimeout(),this.wheelTimeout=window.setTimeout(()=>{this.wheelTimeout=null,this.springBack()},80)},{passive:!1})}setTileHandlers(e,t){this.onHoverTile=e,this.onClickTile=t}screenToTile(e,t){const i=(e-this.world.x)/this.world.scale.x,n=(t-this.world.y)/this.world.scale.y,s=Math.floor(i/w),o=Math.floor(n/w);return s<0||s>=50||o<0||o>=50?null:{tx:s,ty:o}}centerView(){const e=this.container.clientWidth/2,t=this.container.clientHeight/2,i=this.world.scale.x;this.world.x=e-Ee*i/2,this.world.y=t-Ee*i/2}resetView(){this.cancelBounce(),this.cancelWheelTimeout(),this.world.scale.set(this.getMinScale()),this.centerView(),this.clampView()}setupResizeObserver(){const{width:e,height:t}=this.container.getBoundingClientRect();this.app.renderer.resize(e,t),this.resizeObserver=new ResizeObserver(i=>{const{width:n,height:s}=i[0].contentRect;this.app.renderer.resize(n,s),this.clampView()}),this.resizeObserver.observe(this.container)}setupNavigationZones(e){this.navOverlay.removeChildren();const t=(o,l,a,c,d,f)=>{if(!f)return;const p=new K;p.x=o,p.y=l,p.hitArea=new ds(0,0,a,c),p.fill({color:16777215,alpha:.12}),p.poly(d),p.fill(),p.eventMode="static",p.cursor="pointer",p.alpha=1,p.on("pointerover",()=>{p.clear(),p.fill({color:16777215,alpha:.06}),p.rect(0,0,a,c),p.fill(),p.fill({color:16777215,alpha:.35}),p.poly(d),p.fill()}),p.on("pointerout",()=>{p.clear(),p.fill({color:16777215,alpha:.12}),p.poly(d),p.fill()}),p.on("pointerdown",f),this.navOverlay.addChild(p)},i=Ee/2,n=Ee/2,s=18;t(-ge,0,ge,Ee,[18,n,ge-6,n-s,ge-6,n+s],e.west),t(Ee,0,ge,Ee,[ge-18,n,6,n-s,6,n+s],e.east),t(0,-ge,Ee,ge,[i,18,i-s,ge-6,i+s,ge-6],e.north),t(0,Ee,Ee,ge,[i,ge-18,i-s,6,i+s,6],e.south);for(const o of this.navOverlay.children){const l=o,a=l.hitArea,c=this.world.x+l.x*this.world.scale.x,d=this.world.y+l.y*this.world.scale.y,f=a.width*this.world.scale.x,p=a.height*this.world.scale.y;this.lastMouseX>=c&&this.lastMouseX<=c+f&&this.lastMouseY>=d&&this.lastMouseY<=d+p&&l.emit("pointerover",new Event("pointerover"))}}clear(){for(let e=this.world.children.length-1;e>=0;e--){const t=this.world.children[e];t!==this.navOverlay&&t!==this.hoverLayer.container&&this.world.removeChild(t)}this.navOverlay.removeChildren(),this.hoverLayer.clearSelection(),this.hoverLayer.setHoveredTile(null,null),this.world.scale.set(1),this.cancelBounce(),this.cancelWheelTimeout(),this.clampView()}destroy(){var e;this.destroyed||(this.destroyed=!0,this.cancelBounce(),this.cancelWheelTimeout(),(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=null,this.hoverLayer.destroy(),this.app.destroy(!0,{children:!0}))}}const Ts=856343,Mc=1448738,Ec=1843496,Pc=3421243,Rc=Pc,Oc=Ts,pn=7039337,Ms=3159613,Lc=1579032,Ac=0,Ic=2631720,Nc=2632986,Gc=2500383,Dc=2771488,zc=5000268,Bc=11122630,Hc=16770413,Fc=7829367,Wc=16332866,Uc=6127794,Xc=6684002,Yc=12164347,Lr={tough:zc,move:Bc,work:Hc,carry:Fc,attack:Wc,ranged_attack:Uc,heal:Xc,claim:Yc},mi=5809919,St=7979263,Es=4176208,yi=9147550,Ar=13801762,On=10711543,qc=16218298,Ln=16273737,gr=15763518,jc=2172461,Ps=pn,Vc=13226457,vt=12283502,Wt=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],Zc={creep:gr,spawn:mi,extension:St,tower:Es,container:yi,storage:Ar,link:On,rampart:mi,road:Ps,wall:jc,extractor:yi,lab:qc,terminal:Ar,observer:St,powerSpawn:gr,nuker:Ln,factory:yi,invaderCore:Ln,source:Ar,mineral:St,deposit:Ar,controller:mi,powerBank:gr,portal:On},Mr=16771195,Kc=Mr,Jc=St,Qc=Mr,mr=9419667,ed=7245682,td=12116924,rd=12283502,id=9787480,nd=14721184,An=Ec,sd=13684944,me=1579032,gt=5592405,qr=11184810,od=9419667,Ye=16771195,ld=16069959,In=4410435,ad=w*.05,cd=w*.2;function Ut(r,e,t,i){const n=w,s=n/2;let o=!1;for(let l=0;l<50;l++)for(let a=0;a<50;a++){const c=e.get(a,l)===t,d=l>0&&e.get(a,l-1)===t,f=l<49&&e.get(a,l+1)===t,p=a>0&&e.get(a-1,l)===t,h=a<49&&e.get(a+1,l)===t,u=a*n+s,g=l*n+s;c?(o=!0,!d&&!p&&l>0&&a>0?(r.moveTo(u,l*n),r.arc(u,g,s,-Math.PI/2,Math.PI,!0),r.lineTo(u,g),r.closePath()):r.rect(a*n,l*n,s,s)):d&&p&&e.get(a-1,l-1)===t&&(o=!0,r.moveTo(u,l*n),r.lineTo(a*n,l*n),r.lineTo(a*n,g),r.arc(u,g,s,Math.PI,-Math.PI/2,!1),r.closePath()),c?!d&&!h&&l>0&&a<49?(r.moveTo(u,l*n),r.arc(u,g,s,-Math.PI/2,0,!1),r.lineTo(u,g),r.closePath()):r.rect(u,l*n,s,s):d&&h&&e.get(a+1,l-1)===t&&(o=!0,r.moveTo(u,l*n),r.lineTo(a*n+n,l*n),r.lineTo(a*n+n,g),r.arc(u,g,s,0,-Math.PI/2,!0),r.closePath()),c?!f&&!p&&l<49&&a>0?(r.moveTo(a*n,g),r.arc(u,g,s,Math.PI,Math.PI/2,!0),r.lineTo(u,g),r.closePath()):r.rect(a*n,g,s,s):f&&p&&e.get(a-1,l+1)===t&&(o=!0,r.moveTo(a*n,g),r.lineTo(a*n,l*n+n),r.lineTo(u,l*n+n),r.arc(u,g,s,Math.PI/2,Math.PI,!1),r.closePath()),c?!f&&!h&&l<49&&a<49?(r.moveTo(u,l*n+n),r.arc(u,g,s,Math.PI/2,0,!0),r.lineTo(u,g),r.closePath()):r.rect(u,g,s,s):f&&h&&e.get(a+1,l+1)===t&&(o=!0,r.moveTo(u,l*n+n),r.lineTo(a*n+n,l*n+n),r.lineTo(a*n+n,g),r.arc(u,g,s,0,Math.PI/2,!1),r.closePath())}o&&i(r)}function dd(r,e){const t=pn,i=w,n=(s,o,l)=>{const a=s*i+i/2,c=o*i+i/2,d=i*.3;l==="up"?(r.moveTo(a,c-d),r.lineTo(a+d,c+d),r.lineTo(a-d,c+d)):l==="down"?(r.moveTo(a,c+d),r.lineTo(a+d,c-d),r.lineTo(a-d,c-d)):l==="left"?(r.moveTo(a-d,c),r.lineTo(a+d,c-d),r.lineTo(a+d,c+d)):l==="right"&&(r.moveTo(a+d,c),r.lineTo(a-d,c-d),r.lineTo(a-d,c+d)),r.fill(t)};for(let s=0;s<50;s++)e.get(s,0)!==Fe.Wall&&n(s,0,"up"),e.get(s,49)!==Fe.Wall&&n(s,49,"down");for(let s=0;s<50;s++)e.get(0,s)!==Fe.Wall&&n(0,s,"left"),e.get(49,s)!==Fe.Wall&&n(49,s,"right")}function ud(r){const e=new K;e.rect(0,0,50*w,50*w),e.fill(Rc);const t={color:Gc,width:cd,alignment:0,cap:"round",join:"round"};Ut(e,r,Fe.Swamp,n=>n.stroke(t)),Ut(e,r,Fe.Swamp,n=>n.fill(Nc));const i={color:Ac,width:ad,alignment:0,cap:"round",join:"round"};return Ut(e,r,Fe.Wall,n=>n.stroke(i)),Ut(e,r,Fe.Wall,n=>n.fill(Lc)),dd(e,r),e.rect(0,0,50*w,50*w),e.stroke({width:1,color:Ms}),e}function hd(r){const e=new K;return e.label="swampGlow",Ut(e,r,Fe.Swamp,t=>t.fill(Dc)),e.alpha=.45,e.filters=[new _o({strength:5,quality:3})],e}function fd(r,e){const t=new K;Ut(t,r,Fe.Wall,s=>s.fill(Ic)),t.alpha=.5,t.filters=[new $o({noise:.12,seed:1})],t.filterArea=new ds(0,0,50*w,50*w);const i=e.generateTexture({target:t,frame:t.filterArea});t.filters=null,t.destroy();const n=new Zt(i);return n.label="wallNoise",n}function Nn(r,e){const t=new Re,i=fd(r,e),n=t.destroy.bind(t);return t.destroy=s=>{i.destroyed||(i.removeFromParent(),i.destroy({texture:!0,textureSource:!0})),n(s)},t.addChild(ud(r)),t.addChild(hd(r)),t.addChild(i),t}function vi(r,e){r.getChildByLabel("swampGlow").visible=e,r.getChildByLabel("wallNoise").visible=e}function pd(r){return new Promise((e,t)=>{const i=new Image;i.onload=()=>e(i),i.onerror=t,i.src=r})}class Rs{constructor(){_(this,"cache",new Map);_(this,"pending",new Map)}getKey(e){return JSON.stringify(e)}has(e){return this.cache.has(this.getKey(e))}getOrCreate(e){const t=this.getKey(e),i=this.cache.get(t);if(i)return Promise.resolve(i);const n=this.pending.get(t);if(n)return n;const s=this.buildTexture(e,t);return this.pending.set(t,s),s.then(()=>{this.pending.delete(t)}).catch(()=>{this.pending.delete(t)}),s}async buildTexture(e,t){const i=si(e),n=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(n);try{const o=window.devicePixelRatio||1,l=128*Math.max(2,o),a=await pd(s),c=document.createElement("canvas");c.width=l,c.height=l,c.getContext("2d").drawImage(a,0,0,l,l);const f=yt.from(c);return this.cache.set(t,f),f}finally{URL.revokeObjectURL(s)}}destroy(){for(const e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}}const gd=new Rs,ct=w*.44,Xe=w*.28,nr=50,Di=32,zi=12/Di,Os=w/2-w*.44,Ls=2,Gn=w*.42,As=w*.3,md=Math.max(1,w*.08),yd={H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379},vd={H:2236962,O:2236962},bd=w*.42,Is=32,wd=9/Is,Bi=w-4,Dn=w*.28,zn=1600,xd=16776428;function Hi(r,e){if(e<=0)return Bi;const t=Math.max(0,Math.min(1,r/e));return Dn+(Bi-Dn)*t}function gn(r,e,t=Ye){const i=e/2,n=w/2,s=w/2,o=e*.25;r.clear(),r.roundRect(n-i,s-i,e,e,o),r.fill(t)}function $d(r,e){const t=r.__sourceGraphics;t&&(r.__sourceSize=e,gn(t,e,mn(performance.now())))}function mn(r){const e=r%zn/zn,t=.5-.5*Math.cos(e*Math.PI*2);return Ds(Ye,xd,t)}function Fi(r){const e=typeof r.energy=="number"?r.energy:0,t=typeof r.energyCapacity=="number"?r.energyCapacity:3e3;return{energy:e,capacity:t}}const Ns=w*.3,Gs=Math.max(1,w*.12),Wi=Ns-Gs/2,_d=w*.42,Sd=1500;function Ds(r,e,t){const i=r>>16&255,n=r>>8&255,s=r&255,o=e>>16&255,l=e>>8&255,a=e&255,c=Math.round(i+(o-i)*t),d=Math.round(n+(l-n)*t),f=Math.round(s+(a-s)*t);return c<<16|d<<8|f}function zs(r,e){r.clear(),r.circle(w/2,w/2,Ns),r.stroke({width:Gs,color:e,alpha:.95})}function Ui(r,e,t,i,n,s,o){if(r.clear(),s<=0||n<=0)return;const l=Math.min(1,n/s);if(l>=1){r.circle(e,t,i),r.fill({color:o,alpha:.55});return}const a=-Math.PI/2,c=a+l*Math.PI*2;r.moveTo(e,t),r.lineTo(e+i*Math.cos(a),t+i*Math.sin(a)),r.arc(e,t,i,a,c),r.closePath(),r.fill({color:o,alpha:.55})}function ot(r,e,t){return t.flatMap(([i,n])=>[r+i*w,e+n*w])}function At(r,e,t,i){t-e<.001||(r.moveTo(ct*Math.cos(e),ct*Math.sin(e)),r.arc(0,0,ct,e,t),r.lineTo(Xe*Math.cos(t),Xe*Math.sin(t)),r.arc(0,0,Xe,t,e,!0),r.closePath(),r.fill(i))}function Xi(r){let e=0;if(typeof r.storeCapacity=="number")e=r.storeCapacity;else{const i=r.body;i&&(e=i.filter(n=>n.type==="carry").length*50)}if(e===0)return{used:0,capacity:0};let t=0;if(r.store&&typeof r.store=="object"){const i=r.store;for(const n in i){const s=i[n];typeof s=="number"&&(t+=s)}}else typeof r.energy=="number"&&(t=r.energy);return{used:t,capacity:e}}function Yi(r,e){return e<=0||r<=0?0:Xe*.8*Math.min(1,r/e)}function kd(r,e){const t=r.__creepFillGraphics;t&&(t.clear(),e>0&&(t.circle(0,0,e),t.fill(Mr)))}function Cd(r){return Zc[r]??Vc}function Xt(r){let e=50;typeof r.energyCapacity=="number"?e=r.energyCapacity:typeof r.storeCapacity=="number"?e=r.storeCapacity:r.storeCapacityResource&&typeof r.storeCapacityResource=="object"&&(e=r.storeCapacityResource.energy??50);let t=0;return typeof r.energy=="number"?t=r.energy:r.store&&typeof r.store=="object"&&(t=r.store.energy??0),{energy:t,capacity:e}}function Bs(r){return r>=200?1.15:r>=100?.85:.7}function qi(r,e){return e<=0||r<=0?0:As*Bs(e)*Math.min(1,r/e)}function Td(r,e,t,i){const n=w/2,s=w/2,o=Bs(t),l=new K;l.circle(n,s,Gn*o),l.fill(me),l.circle(n,s,Gn*o),l.stroke({width:md*o,color:i}),l.circle(n,s,As*o),l.fill(qr),r.addChild(l);const a=new K,c=qi(e,t);c>0&&(a.circle(n,s,c),a.fill(Ye)),r.addChild(a),r.__fillGraphics=a}function Md(r,e){const t=w/2,i=w/2,n=r.__fillGraphics;n&&(n.clear(),e>0&&(n.circle(t,i,e),n.fill(Ye)))}const ji=-w*.4,Vi=-w*.3,Zi=w*.8,Kr=w*.6;function Ki(r,e){return e<=0||r<=0?0:Kr*Math.min(1,r/e)}function Hs(r,e){const t=r.__towerFillGraphics;if(t&&(t.clear(),e>0)){const i=Math.max(.5,w*.02);t.rect(ji+i,Vi+Kr-e+i,Zi-i*2,e-i*2),t.fill(Ye)}}const Ji=w*.65,Qi=Ji,Ve=w*.42;function en(r,e,t,i,n,s,o,l){r.clear();const a=8,c=.1,d=2*Math.PI/a-c;for(let f=0;f<a;f++){const p=-Math.PI/2+f*(2*Math.PI/a)+c/2,h=p+d,u=e+n*Math.cos(p),g=t+n*Math.sin(p);if(f<s)r.moveTo(u,g),r.arc(e,t,i,p,h),r.arc(e,t,n,h,p,!0),r.closePath(),r.fill({color:14540253,alpha:.9});else if(f===s&&l>0){if(r.moveTo(u,g),r.arc(e,t,i,p,h),r.arc(e,t,n,h,p,!0),r.closePath(),r.fill({color:1973790,alpha:.85}),o>0){const $=Math.min(1,o/l),m=p+d*$;r.moveTo(u,g),r.arc(e,t,i,p,m),r.arc(e,t,n,m,p,!0),r.closePath(),r.fill({color:14540253,alpha:.9})}}else r.moveTo(u,g),r.arc(e,t,i,p,h),r.arc(e,t,n,h,p,!0),r.closePath(),r.fill({color:1973790,alpha:.6})}}function Jr(r,e){const t=r.user;return typeof t!="string"||!e?!1:t!==e}function Ir(r,e=!0,t,i,n,s){var u,g,$;const o=new Re,l=new K,a=Cd(r.type),c=w/2,d=w/2,f=typeof r.user=="string"?r.user:void 0,h=f!==void 0&&t!==void 0&&f!==t?vt:od;switch(r.type){case"creep":{const m=2*Math.PI,S=new Re;S.position.set(c,d),S.rotation=-Math.PI/2;const M=Jr(r,t);if(M){const ie=new K;ie.circle(0,0,ct+.75),ie.stroke({width:1.5,color:vt}),S.addChild(ie)}const b=new K;b.circle(0,0,ct),b.fill(Ts),S.addChild(b);const y=r.body??[];let T=0,P=0,x=0;const C=[],I={};for(const ie of y)ie.type==="work"?T++:ie.type==="move"?P++:(I[ie.type]===void 0&&(C.push(ie.type),I[ie.type]=0),I[ie.type]++,x++);const O=T/nr*m,G=P/nr*m,R=x/nr*m,L=O/2,H=L+R/2,z=Math.PI-G/2,U=Math.PI+G/2,F=m-O/2-R/2,Y=m-O/2,Z=new K;O>0&&At(Z,-O/2,L,Lr.work);let W=L;for(const ie of C){const Me=(I[ie]??0)/nr*m/2;At(Z,W,W+Me,Lr[ie]??7829367),W+=Me}At(Z,H,z,An),G>0&&At(Z,z,U,Lr.move),At(Z,U,F,An);let j=Y;for(const ie of C){const Me=(I[ie]??0)/nr*m/2;At(Z,j-Me,j,Lr[ie]??7829367),j-=Me}S.addChild(Z);const J=new K;J.circle(0,0,Xe),J.fill(Mc),S.addChild(J);const Q=typeof r.user=="string"?r.user:void 0,q=Q?(u=s==null?void 0:s[Q])==null?void 0:u.badge:void 0;if(q&&n){const ie=new Zt;ie.anchor.set(.5,.5);const Me=Xe*2;ie.width=Me,ie.height=Me,ie.rotation=Math.PI/2,S.addChild(ie),o.__creepBadgeSprite=ie,n.getOrCreate(q).then(pt=>{ie.destroyed||(ie.texture=pt)}).catch(()=>{})}else if(M){const ie=new K;ie.circle(0,0,Xe*.82),ie.fill({color:vt,alpha:.9}),S.addChild(ie),o.__creepForeignMark=ie}const{used:ue,capacity:Oe}=Xi(r),rt=Yi(ue,Oe),Ne=new K;rt>0&&(Ne.circle(0,0,rt),Ne.fill(Mr)),S.addChild(Ne),o.__creepFillGraphics=Ne,o.__creepUsed=ue,o.__creepCapacity=Oe;const Ge=(ct+Xe)/2,it=(ct-Xe)*.45,De=new K;De.moveTo(ct,0),De.lineTo(Ge,-it),De.lineTo(Ge,it),De.closePath(),De.fill(sd),S.addChild(De),o.addChild(S),o.__bodyContainer=S;break}case"extension":{const{energy:m,capacity:S}=Xt(r);Td(o,m,S,h),o.__extEnergy=m,o.__extCapacity=S;break}case"spawn":{l.circle(c,d,w*.65),l.fill(me),l.circle(c,d,w*.65),l.stroke({width:w*.1,color:13421772}),l.circle(c,d,w*.4),l.fill(Ye);break}case"powerSpawn":{l.circle(c,d,w*.65),l.fill(me),l.circle(c,d,w*.65),l.stroke({width:w*.1,color:ld}),l.circle(c,d,w*.4),l.fill(Ye);break}case"source":{const{energy:m,capacity:S}=Fi(r),M=Hi(m,S),b=new K;gn(b,M,mn(performance.now())),o.addChild(b),o.__sourceGraphics=b,o.__sourceEnergy=m,o.__sourceCapacity=S,o.__sourceSize=M;break}case"constructionSite":{const m=typeof r.user=="string"?r.user:void 0,S=m!==void 0&&m===t,M=S?mr:rd,b=S?ed:id,y=S?td:nd,T=typeof r.progress=="number"?r.progress:0,P=typeof r.progressTotal=="number"?r.progressTotal:1,x=new K;o.addChild(x),o.__csBuildGlow=x;const C=new K;Ui(C,c,d,Wi,T,P,M),o.addChild(C),o.__csFillGraphics=C;const I=new K;zs(I,M),o.addChild(I),o.__csRingGraphics=I,o.__csProgress=T,o.__csProgressTotal=P,o.__csUser=m,o.__csColor=M,o.__csColorDark=b,o.__csColorLight=y;break}case"mineral":{const m=typeof r.mineralType=="string"?r.mineralType:"?",S=yd[m]??St,M=vd[m]??16777215,b=new K;b.circle(c,d,bd),b.fill(S),o.addChild(b);const y=new qt({text:m,style:{fontSize:Is,fill:M,fontWeight:"bold"}});y.anchor.set(.5,.5),y.scale.set(wd),y.position.set(c,d),o.addChild(y);break}case"deposit":{l.rect(2,2,w-4,w-4),l.fill(a);break}case"controller":{const m=typeof r.level=="number"?r.level:0,S=typeof r.progress=="number"?r.progress:0,M=typeof r.progressTotal=="number"?r.progressTotal:0,b=typeof r.user=="string"?r.user:void 0,y=b?(g=s==null?void 0:s[b])==null?void 0:g.badge:void 0,T=new K,P=[];for(let I=0;I<8;I++){const O=-Math.PI/2+I*Math.PI/4;P.push(c+Ji*Math.cos(O),d+Ji*Math.sin(O))}T.poly(P),T.fill(2238513),T.poly(P),T.stroke({width:w*.07,color:8027781}),o.addChild(T);const x=new K;en(x,c,d,Qi,Ve,m,S,M),o.addChild(x),o.__ctrlSegGraphics=x,o.__ctrlLevel=m,o.__ctrlProgress=S,o.__ctrlProgressTotal=M;const C=new K;if(y?(C.circle(c,d,Ve),C.fill(me)):(C.circle(c,d,Ve),C.fill(3028031),C.circle(c,d,Ve),C.stroke({width:w*.04,color:8027781}),C.circle(c,d,w*.16),C.fill(10133672)),o.addChild(C),y&&n){const I=new Zt;I.anchor.set(.5,.5),I.width=Ve*2,I.height=Ve*2,I.position.set(c,d);const O=new K;O.circle(c,d,Ve),O.fill(16777215),o.addChild(I),I.mask=O,o.addChild(O),n.getOrCreate(y).then(G=>{I.destroyed||(I.texture=G)}).catch(()=>{})}break}case"energy":{l.circle(c,d,w*.2),l.fill(Ye);break}case"road":break;case"wall":{l.circle(c,d,w*.4),l.fill(me),l.circle(c,d,w*.4),l.stroke({width:w*.05,color:qr});break}case"rampart":break;case"tower":{const{energy:m,capacity:S}=Xt(r),M=new K;M.circle(c,d,w*.6),M.fill(me),M.circle(c,d,w*.6),M.stroke({width:w*.05,color:h}),o.addChild(M);const b=new Re;b.position.set(c,d);const y=new K;y.rect(ji,Vi,Zi,Kr),y.fill(me),b.addChild(y);const T=new K;b.addChild(T),o.__towerFillGraphics=T,o.__towerEnergy=m,o.__towerCapacity=S,Hs(o,Ki(m,S));const P=new K;P.rect(ji,Vi,Zi,Kr),P.stroke({width:1,color:gt}),b.addChild(P);const x=new K;x.rect(-w*.2,-w*.9,w*.4,w*.5),x.fill(qr),x.rect(-w*.2,-w*.9,w*.4,w*.5),x.stroke({width:w*.07,color:me}),b.addChild(x),o.addChild(b),o.__barrelContainer=b;break}case"storage":{const m=ot(c,d,[[-.6,-.7],[0,-.8],[.6,-.7],[.65,0],[.6,.7],[0,.8],[-.6,.7],[-.65,0],[-.6,-.7]]);l.poly(m),l.fill(me),l.poly(m),l.stroke({width:w*.05,color:h}),l.rect(c-w*.5,d-w*.6,w*1,w*1.2),l.fill(gt),l.rect(c-w*.5,d-w*.6,w*1,w*1.2),l.stroke({width:w*.1,color:me});break}case"terminal":{const m=ot(c,d,[[0,-.8],[.55,-.55],[.8,0],[.55,.55],[0,.8],[-.55,.55],[-.8,0],[-.55,-.55],[0,-.8]]),S=ot(c,d,[[0,-.65],[.45,-.45],[.65,0],[.45,.45],[0,.65],[-.45,.45],[-.65,0],[-.45,-.45],[0,-.65]]);l.poly(m),l.fill(me),l.poly(m),l.stroke({width:w*.05,color:h}),l.poly(S),l.fill(qr),l.rect(c-w*.45,d-w*.45,w*.9,w*.9),l.fill(gt),l.rect(c-w*.45,d-w*.45,w*.9,w*.9),l.stroke({width:w*.1,color:me});break}case"link":{const m=ot(c,d,[[0,-.5],[.4,0],[0,.5],[-.4,0],[0,-.5]]),S=ot(c,d,[[0,-.3],[.25,0],[0,.3],[-.25,0],[0,-.3]]);l.poly(m),l.fill(me),l.poly(m),l.stroke({width:w*.05,color:h}),l.poly(S),l.fill(gt);break}case"lab":{const m=d-w*.025;l.circle(c,m,w*.55),l.fill(me),l.circle(c,m,w*.55),l.stroke({width:w*.05,color:h}),l.circle(c,m,w*.4),l.fill(gt),l.rect(c-w*.45,d+w*.3,w*.9,w*.25),l.fill(me),l.poly(ot(c,d,[[-.45,.3],[-.45,.55],[.45,.55],[.45,.3]])),l.stroke({width:w*.05,color:h});break}case"container":{l.rect(c-w*.225,d-w*.3,w*.45,w*.6),l.fill(Ye),l.rect(c-w*.225,d-w*.3,w*.45,w*.6),l.stroke({width:w*.1,color:me});break}case"observer":{l.circle(c,d,w*.45),l.fill(me),l.circle(c,d,w*.45),l.stroke({width:w*.05,color:h}),l.circle(c+w*.225,d,w*.2),l.fill(h);break}case"nuker":{const m=ot(c,d,[[0,-1],[-.47,.2],[-.5,.5],[.5,.5],[.47,.2],[0,-1]]),S=ot(c,d,[[0,-.8],[-.4,.2],[.4,.2],[0,-.8]]);l.poly(m),l.fill(me),l.poly(m),l.stroke({width:w*.05,color:h}),l.poly(S),l.fill(gt),l.poly(S),l.stroke({width:w*.01,color:h});break}case"factory":case"extractor":case"invaderCore":{l.circle(c,d,w*.45),l.fill(me),l.circle(c,d,w*.45),l.stroke({width:w*.05,color:h}),l.circle(c,d,w*.35),l.fill(gt);break}case"flag":{const m=typeof r.color=="number"?r.color:0,S=typeof r.secondaryColor=="number"?r.secondaryColor:0,M=Wt[m]??Wt[0],b=Wt[S]??Wt[0],y=1.5,T=w*.08*y,P=w*.7*y,x=c-T/2,C=d-w*.25*y;l.rect(x,C,T,P),l.fill(8947848);const I=x+T,O=C,G=I+w*.45*y,R=O,L=O+w*.44*y,H=(R+L)/2,z=H;if(l.moveTo(I,R),l.lineTo(G,H),l.lineTo(I,z),l.closePath(),l.fill(M),l.moveTo(I,z),l.lineTo(G,H),l.lineTo(I,L),l.closePath(),l.fill(b),o.addChild(l),o.__flagColor=m,o.__flagSecondaryColor=S,typeof r.name=="string"){const U=new qt({text:r.name,style:{fontSize:Di,fill:16777215}});U.scale.set(zi),U.anchor.set(.5,0),U.x=c,U.y=d+w*.55,U.visible=e,o.__nameLabel=U,o.addChild(U)}break}case"ruin":{const m=typeof r.user=="string"?r.user:void 0,M=m!==void 0&&m===t?mr:vt,b=w*.42,y=6,T=Math.PI/5,P=new K;for(let I=0;I<y;I++){const O=I*Math.PI*2/y,G=O-T/2,R=O+T/2,L=c+b*Math.cos(G),H=d+b*Math.sin(G);P.moveTo(L,H),P.arc(c,d,b,G,R),P.stroke({width:w*.09,color:M,alpha:.75,cap:"round"})}o.addChild(P);const x=w*.18,C=new K;C.moveTo(c-x,d-x),C.lineTo(c+x,d+x),C.moveTo(c+x,d-x),C.lineTo(c-x,d+x),C.stroke({width:w*.11,color:M,cap:"round"}),o.addChild(C);break}case"tombstone":{const m=typeof r.user=="string"?r.user:void 0,M=m!==void 0&&m===t?mr:vt,b=w*.62,y=w*.82,T=c-b/2,P=d-y/2,x=b/2,C=new K;C.moveTo(T,P+x),C.arc(c,P+x,x,Math.PI,0,!1),C.lineTo(T+b,P+y),C.lineTo(T,P+y),C.closePath(),C.fill(me),C.moveTo(T,P+x),C.arc(c,P+x,x,Math.PI,0,!1),C.lineTo(T+b,P+y),C.lineTo(T,P+y),C.closePath(),C.stroke({width:w*.07,color:M,alpha:.9}),o.addChild(C);const I=w*.18,O=new K;O.moveTo(c-I,d-I*.6),O.lineTo(c+I,d+I*.6),O.moveTo(c+I,d-I*.6),O.lineTo(c-I,d+I*.6),O.stroke({width:w*.09,color:M,cap:"round"}),o.addChild(O);break}default:{const m=w-2;l.rect(1,1,m,m),l.fill(a)}}if(r.type!=="extension"&&r.type!=="road"&&r.type!=="creep"&&r.type!=="tower"&&r.type!=="controller"&&r.type!=="flag"&&r.type!=="source"&&r.type!=="constructionSite"&&r.type!=="mineral"&&r.type!=="tombstone"&&r.type!=="ruin"&&o.addChild(l),r.type==="creep"&&typeof r.name=="string"){const m=Jr(r,t);let S;if(m){const y=typeof r.user=="string"?r.user:void 0;S=y?(($=s==null?void 0:s[y])==null?void 0:$.username)??y:"Hostile"}else S=r.name;const M=m?vt:16777215,b=new qt({text:S,style:{fontSize:Di,fill:M}});b.scale.set(zi),b.anchor.set(.5,1),b.x=c,b.y=Os-Ls,b.visible=e,o.__nameLabel=b,o.addChild(b)}return r.type==="creep"&&(o.zIndex=1),r.type==="flag"&&(o.zIndex=10),o.position.set(r.x*w,r.y*w),o}function sr(r){r.destroy({children:!0})}class Ed{constructor(e,t=!0,i,n,s){_(this,"container");_(this,"objects",new Map);_(this,"rawObjects",new Map);_(this,"roadGraphics");_(this,"rampartGraphics");_(this,"ticker",null);_(this,"tickerCallback",null);_(this,"extAnimations",new Map);_(this,"creepFillAnimations",new Map);_(this,"towerFillAnimations",new Map);_(this,"sourceAnimations",new Map);_(this,"buildGlowAnimations",new Map);_(this,"EXT_ANIM_DURATION",300);_(this,"lastWorldScale",1);_(this,"showLabels");_(this,"currentUserId");_(this,"badge");_(this,"badgeCache",gd);_(this,"users");this.showLabels=t,this.currentUserId=i,this.badge=n,this.users=s,this.container=new Re,this.container.sortableChildren=!0,this.rampartGraphics=new K,this.rampartGraphics.zIndex=-1,this.container.addChild(this.rampartGraphics),this.roadGraphics=new K,this.container.addChild(this.roadGraphics),e&&(this.ticker=e,this.tickerCallback=()=>this.tick(),e.add(this.tickerCallback))}tick(){var o;for(const l of this.objects.values()){const a=l.__targetX,c=l.__targetY;if(a!==void 0&&c!==void 0){const d=a-l.x,f=c-l.y;Math.abs(d)<.5&&Math.abs(f)<.5?(l.position.set(a,c),l.__targetX=void 0,l.__targetY=void 0):(l.x+=d*.15,l.y+=f*.15)}}const e=((o=this.container.parent)==null?void 0:o.scale.x)??1;if(e!==this.lastWorldScale){this.lastWorldScale=e;for(const l of this.objects.values())this.applyLabelScale(l)}const t=performance.now(),i=t/1e3,n=.5+.5*Math.sin(t*2*Math.PI/Sd);for(const l of this.objects.values())l.__barrelContainer&&(l.__barrelContainer.rotation=i*.4),l.__csRingGraphics&&l.__csColorDark!==void 0&&l.__csColorLight!==void 0&&zs(l.__csRingGraphics,Ds(l.__csColorDark,l.__csColorLight,n));for(const[l,a]of this.extAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),f=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;Md(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*f),d>=1&&this.extAnimations.delete(l)}for(const[l,a]of this.creepFillAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),f=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;kd(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*f),d>=1&&this.creepFillAnimations.delete(l)}for(const[l,a]of this.towerFillAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),f=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;Hs(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*f),d>=1&&this.towerFillAnimations.delete(l)}for(const[l,a]of this.sourceAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),f=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;$d(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*f),d>=1&&this.sourceAnimations.delete(l)}const s=mn(t);for(const l of this.objects.values()){const a=l.__sourceGraphics;a&&gn(a,l.__sourceSize??Bi,s)}for(const[l,a]of this.buildGlowAnimations){const c=this.objects.get(l),d=c==null?void 0:c.__csBuildGlow;if(!c||!d){this.buildGlowAnimations.delete(l);continue}const f=(t-a.startTime)/a.duration;let p;f<=0?p=0:f<.5?p=f/.5:f<.7?p=1:f<1?p=1-(f-.7)/.3:p=0,d.clear(),p>0&&(d.circle(w/2,w/2,_d),d.fill({color:Ye,alpha:p*.75})),f>=1&&this.buildGlowAnimations.delete(l)}}startExtAnimation(e,t,i,n,s,o){const l=qi(i,n),a=qi(s,o);l!==a&&this.extAnimations.set(e,{visual:t,fromRadius:l,toRadius:a,startTime:performance.now()})}startCreepFillAnimation(e,t,i,n,s,o){const l=Yi(i,n),a=Yi(s,o);l!==a&&this.creepFillAnimations.set(e,{visual:t,fromRadius:l,toRadius:a,startTime:performance.now()})}startTowerFillAnimation(e,t,i,n,s,o){const l=Ki(i,n),a=Ki(s,o);l!==a&&this.towerFillAnimations.set(e,{visual:t,fromRadius:l,toRadius:a,startTime:performance.now()})}startSourceAnimation(e,t,i,n,s,o){const l=Hi(i,n),a=Hi(s,o);l!==a&&this.sourceAnimations.set(e,{visual:t,fromRadius:l,toRadius:a,startTime:performance.now()})}update(e,t,i){i&&(this.users=i);let n=!1;if(t)for(const s in t)if(t[s]===null){const l=this.rawObjects.get(s);l&&l.type==="road"&&(n=!0);const a=this.objects.get(s);a&&(this.container.removeChild(a),sr(a),this.objects.delete(s),this.rawObjects.delete(s),this.extAnimations.delete(s),this.creepFillAnimations.delete(s),this.towerFillAnimations.delete(s),this.sourceAnimations.delete(s),this.buildGlowAnimations.delete(s))}else{const l=e[s];if(!l)continue;if(l.type==="road"){const c=this.rawObjects.get(s);(!c||c.x!==l.x||c.y!==l.y)&&(n=!0)}this.rawObjects.set(s,l);const a=this.objects.get(s);if(a){const c=l.x*w,d=l.y*w;if(l.type==="creep"){const f=l.x-(a.__tileX??l.x),p=l.y-(a.__tileY??l.y);(f!==0||p!==0)&&(a.__angle=Math.atan2(p,f),a.__bodyContainer&&(a.__bodyContainer.rotation=a.__angle)),a.__tileX=l.x,a.__tileY=l.y,(a.x!==c||a.y!==d)&&(a.__targetX=c,a.__targetY=d);const{used:h,capacity:u}=Xi(l);(a.__creepUsed!==h||a.__creepCapacity!==u)&&(this.startCreepFillAnimation(s,a,a.__creepUsed??0,a.__creepCapacity??u,h,u),a.__creepUsed=h,a.__creepCapacity=u)}else if(l.type==="flag"){const f=typeof l.color=="number"?l.color:0,p=typeof l.secondaryColor=="number"?l.secondaryColor:0;if(a.__flagColor!==f||a.__flagSecondaryColor!==p){this.container.removeChild(a),sr(a),this.objects.delete(s);const u=Ir(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);u.__tileX=l.x,u.__tileY=l.y,this.applyLabelScale(u),this.objects.set(s,u),this.container.addChild(u)}else a.position.set(c,d)}else a.position.set(c,d);if(l.type==="extension"){const{energy:f,capacity:p}=Xt(l),h=a;(h.__extEnergy!==f||h.__extCapacity!==p)&&(this.startExtAnimation(s,a,h.__extEnergy??0,h.__extCapacity??p,f,p),h.__extEnergy=f,h.__extCapacity=p)}if(l.type==="tower"){const{energy:f,capacity:p}=Xt(l);(a.__towerEnergy!==f||a.__towerCapacity!==p)&&(this.startTowerFillAnimation(s,a,a.__towerEnergy??0,a.__towerCapacity??p,f,p),a.__towerEnergy=f,a.__towerCapacity=p)}if(l.type==="controller"){const f=typeof l.level=="number"?l.level:0,p=typeof l.progress=="number"?l.progress:0,h=typeof l.progressTotal=="number"?l.progressTotal:0;(a.__ctrlLevel!==f||a.__ctrlProgress!==p||a.__ctrlProgressTotal!==h)&&(a.__ctrlSegGraphics&&en(a.__ctrlSegGraphics,w/2,w/2,Qi,Ve,f,p,h),a.__ctrlLevel=f,a.__ctrlProgress=p,a.__ctrlProgressTotal=h)}if(l.type==="source"){const{energy:f,capacity:p}=Fi(l);(a.__sourceEnergy!==f||a.__sourceCapacity!==p)&&(this.startSourceAnimation(s,a,a.__sourceEnergy??0,a.__sourceCapacity??p,f,p),a.__sourceEnergy=f,a.__sourceCapacity=p)}if(l.type==="constructionSite"){const f=typeof l.progress=="number"?l.progress:0,p=typeof l.progressTotal=="number"?l.progressTotal:1;(a.__csProgress!==f||a.__csProgressTotal!==p)&&(a.__csFillGraphics&&Ui(a.__csFillGraphics,w/2,w/2,Wi,f,p,a.__csColor??mr),a.__csProgress=f,a.__csProgressTotal=p)}}else{const c=Ir(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);c.__tileX=l.x,c.__tileY=l.y,this.applyLabelScale(c),this.objects.set(s,c),this.container.addChild(c)}}else{const s=new Set;for(const o in e){const l=e[o];if(!l)continue;s.add(o),this.rawObjects.set(o,l);const a=this.objects.get(o);if(a){const c=l.x*w,d=l.y*w;if(l.type==="creep"){const f=l.x-(a.__tileX??l.x),p=l.y-(a.__tileY??l.y);(f!==0||p!==0)&&(a.__angle=Math.atan2(p,f),a.__bodyContainer&&(a.__bodyContainer.rotation=a.__angle)),a.__tileX=l.x,a.__tileY=l.y,(a.x!==c||a.y!==d)&&(a.__targetX=c,a.__targetY=d);const{used:h,capacity:u}=Xi(l);(a.__creepUsed!==h||a.__creepCapacity!==u)&&(this.startCreepFillAnimation(o,a,a.__creepUsed??0,a.__creepCapacity??u,h,u),a.__creepUsed=h,a.__creepCapacity=u)}else if(l.type==="flag"){const f=typeof l.color=="number"?l.color:0,p=typeof l.secondaryColor=="number"?l.secondaryColor:0;if(a.__flagColor!==f||a.__flagSecondaryColor!==p){this.container.removeChild(a),sr(a),this.objects.delete(o);const u=Ir(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);u.__tileX=l.x,u.__tileY=l.y,this.applyLabelScale(u),this.objects.set(o,u),this.container.addChild(u)}else a.position.set(c,d)}else a.position.set(c,d);if(l.type==="extension"){const{energy:f,capacity:p}=Xt(l),h=a;(h.__extEnergy!==f||h.__extCapacity!==p)&&(this.startExtAnimation(o,a,h.__extEnergy??0,h.__extCapacity??p,f,p),h.__extEnergy=f,h.__extCapacity=p)}if(l.type==="tower"){const{energy:f,capacity:p}=Xt(l);(a.__towerEnergy!==f||a.__towerCapacity!==p)&&(this.startTowerFillAnimation(o,a,a.__towerEnergy??0,a.__towerCapacity??p,f,p),a.__towerEnergy=f,a.__towerCapacity=p)}if(l.type==="controller"){const f=typeof l.level=="number"?l.level:0,p=typeof l.progress=="number"?l.progress:0,h=typeof l.progressTotal=="number"?l.progressTotal:0;(a.__ctrlLevel!==f||a.__ctrlProgress!==p||a.__ctrlProgressTotal!==h)&&(a.__ctrlSegGraphics&&en(a.__ctrlSegGraphics,w/2,w/2,Qi,Ve,f,p,h),a.__ctrlLevel=f,a.__ctrlProgress=p,a.__ctrlProgressTotal=h)}if(l.type==="source"){const{energy:f,capacity:p}=Fi(l);(a.__sourceEnergy!==f||a.__sourceCapacity!==p)&&(this.startSourceAnimation(o,a,a.__sourceEnergy??0,a.__sourceCapacity??p,f,p),a.__sourceEnergy=f,a.__sourceCapacity=p)}if(l.type==="constructionSite"){const f=typeof l.progress=="number"?l.progress:0,p=typeof l.progressTotal=="number"?l.progressTotal:1;(a.__csProgress!==f||a.__csProgressTotal!==p)&&(a.__csFillGraphics&&Ui(a.__csFillGraphics,w/2,w/2,Wi,f,p,a.__csColor??mr),a.__csProgress=f,a.__csProgressTotal=p)}}else{const c=Ir(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);c.__tileX=l.x,c.__tileY=l.y,this.applyLabelScale(c),this.objects.set(o,c),this.container.addChild(c)}}for(const[o,l]of this.objects)s.has(o)||(this.container.removeChild(l),sr(l),this.objects.delete(o),this.rawObjects.delete(o),this.extAnimations.delete(o),this.creepFillAnimations.delete(o),this.towerFillAnimations.delete(o),this.sourceAnimations.delete(o),this.buildGlowAnimations.delete(o));n=!0}this.redrawRamparts(),n&&this.redrawRoads(),this.refreshForeignCreepLabels(),this.refreshForeignCreepBadges()}redrawRoads(){this.roadGraphics.clear();const e=Ps,t=Array.from({length:50},()=>new Array(50).fill(!1)),i=[];for(const a of this.rawObjects.values())a.type==="road"&&(i.push(a),a.x>=0&&a.x<50&&a.y>=0&&a.y<50&&(t[a.x][a.y]=!0));if(i.length===0)return;const n=w/2,s=w/2,o=w*.125;for(const a of i)this.roadGraphics.circle(a.x*w+n,a.y*w+s,o);this.roadGraphics.fill(e);const l=[[1,0],[1,1],[0,1],[-1,1]];for(const a of i){const c=a.x*w+n,d=a.y*w+s;for(const[f,p]of l){const h=a.x+f,u=a.y+p;if(h>=0&&h<50&&u>=0&&u<50&&t[h][u]){const g=h*w+n,$=u*w+s;this.roadGraphics.moveTo(c,d),this.roadGraphics.lineTo(g,$)}}}this.roadGraphics.stroke({width:o*2,color:e})}redrawRamparts(){this.rampartGraphics.clear();const e=w,t=e/2,i=Array.from({length:50},()=>new Array(50).fill(void 0));for(const s of this.rawObjects.values())s.type==="rampart"&&s.x>=0&&s.x<50&&s.y>=0&&s.y<50&&(i[s.x][s.y]=typeof s.user=="string"?s.user:void 0);const n=s=>!s||!this.currentUserId?{color:In,alpha:.7}:s===this.currentUserId?{color:In,alpha:.7}:{color:7807522,alpha:.5};for(let s=0;s<50;s++)for(let o=0;o<50;o++){const l=i[o][s],a=l!==void 0,c=s>0&&i[o][s-1]!==void 0,d=s<49&&i[o][s+1]!==void 0,f=o>0&&i[o-1][s]!==void 0,p=o<49&&i[o+1][s]!==void 0,h=o*e+t,u=s*e+t;if(a){const g=n(l);!c&&!f&&s>0&&o>0?(this.rampartGraphics.moveTo(h,s*e),this.rampartGraphics.arc(h,u,t,-Math.PI/2,Math.PI,!0),this.rampartGraphics.lineTo(h,u),this.rampartGraphics.fill(g)):(this.rampartGraphics.rect(o*e,s*e,t,t),this.rampartGraphics.fill(g))}else if(c&&f&&i[o-1][s-1]!==void 0){const g=n(i[o-1][s-1]);this.rampartGraphics.moveTo(h,s*e),this.rampartGraphics.lineTo(o*e,s*e),this.rampartGraphics.lineTo(o*e,u),this.rampartGraphics.arc(h,u,t,Math.PI,-Math.PI/2,!1),this.rampartGraphics.fill(g)}if(a){const g=n(l);!c&&!p&&s>0&&o<49?(this.rampartGraphics.moveTo(h,s*e),this.rampartGraphics.arc(h,u,t,-Math.PI/2,0,!1),this.rampartGraphics.lineTo(h,u),this.rampartGraphics.fill(g)):(this.rampartGraphics.rect(h,s*e,t,t),this.rampartGraphics.fill(g))}else if(c&&p&&i[o+1][s-1]!==void 0){const g=n(i[o+1][s-1]);this.rampartGraphics.moveTo(h,s*e),this.rampartGraphics.lineTo(o*e+e,s*e),this.rampartGraphics.lineTo(o*e+e,u),this.rampartGraphics.arc(h,u,t,0,-Math.PI/2,!0),this.rampartGraphics.fill(g)}if(a){const g=n(l);!d&&!f&&s<49&&o>0?(this.rampartGraphics.moveTo(o*e,u),this.rampartGraphics.arc(h,u,t,Math.PI,Math.PI/2,!0),this.rampartGraphics.lineTo(h,u),this.rampartGraphics.fill(g)):(this.rampartGraphics.rect(o*e,u,t,t),this.rampartGraphics.fill(g))}else if(d&&f&&i[o-1][s+1]!==void 0){const g=n(i[o-1][s+1]);this.rampartGraphics.moveTo(o*e,u),this.rampartGraphics.lineTo(o*e,s*e+e),this.rampartGraphics.lineTo(h,s*e+e),this.rampartGraphics.arc(h,u,t,Math.PI/2,Math.PI,!1),this.rampartGraphics.fill(g)}if(a){const g=n(l);!d&&!p&&s<49&&o<49?(this.rampartGraphics.moveTo(h,s*e+e),this.rampartGraphics.arc(h,u,t,Math.PI/2,0,!0),this.rampartGraphics.lineTo(h,u),this.rampartGraphics.fill(g)):(this.rampartGraphics.rect(h,u,t,t),this.rampartGraphics.fill(g))}else if(d&&p&&i[o+1][s+1]!==void 0){const g=n(i[o+1][s+1]);this.rampartGraphics.moveTo(h,s*e+e),this.rampartGraphics.lineTo(o*e+e,s*e+e),this.rampartGraphics.lineTo(o*e+e,u),this.rampartGraphics.arc(h,u,t,0,Math.PI/2,!1),this.rampartGraphics.fill(g)}}}getObjectsAtTile(e,t){const i=[];for(const[n,s]of this.objects){const o=this.rawObjects.get(n);o&&o.x===e&&o.y===t&&i.push({id:n,obj:o,visual:s})}return i}applyLabelScale(e){if(!e.__nameLabel)return;const t=this.lastWorldScale||1;e.__nameLabel.scale.set(zi/t),e.__nameLabel.anchor.y===0?e.__nameLabel.y=w/2+w*.55:e.__nameLabel.y=Os-Ls/t}refreshForeignCreepLabels(){var e,t;if(this.currentUserId)for(const[i,n]of this.objects){const s=this.rawObjects.get(i);if(!s||s.type!=="creep"||!n.__nameLabel||!Jr(s,this.currentUserId))continue;const o=typeof s.user=="string"?s.user:void 0,l=o?((t=(e=this.users)==null?void 0:e[o])==null?void 0:t.username)??o:"Hostile";n.__nameLabel.text!==l&&(n.__nameLabel.text=l)}}refreshForeignCreepBadges(){var e,t;if(this.currentUserId)for(const[i,n]of this.objects){const s=this.rawObjects.get(i);if(!s||s.type!=="creep"||!Jr(s,this.currentUserId)||n.__creepBadgeSprite)continue;const o=typeof s.user=="string"?s.user:void 0,l=o?(t=(e=this.users)==null?void 0:e[o])==null?void 0:t.badge:void 0;if(!l)continue;const a=n.__bodyContainer;if(!a)continue;n.__creepForeignMark&&!n.__creepForeignMark.destroyed&&(a.removeChild(n.__creepForeignMark),n.__creepForeignMark.destroy(),n.__creepForeignMark=void 0);const c=new Zt;c.anchor.set(.5,.5);const d=Xe*2;c.width=d,c.height=d,c.rotation=Math.PI/2,a.addChild(c),n.__creepBadgeSprite=c,this.badgeCache.getOrCreate(l).then(f=>{c.destroyed||(c.texture=f)}).catch(()=>{c.destroyed||(a.removeChild(c),c.destroy()),n.__creepBadgeSprite=void 0})}}triggerBuildAt(e,t,i){for(const[n,s]of this.objects){const o=this.rawObjects.get(n);if(!(!o||o.type!=="constructionSite")&&!(o.x!==e||o.y!==t)&&s.__csBuildGlow){this.buildGlowAnimations.set(n,{startTime:performance.now(),duration:i});return}}}setShowLabels(e){this.showLabels=e;for(const t of this.objects.values())t.__nameLabel&&(t.__nameLabel.visible=e)}getVisualById(e){return this.objects.get(e)}clear(){for(const e of this.objects.values())sr(e);this.objects.clear(),this.rawObjects.clear(),this.extAnimations.clear(),this.creepFillAnimations.clear(),this.towerFillAnimations.clear(),this.sourceAnimations.clear(),this.buildGlowAnimations.clear(),this.roadGraphics.clear(),this.rampartGraphics.clear(),this.container.removeChildren()}destroy(){this.clear(),this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null}}const bi=2;function It(r,e){return{cx:r*w+w/2,cy:e*w+w/2}}class Pd{constructor(e){_(this,"container");_(this,"graphics");_(this,"animations",[]);_(this,"ticker",null);_(this,"tickerCallback",null);this.container=new Re,this.graphics=new K,this.container.addChild(this.graphics),e&&(this.ticker=e,this.tickerCallback=()=>this.animate(),e.add(this.tickerCallback))}addHarvest(e,t,i,n,s){const o=It(e,t),l=It(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:l.cx,toY:l.cy,startTime:performance.now(),duration:s,color:Kc,width:bi})}addUpgradeController(e,t,i,n,s){const o=It(e,t),l=It(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:l.cx,toY:l.cy,startTime:performance.now(),duration:s,color:Jc,width:bi})}addBuild(e,t,i,n,s){const o=It(e,t),l=It(i,n);this.animations.push({fromX:o.cx,fromY:o.cy,toX:l.cx,toY:l.cy,startTime:performance.now(),duration:s,color:Qc,width:bi})}animate(){this.graphics.clear();const e=performance.now();let t=!1;for(let i=this.animations.length-1;i>=0;i--){const n=this.animations[i],s=e-n.startTime,o=Math.min(1,s/n.duration);let l,a,c,d;const f=.5,p=.2;if(o<f){const h=o/f;l=n.fromX,a=n.fromY,c=n.fromX+(n.toX-n.fromX)*h,d=n.fromY+(n.toY-n.fromY)*h}else if(o<f+p)l=n.fromX,a=n.fromY,c=n.toX,d=n.toY;else{const h=(o-f-p)/(1-f-p);l=n.fromX+(n.toX-n.fromX)*h,a=n.fromY+(n.toY-n.fromY)*h,c=n.toX,d=n.toY}this.graphics.moveTo(l,a),this.graphics.lineTo(c,d),this.graphics.stroke({width:n.width,color:n.color}),t=!0,o>=1&&this.animations.splice(i,1)}t||this.graphics.clear()}clear(){this.animations.length=0,this.graphics.clear()}destroy(){this.clear(),this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null,this.graphics.destroy(),this.container.destroy()}}const Te=r=>(r+.5)*w,or=4,Nr={dashed:[.4*w,.4*w],dotted:[.1*w,.3*w]};function Gr(r,e,t,i){let n=!0,s=t;for(let o=0;o<e.length-1;o++){const[l,a]=e[o],[c,d]=e[o+1],f=c-l,p=d-a,h=Math.sqrt(f*f+p*p);if(h<.001)continue;const u=f/h,g=p/h;let $=0;for(;$<h;){const m=Math.min(s,h-$);if(n){const S=l+u*$,M=a+g*$;r.moveTo(S,M),r.lineTo(S+u*m,M+g*m)}$+=m,s-=m,s<.001&&(n=!n,s=n?t:i)}}}function Rd(r,e,t){const i=Math.max(32,Math.ceil(2*Math.PI*t/2)),n=[];for(let s=0;s<=i;s++){const o=s/i*2*Math.PI;n.push([r+Math.cos(o)*t,e+Math.sin(o)*t])}return n}function Od(r){if(r==null)return .7;if(typeof r=="number")return r;const e=r.match(/^([0-9.]+)(px)?/);if(!e)return .7;const t=parseFloat(e[1]);return e[2]?t/w:t}function Ld(r){if(typeof r!="string")return"Arial";const e=r.match(/^[0-9.]+(px)?\s+(.+)$/);return e?e[2]:"Arial"}class Ad{constructor(){_(this,"container");_(this,"g");this.container=new Re,this.container.label="visuals",this.g=new K,this.container.addChild(this.g)}update(e){const t=this.container.removeChildren();for(const n of t)n!==this.g&&n.destroy();if(this.g.clear(),this.container.addChild(this.g),!e)return;const i=this.g;for(const n of e.split(`
9
+ `)){if(!n.trim())continue;let s;try{s=JSON.parse(n)}catch{continue}const o=s.s??{},l=o.opacity??1;switch(s.t){case"l":this.drawLine(i,s,o,l);break;case"c":this.drawCircle(i,s,o,l);break;case"r":this.drawRect(i,s,o,l);break;case"p":this.drawPoly(i,s,o,l);break;case"t":this.drawText(s,o,l);break}}}drawLine(e,t,i,n){const s=Te(t.x1),o=Te(t.y1),l=Te(t.x2),a=Te(t.y2),c=i.color??"#ffffff",d=(i.width??.1)*w;if(i.lineStyle&&i.lineStyle!=="solid"){const[f,p]=Nr[i.lineStyle];Gr(e,[[s,o],[l,a]],f,p)}else e.moveTo(s,o),e.lineTo(l,a);e.stroke({color:c,width:d,alpha:n})}drawCircle(e,t,i,n){const s=Te(t.x),o=Te(t.y),l=(i.radius??.5)*w,a=!!(i.fill&&i.fill!=="transparent"),c=!!(i.stroke&&i.strokeWidth),d=i.lineStyle&&i.lineStyle!=="solid";if(a&&(e.circle(s,o,l),e.fill({color:i.fill,alpha:n})),c){const f=i.strokeWidth*w;if(d){const[p,h]=Nr[i.lineStyle];Gr(e,Rd(s,o,l),p,h)}else e.circle(s,o,l);e.stroke({color:i.stroke,width:f,alpha:n})}}drawRect(e,t,i,n){const s=Te(t.x),o=Te(t.y),l=t.w*w,a=t.h*w,c=!!(i.fill&&i.fill!=="transparent"),d=!!(i.stroke&&i.strokeWidth),f=i.lineStyle&&i.lineStyle!=="solid";if(c&&(e.rect(s,o,l,a),e.fill({color:i.fill,alpha:n})),d){const p=i.strokeWidth*w;if(f){const[h,u]=Nr[i.lineStyle],g=[[s,o],[s+l,o],[s+l,o+a],[s,o+a],[s,o]];Gr(e,g,h,u)}else e.rect(s,o,l,a);e.stroke({color:i.stroke,width:p,alpha:n})}}drawPoly(e,t,i,n){if(!t.points||t.points.length===0)return;const s=!!(i.fill&&i.fill!=="transparent"),o=!!(i.stroke&&i.strokeWidth);if(!s&&!o)return;const l=i.lineStyle&&i.lineStyle!=="solid",a=new Array(t.points.length*2);let c;o&&l&&(c=new Array(t.points.length));for(let d=0;d<t.points.length;d++){const[f,p]=t.points[d],h=Te(f),u=Te(p);a[d*2]=h,a[d*2+1]=u,c&&(c[d]=[h,u])}if(s&&(e.poly(a,!0),e.fill({color:i.fill,alpha:n})),o){const d=i.strokeWidth*w;if(l&&c){const[f,p]=Nr[i.lineStyle],h=c[0],u=c[c.length-1],g=h[0]===u[0]&&h[1]===u[1];Gr(e,g?c:[...c,h],f,p)}else e.poly(a,!0);e.stroke({color:i.stroke,width:d,alpha:n})}}drawText(e,t,i){const n=Od(t.font),s=Ld(t.font),o=t.align??"left",l=new So({fill:t.color??"#ffffff",fontSize:Math.round(n*w*or),fontFamily:s,align:o,...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*w*or}}:{}});if(t.backgroundColor&&t.backgroundColor!=="transparent"){const c=ko.measureText(e.text,l),d=c.width/or,f=c.height/or,p=(t.backgroundPadding??.3)*w,h=o==="center"?.5:o==="right"?1:0,u=Te(e.x)-h*d-p,g=Te(e.y)-f/2-p,$=new K;$.rect(u,g,d+p*2,f+p*2),$.fill({color:t.backgroundColor,alpha:i}),this.container.addChild($)}const a=new qt({text:e.text,style:l});a.scale.set(1/or),a.anchor.x=o==="center"?.5:o==="right"?1:0,a.anchor.y=.5,a.position.set(Te(e.x),Te(e.y)),a.alpha=i,this.container.addChild(a)}destroy(){const e=this.container.removeChildren();for(const t of e)t!==this.g&&t.destroy();this.g.destroy(),this.container.destroy()}}function Er(r,e){const t=localStorage.getItem(r),[i,n]=N(t!==null?t==="true":e);return[i,s=>{n(s),localStorage.setItem(r,String(s))}]}const[Fs,Id]=Er(ye.widescreenMode,!0),[tn,Nd]=Er(ye.showCreepLabels,!0),[Ws,Us]=Er(ye.showMapRoomNames,!1),[Xs,Ys]=Er(ye.showUnclaimableRooms,!0),[jr,Gd]=Er(ye.terrainEffects,!0),rn=Symbol("store-raw"),jt=Symbol("store-node"),Ze=Symbol("store-has"),qs=Symbol("store-self");function js(r){let e=r[Tt];if(!e&&(Object.defineProperty(r,Tt,{value:e=new Proxy(r,Bd)}),!Array.isArray(r))){const t=Object.keys(r),i=Object.getOwnPropertyDescriptors(r),n=Object.getPrototypeOf(r),s=n!==null&&r!==null&&typeof r=="object"&&!Array.isArray(r)&&n!==Object.prototype;if(s){const o=Object.getOwnPropertyDescriptors(n);t.push(...Object.keys(o)),Object.assign(i,o)}for(let o=0,l=t.length;o<l;o++){const a=t[o];s&&a==="constructor"||i[a].get&&Object.defineProperty(r,a,{configurable:!0,enumerable:i[a].enumerable,get:i[a].get.bind(e)})}}return e}function ht(r){let e;return r!=null&&typeof r=="object"&&(r[Tt]||!(e=Object.getPrototypeOf(r))||e===Object.prototype||Array.isArray(r))}function Kt(r,e=new Set){let t,i,n,s;if(t=r!=null&&r[rn])return t;if(!ht(r)||e.has(r))return r;if(Array.isArray(r)){Object.isFrozen(r)?r=r.slice(0):e.add(r);for(let o=0,l=r.length;o<l;o++)n=r[o],(i=Kt(n,e))!==n&&(r[o]=i)}else{Object.isFrozen(r)?r=Object.assign({},r):e.add(r);const o=Object.keys(r),l=Object.getOwnPropertyDescriptors(r);for(let a=0,c=o.length;a<c;a++)s=o[a],!l[s].get&&(n=r[s],(i=Kt(n,e))!==n&&(r[s]=i))}return r}function Qr(r,e){let t=r[e];return t||Object.defineProperty(r,e,{value:t=Object.create(null)}),t}function wr(r,e,t){if(r[e])return r[e];const[i,n]=N(t,{equals:!1,internal:!0});return i.$=n,r[e]=i}function Dd(r,e){const t=Reflect.getOwnPropertyDescriptor(r,e);return!t||t.get||!t.configurable||e===Tt||e===jt||(delete t.value,delete t.writable,t.get=()=>r[Tt][e]),t}function Vs(r){Li()&&wr(Qr(r,jt),qs)()}function zd(r){return Vs(r),Reflect.ownKeys(r)}const Bd={get(r,e,t){if(e===rn)return r;if(e===Tt)return t;if(e===wn)return Vs(r),t;const i=Qr(r,jt),n=i[e];let s=n?n():r[e];if(e===jt||e===Ze||e==="__proto__")return s;if(!n){const o=Object.getOwnPropertyDescriptor(r,e);Li()&&(typeof s!="function"||r.hasOwnProperty(e))&&!(o&&o.get)&&(s=wr(i,e,s)())}return ht(s)?js(s):s},has(r,e){return e===rn||e===Tt||e===wn||e===jt||e===Ze||e==="__proto__"?!0:(Li()&&wr(Qr(r,Ze),e)(),e in r)},set(){return console.warn("Cannot mutate a Store directly"),!0},deleteProperty(){return console.warn("Cannot mutate a Store directly"),!0},ownKeys:zd,getOwnPropertyDescriptor:Dd};function Le(r,e,t,i=!1){if(e==="__proto__"){console.warn('Refusing to set "__proto__" on a store.');return}if(!i&&r[e]===t)return;const n=r[e],s=r.length;t===void 0?(delete r[e],r[Ze]&&r[Ze][e]&&n!==void 0&&r[Ze][e].$()):(r[e]=t,r[Ze]&&r[Ze][e]&&n===void 0&&r[Ze][e].$());let o=Qr(r,jt),l;if((l=wr(o,e,n))&&l.$(()=>t),Array.isArray(r)&&r.length!==s){for(let a=r.length;a<s;a++)(l=o[a])&&l.$();(l=wr(o,"length",s))&&l.$(r.length)}(l=o[qs])&&l.$()}function Zs(r,e){const t=Object.keys(e);for(let i=0;i<t.length;i+=1){const n=t[i];Ks(n)||Le(r,n,e[n])}}function Ks(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function Hd(r,e){if(typeof e=="function"&&(e=e(r)),e=Kt(e),Array.isArray(e)){if(r===e)return;let t=0,i=e.length;for(;t<i;t++){const n=e[t];r[t]!==n&&Le(r,t,n)}Le(r,"length",i)}else Zs(r,e)}function ur(r,e,t=[]){let i,n=r;if(e.length>1){i=e.shift();const o=typeof i,l=Array.isArray(r);if(o==="string"&&(i==="__proto__"||e.length>1&&Ks(i))){console.warn(`Refusing to traverse unsafe key "${i}" on a store.`);return}if(Array.isArray(i)){for(let a=0;a<i.length;a++)ur(r,[i[a]].concat(e),t);return}else if(l&&o==="function"){for(let a=0;a<r.length;a++)i(r[a],a)&&ur(r,[a].concat(e),t);return}else if(l&&o==="object"){const{from:a=0,to:c=r.length-1,by:d=1}=i;for(let f=a;f<=c;f+=d)ur(r,[f].concat(e),t);return}else if(e.length>1){ur(r[i],e,[i].concat(t));return}n=r[i],t=[i].concat(t)}let s=e[0];typeof s=="function"&&(s=s(n,t),s===n)||i===void 0&&s==null||(s=Kt(s),i===void 0||ht(n)&&ht(s)&&!Array.isArray(s)?Zs(n,s):Le(r,i,s))}function Fd(...[r,e]){const t=Kt(r||{}),i=Array.isArray(t);if(typeof t!="object"&&typeof t!="function")throw new Error(`Unexpected type ${typeof t} received when initializing 'createStore'. Expected an object.`);const n=js(t);bo.registerGraph({value:t,name:e&&e.name});function s(...o){wo(()=>{i&&o.length===1?Hd(t,o[0]):ur(t,o)})}return[n,s]}const nn=Symbol("store-root");function Bn(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function Bt(r,e,t,i,n){if(Bn(t))return;const s=e[t];if(r===s)return;const o=Array.isArray(r);if(t!==nn&&(!ht(r)||!ht(s)||o!==Array.isArray(s)||n&&r[n]!==s[n])){Le(e,t,r);return}if(o){if(r.length&&s.length&&(!i||n&&r[0]&&r[0][n]!=null)){let c,d,f,p,h,u,g,$;for(f=0,p=Math.min(s.length,r.length);f<p&&(s[f]===r[f]||n&&s[f]&&r[f]&&s[f][n]&&s[f][n]===r[f][n]);f++)Bt(r[f],s,f,i,n);const m=new Array(r.length),S=new Map;for(p=s.length-1,h=r.length-1;p>=f&&h>=f&&(s[p]===r[h]||n&&s[p]&&r[h]&&s[p][n]&&s[p][n]===r[h][n]);p--,h--)m[h]=s[p];if(f>h||f>p){for(d=f;d<=h;d++)Le(s,d,r[d]);for(;d<r.length;d++)Le(s,d,m[d]),Bt(r[d],s,d,i,n);s.length>r.length&&Le(s,"length",r.length);return}for(g=new Array(h+1),d=h;d>=f;d--)u=r[d],$=n&&u?u[n]:u,c=S.get($),g[d]=c===void 0?-1:c,S.set($,d);for(c=f;c<=p;c++)u=s[c],$=n&&u?u[n]:u,d=S.get($),d!==void 0&&d!==-1&&(m[d]=s[c],d=g[d],S.set($,d));for(d=f;d<r.length;d++)d in m?(Le(s,d,m[d]),Bt(r[d],s,d,i,n)):Le(s,d,r[d])}else for(let c=0,d=r.length;c<d;c++)Bt(r[c],s,c,i,n);s.length>r.length&&Le(s,"length",r.length);return}const l=Object.keys(r);for(let c=0,d=l.length;c<d;c++)Bn(l[c])||Bt(r[l[c]],s,l[c],i,n);const a=Object.keys(s);for(let c=0,d=a.length;c<d;c++)r[a[c]]===void 0&&Le(s,a[c],void 0)}function Wd(r,e={}){const{merge:t,key:i="id"}=e,n=Kt(r);return s=>{if(!ht(s)||!ht(n))return n;const o=Bt(n,{[nn]:s},nn,t,i);return o===void 0?s:o}}const Js=new WeakMap;function Hn(r,e){const[t,i]=Fd(e),n={id:r,type:e.type,raw:t};return Js.set(n,s=>i(Wd(s,{key:"_id",merge:!1}))),n}const[ei,xr]=N([]);function Ud(){xr([])}function Dr(r){xr(e=>e.filter(t=>t.id!==r))}function Xd(r,e){const t=ei();let i=!1;const n=[];for(const s of t){const o=r[s.id];if(o===null){i=!0;continue}if(o!==void 0){const l=e[s.id];if(l){const a=Js.get(s);a==null||a(l)}}n.push(s)}i&&xr(n)}const[Yd,wi]=N(null),[Qs,xi]=N(null),[Yt,$i]=N(null),[ti,_i]=N({}),[eo,Fn]=N(null);function sn(r,e,t){return isNaN(t.minX)||isNaN(t.maxX)||isNaN(t.minY)||isNaN(t.maxY)?!0:r>=t.minX&&r<=t.maxX&&e>=t.minY&&e<=t.maxY}function Qe(r){const e=r.match(/^([WE])(\d+)([NS])(\d+)$/);if(!e)return null;const[,t,i,n,s]=e,o=t==="W"?-(parseInt(i,10)+1):parseInt(i,10),l=n==="N"?-(parseInt(s,10)+1):parseInt(s,10);return{x:o,y:l}}function Be(r,e){const t=r<0?"W":"E",i=e<0?"N":"S",n=r<0?-r-1:r,s=e<0?-e-1:e;return`${t}${n}${i}${s}`}function Wn(r){return r===0||r<0&&(r+1)%10===0||r>0&&r%10===0}function Pp(r,e){return Wn(r)||Wn(e)}function Rp(r,e){const t=r<0?Math.abs(r+1)%10:Math.abs(r)%10,i=e<0?Math.abs(e+1)%10:Math.abs(e)%10;return t>=4&&t<=6&&i>=4&&i<=6}function to(r){const e=r;if(!e)return!1;const t=e.tagName??"";return t==="INPUT"||t==="TEXTAREA"?!0:e.isContentEditable===!0}function qd(r){const e=t=>{if(to(t.target))return;const i=r.currentRoom(),n=i?Qe(i):null;if(!n)return;const s=r.worldBounds(),o=(l,a)=>!s||sn(l,a,s);switch(t.key){case"ArrowLeft":t.preventDefault(),o(n.x-1,n.y)&&r.onMove(n.x-1,n.y);break;case"ArrowRight":t.preventDefault(),o(n.x+1,n.y)&&r.onMove(n.x+1,n.y);break;case"ArrowUp":t.preventDefault(),o(n.x,n.y-1)&&r.onMove(n.x,n.y-1);break;case"ArrowDown":t.preventDefault(),o(n.x,n.y+1)&&r.onMove(n.x,n.y+1);break}};window.addEventListener("keydown",e),Ie(()=>window.removeEventListener("keydown",e))}const[He,ro]=N(!1),[kt,yn]=N(0),[on,jd]=N(0),[$r,Vd]=N(0),[yr,_r]=N(!1),[io,Zd]=N(1),[Ue,Si]=N(!1);let Vr=null;function Sr(){Vr!==null&&(clearInterval(Vr),Vr=null)}function no(){Sr(),Vr=setInterval(()=>{const r=kt()+1;r>$r()?(Sr(),_r(!1)):yn(r)},Math.max(50,Math.round(1e3/io())))}function Kd(r){const e=r,t=Math.max(0,e-2e5);Vd(e),jd(t),yn(r),_r(!1),Sr(),ro(!0)}function Jd(){Sr(),_r(!1),ro(!1)}function so(r){const e=Math.max(on(),Math.min($r(),r));yn(e)}function Un(r){so(kt()+r)}function Qd(){yr()?(Sr(),_r(!1)):(_r(!0),no())}function eu(r){Zd(r),yr()&&no()}class tu{constructor(e,t,i,n,s,o){_(this,"chunkCache",new Map);this.room=e,this.shard=t,this.baseUrl=i,this.getToken=n,this.chunkSize=s,this.isPrivate=o}chunkBase(e){return e-e%this.chunkSize}buildUrl(e){return this.isPrivate||this.shard===null?`${this.baseUrl}room-history?room=${encodeURIComponent(this.room)}&time=${e}`:`${this.baseUrl}room-history/${encodeURIComponent(this.shard)}/${encodeURIComponent(this.room)}/${e}.json`}async loadChunk(e){const t=this.chunkCache.get(e);if(t)return t;const i=this.buildUrl(e),n=this.getToken(),s={};n&&(s["X-Token"]=n,s["X-Username"]=n);const o=await fetch(i,{headers:s});if(!o.ok)throw new Error(`HTTP ${o.status}`);const l=await o.json();return this.chunkCache.set(e,l),l}applyDiff(e,t){const i={...e};for(const n in t){const s=t[n];s===null?delete i[n]:i[n]?i[n]={...i[n],...s}:i[n]=s}return i}async getStateAtTick(e){const t=this.chunkBase(e),i=await this.loadChunk(t),n=i.ticks[String(t)]??{};let s={};for(const o in n)n[o]!==null&&(s[o]=n[o]);for(let o=t+1;o<=e;o++){const l=i.ticks[String(o)];l&&Object.keys(l).length>0&&(s=this.applyDiff(s,l))}return{objects:s,diff:i.ticks[String(e)]??{},gameTime:e}}}var ru=E('<div style=text-align:center;display:flex;flex-direction:column;align-items:center;gap:6px><div style=font-size:14px;font-weight:600;color:#f85149>You have no rooms!</div><button style="padding:4px 12px;border-radius:4px;border:1px solid #238636;background:#1a3a2a;color:#3fb950;font-size:12px;cursor:pointer">Place Spawn'),iu=E('<div style=text-align:center;display:flex;flex-direction:column;align-items:center;gap:6px><div style=font-size:14px;font-weight:600;color:#f85149>You lost all your spawns!</div><button style="padding:4px 12px;border-radius:4px;border:1px solid #da3633;background:#3d1a1a;color:#f85149;font-size:12px;cursor:pointer">Respawn'),nu=E("<span>Choose new flag position"),ki=E("<span>"),su=E("<span>Select structure type, then click to build — Ctrl+click to remove construction sites");const{log:Xn,warn:ou,error:Yn}=Pt("build"),kr={COLOR_RED:1,COLOR_PURPLE:2,COLOR_BLUE:3,COLOR_CYAN:4,COLOR_GREEN:5,COLOR_YELLOW:6,COLOR_ORANGE:7,COLOR_BROWN:8,COLOR_GREY:9,COLOR_WHITE:10},ri={spawn:{0:0,1:1,2:1,3:1,4:1,5:1,6:1,7:2,8:3},extension:{0:0,1:0,2:5,3:10,4:20,5:30,6:40,7:50,8:60},link:{1:0,2:0,3:0,4:0,5:2,6:3,7:4,8:6},road:{0:2500,1:2500,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},constructedWall:{1:0,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},rampart:{1:0,2:2500,3:2500,4:2500,5:2500,6:2500,7:2500,8:2500},storage:{1:0,2:0,3:0,4:1,5:1,6:1,7:1,8:1},tower:{1:0,2:0,3:1,4:1,5:2,6:2,7:3,8:6},observer:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},powerSpawn:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},extractor:{1:0,2:0,3:0,4:0,5:0,6:1,7:1,8:1},terminal:{1:0,2:0,3:0,4:0,5:0,6:1,7:1,8:1},lab:{1:0,2:0,3:0,4:0,5:0,6:3,7:6,8:10},container:{0:5,1:5,2:5,3:5,4:5,5:5,6:5,7:5,8:5},nuker:{1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:1},factory:{1:0,2:0,3:0,4:0,5:0,6:0,7:1,8:1}},[Et,xt]=N("view"),[Ht,oo]=N({name:"",color:"COLOR_WHITE",secondaryColor:"COLOR_WHITE"}),[Ct,ln]=N(null),[vn,an]=N(null),[et,$t]=N({structureType:"",structureName:""});os(()=>{he(()=>{const r=et().structureType;if(!r)return;const e=Yt()??0,t=ri[r];if(!t)return;const i=Mt()==="empty"&&r==="spawn"?Math.max(t[e]??0,1):t[e]??0;if(i===2500)return;(ti()[r]??0)>=i&&($t({structureType:"",structureName:""}),dt())})});function dt(){ln(null)}function cn(){an(null)}function lu(){$t({structureType:"",structureName:""})}function au(r,e){const t=ae(),i=et(),n=Ct();if(!t||!i.structureType||!n){ou("missing requirements",{hasClient:!!t,structureType:i.structureType,pending:n});return}if(Mt()==="empty"&&i.structureType==="spawn"){Xn("placing spawn",{room:r,x:n.tx,y:n.ty,name:i.structureName||void 0,shard:e??void 0}),t.http.game.placeSpawn(r,n.tx,n.ty,i.structureName||void 0,e??void 0).then(()=>(fe("Spawn placed successfully","success"),dt(),t.stores.user.refreshWorldStatus())).catch(s=>{Yn("place spawn failed:",s),fe(`Failed to place spawn: ${s.message}`,"error")});return}Xn("creating construction site",{room:r,x:n.tx,y:n.ty,structureType:i.structureType,name:i.structureName||void 0,shard:e??void 0}),t.http.game.createConstruction(r,n.tx,n.ty,i.structureType,i.structureName||void 0,e??void 0).then(()=>{fe(`Construction site for ${i.structureType} created`,"success"),dt()}).catch(s=>{Yn("create construction failed:",s),fe(`Failed to create construction site: ${s.message}`,"error")})}function cu(){xt("view"),dt(),cn(),lu()}function qn(){const r=Et(),e=Ct(),t=vn(),i=Mt();if(i==="empty")return(()=>{var n=ru(),s=n.firstChild,o=s.nextSibling;return o.$$click=()=>{xt("build"),$t({structureType:"spawn",structureName:""})},n})();if(i==="lost")return(()=>{var n=iu(),s=n.firstChild,o=s.nextSibling;return o.$$click=()=>{const l=ae();l&&l.http.user.respawn().then(()=>{fe("Respawn successful","success"),l.stores.user.refreshWorldStatus()}).catch(a=>{fe(`Respawn failed: ${a.message}`,"error")})},n})();if((t==null?void 0:t.type)==="moveFlag")return nu();if(r==="flag")return(()=>{var n=ki();return v(n,e?"Confirm position":"Choose position"),n})();if(r==="build"){const n=et(),s=Yt(),o=ti(),l=n.structureType,a=" — Ctrl+click to remove construction sites";if(!l)return su();const c=ri[l],d=(c==null?void 0:c[s??0])??0,f=o[l]??0,p=l.replace(/([A-Z])/g," $1").trim();return d===2500?(()=>{var h=ki();return v(h,`Click to build ${p} (${f}/∞)${a}`),h})():(()=>{var h=ki();return v(h,`Click to build ${p} (${f}/${d})${a}`),h})()}return null}Se(["click"]);var du=E('<div style="position:absolute;bottom:0;left:0;right:0;padding:8px 12px;background:rgba(13, 17, 23, 0.85);border-top:1px solid #30363d;z-index:10"><input type=range step=1 style=width:100%;cursor:pointer><div style=display:flex;justify-content:space-between;font-size:10px;color:#8b949e;margin-top:2px><span></span><span></span><span>'),uu=E("<div style=width:100%;height:100%;position:relative><div style=width:100%;height:100%>"),hu=E('<div style="position:absolute;top:12px;left:50%;transform:translateX(-50%);padding:6px 16px;border-radius:6px;background:rgba(13, 17, 23, 0.65);border:1px solid rgba(48, 54, 61, 0.6);font-size:13px;font-weight:500;color:#c9d1d9;user-select:none;z-index:10">'),fu=E('<div style="position:absolute;top:8px;right:8px;padding:4px 10px;border-radius:4px;background:rgba(13, 17, 23, 0.8);border:1px solid #30363d;font-size:12px;color:#8b949e;z-index:10">Tick ');const{log:lr,error:ar}=Pt("room");function pu(r){let e,t=null,i=null,n=null,s=null;const[o,l]=N(null),[a,c]=N(null),[d,f]=N(null),[p,h]=N("");return Cr(async()=>{if(!e)return;const u=await fn.create(e);l(u)}),Ie(()=>{t==null||t.destroy(),t=null,i==null||i.destroy(),i=null,n==null||n.destroy(),n=null;const u=o();u&&u.destroy()}),he(()=>{const u=ae();if(!u||He())return;const g=r.room,$=r.shard;c(null),f(null),h(""),Ur(null),Ud(),wi(null),xi(null),$i(null),_i({}),Fn(null);const m=new un;let S=!1;u.stores.room.terrain(g,$).then(M=>{S||c({room:g,data:M})}).catch(M=>{S||ar(`terrain load failed for ${g}:`,M)}),m.add(u.stores.room.subscribe(g,$)),m.add(u.stores.room.on("room:error",M=>{fe(`Room subscription error (${M.room}): ${M.message}`,"error",8e3)})),m.add(u.stores.room.on("room:update",M=>{var x,C;let b=0;const y={};let T=0,P=null;for(const I in M.objects){b++;const O=M.objects[I];if(!O)continue;const G=O.type;if(typeof G=="string")if(G==="constructionSite"){const R=O.structureType;typeof R=="string"&&(y[R]=(y[R]||0)+1)}else y[G]=(y[G]||0)+1;if(G==="controller"&&typeof O.user=="string"){const R=O.user,L=((C=(x=M.users)==null?void 0:x[R])==null?void 0:C.username)??R;P={userId:R,username:L},typeof O.level=="number"&&(T=O.level)}}M.diff||lr(`objects loaded — ${g}: ${b} objects, tick=${M.gameTime}`),f({objects:M.objects,diff:M.diff,users:M.users}),h(M.visual),Ur(M.gameTime??null),Fl(M.gameTime),wi(b),xi(P),$i(T||null),_i(y),Fn(M.users??null)})),Ie(()=>{S=!0,m.dispose()})}),he(()=>{var y,T;const u=ae();if(!u||!He())return;const g=r.room,$=r.shard,m=Ul()??!0,S=((T=(y=bs())==null?void 0:y.serverData)==null?void 0:T.historyChunkSize)??(m?20:100),M=xe(eo)??void 0,b=new tu(g,$,u.http.baseUrl,()=>u.http.token,S,m);he(()=>{const P=kt();let x=!1;Si(!0),b.getStateAtTick(P).then(C=>{var L;if(x)return;Si(!1),f({objects:C.objects,diff:C.diff,users:M}),Ur(C.gameTime);let I=0;const O={};let G=0,R=null;for(const H in C.objects){I++;const z=C.objects[H];if(!z)continue;const U=z.type;if(typeof U=="string")if(U==="constructionSite"){const F=z.structureType;typeof F=="string"&&(O[F]=(O[F]||0)+1)}else O[U]=(O[U]||0)+1;if(U==="controller"&&typeof z.user=="string"){const F=z.user,Y=((L=M==null?void 0:M[F])==null?void 0:L.username)??F;R={userId:F,username:Y},typeof z.level=="number"&&(G=z.level)}}wi(I),xi(R),$i(G||null),_i(O)}).catch(C=>{x||(Si(!1),fe(`History load failed for tick ${P}: ${C.message}`,"error",5e3))}),Ie(()=>{x=!0})})}),he(()=>{const u=o();if(!u)return;r.room,r.shard,cu(),u.hoverLayer.clearPendingTile(),s==null||s.destroy(),s=null,u.clear(),u.resetView(),t==null||t.destroy(),t=null,i==null||i.destroy(),i=null,n==null||n.destroy(),n=null;const g=xe(a);g&&g.room===r.room&&(lr(`terrain applied immediately (pre-loaded) — ${r.room}`),s=Nn(g.data,u.app.renderer),vi(s,xe(jr)),u.world.addChildAt(s,0),u.bringNavOverlayToTop());const $=r.room,m=r.shard,S=Qe($),M=xe(()=>r.onNavigate),b=xe(gi);if(S&&M){const y=(P,x)=>!b||sn(P,x,b),T=P=>{M(P,m)};u.setupNavigationZones({west:y(S.x-1,S.y)?()=>T(Be(S.x-1,S.y)):void 0,east:y(S.x+1,S.y)?()=>T(Be(S.x+1,S.y)):void 0,north:y(S.x,S.y-1)?()=>T(Be(S.x,S.y-1)):void 0,south:y(S.x,S.y+1)?()=>T(Be(S.x,S.y+1)):void 0})}}),he(()=>{const u=o();if(!u)return;const g=xe(()=>r.room),$=xe(()=>r.shard),m=Qe(g);if(m&&r.onNavigate){const S=r.onNavigate,M=gi(),b=(T,P)=>!M||sn(T,P,M),y=T=>{S(T,$)};qd({currentRoom:()=>r.room,worldBounds:gi,onMove:(T,P)=>y(Be(T,P))}),u.setupNavigationZones({west:b(m.x-1,m.y)?()=>y(Be(m.x-1,m.y)):void 0,east:b(m.x+1,m.y)?()=>y(Be(m.x+1,m.y)):void 0,north:b(m.x,m.y-1)?()=>y(Be(m.x,m.y-1)):void 0,south:b(m.x,m.y+1)?()=>y(Be(m.x,m.y+1)):void 0})}}),he(()=>{const u=Et(),g=o();u==="view"&&g&&(dt(),g.hoverLayer.clearPendingTile())}),he(()=>{const u=o(),g=Ct();u&&(g?u.hoverLayer.setPendingTile(g.tx,g.ty):u.hoverLayer.clearPendingTile())}),he(()=>{const u=o(),g=a();if(!(!u||!g||g.room!==r.room)){if(s!=null&&s.parent){lr(`terrain already in scene, skipping — ${r.room}`);return}lr(`terrain applied (async) — ${r.room}`),s=Nn(g.data,u.app.renderer),vi(s,xe(jr)),u.world.addChildAt(s,0),u.bringNavOverlayToTop()}}),he(()=>{var M,b;const u=o(),g=d();if(!u||!g)return;const{objects:$,diff:m,users:S}=g;if(t||(lr(`object layer created — ${r.room}`),t=new Ed(u.app.ticker,tn(),(M=Ae())==null?void 0:M._id,(b=Ae())==null?void 0:b.badge,S),t.container.label="objects",u.world.addChild(t.container),u.bringNavOverlayToTop(),i=new Pd(u.app.ticker),i.container.label="animations",u.world.addChild(i.container),n=new Ad,u.world.addChild(n.container),u.bringNavOverlayToTop(),u.setTileHandlers((y,T)=>{},(y,T,P)=>{const x=r.room,C=r.shard,I=Et(),O=vn();if((O==null?void 0:O.type)==="moveFlag"){const H=ae();if(!H)return;const{name:z,room:U,color:F,secondaryColor:Y}=O;H.http.game.removeFlag(U,z).then(()=>H.http.game.createFlag(x,y,T,z,F,Y,C??void 0)).then(()=>{fe(`Flag "${z}" moved`,"success"),cn()}).catch(Z=>{ar("move flag failed:",Z),fe(`Failed to move flag "${z}"`,"error"),cn()});return}if(I==="flag"){const H=Ct();if(!H||H.tx!==y||H.ty!==T){ln({tx:y,ty:T}),u.hoverLayer.setPendingTile(y,T);return}const z=ae();if(!z)return;const U=Ht(),F=U.name.trim();if(!F){fe("Flag name is required","error");return}const Y=kr[U.color]??0,Z=kr[U.secondaryColor]??0;z.http.game.createFlag(x,y,T,F,Y,Z,C??void 0).then(()=>{fe(`Flag "${F}" created`,"success"),dt(),u.hoverLayer.clearPendingTile(),z.http.game.genUniqueFlagName().then(W=>oo(j=>({...j,name:W.name}))).catch(W=>ar("gen unique flag name failed:",W))}).catch(W=>ar("create flag failed:",W));return}if(I==="build"){if(!P&&!et().structureType){fe("Select a structure type first","error");return}if(P){if(!t)return;const z=t.getObjectsAtTile(y,T).filter(({obj:F})=>F.type==="constructionSite");if(z.length===0){fe("No construction sites on this tile","error");return}const U=ae();if(!U)return;U.http.game.removeConstructionSite(x,z.map(({id:F})=>F),C??void 0).then(()=>{fe(`Removed ${z.length} construction site${z.length>1?"s":""}`,"success"),dt(),u.hoverLayer.clearPendingTile()}).catch(F=>{ar("remove construction sites failed:",F),fe(`Failed to remove construction sites: ${F.message}`,"error")});return}ln({tx:y,ty:T}),u.hoverLayer.setPendingTile(y,T),au(x,C);return}if(dt(),u.hoverLayer.clearPendingTile(),!t)return;const G=t.getObjectsAtTile(y,T);if(G.length===0){P||(xr([]),u.hoverLayer.clearSelection());return}let R=[...ei()];if(P){const H=new Set(G.map(U=>U.id));if(R.some(U=>H.has(U.id)))R=R.filter(U=>!H.has(U.id));else{const U=G.filter(({id:F})=>!R.some(Y=>Y.id===F)).map(({id:F,obj:Y})=>Hn(F,Y));R=[...R,...U]}}else R=G.map(({id:H,obj:z})=>Hn(H,z));xr(R);const L=R.map(({id:H,type:z})=>({id:H,type:z,visual:t.getVisualById(H)})).filter(H=>H.visual!=null);u.hoverLayer.setSelectedObjects(L)})),m&&Xd(m,$),t.update($,m,S),i){i.clear();const y=(Zr()??2e3)*.6;for(const T in $){const P=$[T];if(!P||P.type!=="creep")continue;const x=P.actionLog;if(x){if(x.harvest){const C=x.harvest;i.addHarvest(C.x,C.y,P.x,P.y,y)}if(x.upgradeController){const C=x.upgradeController;i.addUpgradeController(P.x,P.y,C.x,C.y,y)}if(x.build){const C=x.build;i.addBuild(P.x,P.y,C.x,C.y,y),t==null||t.triggerBuildAt(C.x,C.y,y)}}}}}),he(()=>{const u=p();n==null||n.update(u)}),he(()=>{t==null||t.setShowLabels(tn())}),he(()=>{const u=jr();s&&vi(s,u)}),(()=>{var u=uu(),g=u.firstChild;return hr($=>e=$,g),v(u,(()=>{var $=re(()=>!!qn());return()=>$()&&(()=>{var m=hu();return v(m,qn),A(S=>D(m,"pointer-events",Mt()==="empty"||Mt()==="lost"?"auto":"none")),m})()})(),null),v(u,(()=>{var $=re(()=>!He()&&ut()!==null);return()=>$()&&(()=>{var m=fu();return m.firstChild,v(m,ut,null),m})()})(),null),v(u,k(X,{get when(){return He()},get children(){var $=du(),m=$.firstChild,S=m.nextSibling,M=S.firstChild,b=M.nextSibling,y=b.nextSibling;return m.$$input=T=>so(parseInt(T.currentTarget.value,10)),v(M,on),v(b,(()=>{var T=re(()=>!!Ue());return()=>T()?"Loading…":`Tick ${kt()}`})()),v(y,$r),A(T=>{var P=on(),x=$r(),C=Ue()?"#f0883e":"#8b949e";return P!==T.e&&ve(m,"min",T.e=P),x!==T.t&&ve(m,"max",T.t=x),C!==T.a&&D(b,"color",T.a=C),T},{e:void 0,t:void 0,a:void 0}),A(()=>m.value=kt()),$}}),null),u})()}Se(["input"]);var gu=E("<div style=position:fixed;bottom:16px;right:16px;display:flex;flex-direction:column;gap:8px;z-index:9999;pointer-events:none>"),mu=E('<div style="padding:10px 16px;border-radius:6px;font-size:13px;color:#fff;box-shadow:0 4px 12px rgba(0,0,0,0.4);max-width:320px;word-break:break-word;pointer-events:auto;animation:toast-in 0.2s ease">');function yu(){return(()=>{var r=gu();return v(r,k(pe,{get each(){return Pl()},children:e=>(()=>{var t=mu();return v(t,()=>e.message),A(i=>D(t,"background",e.type==="error"?"#da3633":"#238636")),t})()})),r})()}const[lt,vu]=N(!0),[je,bu]=N(!0),[Nt,wu]=N(!1);function lo(){vu(r=>!r)}function ao(){bu(r=>!r)}function co(){wu(r=>!r)}var xu=E('<div style=flex-shrink:0;display:flex;overflow:hidden><div style="width:32px;flex-shrink:0;border-right:1px solid #30363d;display:flex;flex-direction:column;align-items:center;padding:6px 0;gap:6px"><button></button><button title=Clear></button></div><div class=console-scroll style=flex:1;overflow:auto;padding:8px>'),jn=E("<div style=width:4px;flex-shrink:0;cursor:col-resize>"),$u=E('<div style=flex-shrink:0;display:flex;flex-direction:column;overflow:hidden><div class=console-scroll style=flex:1;overflow:auto;padding:8px></div><form style="display:flex;gap:6px;padding:8px;border-top:1px solid #30363d"><span style=color:#8b949e;font-size:13px;line-height:28px>&gt;</span><input type=text placeholder="Game.creeps.Harvester1.moveTo(10, 10)"style="flex:1;padding:6px 8px;border-radius:4px;border:1px solid #30363d;background:#161b22;color:#c9d1d9;font-size:12px;font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace"><button type=submit style="padding:6px 12px;border-radius:4px;border:none;background:#238636;color:#fff;font-size:12px;cursor:pointer">Run'),_u=E("<div style=flex-shrink:0;display:flex;flex-direction:column;overflow:hidden><div style=flex:1;display:flex;align-items:center;justify-content:center;color:#484f58;font-style:italic>Memory – coming soon"),Su=E("<div style=flex:1;display:flex;overflow:hidden>"),ku=E(`<div style=display:flex;flex-direction:column;height:100%;background:#0d1117><div style="height:32px;flex-shrink:0;padding:0 10px;border-bottom:1px solid #30363d;display:flex;align-items:center;gap:6px"><button>Log</button><button>Console</button><button>Memory</button></div><style>
10
+ .console-scroll::-webkit-scrollbar {
11
+ width: 8px;
12
+ height: 8px;
13
+ }
14
+ .console-scroll::-webkit-scrollbar-track {
15
+ background: #161b22;
16
+ }
17
+ .console-scroll::-webkit-scrollbar-thumb {
18
+ background: #484f58;
19
+ border-radius: 4px;
20
+ }
21
+ .console-scroll::-webkit-scrollbar-thumb:hover {
22
+ background: #6e7681;
23
+ }
24
+ `),Cu=E("<div style=color:#484f58;font-style:italic>No log output yet…"),Tu=E("<div style=margin-bottom:4px;color:#f85149;white-space:pre-wrap;word-break:break-word>"),Mu=E("<div style=margin-bottom:4px;color:#c9d1d9;white-space:pre-wrap;word-break:break-word>"),Eu=E("<div style=color:#484f58;font-style:italic>No command results yet…"),Pu=E("<div style=margin-bottom:4px;color:#58a6ff;white-space:pre-wrap;word-break:break-word>");const{error:Ru}=Pt("console");function Ou(r){const[e,t]=N([]),[i,n]=N(""),[s,o]=N(!0),l=[1,1,1],[a,c]=N(Gl(ye.consoleWeights,[...l])),[d,f]=N(null);let p,h,u,g=0;Cr(()=>{const R=ae();if(!R)return;const L=new un;L.add(R.stores.user.subscribe("console")),L.add(R.stores.user.on("user:console",H=>{const z=H.messages,U={id:g++,log:z.log??[],results:z.results??[],error:z.error??[]};t(F=>{const Y=[...F,U];return Y.length>200?Y.slice(Y.length-200):Y})})),Ie(()=>L.dispose())}),he(()=>{e(),s()&&requestAnimationFrame(()=>{lt()&&p&&(p.scrollTop=p.scrollHeight),je()&&h&&(h.scrollTop=h.scrollHeight)})});const $=(R,L,H)=>{var U,F;const z=!R&&!L&&!H;z&&!r.isCollapsed&&((U=r.onToggle)==null||U.call(r)),!z&&r.isCollapsed&&((F=r.onToggle)==null||F.call(r))};he(()=>{$(lt(),je(),Nt())});const m=()=>{const R=a(),L=[lt(),je(),Nt()],H=L.filter(Boolean).length;if(H===0)return[0,0,0];if(H===1){const F=L.findIndex(Boolean);return[0,0,0].map((Y,Z)=>Z===F?1:0)}const U=L.map((F,Y)=>F?R[Y]:0).reduce((F,Y)=>F+Y,0);if(U===0){const F=1/H;return[0,0,0].map((Y,Z)=>L[Z]?F:0)}return L.map((F,Y)=>F?R[Y]/U:0)};he(()=>{Dl(ye.consoleWeights,a())});const S=R=>L=>{L.preventDefault(),L.stopPropagation(),f(R),document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",M),window.addEventListener("pointerup",b,{once:!0})},M=R=>{const L=d();if(L===null)return;const H=u;if(!H)return;const z=H.getBoundingClientRect(),U=Math.max(.02,Math.min(.98,(R.clientX-z.left)/z.width)),F=[...a()],Y=[lt(),je(),Nt()];if(L===0){const Z=Y[0],W=Y[1];if(!Z||!W)return;const j=U/(1-U);F[0]=j,F[1]=1,c(F)}else{const Z=Y[1],W=Y[2];if(!Z||!W)return;const j=U/(1-U);F[1]=j,F[2]=1,c(F)}},b=()=>{f(null),document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("pointermove",M)},y=async R=>{R.preventDefault();const L=ae();if(!(!L||!i().trim()))try{await L.http.user.console(i().trim(),r.shard??"shard0"),n("")}catch(H){Ru("command failed:",H)}},T=R=>({background:R?"#30363d":"transparent",border:`1px solid ${R?"#58a6ff":"transparent"}`,color:R?"#c9d1d9":"#8b949e","font-size":"12px",cursor:"pointer",padding:"2px 10px","border-radius":"4px"}),P=()=>e().flatMap(R=>R.log),x=()=>e().flatMap(R=>R.error),C=()=>e().flatMap(R=>R.results),I={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},O={background:"transparent",border:"none",color:"#8b949e",cursor:"pointer",padding:"4px","border-radius":"4px",display:"flex","align-items":"center","justify-content":"center"},G=()=>{o(!0),requestAnimationFrame(()=>{lt()&&p&&(p.scrollTop=p.scrollHeight),je()&&h&&(h.scrollTop=h.scrollHeight)})};return(()=>{var R=ku(),L=R.firstChild,H=L.firstChild,z=H.nextSibling,U=z.nextSibling;return L.nextSibling,at(H,"click",lo,!0),at(z,"click",ao,!0),at(U,"click",co,!0),v(R,k(X,{get when(){return!r.isCollapsed},get children(){var F=Su();return hr(Y=>u=Y,F),v(F,k(X,{get when(){return lt()},get children(){var Y=xu(),Z=Y.firstChild,W=Z.firstChild,j=W.nextSibling,J=Z.nextSibling;W.$$click=()=>s()?o(!1):G(),v(W,(()=>{var q=re(()=>!!s());return()=>q()?k(za,{size:16}):k(Fa,{size:16})})()),j.$$click=()=>t([]),v(j,k(Yr,{size:16})),J.addEventListener("scroll",()=>{p&&o(p.scrollHeight-p.scrollTop-p.clientHeight<20)});var Q=p;return typeof Q=="function"?hr(Q,J):p=J,v(J,(()=>{var q=re(()=>P().length===0&&x().length===0);return()=>q()&&Cu()})(),null),v(J,k(pe,{get each(){return x()},children:q=>(()=>{var ue=Tu();return ue.innerHTML=q,ue})()}),null),v(J,k(pe,{get each(){return P()},children:q=>(()=>{var ue=Mu();return ue.innerHTML=q,ue})()}),null),A(q=>{var ue=`${m()[0]*100}%`,Oe=s()?"Pause scrolling":"Resume scrolling",rt=O,Ne=O,Ge={...I};return ue!==q.e&&D(Y,"width",q.e=ue),Oe!==q.t&&ve(W,"title",q.t=Oe),q.a=V(W,rt,q.a),q.o=V(j,Ne,q.o),q.i=V(J,Ge,q.i),q},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),Y}}),null),v(F,k(X,{get when(){return re(()=>!!lt())()&&je()},get children(){var Y=jn();return at(Y,"pointerdown",S(0),!0),A(Z=>D(Y,"background",d()===0?"#388bfd":"#21262d")),Y}}),null),v(F,k(X,{get when(){return je()},get children(){var Y=$u(),Z=Y.firstChild,W=Z.nextSibling,j=W.firstChild,J=j.nextSibling;J.nextSibling,Z.addEventListener("scroll",()=>{h&&o(h.scrollHeight-h.scrollTop-h.clientHeight<20)});var Q=h;return typeof Q=="function"?hr(Q,Z):h=Z,v(Z,(()=>{var q=re(()=>C().length===0);return()=>q()&&Eu()})(),null),v(Z,k(pe,{get each(){return C()},children:q=>(()=>{var ue=Pu();return ue.innerHTML=q,ue})()}),null),W.addEventListener("submit",y),J.$$input=q=>n(q.currentTarget.value),A(q=>{var ue=`${m()[1]*100}%`,Oe={...I};return ue!==q.e&&D(Y,"width",q.e=ue),q.t=V(Z,Oe,q.t),q},{e:void 0,t:void 0}),A(()=>J.value=i()),Y}}),null),v(F,k(X,{get when(){return re(()=>!!je())()&&Nt()},get children(){var Y=jn();return at(Y,"pointerdown",S(1),!0),A(Z=>D(Y,"background",d()===1?"#388bfd":"#21262d")),Y}}),null),v(F,k(X,{get when(){return Nt()},get children(){var Y=_u();return Y.firstChild,A(Z=>D(Y,"width",`${m()[2]*100}%`)),Y}}),null),A(Y=>D(F,"user-select",d()!==null?"none":"auto")),F}}),null),A(F=>{var Y=T(lt()),Z=T(je()),W=T(Nt());return F.e=V(H,Y,F.e),F.t=V(z,Z,F.t),F.a=V(U,W,F.a),F},{e:void 0,t:void 0,a:void 0}),R})()}Se(["click","pointerdown","input"]);const Lu={1:2e4,2:1e4,3:2e4,4:4e4,5:8e4,6:12e4,7:15e4,8:2e5};var Au=E("<div style=display:flex;gap:5px;flex-wrap:wrap>"),Iu=E("<div style=width:18px;height:18px;border-radius:50%;cursor:pointer;flex-shrink:0>");const Nu=[{label:"Red",value:1,css:"#ff0000"},{label:"Purple",value:2,css:"#800080"},{label:"Blue",value:3,css:"#0000ff"},{label:"Cyan",value:4,css:"#00ffff"},{label:"Green",value:5,css:"#008000"},{label:"Yellow",value:6,css:"#ffff00"},{label:"Orange",value:7,css:"#ffa500"},{label:"Brown",value:8,css:"#a52a2a"},{label:"Grey",value:9,css:"#808080"},{label:"White",value:10,css:"#ffffff"}];function ii(r){return(()=>{var e=Au();return v(e,k(pe,{each:Nu,children:t=>(()=>{var i=Iu();return i.$$click=()=>r.onChange(t.value),A(n=>{var s=t.label,o=t.css,l=r.value===t.value?"0 0 0 2px #0d1117, 0 0 0 4px #c9d1d9":"none";return s!==n.e&&ve(i,"title",n.e=s),o!==n.t&&D(i,"background",n.t=o),l!==n.a&&D(i,"box-shadow",n.a=l),n},{e:void 0,t:void 0,a:void 0}),i})()})),e})()}Se(["click"]);var Vt=E("<div>"),ni=E("<div style=font-variant-numeric:tabular-nums>"),Gu=E("<span style=font-variant-numeric:tabular-nums;font-weight:400> / "),Du=E('<div style="background:#21262d;border-top:1px solid #30363d;font-size:10px"><div style="padding:4px 8px;background:#161b22;color:#8b949e;font-weight:600;display:flex;justify-content:space-between"><span>Store Contents</span></div><div style="display:grid;grid-template-columns:1fr 1fr;gap:1px;background:#21262d">'),zu=E('<div style="padding:3px 8px;background:#0d1117;color:#8b949e">'),Bu=E('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;font-variant-numeric:tabular-nums">'),Hu=E("<div>Owner"),uo=E("<div>Hits"),bn=E("<div style=font-variant-numeric:tabular-nums> / "),Fu=E("<div>Time to live"),Wu=E("<div>Fatigue"),Uu=E('<div style="background:#21262d;border-top:1px solid #30363d;font-size:10px"><div style="padding:4px 8px;background:#161b22;color:#8b949e;font-weight:600">Body (<!>)</div><div style=display:flex;flex-wrap:wrap;gap:3px;padding:8px;background:#0d1117>'),Xu=E("<div><div>"),Yu=E("<div style=width:11px;height:11px;border-radius:50%;flex-shrink:0>"),qu=E('<div style=padding:8px;display:flex;flex-direction:column;gap:8px;background:#0d1117><label>Primary color</label><label>Secondary color</label><div style=display:flex;gap:6px><button style="flex:1;border-radius:4px;padding:5px 8px;font-size:11px;transition:background 150ms ease, color 150ms ease, border-color 150ms ease">Apply color</button><button style="border-radius:4px;padding:5px 8px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background 150ms ease, color 150ms ease">'),ju=E("<div>Level"),Vu=E("<div>Progress"),Zu=E("<div>Safe modes"),Ku=E("<div>Power"),Ju=E("<div>Downgrade in"),Qu=E("<div>Safe mode active"),eh=E("<div style=font-variant-numeric:tabular-nums> ticks"),th=E('<div style=padding:8px;display:flex;flex-direction:column;gap:6px;background:#0d1117><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px">Activate safe mode</button><button style="color:#fff;border:none;border-radius:4px;padding:6px 8px;font-size:12px;cursor:pointer">'),rh=E("<div><div><div>Owner</div><div>"),ih=E("<div>Reserved"),nh=E("<div> (<!>)"),sh=E("<div>Notify when attacked"),oh=E("<div style=display:flex;align-items:center><button style=background:transparent;border:none;cursor:pointer;padding:0;display:flex;align-items:center>"),lh=E("<div><div>Energy</div><div style=font-variant-numeric:tabular-nums> / "),ah=E("<div style=width:8px;height:8px;border-radius:50%;flex-shrink:0>"),Ci=E('<button style="background:transparent;border:none;cursor:pointer;padding:0 2px;display:flex;align-items:center;justify-content:center;flex-shrink:0">'),ch=E('<div style="border-radius:6px;margin-bottom:6px;overflow:hidden;transition:border-color 150ms ease"><div style="display:flex;align-items:center;gap:7px;padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d"><span style=font-size:11px;font-weight:600;color:#c9d1d9;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:flex;align-items:center;gap:5px></span><span style=font-size:10px;color:#484f58;flex-shrink:0;margin-right:2px>(<!>,<!>)</span><button title=Deselect style="background:transparent;border:none;color:#8b949e;cursor:pointer;padding:0 4px;font-size:14px;line-height:1;display:flex;align-items:center;justify-content:center">×'),dh=E("<span style=font-weight:400;color:#8b949e>"),uh=E("<div style=flex:1;overflow:auto;min-height:0;padding:8px>"),hh=E("<div style=color:#484f58;font-style:italic;font-size:12px>Click a tile to select objects…");const{log:Vn,error:Jt}=Pt("SelectionList"),fh={creep:"#f0883e",spawn:"#58a6ff",extension:"#79c0ff",tower:"#3fb950",container:"#8b949e",storage:"#d29922",link:"#a371f7",rampart:"#58a6ff",road:"#484f58",wall:"#21262d",extractor:"#8b949e",lab:"#f778ba",terminal:"#d29922",observer:"#79c0ff",powerSpawn:"#f0883e",nuker:"#f85149",factory:"#8b949e",invaderCore:"#f85149",source:"#d29922",mineral:"#79c0ff",deposit:"#d29922",controller:"#58a6ff",powerBank:"#f0883e",portal:"#a371f7",energy:"#d29922"},ph={creep:"Creep",spawn:"Spawn",extension:"Extension",tower:"Tower",container:"Container",storage:"Storage",link:"Link",rampart:"Rampart",road:"Road",wall:"Wall",extractor:"Extractor",lab:"Lab",terminal:"Terminal",observer:"Observer",powerSpawn:"Power Spawn",nuker:"Nuker",factory:"Factory",invaderCore:"Invader Core",source:"Source",mineral:"Mineral",deposit:"Deposit",controller:"Controller",powerBank:"Power Bank",portal:"Portal",energy:"Energy",flag:"Flag"},gh=new Set(["x","y","type","id","name","user","_id","room","hitsMax","energyCapacity","body","storeCapacity","storeCapacityResource"]),Zn=new Set(["hits","energy","energyCapacity","store","progress","progressTotal","nextDecayTime"]),Kn={hits:"Hits",energy:"Energy",progress:"Progress",progressTotal:"Progress total",ticksToLive:"Ticks to live",ticksToRegeneration:"Ticks to regen",ticksToDecay:"Ticks to decay",nextDecayTime:"Decays in",fatigue:"Fatigue",cooldown:"Cooldown",mineralType:"Mineral type",mineralAmount:"Mineral amount",density:"Density",notifyWhenAttacked:"Notify when attacked",isPublic:"Public",structureType:"Structure type",level:"Level",power:"Power",powerCapacity:"Power capacity",depositType:"Deposit type",lastCooldown:"Last cooldown",resourceType:"Resource type",amount:"Amount",decay:"Decay in",mode:"Mode",actionLog:"Action log",store:"Store"};function mh(r){return Kn[r]?Kn[r]:r.replace(/([A-Z])/g," $1").replace(/^./,e=>e.toUpperCase()).trim()}function yh(r){return typeof r=="number"?String(r):typeof r=="string"?r:typeof r=="boolean"?r?"Yes":"No":null}function Jn(r){if(r>=1e6){const e=r/1e6;return`${parseFloat(e.toFixed(2))}M`}if(r>=1e3){const e=r/1e3;return`${parseFloat(e.toFixed(1))}K`}return String(r)}const oe=(r=!1)=>({padding:"3px 8px",background:"#0d1117",color:r?"#8b949e":"#c9d1d9",overflow:"hidden","text-overflow":"ellipsis","white-space":"nowrap"}),ci={display:"grid","grid-template-columns":"1fr 1fr",gap:"1px",background:"#21262d","font-size":"10px"};function vh(r){const e=()=>{const t=r.item.raw,i=[];for(const n in t){if(gh.has(n))continue;const s=t[n];let o=yh(s);if(!(n==="notifyWhenAttacked"&&s===!1)&&!(n==="off"&&s===!1)){if(n==="hits"&&typeof t.hitsMax=="number"&&(o=`${s} / ${t.hitsMax}`),n==="energy"&&typeof t.energyCapacity=="number"&&(o=`${s} / ${t.energyCapacity}`),n==="nextDecayTime"&&typeof s=="number"){const l=ut();l!==null&&(o=String(s-l))}o!==null&&i.push({key:n,label:mh(n),value:o})}}return i.sort((n,s)=>{const o=Zn.has(n.key)?0:1,l=Zn.has(s.key)?0:1;return o-l}),i};return k(X,{get when(){return e().length>0},get children(){var t=Vt();return v(t,k(pe,{get each(){return e()},children:i=>[(()=>{var n=Vt();return v(n,()=>i.label),A(s=>V(n,oe(!0),s)),n})(),(()=>{var n=ni();return v(n,()=>i.value),A(s=>V(n,{...oe()},s)),n})()]})),A(i=>V(t,ci,i)),t}})}function bh(r){const e=()=>{const i=r.store||{},n=[];for(const s in i)n.push([s,i[s]]);return n},t=()=>{const i=r.store||{};let n=0;for(const s in i)n+=i[s];return n};return k(X,{get when(){return e().length>0},get children(){var i=Du(),n=i.firstChild;n.firstChild;var s=n.nextSibling;return v(n,k(X,{get when(){return r.capacity!=null},get children(){var o=Gu(),l=o.firstChild;return v(o,t,l),v(o,()=>r.capacity,null),o}}),null),v(s,k(pe,{get each(){return e()},children:([o,l])=>[(()=>{var a=zu();return v(a,o),a})(),(()=>{var a=Bu();return v(a,l),a})()]})),i}})}const wh={tough:"#4c4c4c",move:"#a9b7c6",work:"#ffe56d",carry:"#777777",attack:"#f93842",ranged_attack:"#5d80b2",heal:"#65fd62",claim:"#b99cfb"};function xh(r){const e=()=>r.item.raw,t=()=>typeof e().user=="string"?e().user:null,i=()=>{var p,h;const f=t();return f?((h=(p=eo())==null?void 0:p[f])==null?void 0:h.username)??f:null},n=()=>typeof e().hits=="number"?e().hits:null,s=()=>typeof e().hitsMax=="number"?e().hitsMax:null,o=()=>{const f=e().ageTime,p=ut();return typeof f=="number"&&p!==null?Math.max(0,f-p):null},l=()=>typeof e().fatigue=="number"?e().fatigue:null,a=()=>e().store,c=()=>typeof e().storeCapacity=="number"?e().storeCapacity:null,d=()=>e().body??[];return(()=>{var f=Xu(),p=f.firstChild;return v(p,k(X,{get when(){return i()},get children(){return[(()=>{var h=Hu();return A(u=>V(h,oe(!0),u)),h})(),(()=>{var h=Vt();return v(h,i),A(u=>V(h,oe(),u)),h})()]}}),null),v(p,k(X,{get when(){return re(()=>n()!==null)()&&s()!==null},get children(){return[(()=>{var h=uo();return A(u=>V(h,oe(!0),u)),h})(),(()=>{var h=bn(),u=h.firstChild;return v(h,n,u),v(h,s,null),A(g=>V(h,{...oe()},g)),h})()]}}),null),v(p,k(X,{get when(){return o()!==null},get children(){return[(()=>{var h=Fu();return A(u=>V(h,oe(!0),u)),h})(),(()=>{var h=ni();return v(h,o),A(u=>V(h,{...oe()},u)),h})()]}}),null),v(p,k(X,{get when(){return re(()=>l()!==null)()&&l()>0},get children(){return[(()=>{var h=Wu();return A(u=>V(h,oe(!0),u)),h})(),(()=>{var h=ni();return v(h,l),A(u=>V(h,{...oe()},u)),h})()]}}),null),v(f,k(bh,{get store(){return a()},get capacity(){return c()}}),null),v(f,k(X,{get when(){return d().length>0},get children(){var h=Uu(),u=h.firstChild,g=u.firstChild,$=g.nextSibling;$.nextSibling;var m=u.nextSibling;return v(u,()=>d().length,$),v(m,k(pe,{get each(){return d()},children:S=>(()=>{var M=Yu();return A(b=>{var y=S.type.replace("_"," "),T=wh[S.type]??"#484f58",P=S.hits===0?.25:1;return y!==b.e&&ve(M,"title",b.e=y),T!==b.t&&D(M,"background",b.t=T),P!==b.a&&D(M,"opacity",b.a=P),b},{e:void 0,t:void 0,a:void 0}),M})()})),h}}),null),A(h=>V(p,ci,h)),f})()}function $h(r){const e=()=>r.item.raw,t=()=>typeof e().name=="string"?e().name:"",i=()=>typeof e().room=="string"?e().room:"",n=()=>typeof e().color=="number"?e().color:1,s=()=>typeof e().secondaryColor=="number"?e().secondaryColor:1,[o,l]=N(n()),[a,c]=N(s());he(()=>{l(n()),c(s())});const d=()=>o()!==n()||a()!==s(),f=()=>{const g=ae();if(!g)return;const $=o(),m=a();Vn(`changeFlagColor: name="${t()}" room=${i()} primary=${$} secondary=${m}`),g.http.game.changeFlagColor(i(),t(),$,m).then(()=>Vn("changeFlagColor OK")).catch(S=>Jt("changeFlagColor FAILED:",S))},p=()=>{const g=vn();return(g==null?void 0:g.type)==="moveFlag"&&g.id===r.item.id},h=()=>{if(p()){an(null);return}an({type:"moveFlag",id:r.item.id,name:t(),room:i(),color:o(),secondaryColor:a()})},u={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var g=qu(),$=g.firstChild;$.firstChild;var m=$.nextSibling;m.firstChild;var S=m.nextSibling,M=S.firstChild,b=M.nextSibling;return v($,k(ii,{get value(){return o()},onChange:l}),null),v(m,k(ii,{get value(){return a()},onChange:c}),null),M.addEventListener("mouseleave",y=>{d()&&(y.currentTarget.style.background="#238636")}),M.addEventListener("mouseenter",y=>{d()&&(y.currentTarget.style.background="#2ea043")}),M.$$click=f,b.addEventListener("mouseleave",y=>{y.currentTarget.style.color=p()?"#c9d1d9":"#8b949e"}),b.addEventListener("mouseenter",y=>{y.currentTarget.style.color="#c9d1d9"}),b.$$click=h,v(b,(()=>{var y=re(()=>!!p());return()=>y()?k(ai,{size:13}):k(Na,{size:13})})()),A(y=>{var T=u,P=u,x=!d(),C=d()?"#238636":"#161b22",I=d()?"#fff":"#484f58",O=`1px solid ${d()?"#238636":"#30363d"}`,G=d()?"pointer":"not-allowed",R=p()?"Abort move":"Move flag",L=p()?"#30363d":"#21262d",H=p()?"#c9d1d9":"#8b949e",z=`1px solid ${p()?"#8b949e":"#30363d"}`;return y.e=V($,T,y.e),y.t=V(m,P,y.t),x!==y.a&&(M.disabled=y.a=x),C!==y.o&&D(M,"background",y.o=C),I!==y.i&&D(M,"color",y.i=I),O!==y.n&&D(M,"border",y.n=O),G!==y.s&&D(M,"cursor",y.s=G),R!==y.h&&ve(b,"title",y.h=R),L!==y.r&&D(b,"background",y.r=L),H!==y.d&&D(b,"color",y.d=H),z!==y.l&&D(b,"border",y.l=z),y},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0}),g})()}function _h(r){const e=()=>r.item.raw,t=()=>typeof e().level=="number"?e().level:0,i=()=>typeof e().progress=="number"?e().progress:null,n=()=>typeof e().progressTotal=="number"?e().progressTotal:null,s=()=>typeof e().downgradeTime=="number"?e().downgradeTime:null,o=()=>typeof e().safeModeAvailable=="number"?e().safeModeAvailable:0,l=()=>typeof e().safeMode=="number"?e().safeMode:null,a=()=>e().isPowerEnabled===!0,c=()=>e().reservation,d=()=>typeof e().user=="string"?e().user:null,f=()=>{var y;const b=d();return b?((y=Qs())==null?void 0:y.username)??b:null},p=()=>{const b=s(),y=ut();return b!==null&&y!==null?Math.max(0,b-y):null},h=()=>{const b=p();if(b===null)return"—";const y=Lu[t()];return y!==void 0&&b>=y?"Max":String(b)},u=()=>{var b;return d()!==null&&d()===((b=Ae())==null?void 0:b._id)},[g,$]=N(!1);let m=null;const S=()=>{const b=ae();b&&b.http.game.addObjectIntent(r.item.id,e().room,"activateSafeMode",{}).catch(y=>Jt("activateSafeMode failed:",y))},M=()=>{if(!g()){$(!0),m=setTimeout(()=>$(!1),3e3);return}m&&(clearTimeout(m),m=null),$(!1);const b=ae();b&&b.http.game.addObjectIntent(r.item.id,e().room,"unclaim",{}).catch(y=>Jt("unclaim failed:",y))};return(()=>{var b=rh(),y=b.firstChild,T=y.firstChild,P=T.nextSibling;return v(P,()=>f()??"None"),v(y,k(X,{get when(){return c()},children:x=>[(()=>{var C=ih();return A(I=>V(C,oe(!0),I)),C})(),(()=>{var C=nh(),I=C.firstChild,O=I.nextSibling;return O.nextSibling,v(C,()=>x().username,I),v(C,()=>x().ticksToEnd,O),A(G=>V(C,oe(),G)),C})()]}),null),v(y,k(X,{get when(){return t()>0},get children(){return[(()=>{var x=ju();return A(C=>V(x,oe(!0),C)),x})(),(()=>{var x=Vt();return v(x,t),A(C=>V(x,oe(),C)),x})(),k(X,{get when(){return re(()=>i()!==null)()&&n()!==null},get children(){return[(()=>{var x=Vu();return A(C=>V(x,oe(!0),C)),x})(),(()=>{var x=bn(),C=x.firstChild;return v(x,()=>Jn(i()),C),v(x,()=>Jn(n()),null),A(I=>V(x,{...oe()},I)),x})()]}}),(()=>{var x=Zu();return A(C=>V(x,oe(!0),C)),x})(),(()=>{var x=Vt();return v(x,o),A(C=>V(x,oe(),C)),x})(),(()=>{var x=Ku();return A(C=>V(x,oe(!0),C)),x})(),(()=>{var x=Vt();return v(x,()=>a()?"Enabled":"Disabled"),A(C=>V(x,oe(),C)),x})(),(()=>{var x=Ju();return A(C=>V(x,oe(!0),C)),x})(),(()=>{var x=ni();return v(x,h),A(C=>V(x,{...oe(),color:h()==="Max"?"#3fb950":void 0},C)),x})()]}}),null),v(y,k(X,{get when(){return l()!==null},get children(){return[(()=>{var x=Qu();return A(C=>V(x,oe(!0),C)),x})(),(()=>{var x=eh(),C=x.firstChild;return v(x,l,C),A(I=>V(x,{...oe()},I)),x})()]}}),null),v(b,k(X,{get when(){return u()},get children(){var x=th(),C=x.firstChild,I=C.nextSibling;return C.addEventListener("mouseleave",O=>{o()>0&&(O.currentTarget.style.background="#1f6feb")}),C.addEventListener("mouseenter",O=>{o()>0&&(O.currentTarget.style.background="#388bfd")}),C.$$click=S,I.addEventListener("mouseleave",O=>{g()||(O.currentTarget.style.background="#f85149")}),I.addEventListener("mouseenter",O=>{g()||(O.currentTarget.style.background="#da3633")}),I.$$click=M,v(I,()=>g()?"Confirm unclaim":"Unclaim"),A(O=>{var G=o()===0,R=o()>0?"#1f6feb":"#161b22",L=o()>0?"pointer":"not-allowed",H=o()>0?1:.5,z=g()?"#da3633":"#f85149";return G!==O.e&&(C.disabled=O.e=G),R!==O.t&&D(C,"background",O.t=R),L!==O.a&&D(C,"cursor",O.a=L),H!==O.o&&D(C,"opacity",O.o=H),z!==O.i&&D(I,"background",O.i=z),O},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),x}}),null),A(x=>{var C=ci,I=oe(!0),O=oe();return x.e=V(y,C,x.e),x.t=V(T,I,x.t),x.a=V(P,O,x.a),x},{e:void 0,t:void 0,a:void 0}),b})()}function Sh(r){const e=()=>r.item.raw,t=()=>{const d=e().store;return(d==null?void 0:d.energy)??0},i=()=>{const d=e().storeCapacityResource;return(d==null?void 0:d.energy)??0},n=()=>typeof e().hits=="number"?e().hits:null,s=()=>typeof e().hitsMax=="number"?e().hitsMax:null,o=()=>e().notifyWhenAttacked===!0,l=()=>typeof e().user=="string"?e().user:null,a=()=>{var d;return l()!==null&&l()===((d=Ae())==null?void 0:d._id)},c=()=>{const d=ae();d&&d.http.game.addObjectIntent(r.item.id,e().room,"notifyWhenAttacked",{enabled:!o()}).catch(f=>Jt("notifyWhenAttacked failed:",f))};return(()=>{var d=lh(),f=d.firstChild,p=f.nextSibling,h=p.firstChild;return v(p,t,h),v(p,i,null),v(d,k(X,{get when(){return re(()=>n()!==null)()&&s()!==null},get children(){return[(()=>{var u=uo();return A(g=>V(u,oe(!0),g)),u})(),(()=>{var u=bn(),g=u.firstChild;return v(u,n,g),v(u,s,null),A($=>V(u,{...oe()},$)),u})()]}}),null),v(d,k(X,{get when(){return a()},get children(){return[(()=>{var u=sh();return A(g=>V(u,oe(!0),g)),u})(),(()=>{var u=oh(),g=u.firstChild;return g.addEventListener("mouseleave",$=>{$.currentTarget.style.color=o()?"#3fb950":"#484f58"}),g.addEventListener("mouseenter",$=>{$.currentTarget.style.color=o()?"#56d364":"#8b949e"}),g.$$click=c,v(g,(()=>{var $=re(()=>!!o());return()=>$()?k(na,{size:12}):k(ta,{size:12})})()),A($=>{var m={...oe()},S=o()?"Notifications on — click to disable":"Notifications off — click to enable",M=o()?"#3fb950":"#484f58";return $.e=V(u,m,$.e),S!==$.t&&ve(g,"title",$.t=S),M!==$.a&&D(g,"color",$.a=M),$},{e:void 0,t:void 0,a:void 0}),u})()]}}),null),A(u=>{var g=ci,$=oe(!0),m={...oe()};return u.e=V(d,g,u.e),u.t=V(f,$,u.t),u.a=V(p,m,u.a),u},{e:void 0,t:void 0,a:void 0}),d})()}const kh={creep:xh,flag:$h,controller:_h,extension:Sh};function Ch(r){const e=()=>fh[r.item.type]??"#c9d1d9",t=()=>ph[r.item.type]??r.item.type,i=()=>r.item.type==="creep",n=()=>r.item.type==="flag",s=()=>{var T;if(!i())return!1;const b=r.item.raw,y=typeof b.user=="string"?b.user:null;return y!==null&&y===((T=Ae())==null?void 0:T._id)},o=()=>{var T;if(i()||n()||r.item.type==="controller")return!1;const b=r.item.raw,y=typeof b.user=="string"?b.user:null;return y!==null&&y===((T=Ae())==null?void 0:T._id)},l=()=>kh[r.item.type]||vh,[a,c]=N(!1);let d=null;const[f,p]=N(!1);let h=null;const[u,g]=N(!1);let $=null;const m=b=>{if(b.stopPropagation(),!u()){g(!0),$=setTimeout(()=>g(!1),3e3);return}$&&(clearTimeout($),$=null),g(!1);const y=ae();if(!y)return;const T=r.item.id,P=r.item.raw;y.http.game.removeFlag(P.room,P.name).then(()=>Dr(T)).catch(()=>{})},S=b=>{if(b.stopPropagation(),!f()){p(!0),h=setTimeout(()=>p(!1),3e3);return}h&&(clearTimeout(h),h=null),p(!1);const y=ae();if(!y)return;const T=r.item.id,P=r.item.raw,x=P.room;y.http.game.addObjectIntent("room",x,"destroyStructure",[{id:T,roomName:x,user:P.user}]).then(()=>Dr(T)).catch(C=>Jt("destroyStructure failed:",C))},M=b=>{if(b.stopPropagation(),!a()){c(!0),d=setTimeout(()=>c(!1),3e3);return}d&&(clearTimeout(d),d=null),c(!1);const y=ae();if(!y)return;const T=r.item.id;y.http.game.addObjectIntent(T,r.item.raw.room,"suicide",{}).then(()=>Dr(T)).catch(P=>Jt("suicide failed:",P))};return(()=>{var b=ch(),y=b.firstChild,T=y.firstChild,P=T.nextSibling,x=P.firstChild,C=x.nextSibling,I=C.nextSibling,O=I.nextSibling;O.nextSibling;var G=P.nextSibling;return v(y,k(X,{get when(){return re(()=>!i())()&&!n()},get children(){var R=ah();return A(L=>D(R,"background",e())),R}}),T),v(T,k(X,{get when(){return n()},get fallback(){return re(t)},get children(){return k(ks,{size:12})}}),null),v(T,k(X,{get when(){return re(()=>typeof r.item.raw.name=="string")()&&r.item.raw.name},children:R=>(()=>{var L=dh();return v(L,()=>R()),L})()}),null),v(P,()=>r.item.raw.x,C),v(P,()=>r.item.raw.y,O),v(y,k(X,{get when(){return s()},get children(){var R=Ci();return R.addEventListener("mouseleave",L=>{a()||(L.currentTarget.style.color="#8b949e")}),R.addEventListener("mouseenter",L=>{a()||(L.currentTarget.style.color="#f85149")}),R.$$click=M,v(R,k(Yr,{size:13})),A(L=>{var H=a()?"Click again to confirm suicide":"Suicide",z=a()?"#f85149":"#8b949e";return H!==L.e&&ve(R,"title",L.e=H),z!==L.t&&D(R,"color",L.t=z),L},{e:void 0,t:void 0}),R}}),G),v(y,k(X,{get when(){return o()},get children(){var R=Ci();return R.addEventListener("mouseleave",L=>{f()||(L.currentTarget.style.color="#8b949e")}),R.addEventListener("mouseenter",L=>{f()||(L.currentTarget.style.color="#f85149")}),R.$$click=S,v(R,k(Yr,{size:13})),A(L=>{var H=f()?"Click again to confirm destruction":"Destroy structure",z=f()?"#f85149":"#8b949e";return H!==L.e&&ve(R,"title",L.e=H),z!==L.t&&D(R,"color",L.t=z),L},{e:void 0,t:void 0}),R}}),G),v(y,k(X,{get when(){return n()},get children(){var R=Ci();return R.addEventListener("mouseleave",L=>{u()||(L.currentTarget.style.color="#8b949e")}),R.addEventListener("mouseenter",L=>{u()||(L.currentTarget.style.color="#f85149")}),R.$$click=m,v(R,k(Yr,{size:13})),A(L=>{var H=u()?"Click again to confirm deletion":"Delete flag",z=u()?"#f85149":"#8b949e";return H!==L.e&&ve(R,"title",L.e=H),z!==L.t&&D(R,"color",L.t=z),L},{e:void 0,t:void 0}),R}}),G),G.addEventListener("mouseleave",R=>R.currentTarget.style.color="#8b949e"),G.addEventListener("mouseenter",R=>R.currentTarget.style.color="#fff"),G.$$click=()=>Dr(r.item.id),v(b,k(fs,{get component(){return l()},get item(){return r.item}}),null),A(R=>D(b,"border",`1px solid ${s()&&a()||f()||u()?"#f85149":"#30363d"}`)),b})()}function Th(){return(()=>{var r=uh();return v(r,k(X,{get when(){return ei().length>0},get fallback(){return hh()},get children(){return k(pe,{get each(){return ei()},children:e=>k(Ch,{item:e})})}})),r})()}Se(["click"]);var Mh=E('<div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),Eh=E('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style="padding:4px 8px;background:#161b22;border-radius:6px;border:1px solid #30363d"><div style=font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:4px> Room</div><div style=font-size:13px;font-weight:600;color:#c9d1d9></div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;margin-top:4px;font-size:11px"><div style="padding:3px 0;color:#8b949e">Shard</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Tick</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Tick duration</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Objects</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Owner</div><div style="padding:3px 0;color:#c9d1d9">'),Ph=E('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;display:flex;align-items:center;justify-content:center">');const Rh=[{mode:"view",label:"View",icon:()=>k(ba,{size:14})},{mode:"flag",label:"Flag",icon:()=>k(ks,{size:14})},{mode:"build",label:"Build",icon:()=>k(Sa,{size:14})}];function Oh(r){return(()=>{var e=Eh(),t=e.firstChild,i=t.firstChild,n=i.nextSibling,s=n.nextSibling,o=s.firstChild,l=o.nextSibling,a=l.nextSibling,c=a.nextSibling,d=c.nextSibling,f=d.nextSibling,p=f.nextSibling,h=p.nextSibling,u=h.nextSibling,g=u.nextSibling;return v(n,()=>r.room),v(l,()=>r.shard??"—"),v(c,()=>ut()??"—"),v(f,(()=>{var $=re(()=>!!Zr());return()=>$()?`${Zr()}ms`:"—"})()),v(h,()=>Yd()??"—"),v(g,()=>{var $;return(($=Qs())==null?void 0:$.username)??"—"}),v(e,k(X,{get when(){return!Ke()},get children(){var $=Mh();return v($,k(pe,{each:Rh,children:m=>{const S=()=>Et()===m.mode;return(()=>{var M=Ph();return M.$$click=()=>xt(m.mode),v(M,()=>m.icon()),A(b=>{var y=m.label,T=`1px solid ${S()?"#58a6ff":"#30363d"}`,P=S()?"#1f6feb33":"#161b22",x=S()?"#c9d1d9":"#8b949e";return y!==b.e&&ve(M,"title",b.e=y),T!==b.t&&D(M,"border",b.t=T),P!==b.a&&D(M,"background",b.a=P),x!==b.o&&D(M,"color",b.o=x),b},{e:void 0,t:void 0,a:void 0,o:void 0}),M})()}})),$}}),null),e})()}Se(["click"]);const[Lh,Ah]=N("owner"),ho="screeps-terrain-v1";async function Ih(r,e,t){try{const i=await caches.open(ho),n=`/terrain/${r}_${e}_z${t}.webp`,s=new Request(n),o=await i.match(s);if(o)return await o.blob()}catch{}return null}async function Nh(r,e,t,i){try{const n=await caches.open(ho),s=`/terrain/${r}_${e}_z${t}.webp`,o=new Request(s),l=new Response(i);await n.put(o,l)}catch{}}async function Gh(r){const e=new OffscreenCanvas(r.width,r.height),t=e.getContext("2d");if(!t)throw new Error("OffscreenCanvas 2D context not available");return t.drawImage(r,0,0),await e.convertToBlob({type:"image/webp"})}async function Dh(r){return await createImageBitmap(r)}function zh(r){return new Worker("/assets/terrain.worker-D9zNeJfz.js",{name:r==null?void 0:r.name})}const{warn:Bh}=Pt("MapRenderer"),fo=3,ee=fo*50,Hh=[50,60,70,80,90,100,110],cr=1,bt=.5,zr=50,Fh=2600,Wh=5,Ti=.2,Mi=5,Uh=Mr,Xh=16777215,Yh=St,qh=gr,jh=Es,Vh=vt,Zh=4486980,Kh=8921634,Jh=new Set(["w","r","pb","p","s","c","m","k"]),Qh={H:13421772,O:13421772,U:5809919,L:4176208,K:10711543,Z:13801762,X:16273737},ef=[16,24,32,40];class Op{constructor(e){_(this,"app");_(this,"world");_(this,"boundsGraphics",null);_(this,"selectionGraphics",null);_(this,"safeModeGraphics",null);_(this,"safeModeRooms",new Set);_(this,"activeRooms",new Map);_(this,"roomPool",[]);_(this,"terrainBaked",new Set);_(this,"terrainData",new Map);_(this,"worker");_(this,"pendingBakes",new Map);_(this,"nextBakeId",0);_(this,"currentShard","shard0");_(this,"callbacks");_(this,"resizeObserver",null);_(this,"_destroyed",!1);_(this,"showRoomNames",!1);_(this,"worldBoundsSet",null);_(this,"lastVisibleBounds",null);_(this,"animTargetX",0);_(this,"animTargetY",0);_(this,"isAnimating",!1);_(this,"overlayMode","owner");_(this,"showUnclaimableOverlay",!0);_(this,"isDragging",!1);_(this,"hasDragged",!1);_(this,"dragStartX",0);_(this,"dragStartY",0);_(this,"dragWorldX",0);_(this,"dragWorldY",0);_(this,"isPinching",!1);_(this,"pinchPivotWorldX",0);_(this,"pinchPivotWorldY",0);_(this,"pinchStartDist",0);_(this,"pinchStartScale",0);_(this,"lastVisibleKey","");_(this,"visibleDebounceTimer",null);_(this,"selectedRoom",null);_(this,"currentUserId",null);_(this,"badgeCache",new Rs);_(this,"lastCheckX",0);_(this,"lastCheckY",0);_(this,"lastCheckScale",0);this.app=new cs,this.callbacks=e,this.worker=new zh,this.worker.onmessage=t=>{const{id:i,bitmap:n}=t.data,s=this.pendingBakes.get(i);s&&(this.pendingBakes.delete(i),s.resolve(n))}}async init(e){const t=e.parentElement??e,{width:i,height:n}=t.getBoundingClientRect();await this.app.init({canvas:e,width:i,height:n,background:Oc,antialias:!1,preference:"webgl"}),this.resizeObserver=new ResizeObserver(s=>{const{width:o,height:l}=s[0].contentRect,a=this.app.screen.width,c=this.app.screen.height;this.app.renderer.resize(o,l),this.world.x+=(o-a)/2,this.world.y+=(l-c)/2}),this.resizeObserver.observe(t),this.world=new Re,this.app.stage.addChild(this.world),this.boundsGraphics=new K,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new K,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new K,this.world.addChild(this.safeModeGraphics),this.setupInteraction(),this.app.ticker.add(()=>{if(this.isAnimating){const s=this.animTargetX-this.world.x,o=this.animTargetY-this.world.y;Math.abs(s)<.5&&Math.abs(o)<.5?(this.world.x=this.animTargetX,this.world.y=this.animTargetY,this.isAnimating=!1):(this.world.x+=s*.2,this.world.y+=o*.2)}this.checkVisibleRooms()})}get zoom(){var e;return((e=this.world)==null?void 0:e.scale.x)??1}setZoom(e){if(!this.world||(e=Math.max(Ti,Math.min(Mi,e)),e===this.world.scale.x))return;const t=this.app.screen.width/2,i=this.app.screen.height/2;this.applyZoomAt(e,t,i)}applyZoomAt(e,t,i){var d,f;const n=this.world.scale.x,s=this.getLOD(),o=this.zoom>=cr,l=this.zoom>=bt,a=(t-this.world.x)/n,c=(i-this.world.y)/n;this.world.scale.set(e),this.world.x=t-a*e,this.world.y=i-c*e,this.getLOD()!==s&&this.applyLOD(),(e>=cr!==o||e>=bt!==l)&&this.updateAllNameLabels(),this.updateAllRoomScales(e),(f=(d=this.callbacks).onZoomChanged)==null||f.call(d,e),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(e,t,i=!1){const n=e*ee+ee/2,s=t*ee+ee/2,o=this.world.scale.x,l=this.app.screen.width/2-n*o,a=this.app.screen.height/2-s*o;i?(this.animTargetX=l,this.animTargetY=a,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=l,this.world.y=a)}async getTerrainBitmap(e,t,i){const n=this.currentShard;try{const s=await Ih(n,e,t);if(s)return await Dh(s);const o=this.nextBakeId++,l=new Promise((c,d)=>{this.pendingBakes.set(o,{roomName:e,lod:t,resolve:c,reject:d})});this.worker.postMessage({id:o,roomName:e,lod:t,raw:i});const a=await l;return Gh(a).then(c=>{Nh(n,e,t,c)}).catch(c=>Bh("failed to save to terrainCache:",c)),a}catch{return null}}async setRoomTerrain(e,t){const i=t.raw;let n=!1;for(let c=0;c<i.length;c++)if(i[c]!==0){n=!0;break}if(!n){this.terrainBaked.add(e);return}const s=this.getOrCreate(e),o=this.getLOD();o===0&&this.terrainData.set(e,i);const l=await this.getTerrainBitmap(e,o,i);if(!l)return;if(!this.activeRooms.has(e)){l.close();return}const a=yt.from(l);o===0?(s.texLo&&!s.texLo.destroyed&&(s.terrainSprite.texture===s.texLo&&(s.terrainSprite.texture=yt.EMPTY),s.texLo.destroy(!0)),s.texLo=a,this.getLOD()===0&&(s.terrainSprite.texture=a)):(s.texHi&&!s.texHi.destroyed&&(s.terrainSprite.texture===s.texHi&&(s.terrainSprite.texture=yt.EMPTY),s.texHi.destroy(!0)),s.texHi=a,this.getLOD()===1&&(s.terrainSprite.texture=a)),s.terrainSprite.width=ee,s.terrainSprite.height=ee,this.terrainBaked.add(e)}getLOD(){return this.zoom<cr?0:1}async applyLOD(){const e=this.getLOD()===1,t=[];for(const[i,n]of this.activeRooms)if(this.terrainBaked.has(i))if(e&&!n.texHi){const s=this.terrainData.get(i);s&&(this.terrainData.delete(i),t.push(this.getTerrainBitmap(i,1,s).then(o=>{o&&this.activeRooms.has(i)?(n.texHi=yt.from(o),this.getLOD()===1&&(n.terrainSprite.texture=n.texHi)):o&&o.close()})))}else{const s=e?n.texHi:n.texLo;s&&!s.destroyed&&(n.terrainSprite.texture=s)}await Promise.all(t)}setRoomMap2(e,t,i="live"){const n=this.getOrCreate(e);n.lastMap2Data=t,n.lastMap2Source=i,this.drawMap2(n,t,i)}drawMap2(e,t,i){const n=e.map2Graphics;n.alpha=i==="cache"?.6:1;const s=fo;n.clear();const o=t.r??[];for(const[u,g]of o)n.rect(u*s,g*s,s,s);o.length&&n.fill(pn);const l=t.w??[];for(const[u,g]of l)n.rect(u*s+.5,g*s+.5,s-1,s-1);l.length&&n.fill(e.ownerState==="other"?Kh:Zh);const a=t.s??[];for(const[u,g]of a)n.circle((u+.5)*s,(g+.5)*s,2.5);a.length&&n.fill(Uh);const c=t.c??[];for(const[u,g]of c)n.circle((u+.5)*s,(g+.5)*s,2);c.length&&n.fill(Xh);const d=t.m??[];for(const[u,g]of d)n.circle((u+.5)*s,(g+.5)*s,2);d.length&&n.fill(Yh);const f=t.k??[];for(const[u,g]of f)n.circle((u+.5)*s,(g+.5)*s,2);f.length&&n.fill(qh);const p=t.pb??[];for(const[u,g]of p)n.circle((u+.5)*s,(g+.5)*s,1.5);p.length&&n.fill(gr);const h=t;for(const u in h){if(Jh.has(u))continue;const g=h[u];if(!Array.isArray(g)||g.length===0)continue;for(const[m,S]of g)n.circle((m+.5)*s,(S+.5)*s,1);const $=u===this.currentUserId?jh:Vh;n.fill($)}}clearRoomMap2(e){var t;(t=this.activeRooms.get(e))==null||t.map2Graphics.clear()}clearAllMap2(){for(const e of this.activeRooms.values())e.map2Graphics.clear()}setRoomOwned(e,t){const i=this.activeRooms.get(e);if(!i)return;i.ownerState!==t&&(i.ownerState=t,i.lastMap2Data&&this.drawMap2(i,i.lastMap2Data,i.lastMap2Source??"live"));const n=i.ownerOverlay;n.clear(),t==="other"?(n.rect(0,0,ee,ee),n.fill({color:10027008,alpha:.18})):t==="own"&&(n.rect(0,0,ee,ee),n.fill({color:102,alpha:.35})),n.visible=this.showUnclaimableOverlay}setUnclaimableOverlayVisible(e){if(this.showUnclaimableOverlay!==e){this.showUnclaimableOverlay=e;for(const t of this.activeRooms.values())t.ownerOverlay.visible=e}}async setRoomBadge(e,t,i){const n=this.activeRooms.get(e);if(n){if(!t){n.badgeSprite&&(n.container.removeChild(n.badgeSprite),n.badgeSprite.destroy(),n.badgeSprite=void 0),n.badgeLevel=void 0;return}try{const s=await this.badgeCache.getOrCreate(t);if(!this.activeRooms.has(e))return;if(n.badgeSprite){if(n.badgeSprite.texture===s){n.badgeLevel=i,this.applyBadgeSize(n,this.zoom),this.applyOverlayMode(n);return}n.badgeSprite.texture=s}else{const o=new Zt(s);o.anchor.set(.5),o.x=ee/2,o.y=ee/2;const l=n.container.getChildIndex(n.nameLabel);n.container.addChildAt(o,l),n.badgeSprite=o}n.badgeLevel=i,this.applyBadgeSize(n,this.zoom),this.applyOverlayMode(n)}catch{}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;const n=(Hh[e.badgeLevel-1]??24)*Math.min(1,t);e.badgeSprite.width=n/t,e.badgeSprite.height=n/t}setOverlayMode(e){if(this.overlayMode!==e){this.overlayMode=e;for(const t of this.activeRooms.values())this.applyOverlayMode(t)}}setRoomMineral(e,t,i){const n=this.activeRooms.get(e);if(!n)return;if(!t||!i){n.mineralCircle&&(n.container.removeChild(n.mineralCircle),n.mineralCircle.destroy(),n.mineralCircle=void 0),n.mineralLabel&&(n.container.removeChild(n.mineralLabel),n.mineralLabel.destroy(),n.mineralLabel=void 0),n.mineralDensity=void 0;return}const s=Qh[t]??St;if(n.mineralDensity=i,n.mineralColor=s,!n.mineralCircle){const o=new K;o.x=ee/2,o.y=ee/2;const l=n.container.getChildIndex(n.nameLabel);n.container.addChildAt(o,l),n.mineralCircle=o}if(n.mineralLabel)n.mineralLabel.text=t;else{const o=new qt({text:t,style:{fontSize:36,fill:16777215,fontFamily:"ui-monospace, monospace",fontWeight:"bold"}});o.anchor.set(.5),o.x=ee/2,o.y=ee/2,n.container.addChild(o),n.mineralLabel=o}this.applyMineralSize(n,this.zoom),this.applyOverlayMode(n)}applyOverlayMode(e){e.badgeSprite&&(e.badgeSprite.visible=this.overlayMode==="owner"),e.mineralCircle&&(e.mineralCircle.visible=this.overlayMode==="mineral"),e.mineralLabel&&(e.mineralLabel.visible=this.overlayMode==="mineral")}applyMineralSize(e,t){if(!e.mineralCircle||!e.mineralLabel||e.mineralDensity===void 0||e.mineralColor===void 0)return;const i=Math.max(.5,Math.min(1.5,t)),n=(ef[e.mineralDensity-1]??24)*i,s=n/2/t;e.mineralCircle.clear(),e.mineralCircle.circle(0,0,1),e.mineralCircle.fill(e.mineralColor);const l=2/t;e.mineralCircle.stroke({color:0,width:l/s}),e.mineralCircle.scale.set(s);const c=n*.55/36/t;e.mineralLabel.scale.set(c)}updateNameLabelScale(e,t){const n=.3/Math.sqrt(t),s=12/(36*t);e.nameLabel.scale.set(Math.max(n,s))}updateAllRoomScales(e){for(const t of this.activeRooms.values())this.applyBadgeSize(t,e),this.updateNameLabelScale(t,e),this.applyMineralSize(t,e)}setCurrentUser(e){this.currentUserId=e}setSelectedRoom(e){if(this.selectedRoom=e,!this.selectionGraphics||(this.selectionGraphics.clear(),this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics),!e))return;const t=Qe(e);if(!t)return;const i=t.x*ee,n=t.y*ee;this.selectionGraphics.rect(i,n,ee,ee);const s=Math.max(2,Math.ceil(2/this.zoom));this.selectionGraphics.stroke({color:16777215,width:s,alignment:0})}setRoomSafeMode(e,t){t?this.safeModeRooms.add(e):this.safeModeRooms.delete(e),this.redrawSafeMode()}redrawSafeMode(){if(!this.safeModeGraphics||(this.safeModeGraphics.clear(),this.safeModeRooms.size===0))return;const e=Math.max(1,Math.ceil(1/this.zoom));for(const t of this.safeModeRooms){const i=Qe(t);if(!i)continue;const n=i.x*ee,s=i.y*ee;this.safeModeGraphics.rect(n,s,ee,ee),this.safeModeGraphics.stroke({color:16776960,width:e,alignment:1,alpha:.5})}this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)}setBounds(e,t,i,n){if(!this.boundsGraphics)return;this.worldBoundsSet={minX:e,maxX:t,minY:i,maxY:n},this.boundsGraphics.clear();const s=e*ee,o=i*ee,l=(t-e+1)*ee,a=(n-i+1)*ee;this.boundsGraphics.rect(s,o,l,a),this.boundsGraphics.stroke({color:Ms,width:6,alignment:0}),this.updateAllNameLabels()}clearBounds(){var e;this.worldBoundsSet=null,(e=this.boundsGraphics)==null||e.clear(),this.updateAllNameLabels()}setShowRoomNames(e){this.showRoomNames=e,this.updateAllNameLabels()}hasRoom(e){return this.terrainBaked.has(e)}markRoomFetched(e){this.terrainBaked.add(e)}clearRoom(e){const t=this.activeRooms.get(e);t&&(t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0),t.texLo=null,t.texHi=null,t.terrainSprite.texture=yt.EMPTY,t.map2Graphics.clear(),t.ownerOverlay.clear(),t.badgeSprite&&(t.container.removeChild(t.badgeSprite),t.badgeSprite.destroy(),t.badgeSprite=void 0),t.mineralCircle&&(t.container.removeChild(t.mineralCircle),t.mineralCircle.destroy(),t.mineralCircle=void 0),t.mineralLabel&&(t.container.removeChild(t.mineralLabel),t.mineralLabel.destroy(),t.mineralLabel=void 0),t.mineralDensity=void 0,t.mineralColor=void 0,t.container.visible=!1,this.safeModeRooms.delete(e),this.terrainBaked.delete(e),this.terrainData.delete(e),this.activeRooms.delete(e),this.roomPool.length<Fh?this.roomPool.push(t):(this.world.removeChild(t.container),t.container.destroy({children:!0,context:!0})))}clearInvisibleRooms(e){const t=this.lastVisibleBounds;for(const i of[...this.activeRooms.keys()])if(!e.has(i)){if(t){const n=Qe(i);if(n&&n.x>=t.rxMin-zr&&n.x<=t.rxMax+zr&&n.y>=t.ryMin-zr&&n.y<=t.ryMax+zr)continue}this.clearRoom(i)}}destroy(){var e;if(!this._destroyed){this._destroyed=!0,(e=this.resizeObserver)==null||e.disconnect(),this.resizeObserver=null,this.visibleDebounceTimer!==null&&(clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=null);for(const[,t]of this.activeRooms)t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0);this.activeRooms.clear(),this.safeModeRooms.clear();for(const t of this.roomPool)t.texLo&&!t.texLo.destroyed&&t.texLo.destroy(!0),t.texHi&&!t.texHi.destroyed&&t.texHi.destroy(!0);this.roomPool.length=0,this.terrainBaked.clear(),this.terrainData.clear(),this.worker.terminate(),this.pendingBakes.clear(),this.badgeCache.destroy();try{this.app.destroy(!1,{children:!0,texture:!0,context:!0})}catch{}}}getOrCreate(e){const t=this.activeRooms.get(e);if(t)return t;const i=Qe(e);if(!i)throw new Error(`MapRenderer: invalid room "${e}"`);let n;if(this.roomPool.length>0)n=this.roomPool.pop();else{const s=new Re;s.cullable=!0;const o=new Zt(yt.EMPTY),l=new K,a=new K;s.addChild(o),s.addChild(l),s.addChild(a);const c=new qt({text:"",style:{fontSize:36,fill:9147550,fontFamily:"ui-monospace, monospace"}});c.scale.set(.25),c.x=2,c.y=2,s.addChild(c),this.world.addChild(s),n={container:s,terrainSprite:o,texLo:null,texHi:null,map2Graphics:l,ownerOverlay:a,ownerState:"none",nameLabel:c}}return n.container.x=i.x*ee,n.container.y=i.y*ee,n.container.visible=!0,n.nameLabel.text=e,n.nameLabel.visible=this.showRoomNames&&this.zoom>=bt&&this.nameLabelShouldShow(i.x,i.y),this.updateNameLabelScale(n,this.zoom),n.badgeSprite&&(n.container.removeChild(n.badgeSprite),n.badgeSprite.destroy(),n.badgeSprite=void 0),n.mineralCircle&&(n.container.removeChild(n.mineralCircle),n.mineralCircle.destroy(),n.mineralCircle=void 0),n.mineralLabel&&(n.container.removeChild(n.mineralLabel),n.mineralLabel.destroy(),n.mineralLabel=void 0),n.mineralDensity=void 0,n.mineralColor=void 0,this.safeModeGraphics&&(this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)),this.selectionGraphics&&(this.world.removeChild(this.selectionGraphics),this.world.addChild(this.selectionGraphics)),this.activeRooms.set(e,n),n}nameLabelShouldShow(e,t){const i=this.worldBoundsSet;return!(i&&(e<i.minX||e>i.maxX||t<i.minY||t>i.maxY))}updateAllNameLabels(){const e=this.showRoomNames&&this.zoom>=bt;for(const[t,i]of this.activeRooms){if(!e){i.nameLabel.visible=!1;continue}const n=Qe(t);n&&(i.nameLabel.visible=this.nameLabelShouldShow(n.x,n.y))}}setupInteraction(){const e=this.app.canvas;e.style.touchAction="none",e.style.userSelect="none";const t=new Map;e.addEventListener("pointermove",i=>{var n,s;if(!t.has(i.pointerId)){if(!this.isDragging&&!this.isPinching){const o=e.getBoundingClientRect();this.emitHover(i.clientX-o.left,i.clientY-o.top)}return}if(t.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPinching&&t.size===2){const o=[...t.values()],l=e.getBoundingClientRect(),a=(o[0].x+o[1].x)/2-l.left,c=(o[0].y+o[1].y)/2-l.top,d=Math.hypot(o[1].x-o[0].x,o[1].y-o[0].y),f=Math.max(Ti,Math.min(Mi,this.pinchStartScale*(d/this.pinchStartDist))),p=this.getLOD(),h=this.zoom>=cr,u=this.zoom>=bt;this.world.scale.set(f),this.world.x=a-this.pinchPivotWorldX*f,this.world.y=c-this.pinchPivotWorldY*f,this.getLOD()!==p&&this.applyLOD(),(f>=cr!==h||f>=bt!==u)&&this.updateAllNameLabels(),this.updateAllRoomScales(f),(s=(n=this.callbacks).onZoomChanged)==null||s.call(n,f),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode();return}if(this.isDragging){const o=i.clientX-this.dragStartX,l=i.clientY-this.dragStartY;(Math.abs(o)>3||Math.abs(l)>3)&&(this.hasDragged=!0);const a=this.worldBoundsSet;if(a){const c=this.world.scale.x,d=50,f=d-(a.maxX+1)*ee*c,p=this.app.screen.width-d-a.minX*ee*c,h=d-(a.maxY+1)*ee*c,u=this.app.screen.height-d-a.minY*ee*c;this.world.x=this.rubberBand(this.dragWorldX+o,f,p),this.world.y=this.rubberBand(this.dragWorldY+l,h,u)}else this.world.x=this.dragWorldX+o,this.world.y=this.dragWorldY+l}}),e.addEventListener("pointerleave",()=>{!this.isDragging&&!this.isPinching&&this.callbacks.onRoomHover(null)}),e.addEventListener("pointerdown",i=>{if(i.preventDefault(),this.isAnimating=!1,t.set(i.pointerId,{x:i.clientX,y:i.clientY}),e.setPointerCapture(i.pointerId),t.size>=2){this.isDragging=!1,this.isPinching=!0;const n=[...t.values()],s=e.getBoundingClientRect(),o=(n[0].x+n[1].x)/2-s.left,l=(n[0].y+n[1].y)/2-s.top;this.pinchStartDist=Math.hypot(n[1].x-n[0].x,n[1].y-n[0].y),this.pinchStartScale=this.world.scale.x,this.pinchPivotWorldX=(o-this.world.x)/this.pinchStartScale,this.pinchPivotWorldY=(l-this.world.y)/this.pinchStartScale}else this.isPinching=!1,this.isDragging=!0,this.hasDragged=!1,this.dragStartX=i.clientX,this.dragStartY=i.clientY,this.dragWorldX=this.world.x,this.dragWorldY=this.world.y}),e.addEventListener("pointerup",i=>{if(t.delete(i.pointerId),e.releasePointerCapture(i.pointerId),this.isPinching){t.size<2&&(this.isPinching=!1,this.isDragging=!1,this.springBack());return}if(this.isDragging){if(this.isDragging=!1,!this.hasDragged){const n=e.getBoundingClientRect(),s=this.screenToRoom(i.clientX-n.left,i.clientY-n.top);s&&this.callbacks.onRoomClick(s)}this.springBack()}}),e.addEventListener("pointercancel",i=>{t.delete(i.pointerId),e.releasePointerCapture(i.pointerId),(this.isPinching||this.isDragging)&&(this.isPinching=!1,this.isDragging=!1,this.springBack())}),e.addEventListener("wheel",i=>{if(i.preventDefault(),this.isDragging||this.isPinching)return;this.isAnimating=!1;const n=this.world.scale.x,s=i.deltaY<0?1.1:.9,o=Math.max(Ti,Math.min(Mi,n*s));this.applyZoomAt(o,i.offsetX,i.offsetY)},{passive:!1})}rubberBand(e,t,i){const n=i-t;if(n<=0||e>=t&&e<=i)return e;const s=.55;if(e<t){const l=t-e;return t-(1-1/(l*s/n+1))*n*s}const o=e-i;return i+(1-1/(o*s/n+1))*n*s}springBack(){const e=this.worldBoundsSet;if(!e)return;const t=this.world.scale.x,i=this.app.screen.width,n=this.app.screen.height,s=50,o=this.world.x+e.minX*ee*t,l=this.world.x+(e.maxX+1)*ee*t,a=this.world.y+e.minY*ee*t,c=this.world.y+(e.maxY+1)*ee*t;let d=this.world.x,f=this.world.y;l<s?d+=s-l:o>i-s&&(d-=o-(i-s)),c<s?f+=s-c:a>n-s&&(f-=a-(n-s)),(d!==this.world.x||f!==this.world.y)&&(this.animTargetX=d,this.animTargetY=f,this.isAnimating=!0)}screenToRoom(e,t){const i=this.world.scale.x,n=(e-this.world.x)/i,s=(t-this.world.y)/i,o=Math.floor(n/ee),l=Math.floor(s/ee);return Be(o,l)}emitHover(e,t){this.callbacks.onRoomHover(this.screenToRoom(e,t))}checkVisibleRooms(){const e=this.world.scale.x,t=this.world.x,i=this.world.y;if(this.lastCheckX===t&&this.lastCheckY===i&&this.lastCheckScale===e)return;this.lastCheckX=t,this.lastCheckY=i,this.lastCheckScale=e;const n=-t/e,s=-i/e,o=(this.app.screen.width-t)/e,l=(this.app.screen.height-i)/e,a=Math.floor(n/ee)-1,c=Math.ceil(o/ee),d=Math.floor(s/ee)-1,f=Math.ceil(l/ee);this.lastVisibleBounds={rxMin:a,rxMax:c,ryMin:d,ryMax:f};const p=[],h=this.worldBoundsSet,u=h?Math.max(a,h.minX):a,g=h?Math.min(c,h.maxX):c,$=h?Math.max(d,h.minY):d,m=h?Math.min(f,h.maxY):f;for(let M=u;M<=g;M++)for(let b=$;b<=m;b++){const y=Be(M,b);y&&p.push(y)}const S=`${a},${d},${c},${f}`;S!==this.lastVisibleKey&&(this.lastVisibleKey=S,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(p)},Wh))}}var tf=E('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style="padding:4px 8px;background:#161b22;border-radius:6px;border:1px solid #30363d"><div style=font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:4px>Map</div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;font-size:11px;margin-bottom:8px"><div style="padding:3px 0;color:#8b949e">Zoom</div><div style="padding:3px 0;color:#c9d1d9"></div><div style="padding:3px 0;color:#8b949e">Live</div><div style="padding:3px 0;color:#c9d1d9"></div></div><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px><span>Show room names</span><input type=checkbox></label><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:4px><span>Show unclaimable rooms</span><input type=checkbox></label></div><div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:4px;margin-top:8px">'),rf=E('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const nf=[{mode:"owner",label:"Owner"},{mode:"mineral",label:"Mineral"},{mode:"none",label:"None"}];function sf(r){const e=()=>(r.zoom??1)>=bt;return(()=>{var t=tf(),i=t.firstChild,n=i.firstChild,s=n.nextSibling,o=s.firstChild,l=o.nextSibling,a=l.nextSibling,c=a.nextSibling,d=s.nextSibling,f=d.firstChild,p=f.nextSibling,h=d.nextSibling,u=h.firstChild,g=u.nextSibling,$=i.nextSibling;return v(l,()=>{var m;return((m=r.zoom)==null?void 0:m.toFixed(2))??"—"}),v(c,()=>r.subsActive?"Yes":"No"),p.addEventListener("change",m=>Us(m.currentTarget.checked)),g.addEventListener("change",m=>Ys(m.currentTarget.checked)),v($,k(pe,{each:nf,children:m=>{const S=()=>Lh()===m.mode;return(()=>{var M=rf();return M.$$click=()=>Ah(m.mode),v(M,()=>m.label),A(b=>{var y=`1px solid ${S()?"#58a6ff":"#30363d"}`,T=S()?"#1f6feb33":"#161b22",P=S()?"#c9d1d9":"#8b949e";return y!==b.e&&D(M,"border",b.e=y),T!==b.t&&D(M,"background",b.t=T),P!==b.a&&D(M,"color",b.a=P),b},{e:void 0,t:void 0,a:void 0}),M})()}})),A(m=>{var S=e()?"#c9d1d9":"#484f58",M=e()?"pointer":"default",b=!e();return S!==m.e&&D(d,"color",m.e=S),M!==m.t&&D(d,"cursor",m.t=M),b!==m.a&&(p.disabled=m.a=b),m},{e:void 0,t:void 0,a:void 0}),A(()=>p.checked=Ws()),A(()=>g.checked=Xs()),t})()}Se(["click"]);var of=E('<div style="margin:8px 8px 0;border-radius:6px;overflow:hidden"><div style="padding:4px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:10px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:0.04em">'),lf=E('<div style="padding:6px 8px;font-size:11px;color:#484f58;font-style:italic">None'),af=E('<div style="padding:3px 8px;color:#8b949e">Mineral'),cf=E('<div style="padding:3px 8px;color:#79c0ff">'),df=E('<div style="padding:3px 8px;color:#8b949e">Density'),uf=E('<div style="padding:3px 8px;color:#c9d1d9">'),hf=E('<div style=font-size:11px><div style="padding:5px 8px;font-weight:600;color:#c9d1d9;font-size:12px;border-bottom:1px solid #21262d"></div><div style="display:grid;grid-template-columns:auto 1fr;row-gap:1px;column-gap:0"><div style="padding:3px 8px;color:#8b949e">Owner</div><div style="padding:3px 8px;color:#c9d1d9">');const ff=["Low","Medium","High","Ultra"];function pf(r){return ff[r-1]??String(r)}function Qn(r){return(()=>{var e=of(),t=e.firstChild;return v(t,()=>r.label),v(e,k(X,{get when(){return r.info},get fallback(){return lf()},children:i=>(()=>{var n=hf(),s=n.firstChild,o=s.nextSibling,l=o.firstChild,a=l.nextSibling;return v(s,()=>i().room),v(a,()=>i().owner??"None"),v(o,k(X,{get when(){return i().mineral},get children(){return[af(),(()=>{var c=cf();return v(c,()=>i().mineral),c})(),df(),(()=>{var c=uf();return v(c,()=>pf(i().density??0)),c})()]}}),null),n})()}),null),A(i=>{var n=`1px solid ${r.dim?"#21262d":"#30363d"}`,s=r.dim?.6:1;return n!==i.e&&D(e,"border",i.e=n),s!==i.t&&D(e,"opacity",i.t=s),i},{e:void 0,t:void 0}),e})()}var gf=E("<span style=color:#8b949e;font-size:11px>Checking…"),mf=E('<div style=margin-top:8px><div style="padding:6px 8px;font-size:11px;font-weight:600;color:#c9d1d9;margin-bottom:6px">Your flags'),yf=E('<div style=flex:1;overflow:auto;min-height:0;padding:8px><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Create flag</div><div style=padding:8px;display:flex;flex-direction:column;gap:8px><label>Name<input placeholder="Flag name"style="background:#010409;color:#c9d1d9;border-radius:4px;padding:5px 6px;font-size:12px;outline:none"></label><label>Primary color</label><label>Secondary color</label><div style=color:#484f58;font-size:11px;line-height:1.4>'),vf=E("<span style=color:#f85149;font-size:11px>"),bf=E("<div style=margin-top:8px;color:#484f58;font-style:italic;font-size:12px>No flags."),wf=E('<div style="border-radius:6px;border:1px solid #30363d;margin-bottom:6px;overflow:hidden"><div style="display:flex;align-items:center;gap:7px;padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d"><div style=width:8px;height:8px;border-radius:50%;flex-shrink:0></div><span style=font-size:11px;font-weight:600;color:#c9d1d9;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span><span style=font-size:10px;color:#8b949e;flex-shrink:0></span><span style=font-size:10px;color:#484f58;flex-shrink:0;margin-left:4px>(<!>,<!>)');const{error:xf}=Pt("flag"),dn={};for(const[r,e]of Object.entries(kr))dn[e]=r;function $f(){const r=u=>{oo({...Ht(),...u})},[e,t]=N(null),[i,n]=N(!1);let s=null;he(()=>{if(Et()!=="flag"||Ht().name.trim()!=="")return;const u=ae();u&&u.http.game.genUniqueFlagName().then(g=>{r({name:g.name}),t(null)}).catch(g=>{xf("gen unique name failed:",g)})});const o=u=>{r({name:u}),t(null),s&&clearTimeout(s);const g=u.trim();if(!g){n(!1);return}n(!0),s=setTimeout(()=>{const $=ae();if(!$){n(!1);return}$.http.game.checkUniqueFlagName(g).then(()=>{t(null)}).catch(m=>{t(m.message)}).finally(()=>{n(!1)})},300)},l=()=>kr[Ht().color]??1,a=()=>kr[Ht().secondaryColor]??1,c=u=>{r({color:dn[u]??"COLOR_WHITE"})},d=u=>{r({secondaryColor:dn[u]??"COLOR_WHITE"})},f=()=>{const u=Bl(),g=[];for(const[$,m]of Object.entries(u))m&&typeof m=="object"&&"room"in m&&"x"in m&&"y"in m&&g.push([$,m]);return g},p=u=>u===void 0||u<0||u>=Wt.length?"#8b949e":`#${Wt[u].toString(16).padStart(6,"0")}`,h={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var u=yf(),g=u.firstChild,$=g.firstChild,m=$.nextSibling,S=m.firstChild,M=S.firstChild,b=M.nextSibling,y=S.nextSibling;y.firstChild;var T=y.nextSibling;T.firstChild;var P=T.nextSibling;return b.$$input=x=>o(x.currentTarget.value),v(S,k(X,{get when(){return e()},children:x=>(()=>{var C=vf();return v(C,x),C})()}),null),v(S,k(X,{get when(){return i()},get children(){return gf()}}),null),v(y,k(ii,{get value(){return l()},onChange:c}),null),v(T,k(ii,{get value(){return a()},onChange:d}),null),v(P,(()=>{var x=re(()=>!!Ct());return()=>x()?`Marked at x=${Ct().tx}, y=${Ct().ty}. Click again to create the flag, or click elsewhere to move the mark.`:"Click a position in the room to mark it."})()),v(u,k(X,{get when(){return f().length>0},get fallback(){return bf()},get children(){var x=mf();return x.firstChild,v(x,k(pe,{get each(){return f()},children:([C,I])=>(()=>{var O=wf(),G=O.firstChild,R=G.firstChild,L=R.nextSibling,H=L.nextSibling,z=H.nextSibling,U=z.firstChild,F=U.nextSibling,Y=F.nextSibling,Z=Y.nextSibling;return Z.nextSibling,v(L,C),v(H,()=>I.room),v(z,()=>I.x,F),v(z,()=>I.y,Z),A(W=>D(R,"background",p(I.color))),O})()}),null),x}}),null),A(x=>{var C=h,I=`1px solid ${e()?"#f85149":"#30363d"}`,O=h,G=h;return x.e=V(S,C,x.e),I!==x.t&&D(b,"border",x.t=I),x.a=V(y,O,x.a),x.o=V(T,G,x.o),x},{e:void 0,t:void 0,a:void 0,o:void 0}),A(()=>b.value=Ht().name),u})()}Se(["input"]);var _f=E("<span style=color:#8b949e>…"),Sf=E("<span style=color:#3fb950>✓"),kf=E("<span style=color:#f85149>✗"),Cf=E("<div style=font-size:10px;color:#f85149>"),Tf=E('<div style="margin-top:8px;border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Spawn name</div><div style=padding:8px;display:flex;flex-direction:column;gap:6px><div style=display:flex;gap:6px;align-items:center><input type=text style="flex:1;background:#010409;color:#c9d1d9;border-radius:4px;padding:5px 7px;font-size:12px;outline:none;transition:border-color 150ms ease"><span style=font-size:14px;flex-shrink:0;width:14px;text-align:center>'),Mf=E('<div style=flex:1;overflow:auto;min-height:0;padding:8px><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117;margin-bottom:8px"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Controller Level </div><div style=padding:8px;font-size:11px;color:#8b949e></div></div><div style="border-radius:6px;border:1px solid #30363d;overflow:hidden;background:#0d1117"><div style="padding:6px 8px;background:#161b22;border-bottom:1px solid #21262d;font-size:11px;font-weight:600;color:#c9d1d9">Structures</div></div><div style="margin-top:8px;padding:0 4px"><div style=color:#484f58;font-style:italic;font-size:12px>'),Ef=E('<div style="padding:6px 8px;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid #21262d;font-size:11px;color:#c9d1d9"><span style=text-transform:capitalize></span><span style=color:#8b949e>');function Pf(r){const e=Object.keys(ri),[t,i]=N("idle"),[n,s]=N("");let o=null;const l=(u,g)=>{const $=ri[u];return $?Mt()==="empty"&&u==="spawn"?Math.max($[g]??0,1):$[g]??0:0},a=(u,g)=>{const $=l(u,g);if($===2500)return 1/0;const m=ti()[u]??0;return Math.max(0,$-m)},c=()=>et().structureType==="spawn";he(xo(()=>et().structureType,u=>{if(u!=="spawn")return;const g=ae();g&&(i("loading"),s(""),g.http.game.genUniqueObjectName("spawn",r.shard).then($=>{$t({structureType:"spawn",structureName:$.name}),i("valid")}).catch(()=>{$t({structureType:"spawn",structureName:"Spawn1"}),i("idle")}))}));const d=u=>{if(o&&clearTimeout(o),!u.trim()){i("invalid"),s("Name cannot be empty");return}i("loading"),s(""),o=setTimeout(()=>{const g=ae();g&&g.http.game.checkUniqueObjectName("spawn",u.trim(),r.shard).then($=>{$.error?(i("invalid"),s($.error)):(i("valid"),s(""))}).catch(()=>{i("invalid"),s("Could not validate name")})},400)},f=u=>{$t({structureType:"spawn",structureName:u}),d(u)},p=u=>{$t({structureType:u,structureName:""}),i("idle"),s("")},h=()=>{switch(t()){case"loading":return _f();case"valid":return Sf();case"invalid":return kf();default:return null}};return(()=>{var u=Mf(),g=u.firstChild,$=g.firstChild;$.firstChild;var m=$.nextSibling,S=g.nextSibling;S.firstChild;var M=S.nextSibling,b=M.firstChild;return v($,()=>Yt()??"?",null),v(m,()=>{const y=Mt();return y==="empty"?"World is empty — place a spawn to claim this room.":y==="lost"?"You lost all your spawns — respawn to continue.":Yt()!=null?`RCL ${Yt()} — Select a structure type and click a tile to build.`:"No controller — roads and containers only."}),v(S,k(pe,{each:e,children:y=>{const T=()=>Yt()??0,P=()=>l(y,T()),x=()=>ti()[y]??0,C=()=>et().structureType===y,I=()=>P()===2500,O=()=>!I()&&a(y,T())<=0;return k(X,{get when(){return P()>0},get children(){var G=Ef(),R=G.firstChild,L=R.nextSibling;return G.$$click=()=>!O()&&p(y),v(R,()=>y.replace(/([A-Z])/g," $1").trim(),null),v(R,()=>C()&&" ✓",null),v(L,(()=>{var H=re(()=>!!I());return()=>H()?`${x()}/∞`:`${x()}/${P()}`})(),null),v(L,()=>O()&&" (Max)",null),A(H=>{var z=C()?"#1f3158":"transparent",U=O()?"default":"pointer",F=O()?.5:1;return z!==H.e&&D(G,"background",H.e=z),U!==H.t&&D(G,"cursor",H.t=U),F!==H.a&&D(G,"opacity",H.a=F),H},{e:void 0,t:void 0,a:void 0}),G}})}}),null),v(u,k(X,{get when(){return c()},get children(){var y=Tf(),T=y.firstChild,P=T.nextSibling,x=P.firstChild,C=x.firstChild,I=C.nextSibling;return C.$$input=O=>f(O.currentTarget.value),v(I,h),v(P,k(X,{get when(){return re(()=>t()==="invalid")()&&n()},get children(){var O=Cf();return v(O,n),O}}),null),A(O=>D(C,"border",`1px solid ${t()==="invalid"?"#f85149":t()==="valid"?"#238636":"#30363d"}`)),A(()=>C.value=et().structureName??""),y}}),M),v(b,()=>et().structureType?"Click a tile in the room to build.":"Select a structure type, then click a tile."),u})()}Se(["input","click"]);var Rf=E('<div style=margin-top:8px;display:flex;flex-direction:column;gap:6px><div style=font-size:11px><div></div><div style=font-size:10px;color:#484f58;margin-top:2px>~</div></div><div style=display:flex;gap:3px><button type=button style="flex:1.5;padding:4px;border-radius:4px;border:1px solid #30363d;font-size:11px"></button></div><div style=display:flex;align-items:center;gap:6px><span style=font-size:10px;color:#8b949e;white-space:nowrap>Speed</span><select style="flex:1;background:#161b22;color:#8b949e;border:1px solid #30363d;border-radius:4px;padding:3px 6px;font-size:11px;cursor:pointer">'),Of=E('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><button type=button style="width:100%;padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;display:flex;align-items:center;justify-content:center;gap:4px">'),es=E("<button type=button>"),Lf=E("<option>/s");const Af=[.5,1,2,5,10,20],If=[{delta:-100,label:"-100"},{delta:-10,label:"-10"}],Nf=[{delta:10,label:"+10"},{delta:100,label:"+100"}];function ts(r){return{flex:"1",padding:"4px","border-radius":"4px",border:"1px solid #30363d",background:"#161b22",color:r?"#484f58":"#8b949e",cursor:r?"not-allowed":"pointer","font-size":"11px"}}function Gf(){const r=()=>{const t=$r(),i=kt(),n=Zr()??3e3,s=(t-i)*n;return new Date(Date.now()-s).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})},e=()=>{if(He())Jd();else{const t=ut();t!==null&&Kd(t)}};return(()=>{var t=Of(),i=t.firstChild;return i.$$click=e,v(i,()=>He()?"⏺ History (active)":"⏺ History"),v(t,k(X,{get when(){return He()},get children(){var n=Rf(),s=n.firstChild,o=s.firstChild,l=o.nextSibling;l.firstChild;var a=s.nextSibling,c=a.firstChild,d=a.nextSibling,f=d.firstChild,p=f.nextSibling;return v(o,(()=>{var h=re(()=>!!Ue());return()=>h()?"Loading…":`Tick ${kt()}`})()),v(l,r,null),v(a,k(pe,{each:If,children:h=>(()=>{var u=es();return u.$$click=()=>Un(h.delta),v(u,()=>h.label),A(g=>{var $=Ue(),m=ts(Ue());return $!==g.e&&(u.disabled=g.e=$),g.t=V(u,m,g.t),g},{e:void 0,t:void 0}),u})()}),c),at(c,"click",Qd,!0),v(c,()=>yr()?"⏸":"▶"),v(a,k(pe,{each:Nf,children:h=>(()=>{var u=es();return u.$$click=()=>Un(h.delta),v(u,()=>h.label),A(g=>{var $=Ue(),m=ts(Ue());return $!==g.e&&(u.disabled=g.e=$),g.t=V(u,m,g.t),g},{e:void 0,t:void 0}),u})()}),null),p.addEventListener("change",h=>eu(parseFloat(h.currentTarget.value))),v(p,k(pe,{each:Af,children:h=>(()=>{var u=Lf(),g=u.firstChild;return u.value=h,v(u,h,g),u})()})),A(h=>{var u=Ue()?"#f0883e":"#c9d1d9",g=Ue(),$=yr()?"#1a3a2a":"#161b22",m=yr()?"#3fb950":"#8b949e",S=Ue()?"not-allowed":"pointer";return u!==h.e&&D(o,"color",h.e=u),g!==h.t&&(c.disabled=h.t=g),$!==h.a&&D(c,"background",h.a=$),m!==h.o&&D(c,"color",h.o=m),S!==h.i&&D(c,"cursor",h.i=S),h},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),A(()=>p.value=io()),n}}),null),A(n=>{var s=!He()&&ut()===null,o=`1px solid ${He()?"#58a6ff":"#30363d"}`,l=He()?"#1f6feb33":"#161b22",a=He()?"#c9d1d9":"#8b949e";return s!==n.e&&(i.disabled=n.e=s),o!==n.t&&D(i,"border",n.t=o),l!==n.a&&D(i,"background",n.a=l),a!==n.o&&D(i,"color",n.o=a),n},{e:void 0,t:void 0,a:void 0,o:void 0}),t})()}Se(["click"]);var Df=E("<div style=padding-bottom:8px;overflow:auto;min-height:0>"),zf=E('<div style=display:flex;flex-direction:row;height:100%;background:#0d1117><div style="width:32px;height:100%;display:flex;flex-direction:column;align-items:center;border-right:1px solid #30363d;padding:8px 0;cursor:pointer"></div><div style=flex:1;display:flex;flex-direction:column;overflow:hidden><div style="padding:6px 10px;border-bottom:1px solid #30363d;font-size:12px;font-weight:600;color:#8b949e;display:flex;justify-content:space-between;align-items:center"><span>Properties'),Bf=E("<button style=background:transparent;border:none;color:#8b949e;font-size:14px;cursor:pointer;padding:4px>"),Hf=E("<button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Collapse");function Ff(r){return k(X,{get when(){return Et()==="flag"},get fallback(){return k(X,{get when(){return Et()==="build"},get fallback(){return k(Th,{})},get children(){return k(Pf,{get shard(){return r.shard}})}})},get children(){return k($f,{})}})}function Wf(r){const e=()=>{var i;(i=r.onToggle)==null||i.call(r)},t=i=>{var n;i.stopPropagation(),(n=r.onToggle)==null||n.call(r)};return(()=>{var i=zf(),n=i.firstChild,s=n.nextSibling,o=s.firstChild;return o.firstChild,n.$$click=e,v(n,(()=>{var l=re(()=>!!r.onToggle);return()=>l()&&(()=>{var a=Bf();return a.$$click=t,v(a,()=>r.isCollapsed?"▶":"◀"),a})()})()),v(o,(()=>{var l=re(()=>!!r.onToggle);return()=>l()&&(()=>{var a=Hf();return a.$$click=t,a})()})(),null),v(s,k(X,{get when(){return r.mapMode},get fallback(){return k(Oh,{get room(){return r.room??"—"},get shard(){return r.shard??null}})},get children(){return k(sf,{get zoom(){return r.mapZoom},get subsActive(){return r.mapSubsActive}})}}),null),v(s,k(X,{get when(){return!r.mapMode},get children(){return k(Gf,{})}}),null),v(s,k(X,{get when(){return r.mapMode},get fallback(){return k(Ff,{get shard(){return r.shard}})},get children(){var l=Df();return v(l,k(Qn,{label:"Selected",get info(){return r.selectedRoomInfo??null}}),null),v(l,k(Qn,{label:"Cursor",get info(){return r.hoveredRoomInfo??null},dim:!0}),null),l}}),null),i})()}Se(["click"]);var Uf=E("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>CPU:</span><span style=color:#c9d1d9>"),Xf=E("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Memory:</span><span style=color:#c9d1d9>"),Yf=E("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Zoom:</span><span style=color:#c9d1d9>%"),qf=E("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Subs:</span><span>"),jf=E('<div style="display:flex;gap:16px;padding:6px 16px;font-size:12px;color:#8b949e;align-items:center">');function Vf(r){const[e,t]=N(null);Cr(()=>{const s=ae();if(!s)return;const o=new un;o.add(s.stores.user.subscribe("cpu")),o.add(s.stores.user.on("user:cpu",l=>{t(l)})),Ie(()=>{o.dispose()})});const i=()=>{var l;const s=e();if(!s)return"—";const o=((l=Ae())==null?void 0:l.cpu)??"?";return`${s.cpu.toFixed(1)} / ${o}`},n=()=>{const s=e();return s?`${(s.memory/1024).toFixed(1)} KB`:"—"};return(()=>{var s=jf();return v(s,k(X,{get when(){return e()!==null},get children(){return[(()=>{var o=Uf(),l=o.firstChild,a=l.nextSibling;return v(a,i),o})(),(()=>{var o=Xf(),l=o.firstChild,a=l.nextSibling;return v(a,n),o})()]}}),null),v(s,k(X,{get when(){return re(()=>r.mapZoom!==null)()&&r.mapZoom!==void 0},get children(){return[(()=>{var o=Yf(),l=o.firstChild,a=l.nextSibling,c=a.firstChild;return v(a,()=>(r.mapZoom*100).toFixed(0),c),o})(),(()=>{var o=qf(),l=o.firstChild,a=l.nextSibling;return v(a,()=>r.mapSubsActive===!1?"paused":"active"),A(c=>D(a,"color",r.mapSubsActive===!1?"#e3b341":"#3fb950")),o})()]}}),null),s})()}var Zf=E('<div style=position:fixed;inset:0;background:rgba(0,0,0,0.65);z-index:200;display:flex;align-items:center;justify-content:center><div style="background:#161b22;border:1px solid #30363d;border-radius:10px;width:540px;max-height:90vh;display:flex;flex-direction:column;overflow:hidden"><div style="display:flex;align-items:center;justify-content:space-between;padding:14px 20px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Edit Badge</span><button style="background:transparent;border:none;color:#8b949e;cursor:pointer;line-height:1;padding:2px 6px"></button></div><div style=overflow:auto;flex:1;padding:20px><div style=display:flex;gap:16px;margin-bottom:20px><div style=flex-shrink:0><div style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;font-weight:700>Preview</div><img width=96 height=96 style=display:block></div><div style=flex:1;min-width:0><div style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;font-weight:700>Badge Design</div><div style="display:grid;grid-template-columns:repeat(6, 1fr);gap:4px"></div></div></div><div style=margin-bottom:20px><div style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:8px;font-weight:700>Colors</div><div style=display:flex;gap:6px;margin-bottom:10px></div><div style="display:grid;grid-template-columns:repeat(20, 1fr);gap:2px;margin-bottom:10px"></div><div style=display:flex;align-items:center;gap:8px><div style="width:24px;height:24px;border-radius:4px;border:1px solid rgba(255,255,255,0.2);flex-shrink:0"></div><input type=text maxlength=7 placeholder=#rrggbb style="width:90px;padding:4px 8px;border-radius:4px;background:#0d1117;color:#c9d1d9;font-size:12px;font-family:monospace;outline:none"></div></div><div style=margin-bottom:16px><div style=display:flex;align-items:baseline;gap:8px;margin-bottom:6px><span style=font-size:11px;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;font-weight:700>Variation</span><span style=font-size:12px;color:#c9d1d9></span></div><input type=range min=-100 max=100 style=width:100%;accent-color:#58a6ff></div><label style=display:flex;align-items:center;gap:8px;cursor:pointer;font-size:13px;color:#c9d1d9><input type=checkbox style=accent-color:#58a6ff;width:14px;height:14px>Rotate / Flip</label></div><div style="display:flex;justify-content:flex-end;gap:8px;padding:14px 20px;border-top:1px solid #30363d;flex-shrink:0"><button style="padding:8px 16px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#8b949e;font-size:13px">Cancel</button><button style="padding:8px 16px;border-radius:6px;border:none;background:#238636;color:#fff;font-size:13px;font-weight:600">'),Kf=E("<button style=border-radius:4px;padding:3px;cursor:pointer;display:flex;align-items:center;justify-content:center><img width=48 height=48 style=display:block>"),Jf=E('<button style="display:flex;align-items:center;gap:6px;padding:5px 10px;border-radius:6px;font-size:12px;cursor:pointer"><div style="width:12px;height:12px;border-radius:50%;border:1px solid rgba(255,255,255,0.2);flex-shrink:0">'),Qf=E("<button style=width:100%;aspect-ratio:1;border-radius:2px;cursor:pointer;padding:0;outline:none>");const po={};for(let r=1;r<=24;r++){const e=si({type:r,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1});po[r]=`data:image/svg+xml,${encodeURIComponent(e)}`}function mt(r){var e;return typeof r=="string"?r:((e=fr[r])==null?void 0:e.rgb)??"#000000"}function Br(r){return typeof r=="number"?Math.max(0,Math.min(79,r)):r}const ep=[{slot:1,label:"Background"},{slot:2,label:"Primary"},{slot:3,label:"Secondary"}],tp=Array.from({length:24},(r,e)=>e+1),Ei=/^#[0-9a-f]{6}$/i;function rp(r){const[e,t]=N(xe(()=>typeof r.badge.type=="number"?r.badge.type:1)),[i,n]=N(xe(()=>Br(r.badge.color1))),[s,o]=N(xe(()=>Br(r.badge.color2))),[l,a]=N(xe(()=>Br(r.badge.color3))),[c,d]=N(xe(()=>r.badge.param??0)),[f,p]=N(xe(()=>r.badge.flip??!1)),[h,u]=N(1),[g,$]=N(!1),[m,S]=N(xe(()=>mt(Br(r.badge.color1)))),M=O=>O===1?i():O===2?s():l(),b=O=>{const G=h();G===1?n(O):G===2?o(O):a(O)};he(()=>{S(mt(M(h())))});const y=O=>{var R;const G=M(h());return typeof G=="number"?G===O:G.toLowerCase()===(((R=fr[O])==null?void 0:R.rgb)??"").toLowerCase()},T=()=>({type:e(),color1:mt(i()),color2:mt(s()),color3:mt(l()),param:c(),flip:f()}),P=vr(()=>{const O=si(T());return`data:image/svg+xml,${encodeURIComponent(O)}`}),x=O=>{if(S(O),!Ei.test(O))return;const G=fr.findIndex(R=>R.rgb.toLowerCase()===O.toLowerCase());b(G>=0?G:O)},C=async()=>{var G;const O=ae();if(O){$(!0);try{await O.http.user.badge(T()),await O.stores.user.refreshMe(),r.onClose(),(G=r.onSaved)==null||G.call(r),fe("Badge saved","success",3e3)}catch(R){fe(`Failed to save badge: ${R instanceof Error?R.message:String(R)}`,"error",5e3)}finally{$(!1)}}},I=O=>{O.target===O.currentTarget&&r.onClose()};return(()=>{var O=Zf(),G=O.firstChild,R=G.firstChild,L=R.firstChild,H=L.nextSibling,z=R.nextSibling,U=z.firstChild,F=U.firstChild,Y=F.firstChild,Z=Y.nextSibling,W=F.nextSibling,j=W.firstChild,J=j.nextSibling,Q=U.nextSibling,q=Q.firstChild,ue=q.nextSibling,Oe=ue.nextSibling,rt=Oe.nextSibling,Ne=rt.firstChild,Ge=Ne.nextSibling,it=Q.nextSibling,De=it.firstChild,ie=De.firstChild,Me=ie.nextSibling,pt=De.nextSibling,Pr=it.nextSibling,se=Pr.firstChild,ne=z.nextSibling,ce=ne.firstChild,le=ce.nextSibling;return O.$$click=I,H.$$click=()=>r.onClose(),v(H,k(ai,{size:18})),v(J,k(pe,{each:tp,children:B=>(()=>{var te=Kf(),de=te.firstChild;return te.$$click=()=>t(B),A(ke=>{var we=e()===B?"#1f3a2a":"#0d1117",ze=`1px solid ${e()===B?"#238636":"#21262d"}`,nt=e()===B?P():po[B];return we!==ke.e&&D(te,"background",ke.e=we),ze!==ke.t&&D(te,"border",ke.t=ze),nt!==ke.a&&ve(de,"src",ke.a=nt),ke},{e:void 0,t:void 0,a:void 0}),te})()})),v(ue,k(pe,{each:ep,children:({slot:B,label:te})=>(()=>{var de=Jf(),ke=de.firstChild;return de.$$click=()=>u(B),v(de,te,null),A(we=>{var ze=`1px solid ${h()===B?"#58a6ff":"#30363d"}`,nt=h()===B?"#1c2d47":"transparent",er=h()===B?"#58a6ff":"#8b949e",tr=mt(M(B));return ze!==we.e&&D(de,"border",we.e=ze),nt!==we.t&&D(de,"background",we.t=nt),er!==we.a&&D(de,"color",we.a=er),tr!==we.o&&D(ke,"background",we.o=tr),we},{e:void 0,t:void 0,a:void 0,o:void 0}),de})()})),v(Oe,k(pe,{each:fr,children:B=>(()=>{var te=Qf();return te.$$click=()=>b(B.index),A(de=>{var ke=B.rgb,we=B.rgb,ze=y(B.index)?"2px solid #fff":"1px solid transparent";return ke!==de.e&&ve(te,"title",de.e=ke),we!==de.t&&D(te,"background",de.t=we),ze!==de.a&&D(te,"border",de.a=ze),de},{e:void 0,t:void 0,a:void 0}),te})()})),Ge.$$input=B=>x(B.currentTarget.value),v(Me,c),pt.$$input=B=>d(+B.currentTarget.value),se.addEventListener("change",B=>p(B.currentTarget.checked)),ce.$$click=()=>r.onClose(),le.$$click=C,v(le,()=>g()?"Saving…":"Save Badge"),A(B=>{var te=P(),de=Ei.test(m())?m():mt(M(h())),ke=`1px solid ${Ei.test(m())?"#30363d":"#f85149"}`,we=g(),ze=g()?"not-allowed":"pointer",nt=g(),er=g()?"not-allowed":"pointer",tr=g()?.7:1;return te!==B.e&&ve(Z,"src",B.e=te),de!==B.t&&D(Ne,"background",B.t=de),ke!==B.a&&D(Ge,"border",B.a=ke),we!==B.o&&(ce.disabled=B.o=we),ze!==B.i&&D(ce,"cursor",B.i=ze),nt!==B.n&&(le.disabled=B.n=nt),er!==B.s&&D(le,"cursor",B.s=er),tr!==B.h&&D(le,"opacity",B.h=tr),B},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),A(()=>Ge.value=m()),A(()=>pt.value=c()),A(()=>se.checked=f()),O})()}Se(["click","input"]);var ip=E('<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 0;border-bottom:1px solid #21262d"><div><div style=font-size:13px;color:#c9d1d9></div></div><button style="flex-shrink:0;margin-left:24px;width:40px;height:20px;border-radius:10px;border:none;cursor:pointer;position:relative;transition:background 0.15s"><div style="position:absolute;top:2px;width:16px;height:16px;border-radius:50%;background:#fff;transition:left 0.15s">'),np=E("<div style=font-size:11px;color:#8b949e;margin-top:3px>"),sp=E("<div style=margin-bottom:24px><div style=font-size:10px;font-weight:700;color:#8b949e;text-transform:uppercase;letter-spacing:0.06em;margin-bottom:4px>"),op=E('<div style="display:flex;align-items:center;justify-content:space-between;gap:24px;padding:10px 0;border-bottom:1px solid #21262d"><div style=font-size:13px;color:#c9d1d9></div><div style=font-size:12px;color:#8b949e;text-align:right>'),lp=E("<img width=40 height=40 style=display:block>"),ap=E('<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 0;border-bottom:1px solid #21262d"><div style=display:flex;align-items:center;gap:12px><span style=font-size:13px;color:#c9d1d9></span></div><button style="padding:6px 14px;border-radius:6px;border:1px solid #30363d;background:transparent;color:#c9d1d9;font-size:12px;cursor:pointer;flex-shrink:0">'),cp=E('<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 0;border-bottom:1px solid #21262d"><div><div style=font-size:13px;color:#c9d1d9>Clear all caches</div><div style=font-size:11px;color:#8b949e;margin-top:3px>Deletes IndexedDB, Cache API, and localStorage. Session is kept. Page reloads afterwards.</div></div><button style="flex-shrink:0;margin-left:24px;padding:6px 14px;border-radius:6px;border:1px solid #da3633;background:transparent;font-size:12px">'),dp=E('<div style="position:absolute;inset:0px;background:rgba(13, 17, 23, 0.96);z-index:100;display:flex;flex-direction:column;overflow:hidden"><div style="display:flex;align-items:center;justify-content:space-between;padding:14px 24px;border-bottom:1px solid #30363d;flex-shrink:0"><span style=font-size:15px;font-weight:600;color:#c9d1d9>Settings</span><button style="background:transparent;border:none;color:#8b949e;cursor:pointer;line-height:1;padding:2px 6px"></button></div><div style="overflow:auto;flex:1;padding:20px 24px"><div style=max-width:480px>');const up={type:1,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1};function dr(r){return(()=>{var e=ip(),t=e.firstChild,i=t.firstChild,n=t.nextSibling,s=n.firstChild;return v(i,()=>r.label),v(t,(()=>{var o=re(()=>!!r.description);return()=>o()&&(()=>{var l=np();return v(l,()=>r.description),l})()})(),null),n.$$click=()=>r.onChange(!r.value),A(o=>{var l=r.value?"#238636":"#30363d",a=r.value?"22px":"2px";return l!==o.e&&D(n,"background",o.e=l),a!==o.t&&D(s,"left",o.t=a),o},{e:void 0,t:void 0}),e})()}function Gt(r){return(()=>{var e=sp(),t=e.firstChild;return v(t,()=>r.title),v(e,()=>r.children,null),e})()}function rs(r){return(()=>{var e=op(),t=e.firstChild,i=t.nextSibling;return v(t,()=>r.label),v(i,()=>r.value),e})()}function hp(r){var c;const e=Il(),t=!Ke()&&!((c=Ae())!=null&&c.badge),[i,n]=N(t),[s,o]=N(!1),l=vr(()=>{var p;const d=(p=Ae())==null?void 0:p.badge;if(!d)return null;const f=si(d);return`data:image/svg+xml,${encodeURIComponent(f)}`});async function a(){o(!0);try{await zl(),fe("All caches cleared. Reloading…","success",2e3),setTimeout(()=>window.location.reload(),1500)}catch{fe("Failed to clear caches.","error"),o(!1)}}return(()=>{var d=dp(),f=d.firstChild,p=f.firstChild,h=p.nextSibling,u=f.nextSibling,g=u.firstChild;return h.$$click=()=>r.onClose(),v(h,k(ai,{size:18})),v(d,k(X,{get when(){return i()},get children(){return k(rp,{get badge(){var $;return(($=Ae())==null?void 0:$.badge)??up},onClose:()=>n(!1),onSaved:t?()=>r.onClose():void 0})}}),u),v(g,k(Gt,{title:"Layout",get children(){return k(dr,{label:"Widescreen mode",description:"Sidebar spans full height; console sits below the room view only. When off, the console spans the full width below both the view and the sidebar.",get value(){return Fs()},onChange:Id})}}),null),v(g,k(Gt,{title:"Room View",get children(){return[k(dr,{label:"Show creep labels",description:"Display each creep's name above its sprite.",get value(){return tn()},onChange:Nd}),k(dr,{label:"Terrain effects",description:"Swamp glow and wall noise texture overlay.",get value(){return jr()},onChange:Gd})]}}),null),v(g,k(Gt,{title:"Map View",get children(){return[k(dr,{label:"Show room names",description:"Render a small room name in the top-left corner of each map tile.",get value(){return Ws()},onChange:Us}),k(dr,{label:"Show unclaimable rooms",description:"Highlight rooms where you cannot claim a controller: corridors, sector centres, rooms already owned, and restricted areas.",get value(){return Xs()},onChange:Ys})]}}),null),v(g,k(X,{get when(){return!Ke()},get children(){return k(Gt,{title:"Player Badge",get children(){var $=ap(),m=$.firstChild,S=m.firstChild,M=m.nextSibling;return v(m,k(X,{get when(){return l()},get children(){var b=lp();return A(()=>ve(b,"src",l())),b}}),S),v(S,()=>{var b;return((b=Ae())==null?void 0:b.username)??""}),M.$$click=()=>n(!0),v(M,()=>l()?"Edit Badge":"Create Badge"),$}})}}),null),v(g,k(Gt,{title:"Data",get children(){var $=cp(),m=$.firstChild,S=m.firstChild;S.nextSibling;var M=m.nextSibling;return M.$$click=a,v(M,()=>s()?"Clearing…":"Clear"),A(b=>{var y=s(),T=s()?"#8b949e":"#f85149",P=s()?"default":"pointer",x=s()?.6:1;return y!==b.e&&(M.disabled=b.e=y),T!==b.t&&D(M,"color",b.t=T),P!==b.a&&D(M,"cursor",b.a=P),x!==b.o&&D(M,"opacity",b.o=x),b},{e:void 0,t:void 0,a:void 0,o:void 0}),$}}),null),v(g,k(Gt,{title:"About",get children(){return[k(rs,{label:"Client version",get value(){return Al()}}),re(()=>e&&k(rs,{label:"Mod version",get value(){return`${e.version} (${e.kind})`}}))]}}),null),d})()}Se(["click"]);var fp=E('<button style="padding:7px;border-radius:4px;cursor:pointer;margin:0 4px;display:flex;align-items:center">'),pp=E('<button style="padding:7px;border-radius:4px;border:1px solid #30363d;background:#21262d;margin:0 2px;display:flex;align-items:center">'),gp=E("<div style=flex:1;position:relative;overflow:hidden>"),mp=E('<div style="border-top:1px solid #30363d;overflow:hidden;position:relative"><div style=position:absolute;top:0;left:0;width:100%;height:4px;cursor:row-resize;z-index:10;background:#21262d>'),yp=E('<div style="border-left:1px solid #30363d;overflow:hidden;position:relative"><div style=position:absolute;top:0;left:0;width:4px;height:100%;cursor:col-resize;z-index:10;background:#21262d>'),vp=E("<div style=display:flex;flex:1;overflow:hidden><div style=display:flex;flex-direction:column;flex:1;overflow:hidden>"),bp=E('<div style=width:100%;height:100%;display:flex;flex-direction:column;overflow:hidden;background:#0d1117><div style="display:flex;border-bottom:1px solid #30363d;align-items:center"><div style=flex:1></div><button title=Logout style="padding:7px;border-radius:4px;border:none;background:#da3633;color:#fff;cursor:pointer;margin:0 16px 0 8px;display:flex;align-items:center">'),wp=E("<div style=display:flex;flex-direction:column;flex:1;overflow:hidden><div style=display:flex;flex:1;overflow:hidden>");const xp=as(()=>us(()=>import("./CodePanel-CBhC-97J.js"),__vite__mapDeps([0,1,2])).then(r=>({default:r.CodePanel}))),$p=as(()=>us(()=>import("./MapViewer-TlyktL4n.js"),__vite__mapDeps([3,1,2])).then(r=>({default:r.MapViewer})));function Pi(){const r=li(),e=window.location.pathname.match(new RegExp(`^${r}/room/([A-Za-z0-9]+)`));if(!e)return{room:null,shard:null};const t=e[1].toUpperCase();if(!Qe(t))return{room:null,shard:null};const i=new URLSearchParams(window.location.search).get("shard");return{room:t,shard:i}}function is(r,e){return`${li()}/room/${r}${e?`?shard=${encodeURIComponent(e)}`:""}`}function ns(r){return`${li()}/map${r?`?shard=${encodeURIComponent(r)}`:""}`}function Ri(){return window.location.pathname.startsWith(`${li()}/map`)?{shard:new URLSearchParams(window.location.search).get("shard")}:null}function Oi(r){return(()=>{var e=fp();return e.$$click=()=>r.onClick(),v(e,()=>r.children),A(t=>{var i=r.title,n=`1px solid ${r.active?"#388bfd":"#30363d"}`,s=r.active?"#1f3158":"#21262d",o=r.active?"#58a6ff":"#c9d1d9";return i!==t.e&&ve(e,"title",t.e=i),n!==t.t&&D(e,"border",t.t=n),s!==t.a&&D(e,"background",t.a=s),o!==t.o&&D(e,"color",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function ss(r){return(()=>{var e=pp();return e.$$click=()=>r.onClick(),v(e,()=>r.children),A(t=>{var i=r.title,n=r.disabled,s=r.disabled?"#484f58":"#c9d1d9",o=r.disabled?"default":"pointer";return i!==t.e&&ve(e,"title",t.e=i),n!==t.t&&(e.disabled=t.t=n),s!==t.a&&D(e,"color",t.a=s),o!==t.o&&D(e,"cursor",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function _p(){var Pr;const r=Pi(),[e,t]=N(r.room??fi(ye.room)??"W1N1"),[i,n]=N(r.shard??fi(ye.shard)),[s,o]=N(Ri()!==null||!r.room),[l,a]=N(!Ke()&&!((Pr=Ae())!=null&&Pr.badge)),[c,d]=N(!1),[f,p]=N(!1);he(()=>{c(),p(!0),Promise.resolve().then(()=>p(!1))}),he(()=>{Ke()&&xt("view")});const[h,u]=N(void 0),[g,$]=N(null),[m,S]=N(null),M=fi(ye.mapZoom),[b,y]=N(r.room&&M?Number(M):null),[T,P]=N(null),[x,C]=N(!1),[I,O]=N(!1),[G,R]=N(Rr(ye.sidebarWidth,300)),[L,H]=N(Rr(ye.sidebarWidth,300)),[z,U]=N(Rr(ye.consoleHeight,220)),[F,Y]=N(Rr(ye.consoleHeight,220)),[Z,W]=N(!1),[j,J]=N(!1),Q=()=>G()<=32,q=()=>z()<=32,ue=()=>{G()>32?(H(G()),R(32)):R(L())},Oe=()=>{z()>32?(Y(z()),U(32)):U(F())},rt=se=>{se.preventDefault(),W(!0);const ne=se.clientX,ce=G(),le=te=>{const de=te.clientX-ne;R(Math.max(32,Math.min(500,ce-de)))},B=()=>{W(!1),pi(ye.sidebarWidth,G()),window.removeEventListener("pointermove",le),window.removeEventListener("pointerup",B)};window.addEventListener("pointermove",le),window.addEventListener("pointerup",B)},Ne=se=>{se.preventDefault(),J(!0);const ne=se.clientY,ce=z(),le=te=>{const de=te.clientY-ne;U(Math.max(32,Math.min(500,ce-de)))},B=()=>{J(!1),pi(ye.consoleHeight,z()),window.removeEventListener("pointermove",le),window.removeEventListener("pointerup",B)};window.addEventListener("pointermove",le),window.addEventListener("pointerup",B)},Ge=(se,ne)=>{var ce;(ce=ae())==null||ce.stores.navigation.navigateTo(se,ne)},it=se=>{u(se),o(!0),history.pushState(null,"",ns(i()))},De=()=>{s()?(o(!1),$(null),S(null),history.pushState(null,"",is(e(),i()))):it(e())};Cr(()=>{var le;!Pi().room&&!Ri()&&history.replaceState(null,"",ns(i()));const se=()=>{const B=Ri();if(B){o(!0),B.shard!==null&&n(B.shard);return}const{room:te,shard:de}=Pi();te&&(t(te),n(de),o(!1))};window.addEventListener("popstate",se),Ie(()=>window.removeEventListener("popstate",se));const ne=(le=ae())==null?void 0:le.stores.navigation;if(ne){const B=ne.on("navigation:change",te=>{te.room!==null&&(t(te.room),n(te.shard),o(!1),$(null),S(null),C(ne.canBack()),O(ne.canForward()),Tn(ye.room,te.room),te.shard?Tn(ye.shard,te.shard):Nl(ye.shard),history.pushState(null,"",is(te.room,te.shard)))});Ie(()=>B.dispose())}const ce=B=>{if(!to(B.target)){if(B.key==="o"||B.key==="O"){d(te=>!te),a(!1);return}(B.key==="l"||B.key==="L")&&lo(),(B.key==="c"||B.key==="C")&&ao(),(B.key==="y"||B.key==="Y")&&co(),s()||(B.key==="1"&&xt("view"),Ke()||(B.key==="2"&&xt("flag"),B.key==="3"&&xt("build")),B.key==="m"&&it(e()))}};window.addEventListener("keydown",ce),Ie(()=>window.removeEventListener("keydown",ce))});const ie=()=>(()=>{var se=gp();return v(se,k(X,{get when(){return l()},get children(){return k(hp,{onClose:()=>a(!1)})}}),null),v(se,k(X,{get when(){return c()},get children(){return k(xp,{onClose:()=>d(!1)})}}),null),v(se,k(X,{get when(){return!s()},get fallback(){return k($p,{get shard(){return i()},get originRoom(){return h()},get initialZoom(){return b()??void 0},onNavigateToRoom:ne=>Ge(ne,i()),onHoveredRoomChanged:$,onSelectedRoomChanged:S,onZoomChanged:ne=>{y(ne),pi(ye.mapZoom,ne)},onSubscriptionStateChanged:P})},get children(){return k(pu,{get room(){return e()},get shard(){return i()},onNavigate:Ge})}}),null),se})(),Me=()=>k(X,{get when(){return!Ke()},get children(){var se=mp(),ne=se.firstChild;return ne.$$pointerdown=Ne,v(se,k(Ou,{get shard(){return i()},get isCollapsed(){return q()},onToggle:Oe}),null),A(ce=>{var le=`${z()}px`,B=j()?"none":"height 0.15s ease";return le!==ce.e&&D(se,"height",ce.e=le),B!==ce.t&&D(se,"transition",ce.t=B),ce},{e:void 0,t:void 0}),se}}),pt=se=>(()=>{var ne=yp(),ce=ne.firstChild;return ce.$$pointerdown=rt,v(ne,k(Wf,{get isCollapsed(){return Q()},onToggle:ue,get mapMode(){return s()},get hoveredRoomInfo(){return g()},get selectedRoomInfo(){return m()},get room(){return e()},get shard(){return i()},get mapZoom(){return b()},get mapSubsActive(){return T()}}),null),A(le=>{var B=c()?"0":`${G()}px`,te=se&&!(f()||Z())?"width 0.15s ease":"none";return B!==le.e&&D(ne,"width",le.e=B),te!==le.t&&D(ne,"transition",le.t=te),le},{e:void 0,t:void 0}),ne})();return(()=>{var se=bp(),ne=se.firstChild,ce=ne.firstChild,le=ce.nextSibling;return v(ne,k(Cc,{}),ce),v(ne,k(X,{get when(){return!Ke()||s()},get children(){return k(Vf,{get mapZoom(){return re(()=>!!s())()?b():null},get mapSubsActive(){return re(()=>!!s())()?T():null}})}}),ce),v(ne,k(ss,{title:"Back",get disabled(){return!x()},onClick:()=>{var B;return(B=ae())==null?void 0:B.stores.navigation.back()},get children(){return k(fa,{size:16})}}),le),v(ne,k(ss,{title:"Forward",get disabled(){return!I()},onClick:()=>{var B;return(B=ae())==null?void 0:B.stores.navigation.forward()},get children(){return k(da,{size:16})}}),le),v(ne,k(Oi,{get title(){return s()?"Room View":"Map"},get active(){return s()},onClick:De,get children(){return re(()=>!!s())()?k(Ta,{size:16}):k(La,{size:16})}}),le),v(ne,k(Oi,{title:"Code Editor",get active(){return c()},onClick:()=>{d(B=>!B),a(!1)},get children(){return k(ma,{size:16})}}),le),v(ne,k(Oi,{title:"Settings",get active(){return l()},onClick:()=>{a(B=>!B),d(!1)},get children(){return k(Xa,{size:16})}}),le),at(le,"click",Yl,!0),v(le,k(Pa,{size:16})),v(se,k(X,{get when(){return Fs()},get fallback(){return(()=>{var B=wp(),te=B.firstChild;return v(te,ie,null),v(te,()=>pt(!0),null),v(B,Me,null),B})()},get children(){var B=vp(),te=B.firstChild;return v(te,ie,null),v(te,Me,null),v(B,()=>pt(!1),null),B}}),null),v(se,k(yu,{}),null),se})()}Se(["click","pointerdown"]);var Sp=E("<div style=width:100%;height:100%>");function kp(){const r=new URLSearchParams(window.location.search).get("guest");return r===null?null:r.startsWith("http")?r:Hr(Pe.url)??"https://screeps.com"}function Cp(){const r=()=>_t()==="connected"&&ae()!==null;return Cr(async()=>{if(_t()==="idle"&&(await Xl().catch(()=>{}),_t()!=="connected"&&!oi())){const e=kp();e&&wt({url:e,auth:"guest",storage:null}).catch(()=>{})}}),(()=>{var e=Sp();return v(e,(()=>{var t=re(()=>!!r());return()=>t()?k(_p,{}):k(_c,{})})()),e})()}const go=document.getElementById("root");if(!go)throw new Error("Root element not found");No(()=>k(Cp,{}),go);export{Op as M,fe as a,Pt as b,ae as c,Se as d,Pp as e,Be as f,Rp as g,sn as h,v as i,$s as j,Ws as k,Xs as l,Lh as m,qd as n,Ae as o,Qe as p,D as s,E as t,hr as u,gi as w};