screeps-client 0.3.5 → 0.4.1

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.
Files changed (25) hide show
  1. package/dist/embedded/{assets/CodePanel-DwY4J5sq.js → _client/CodePanel-CQz186KT.js} +1 -1
  2. package/dist/embedded/{assets/MapViewer-DQGXhk2D.js → _client/MapViewer-CvJfxsK0.js} +1 -1
  3. package/dist/embedded/_client/index-RlhG0JKu.js +24 -0
  4. package/dist/embedded/index.html +3 -3
  5. package/dist/standalone/{assets/CodePanel-BXBo2h-F.js → _client/CodePanel-U6dyPwU0.js} +1 -1
  6. package/dist/standalone/{assets/MapViewer-YLclqH-L.js → _client/MapViewer-BlPsc-Ax.js} +1 -1
  7. package/dist/standalone/_client/index-BQrrXAc2.js +24 -0
  8. package/dist/standalone/index.html +3 -3
  9. package/dist/xxscreeps-mod/{assets/CodePanel-CTa3DpMi.js → _client/CodePanel-DFEeWiMS.js} +1 -1
  10. package/dist/xxscreeps-mod/{assets/MapViewer-DhpwVvu_.js → _client/MapViewer-B8jKtgs1.js} +1 -1
  11. package/dist/xxscreeps-mod/_client/index-63TVlkxt.js +24 -0
  12. package/dist/xxscreeps-mod/index.html +3 -3
  13. package/package.json +1 -1
  14. package/dist/embedded/assets/index-CsVFgPW8.js +0 -24
  15. package/dist/standalone/assets/index-DlCmDpPr.js +0 -24
  16. package/dist/xxscreeps-mod/assets/index-C9JapZJr.js +0 -24
  17. /package/dist/embedded/{assets → _client}/terrain.worker-D9zNeJfz.js +0 -0
  18. /package/dist/embedded/{assets → _client}/vendor-codemirror-D3PB7yT8.js +0 -0
  19. /package/dist/embedded/{assets → _client}/vendor-pixi-Do7-_WYv.js +0 -0
  20. /package/dist/standalone/{assets → _client}/terrain.worker-D9zNeJfz.js +0 -0
  21. /package/dist/standalone/{assets → _client}/vendor-codemirror-D3PB7yT8.js +0 -0
  22. /package/dist/standalone/{assets → _client}/vendor-pixi-CXkRT4gi.js +0 -0
  23. /package/dist/xxscreeps-mod/{assets → _client}/terrain.worker-D9zNeJfz.js +0 -0
  24. /package/dist/xxscreeps-mod/{assets → _client}/vendor-codemirror-D3PB7yT8.js +0 -0
  25. /package/dist/xxscreeps-mod/{assets → _client}/vendor-pixi-CXkRT4gi.js +0 -0
@@ -0,0 +1,24 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_client/CodePanel-DFEeWiMS.js","_client/vendor-codemirror-D3PB7yT8.js","_client/vendor-pixi-CXkRT4gi.js","_client/MapViewer-B8jKtgs1.js"])))=>i.map(i=>d[i]);
2
+ var ol=Object.defineProperty;var ll=(r,e,t)=>e in r?ol(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var T=(r,e,t)=>ll(r,typeof e!="symbol"?e+"":e,t);import{k as Oi,j as N,i as Mr,v as As,w as ge,$ as al,u as ke,l as G,p as he,f as _,F as ye,S as W,h as de,r as Pe,D as cl,a as Lt,d as dl,b as Xi,m as Qn,s as Nt,q as ul,o as Is}from"./vendor-codemirror-D3PB7yT8.js";import{_ as Li,a as Oe,G as ee,A as Ns,P as hr,R as Gs,N as hl,S as tr,B as fl,c as _t,T as Qt,b as pl,C as gl}from"./vendor-pixi-CXkRT4gi.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&n(o)}).observe(document,{childList:!0,subtree:!0});function t(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function n(i){if(i.ep)return;i.ep=!0;const s=t(i);fetch(i.href,s)}})();const ml=["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"],yl=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline","adAuctionHeaders","allowFullscreen","browsingTopics","defaultChecked","defaultMuted","defaultSelected","disablePictureInPicture","disableRemotePlayback","preservesPitch","shadowRootClonable","shadowRootCustomElementRegistry","shadowRootDelegatesFocus","shadowRootSerializable","sharedStorageWritable",...ml]),vl=new Set(["innerHTML","textContent","innerText","children"]),bl=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),wl=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 xl(r,e){const t=wl[r];return typeof t=="object"?t[e]?t.$:void 0:t}const _l=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),$l=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"]),Sl={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},J=r=>Mr(()=>r());function kl(r,e,t){let n=t.length,i=e.length,s=n,o=0,l=0,a=e[i-1].nextSibling,c=null;for(;o<i||l<s;){if(e[o]===t[l]){o++,l++;continue}for(;e[i-1]===t[s-1];)i--,s--;if(i===o){const d=s<n?l?t[l-1].nextSibling:t[s-l]:a;for(;l<s;)r.insertBefore(t[l++],d)}else if(s===l)for(;o<i;)(!c||!c.has(e[o]))&&e[o].remove(),o++;else if(e[o]===t[s-1]&&t[l]===e[i-1]){const d=e[--i].nextSibling;r.insertBefore(t[l++],e[o++].nextSibling),r.insertBefore(t[--s],d),e[i]=t[s]}else{if(!c){c=new Map;let h=l;for(;h<s;)c.set(t[h],h++)}const d=c.get(e[o]);if(d!=null)if(l<d&&d<s){let h=o,f=1,u;for(;++h<i&&h<s&&!((u=c.get(e[h]))==null||u!==d+f);)f++;if(f>d-l){const p=e[o];for(;l<d;)r.insertBefore(t[l++],p)}else r.replaceChild(t[l++],e[o++])}else o++;else e[o++].remove()}}}const ji="_$DX_DELEGATE";function Cl(r,e,t,n={}){if(!e)throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");let i;return Oi(s=>{i=s,e===document?r():g(e,r(),e.firstChild?null:void 0,t)},n.owner),()=>{i(),e.textContent=""}}function R(r,e,t,n){let i;const s=()=>{if(mt())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=()=>(i||(i=s())).cloneNode(!0);return o.cloneNode=o,o}function Se(r,e=window.document){const t=e[ji]||(e[ji]=new Set);for(let n=0,i=r.length;n<i;n++){const s=r[n];t.has(s)||(t.add(s),e.addEventListener(s,Al))}}function me(r,e,t){mt(r)||(t==null?r.removeAttribute(e):r.setAttribute(e,t))}function Tl(r,e,t,n){mt(r)||(n==null?r.removeAttributeNS(e,t):r.setAttributeNS(e,t,n))}function Ml(r,e,t){mt(r)||(t?r.setAttribute(e,""):r.removeAttribute(e))}function El(r,e){mt(r)||(e==null?r.removeAttribute("class"):r.className=e)}function Qe(r,e,t,n){if(n)Array.isArray(t)?(r[`$$${e}`]=t[0],r[`$$${e}Data`]=t[1]):r[`$$${e}`]=t;else if(Array.isArray(t)){const i=t[0];r.addEventListener(e,t[0]=s=>i.call(r,t[1],s))}else r.addEventListener(e,t,typeof t!="function"&&t)}function Rl(r,e,t={}){const n=Object.keys(e||{}),i=Object.keys(t);let s,o;for(s=0,o=i.length;s<o;s++){const l=i[s];!l||l==="undefined"||e[l]||(Yi(r,l,!1),delete t[l])}for(s=0,o=n.length;s<o;s++){const l=n[s],a=!!e[l];!l||l==="undefined"||t[l]===a||!a||(Yi(r,l,!0),t[l]=a)}return t}function Y(r,e,t){if(!e)return t?me(r,"style"):e;const n=r.style;if(typeof e=="string")return n.cssText=e;typeof t=="string"&&(n.cssText=t=void 0),t||(t={}),e||(e={});let i,s;for(s in t)e[s]==null&&n.removeProperty(s),delete t[s];for(s in e)i=e[s],i!==t[s]&&(n.setProperty(s,i),t[s]=i);return t}function z(r,e,t){t!=null?r.style.setProperty(e,t):r.style.removeProperty(e)}function Ds(r,e={},t,n){const i={};return n||N(()=>i.children=Er(r,e.children,i.children)),N(()=>typeof e.ref=="function"&&Vt(e.ref,r)),N(()=>Pl(r,e,t,!0,i,!0)),i}function Vt(r,e,t){return ge(()=>r(e,t))}function g(r,e,t,n){if(t!==void 0&&!n&&(n=[]),typeof e!="function")return Er(r,e,n,t);N(i=>Er(r,e(),i,t),n)}function Pl(r,e,t,n,i={},s=!1){e||(e={});for(const o in i)if(!(o in e)){if(o==="children")continue;i[o]=Vi(r,o,null,i[o],t,s,e)}for(const o in e){if(o==="children")continue;const l=e[o];i[o]=Vi(r,o,l,i[o],t,s,e)}}function Ol(r){let e,t,n=mt();if(!n||!(e=ke.registry.get(t=Il()))){if(n)throw ke.done=!0,new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${t}
3
+ `);return r()}return ke.completed&&ke.completed.add(e),ke.registry.delete(t),e}function mt(r){return!!ke.context&&!ke.done&&(!r||r.isConnected)}function Ll(r){return r.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function Yi(r,e,t){const n=e.trim().split(/\s+/);for(let i=0,s=n.length;i<s;i++)r.classList.toggle(n[i],t)}function Vi(r,e,t,n,i,s,o){let l,a,c,d,h;if(e==="style")return Y(r,t,n);if(e==="classList")return Rl(r,t,n);if(t===n)return n;if(e==="ref")s||t(r);else if(e.slice(0,3)==="on:"){const f=e.slice(3);n&&r.removeEventListener(f,n,typeof n!="function"&&n),t&&r.addEventListener(f,t,typeof t!="function"&&t)}else if(e.slice(0,10)==="oncapture:"){const f=e.slice(10);n&&r.removeEventListener(f,n,!0),t&&r.addEventListener(f,t,!0)}else if(e.slice(0,2)==="on"){const f=e.slice(2).toLowerCase(),u=_l.has(f);if(!u&&n){const p=Array.isArray(n)?n[0]:n;r.removeEventListener(f,p)}(u||t)&&(Qe(r,f,t,u),u&&Se([f]))}else if(e.slice(0,5)==="attr:")me(r,e.slice(5),t);else if(e.slice(0,5)==="bool:")Ml(r,e.slice(5),t);else if((h=e.slice(0,5)==="prop:")||(c=vl.has(e))||!i&&((d=xl(e,r.tagName))||(a=yl.has(e)))||(l=r.nodeName.includes("-")||"is"in o)){if(h)e=e.slice(5),a=!0;else if(mt(r))return t;e==="class"||e==="className"?El(r,t):l&&!a&&!c?r[Ll(e)]=t:r[d||e]=t}else{const f=i&&e.indexOf(":")>-1&&Sl[e.split(":")[0]];f?Tl(r,f,e,t):me(r,bl[e]||e,t)}return t}function Al(r){if(ke.registry&&ke.events&&ke.events.find(([a,c])=>c===r))return;let e=r.target;const t=`$$${r.type}`,n=r.target,i=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}}),ke.registry&&!ke.done&&(ke.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===i)break}}else l();s(n)}function Er(r,e,t,n,i){const s=mt(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=n!==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=Gt(r,t,n,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=Gt(r,t,n)}else{if(o==="function")return N(()=>{let a=e();for(;typeof a=="function";)a=a();t=Er(r,a,t,n)}),()=>t;if(Array.isArray(e)){const a=[],c=t&&Array.isArray(t);if(ei(a,e,t,i))return N(()=>t=Er(r,a,t,n,!0)),()=>t;if(s){if(!a.length)return t;if(n===void 0)return t=[...r.childNodes];let d=a[0];if(d.parentNode!==r)return t;const h=[d];for(;(d=d.nextSibling)!==n;)h.push(d);return t=h}if(a.length===0){if(t=Gt(r,t,n),l)return t}else c?t.length===0?qi(r,a,n):kl(r,t,a):(t&&Gt(r),qi(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=Gt(r,t,n,e);Gt(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 ei(r,e,t,n){let i=!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))i=ei(r,l,a)||i;else if(c==="function")if(n){for(;typeof l=="function";)l=l();i=ei(r,Array.isArray(l)?l:[l],Array.isArray(a)?a:[a])||i}else r.push(l),i=!0;else{const d=String(l);a&&a.nodeType===3&&a.data===d?r.push(a):r.push(document.createTextNode(d))}}return i}function qi(r,e,t=null){for(let n=0,i=e.length;n<i;n++)r.insertBefore(e[n],t)}function Gt(r,e,t,n){if(t===void 0)return r.textContent="";const i=n||document.createTextNode("");if(e.length){let s=!1;for(let o=e.length-1;o>=0;o--){const l=e[o];if(i!==l){const a=l.parentNode===r;!s&&!o?a?r.replaceChild(i,l):r.insertBefore(i,t):a&&l.remove()}else s=!0}}else r.insertBefore(i,t);return[i]}function Il(){return ke.getNextContextId()}const Nl="http://www.w3.org/2000/svg";function Gl(r,e=!1,t=void 0){return e?document.createElementNS(Nl,r):document.createElement(r,{is:t})}function Dl(r,e){const t=Mr(r);return Mr(()=>{const n=t();switch(typeof n){case"function":return Object.assign(n,{[al]:!0}),ge(()=>n(e));case"string":const i=$l.has(n),s=ke.context?Ol():Gl(n,i,ge(()=>e.is));return Ds(s,e,i),s}})}function zs(r){const[,e]=As(r,["component"]);return Dl(()=>r.component,e)}async function Bs(r,e){const t=r.slice(3),n=Uint8Array.from(atob(t),o=>o.charCodeAt(0)),i=new Blob([n]).stream().pipeThrough(new DecompressionStream(e)),s=await new Response(i).text();try{return JSON.parse(s)}catch{return s}}function Fs(r){return Bs(r,"gzip")}function Hs(r){return Bs(r,"deflate")}const zl=Object.freeze(Object.defineProperty({__proto__:null,decompressGzip:Fs,decompressZlib:Hs},Symbol.toStringTag,{value:"Module"}));class nt{constructor(e){T(this,"fn");this.fn=e}static create(e){return e===!0?new nt(console.debug.bind(console)):typeof e=="function"?new nt(e):new nt(null)}child(e){if(!this.fn)return this;const t=this.fn;return new nt((...n)=>t(`[screeps:${e}]`,...n))}log(...e){var t;(t=this.fn)==null||t.call(this,...e)}}function Bl(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 Fl(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 Hl(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,n)=>r.request("GET","/api/game/room-overview",$e({room:e,interval:t},n)),time:e=>r.request("GET","/api/game/time",$e({},e)),worldSize:e=>r.request("GET","/api/game/world-size",$e({},e)),mapStats:(e,t,n)=>r.request("POST","/api/game/map-stats",$e({rooms:e,statName:t},n)),roomsTerrain:(e,t)=>{const n=new URLSearchParams({encoded:"true"});return t&&n.set("shard",t),r.request("POST",`/api/game/rooms?${n}`,{rooms:e})},createFlag:(e,t,n,i,s,o,l)=>r.request("POST","/api/game/create-flag",$e({room:e,x:t,y:n,name:i,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,n,i)=>r.request("POST","/api/game/change-flag-color",{room:e,name:t,color:n,secondaryColor:i}),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,n)=>r.request("POST","/api/game/check-unique-object-name",$e({type:e,name:t},n)),placeSpawn:(e,t,n,i,s)=>r.request("POST","/api/game/place-spawn",$e({room:e,x:t,y:n,...i?{name:i}:{}},s)),createConstruction:(e,t,n,i,s,o)=>r.request("POST","/api/game/create-construction",$e({room:e,x:t,y:n,structureType:i,...s?{name:s}:{}},o)),removeConstructionSite:(e,t,n)=>r.request("POST","/api/game/add-object-intent",$e({_id:"room",room:e,name:"removeConstructionSite",intent:t.map(i=>({id:i,roomName:e}))},n)),addObjectIntent:(e,t,n,i,s)=>r.request("POST","/api/game/add-object-intent",$e({_id:e,room:t,name:n,intent:i},s)),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,n,i,s,o)=>r.request("POST","/api/game/create-invader",{room:e,x:t,y:n,size:i,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:Fl(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 Wl(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 Dt(r,e){return e&&(r.shard=e),r}function Ul(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",Dt({path:e},t)),set:(e,t,n)=>r.request("POST","/api/user/memory",Dt({path:e,value:t},n)),segment:{get:(e,t)=>r.request("GET","/api/user/memory-segment",Dt({segment:e},t)),set:(e,t,n)=>r.request("POST","/api/user/memory-segment",Dt({segment:e,data:t},n))}},console:(e,t)=>r.request("POST","/api/user/console",Dt({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",Dt({},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,n)=>r.request("POST","/api/user/clone-branch",{newName:e,...t?{branch:t}:{},...n!=null?{defaultModules:n}:{}}),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:Wl(r)}}function Xl(r){return{list:(e=10,t="world",n=0,i)=>r.request("GET","/api/leaderboard/list",{limit:e,mode:t,offset:n,season:i}),find:(e,t="world",n="")=>r.request("GET","/api/leaderboard/find",{username:e,mode:t,season:n}),seasons:()=>r.request("GET","/api/leaderboard/seasons")}}function jl(r){return{pvp:(e=100)=>r.request("GET","/api/experimental/pvp",{interval:e}),nukes:()=>r.request("GET","/api/experimental/nukes")}}function Yl(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,n,i)=>r.request("POST","/api/register/submit",{username:e,email:t,password:n,...i!=null?{modules:i}:{}})}}class Vl extends EventTarget{constructor(t){super();T(this,"baseUrl");T(this,"authStrategy");T(this,"logger");T(this,"serverPassword");T(this,"token",null);T(this,"rateLimits",new Map);T(this,"authenticating",!1);T(this,"auth");T(this,"register");T(this,"game");T(this,"user");T(this,"leaderboard");T(this,"experimental");this.baseUrl=t.url.endsWith("/")?t.url:`${t.url}/`,this.authStrategy=t.auth,this.logger=t.logger??nt.create(),this.serverPassword=t.serverPassword??null,this.auth=Bl(this),this.register=Yl(this),this.game=Hl(this),this.user=Ul(this),this.leaderboard=Xl(this),this.experimental=jl(this)}emit(t,n){this.dispatchEvent(new CustomEvent(t,{detail:n}))}on(t,n){const i=s=>n(s.detail);return this.addEventListener(t,i),{dispose:()=>{this.removeEventListener(t,i)}}}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,n,i,s=!1){this.logger.log(t,n);const o=new URL(n.startsWith("/")?n.slice(1):n,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"&&i)for(const[f,u]of Object.entries(i))u!=null&&o.searchParams.set(f,String(u));else i&&(l["Content-Type"]="application/json",a.body=JSON.stringify(i));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(n,c),c.status===401&&!s&&!this.authenticating)return await this.authenticate(),this.request(t,n,i,!0);if(!c.ok&&c.status!==304){let f="";try{f=await c.text()}catch{}const u=new Error(`HTTP ${c.status}: ${f}`);throw this.emit("http:error",{method:t,path:n,status:c.status,error:u}),u}this.emit("http:success",{method:t,path:n,status:c.status});const h=await c.json();if(typeof h.error=="string"){const f=new Error(`Screeps API error: ${h.error}`);throw this.emit("http:error",{method:t,path:n,status:c.status,error:f}),f}return typeof h.data=="string"&&h.data.startsWith("gz:")&&(h.data=await Fs(h.data)),h}updateRateLimit(t,n){const i=n.headers.get("x-ratelimit-limit"),s=n.headers.get("x-ratelimit-remaining"),o=n.headers.get("x-ratelimit-reset");i&&s&&o&&this.rateLimits.set(t,{limit:parseInt(i,10),remaining:parseInt(s,10),reset:parseInt(o,10)})}}async function ql(r){let e=typeof r=="string"?r:r.data;if(e.startsWith("gz:")&&(e=JSON.stringify(await Hs(e))),e.startsWith("[")){const[i,s]=JSON.parse(e);return{kind:"channel",message:{channel:i,data:s}}}const[t,...n]=e.split(" ");switch(t){case"auth":return{kind:"server",command:{type:"auth",status:n[0],token:n[1]}};case"time":return{kind:"server",command:{type:"time",time:parseInt(n[0],10)}};case"protocol":return{kind:"server",command:{type:"protocol",protocol:parseInt(n[0],10)}};case"package":return{kind:"server",command:{type:"package",package:parseInt(n[0],10)}};default:throw new Error(`Unknown server command: ${t}`)}}class Zl{constructor(e){T(this,"wsUrl");T(this,"WS");T(this,"logger");T(this,"ws",null);T(this,"token",null);T(this,"authed",!1);T(this,"_connected",!1);T(this,"reconnecting",!1);T(this,"authSub",null);T(this,"queue",[]);T(this,"subs",new Map);T(this,"listeners",new Map);T(this,"MAX_RETRIES",10);T(this,"MAX_DELAY_MS",6e4);T(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??nt.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((n,i)=>{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",{}),n()}else this.logger.log("auth failed"),i(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||i(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 n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),{dispose:()=>{var i;(i=this.listeners.get(e))==null||i.delete(t)}}}once(e,t){const n=this.on(e,i=>{n.dispose(),t(i)});return n}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 n;(n=this.listeners.get(e))==null||n.forEach(i=>{try{i(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 ql(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 n=Math.min(Math.pow(2,e)*100,this.MAX_DELAY_MS);if(this.logger.log(`reconnect attempt ${e+1}/${this.MAX_RETRIES} in ${n}ms`),await new Promise(i=>setTimeout(i,n)),!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 i of this.subs.keys())this.rawSend(`subscribe ${i}`);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 Kl{constructor(e,t){T(this,"memory",new Map);T(this,"storage");T(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,n){this.memory.set(this.memKey(e),{data:t,expires:n!==void 0?Date.now()+n: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 lr extends EventTarget{constructor(t){super();T(this,"logger");this.logger=t??nt.create()}emit(t,n){this.dispatchEvent(new CustomEvent(t,{detail:n}))}on(t,n){this.logger.log(`on "${t}"`);const i=s=>n(s.detail);return this.addEventListener(t,i),{dispose:()=>{this.logger.log(`off "${t}"`),this.removeEventListener(t,i)}}}}var Fe=(r=>(r[r.Plain=0]="Plain",r[r.Wall=1]="Wall",r[r.Swamp=2]="Swamp",r))(Fe||{});class qt{constructor(e){T(this,"raw");this.raw=e}static fromEncodedString(e){const t=new Uint8Array(2500);for(let n=0;n<2500;n++){const i=parseInt(e[n],10);t[n]=i===3?1:i}return new qt(t)}get(e,t){return this.raw[t*50+e]}}class Jl extends lr{constructor(t,n,i,s){super(s);T(this,"http");T(this,"socket");T(this,"cache");T(this,"roomObjects",new Map);T(this,"roomUsers",new Map);T(this,"roomSubCount",new Map);T(this,"lastFlagsString",new Map);this.http=t,this.socket=n,this.cache=i}parseFlagsString(t,n){if(!t||t.length===0)return[];const i=[],s=t.split("|");for(const o of s){const l=o.split("~");if(l.length!==5)continue;const[a,c,d,h,f]=l,u=parseInt(c,10),p=parseInt(d,10),x=parseInt(h,10),M=parseInt(f,10);isNaN(u)||isNaN(p)||isNaN(x)||isNaN(M)||i.push({_id:a,type:"flag",room:n,name:a,x,y:M,color:u,secondaryColor:p})}return i}async terrain(t,n){const i=`terrain/${n}/${t}`,s=this.cache.get(i);if(s)return this.logger.log("terrain",t,n,"(memory cache hit)"),s;const o=await this.cache.getPersistent(i);if(o){this.logger.log("terrain",t,n,"(persistent cache hit)");const d=new qt(o);return this.cache.set(i,d),d}this.logger.log("terrain",t,n,"(fetching)");const a=(await this.http.game.roomTerrain(t,n??void 0)).terrain[0];if(!a)throw new Error(`No terrain data for room ${t} shard ${n}`);const c=qt.fromEncodedString(a.terrain);return this.cache.set(i,c),await this.cache.setPersistent(i,c.raw),this.emit("room:terrainavailable",{room:t,shard:n,terrain:c}),c}async terrainBulk(t,n){const i=new Map,s=[];for(const a of t){const c=this.cache.get(`terrain/${n}/${a}`);c?i.set(a,c):s.push(a)}if(s.length===0)return i;const o=[];if(await Promise.all(s.map(async a=>{const c=`terrain/${n}/${a}`,d=await this.cache.getPersistent(c);if(d){const h=new qt(d);this.cache.set(c,h),i.set(a,h)}else o.push(a)})),o.length===0)return i;this.logger.log("terrainBulk",`fetching ${o.length} rooms`,n);const l=await this.http.game.roomsTerrain(o,n??void 0);return await Promise.all(l.rooms.map(async a=>{const c=qt.fromEncodedString(a.terrain),d=`terrain/${n}/${a.room}`;this.cache.set(d,c),await this.cache.setPersistent(d,c.raw),this.emit("room:terrainavailable",{room:a.room,shard:n,terrain:c}),i.set(a.room,c)})),i}objects(t,n){const i=this.roomObjects.get(`${t}/${n}`);return i?{...i}:null}async fetchObjects(t,n){const i=`${t}/${n}`,s=await this.http.game.roomObjects(t,n??void 0),o={};for(const a of s.objects)a&&typeof a=="object"&&"_id"in a&&(o[a._id]=a);this.roomObjects.set(i,o);const l=this.roomUsers.get(i);this.emit("room:update",{room:t,shard:n,gameTime:void 0,objects:o,diff:o,visual:"",users:l})}activeRooms(){return Array.from(this.roomSubCount.entries()).map(([t,n])=>`${t}(${n})`).join(", ")||"(none)"}subscribe(t,n){const i=`${t}/${n}`,s=this.roomSubCount.get(i)??0;this.roomSubCount.set(i,s+1),this.logger.log("subscribe",t,n,`(refs: ${s+1})`,"active:",this.activeRooms());const o=n?`room:${n}/${t}`:`room:${t}`,l=n?`err@room:${n}/${t}`:`err@room:${t}`,a=this.socket.subscribe(o),c=this.socket.on(l,h=>{const f=typeof h=="string"?h:JSON.stringify(h);this.logger.log("room error",t,n,f),this.emit("room:error",{room:t,shard:n,message:f})}),d=this.socket.on(o,h=>{const f=h,u={...this.roomObjects.get(i)??{}};if(f.objects==null)f.objects===null&&this.logger.log("room update has null objects field",t,n,`gameTime: ${f.gameTime}`);else for(const[M,m]of Object.entries(f.objects))m===null?delete u[M]:u[M]?u[M]={...u[M],...m}:u[M]=m;const p={...f.objects??{}};if("flags"in f){const M=f.flags??"",m=this.lastFlagsString.get(i)??"";if(M!==m){this.lastFlagsString.set(i,M);const k=this.parseFlagsString(M,t),A=new Map;for(const w of k)A.set(w.name,w);for(const w in u){const b=u[w];(b==null?void 0:b.type)==="flag"&&!A.has(w)&&(delete u[w],p[w]=null,this.logger.log(`[flag:room] removed ${w} @ ${t}`))}for(const[w,b]of A){const C=u[w];(!C||C.x!==b.x||C.y!==b.y||C.color!==b.color||C.secondaryColor!==b.secondaryColor)&&(u[w]=b,p[w]=b,this.logger.log(`[flag:room] ${C?"changed":"added"} ${w} @ ${t} (${b.x},${b.y})`))}}}if(f.users){const M=this.roomUsers.get(i)??{};this.roomUsers.set(i,{...M,...f.users})}this.roomObjects.set(i,u);const x=this.roomUsers.get(i);this.emit("room:update",{room:t,shard:n,gameTime:f.gameTime,objects:u,diff:p,visual:f.visual??"",users:x})});return{dispose:()=>{a.dispose(),d.dispose(),c.dispose();const h=(this.roomSubCount.get(i)??1)-1;h<=0?(this.roomSubCount.delete(i),this.roomObjects.delete(i),this.roomUsers.delete(i),this.lastFlagsString.delete(i),this.logger.log("unsubscribe",t,n,"(last ref)","active:",this.activeRooms())):(this.roomSubCount.set(i,h),this.logger.log("unsubscribe",t,n,`(refs: ${h})`,"active:",this.activeRooms()))}}}}class Ql extends lr{constructor(t,n,i,s,o=100){super(s);T(this,"http");T(this,"socket");T(this,"cache");T(this,"console",[]);T(this,"maxConsoleSize");T(this,"_cpu",null);T(this,"_userInfo",null);T(this,"_userId",null);T(this,"_worldStatus",null);T(this,"_mePromise",null);this.http=t,this.socket=n,this.cache=i,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(n=>{const i=n;return this._userId=i._id,this._userInfo=i,this.cache.set("user/me",i,6e4),this.emit("user:me",i),i}).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 n=await this.http.user.worldStatus();return this._worldStatus=n.status,this.cache.set("user/worldStatus",n.status,6e4),this.emit("user:worldStatus",{status:n.status}),n.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 n=null,i=null,s=!1;return(async()=>{try{const l=this._userId??(await this.me())._id;if(s)return;const a=`user:${l}/${t}`;n=this.socket.subscribe(a),i=this.socket.on(a,c=>{var d,h,f;if(t==="cpu")this._cpu=c,this.emit("user:cpu",this._cpu);else if(t==="console"){const u=c,p={log:((d=u.messages)==null?void 0:d.log)??[],results:((h=u.messages)==null?void 0:h.results)??[],error:((f=u.messages)==null?void 0:f.error)??[]};u.error&&p.error.push(u.error),this.console.push(p),this.console.length>this.maxConsoleSize&&this.console.splice(0,this.console.length-this.maxConsoleSize),this.emit("user:console",{messages:p})}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,n==null||n.dispose(),i==null||i.dispose()}}}subscribeMemory(t,n){this.logger.log("subscribe memory",t);let i=null,s=null,o=!1;return(async()=>{try{const a=this._userId??(await this.me())._id;if(o)return;const c=n?`${n}/`:"",d=`user:${a}/memory/${c}${t}`;i=this.socket.subscribe(d),s=this.socket.on(d,h=>{if(typeof h=="string"&&h.startsWith("gz:")){(async()=>{try{const{decompressZlib:u}=await Li(async()=>{const{decompressZlib:x}=await Promise.resolve().then(()=>zl);return{decompressZlib:x}},void 0),p=await u(h);this.emit("user:memory",{path:t,shard:n??null,value:p})}catch(u){this.logger.log("memory decompress failed",u)}})();return}if(h==="[object Object]"){this.logger.log("memory object placeholder",t),this.emit("user:memory",{path:t,shard:n??null,value:{__screeps_object__:!0}});return}let f=h;if(h==="undefined")f=void 0;else if(typeof h=="string")try{f=JSON.parse(h)}catch{}this.logger.log("memory value received",t,f),this.emit("user:memory",{path:t,shard:n??null,value:f})})}catch(a){o||this.dispatchEvent(new ErrorEvent("error",{error:a instanceof Error?a:new Error(String(a))}))}})(),{dispose:()=>{this.logger.log("unsubscribe memory",t),o=!0,i==null||i.dispose(),s==null||s.dispose()}}}subscribeUserStream(){this.logger.log("subscribe user stream");let t=null,n=null,i=!1;return(async()=>{try{const o=this._userId??(await this.me())._id;if(i)return;const l=`user:${o}`;t=this.socket.subscribe(l),n=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[h,f]of Object.entries(d)){const u=f;if(u&&typeof u=="object"){const p=u.room??"unknown",x=u.x??"?",M=u.y??"?";this.logger.log(`[flag:user] ${h} @ ${p} (${x},${M})`)}}}this.emit("user:stream",c)})}catch(o){i||this.dispatchEvent(new ErrorEvent("error",{error:o instanceof Error?o:new Error(String(o))}))}})(),{dispose:()=>{this.logger.log("unsubscribe user stream"),i=!0,t==null||t.dispose(),n==null||n.dispose()}}}}class ea extends lr{constructor(t,n,i,s){super(s);T(this,"http");T(this,"cache");T(this,"socketSubs",[]);T(this,"_version",null);T(this,"_shards",null);this.http=t,this.cache=i,this.socketSubs.push(n.on("connected",()=>{this.emit("server:connected",{})})),this.socketSubs.push(n.on("disconnected",o=>{const l=o;this.emit("server:disconnected",{willReconnect:l.willReconnect})})),this.socketSubs.push(n.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,n;return this._version?(((n=(t=this._version.serverData)==null?void 0:t.shards)==null?void 0:n.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 n=await this.http.request("GET","/api/version");return this._version=n,this.cache.set("server/version",n,5*6e4),this.emit("server:version",n),n}async refreshVersion(){return this.cache.delete("server/version"),this.version()}async shards(){const t=this.cache.get("server/shards");if(t)return t;const n=await this.http.request("GET","/api/game/shards/info");return this._shards=n.shards,this.cache.set("server/shards",n.shards,5*6e4),this.emit("server:shards",n.shards),n.shards}async refreshShards(){return this.cache.delete("server/shards"),this.shards()}async worldInfo(t){const i=`server/world/${t??"default"}`,s=this.cache.get(i);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,h=-1,f=-c,u=-1;try{const M=(await this.http.request("POST","/api/game/map-stats",{rooms:["W0N0","E0N0","W0S0","E0S0"],statName:"owner0",...o})).stats??{},m=["W0N0","E0N0","W0S0","E0S0"].filter(k=>k in M);this.logger.log(`worldInfo corner probe — found: [${m.length?m.join(", "):"none"}]`),("E0N0"in M||"E0S0"in M)&&(d=-Math.ceil(a/2),h=Math.floor(a/2)-1),("W0S0"in M||"E0S0"in M)&&(f=-Math.ceil(c/2),u=Math.floor(c/2)-1)}catch(x){this.logger.log("worldInfo corner probe failed — keeping W/N defaults:",x)}this.logger.log(`worldInfo computed bounds — x: [${d}, ${h}] y: [${f}, ${u}]`);const p={shard:t??null,width:a,height:c,minX:d,maxX:h,minY:f,maxY:u};return this.cache.set(i,p,10*6e4),p}invalidateWorldInfo(t){this.cache.delete(`server/world/${t??"default"}`)}}class ta{constructor(e){T(this,"memory",new Map);T(this,"adapter");T(this,"maxEntries");T(this,"namespace");T(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 n=this.memory.get(this.key(e,t));return n?(n.lastAccess=this.tick(),n.data):null}async get(e,t){const n=this.getMemory(e,t);if(n)return n;if(!this.adapter)return null;const i=this.key(e,t),s=await this.adapter.get(this.adapterKey(i));if(!s)return null;const o=this.deserialize(s);return o?(this.memory.set(i,{data:o.data,lastSeen:o.lastSeen,lastAccess:this.tick()}),o.data):null}async put(e,t,n){const i=this.key(e,t),s={data:n,lastSeen:Date.now(),lastAccess:this.tick()};this.memory.set(i,s),await this.pruneIfNeeded(),this.adapter&&await this.adapter.set(this.adapterKey(i),this.serialize(s))}async pruneIfNeeded(){if(this.memory.size<=this.maxEntries)return;const t=[...this.memory.entries()].sort((n,i)=>n[1].lastAccess-i[1].lastAccess).slice(0,this.memory.size-this.maxEntries);for(const[n]of t)this.memory.delete(n),this.adapter&&await this.adapter.delete(this.adapterKey(n))}}function Zi(r){const e=Object.keys(r).sort(),t={};for(const n of e){const i=r[n];t[n]=i?[...i].sort((s,o)=>s[0]-o[0]||s[1]-o[1]):null}return JSON.stringify(t)}class ra extends lr{constructor(t,n,i={},s){super(s);T(this,"socket");T(this,"storage");T(this,"maxSubscriptions");T(this,"active",new Map);T(this,"waitlist",[]);T(this,"keyStates",new Map);T(this,"warnedAboutWaitlist",!1);this.socket=t,this.storage=n,this.maxSubscriptions=i.maxSubscriptions??500,this.socket.on("connected",()=>this.onReconnect())}map2data(t,n){return this.storage.getMemory(t,n)}subscribeMap2(t,n){const i=`${t}/${n}`,s=this.active.get(i);if(s){s.refCount++,this.logger.log("subscribeMap2",t,n,`(active, refs: ${s.refCount})`);const a=this.getOrCreateKeyState(i,"active");return this.emitWarmStart(t,n),this.makeSubscription(t,n,i,a)}const o=this.waitlist.find(a=>a.key===i);if(o){o.refCount++,this.logger.log("subscribeMap2",t,n,`(pending, refs: ${o.refCount})`);const a=this.getOrCreateKeyState(i,"pending");return this.emitWarmStart(t,n),this.makeSubscription(t,n,i,a)}if(this.active.size<this.maxSubscriptions){this.activateKey(t,n,i,1),this.logger.log("subscribeMap2",t,n,"(new active)");const a=this.getOrCreateKeyState(i,"active");return this.emit("room:map2state",{room:t,shard:n,status:"active"}),this.emitWarmStart(t,n),this.makeSubscription(t,n,i,a)}this.waitlist.push({key:i,room:t,shard:n,refCount:1}),this.logger.log("subscribeMap2",t,n,"(new pending)");const l=this.getOrCreateKeyState(i,"pending");return this.emit("room:map2state",{room:t,shard:n,status:"pending"}),this.emitWarmStart(t,n),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,n,i,l)}activateKey(t,n,i,s){const o=n?`roomMap2:${n}/${t}`:`roomMap2:${t}`,l=this.socket.subscribe(o),a=this.storage.getMemory(t,n),c={room:t,shard:n,refCount:s,socketSub:l,listenerSub:void 0,lastHash:a?Zi(a):null};c.listenerSub=this.socket.on(o,d=>{const h=d,f=Zi(h);c.lastHash!==f&&(c.lastHash=f,this.storage.put(t,n,h),this.emit("room:map2update",{room:t,shard:n,data:h,source:"live"}))}),this.active.set(i,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 n=this.keyStates.get(t.key);n&&(n.status="active",n.statusHandlers.forEach(i=>i("active"))),this.emit("room:map2state",{room:t.room,shard:t.shard,status:"active"})}getOrCreateKeyState(t,n){let i=this.keyStates.get(t);return i||(i={status:n,statusHandlers:new Set},this.keyStates.set(t,i)),i}makeSubscription(t,n,i,s){let o=!1;return{status:()=>s.status,cachedData:()=>this.storage.getMemory(t,n),onStatusChange:l=>(s.statusHandlers.add(l),{dispose:()=>{s.statusHandlers.delete(l)}}),dispose:()=>{o||(o=!0,this.disposeSubscription(t,n,i))}}}disposeSubscription(t,n,i){const s=this.waitlist.findIndex(l=>l.key===i);if(s>=0){const l=this.waitlist[s];l.refCount--,this.logger.log("unsubscribeMap2",t,n,`(pending, refs: ${l.refCount})`),l.refCount<=0&&(this.waitlist.splice(s,1),this.keyStates.delete(i),this.logger.log("unsubscribeMap2",t,n,"(removed from waitlist)"));return}const o=this.active.get(i);o&&(o.refCount--,this.logger.log("unsubscribeMap2",t,n,`(active, refs: ${o.refCount})`),o.refCount<=0&&(o.socketSub.dispose(),o.listenerSub.dispose(),this.active.delete(i),this.keyStates.delete(i),this.logger.log("unsubscribeMap2",t,n,"(deactivated, promoting next)"),this.promoteNext()))}emitWarmStart(t,n){const i=`${t}/${n}`,s=this.storage.getMemory(t,n);s?queueMicrotask(()=>{this.isSubscribed(i)&&this.emit("room:map2update",{room:t,shard:n,data:s,source:"cache"})}):this.storage.get(t,n).then(o=>{o&&this.isSubscribed(i)&&this.emit("room:map2update",{room:t,shard:n,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(n=>n.key===t)}}class na extends lr{constructor(t,n=100,i=500,s){super(s);T(this,"http");T(this,"debounceMs");T(this,"minIntervalMs");T(this,"pending",new Map);T(this,"timer",null);T(this,"lastFlushTime",0);this.http=t,this.debounceMs=n,this.minIntervalMs=i}request(t,n,i){if(t.length===0)return;const s=JSON.stringify([n,i??"shard0"]);let o=this.pending.get(s);o||(o={rooms:new Set,statName:n,shard:i??"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[,n]of t){const i=[...n.rooms];try{const s=await this.http.request("POST","/api/game/map-stats",{rooms:i,statName:n.statName,shard:n.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:n.shard==="shard0"?null:n.shard,stat:c})}for(const l of i)s.stats[l]||this.emit("mapStats:room",{room:l,shard:n.shard==="shard0"?null:n.shard,stat:{}})}catch(s){this.logger.log("mapStats fetch failed:",s)}}}buildData(t,n){var l,a,c;let i,s;for(let d=0;d<3;d++){const h=`minerals${d}`,f=t[h];if(f){i=f.type,s=f.density;break}}const o=(l=t.own)==null?void 0:l.user;return{own:t.own,mineral:i,density:s,username:o?(a=n[o])==null?void 0:a.username:void 0,safeMode:t.safeMode,badge:o?(c=n[o])==null?void 0:c.badge:void 0,status:t.status}}}class ia extends lr{constructor(t=50,n){super(n);T(this,"_history",[]);T(this,"_index",-1);T(this,"maxHistory");this.maxHistory=t}navigateTo(t,n){this._history=this._history.slice(0,this._index+1),this._history.push({room:t,shard:n}),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,n;return{room:((t=this._history[this._index])==null?void 0:t.room)??null,shard:((n=this._history[this._index])==null?void 0:n.shard)??null,index:this._index,history:[...this._history]}}}class sa{constructor(e){T(this,"http");T(this,"socket");T(this,"stores");T(this,"cache");T(this,"logger");T(this,"tokenRefreshIntervalMs");T(this,"tokenSyncSubs",[]);T(this,"tokenRefreshTimer",null);T(this,"lastHttpActivity",0);T(this,"refreshInFlight",!1);var i,s,o;let t;try{t=new URL(e.url).hostname}catch{throw new TypeError(`ScreepsClient: invalid url "${e.url}"`)}this.logger=nt.create(e.debug),this.logger.log(`[screeps:client] init ${e.url}`),this.cache=new Kl(t,e.storage??null),this.http=new Vl({url:e.url,auth:e.auth,logger:this.logger.child("http"),serverPassword:e.serverPassword}),this.socket=new Zl({url:e.url,WebSocket:e.WebSocket,logger:this.logger.child("socket")});const n=new ta({adapter:e.storage??null,namespace:t,maxEntries:((i=e.map2)==null?void 0:i.maxCacheEntries)??1e4});this.stores={room:new Jl(this.http,this.socket,this.cache,this.logger.child("room")),user:new Ql(this.http,this.socket,this.cache,this.logger.child("user")),server:new ea(this.http,this.socket,this.cache,this.logger.child("server")),map:new ra(this.socket,n,{maxSubscriptions:((s=e.map2)==null?void 0:s.maxSubscriptions)??500},this.logger.child("map")),mapStats:new na(this.http,100,500,this.logger.child("mapStats")),navigation:new ia(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 oa{constructor(e){T(this,"token");this.token=e.token}async authenticate(e){return this.token}}class la{constructor(e){T(this,"email");T(this,"password");this.email=e.email,this.password=e.password}async authenticate(e){return(await e.auth.signin(this.email,this.password)).token}}class aa{async authenticate(e){return"guest"}}const ca=1,qe="data";class da{constructor(e){T(this,"namespace");T(this,"db",null);T(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 n=indexedDB.open(this.dbName,ca);n.onupgradeneeded=()=>{n.result.createObjectStore(qe)},n.onsuccess=()=>{this.db=n.result,this.openPromise=null,e(n.result)},n.onerror=()=>t(n.error),n.onblocked=()=>t(new Error(`IndexedDB open blocked: ${this.dbName}`))}),this.openPromise)}async get(e){const t=await this.open();return new Promise((n,i)=>{const o=t.transaction(qe,"readonly").objectStore(qe).get(e);o.onsuccess=()=>n(o.result??null),o.onerror=()=>i(o.error)})}async set(e,t){const n=await this.open();return new Promise((i,s)=>{const l=n.transaction(qe,"readwrite").objectStore(qe).put(t,e);l.onsuccess=()=>i(),l.onerror=()=>s(l.error)})}async delete(e){const t=await this.open();return new Promise((n,i)=>{const o=t.transaction(qe,"readwrite").objectStore(qe).delete(e);o.onsuccess=()=>n(),o.onerror=()=>i(o.error)})}async clear(){const e=await this.open();return new Promise((t,n)=>{const s=e.transaction(qe,"readwrite").objectStore(qe).clear();s.onsuccess=()=>t(),s.onerror=()=>n(s.error)})}}class Ai{constructor(){T(this,"subs",[])}add(e){this.subs.push(e)}dispose(){for(const e of this.subs)e.dispose();this.subs.length=0}}const ua=5*6e4;function Ws(r,e){try{return`screeps:${r}:${new URL(e).hostname}`}catch{return`screeps:${r}:${e}`}}function Us(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 Xs(r,e){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(r,JSON.stringify({data:e,expires:Date.now()+ua}))}catch{}}function Nr(r){return r.endsWith("/")?r:`${r}/`}async function ha(r){const e=Ws("version",r),t=Us(e);if(t)return t;const n=await fetch(`${Nr(r)}api/version`);if(!n.ok)throw new Error(`HTTP ${n.status}`);const i=await n.json();return Xs(e,i),i}async function fa(r){const e=Ws("authmod",r),t=Us(e);if(t)return t;const n=await fetch(`${Nr(r)}api/authmod`);if(!n.ok)return null;const i=await n.json();return i.ok?(Xs(e,i),i):null}async function pa(r,e){const t=new URLSearchParams({username:e}),n=await fetch(`${Nr(r)}api/register/check-username?${t}`);if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}async function ga(r,e){const t=new URLSearchParams({email:e}),n=await fetch(`${Nr(r)}api/register/check-email?${t}`);if(!n.ok)throw new Error(`HTTP ${n.status}`);return n.json()}async function ma(r,e,t,n){const i=await fetch(`${Nr(r)}api/register/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,email:t,password:n})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}function ya(r,e){return r.serverData.features.find(t=>t.name===e)}function js(r){return ya(r,"screepsmod-auth")}const Sn={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,n=Math.PI/2+Math.PI/3,i=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(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)} Z 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)}`},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,n=20,i=80;this.path1=`M ${t-e} 0 H ${t+e} V 100 H ${t-e}`,this.path2=`M ${n-e} 0 H ${n+e} V 100 H ${n-e} Z M ${i-e} 0 H ${i+e} V 100 H ${i-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 n=70;r>0&&(e+=r/100*20),r<0&&(t+=r/100*30),this.path1=`M 50 ${e} L 100 ${e+n} V 101 H 0 V ${e+n} Z`,this.path2=`M 50 ${e+t} L 100 ${e+t+n} V 101 H 0 V ${e+t+n} 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 n=50-50*Math.cos(Math.PI/4),i=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 ${n} ${i} Q ${e} 50 ${n} ${100-i} H 0 V ${i} Z M ${100-n} ${i} Q ${100-e} 50 ${100-n} ${100-i} H 100 V ${i} Z`,this.path2=`M ${n} ${i} Q 50 ${t} ${100-n} ${i} V 0 H ${n} Z M ${n} ${100-i} Q 50 ${100-t} ${100-n} ${100-i} V 100 H ${n} 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,n=45,i=10;this.path1=`M ${50-t-e} ${100+i} A ${t+e} ${t+e} 0 0 1 ${50+t+e} ${100+i} H ${50+t-e} A ${t-e} ${t-e} 0 1 0 ${50-t+e} ${100+i}`,this.path2=`M ${50-n-e} ${100+i} A ${n+e} ${n+e} 0 0 1 ${50+n+e} ${100+i} H ${50+n-e} A ${n-e} ${n-e} 0 1 0 ${50-n+e} ${100+i}`},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 n=0;n<3;n++){const i=n*Math.PI*2/3+e/2-Math.PI/2,s=n*Math.PI*2/3-e/2-Math.PI/2;this.path1+=`M ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} 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(i)} ${50+t*Math.sin(i)} Z`}this.path2="";for(let n=0;n<3;n++){const i=n*Math.PI*2/3+e/2+Math.PI/2,s=n*Math.PI*2/3-e/2+Math.PI/2;this.path2+=`M ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} 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(i)} ${50+t*Math.sin(i)} 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 n=0;n<3;n++){const i=Math.PI*2/3*n+e/2-Math.PI/2,s=Math.PI*2/3*n-e/2-Math.PI/2,o=`M ${50+100*Math.cos(i)} ${50+100*Math.sin(i)} L ${50+100*Math.cos(s)} ${50+100*Math.sin(s)} L ${50+t*Math.cos((i+s)/2)} ${50+t*Math.sin((i+s)/2)} Z`;n?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 n=-4;n<4;n++){const i=(t+n)%2;this.path2+=`M ${50-e-e*2*t} ${50-e-e*2*(n+i)} 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 n=-4;n<=4;n++)this.path1+=`M ${50-e*n*2} ${50-t} l ${-e} ${-t} l ${-e} ${t} l ${e} ${t} Z`;this.path2="";for(let n=-4;n<=4;n++)this.path2+=`M ${50-e*n*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 kn(r){const e=Math.round(r).toString(16);return e.length<2?"0"+e:e}function ct(r,e,t){const n=(1-Math.abs(2*t-1))*e,i=r/60,s=n*(1-Math.abs(i%2-1));let o=0,l=0,a=0;!Number.isNaN(r)&&r!==null&&r!==void 0&&(i>=0&&i<1?(o=n,l=s,a=0):i>=1&&i<2?(o=s,l=n,a=0):i>=2&&i<3?(o=0,l=n,a=s):i>=3&&i<4?(o=0,l=s,a=n):i>=4&&i<5?(o=s,l=0,a=n):i>=5&&i<6&&(o=n,l=0,a=s));const c=t-n/2,d=(o+c)*255,h=(l+c)*255,f=(a+c)*255;return"#"+kn(d)+kn(h)+kn(f)}function va(){const r=[];let e=0;r.push({index:e++,rgb:ct(0,0,.8)});for(let t=0;t<19;t++)r.push({index:e++,rgb:ct(t*360/19,.6,.8)});r.push({index:e++,rgb:ct(0,0,.5)});for(let t=0;t<19;t++)r.push({index:e++,rgb:ct(t*360/19,.7,.5)});r.push({index:e++,rgb:ct(0,0,.3)});for(let t=0;t<19;t++)r.push({index:e++,rgb:ct(t*360/19,.4,.3)});r.push({index:e++,rgb:ct(0,0,.1)});for(let t=0;t<19;t++)r.push({index:e++,rgb:ct(t*360/19,.5,.1)});return r}const $r=va();function Cn(r){if(typeof r=="string")return r;if(typeof r=="number"){const e=$r[r];return e?e.rgb:"#000000"}return"#000000"}function xn(r){const e=Cn(r.color1),t=Cn(r.color2),n=Cn(r.color3),i=r.param??0;if(typeof r.type=="number"){const d=Sn[r.type];d&&d.calc(i)}let s=0;if(r.flip&&typeof r.type=="number"){const d=Sn[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=Sn[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="${n}" 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[ba,Ki]=G([]);let wa=0;function we(r,e="success",t=4e3){const n=wa++;Ki(i=>[...i,{id:n,message:r,type:e,duration:t}]),setTimeout(()=>{Ki(i=>i.filter(s=>s.id!==n))},t)}const xa=!0;function Ii(){return!0}function _a(){return xa}function _n(){return window.location.origin}function $a(){return"0.4.1"}function Sa(){return typeof window>"u"?null:window.__SCREEPS_CLIENT_EMBEDDED__??null}function $n(){return"/".replace(/\/$/,"")}function yt(r){const e=`[${r}]`;return{log:()=>{},warn:()=>{},error:(...t)=>console.error(e,...t)}}const fe={room:"screeps:room",shard:"screeps:shard",sidebarWidth:"screeps:sidebarWidth",consoleHeight:"screeps:consoleHeight",consoleWeights:"screeps:consoleWeights",memoryWatches:"screeps:memoryWatches",mapZoom:"screeps:mapZoom",widescreenMode:"screeps:settings:widescreenMode",showCreepLabels:"screeps:settings:showCreepLabels",showMapRoomNames:"screeps:settings:showMapRoomNames",showUnclaimableRooms:"screeps:settings:showUnclaimableRooms",terrainEffects:"screeps:settings:terrainEffects",showRoomVisuals:"screeps:settings:showRoomVisuals"},Ge={url:"screeps:url",token:"screeps:token",serverPassword:"screeps:serverPassword"};function Tn(r){return localStorage.getItem(r)}function Ji(r,e){localStorage.setItem(r,e)}function ka(r){localStorage.removeItem(r)}function Br(r,e){const t=localStorage.getItem(r);if(t===null)return e;const n=Number(t);return Number.isFinite(n)&&n!==0?n:e}function Mn(r,e){localStorage.setItem(r,String(e))}function Ys(r,e){const t=localStorage.getItem(r);if(t===null)return e;try{return JSON.parse(t)}catch{return e}}function Ni(r,e){localStorage.setItem(r,JSON.stringify(e))}function En(r){return sessionStorage.getItem(r)}function Fr(r,e){sessionStorage.setItem(r,e)}function Sr(r){sessionStorage.removeItem(r)}async function Ca(){if(localStorage.clear(),indexedDB.databases){const r=await indexedDB.databases();await Promise.all(r.map(e=>e.name?new Promise(t=>{const n=indexedDB.deleteDatabase(e.name);n.onsuccess=()=>t(),n.onerror=()=>t(),n.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}=yt("client"),[ae,Kr]=G(null),[Et,Ut]=G("idle"),[Qi,Jr]=G(null),[Re,ti]=G(null),[Gi,ri]=G(null),[Ne,Qr]=G(null),[ln,Vs]=G(null),[Be,qs]=G(!1),[Rn,Zs]=G(null),[Ta,Ks]=G({}),[At,Js]=G(null);let en=-1,ni=-1;const Xt=[],Ma=5;function Ea(r){if(r===void 0)return;const e=Date.now();if(en>=0&&r>en){const t=e-ni;if(t>0){Xt.push(t),Xt.length>Ma&&Xt.shift();const n=Xt.reduce((i,s)=>i+s,0)/Xt.length;Vs(Math.round(n))}}en=r,ni=e}function Ra(){en=-1,ni=-1,Xt.length=0,Vs(null)}const Qs=()=>{var e,t;const r=Gi();return r?(((t=(e=r.serverData)==null?void 0:e.shards)==null?void 0:t.length)??0)===0:null};async function Ct(r){Ii()&&(r={...r,url:_n()}),We(`connecting to ${r.url} (auth: ${r.auth})`),Ut("connecting"),Jr(null);try{let e;if(r.auth==="guest")e=new aa,qs(!0);else if(r.auth==="password"){if(!r.email||!r.password)throw new Error("Email and password are required");e=new la({email:r.email,password:r.password})}else{if(!r.token)throw new Error("Token is required");e=new oa({token:r.token})}const t=new sa({url:r.url,auth:e,storage:r.storage??new da("screeps-client"),debug:!1,serverPassword:r.serverPassword});t.http.on("http:tokenRefresh",({token:n})=>{We("token refreshed"),Fr(Ge.token,n)}),t.http.on("http:error",({method:n,path:i,error:s})=>{We("http error:",n,i,s.message),we(`Request failed: ${n} ${i} — ${s.message}`,"error",6e3)}),t.stores.server.on("server:disconnected",n=>{We(`server disconnected (willReconnect: ${n.willReconnect})`),n.willReconnect||(Ut("idle"),Kr(null),ti(null),ri(null))}),t.stores.server.on("server:error",n=>{We("server error:",n.error.message),Jr(n.error.message),Ut("error")}),t.stores.user.on("user:me",n=>{We(`user: ${n.username} (id: ${n._id})`),ti(n)}),t.stores.server.on("server:version",n=>{We(`server version: ${n.package??"unknown"}`),ri(n)}),t.stores.user.on("user:stream",n=>{if(n&&typeof n=="object"&&"flags"in n){const i=n.flags;i&&typeof i=="object"&&Ks(i)}}),t.stores.user.on("user:worldStatus",({status:n})=>{We(`world status: ${n}`),Js(n)}),await t.connect(),t.stores.user.subscribeUserStream(),Kr(t),Ut("connected"),We(`connected to ${r.url}`),t.stores.server.worldInfo().then(n=>{Zs(n),We(`world: ${n.width}x${n.height} x[${n.minX},${n.maxX}] y[${n.minY},${n.maxY}]`)}).catch(()=>{}),Fr(Ge.url,r.url),t.http.token&&Fr(Ge.token,t.http.token),r.serverPassword?Fr(Ge.serverPassword,r.serverPassword):Sr(Ge.serverPassword)}catch(e){const t=e instanceof Error?e.message:String(e);throw Jr(t),Ut("error"),Kr(null),e}}async function Pa(){const r=Ii()?_n():En(Ge.url),e=En(Ge.token);if(!r||!e)return;const t=En(Ge.serverPassword)??void 0;try{e==="guest"?await Ct({url:r,auth:"guest",storage:null,serverPassword:t}):await Ct({url:r,auth:"token",token:e,serverPassword:t})}catch{Sr(Ge.token)}}function Oa(){const r=ae();r&&r.disconnect(),Kr(null),Ut("idle"),Jr(null),ti(null),ri(null),Qr(null),qs(!1),Zs(null),Ks({}),Js(null),Ra(),Sr(Ge.token),Sr(Ge.url),Sr(Ge.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 La={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"},zt=La,Aa=R("<svg>"),es=r=>r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ia=r=>r.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),Na=r=>{const e=Ia(r);return e.charAt(0).toUpperCase()+e.slice(1)},Ga=(...r)=>r.filter((e,t,n)=>!!e&&e.trim()!==""&&n.indexOf(e)===t).join(" ").trim(),Da=r=>{const[e,t]=As(r,["color","size","strokeWidth","children","class","name","iconNode","absoluteStrokeWidth"]);return(()=>{var n=Aa();return Ds(n,he(zt,{get width(){return e.size??zt.width},get height(){return e.size??zt.height},get stroke(){return e.color??zt.stroke},get"stroke-width"(){return J(()=>!!e.absoluteStrokeWidth)()?Number(e.strokeWidth??zt["stroke-width"])*24/Number(e.size):Number(e.strokeWidth??zt["stroke-width"])},get class(){return Ga("lucide","lucide-icon",...e.name!=null?[`lucide-${es(Na(e.name))}`,`lucide-${es(e.name)}`]:[],e.class!=null?e.class:"")}},t),!0,!0),g(n,_(ye,{get each(){return e.iconNode},children:([i,s])=>_(zs,he({component:i},s))})),n})()},pe=Da,za=[["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"}]],Ba=r=>_(pe,he(r,{iconNode:za,name:"bell-off"})),Fa=Ba,Ha=[["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"}]],Wa=r=>_(pe,he(r,{iconNode:Ha,name:"bell"})),Ua=Wa,Xa=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],ja=r=>_(pe,he(r,{iconNode:Xa,name:"check"})),eo=ja,Ya=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Va=r=>_(pe,he(r,{iconNode:Ya,name:"chevron-down"})),qa=Va,Za=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Ka=r=>_(pe,he(r,{iconNode:Za,name:"chevron-right"})),to=Ka,Ja=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Qa=r=>_(pe,he(r,{iconNode:Ja,name:"chevron-left"})),ec=Qa,tc=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]],rc=r=>_(pe,he(r,{iconNode:tc,name:"clock"})),nc=rc,ic=[["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"}]],sc=r=>_(pe,he(r,{iconNode:ic,name:"code-xml"})),oc=sc,lc=[["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"}]],ac=r=>_(pe,he(r,{iconNode:lc,name:"eye"})),ro=ac,cc=[["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"}]],dc=r=>_(pe,he(r,{iconNode:cc,name:"flag"})),no=dc,uc=[["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"}]],hc=r=>_(pe,he(r,{iconNode:uc,name:"hammer"})),fc=hc,pc=[["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"}]],gc=r=>_(pe,he(r,{iconNode:pc,name:"layout-grid"})),mc=gc,yc=[["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m16.2 7.8 2.9-2.9",key:"r700ao"}],["path",{d:"M18 12h4",key:"wj9ykh"}],["path",{d:"m16.2 16.2 2.9 2.9",key:"1bxg5t"}],["path",{d:"M12 18v4",key:"jadmvz"}],["path",{d:"m4.9 19.1 2.9-2.9",key:"bwix9q"}],["path",{d:"M2 12h4",key:"j09sii"}],["path",{d:"m4.9 4.9 2.9 2.9",key:"giyufr"}]],vc=r=>_(pe,he(r,{iconNode:yc,name:"loader"})),bc=vc,wc=[["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"}]],xc=r=>_(pe,he(r,{iconNode:wc,name:"log-out"})),_c=xc,$c=[["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"}]],Sc=r=>_(pe,he(r,{iconNode:$c,name:"map"})),kc=Sc,Cc=[["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"}]],Tc=r=>_(pe,he(r,{iconNode:Cc,name:"move"})),Mc=Tc,Ec=[["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"}]],Rc=r=>_(pe,he(r,{iconNode:Ec,name:"pause"})),Pc=Rc,Oc=[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]],Lc=r=>_(pe,he(r,{iconNode:Oc,name:"play"})),Ac=Lc,Ic=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Nc=r=>_(pe,he(r,{iconNode:Ic,name:"plus"})),Gc=Nc,Dc=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],zc=r=>_(pe,he(r,{iconNode:Dc,name:"refresh-cw"})),Bc=zc,Fc=[["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"}]],Hc=r=>_(pe,he(r,{iconNode:Fc,name:"settings"})),Wc=Hc,Uc=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],Xc=r=>_(pe,he(r,{iconNode:Uc,name:"terminal"})),jc=Xc,Yc=[["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"}]],Vc=r=>_(pe,he(r,{iconNode:Yc,name:"trash-2"})),tn=Vc,qc=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Zc=r=>_(pe,he(r,{iconNode:qc,name:"x"})),It=Zc,Kc=R("<span style=font-size:11px;display:inline-flex;align-items:center;gap:3px>"),Jc=R('<div style="color:#3fb950;font-size:14px;text-align:center;padding:8px 0">Account created! Logging you in…'),Qc=R("<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>"),ed=R("<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>"),td=R("<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>"),rd=R("<span style=font-size:11px;color:#f85149>Passwords don't match"),nd=R("<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>"),id=R("<button type=submit style=padding:10px;border-radius:6px;border:none;background:#238636;color:#fff;font-weight:600>"),sd=R('<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'),od=R("<form style=display:flex;flex-direction:column;gap:16px><h2 style=margin:0;font-size:20px>Create Account"),io=R("<div style=color:#f85149;font-size:13px>"),ld=R('<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">'),ad=R("<button type=button style=background:none;border:none;color:#58a6ff;font-size:12px;cursor:pointer;padding:0>Create account"),cd=R('<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'),dd=R("<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>"),ud=R("<div style=color:#8b949e;font-size:12px;margin-top:-8px>"),hd=R("<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>"),fd=R("<button type=button style=padding:10px;border-radius:6px;border:none;background:#1b2838;color:#c7d5e0;font-weight:600>Login with Steam"),pd=R('<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)'),gd=R('<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>'),md=R('<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>'),yd=R('<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">'),vd=R("<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>"),bd=R("<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>"),wd=R("<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>"),xd=R('<span style="font-size:11px;padding:2px 8px;border-radius:12px;background:#21262d;border:1px solid #30363d;color:#8b949e;font-family:monospace">');const et={padding:"8px 12px","border-radius":"6px",border:"1px solid #30363d",background:"#0d1117",color:"#c9d1d9"};function _d(r){const[e,t]=G(null),[n,i]=G(null),[s,o]=G(null);return de(()=>{const l=r();t(null),i(null),o(null);let a=!1;const c=setTimeout(async()=>{try{const d=await ha(l);if(a)return;if(t(d),o(null),js(d)){const h=await fa(l);a||i(h)}}catch{a||(o("Could not reach server"),t(null))}},400);Pe(()=>{a=!0,clearTimeout(c)})}),{serverVersion:e,authModInfo:n,serverError:s}}function ts(r,e,t){const[n,i]=G("idle");return de(()=>{const s=e();if(!s){i("idle");return}i("checking");let o=!1;const l=setTimeout(async()=>{try{const a=await t(r(),s);o||i(a.error?"taken":"available")}catch{o||i("error")}},500);Pe(()=>{o=!0,clearTimeout(l)})}),n}function rs(r){const e={idle:null,checking:{children:"Checking…",color:"#8b949e"},available:{children:[_(eo,{size:12})," Available"],color:"#3fb950"},taken:{children:[_(It,{size:12})," Already taken"],color:"#f85149"},error:{children:"Could not verify",color:"#d29922"}},t=()=>e[r.state];return _(W,{get when(){return t()},get children(){var n=Kc();return g(n,()=>t().children),N(i=>z(n,"color",t().color)),n}})}function $d(r){const[e,t]=G(""),[n,i]=G(""),[s,o]=G(""),[l,a]=G(""),[c,d]=G(!1),[h,f]=G(null),[u,p]=G(!1),x=ts(()=>r.url,e,pa),M=ts(()=>r.url,n,ga),m=()=>l()!==""&&s()!==l(),k=()=>!c()&&e()!==""&&n()!==""&&s().length>=4&&s()===l()&&x()!=="taken"&&x()!=="checking"&&M()!=="taken"&&M()!=="checking",A=async w=>{if(w.preventDefault(),!!k()){d(!0),f(null);try{const b=await ma(r.url,e(),n(),s());if(b.error){f(b.error);return}p(!0),setTimeout(()=>r.onSuccess(n(),s()),1500)}catch(b){f(b instanceof Error?b.message:"Registration failed")}finally{d(!1)}}};return(()=>{var w=od();return w.firstChild,w.addEventListener("submit",A),g(w,_(W,{get when(){return u()},get children(){return Jc()}}),null),g(w,_(W,{get when(){return!u()},get children(){return[(()=>{var b=Qc(),C=b.firstChild;C.firstChild;var P=C.nextSibling;return g(C,_(rs,{get state(){return x()}}),null),P.$$input=y=>t(y.currentTarget.value),N(y=>{var S=et,O=c();return y.e=Y(P,S,y.e),O!==y.t&&(P.disabled=y.t=O),y},{e:void 0,t:void 0}),N(()=>P.value=e()),b})(),(()=>{var b=ed(),C=b.firstChild;C.firstChild;var P=C.nextSibling;return g(C,_(rs,{get state(){return M()}}),null),P.$$input=y=>i(y.currentTarget.value),N(y=>{var S=et,O=c();return y.e=Y(P,S,y.e),O!==y.t&&(P.disabled=y.t=O),y},{e:void 0,t:void 0}),N(()=>P.value=n()),b})(),(()=>{var b=td(),C=b.firstChild,P=C.nextSibling;return P.$$input=y=>o(y.currentTarget.value),N(y=>{var S=et,O=c();return y.e=Y(P,S,y.e),O!==y.t&&(P.disabled=y.t=O),y},{e:void 0,t:void 0}),N(()=>P.value=s()),b})(),(()=>{var b=nd(),C=b.firstChild;C.firstChild;var P=C.nextSibling;return g(C,_(W,{get when(){return m()},get children(){return rd()}}),null),P.$$input=y=>a(y.currentTarget.value),N(y=>{var S={...et,border:m()?"1px solid #f85149":"1px solid #30363d"},O=c();return y.e=Y(P,S,y.e),O!==y.t&&(P.disabled=y.t=O),y},{e:void 0,t:void 0}),N(()=>P.value=l()),b})(),J(()=>J(()=>!!h())()&&(()=>{var b=io();return g(b,h),b})()),(()=>{var b=id();return g(b,()=>c()?"Creating account…":"Create Account"),N(C=>{var P=!k(),y=k()?"pointer":"not-allowed",S=k()?1:.5;return P!==C.e&&(b.disabled=C.e=P),y!==C.t&&z(b,"cursor",C.t=y),S!==C.a&&z(b,"opacity",C.a=S),C},{e:void 0,t:void 0,a:void 0}),b})(),(()=>{var b=sd();return b.$$click=()=>r.onCancel(),b})()]}}),null),w})()}function Sd(){const r=Ii(),e=_a(),[t,n]=G("login"),[i,s]=G("password"),[o,l]=G(r?_n():window.location.origin),[a,c]=G(""),[d,h]=G(""),[f,u]=G(""),[p,x]=G(""),{serverVersion:M,authModInfo:m,serverError:k}=_d(o),A=()=>{var E,L;return((L=(E=M())==null?void 0:E.serverData)==null?void 0:L.welcomeText)??null},w=()=>{var E,L;return(((L=(E=M())==null?void 0:E.serverData)==null?void 0:L.features)??[]).filter(I=>I.name!=="auth"&&I.version!=null)},b=()=>{var L,I;const E=M();return E?((I=(L=js(E))==null?void 0:L.authTypes)==null?void 0:I.includes("steam"))??!0:!0},C=()=>{var E,L,I;return((E=m())==null?void 0:E.allowRegistration)===!0||(((I=(L=M())==null?void 0:L.serverData)==null?void 0:I.features)??[]).some(B=>B.name==="official-like")},P=()=>{const E=o().replace(/\/$/,""),L=window.open(`${E}/api/auth/steam`,"screeps-steam-auth","width=800,height=600,left=200,top=100"),I=F=>{try{const U=JSON.parse(F.data);U.token&&(D(),Ct({url:E,auth:"token",token:U.token,serverPassword:p()||void 0,storage:null}))}catch{}},B=setInterval(()=>{L!=null&&L.closed&&D()},500),D=()=>{clearInterval(B),window.removeEventListener("message",I)};window.addEventListener("message",I),Pe(D)},y=async E=>{E.preventDefault(),await Ct({url:o(),auth:i(),email:a()||void 0,password:d()||void 0,token:f()||void 0,serverPassword:p()||void 0,storage:null})},S=async E=>{E.preventDefault(),await Ct({url:o(),auth:"guest",serverPassword:p()||void 0,storage:null})},O=async(E,L)=>{try{await Ct({url:o(),auth:"password",email:E,password:L,serverPassword:p()||void 0,storage:null})}catch{n("login"),s("password"),c(E),h(L)}},v=()=>Et()==="connecting";return(()=>{var E=yd(),L=E.firstChild;return g(E,_(W,{get when(){return A()},get children(){var I=ld();return N(()=>I.innerHTML=A()),I}}),L),g(L,_(W,{get when(){return t()==="register"},get children(){return _($d,{get url(){return o()},get serverPassword(){return p()},onSuccess:O,onCancel:()=>n("login")})}}),null),g(L,_(W,{get when(){return t()==="login"},get children(){var I=gd(),B=I.firstChild;B.firstChild;var D=B.nextSibling,F=D.firstChild,U=F.firstChild;U.nextSibling;var Q=F.nextSibling,K=D.nextSibling;return I.addEventListener("submit",y),g(B,_(W,{get when(){return C()},get children(){var H=ad();return H.$$click=()=>n("register"),H}}),null),g(I,_(W,{when:!r,get children(){var H=cd(),X=H.firstChild,j=X.nextSibling;return X.$$click=()=>s("password"),j.$$click=()=>s("token"),N(Z=>{var se=i()==="password"?"#238636":"transparent",Le=i()==="token"?"#238636":"transparent";return se!==Z.e&&z(X,"background",Z.e=se),Le!==Z.t&&z(j,"background",Z.t=Le),Z},{e:void 0,t:void 0}),H}}),D),g(I,_(W,{when:!r,get children(){return[(()=>{var H=dd(),X=H.firstChild,j=X.nextSibling;return j.$$input=Z=>l(Z.currentTarget.value),N(Z=>Y(j,et,Z)),N(()=>j.value=o()),H})(),_(W,{get when(){return k()},get children(){var H=ud();return g(H,k),H}})]}}),D),g(I,(()=>{var H=J(()=>i()==="password");return()=>H()?[(()=>{var X=vd(),j=X.firstChild,Z=j.nextSibling;return Z.$$input=se=>c(se.currentTarget.value),N(se=>Y(Z,et,se)),N(()=>Z.value=a()),X})(),(()=>{var X=bd(),j=X.firstChild,Z=j.nextSibling;return Z.$$input=se=>h(se.currentTarget.value),N(se=>Y(Z,et,se)),N(()=>Z.value=d()),X})()]:(()=>{var X=wd(),j=X.firstChild,Z=j.nextSibling;return Z.$$input=se=>u(se.currentTarget.value),N(se=>Y(Z,et,se)),N(()=>Z.value=f()),X})()})(),D),Q.$$input=H=>x(H.currentTarget.value),g(I,(()=>{var H=J(()=>!!Qi());return()=>H()&&(()=>{var X=io();return g(X,Qi),X})()})(),K),g(K,()=>v()?"Connecting…":"Connect"),g(I,_(W,{get when(){return b()},get children(){return[(()=>{var H=hd(),X=H.firstChild,j=X.nextSibling;return j.nextSibling,H})(),(()=>{var H=fd();return H.$$click=P,N(X=>{var j=v(),Z=v()?"not-allowed":"pointer",se=v()?.6:1;return j!==X.e&&(H.disabled=X.e=j),Z!==X.t&&z(H,"cursor",X.t=Z),se!==X.a&&z(H,"opacity",X.a=se),X},{e:void 0,t:void 0,a:void 0}),H})()]}}),null),g(I,_(W,{when:!r||e,get children(){var H=pd();return H.addEventListener("mouseleave",X=>{X.currentTarget.style.borderColor="#30363d"}),H.addEventListener("mouseenter",X=>{v()||(X.currentTarget.style.borderColor="#8b949e")}),H.$$click=S,N(X=>{var j=v(),Z=v()?"not-allowed":"pointer",se=v()?.6:1;return j!==X.e&&(H.disabled=X.e=j),Z!==X.t&&z(H,"cursor",X.t=Z),se!==X.a&&z(H,"opacity",X.a=se),X},{e:void 0,t:void 0,a:void 0}),H}}),null),N(H=>{var X=et,j=v(),Z=v()?"not-allowed":"pointer",se=v()?.6:1;return H.e=Y(Q,X,H.e),j!==H.t&&(K.disabled=H.t=j),Z!==H.a&&z(K,"cursor",H.a=Z),se!==H.o&&z(K,"opacity",H.o=se),H},{e:void 0,t:void 0,a:void 0,o:void 0}),N(()=>Q.value=p()),I}}),null),g(E,_(W,{get when(){return w().length>0},get children(){var I=md(),B=I.firstChild,D=B.nextSibling;return g(D,_(ye,{get each(){return w()},children:F=>(()=>{var U=xd();return g(U,()=>F.name,null),g(U,(()=>{var Q=J(()=>!!F.version);return()=>Q()?` ${F.version}`:""})(),null),U})()})),I}}),null),E})()}Se(["input","click"]);var kd=R('<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'),Cd=R('<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 Td(){const r=()=>{switch(Et()){case"connected":return"#238636";case"connecting":return"#d29922";case"error":return"#f85149";default:return"#8b949e"}};return(()=>{var e=Cd(),t=e.firstChild,n=t.firstChild,i=n.nextSibling;return g(i,(()=>{var s=J(()=>Et()==="connected");return()=>s()?"Online":Et()})()),g(e,_(W,{get when(){return Be()},get children(){return kd()}}),null),N(s=>z(n,"background-color",r())),e})()}class Md{constructor(e){T(this,"container");T(this,"hoverGraphics");T(this,"pendingGraphics");T(this,"selectionContainer");T(this,"selectionGraphics",new Map);T(this,"selectionTypes",new Map);T(this,"selectionVisuals",new Map);T(this,"ticker",null);T(this,"tickerCallback",null);this.container=new Oe,this.container.label="hoverHighlight",this.container.eventMode="none",this.hoverGraphics=new ee,this.hoverGraphics.eventMode="none",this.container.addChild(this.hoverGraphics),this.pendingGraphics=new ee,this.pendingGraphics.eventMode="none",this.container.addChild(this.pendingGraphics),this.selectionContainer=new Oe,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 n=e*$,i=t*$;this.hoverGraphics.rect(n,i,$,$),this.hoverGraphics.stroke({width:1,color:16777215,alpha:.35}),this.hoverGraphics.rect(n,i,$,$),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:n,visual:i}of e){const s=new ee;s.eventMode="none",this.selectionContainer.addChild(s),this.selectionGraphics.set(t,s),this.selectionTypes.set(t,n),this.selectionVisuals.set(t,i),n==="creep"?this.drawCreepRing(s,i.x,i.y):this.drawStructureBox(s,i.x,i.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 n=e*$,i=t*$,s=n+$/2,o=i+$/2,l=$*.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(n+1,i+1,$-2,$-2),this.pendingGraphics.stroke({width:1.5,color:15763518,alpha:.6})}clearPendingTile(){this.pendingGraphics.clear()}drawCreepRing(e,t,n){e.clear();const i=t+$/2,s=n+$/2,o=$*.48;e.circle(i,s,o),e.stroke({width:1.5,color:16777215,alpha:.9})}drawStructureBox(e,t,n){e.clear();const i=1;e.rect(t+i,n+i,$-i*2,$-i*2),e.stroke({width:1.5,color:16777215,alpha:.9}),e.rect(t+i,n+i,$-i*2,$-i*2),e.fill({color:16777215,alpha:.04})}trackCreepRings(){for(const[e,t]of this.selectionGraphics){if(this.selectionTypes.get(e)!=="creep")continue;const n=this.selectionVisuals.get(e);!n||n.destroyed||this.drawCreepRing(t,n.x,n.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 $=12,Me=50*$,xe=48,fr=128;class Di{constructor(e,t){T(this,"app");T(this,"world");T(this,"hoverLayer");T(this,"destroyed",!1);T(this,"canDrag",!1);T(this,"container");T(this,"resizeObserver",null);T(this,"bounceRaf",null);T(this,"wheelTimeout",null);T(this,"navOverlay");T(this,"lastMouseX",0);T(this,"lastMouseY",0);T(this,"onHoverTile",null);T(this,"onClickTile",null);T(this,"onRightClick",null);this.app=e,this.container=t,this.world=new Oe,this.app.stage.addChild(this.world),this.hoverLayer=new Md(e.ticker),this.world.addChild(this.hoverLayer.container),this.navOverlay=new Oe,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 Ns;return await t.init({background:"#0d1117",antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0}),e.appendChild(t.canvas),new Di(t,e)}getMinScale(){const t=this.container.clientWidth,n=this.container.clientHeight;return Math.min(t,n)/(Me+64)}clampView(e=!1){const t=this.world.scale.x,n=Me*t,i=this.container.clientWidth,s=this.container.clientHeight,o=e?fr:0;if(n<=i){const l=i/2-n/2;e?this.world.x=Math.min(l+fr,Math.max(l-fr,this.world.x)):this.world.x=l}else{const l=i-n-xe-o,a=xe+o;this.world.x=Math.min(a,Math.max(l,this.world.x))}if(n<=s){const l=s/2-n/2;e?this.world.y=Math.min(l+fr,Math.max(l-fr,this.world.y)):this.world.y=l}else{const l=s-n-xe-o,a=xe+o;this.world.y=Math.min(a,Math.max(l,this.world.y))}this.canDrag=!0}getTargetPosition(){const e=this.world.scale.x,t=Me*e,n=this.container.clientWidth,i=this.container.clientHeight;let s=null,o=null;if(t<=n)s=n/2-t/2;else{const l=n-t-xe,a=xe;this.world.x<l?s=l:this.world.x>a&&(s=a)}if(t<=i)o=i/2-t/2;else{const l=i-t-xe,a=xe;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 n=this.world.x,i=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-n)/s,h=(c-i)/s,f=u=>{const p=u-o,x=Math.min(1,p/l),M=1-Math.pow(1-x,3);if(t!==null){const m=s+(t-s)*M;this.world.scale.set(m),this.world.x=a-d*m,this.world.y=c-h*m}e&&t===null&&(this.world.x=n+(e.x-n)*M,this.world.y=i+(e.y-i)*M),x<1?this.bounceRaf=requestAnimationFrame(f):(this.bounceRaf=null,this.clampView())};this.cancelBounce(),this.bounceRaf=requestAnimationFrame(f)}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 hr(0,0),n=new hr(0,0);const i=this.app.canvas,s=4;i.style.touchAction="none",i.style.userSelect="none";const o=new Map;let l=!1,a=0,c=0,d=0,h=0;i.addEventListener("contextmenu",u=>{u.preventDefault()}),i.addEventListener("pointerdown",u=>{if(this.cancelBounce(),this.cancelWheelTimeout(),o.set(u.pointerId,{x:u.clientX,y:u.clientY}),i.setPointerCapture(u.pointerId),o.size>=2){e=!1,l=!0;const p=[...o.values()],x=i.getBoundingClientRect(),M=(p[0].x+p[1].x)/2-x.left,m=(p[0].y+p[1].y)/2-x.top;d=Math.hypot(p[1].x-p[0].x,p[1].y-p[0].y),h=this.world.scale.x,a=(M-this.world.x)/h,c=(m-this.world.y)/h}else l=!1,e=this.canDrag,t=new hr(u.clientX,u.clientY),n=new hr(u.clientX,u.clientY)}),i.addEventListener("pointermove",u=>{var m;const p=i.getBoundingClientRect();if(this.lastMouseX=u.clientX-p.left,this.lastMouseY=u.clientY-p.top,o.has(u.pointerId)&&o.set(u.pointerId,{x:u.clientX,y:u.clientY}),l&&o.size===2){const k=[...o.values()],A=(k[0].x+k[1].x)/2-p.left,w=(k[0].y+k[1].y)/2-p.top,b=Math.hypot(k[1].x-k[0].x,k[1].y-k[0].y),C=this.getMinScale(),P=5,y=.6;let S=h*(b/d);S<C&&(S=C+(S-C)*y),S>P&&(S=P+(S-P)*y),this.cancelBounce(),this.world.scale.set(S),this.world.x=A-a*S,this.world.y=w-c*S,this.clampView(!0);return}if(!l){const k=this.screenToTile(this.lastMouseX,this.lastMouseY);this.hoverLayer.setHoveredTile((k==null?void 0:k.tx)??null,(k==null?void 0:k.ty)??null),(m=this.onHoverTile)==null||m.call(this,(k==null?void 0:k.tx)??null,(k==null?void 0:k.ty)??null)}if(!e||!this.canDrag)return;const x=u.clientX-t.x,M=u.clientY-t.y;this.world.x+=x,this.world.y+=M,t=new hr(u.clientX,u.clientY),this.clampView(!0)});const f=u=>{var m;if(i.releasePointerCapture(u.pointerId),o.delete(u.pointerId),l){o.size<2&&(l=!1,e=!1,this.springBack());return}e=!1;const p=u.clientX-n.x,x=u.clientY-n.y;if(Math.sqrt(p*p+x*x)<s){const k=i.getBoundingClientRect(),A=u.clientX-k.left,w=u.clientY-k.top,b=this.screenToTile(A,w);b&&((m=this.onClickTile)==null||m.call(this,b.tx,b.ty,u.ctrlKey||u.metaKey))}this.springBack()};i.addEventListener("pointerup",f),i.addEventListener("pointercancel",f),i.addEventListener("contextmenu",u=>{var p;u.preventDefault(),(p=this.onRightClick)==null||p.call(this)}),i.addEventListener("pointerleave",()=>{var u;this.hoverLayer.setHoveredTile(null,null),(u=this.onHoverTile)==null||u.call(this,null,null)}),i.addEventListener("wheel",u=>{u.preventDefault();const p=u.deltaY>0?.9:1.1,x=this.getMinScale(),M=5;let m=this.world.scale.x*p;const k=.6;m<x&&(m=x+(m-x)*k),m>M&&(m=M+(m-M)*k);const A=i.getBoundingClientRect(),w=u.clientX-A.left,b=u.clientY-A.top;if(this.cancelBounce(),m<x){const C=this.container.clientWidth/2,P=this.container.clientHeight/2,y=(C-this.world.x)/this.world.scale.x,S=(P-this.world.y)/this.world.scale.y;this.world.scale.set(m),this.world.x=C-y*m,this.world.y=P-S*m}else{const C=(w-this.world.x)/this.world.scale.x,P=(b-this.world.y)/this.world.scale.y;this.world.scale.set(m),this.world.x=w-C*m,this.world.y=b-P*m}this.clampView(),this.cancelWheelTimeout(),this.wheelTimeout=window.setTimeout(()=>{this.wheelTimeout=null,this.springBack()},80)},{passive:!1})}setTileHandlers(e,t,n){this.onHoverTile=e,this.onClickTile=t,this.onRightClick=n??null}screenToTile(e,t){const n=(e-this.world.x)/this.world.scale.x,i=(t-this.world.y)/this.world.scale.y,s=Math.floor(n/$),o=Math.floor(i/$);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,n=this.world.scale.x;this.world.x=e-Me*n/2,this.world.y=t-Me*n/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(n=>{const{width:i,height:s}=n[0].contentRect;this.app.renderer.resize(i,s),this.clampView()}),this.resizeObserver.observe(this.container)}setupNavigationZones(e){this.navOverlay.removeChildren();const t=(o,l,a,c,d,h)=>{if(!h)return;const f=new ee;f.x=o,f.y=l,f.hitArea=new Gs(0,0,a,c),f.fill({color:16777215,alpha:.12}),f.poly(d),f.fill(),f.eventMode="static",f.cursor="pointer",f.alpha=1,f.on("pointerover",()=>{f.clear(),f.fill({color:16777215,alpha:.06}),f.rect(0,0,a,c),f.fill(),f.fill({color:16777215,alpha:.35}),f.poly(d),f.fill()}),f.on("pointerout",()=>{f.clear(),f.fill({color:16777215,alpha:.12}),f.poly(d),f.fill()}),f.on("pointerdown",h),this.navOverlay.addChild(f)},n=Me/2,i=Me/2,s=18;t(-xe,0,xe,Me,[18,i,xe-6,i-s,xe-6,i+s],e.west),t(Me,0,xe,Me,[xe-18,i,6,i-s,6,i+s],e.east),t(0,-xe,Me,xe,[n,18,n-s,xe-6,n+s,xe-6],e.north),t(0,Me,Me,xe,[n,xe-18,n-s,6,n+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,h=a.width*this.world.scale.x,f=a.height*this.world.scale.y;this.lastMouseX>=c&&this.lastMouseX<=c+h&&this.lastMouseY>=d&&this.lastMouseY<=d+f&&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 so=856343,Ed=1448738,Rd=1843496,Pd=3421243,Od=Pd,Ld=so,zi=7039337,oo=3159613,Ad=1579032,Id=0,Nd=2631720,Gd=2632986,Dd=2500383,zd=2771488,Bd=5000268,Fd=11122630,Hd=16770413,Wd=7829367,Ud=16332866,Xd=6127794,jd=6684002,Yd=12164347,Hr={tough:Bd,move:Fd,work:Hd,carry:Wd,attack:Ud,ranged_attack:Xd,heal:jd,claim:Yd},Pn=5809919,Rt=7979263,lo=4176208,On=9147550,Wr=13801762,ns=10711543,Vd=16218298,is=16273737,kr=15763518,qd=2172461,ao=zi,Zd=13226457,$t=12283502,Zt=[16777215,16711680,8388736,255,65535,32768,16776960,16753920,10824234,8421504,16777215],Kd={creep:kr,spawn:Pn,extension:Rt,tower:lo,container:On,storage:Wr,link:ns,rampart:Pn,road:ao,wall:qd,extractor:On,lab:Vd,terminal:Wr,observer:Rt,powerSpawn:kr,nuker:is,factory:On,invaderCore:is,source:Wr,mineral:Rt,deposit:Wr,controller:Pn,powerBank:kr,portal:ns},Gr=16771195,Jd=Gr,Qd=Rt,eu=Gr,Cr=9419667,tu=7245682,ru=12116924,nu=12283502,iu=9787480,su=14721184,ss=Rd,ou=13684944,_e=1579032,bt=5592405,rn=11184810,lu=9419667,He=16771195,au=16069959,os=4410435,cu=$*.05,du=$*.2;function Kt(r,e,t,n){const i=$,s=i/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,h=l<49&&e.get(a,l+1)===t,f=a>0&&e.get(a-1,l)===t,u=a<49&&e.get(a+1,l)===t,p=a*i+s,x=l*i+s;c?(o=!0,!d&&!f&&l>0&&a>0?(r.moveTo(p,l*i),r.arc(p,x,s,-Math.PI/2,Math.PI,!0),r.lineTo(p,x),r.closePath()):r.rect(a*i,l*i,s,s)):d&&f&&e.get(a-1,l-1)===t&&(o=!0,r.moveTo(p,l*i),r.lineTo(a*i,l*i),r.lineTo(a*i,x),r.arc(p,x,s,Math.PI,-Math.PI/2,!1),r.closePath()),c?!d&&!u&&l>0&&a<49?(r.moveTo(p,l*i),r.arc(p,x,s,-Math.PI/2,0,!1),r.lineTo(p,x),r.closePath()):r.rect(p,l*i,s,s):d&&u&&e.get(a+1,l-1)===t&&(o=!0,r.moveTo(p,l*i),r.lineTo(a*i+i,l*i),r.lineTo(a*i+i,x),r.arc(p,x,s,0,-Math.PI/2,!0),r.closePath()),c?!h&&!f&&l<49&&a>0?(r.moveTo(a*i,x),r.arc(p,x,s,Math.PI,Math.PI/2,!0),r.lineTo(p,x),r.closePath()):r.rect(a*i,x,s,s):h&&f&&e.get(a-1,l+1)===t&&(o=!0,r.moveTo(a*i,x),r.lineTo(a*i,l*i+i),r.lineTo(p,l*i+i),r.arc(p,x,s,Math.PI/2,Math.PI,!1),r.closePath()),c?!h&&!u&&l<49&&a<49?(r.moveTo(p,l*i+i),r.arc(p,x,s,Math.PI/2,0,!0),r.lineTo(p,x),r.closePath()):r.rect(p,x,s,s):h&&u&&e.get(a+1,l+1)===t&&(o=!0,r.moveTo(p,l*i+i),r.lineTo(a*i+i,l*i+i),r.lineTo(a*i+i,x),r.arc(p,x,s,0,Math.PI/2,!1),r.closePath())}o&&n(r)}function uu(r,e){const t=zi,n=$,i=(s,o,l)=>{const a=s*n+n/2,c=o*n+n/2,d=n*.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&&i(s,0,"up"),e.get(s,49)!==Fe.Wall&&i(s,49,"down");for(let s=0;s<50;s++)e.get(0,s)!==Fe.Wall&&i(0,s,"left"),e.get(49,s)!==Fe.Wall&&i(49,s,"right")}function hu(r){const e=new ee;e.rect(0,0,50*$,50*$),e.fill(Od);const t={color:Dd,width:du,alignment:0,cap:"round",join:"round"};Kt(e,r,Fe.Swamp,i=>i.stroke(t)),Kt(e,r,Fe.Swamp,i=>i.fill(Gd));const n={color:Id,width:cu,alignment:0,cap:"round",join:"round"};return Kt(e,r,Fe.Wall,i=>i.stroke(n)),Kt(e,r,Fe.Wall,i=>i.fill(Ad)),uu(e,r),e.rect(0,0,50*$,50*$),e.stroke({width:1,color:oo}),e}function fu(r){const e=new ee;return e.label="swampGlow",Kt(e,r,Fe.Swamp,t=>t.fill(zd)),e.alpha=.45,e.filters=[new fl({strength:5,quality:3})],e}function pu(r,e){const t=new ee;Kt(t,r,Fe.Wall,s=>s.fill(Nd)),t.alpha=.5,t.filters=[new hl({noise:.12,seed:1})],t.filterArea=new Gs(0,0,50*$,50*$);const n=e.generateTexture({target:t,frame:t.filterArea});t.filters=null,t.destroy();const i=new tr(n);return i.label="wallNoise",i}function ls(r,e){const t=new Oe,n=pu(r,e),i=t.destroy.bind(t);return t.destroy=s=>{n.destroyed||(n.removeFromParent(),n.destroy({texture:!0,textureSource:!0})),i(s)},t.addChild(hu(r)),t.addChild(fu(r)),t.addChild(n),t}function Ln(r,e){r.getChildByLabel("swampGlow").visible=e,r.getChildByLabel("wallNoise").visible=e}function gu(r){return new Promise((e,t)=>{const n=new Image;n.onload=()=>e(n),n.onerror=t,n.src=r})}class co{constructor(){T(this,"cache",new Map);T(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),n=this.cache.get(t);if(n)return Promise.resolve(n);const i=this.pending.get(t);if(i)return i;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 n=xn(e),i=new Blob([n],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(i);try{const o=window.devicePixelRatio||1,l=128*Math.max(2,o),a=await gu(s),c=document.createElement("canvas");c.width=l,c.height=l,c.getContext("2d").drawImage(a,0,0,l,l);const h=_t.from(c);return this.cache.set(t,h),h}finally{URL.revokeObjectURL(s)}}destroy(){for(const e of this.cache.values())e.destroyed||e.destroy(!0);this.cache.clear(),this.pending.clear()}}const mu=new co,ht=$*.44,je=$*.28,pr=50,ii=32,si=12/ii,uo=$/2-$*.44,ho=2,as=$*.42,fo=$*.3,yu=Math.max(1,$*.08),vu={H:13421772,O:16777215,U:5822457,L:62626,K:10514943,Z:16631694,X:11568379},bu={H:2236962,O:2236962},wu=$*.42,po=32,xu=9/po,oi=$-4,cs=$*.28,ds=1600,_u=16776428;function li(r,e){if(e<=0)return oi;const t=Math.max(0,Math.min(1,r/e));return cs+(oi-cs)*t}function Bi(r,e,t=He){const n=e/2,i=$/2,s=$/2,o=e*.25;r.clear(),r.roundRect(i-n,s-n,e,e,o),r.fill(t)}function An(r,e){const t=r.__sourceGraphics;t&&(r.__sourceSize=e,Bi(t,e,Fi(performance.now())))}function Fi(r){const e=r%ds/ds,t=.5-.5*Math.cos(e*Math.PI*2);return yo(He,_u,t)}function ai(r){const e=typeof r.energy=="number"?r.energy:0,t=typeof r.energyCapacity=="number"?r.energyCapacity:3e3;return{energy:e,capacity:t}}const go=$*.3,mo=Math.max(1,$*.12),ci=go-mo/2,$u=$*.42,Su=1500;function yo(r,e,t){const n=r>>16&255,i=r>>8&255,s=r&255,o=e>>16&255,l=e>>8&255,a=e&255,c=Math.round(n+(o-n)*t),d=Math.round(i+(l-i)*t),h=Math.round(s+(a-s)*t);return c<<16|d<<8|h}function vo(r,e){r.clear(),r.circle($/2,$/2,go),r.stroke({width:mo,color:e,alpha:.95})}function di(r,e,t,n,i,s,o){if(r.clear(),s<=0||i<=0)return;const l=Math.min(1,i/s);if(l>=1){r.circle(e,t,n),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+n*Math.cos(a),t+n*Math.sin(a)),r.arc(e,t,n,a,c),r.closePath(),r.fill({color:o,alpha:.55})}function dt(r,e,t){return t.flatMap(([n,i])=>[r+n*$,e+i*$])}function Bt(r,e,t,n){t-e<.001||(r.moveTo(ht*Math.cos(e),ht*Math.sin(e)),r.arc(0,0,ht,e,t),r.lineTo(je*Math.cos(t),je*Math.sin(t)),r.arc(0,0,je,t,e,!0),r.closePath(),r.fill(n))}function ui(r){let e=0;if(typeof r.storeCapacity=="number")e=r.storeCapacity;else{const n=r.body;n&&(e=n.filter(i=>i.type==="carry").length*50)}if(e===0)return{used:0,capacity:0};let t=0;if(r.store&&typeof r.store=="object"){const n=r.store;for(const i in n){const s=n[i];typeof s=="number"&&(t+=s)}}else typeof r.energy=="number"&&(t=r.energy);return{used:t,capacity:e}}function hi(r,e){return e<=0||r<=0?0:je*.8*Math.min(1,r/e)}function In(r,e){const t=r.__creepFillGraphics;t&&(t.clear(),e>0&&(t.circle(0,0,e),t.fill(Gr)))}function ku(r){return Kd[r]??Zd}function Jt(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 bo(r){return r>=200?1.15:r>=100?.85:.7}function fi(r,e){return e<=0||r<=0?0:fo*bo(e)*Math.min(1,r/e)}function Cu(r,e,t,n){const i=$/2,s=$/2,o=bo(t),l=new ee;l.circle(i,s,as*o),l.fill(_e),l.circle(i,s,as*o),l.stroke({width:yu*o,color:n}),l.circle(i,s,fo*o),l.fill(rn),r.addChild(l);const a=new ee,c=fi(e,t);c>0&&(a.circle(i,s,c),a.fill(He)),r.addChild(a),r.__fillGraphics=a}function Nn(r,e){const t=$/2,n=$/2,i=r.__fillGraphics;i&&(i.clear(),e>0&&(i.circle(t,n,e),i.fill(He)))}const pi=-$*.4,gi=-$*.3,mi=$*.8,an=$*.6;function yi(r,e){return e<=0||r<=0?0:an*Math.min(1,r/e)}function nn(r,e){const t=r.__towerFillGraphics;if(t&&(t.clear(),e>0)){const n=Math.max(.5,$*.02);t.rect(pi+n,gi+an-e+n,mi-n*2,e-n*2),t.fill(He)}}const Tu=0,Mu=-$*.1,Eu=$*1,wo=$*1.2;function xo(r){const e=typeof r.storeCapacity=="number"?r.storeCapacity:0;if(e===0)return{used:0,capacity:0};let t=0;if(r.store&&typeof r.store=="object"){const n=r.store;for(const i in n){const s=n[i];typeof s=="number"&&(t+=s)}}return{used:t,capacity:e}}function vi(r,e){return e<=0||r<=0?0:wo*Math.min(1,r/e)}function bi(r,e){const t=r.__storageFillG;t&&(t.clear(),e>0&&(t.rect(Tu,Mu+wo-e,Eu,e),t.fill(He)))}const wi=$*.65,xi=wi,Ke=$*.42;function _i(r,e,t,n,i,s,o,l){r.clear();const a=8,c=.1,d=2*Math.PI/a-c;for(let h=0;h<a;h++){const f=-Math.PI/2+h*(2*Math.PI/a)+c/2,u=f+d,p=e+i*Math.cos(f),x=t+i*Math.sin(f);if(h<s)r.moveTo(p,x),r.arc(e,t,n,f,u),r.arc(e,t,i,u,f,!0),r.closePath(),r.fill({color:14540253,alpha:.9});else if(h===s&&l>0){if(r.moveTo(p,x),r.arc(e,t,n,f,u),r.arc(e,t,i,u,f,!0),r.closePath(),r.fill({color:1973790,alpha:.85}),o>0){const M=Math.min(1,o/l),m=f+d*M;r.moveTo(p,x),r.arc(e,t,n,f,m),r.arc(e,t,i,m,f,!0),r.closePath(),r.fill({color:14540253,alpha:.9})}}else r.moveTo(p,x),r.arc(e,t,n,f,u),r.arc(e,t,i,u,f,!0),r.closePath(),r.fill({color:1973790,alpha:.6})}}function cn(r,e){const t=r.user;return typeof t!="string"||!e?!1:t!==e}function Ur(r,e=!0,t,n,i,s){var p,x,M;const o=new Oe,l=new ee,a=ku(r.type),c=$/2,d=$/2,h=typeof r.user=="string"?r.user:void 0,u=h!==void 0&&t!==void 0&&h!==t?$t:lu;switch(r.type){case"creep":{const m=2*Math.PI,k=new Oe;k.position.set(c,d),k.rotation=-Math.PI/2;const A=cn(r,t);if(A){const oe=new ee;oe.circle(0,0,ht+.75),oe.stroke({width:1.5,color:$t}),k.addChild(oe)}const w=new ee;w.circle(0,0,ht),w.fill(so),k.addChild(w);const b=r.body??[];let C=0,P=0,y=0;const S=[],O={};for(const oe of b)oe.type==="work"?C++:oe.type==="move"?P++:(O[oe.type]===void 0&&(S.push(oe.type),O[oe.type]=0),O[oe.type]++,y++);const v=C/pr*m,E=P/pr*m,L=y/pr*m,I=v/2,B=I+L/2,D=Math.PI-E/2,F=Math.PI+E/2,U=m-v/2-L/2,Q=m-v/2,K=new ee;v>0&&Bt(K,-v/2,I,Hr.work);let H=I;for(const oe of S){const Te=(O[oe]??0)/pr*m/2;Bt(K,H,H+Te,Hr[oe]??7829367),H+=Te}Bt(K,B,D,ss),E>0&&Bt(K,D,F,Hr.move),Bt(K,F,U,ss);let X=Q;for(const oe of S){const Te=(O[oe]??0)/pr*m/2;Bt(K,X-Te,X,Hr[oe]??7829367),X-=Te}k.addChild(K);const j=new ee;j.circle(0,0,je),j.fill(Ed),k.addChild(j);const Z=typeof r.user=="string"?r.user:void 0,se=Z?(p=s==null?void 0:s[Z])==null?void 0:p.badge:void 0;if(se&&i){const oe=new tr;oe.anchor.set(.5,.5);const Te=je*2;oe.width=Te,oe.height=Te,oe.rotation=Math.PI/2,k.addChild(oe),o.__creepBadgeSprite=oe,i.getOrCreate(se).then(vt=>{oe.destroyed||(oe.texture=vt)}).catch(()=>{})}else if(A){const oe=new ee;oe.circle(0,0,je*.82),oe.fill({color:$t,alpha:.9}),k.addChild(oe),o.__creepForeignMark=oe}const{used:Le,capacity:Ye}=ui(r),st=hi(Le,Ye),Ve=new ee;st>0&&(Ve.circle(0,0,st),Ve.fill(Gr)),k.addChild(Ve),o.__creepFillGraphics=Ve,o.__creepUsed=Le,o.__creepCapacity=Ye;const ot=(ht+je)/2,lt=(ht-je)*.45,Ae=new ee;Ae.moveTo(ht,0),Ae.lineTo(ot,-lt),Ae.lineTo(ot,lt),Ae.closePath(),Ae.fill(ou),k.addChild(Ae),o.addChild(k),o.__bodyContainer=k;break}case"extension":{const{energy:m,capacity:k}=Jt(r);Cu(o,m,k,u),o.__extEnergy=m,o.__extCapacity=k;break}case"spawn":{l.circle(c,d,$*.65),l.fill(_e),l.circle(c,d,$*.65),l.stroke({width:$*.1,color:13421772}),l.circle(c,d,$*.4),l.fill(He);break}case"powerSpawn":{l.circle(c,d,$*.65),l.fill(_e),l.circle(c,d,$*.65),l.stroke({width:$*.1,color:au}),l.circle(c,d,$*.4),l.fill(He);break}case"source":{const{energy:m,capacity:k}=ai(r),A=li(m,k),w=new ee;Bi(w,A,Fi(performance.now())),o.addChild(w),o.__sourceGraphics=w,o.__sourceEnergy=m,o.__sourceCapacity=k,o.__sourceSize=A;break}case"constructionSite":{const m=typeof r.user=="string"?r.user:void 0,k=m!==void 0&&m===t,A=k?Cr:nu,w=k?tu:iu,b=k?ru:su,C=typeof r.progress=="number"?r.progress:0,P=typeof r.progressTotal=="number"?r.progressTotal:1,y=new ee;o.addChild(y),o.__csBuildGlow=y;const S=new ee;di(S,c,d,ci,C,P,A),o.addChild(S),o.__csFillGraphics=S;const O=new ee;vo(O,A),o.addChild(O),o.__csRingGraphics=O,o.__csProgress=C,o.__csProgressTotal=P,o.__csUser=m,o.__csColor=A,o.__csColorDark=w,o.__csColorLight=b;break}case"mineral":{const m=typeof r.mineralType=="string"?r.mineralType:"?",k=vu[m]??Rt,A=bu[m]??16777215,w=new ee;w.circle(c,d,wu),w.fill(k),o.addChild(w);const b=new Qt({text:m,style:{fontSize:po,fill:A,fontWeight:"bold"}});b.anchor.set(.5,.5),b.scale.set(xu),b.position.set(c,d),o.addChild(b);break}case"deposit":{l.rect(2,2,$-4,$-4),l.fill(a);break}case"controller":{const m=typeof r.level=="number"?r.level:0,k=typeof r.progress=="number"?r.progress:0,A=typeof r.progressTotal=="number"?r.progressTotal:0,w=typeof r.user=="string"?r.user:void 0,b=w?(x=s==null?void 0:s[w])==null?void 0:x.badge:void 0,C=new ee,P=[];for(let O=0;O<8;O++){const v=-Math.PI/2+O*Math.PI/4;P.push(c+wi*Math.cos(v),d+wi*Math.sin(v))}C.poly(P),C.fill(2238513),C.poly(P),C.stroke({width:$*.07,color:8027781}),o.addChild(C);const y=new ee;_i(y,c,d,xi,Ke,m,k,A),o.addChild(y),o.__ctrlSegGraphics=y,o.__ctrlLevel=m,o.__ctrlProgress=k,o.__ctrlProgressTotal=A;const S=new ee;if(b?(S.circle(c,d,Ke),S.fill(_e)):(S.circle(c,d,Ke),S.fill(3028031),S.circle(c,d,Ke),S.stroke({width:$*.04,color:8027781}),S.circle(c,d,$*.16),S.fill(10133672)),o.addChild(S),b&&i){const O=new tr;O.anchor.set(.5,.5),O.width=Ke*2,O.height=Ke*2,O.position.set(c,d);const v=new ee;v.circle(c,d,Ke),v.fill(16777215),o.addChild(O),O.mask=v,o.addChild(v),i.getOrCreate(b).then(E=>{O.destroyed||(O.texture=E)}).catch(()=>{})}break}case"energy":{l.circle(c,d,$*.2),l.fill(He);break}case"road":break;case"wall":{l.circle(c,d,$*.4),l.fill(_e),l.circle(c,d,$*.4),l.stroke({width:$*.05,color:rn});break}case"rampart":break;case"tower":{const{energy:m,capacity:k}=Jt(r),A=new ee;A.circle(c,d,$*.6),A.fill(_e),A.circle(c,d,$*.6),A.stroke({width:$*.05,color:u}),o.addChild(A);const w=new Oe;w.position.set(c,d);const b=new ee;b.rect(pi,gi,mi,an),b.fill(_e),w.addChild(b);const C=new ee;w.addChild(C),o.__towerFillGraphics=C,o.__towerEnergy=m,o.__towerCapacity=k,nn(o,yi(m,k));const P=new ee;P.rect(pi,gi,mi,an),P.stroke({width:1,color:bt}),w.addChild(P);const y=new ee;y.rect(-$*.2,-$*.9,$*.4,$*.5),y.fill(rn),y.rect(-$*.2,-$*.9,$*.4,$*.5),y.stroke({width:$*.07,color:_e}),w.addChild(y),o.addChild(w),o.__barrelContainer=w;break}case"storage":{const{used:m,capacity:k}=xo(r),A=dt(c,d,[[-.6,-.7],[0,-.8],[.6,-.7],[.65,0],[.6,.7],[0,.8],[-.6,.7],[-.65,0],[-.6,-.7]]);l.poly(A),l.fill(_e),l.poly(A),l.stroke({width:$*.05,color:u}),l.rect(c-$*.5,d-$*.6,$*1,$*1.2),l.fill(bt),o.addChild(l);const w=new ee;o.addChild(w),o.__storageFillG=w,o.__storageUsed=m,o.__storageCapacity=k,bi(o,vi(m,k));const b=new ee;b.rect(c-$*.5,d-$*.6,$*1,$*1.2),b.stroke({width:$*.1,color:_e}),o.addChild(b);break}case"terminal":{const m=dt(c,d,[[0,-.8],[.55,-.55],[.8,0],[.55,.55],[0,.8],[-.55,.55],[-.8,0],[-.55,-.55],[0,-.8]]),k=dt(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(_e),l.poly(m),l.stroke({width:$*.05,color:u}),l.poly(k),l.fill(rn),l.rect(c-$*.45,d-$*.45,$*.9,$*.9),l.fill(bt),l.rect(c-$*.45,d-$*.45,$*.9,$*.9),l.stroke({width:$*.1,color:_e});break}case"link":{const m=dt(c,d,[[0,-.5],[.4,0],[0,.5],[-.4,0],[0,-.5]]),k=dt(c,d,[[0,-.3],[.25,0],[0,.3],[-.25,0],[0,-.3]]);l.poly(m),l.fill(_e),l.poly(m),l.stroke({width:$*.05,color:u}),l.poly(k),l.fill(bt);break}case"lab":{const m=d-$*.025;l.circle(c,m,$*.55),l.fill(_e),l.circle(c,m,$*.55),l.stroke({width:$*.05,color:u}),l.circle(c,m,$*.4),l.fill(bt),l.rect(c-$*.45,d+$*.3,$*.9,$*.25),l.fill(_e),l.poly(dt(c,d,[[-.45,.3],[-.45,.55],[.45,.55],[.45,.3]])),l.stroke({width:$*.05,color:u});break}case"container":{l.rect(c-$*.225,d-$*.3,$*.45,$*.6),l.fill(He),l.rect(c-$*.225,d-$*.3,$*.45,$*.6),l.stroke({width:$*.1,color:_e});break}case"observer":{l.circle(c,d,$*.45),l.fill(_e),l.circle(c,d,$*.45),l.stroke({width:$*.05,color:u}),l.circle(c+$*.225,d,$*.2),l.fill(u);break}case"nuker":{const m=dt(c,d,[[0,-1],[-.47,.2],[-.5,.5],[.5,.5],[.47,.2],[0,-1]]),k=dt(c,d,[[0,-.8],[-.4,.2],[.4,.2],[0,-.8]]);l.poly(m),l.fill(_e),l.poly(m),l.stroke({width:$*.05,color:u}),l.poly(k),l.fill(bt),l.poly(k),l.stroke({width:$*.01,color:u});break}case"factory":case"extractor":case"invaderCore":{l.circle(c,d,$*.45),l.fill(_e),l.circle(c,d,$*.45),l.stroke({width:$*.05,color:u}),l.circle(c,d,$*.35),l.fill(bt);break}case"flag":{const m=typeof r.color=="number"?r.color:0,k=typeof r.secondaryColor=="number"?r.secondaryColor:0,A=Zt[m]??Zt[0],w=Zt[k]??Zt[0],b=1.5,C=$*.08*b,P=$*.7*b,y=c-C/2,S=d-$*.25*b;l.rect(y,S,C,P),l.fill(8947848);const O=y+C,v=S,E=O+$*.45*b,L=v,I=v+$*.44*b,B=(L+I)/2,D=B;if(l.moveTo(O,L),l.lineTo(E,B),l.lineTo(O,D),l.closePath(),l.fill(A),l.moveTo(O,D),l.lineTo(E,B),l.lineTo(O,I),l.closePath(),l.fill(w),o.addChild(l),o.__flagColor=m,o.__flagSecondaryColor=k,typeof r.name=="string"){const F=new Qt({text:r.name,style:{fontSize:ii,fill:16777215}});F.scale.set(si),F.anchor.set(.5,0),F.x=c,F.y=d+$*.55,F.visible=e,o.__nameLabel=F,o.addChild(F)}break}case"ruin":{const m=typeof r.user=="string"?r.user:void 0,A=m!==void 0&&m===t?Cr:$t,w=$*.42,b=6,C=Math.PI/5,P=new ee;for(let O=0;O<b;O++){const v=O*Math.PI*2/b,E=v-C/2,L=v+C/2,I=c+w*Math.cos(E),B=d+w*Math.sin(E);P.moveTo(I,B),P.arc(c,d,w,E,L),P.stroke({width:$*.09,color:A,alpha:.75,cap:"round"})}o.addChild(P);const y=$*.18,S=new ee;S.moveTo(c-y,d-y),S.lineTo(c+y,d+y),S.moveTo(c+y,d-y),S.lineTo(c-y,d+y),S.stroke({width:$*.11,color:A,cap:"round"}),o.addChild(S);break}case"tombstone":{const m=typeof r.user=="string"?r.user:void 0,A=m!==void 0&&m===t?Cr:$t,w=$*.62,b=$*.82,C=c-w/2,P=d-b/2,y=w/2,S=new ee;S.moveTo(C,P+y),S.arc(c,P+y,y,Math.PI,0,!1),S.lineTo(C+w,P+b),S.lineTo(C,P+b),S.closePath(),S.fill(_e),S.moveTo(C,P+y),S.arc(c,P+y,y,Math.PI,0,!1),S.lineTo(C+w,P+b),S.lineTo(C,P+b),S.closePath(),S.stroke({width:$*.07,color:A,alpha:.9}),o.addChild(S);const O=$*.18,v=new ee;v.moveTo(c-O,d-O*.6),v.lineTo(c+O,d+O*.6),v.moveTo(c+O,d-O*.6),v.lineTo(c-O,d+O*.6),v.stroke({width:$*.09,color:A,cap:"round"}),o.addChild(v);break}default:{const m=$-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"&&r.type!=="storage"&&o.addChild(l),r.type==="creep"&&typeof r.name=="string"){const m=cn(r,t);let k;if(m){const b=typeof r.user=="string"?r.user:void 0;k=b?((M=s==null?void 0:s[b])==null?void 0:M.username)??b:"Hostile"}else k=r.name;const A=m?$t:16777215,w=new Qt({text:k,style:{fontSize:ii,fill:A}});w.scale.set(si),w.anchor.set(.5,1),w.x=c,w.y=uo-ho,w.visible=e,o.__nameLabel=w,o.addChild(w)}return r.type==="creep"&&(o.zIndex=1),r.type==="flag"&&(o.zIndex=10),o.position.set(r.x*$,r.y*$),o}function gr(r){r.destroy({children:!0})}class Ru{constructor(e,t=!0,n,i,s){T(this,"container");T(this,"objects",new Map);T(this,"rawObjects",new Map);T(this,"roadGraphics");T(this,"rampartGraphics");T(this,"ticker",null);T(this,"tickerCallback",null);T(this,"extAnimations",new Map);T(this,"creepFillAnimations",new Map);T(this,"towerFillAnimations",new Map);T(this,"storageFillAnimations",new Map);T(this,"sourceAnimations",new Map);T(this,"buildGlowAnimations",new Map);T(this,"EXT_ANIM_DURATION",300);T(this,"instantMode",!1);T(this,"lastWorldScale",1);T(this,"showLabels");T(this,"currentUserId");T(this,"badge");T(this,"badgeCache",mu);T(this,"users");this.showLabels=t,this.currentUserId=n,this.badge=i,this.users=s,this.container=new Oe,this.container.sortableChildren=!0,this.rampartGraphics=new ee,this.rampartGraphics.zIndex=-1,this.container.addChild(this.rampartGraphics),this.roadGraphics=new ee,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,h=c-l.y;Math.abs(d)<.5&&Math.abs(h)<.5?(l.position.set(a,c),l.__targetX=void 0,l.__targetY=void 0):(l.x+=d*.15,l.y+=h*.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(),n=t/1e3,i=.5+.5*Math.sin(t*2*Math.PI/Su);for(const l of this.objects.values())l.__barrelContainer&&(l.__barrelContainer.rotation=n*.4),l.__csRingGraphics&&l.__csColorDark!==void 0&&l.__csColorLight!==void 0&&vo(l.__csRingGraphics,yo(l.__csColorDark,l.__csColorLight,i));for(const[l,a]of this.extAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;Nn(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*h),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),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;In(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*h),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),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;nn(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*h),d>=1&&this.towerFillAnimations.delete(l)}for(const[l,a]of this.storageFillAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;bi(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*h),d>=1&&this.storageFillAnimations.delete(l)}for(const[l,a]of this.sourceAnimations){const c=t-a.startTime,d=Math.min(1,c/this.EXT_ANIM_DURATION),h=d<.5?2*d*d:1-Math.pow(-2*d+2,2)/2;An(a.visual,a.fromRadius+(a.toRadius-a.fromRadius)*h),d>=1&&this.sourceAnimations.delete(l)}const s=Fi(t);for(const l of this.objects.values()){const a=l.__sourceGraphics;a&&Bi(a,l.__sourceSize??oi,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 h=(t-a.startTime)/a.duration;let f;h<=0?f=0:h<.5?f=h/.5:h<.7?f=1:h<1?f=1-(h-.7)/.3:f=0,d.clear(),f>0&&(d.circle($/2,$/2,$u),d.fill({color:He,alpha:f*.75})),h>=1&&this.buildGlowAnimations.delete(l)}}startExtAnimation(e,t,n,i,s,o){const l=fi(s,o);if(this.instantMode){Nn(t,l);return}const a=fi(n,i);a!==l&&this.extAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}startCreepFillAnimation(e,t,n,i,s,o){const l=hi(s,o);if(this.instantMode){In(t,l);return}const a=hi(n,i);a!==l&&this.creepFillAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}startTowerFillAnimation(e,t,n,i,s,o){const l=yi(s,o);if(this.instantMode){nn(t,l);return}const a=yi(n,i);a!==l&&this.towerFillAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}startStorageFillAnimation(e,t,n,i,s,o){const l=vi(s,o);if(this.instantMode){bi(t,l);return}const a=vi(n,i);a!==l&&this.storageFillAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}startSourceAnimation(e,t,n,i,s,o){const l=li(s,o);if(this.instantMode){An(t,l);return}const a=li(n,i);a!==l&&this.sourceAnimations.set(e,{visual:t,fromRadius:a,toRadius:l,startTime:performance.now()})}update(e,t,n){n&&(this.users=n);let i=!1;if(t)for(const s in t)if(t[s]===null){const l=this.rawObjects.get(s);l&&l.type==="road"&&(i=!0);const a=this.objects.get(s);a&&(this.container.removeChild(a),gr(a),this.objects.delete(s),this.rawObjects.delete(s),this.extAnimations.delete(s),this.creepFillAnimations.delete(s),this.towerFillAnimations.delete(s),this.storageFillAnimations.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)&&(i=!0)}this.rawObjects.set(s,l);const a=this.objects.get(s);if(a){const c=l.x*$,d=l.y*$;if(l.type==="creep"){const h=l.x-(a.__tileX??l.x),f=l.y-(a.__tileY??l.y);(h!==0||f!==0)&&(a.__angle=Math.atan2(f,h),a.__bodyContainer&&(a.__bodyContainer.rotation=a.__angle)),a.__tileX=l.x,a.__tileY=l.y,this.instantMode?(a.position.set(c,d),a.__targetX=void 0,a.__targetY=void 0):(a.x!==c||a.y!==d)&&(a.__targetX=c,a.__targetY=d);const{used:u,capacity:p}=ui(l);(a.__creepUsed!==u||a.__creepCapacity!==p)&&(this.startCreepFillAnimation(s,a,a.__creepUsed??0,a.__creepCapacity??p,u,p),a.__creepUsed=u,a.__creepCapacity=p)}else if(l.type==="flag"){const h=typeof l.color=="number"?l.color:0,f=typeof l.secondaryColor=="number"?l.secondaryColor:0;if(a.__flagColor!==h||a.__flagSecondaryColor!==f){this.container.removeChild(a),gr(a),this.objects.delete(s);const p=Ur(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);p.__tileX=l.x,p.__tileY=l.y,this.applyLabelScale(p),this.objects.set(s,p),this.container.addChild(p)}else a.position.set(c,d)}else a.position.set(c,d);if(l.type==="extension"){const{energy:h,capacity:f}=Jt(l),u=a;(u.__extEnergy!==h||u.__extCapacity!==f)&&(this.startExtAnimation(s,a,u.__extEnergy??0,u.__extCapacity??f,h,f),u.__extEnergy=h,u.__extCapacity=f)}if(l.type==="tower"){const{energy:h,capacity:f}=Jt(l);(a.__towerEnergy!==h||a.__towerCapacity!==f)&&(this.startTowerFillAnimation(s,a,a.__towerEnergy??0,a.__towerCapacity??f,h,f),a.__towerEnergy=h,a.__towerCapacity=f)}if(l.type==="storage"){const{used:h,capacity:f}=xo(l);(a.__storageUsed!==h||a.__storageCapacity!==f)&&(this.startStorageFillAnimation(s,a,a.__storageUsed??0,a.__storageCapacity??f,h,f),a.__storageUsed=h,a.__storageCapacity=f)}if(l.type==="controller"){const h=typeof l.level=="number"?l.level:0,f=typeof l.progress=="number"?l.progress:0,u=typeof l.progressTotal=="number"?l.progressTotal:0;(a.__ctrlLevel!==h||a.__ctrlProgress!==f||a.__ctrlProgressTotal!==u)&&(a.__ctrlSegGraphics&&_i(a.__ctrlSegGraphics,$/2,$/2,xi,Ke,h,f,u),a.__ctrlLevel=h,a.__ctrlProgress=f,a.__ctrlProgressTotal=u)}if(l.type==="source"){const{energy:h,capacity:f}=ai(l);(a.__sourceEnergy!==h||a.__sourceCapacity!==f)&&(this.startSourceAnimation(s,a,a.__sourceEnergy??0,a.__sourceCapacity??f,h,f),a.__sourceEnergy=h,a.__sourceCapacity=f)}if(l.type==="constructionSite"){const h=typeof l.progress=="number"?l.progress:0,f=typeof l.progressTotal=="number"?l.progressTotal:1;(a.__csProgress!==h||a.__csProgressTotal!==f)&&(a.__csFillGraphics&&di(a.__csFillGraphics,$/2,$/2,ci,h,f,a.__csColor??Cr),a.__csProgress=h,a.__csProgressTotal=f)}}else{const c=Ur(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*$,d=l.y*$;if(l.type==="creep"){const h=l.x-(a.__tileX??l.x),f=l.y-(a.__tileY??l.y);(h!==0||f!==0)&&(a.__angle=Math.atan2(f,h),a.__bodyContainer&&(a.__bodyContainer.rotation=a.__angle)),a.__tileX=l.x,a.__tileY=l.y,this.instantMode?(a.position.set(c,d),a.__targetX=void 0,a.__targetY=void 0):(a.x!==c||a.y!==d)&&(a.__targetX=c,a.__targetY=d);const{used:u,capacity:p}=ui(l);(a.__creepUsed!==u||a.__creepCapacity!==p)&&(this.startCreepFillAnimation(o,a,a.__creepUsed??0,a.__creepCapacity??p,u,p),a.__creepUsed=u,a.__creepCapacity=p)}else if(l.type==="flag"){const h=typeof l.color=="number"?l.color:0,f=typeof l.secondaryColor=="number"?l.secondaryColor:0;if(a.__flagColor!==h||a.__flagSecondaryColor!==f){this.container.removeChild(a),gr(a),this.objects.delete(o);const p=Ur(l,this.showLabels,this.currentUserId,this.badge,this.badgeCache,this.users);p.__tileX=l.x,p.__tileY=l.y,this.applyLabelScale(p),this.objects.set(o,p),this.container.addChild(p)}else a.position.set(c,d)}else a.position.set(c,d);if(l.type==="extension"){const{energy:h,capacity:f}=Jt(l),u=a;(u.__extEnergy!==h||u.__extCapacity!==f)&&(this.startExtAnimation(o,a,u.__extEnergy??0,u.__extCapacity??f,h,f),u.__extEnergy=h,u.__extCapacity=f)}if(l.type==="tower"){const{energy:h,capacity:f}=Jt(l);(a.__towerEnergy!==h||a.__towerCapacity!==f)&&(this.startTowerFillAnimation(o,a,a.__towerEnergy??0,a.__towerCapacity??f,h,f),a.__towerEnergy=h,a.__towerCapacity=f)}if(l.type==="controller"){const h=typeof l.level=="number"?l.level:0,f=typeof l.progress=="number"?l.progress:0,u=typeof l.progressTotal=="number"?l.progressTotal:0;(a.__ctrlLevel!==h||a.__ctrlProgress!==f||a.__ctrlProgressTotal!==u)&&(a.__ctrlSegGraphics&&_i(a.__ctrlSegGraphics,$/2,$/2,xi,Ke,h,f,u),a.__ctrlLevel=h,a.__ctrlProgress=f,a.__ctrlProgressTotal=u)}if(l.type==="source"){const{energy:h,capacity:f}=ai(l);(a.__sourceEnergy!==h||a.__sourceCapacity!==f)&&(this.startSourceAnimation(o,a,a.__sourceEnergy??0,a.__sourceCapacity??f,h,f),a.__sourceEnergy=h,a.__sourceCapacity=f)}if(l.type==="constructionSite"){const h=typeof l.progress=="number"?l.progress:0,f=typeof l.progressTotal=="number"?l.progressTotal:1;(a.__csProgress!==h||a.__csProgressTotal!==f)&&(a.__csFillGraphics&&di(a.__csFillGraphics,$/2,$/2,ci,h,f,a.__csColor??Cr),a.__csProgress=h,a.__csProgressTotal=f)}}else{const c=Ur(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),gr(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));i=!0}this.redrawRamparts(),i&&this.redrawRoads(),this.refreshForeignCreepLabels(),this.refreshForeignCreepBadges()}redrawRoads(){this.roadGraphics.clear();const e=ao,t=Array.from({length:50},()=>new Array(50).fill(!1)),n=[];for(const a of this.rawObjects.values())a.type==="road"&&(n.push(a),a.x>=0&&a.x<50&&a.y>=0&&a.y<50&&(t[a.x][a.y]=!0));if(n.length===0)return;const i=$/2,s=$/2,o=$*.125;for(const a of n)this.roadGraphics.circle(a.x*$+i,a.y*$+s,o);this.roadGraphics.fill(e);const l=[[1,0],[1,1],[0,1],[-1,1]];for(const a of n){const c=a.x*$+i,d=a.y*$+s;for(const[h,f]of l){const u=a.x+h,p=a.y+f;if(u>=0&&u<50&&p>=0&&p<50&&t[u][p]){const x=u*$+i,M=p*$+s;this.roadGraphics.moveTo(c,d),this.roadGraphics.lineTo(x,M)}}}this.roadGraphics.stroke({width:o*2,color:e})}redrawRamparts(){this.rampartGraphics.clear();const e=$,t=e/2,n=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&&(n[s.x][s.y]=typeof s.user=="string"?s.user:void 0);const i=s=>!s||!this.currentUserId?{color:os,alpha:.7}:s===this.currentUserId?{color:os,alpha:.7}:{color:7807522,alpha:.5};for(let s=0;s<50;s++)for(let o=0;o<50;o++){const l=n[o][s],a=l!==void 0,c=s>0&&n[o][s-1]!==void 0,d=s<49&&n[o][s+1]!==void 0,h=o>0&&n[o-1][s]!==void 0,f=o<49&&n[o+1][s]!==void 0,u=o*e+t,p=s*e+t;if(a){const x=i(l);!c&&!h&&s>0&&o>0?(this.rampartGraphics.moveTo(u,s*e),this.rampartGraphics.arc(u,p,t,-Math.PI/2,Math.PI,!0),this.rampartGraphics.lineTo(u,p),this.rampartGraphics.fill(x)):(this.rampartGraphics.rect(o*e,s*e,t,t),this.rampartGraphics.fill(x))}else if(c&&h&&n[o-1][s-1]!==void 0){const x=i(n[o-1][s-1]);this.rampartGraphics.moveTo(u,s*e),this.rampartGraphics.lineTo(o*e,s*e),this.rampartGraphics.lineTo(o*e,p),this.rampartGraphics.arc(u,p,t,Math.PI,-Math.PI/2,!1),this.rampartGraphics.fill(x)}if(a){const x=i(l);!c&&!f&&s>0&&o<49?(this.rampartGraphics.moveTo(u,s*e),this.rampartGraphics.arc(u,p,t,-Math.PI/2,0,!1),this.rampartGraphics.lineTo(u,p),this.rampartGraphics.fill(x)):(this.rampartGraphics.rect(u,s*e,t,t),this.rampartGraphics.fill(x))}else if(c&&f&&n[o+1][s-1]!==void 0){const x=i(n[o+1][s-1]);this.rampartGraphics.moveTo(u,s*e),this.rampartGraphics.lineTo(o*e+e,s*e),this.rampartGraphics.lineTo(o*e+e,p),this.rampartGraphics.arc(u,p,t,0,-Math.PI/2,!0),this.rampartGraphics.fill(x)}if(a){const x=i(l);!d&&!h&&s<49&&o>0?(this.rampartGraphics.moveTo(o*e,p),this.rampartGraphics.arc(u,p,t,Math.PI,Math.PI/2,!0),this.rampartGraphics.lineTo(u,p),this.rampartGraphics.fill(x)):(this.rampartGraphics.rect(o*e,p,t,t),this.rampartGraphics.fill(x))}else if(d&&h&&n[o-1][s+1]!==void 0){const x=i(n[o-1][s+1]);this.rampartGraphics.moveTo(o*e,p),this.rampartGraphics.lineTo(o*e,s*e+e),this.rampartGraphics.lineTo(u,s*e+e),this.rampartGraphics.arc(u,p,t,Math.PI/2,Math.PI,!1),this.rampartGraphics.fill(x)}if(a){const x=i(l);!d&&!f&&s<49&&o<49?(this.rampartGraphics.moveTo(u,s*e+e),this.rampartGraphics.arc(u,p,t,Math.PI/2,0,!0),this.rampartGraphics.lineTo(u,p),this.rampartGraphics.fill(x)):(this.rampartGraphics.rect(u,p,t,t),this.rampartGraphics.fill(x))}else if(d&&f&&n[o+1][s+1]!==void 0){const x=i(n[o+1][s+1]);this.rampartGraphics.moveTo(u,s*e+e),this.rampartGraphics.lineTo(o*e+e,s*e+e),this.rampartGraphics.lineTo(o*e+e,p),this.rampartGraphics.arc(u,p,t,0,Math.PI/2,!1),this.rampartGraphics.fill(x)}}}getObjectsAtTile(e,t){const n=[];for(const[i,s]of this.objects){const o=this.rawObjects.get(i);o&&o.x===e&&o.y===t&&n.push({id:i,obj:o,visual:s})}return n}applyLabelScale(e){if(!e.__nameLabel)return;const t=this.lastWorldScale||1;e.__nameLabel.scale.set(si/t),e.__nameLabel.anchor.y===0?e.__nameLabel.y=$/2+$*.55:e.__nameLabel.y=uo-ho/t}refreshForeignCreepLabels(){var e,t;if(this.currentUserId)for(const[n,i]of this.objects){const s=this.rawObjects.get(n);if(!s||s.type!=="creep"||!i.__nameLabel||!cn(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";i.__nameLabel.text!==l&&(i.__nameLabel.text=l)}}refreshForeignCreepBadges(){var e,t;if(this.currentUserId)for(const[n,i]of this.objects){const s=this.rawObjects.get(n);if(!s||s.type!=="creep"||!cn(s,this.currentUserId)||i.__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=i.__bodyContainer;if(!a)continue;i.__creepForeignMark&&!i.__creepForeignMark.destroyed&&(a.removeChild(i.__creepForeignMark),i.__creepForeignMark.destroy(),i.__creepForeignMark=void 0);const c=new tr;c.anchor.set(.5,.5);const d=je*2;c.width=d,c.height=d,c.rotation=Math.PI/2,a.addChild(c),i.__creepBadgeSprite=c,this.badgeCache.getOrCreate(l).then(h=>{c.destroyed||(c.texture=h)}).catch(()=>{c.destroyed||(a.removeChild(c),c.destroy()),i.__creepBadgeSprite=void 0})}}triggerBuildAt(e,t,n){if(!this.instantMode)for(const[i,s]of this.objects){const o=this.rawObjects.get(i);if(!(!o||o.type!=="constructionSite")&&!(o.x!==e||o.y!==t)&&s.__csBuildGlow){this.buildGlowAnimations.set(i,{startTime:performance.now(),duration:n});return}}}setInstantMode(e){if(this.instantMode=e,!!e){for(const t of this.objects.values())t.__targetX!==void 0&&(t.position.set(t.__targetX,t.__targetY),t.__targetX=void 0,t.__targetY=void 0);for(const t of this.extAnimations.values())Nn(t.visual,t.toRadius);this.extAnimations.clear();for(const t of this.creepFillAnimations.values())In(t.visual,t.toRadius);this.creepFillAnimations.clear();for(const t of this.towerFillAnimations.values())nn(t.visual,t.toRadius);this.towerFillAnimations.clear();for(const t of this.sourceAnimations.values())An(t.visual,t.toRadius);this.sourceAnimations.clear(),this.buildGlowAnimations.clear()}}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())gr(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(),this.container.addChild(this.rampartGraphics),this.container.addChild(this.roadGraphics)}destroy(){this.clear(),this.ticker&&this.tickerCallback&&this.ticker.remove(this.tickerCallback),this.ticker=null,this.tickerCallback=null}}const Gn=2;function Ft(r,e){return{cx:r*$+$/2,cy:e*$+$/2}}class Pu{constructor(e){T(this,"container");T(this,"graphics");T(this,"animations",[]);T(this,"ticker",null);T(this,"tickerCallback",null);this.container=new Oe,this.graphics=new ee,this.container.addChild(this.graphics),e&&(this.ticker=e,this.tickerCallback=()=>this.animate(),e.add(this.tickerCallback))}addHarvest(e,t,n,i,s){const o=Ft(e,t),l=Ft(n,i);this.animations.push({fromX:o.cx,fromY:o.cy,toX:l.cx,toY:l.cy,startTime:performance.now(),duration:s,color:Jd,width:Gn})}addUpgradeController(e,t,n,i,s){const o=Ft(e,t),l=Ft(n,i);this.animations.push({fromX:o.cx,fromY:o.cy,toX:l.cx,toY:l.cy,startTime:performance.now(),duration:s,color:Qd,width:Gn})}addBuild(e,t,n,i,s){const o=Ft(e,t),l=Ft(n,i);this.animations.push({fromX:o.cx,fromY:o.cy,toX:l.cx,toY:l.cy,startTime:performance.now(),duration:s,color:eu,width:Gn})}animate(){this.graphics.clear();const e=performance.now();let t=!1;for(let n=this.animations.length-1;n>=0;n--){const i=this.animations[n],s=e-i.startTime,o=Math.min(1,s/i.duration);let l,a,c,d;const h=.5,f=.2;if(o<h){const u=o/h;l=i.fromX,a=i.fromY,c=i.fromX+(i.toX-i.fromX)*u,d=i.fromY+(i.toY-i.fromY)*u}else if(o<h+f)l=i.fromX,a=i.fromY,c=i.toX,d=i.toY;else{const u=(o-h-f)/(1-h-f);l=i.fromX+(i.toX-i.fromX)*u,a=i.fromY+(i.toY-i.fromY)*u,c=i.toX,d=i.toY}this.graphics.moveTo(l,a),this.graphics.lineTo(c,d),this.graphics.stroke({width:i.width,color:i.color}),t=!0,o>=1&&this.animations.splice(n,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 Ce=r=>(r+.5)*$,mr=4,Xr={dashed:[.4*$,.4*$],dotted:[.1*$,.3*$]};function jr(r,e,t,n){let i=!0,s=t;for(let o=0;o<e.length-1;o++){const[l,a]=e[o],[c,d]=e[o+1],h=c-l,f=d-a,u=Math.sqrt(h*h+f*f);if(u<.001)continue;const p=h/u,x=f/u;let M=0;for(;M<u;){const m=Math.min(s,u-M);if(i){const k=l+p*M,A=a+x*M;r.moveTo(k,A),r.lineTo(k+p*m,A+x*m)}M+=m,s-=m,s<.001&&(i=!i,s=i?t:n)}}}function Ou(r,e,t){const n=Math.max(32,Math.ceil(2*Math.PI*t/2)),i=[];for(let s=0;s<=n;s++){const o=s/n*2*Math.PI;i.push([r+Math.cos(o)*t,e+Math.sin(o)*t])}return i}function Lu(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/$:t}function Au(r){if(typeof r!="string")return"Arial";const e=r.match(/^[0-9.]+(px)?\s+(.+)$/);return e?e[2]:"Arial"}class Iu{constructor(){T(this,"container");T(this,"g");this.container=new Oe,this.container.label="visuals",this.g=new ee,this.container.addChild(this.g)}update(e){const t=this.container.removeChildren();for(const i of t)i!==this.g&&i.destroy();if(this.g.clear(),this.container.addChild(this.g),!e)return;const n=this.g;for(const i of e.split(`
9
+ `)){if(!i.trim())continue;let s;try{s=JSON.parse(i)}catch{continue}const o=s.s??{},l=o.opacity??1;switch(s.t){case"l":this.drawLine(n,s,o,l);break;case"c":this.drawCircle(n,s,o,l);break;case"r":this.drawRect(n,s,o,l);break;case"p":this.drawPoly(n,s,o,l);break;case"t":this.drawText(s,o,l);break}}}drawLine(e,t,n,i){const s=Ce(t.x1),o=Ce(t.y1),l=Ce(t.x2),a=Ce(t.y2),c=n.color??"#ffffff",d=(n.width??.1)*$;if(n.lineStyle&&n.lineStyle!=="solid"){const[h,f]=Xr[n.lineStyle];jr(e,[[s,o],[l,a]],h,f)}else e.moveTo(s,o),e.lineTo(l,a);e.stroke({color:c,width:d,alpha:i})}drawCircle(e,t,n,i){const s=Ce(t.x),o=Ce(t.y),l=(n.radius??.5)*$,a=!!(n.fill&&n.fill!=="transparent"),c=!!(n.stroke&&n.strokeWidth),d=n.lineStyle&&n.lineStyle!=="solid";if(a&&(e.circle(s,o,l),e.fill({color:n.fill,alpha:i})),c){const h=n.strokeWidth*$;if(d){const[f,u]=Xr[n.lineStyle];jr(e,Ou(s,o,l),f,u)}else e.circle(s,o,l);e.stroke({color:n.stroke,width:h,alpha:i})}}drawRect(e,t,n,i){const s=Ce(t.x),o=Ce(t.y),l=t.w*$,a=t.h*$,c=!!(n.fill&&n.fill!=="transparent"),d=!!(n.stroke&&n.strokeWidth),h=n.lineStyle&&n.lineStyle!=="solid";if(c&&(e.rect(s,o,l,a),e.fill({color:n.fill,alpha:i})),d){const f=n.strokeWidth*$;if(h){const[u,p]=Xr[n.lineStyle],x=[[s,o],[s+l,o],[s+l,o+a],[s,o+a],[s,o]];jr(e,x,u,p)}else e.rect(s,o,l,a);e.stroke({color:n.stroke,width:f,alpha:i})}}drawPoly(e,t,n,i){if(!t.points||t.points.length===0)return;const s=!!(n.fill&&n.fill!=="transparent"),o=!!(n.stroke&&n.strokeWidth);if(!s&&!o)return;const l=n.lineStyle&&n.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[h,f]=t.points[d],u=Ce(h),p=Ce(f);a[d*2]=u,a[d*2+1]=p,c&&(c[d]=[u,p])}if(s&&(e.poly(a,!0),e.fill({color:n.fill,alpha:i})),o){const d=n.strokeWidth*$;if(l&&c){const[h,f]=Xr[n.lineStyle],u=c[0],p=c[c.length-1],x=u[0]===p[0]&&u[1]===p[1];jr(e,x?c:[...c,u],h,f)}else e.poly(a,!0);e.stroke({color:n.stroke,width:d,alpha:i})}}drawText(e,t,n){const i=Lu(t.font),s=Au(t.font),o=t.align??"left",l=new pl({fill:t.color??"#ffffff",fontSize:Math.round(i*$*mr),fontFamily:s,align:o,...t.stroke&&t.strokeWidth?{stroke:{color:t.stroke,width:t.strokeWidth*$*mr}}:{}});if(t.backgroundColor&&t.backgroundColor!=="transparent"){const c=gl.measureText(e.text,l),d=c.width/mr,h=c.height/mr,f=(t.backgroundPadding??.3)*$,u=o==="center"?.5:o==="right"?1:0,p=Ce(e.x)-u*d-f,x=Ce(e.y)-h/2-f,M=new ee;M.rect(p,x,d+f*2,h+f*2),M.fill({color:t.backgroundColor,alpha:n}),this.container.addChild(M)}const a=new Qt({text:e.text,style:l});a.scale.set(1/mr),a.anchor.x=o==="center"?.5:o==="right"?1:0,a.anchor.y=.5,a.position.set(Ce(e.x),Ce(e.y)),a.alpha=n,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 ar(r,e){const t=localStorage.getItem(r),[n,i]=G(t!==null?t==="true":e);return[n,s=>{i(s),localStorage.setItem(r,String(s))}]}const[_o,Nu]=ar(fe.widescreenMode,!0),[dn,$o]=ar(fe.showCreepLabels,!0),[So,ko]=ar(fe.showMapRoomNames,!1),[Co,To]=ar(fe.showUnclaimableRooms,!0),[sn,Gu]=ar(fe.terrainEffects,!0),[Mo,Du]=ar(fe.showRoomVisuals,!0),$i=Symbol("store-raw"),er=Symbol("store-node"),Je=Symbol("store-has"),Eo=Symbol("store-self");function Ro(r){let e=r[Lt];if(!e&&(Object.defineProperty(r,Lt,{value:e=new Proxy(r,Fu)}),!Array.isArray(r))){const t=Object.keys(r),n=Object.getOwnPropertyDescriptors(r),i=Object.getPrototypeOf(r),s=i!==null&&r!==null&&typeof r=="object"&&!Array.isArray(r)&&i!==Object.prototype;if(s){const o=Object.getOwnPropertyDescriptors(i);t.push(...Object.keys(o)),Object.assign(n,o)}for(let o=0,l=t.length;o<l;o++){const a=t[o];s&&a==="constructor"||n[a].get&&Object.defineProperty(r,a,{configurable:!0,enumerable:n[a].enumerable,get:n[a].get.bind(e)})}}return e}function gt(r){let e;return r!=null&&typeof r=="object"&&(r[Lt]||!(e=Object.getPrototypeOf(r))||e===Object.prototype||Array.isArray(r))}function rr(r,e=new Set){let t,n,i,s;if(t=r!=null&&r[$i])return t;if(!gt(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++)i=r[o],(n=rr(i,e))!==i&&(r[o]=n)}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&&(i=r[s],(n=rr(i,e))!==i&&(r[s]=n))}return r}function un(r,e){let t=r[e];return t||Object.defineProperty(r,e,{value:t=Object.create(null)}),t}function Rr(r,e,t){if(r[e])return r[e];const[n,i]=G(t,{equals:!1,internal:!0});return n.$=i,r[e]=n}function zu(r,e){const t=Reflect.getOwnPropertyDescriptor(r,e);return!t||t.get||!t.configurable||e===Lt||e===er||(delete t.value,delete t.writable,t.get=()=>r[Lt][e]),t}function Po(r){Qn()&&Rr(un(r,er),Eo)()}function Bu(r){return Po(r),Reflect.ownKeys(r)}const Fu={get(r,e,t){if(e===$i)return r;if(e===Lt)return t;if(e===Xi)return Po(r),t;const n=un(r,er),i=n[e];let s=i?i():r[e];if(e===er||e===Je||e==="__proto__")return s;if(!i){const o=Object.getOwnPropertyDescriptor(r,e);Qn()&&(typeof s!="function"||r.hasOwnProperty(e))&&!(o&&o.get)&&(s=Rr(n,e,s)())}return gt(s)?Ro(s):s},has(r,e){return e===$i||e===Lt||e===Xi||e===er||e===Je||e==="__proto__"?!0:(Qn()&&Rr(un(r,Je),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:Bu,getOwnPropertyDescriptor:zu};function Ie(r,e,t,n=!1){if(e==="__proto__"){console.warn('Refusing to set "__proto__" on a store.');return}if(!n&&r[e]===t)return;const i=r[e],s=r.length;t===void 0?(delete r[e],r[Je]&&r[Je][e]&&i!==void 0&&r[Je][e].$()):(r[e]=t,r[Je]&&r[Je][e]&&i===void 0&&r[Je][e].$());let o=un(r,er),l;if((l=Rr(o,e,i))&&l.$(()=>t),Array.isArray(r)&&r.length!==s){for(let a=r.length;a<s;a++)(l=o[a])&&l.$();(l=Rr(o,"length",s))&&l.$(r.length)}(l=o[Eo])&&l.$()}function Oo(r,e){const t=Object.keys(e);for(let n=0;n<t.length;n+=1){const i=t[n];Lo(i)||Ie(r,i,e[i])}}function Lo(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function Hu(r,e){if(typeof e=="function"&&(e=e(r)),e=rr(e),Array.isArray(e)){if(r===e)return;let t=0,n=e.length;for(;t<n;t++){const i=e[t];r[t]!==i&&Ie(r,t,i)}Ie(r,"length",n)}else Oo(r,e)}function _r(r,e,t=[]){let n,i=r;if(e.length>1){n=e.shift();const o=typeof n,l=Array.isArray(r);if(o==="string"&&(n==="__proto__"||e.length>1&&Lo(n))){console.warn(`Refusing to traverse unsafe key "${n}" on a store.`);return}if(Array.isArray(n)){for(let a=0;a<n.length;a++)_r(r,[n[a]].concat(e),t);return}else if(l&&o==="function"){for(let a=0;a<r.length;a++)n(r[a],a)&&_r(r,[a].concat(e),t);return}else if(l&&o==="object"){const{from:a=0,to:c=r.length-1,by:d=1}=n;for(let h=a;h<=c;h+=d)_r(r,[h].concat(e),t);return}else if(e.length>1){_r(r[n],e,[n].concat(t));return}i=r[n],t=[n].concat(t)}let s=e[0];typeof s=="function"&&(s=s(i,t),s===i)||n===void 0&&s==null||(s=rr(s),n===void 0||gt(i)&&gt(s)&&!Array.isArray(s)?Oo(i,s):Ie(r,n,s))}function Ao(...[r,e]){const t=rr(r||{}),n=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 i=Ro(t);cl.registerGraph({value:t,name:e&&e.name});function s(...o){dl(()=>{n&&o.length===1?Hu(t,o[0]):_r(t,o)})}return[i,s]}const Si=Symbol("store-root");function us(r){return r==="__proto__"||r==="constructor"||r==="prototype"}function jt(r,e,t,n,i){if(us(t))return;const s=e[t];if(r===s)return;const o=Array.isArray(r);if(t!==Si&&(!gt(r)||!gt(s)||o!==Array.isArray(s)||i&&r[i]!==s[i])){Ie(e,t,r);return}if(o){if(r.length&&s.length&&(!n||i&&r[0]&&r[0][i]!=null)){let c,d,h,f,u,p,x,M;for(h=0,f=Math.min(s.length,r.length);h<f&&(s[h]===r[h]||i&&s[h]&&r[h]&&s[h][i]&&s[h][i]===r[h][i]);h++)jt(r[h],s,h,n,i);const m=new Array(r.length),k=new Map;for(f=s.length-1,u=r.length-1;f>=h&&u>=h&&(s[f]===r[u]||i&&s[f]&&r[u]&&s[f][i]&&s[f][i]===r[u][i]);f--,u--)m[u]=s[f];if(h>u||h>f){for(d=h;d<=u;d++)Ie(s,d,r[d]);for(;d<r.length;d++)Ie(s,d,m[d]),jt(r[d],s,d,n,i);s.length>r.length&&Ie(s,"length",r.length);return}for(x=new Array(u+1),d=u;d>=h;d--)p=r[d],M=i&&p?p[i]:p,c=k.get(M),x[d]=c===void 0?-1:c,k.set(M,d);for(c=h;c<=f;c++)p=s[c],M=i&&p?p[i]:p,d=k.get(M),d!==void 0&&d!==-1&&(m[d]=s[c],d=x[d],k.set(M,d));for(d=h;d<r.length;d++)d in m?(Ie(s,d,m[d]),jt(r[d],s,d,n,i)):Ie(s,d,r[d])}else for(let c=0,d=r.length;c<d;c++)jt(r[c],s,c,n,i);s.length>r.length&&Ie(s,"length",r.length);return}const l=Object.keys(r);for(let c=0,d=l.length;c<d;c++)us(l[c])||jt(r[l[c]],s,l[c],n,i);const a=Object.keys(s);for(let c=0,d=a.length;c<d;c++)r[a[c]]===void 0&&Ie(s,a[c],void 0)}function Wu(r,e={}){const{merge:t,key:n="id"}=e,i=rr(r);return s=>{if(!gt(s)||!gt(i))return i;const o=jt(i,{[Si]:s},Si,t,n);return o===void 0?s:o}}const Hi=new WeakMap;function hs(r,e){const[t,n]=Ao(e),i={id:r,type:e.type,raw:t};return Hi.set(i,s=>n(Wu(s,{key:"_id",merge:!1}))),i}const[nr,ir]=G([]);function Uu(){ir([])}function Yr(r){ir(e=>e.filter(t=>t.id!==r))}function Xu(r,e){const t=nr();let n=!1;const i=[];for(const s of t){const o=r[s.id];if(o===null){n=!0;continue}if(o!==void 0){const l=e[s.id];if(l){const a=Hi.get(s);a==null||a(l)}}i.push(s)}n&&ir(i)}function ju(r){var i;const e=nr();if(e.length===0)return;let t=!1;const n=[];for(const s of e){const o=r[s.id];if(!o){t=!0;continue}(i=Hi.get(s))==null||i(o),n.push(s)}t&&ir(n)}const[Yu,Dn]=G(null),[hn,zn]=G(null),[Ee,Bn]=G(null),[fs,Fn]=G(null),[fn,Hn]=G({}),[Io,ps]=G(null),[No,Vu]=G(null),[qu,Zu]=G(null);function ki(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 tt(r){const e=r.match(/^([WE])(\d+)([NS])(\d+)$/);if(!e)return null;const[,t,n,i,s]=e,o=t==="W"?-(parseInt(n,10)+1):parseInt(n,10),l=i==="N"?-(parseInt(s,10)+1):parseInt(s,10);return{x:o,y:l}}function ze(r,e){const t=r<0?"W":"E",n=e<0?"N":"S",i=r<0?-r-1:r,s=e<0?-e-1:e;return`${t}${i}${n}${s}`}function gs(r){return r===0||r<0&&(r+1)%10===0||r>0&&r%10===0}function i0(r,e){return gs(r)||gs(e)}function s0(r,e){const t=r<0?Math.abs(r+1)%10:Math.abs(r)%10,n=e<0?Math.abs(e+1)%10:Math.abs(e)%10;return t>=4&&t<=6&&n>=4&&n<=6}function Go(r){const e=r;if(!e)return!1;const t=e.tagName??"";return t==="INPUT"||t==="TEXTAREA"?!0:e.isContentEditable===!0}function Ku(r){const e=t=>{if(Go(t.target))return;const n=r.currentRoom(),i=n?tt(n):null;if(!i)return;const s=r.worldBounds(),o=(l,a)=>!s||ki(l,a,s);switch(t.key){case"ArrowLeft":t.preventDefault(),o(i.x-1,i.y)&&r.onMove(i.x-1,i.y);break;case"ArrowRight":t.preventDefault(),o(i.x+1,i.y)&&r.onMove(i.x+1,i.y);break;case"ArrowUp":t.preventDefault(),o(i.x,i.y-1)&&r.onMove(i.x,i.y-1);break;case"ArrowDown":t.preventDefault(),o(i.x,i.y+1)&&r.onMove(i.x,i.y+1);break}};window.addEventListener("keydown",e),Pe(()=>window.removeEventListener("keydown",e))}const[ue,Do]=G(!1),[it,Wi]=G(0),[Ci,Ju]=G(0),[Pr,zo]=G(0),[Tr,Or]=G(!1),[Ui,Qu]=G(1),[Xe,Wn]=G(!1);let on=null;function Lr(){on!==null&&(clearInterval(on),on=null)}function Bo(){Lr(),on=setInterval(()=>{const r=it()+1;r>Pr()?(Lr(),Or(!1)):Wi(r)},Math.max(50,Math.round(1e3/Ui())))}function Fo(r){const e=r,t=Math.max(0,e-2e5);zo(e),Ju(t),Wi(r),Or(!1),Lr(),Do(!0)}function pn(){Lr(),Or(!1),Do(!1)}function gn(r){const e=Math.max(Ci(),Math.min(Pr(),r));Wi(e)}function ms(r){gn(it()+r)}function eh(){Tr()?(Lr(),Or(!1)):(Or(!0),Bo())}function th(r){Qu(r),Tr()&&Bo()}class rh{constructor(e,t,n,i,s,o){T(this,"chunkCache",new Map);T(this,"inflight",new Map);this.room=e,this.shard=t,this.baseUrl=n,this.getToken=i,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`}loadChunk(e){const t=this.chunkCache.get(e);if(t)return Promise.resolve(t);const n=this.inflight.get(e);if(n)return n;const i=this.buildUrl(e),s=this.getToken(),o={};s&&(o["X-Token"]=s,o["X-Username"]=s);const l=fetch(i,{headers:o}).then(a=>{if(!a.ok)throw new Error(`HTTP ${a.status}`);return a.json()}).then(a=>(this.chunkCache.set(e,a),this.inflight.delete(e),a)).catch(a=>{throw this.inflight.delete(e),a});return this.inflight.set(e,l),l}applyDiff(e,t){const n={...e};for(const i in t){const s=t[i];s===null?delete n[i]:n[i]?n[i]={...n[i],...s}:n[i]=s}return n}async getStateAtTick(e){let t=this.chunkBase(e),n,i;try{n=await this.loadChunk(t)}catch{const l=t-this.chunkSize;if(l<0)throw new Error(`No history data available before tick ${t}`);n=await this.loadChunk(l),t=l;const a=Object.keys(n.ticks).map(Number).filter(d=>d>=t),c=a.length>0?Math.max(...a):t;i=c,e=c}const s=n.ticks[String(t)]??{};let o={};for(const l in s)s[l]!==null&&(o[l]=s[l]);for(let l=t+1;l<=e;l++){const a=n.ticks[String(l)];a&&Object.keys(a).length>0&&(o=this.applyDiff(o,a))}return{objects:o,diff:n.ticks[String(e)]??{},gameTime:e,clampedTo:i}}}var nh=R('<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'),ih=R('<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'),sh=R("<div style=display:flex;flex-direction:column;gap:2px;text-align:center><span>Choose new flag position</span><span style=opacity:0.6;font-size:0.9em>Right-click to cancel"),oh=R("<div style=display:flex;flex-direction:column;gap:2px;text-align:center><span></span><span style=opacity:0.6;font-size:0.9em>Right-click to exit flag mode"),lh=R("<div style=display:flex;flex-direction:column;gap:2px;text-align:center><span>Select a structure type, then click to build</span><span style=opacity:0.6;font-size:0.9em>Ctrl+click to remove construction sites</span><span style=opacity:0.6;font-size:0.9em>Right-click to exit build mode"),ah=R("<div style=display:flex;flex-direction:column;gap:2px;text-align:center><span></span><span style=opacity:0.6;font-size:0.9em>Ctrl+click to remove construction sites</span><span style=opacity:0.6;font-size:0.9em>Right-click to exit build mode");const{log:ys,warn:ch,error:vs}=yt("build"),Ar={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},mn={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}},[pt,Tt]=G("view"),[Yt,Ho]=G({name:"",color:"COLOR_WHITE",secondaryColor:"COLOR_WHITE"}),[Pt,Ti]=G(null),[yn,Mi]=G(null),[rt,Mt]=G({structureType:"",structureName:""});Oi(()=>{de(()=>{const r=rt().structureType;if(!r)return;const e=Ee()??0,t=mn[r];if(!t)return;const n=At()==="empty"&&r==="spawn"?Math.max(t[e]??0,1):t[e]??0;if(n===2500)return;(fn()[r]??0)>=n&&(Mt({structureType:"",structureName:""}),ft())})});function ft(){Ti(null)}function Ei(){Mi(null)}function dh(){Mt({structureType:"",structureName:""})}function uh(r,e){const t=ae(),n=rt(),i=Pt();if(!t||!n.structureType||!i){ch("missing requirements",{hasClient:!!t,structureType:n.structureType,pending:i});return}if(At()==="empty"&&n.structureType==="spawn"){ys("placing spawn",{room:r,x:i.tx,y:i.ty,name:n.structureName||void 0,shard:e??void 0}),t.http.game.placeSpawn(r,i.tx,i.ty,n.structureName||void 0,e??void 0).then(()=>(we("Spawn placed successfully","success"),ft(),t.stores.user.refreshWorldStatus())).catch(s=>{vs("place spawn failed:",s),we(`Failed to place spawn: ${s.message}`,"error")});return}ys("creating construction site",{room:r,x:i.tx,y:i.ty,structureType:n.structureType,name:n.structureName||void 0,shard:e??void 0}),t.http.game.createConstruction(r,i.tx,i.ty,n.structureType,n.structureName||void 0,e??void 0).then(()=>{we(`Construction site for ${n.structureType} created`,"success"),ft()}).catch(s=>{vs("create construction failed:",s),we(`Failed to create construction site: ${s.message}`,"error")})}function bs(){Tt("view"),ft(),Ei(),dh()}function ws(){const r=pt(),e=Pt(),t=yn(),n=At();if(n==="empty")return(()=>{var i=nh(),s=i.firstChild,o=s.nextSibling;return o.$$click=()=>{Tt("build"),Mt({structureType:"spawn",structureName:""})},i})();if(n==="lost")return(()=>{var i=ih(),s=i.firstChild,o=s.nextSibling;return o.$$click=()=>{const l=ae();l&&l.http.user.respawn().then(()=>{we("Respawn successful","success"),l.stores.user.refreshWorldStatus()}).catch(a=>{we(`Respawn failed: ${a.message}`,"error")})},i})();if((t==null?void 0:t.type)==="moveFlag")return(()=>{var i=sh(),s=i.firstChild;return s.nextSibling,i})();if(r==="flag")return(()=>{var i=oh(),s=i.firstChild;return s.nextSibling,g(s,e?"Click again to confirm position":"Click to choose flag position"),i})();if(r==="build"){const i=rt(),s=Ee(),o=fn(),l=i.structureType;if(!l)return(()=>{var u=lh(),p=u.firstChild,x=p.nextSibling;return x.nextSibling,u})();const a=mn[l],c=(a==null?void 0:a[s??0])??0,d=o[l]??0,h=l.replace(/([A-Z])/g," $1").trim(),f=c===2500?`${d}/∞`:`${d}/${c}`;return(()=>{var u=ah(),p=u.firstChild,x=p.nextSibling;return x.nextSibling,g(p,`Click to build ${h} (${f})`),u})()}return null}Se(["click"]);var hh=R('<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>'),fh=R("<div style=width:100%;height:100%;position:relative><div style=width:100%;height:100%>"),ph=R('<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">'),gh=R('<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:yr,error:vr}=yt("room");function mh(r){let e,t=null,n=null,i=null,s=null;const[o,l]=G(null),[a,c]=G(null),[d,h]=G(null),[f,u]=G(""),[p,x]=G(it());de(()=>x(it()));let M=null;return Nt(async()=>{if(!e)return;const m=await Di.create(e);l(m)}),Pe(()=>{M!==null&&clearTimeout(M),t==null||t.destroy(),t=null,n==null||n.destroy(),n=null,i==null||i.destroy(),i=null;const m=o();m&&m.destroy()}),de(()=>{const m=ae();if(!m||ue())return;const k=r.room,A=r.shard;c(null),h(null),u(""),Qr(null),Uu(),Zu(k),Vu(A),Dn(null),zn(null),Bn(null),Fn(null),Hn({}),ps(null);const w=new Ai;let b=!1;m.stores.room.terrain(k,A).then(C=>{b||c({room:k,data:C})}).catch(C=>{b||vr(`terrain load failed for ${k}:`,C)}),w.add(m.stores.room.subscribe(k,A)),w.add(m.stores.room.on("room:error",C=>{we(`Room subscription error (${C.room}): ${C.message}`,"error",8e3)})),w.add(m.stores.room.on("room:update",C=>{var E,L;let P=0;const y={};let S=0,O=null,v=null;for(const I in C.objects){P++;const B=C.objects[I];if(!B)continue;const D=B.type;if(typeof D=="string")if(D==="constructionSite"){const F=B.structureType;typeof F=="string"&&(y[F]=(y[F]||0)+1)}else y[D]=(y[D]||0)+1;if(D==="controller"&&typeof B.user=="string"){const F=B.user,U=((L=(E=C.users)==null?void 0:E[F])==null?void 0:L.username)??F;v={userId:F,username:U},typeof B.level=="number"&&(S=B.level),typeof B.progress=="number"&&(O=B.progress)}}C.diff||yr(`objects loaded — ${k}: ${P} objects, tick=${C.gameTime}`),h({objects:C.objects,diff:C.diff,users:C.users}),u(C.visual),Qr(C.gameTime??null),Ea(C.gameTime),Dn(P),zn(v),Bn(S||null),Fn(O),Hn(y),ps(C.users??null)})),Pe(()=>{b=!0,w.dispose()})}),de(()=>{var y,S;const m=ae();if(!m||!ue())return;u("");const k=r.room,A=r.shard,w=Qs()??!0,b=((S=(y=Gi())==null?void 0:y.serverData)==null?void 0:S.historyChunkSize)??(w?20:100),C=ge(Io)??void 0,P=new rh(k,A,m.http.baseUrl,()=>m.http.token,b,w);de(()=>{const O=it();let v=!1;Wn(!0),P.getStateAtTick(O).then(E=>{var U;if(v)return;if(Wn(!1),E.clampedTo!==void 0){zo(E.clampedTo),gn(E.clampedTo);return}h({objects:E.objects,diff:void 0,users:C}),Qr(E.gameTime);let L=0;const I={};let B=0,D=null,F=null;for(const Q in E.objects){L++;const K=E.objects[Q];if(!K)continue;const H=K.type;if(typeof H=="string")if(H==="constructionSite"){const X=K.structureType;typeof X=="string"&&(I[X]=(I[X]||0)+1)}else I[H]=(I[H]||0)+1;if(H==="controller"&&typeof K.user=="string"){const X=K.user,j=((U=C==null?void 0:C[X])==null?void 0:U.username)??X;F={userId:X,username:j},typeof K.level=="number"&&(B=K.level),typeof K.progress=="number"&&(D=K.progress)}}Dn(L),zn(F),Bn(B||null),Fn(D),Hn(I)}).catch(E=>{v||(Wn(!1),we(`History load failed for tick ${O}: ${E.message}`,"error",5e3))}),Pe(()=>{v=!0})})}),de(()=>{const m=o();if(!m)return;r.room,r.shard,bs(),m.hoverLayer.clearPendingTile(),s==null||s.destroy(),s=null,m.clear(),m.resetView(),t==null||t.destroy(),t=null,n==null||n.destroy(),n=null,i==null||i.destroy(),i=null;const k=ge(a);k&&k.room===r.room&&(yr(`terrain applied immediately (pre-loaded) — ${r.room}`),s=ls(k.data,m.app.renderer),Ln(s,ge(sn)),m.world.addChildAt(s,0),m.bringNavOverlayToTop());const A=r.room,w=r.shard,b=tt(A),C=ge(()=>r.onNavigate),P=ge(Rn);if(b&&C){const y=(O,v)=>!P||ki(O,v,P),S=O=>{C(O,w)};m.setupNavigationZones({west:y(b.x-1,b.y)?()=>S(ze(b.x-1,b.y)):void 0,east:y(b.x+1,b.y)?()=>S(ze(b.x+1,b.y)):void 0,north:y(b.x,b.y-1)?()=>S(ze(b.x,b.y-1)):void 0,south:y(b.x,b.y+1)?()=>S(ze(b.x,b.y+1)):void 0})}}),de(()=>{const m=o();if(!m)return;const k=ge(()=>r.room),A=ge(()=>r.shard),w=tt(k);if(w&&r.onNavigate){const b=r.onNavigate,C=Rn(),P=(S,O)=>!C||ki(S,O,C),y=S=>{b(S,A)};Ku({currentRoom:()=>r.room,worldBounds:Rn,onMove:(S,O)=>y(ze(S,O))}),m.setupNavigationZones({west:P(w.x-1,w.y)?()=>y(ze(w.x-1,w.y)):void 0,east:P(w.x+1,w.y)?()=>y(ze(w.x+1,w.y)):void 0,north:P(w.x,w.y-1)?()=>y(ze(w.x,w.y-1)):void 0,south:P(w.x,w.y+1)?()=>y(ze(w.x,w.y+1)):void 0})}}),de(()=>{const m=pt(),k=o();m==="view"&&k&&(ft(),k.hoverLayer.clearPendingTile())}),de(()=>{const m=o(),k=Pt();m&&(k?m.hoverLayer.setPendingTile(k.tx,k.ty):m.hoverLayer.clearPendingTile())}),de(()=>{const m=o(),k=a();if(!(!m||!k||k.room!==r.room)){if(s!=null&&s.parent){yr(`terrain already in scene, skipping — ${r.room}`);return}yr(`terrain applied (async) — ${r.room}`),s=ls(k.data,m.app.renderer),Ln(s,ge(sn)),m.world.addChildAt(s,0),m.bringNavOverlayToTop()}}),de(()=>{var C,P;const m=o(),k=d();if(!m)return;if(!k){t==null||t.clear(),n==null||n.clear();return}const{objects:A,diff:w,users:b}=k;if(t||(yr(`object layer created — ${r.room}`),t=new Ru(m.app.ticker,dn(),(C=Re())==null?void 0:C._id,(P=Re())==null?void 0:P.badge,b),t.setInstantMode(ge(ue)),t.container.label="objects",m.world.addChild(t.container),m.bringNavOverlayToTop(),n=new Pu(m.app.ticker),n.container.label="animations",m.world.addChild(n.container),i=new Iu,m.world.addChild(i.container),m.bringNavOverlayToTop(),m.setTileHandlers((y,S)=>{},(y,S,O)=>{const v=r.room,E=r.shard,L=pt(),I=yn();if((I==null?void 0:I.type)==="moveFlag"){const U=ae();if(!U)return;const{name:Q,room:K,color:H,secondaryColor:X}=I;U.http.game.removeFlag(K,Q).then(()=>U.http.game.createFlag(v,y,S,Q,H,X,E??void 0)).then(()=>{we(`Flag "${Q}" moved`,"success"),Ei()}).catch(j=>{vr("move flag failed:",j),we(`Failed to move flag "${Q}"`,"error"),Ei()});return}if(L==="flag"){const U=Pt();if(!U||U.tx!==y||U.ty!==S){Ti({tx:y,ty:S}),m.hoverLayer.setPendingTile(y,S);return}const Q=ae();if(!Q)return;const K=Yt(),H=K.name.trim();if(!H){we("Flag name is required","error");return}const X=Ar[K.color]??0,j=Ar[K.secondaryColor]??0;Q.http.game.createFlag(v,y,S,H,X,j,E??void 0).then(()=>{we(`Flag "${H}" created`,"success"),ft(),m.hoverLayer.clearPendingTile(),Q.http.game.genUniqueFlagName().then(Z=>Ho(se=>({...se,name:Z.name}))).catch(Z=>vr("gen unique flag name failed:",Z))}).catch(Z=>vr("create flag failed:",Z));return}if(L==="build"){if(!O&&!rt().structureType){we("Select a structure type first","error");return}if(O){if(!t)return;const Q=t.getObjectsAtTile(y,S).filter(({obj:H})=>H.type==="constructionSite");if(Q.length===0){we("No construction sites on this tile","error");return}const K=ae();if(!K)return;K.http.game.removeConstructionSite(v,Q.map(({id:H})=>H),E??void 0).then(()=>{we(`Removed ${Q.length} construction site${Q.length>1?"s":""}`,"success"),ft(),m.hoverLayer.clearPendingTile()}).catch(H=>{vr("remove construction sites failed:",H),we(`Failed to remove construction sites: ${H.message}`,"error")});return}Ti({tx:y,ty:S}),m.hoverLayer.setPendingTile(y,S),uh(v,E);return}if(ft(),m.hoverLayer.clearPendingTile(),!t)return;const B=t.getObjectsAtTile(y,S);if(B.length===0){O||(ir([]),m.hoverLayer.clearSelection());return}let D=[...nr()];if(O){const U=new Set(B.map(K=>K.id));if(D.some(K=>U.has(K.id)))D=D.filter(K=>!U.has(K.id));else{const K=B.filter(({id:H})=>!D.some(X=>X.id===H)).map(({id:H,obj:X})=>hs(H,X));D=[...D,...K]}}else D=B.map(({id:U,obj:Q})=>hs(U,Q));ir(D);const F=D.map(({id:U,type:Q})=>({id:U,type:Q,visual:t.getVisualById(U)})).filter(U=>U.visual!=null);m.hoverLayer.setSelectedObjects(F)},()=>{var S;const y=pt();(y==="build"||y==="flag"||((S=yn())==null?void 0:S.type)==="moveFlag")&&(bs(),m.hoverLayer.clearPendingTile())})),w?Xu(w,A):ju(A),t.update(A,w,b),t.setShowLabels(ge(dn)),n){n.clear();const y=ue()?Math.round(1e3/ge(Ui)):(ln()??2e3)*.6;for(const S in A){const O=A[S];if(!O||O.type!=="creep")continue;const v=O.actionLog;if(v){if(v.harvest){const E=v.harvest;n.addHarvest(E.x,E.y,O.x,O.y,y)}if(v.upgradeController){const E=v.upgradeController;n.addUpgradeController(O.x,O.y,E.x,E.y,y)}if(v.build){const E=v.build;n.addBuild(O.x,O.y,E.x,E.y,y),t==null||t.triggerBuildAt(E.x,E.y,y)}}}}}),de(()=>{const m=f();i==null||i.update(Mo()?m:"")}),de(()=>{t==null||t.setInstantMode(ue())}),de(()=>{const m=sn();s&&Ln(s,m)}),(()=>{var m=fh(),k=m.firstChild;return Vt(A=>e=A,k),g(m,(()=>{var A=J(()=>!!ws());return()=>A()&&(()=>{var w=ph();return g(w,ws),N(b=>z(w,"pointer-events",At()==="empty"||At()==="lost"?"auto":"none")),w})()})(),null),g(m,(()=>{var A=J(()=>!ue()&&Ne()!==null);return()=>A()&&(()=>{var w=gh();return w.firstChild,g(w,Ne,null),w})()})(),null),g(m,_(W,{get when(){return ue()},get children(){var A=hh(),w=A.firstChild,b=w.nextSibling,C=b.firstChild,P=C.nextSibling,y=P.nextSibling;return w.$$input=S=>{const O=parseInt(S.currentTarget.value,10);x(O),M!==null&&clearTimeout(M),M=setTimeout(()=>{M=null,gn(O)},150)},g(C,Ci),g(P,(()=>{var S=J(()=>!!Xe());return()=>S()?"Loading…":`Tick ${it()}`})()),g(y,Pr),N(S=>{var O=Ci(),v=Pr(),E=Xe()?"#f0883e":"#8b949e";return O!==S.e&&me(w,"min",S.e=O),v!==S.t&&me(w,"max",S.t=v),E!==S.a&&z(P,"color",S.a=E),S},{e:void 0,t:void 0,a:void 0}),N(()=>w.value=p()),A}}),null),m})()}Se(["input"]);var yh=R("<div style=position:fixed;bottom:16px;right:16px;display:flex;flex-direction:column;gap:8px;z-index:9999;pointer-events:none>"),vh=R('<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 bh(){return(()=>{var r=yh();return g(r,_(ye,{get each(){return ba()},children:e=>(()=>{var t=vh();return g(t,()=>e.message),N(n=>z(t,"background",e.type==="error"?"#da3633":"#238636")),t})()})),r})()}const[ut,wh]=G(!0),[Ze,Wo]=G(!0),[Ht,Uo]=G(!1),[Un,Ri]=G("");let St;function xh(r){St=r}function _h(r){Ri(r),Wo(!0),requestAnimationFrame(()=>{St==null||St.focus();const e=r.length;St==null||St.setSelectionRange(e,e)})}function Xo(){wh(r=>!r)}function jo(){Wo(r=>!r)}function Yo(){Uo(r=>!r)}const[sr,Vo]=G(Ys(fe.memoryWatches,[])),[Ir,qo]=G(null),[xs,$h]=Ao({});function Sh(r){const e=r.trim();e&&(Vo(t=>t.includes(e)?t:[...t,e]),Ni(fe.memoryWatches,sr()))}function kh(r){Vo(e=>e.filter(t=>t!==r)),Ni(fe.memoryWatches,sr())}function Zo(){qo(null)}function Ch(r,e){qo({creepId:r,name:e})}function Th(r,e){const t=[...e];if(r){const n=`creeps.${r.name}`;t.includes(n)||t.push(n)}return t}function Mh(r){const e=new Map,t=()=>{const s=ae();if(!s)return;const o=new Set(Th(Ir(),sr()));for(const l of o)e.has(l)||e.set(l,s.stores.user.subscribeMemory(l,r));for(const[l,a]of e)o.has(l)||(a.dispose(),e.delete(l))};de(()=>{sr(),Ir(),t()});const n=ae();let i=null;return n&&(i=n.stores.user.on("user:memory",s=>{$h(s.path,s.value)})),Pe(()=>{for(const s of e.values())s.dispose();e.clear(),i==null||i.dispose()}),t(),()=>{for(const s of e.values())s.dispose();e.clear(),i==null||i.dispose()}}Oi(()=>{de(()=>{const r=Ir();if(!r)return;nr().some(t=>t.id===r.creepId)||Zo()})});var Eh=R("<button style=color:#8b949e>"),Rh=R("<span style=width:18px;flex-shrink:0>"),Ph=R("<span style=color:#484f58;font-style:italic>{…}"),Oh=R("<span style=color:#484f58;font-style:italic>"),Lh=R("<button title=Reload>"),Ah=R('<span title="Click to edit"style=cursor:text;flex:1>'),Ih=R('<input type=text autofocus style="background:#161b22;border:1px solid #388bfd;color:#c9d1d9;border-radius:3px;padding:0 4px;font-size:12px;font-family:inherit;flex:1;min-width:60px">'),Nh=R("<button title=Save style=color:#3fb950>"),Gh=R("<button title=Discard style=color:#f85149>"),Dh=R('<div><div style=display:flex;align-items:center;gap:2px;min-height:20px><span style=color:#8b949e;flex-shrink:0></span><span style="color:#484f58;margin:0 2px;flex-shrink:0">:</span><button>');const{error:_s}=yt("MemoryTree");function Ue(r){return r!==null&&typeof r=="object"&&"__screeps_object__"in r}const zh={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},br={background:"transparent",border:"none",color:"#8b949e",cursor:"pointer",padding:"2px","border-radius":"3px",display:"inline-flex","align-items":"center","justify-content":"center","flex-shrink":0};function Vr(r){return r.replace(/^Memory\.?/,"")}function Ko(r){const[e,t]=G((r.depth??0)<2),n=()=>r.depth??0,[i,s]=G(!1),[o,l]=G(""),[a,c]=G(!1),[d,h]=G(void 0),f=()=>Ue(r.value)&&d()!==void 0?d():r.value,u=()=>{const C=f();return!Ue(C)&&C!==null&&typeof C=="object"},p=()=>u()?Object.entries(f()):[],x=()=>p().length,M=async()=>{c(!0);try{const C=ae();if(!C)return;const P=Vr(r.path),y=await C.http.user.memory.get(P,r.shard),S=y.data==="[object Object]"?{__screeps_object__:!0}:y.data;h(S)}catch(C){_s("fetch memory failed",C)}finally{c(!1)}},m=()=>{h(void 0),M()};Nt(()=>{e()&&Ue(r.value)&&d()===void 0&&M()});const k=async()=>{if(Ue(r.value)&&d()===void 0){await M(),t(!0);return}e()&&h(void 0),t(C=>!C)},A=async()=>{var O;const C=o().trim();let P;if(C==="null")P=null;else if(C==="true")P=!0;else if(C==="false")P=!1;else{const v=Number(C);if(!Number.isNaN(v)&&C!=="")P=v;else try{P=JSON.parse(C)}catch{P=C}}const y=ae();if(!y)return;const S=Vr(r.path);try{await y.http.user.memory.set(S,P,r.shard)}catch(v){_s("set memory failed",v),s(!1);return}s(!1),(O=r.onRefresh)==null||O.call(r)},w=()=>{const C=f();return u()?"#c9d1d9":typeof C=="string"?"#3fb950":typeof C=="number"?"#79c0ff":typeof C=="boolean"?"#a371f7":"#8b949e"},b=()=>{const C=f();return C===null?"null":C===void 0?"undefined":typeof C=="string"?JSON.stringify(C):String(C)};return(()=>{var C=Dh(),P=C.firstChild,y=P.firstChild,S=y.nextSibling,O=S.nextSibling;return g(P,_(W,{get when(){return u()||Ue(f())},get children(){var v=Eh();return v.$$click=()=>void k(),g(v,_(W,{get when(){return a()},get children(){return _(bc,{size:12,style:{animation:"spin 1s linear infinite"}})}}),null),g(v,_(W,{get when(){return!a()},get children(){return _(W,{get when(){return e()},get fallback(){return _(to,{size:12})},get children(){return _(qa,{size:12})}})}}),null),N(E=>{var L={...br},I=e()?"Collapse":"Expand",B=a();return E.e=Y(v,L,E.e),I!==E.t&&me(v,"title",E.t=I),B!==E.a&&(v.disabled=E.a=B),E},{e:void 0,t:void 0,a:void 0}),v}}),y),g(P,_(W,{get when(){return J(()=>!u())()&&!Ue(f())},get children(){return Rh()}}),y),g(y,()=>r.label),g(P,_(W,{get when(){return Ue(f())},get children(){return Ph()}}),O),g(P,_(W,{get when(){return u()},get children(){var v=Oh();return g(v,(()=>{var E=J(()=>!!Array.isArray(f()));return()=>E()?`[${x()}]`:`{${x()}}`})()),v}}),O),g(P,_(W,{get when(){return J(()=>!!Ue(r.value))()&&!a()},get children(){var v=Lh();return v.$$click=()=>m(),g(v,_(Bc,{size:11})),N(E=>Y(v,br,E)),v}}),O),g(P,_(W,{get when(){return J(()=>!u())()&&!Ue(f())},get children(){return[_(W,{get when(){return!i()},get children(){var v=Ah();return v.$$click=()=>{l(b()),s(!0)},g(v,b),N(E=>z(v,"color",w())),v}}),_(W,{get when(){return i()},get children(){return[(()=>{var v=Ih();return v.$$keydown=E=>{E.key==="Enter"&&A(),E.key==="Escape"&&s(!1)},v.$$input=E=>l(E.currentTarget.value),N(()=>v.value=o()),v})(),(()=>{var v=Nh();return v.$$mousedown=E=>{E.preventDefault(),A()},g(v,_(eo,{size:12})),N(E=>Y(v,{...br},E)),v})(),(()=>{var v=Gh();return v.$$mousedown=E=>{E.preventDefault(),s(!1)},g(v,_(It,{size:12})),N(E=>Y(v,{...br},E)),v})()]}})]}}),O),O.$$click=()=>_h(`Memory.${Vr(r.path)} = `),g(O,_(jc,{size:11})),g(C,_(W,{get when(){return J(()=>!!u())()&&e()},get children(){return _(ye,{get each(){return p()},children:([v,E])=>{const L=Array.isArray(f())?`${r.path}[${v}]`:`${r.path}.${v}`;return _(Ko,{value:E,path:L,label:v,get shard(){return r.shard},get depth(){return n()+1},get onRefresh(){return J(()=>!!Ue(r.value))()?m:r.onRefresh}})}})}}),null),N(v=>{var E={"padding-left":n()>0?"14px":"0",...zh},L=br,I=`Insert Memory.${Vr(r.path)} = into console`;return v.e=Y(C,E,v.e),v.t=Y(O,L,v.t),I!==v.a&&me(O,"title",v.a=I),v},{e:void 0,t:void 0,a:void 0}),C})()}function $s(r){return _(Ko,{get value(){return r.value},get path(){return r.path},get label(){return r.label},get shard(){return r.shard},depth:0})}Se(["click","input","keydown","mousedown"]);var Bh=R("<div style=color:#484f58;font-style:italic>No paths watched — add one below."),Fh=R('<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"><input type=text placeholder=creeps.Harvester1.energy 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 title="Add watch"style="padding:6px 8px;border-radius:4px;border:none;background:#238636;color:#fff;font-size:12px;cursor:pointer;display:flex;align-items:center;gap:4px"> Watch'),Hh=R('<div style=margin-bottom:8px><div style="display:flex;align-items:center;gap:4px;border-bottom:1px solid #21262d;padding-bottom:4px;margin-bottom:4px"><span style=color:#f0883e;font-weight:600;flex:1></span><span style=color:#484f58;font-size:10px;font-style:italic>temp</span><button title="Remove temp watch">'),Wh=R('<div style=margin-bottom:8px><div style="display:flex;align-items:center;gap:4px;border-bottom:1px solid #21262d;padding-bottom:4px;margin-bottom:4px"><span style=color:#c9d1d9;font-weight:600;flex:1></span><button title="Remove watch">'),Uh=R('<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>'),Ss=R("<div style=width:4px;flex-shrink:0;cursor:col-resize>"),Xh=R('<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'),jh=R("<div style=flex:1;display:flex;overflow:hidden>"),Yh=R(`<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
+ `),Vh=R("<div style=color:#484f58;font-style:italic>No log output yet…"),qh=R("<div style=margin-bottom:4px;color:#f85149;white-space:pre-wrap;word-break:break-word>"),Zh=R("<div style=margin-bottom:4px;color:#c9d1d9;white-space:pre-wrap;word-break:break-word>"),Kh=R("<div style=color:#484f58;font-style:italic>No command results yet…"),Jh=R("<div style=margin-bottom:4px;color:#58a6ff;white-space:pre-wrap;word-break:break-word>");const{error:Qh}=yt("console");function ef(r){const[e,t]=G(""),n=()=>r.shard??No();Nt(()=>{Mh(n())});const i={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},s={background:"transparent",border:"none",color:"#8b949e",cursor:"pointer",padding:"4px","border-radius":"4px",display:"flex","align-items":"center","justify-content":"center"};return(()=>{var o=Fh(),l=o.firstChild,a=l.nextSibling,c=a.firstChild,d=c.nextSibling,h=d.firstChild;return g(l,_(W,{get when(){return Ir()},children:f=>{const u=`creeps.${f().name}`;return(()=>{var p=Hh(),x=p.firstChild,M=x.firstChild,m=M.nextSibling,k=m.nextSibling;return g(M,u),Qe(k,"click",Zo,!0),g(k,_(It,{size:12})),g(p,_($s,{get value(){return xs[u]},path:`Memory.${u}`,label:u,get shard(){return n()}}),null),N(A=>Y(k,s,A)),p})()}}),null),g(l,_(ye,{get each(){return sr()},children:f=>(()=>{var u=Wh(),p=u.firstChild,x=p.firstChild,M=x.nextSibling;return g(x,f),M.$$click=()=>kh(f),g(M,_(It,{size:12})),g(u,_($s,{get value(){return xs[f]},path:`Memory.${f}`,label:f,get shard(){return n()}}),null),N(m=>Y(M,s,m)),u})()}),null),g(l,_(W,{get when(){return J(()=>sr().length===0)()&&!Ir()},get children(){return Bh()}}),null),a.addEventListener("submit",f=>{f.preventDefault(),Sh(e()),t("")}),c.$$input=f=>t(f.currentTarget.value),g(d,_(Gc,{size:14}),h),N(f=>{var u=`${r.width*100}%`,p={...i};return u!==f.e&&z(o,"width",f.e=u),f.t=Y(l,p,f.t),f},{e:void 0,t:void 0}),N(()=>c.value=e()),o})()}function tf(r){const[e,t]=G([]),[n,i]=G(!0),s=[1,1,1],[o,l]=G(Ys(fe.consoleWeights,[...s])),[a,c]=G(null);let d,h,f,u=0;Nt(()=>{const v=ae();if(!v)return;const E=new Ai;E.add(v.stores.user.subscribe("console")),E.add(v.stores.user.on("user:console",L=>{const I=L.messages,B={id:u++,log:I.log??[],results:I.results??[],error:I.error??[]};t(D=>{const F=[...D,B];return F.length>200?F.slice(F.length-200):F})})),Pe(()=>E.dispose())}),de(()=>{e(),n()&&requestAnimationFrame(()=>{ut()&&d&&(d.scrollTop=d.scrollHeight),Ze()&&h&&(h.scrollTop=h.scrollHeight)})});const p=(v,E,L)=>{var B,D;const I=!v&&!E&&!L;I&&!r.isCollapsed&&((B=r.onToggle)==null||B.call(r)),!I&&r.isCollapsed&&((D=r.onToggle)==null||D.call(r))};de(()=>{p(ut(),Ze(),Ht())});const x=()=>{const v=o(),E=[ut(),Ze(),Ht()],L=E.filter(Boolean).length;if(L===0)return[0,0,0];if(L===1){const D=E.findIndex(Boolean);return[0,0,0].map((F,U)=>U===D?1:0)}const B=E.map((D,F)=>D?v[F]:0).reduce((D,F)=>D+F,0);if(B===0){const D=1/L;return[0,0,0].map((F,U)=>E[U]?D:0)}return E.map((D,F)=>D?v[F]/B:0)};de(()=>{Ni(fe.consoleWeights,o())});const M=v=>E=>{E.preventDefault(),E.stopPropagation(),c(v),document.body.style.cursor="col-resize",document.body.style.userSelect="none",window.addEventListener("pointermove",m),window.addEventListener("pointerup",k,{once:!0})},m=v=>{const E=a();if(E===null)return;const L=f;if(!L)return;const I=L.getBoundingClientRect(),B=Math.max(.02,Math.min(.98,(v.clientX-I.left)/I.width)),D=[...o()],F=[ut(),Ze(),Ht()];if(E===0){const U=F[0],Q=F[1];if(!U||!Q)return;const K=B/(1-B);D[0]=K,D[1]=1,l(D)}else{const U=F[1],Q=F[2];if(!U||!Q)return;const K=B/(1-B);D[1]=K,D[2]=1,l(D)}},k=()=>{c(null),document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("pointermove",m)},A=async v=>{v.preventDefault();const E=ae();if(!(!E||!Un().trim()))try{await E.http.user.console(Un().trim(),r.shard??"shard0"),Ri("")}catch(L){Qh("command failed:",L)}},w=v=>({background:v?"#30363d":"transparent",border:`1px solid ${v?"#58a6ff":"transparent"}`,color:v?"#c9d1d9":"#8b949e","font-size":"12px",cursor:"pointer",padding:"2px 10px","border-radius":"4px"}),b=()=>e().flatMap(v=>v.log),C=()=>e().flatMap(v=>v.error),P=()=>e().flatMap(v=>v.results),y={"font-family":"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace","font-size":"12px","line-height":"1.5"},S={background:"transparent",border:"none",color:"#8b949e",cursor:"pointer",padding:"4px","border-radius":"4px",display:"flex","align-items":"center","justify-content":"center"},O=()=>{i(!0),requestAnimationFrame(()=>{ut()&&d&&(d.scrollTop=d.scrollHeight),Ze()&&h&&(h.scrollTop=h.scrollHeight)})};return(()=>{var v=Yh(),E=v.firstChild,L=E.firstChild,I=L.nextSibling,B=I.nextSibling;return E.nextSibling,Qe(L,"click",Xo,!0),Qe(I,"click",jo,!0),Qe(B,"click",Yo,!0),g(v,_(W,{get when(){return!r.isCollapsed},get children(){var D=jh();return Vt(F=>f=F,D),g(D,_(W,{get when(){return ut()},get children(){var F=Uh(),U=F.firstChild,Q=U.firstChild,K=Q.nextSibling,H=U.nextSibling;Q.$$click=()=>n()?i(!1):O(),g(Q,(()=>{var j=J(()=>!!n());return()=>j()?_(Pc,{size:16}):_(Ac,{size:16})})()),K.$$click=()=>t([]),g(K,_(tn,{size:16})),H.addEventListener("scroll",()=>{d&&i(d.scrollHeight-d.scrollTop-d.clientHeight<20)});var X=d;return typeof X=="function"?Vt(X,H):d=H,g(H,(()=>{var j=J(()=>b().length===0&&C().length===0);return()=>j()&&Vh()})(),null),g(H,_(ye,{get each(){return C()},children:j=>(()=>{var Z=qh();return Z.innerHTML=j,Z})()}),null),g(H,_(ye,{get each(){return b()},children:j=>(()=>{var Z=Zh();return Z.innerHTML=j,Z})()}),null),N(j=>{var Z=`${x()[0]*100}%`,se=n()?"Pause scrolling":"Resume scrolling",Le=S,Ye=S,st={...y};return Z!==j.e&&z(F,"width",j.e=Z),se!==j.t&&me(Q,"title",j.t=se),j.a=Y(Q,Le,j.a),j.o=Y(K,Ye,j.o),j.i=Y(H,st,j.i),j},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),F}}),null),g(D,_(W,{get when(){return J(()=>!!ut())()&&Ze()},get children(){var F=Ss();return Qe(F,"pointerdown",M(0),!0),N(U=>z(F,"background",a()===0?"#388bfd":"#21262d")),F}}),null),g(D,_(W,{get when(){return Ze()},get children(){var F=Xh(),U=F.firstChild,Q=U.nextSibling,K=Q.firstChild,H=K.nextSibling;H.nextSibling,U.addEventListener("scroll",()=>{h&&i(h.scrollHeight-h.scrollTop-h.clientHeight<20)});var X=h;return typeof X=="function"?Vt(X,U):h=U,g(U,(()=>{var j=J(()=>P().length===0);return()=>j()&&Kh()})(),null),g(U,_(ye,{get each(){return P()},children:j=>(()=>{var Z=Jh();return Z.innerHTML=j,Z})()}),null),Q.addEventListener("submit",A),H.$$input=j=>Ri(j.currentTarget.value),Vt(j=>xh(j),H),N(j=>{var Z=`${x()[1]*100}%`,se={...y};return Z!==j.e&&z(F,"width",j.e=Z),j.t=Y(U,se,j.t),j},{e:void 0,t:void 0}),N(()=>H.value=Un()),F}}),null),g(D,_(W,{get when(){return J(()=>!!Ze())()&&Ht()},get children(){var F=Ss();return Qe(F,"pointerdown",M(1),!0),N(U=>z(F,"background",a()===1?"#388bfd":"#21262d")),F}}),null),g(D,_(W,{get when(){return Ht()},get children(){return _(ef,{get shard(){return r.shard??null},get width(){return x()[2]}})}}),null),N(F=>z(D,"user-select",a()!==null?"none":"auto")),D}}),null),N(D=>{var F=w(ut()),U=w(Ze()),Q=w(Ht());return D.e=Y(L,F,D.e),D.t=Y(I,U,D.t),D.a=Y(B,Q,D.a),D},{e:void 0,t:void 0,a:void 0}),v})()}Se(["input","click","pointerdown"]);const Jo={1:200,2:45e3,3:135e3,4:405e3,5:1215e3,6:3645e3,7:10935e3},rf={1:2e4,2:1e4,3:2e4,4:4e4,5:8e4,6:12e4,7:15e4,8:2e5};var nf=R("<div style=display:flex;gap:5px;flex-wrap:wrap>"),sf=R("<div style=width:18px;height:18px;border-radius:50%;cursor:pointer;flex-shrink:0>");const of=[{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 vn(r){return(()=>{var e=nf();return g(e,_(ye,{each:of,children:t=>(()=>{var n=sf();return n.$$click=()=>r.onChange(t.value),N(i=>{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!==i.e&&me(n,"title",i.e=s),o!==i.t&&z(n,"background",i.t=o),l!==i.a&&z(n,"box-shadow",i.a=l),i},{e:void 0,t:void 0,a:void 0}),n})()})),e})()}Se(["click"]);var Ot=R("<div>"),bn=R("<div style=font-variant-numeric:tabular-nums>"),lf=R("<span style=font-variant-numeric:tabular-nums;font-weight:400> / "),af=R('<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">'),cf=R('<div style="padding:3px 8px;background:#0d1117;color:#8b949e">'),df=R('<div style="padding:3px 8px;background:#0d1117;color:#c9d1d9;font-variant-numeric:tabular-nums">'),uf=R("<div>Owner"),Qo=R("<div>Hits"),el=R("<div style=font-variant-numeric:tabular-nums> / "),hf=R("<div>Time to live"),ff=R("<div>Fatigue"),pf=R('<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>'),gf=R("<div><div>"),mf=R("<div style=width:11px;height:11px;border-radius:50%;flex-shrink:0>"),yf=R('<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">'),vf=R("<div style=padding:8px;display:flex;flex-direction:column;gap:8px;background:#0d1117><label>Primary color</label><label>Secondary color"),bf=R("<div>Level"),wf=R("<div>Safe modes"),xf=R("<div>Power"),_f=R("<div>Downgrade in"),$f=R("<div>Safe mode active"),Sf=R("<div style=font-variant-numeric:tabular-nums> ticks"),kf=R('<div style="padding:5px 8px;background:#0d1117;border-top:1px solid #21262d"><div style=display:flex;justify-content:space-between;font-size:10px;margin-bottom:4px><span style=color:#8b949e>RCL <!> → </span><span style=color:#c9d1d9;font-variant-numeric:tabular-nums> / <!> (<!>%)</span></div><div style=height:5px;background:#21262d;border-radius:3px;overflow:hidden><div style=height:100%;background:#58a6ff;border-radius:3px>'),Cf=R('<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">'),Tf=R("<div><div><div>Owner</div><div>"),Mf=R("<div>Reserved"),Ef=R("<div> (<!>)"),Rf=R("<div>Notify when attacked"),Pf=R("<div style=display:flex;align-items:center><button style=background:transparent;border:none;cursor:pointer;padding:0;display:flex;align-items:center>"),Of=R("<div><div>Energy</div><div style=font-variant-numeric:tabular-nums> / "),Lf=R("<div><div>Hits</div><div style=font-variant-numeric:tabular-nums> / "),Af=R('<div style="padding:5px 8px;background:#0d1117;border-top:1px solid #21262d"><div style=display:flex;justify-content:space-between;font-size:10px;margin-bottom:4px><span style=color:#8b949e>Fill</span><span style=color:#c9d1d9;font-variant-numeric:tabular-nums> / <!> (<!>%)</span></div><div style=height:5px;background:#21262d;border-radius:3px;overflow:hidden><div style=height:100%;background:#ffe87b;border-radius:3px>'),If=R("<div style=width:8px;height:8px;border-radius:50%;flex-shrink:0>"),Xn=R('<button style="background:transparent;border:none;cursor:pointer;padding:0 2px;display:flex;align-items:center;justify-content:center;flex-shrink:0">'),Nf=R('<button title="Watch memory"style="background:transparent;border:none;color:#8b949e;cursor:pointer;padding:0 2px;display:flex;align-items:center;justify-content:center;flex-shrink:0">'),Gf=R('<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">×'),Df=R("<span style=font-weight:400;color:#8b949e>"),zf=R('<div style="padding:3px 8px;border-top:1px solid #21262d;font-size:9px;color:#484f58;font-family:monospace;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:pointer">'),Bf=R("<div style=flex:1;overflow:auto;min-height:0;padding:8px>"),Ff=R("<div style=color:#484f58;font-style:italic;font-size:12px>Click a tile to select objects…");const{log:ks,error:or}=yt("SelectionList"),Hf={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"},Wf={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"},Uf=new Set(["x","y","type","id","name","user","_id","room","hitsMax","energyCapacity","body","storeCapacity","storeCapacityResource"]),Cs=new Set(["hits","energy","energyCapacity","store","progress","progressTotal","nextDecayTime"]),Ts={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 Xf(r){return Ts[r]?Ts[r]:r.replace(/([A-Z])/g," $1").replace(/^./,e=>e.toUpperCase()).trim()}function jf(r){return typeof r=="number"?String(r):typeof r=="string"?r:typeof r=="boolean"?r?"Yes":"No":null}function wn(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 le=(r=!1)=>({padding:"3px 8px",background:"#0d1117",color:r?"#8b949e":"#c9d1d9",overflow:"hidden","text-overflow":"ellipsis","white-space":"nowrap"}),Dr={display:"grid","grid-template-columns":"1fr 1fr",gap:"1px",background:"#21262d","font-size":"10px"};function Yf(r){const e=()=>{const t=r.item.raw,n=[];for(const i in t){if(Uf.has(i))continue;const s=t[i];let o=jf(s);if(!(i==="notifyWhenAttacked"&&s===!1)&&!(i==="off"&&s===!1)){if(i==="hits"&&typeof t.hitsMax=="number"&&(o=`${s} / ${t.hitsMax}`),i==="energy"&&typeof t.energyCapacity=="number"&&(o=`${s} / ${t.energyCapacity}`),i==="nextDecayTime"&&typeof s=="number"){const l=Ne();l!==null&&(o=String(s-l))}o!==null&&n.push({key:i,label:Xf(i),value:o})}}return n.sort((i,s)=>{const o=Cs.has(i.key)?0:1,l=Cs.has(s.key)?0:1;return o-l}),n};return _(W,{get when(){return e().length>0},get children(){var t=Ot();return g(t,_(ye,{get each(){return e()},children:n=>[(()=>{var i=Ot();return g(i,()=>n.label),N(s=>Y(i,le(!0),s)),i})(),(()=>{var i=bn();return g(i,()=>n.value),N(s=>Y(i,{...le()},s)),i})()]})),N(n=>Y(t,Dr,n)),t}})}function tl(r){const e=()=>{const n=r.store||{},i=[];for(const s in n)i.push([s,n[s]]);return i},t=()=>{const n=r.store||{};let i=0;for(const s in n)i+=n[s];return i};return _(W,{get when(){return e().length>0},get children(){var n=af(),i=n.firstChild;i.firstChild;var s=i.nextSibling;return g(i,_(W,{get when(){return r.capacity!=null},get children(){var o=lf(),l=o.firstChild;return g(o,t,l),g(o,()=>r.capacity,null),o}}),null),g(s,_(ye,{get each(){return e()},children:([o,l])=>[(()=>{var a=cf();return g(a,o),a})(),(()=>{var a=df();return g(a,l),a})()]})),n}})}const Vf={tough:"#4c4c4c",move:"#a9b7c6",work:"#ffe56d",carry:"#777777",attack:"#f93842",ranged_attack:"#5d80b2",heal:"#65fd62",claim:"#b99cfb"};function qf(r){const e=()=>r.item.raw,t=()=>typeof e().user=="string"?e().user:null,n=()=>{var f,u;const h=t();return h?((u=(f=Io())==null?void 0:f[h])==null?void 0:u.username)??h:null},i=()=>typeof e().hits=="number"?e().hits:null,s=()=>typeof e().hitsMax=="number"?e().hitsMax:null,o=()=>{const h=e().ageTime,f=Ne();return typeof h=="number"&&f!==null?Math.max(0,h-f):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 h=gf(),f=h.firstChild;return g(f,_(W,{get when(){return n()},get children(){return[(()=>{var u=uf();return N(p=>Y(u,le(!0),p)),u})(),(()=>{var u=Ot();return g(u,n),N(p=>Y(u,le(),p)),u})()]}}),null),g(f,_(W,{get when(){return J(()=>i()!==null)()&&s()!==null},get children(){return[(()=>{var u=Qo();return N(p=>Y(u,le(!0),p)),u})(),(()=>{var u=el(),p=u.firstChild;return g(u,i,p),g(u,s,null),N(x=>Y(u,{...le()},x)),u})()]}}),null),g(f,_(W,{get when(){return o()!==null},get children(){return[(()=>{var u=hf();return N(p=>Y(u,le(!0),p)),u})(),(()=>{var u=bn();return g(u,o),N(p=>Y(u,{...le()},p)),u})()]}}),null),g(f,_(W,{get when(){return l()!==null},get children(){return[(()=>{var u=ff();return N(p=>Y(u,le(!0),p)),u})(),(()=>{var u=bn();return g(u,l),N(p=>Y(u,{...le(),color:l()>0?"#e3b341":void 0},p)),u})()]}}),null),g(h,_(tl,{get store(){return a()},get capacity(){return c()}}),null),g(h,_(W,{get when(){return d().length>0},get children(){var u=pf(),p=u.firstChild,x=p.firstChild,M=x.nextSibling;M.nextSibling;var m=p.nextSibling;return g(p,()=>d().length,M),g(m,_(ye,{get each(){return d()},children:k=>(()=>{var A=mf();return N(w=>{var b=k.type.replace("_"," "),C=Vf[k.type]??"#484f58",P=k.hits===0?.25:1;return b!==w.e&&me(A,"title",w.e=b),C!==w.t&&z(A,"background",w.t=C),P!==w.a&&z(A,"opacity",w.a=P),w},{e:void 0,t:void 0,a:void 0}),A})()})),u}}),null),N(u=>Y(f,Dr,u)),h})()}function Zf(r){const e=()=>r.item.raw,t=()=>typeof e().name=="string"?e().name:"",n=()=>typeof e().room=="string"?e().room:"",i=()=>typeof e().color=="number"?e().color:1,s=()=>typeof e().secondaryColor=="number"?e().secondaryColor:1,[o,l]=G(i()),[a,c]=G(s());de(()=>{l(i()),c(s())});const d=()=>o()!==i()||a()!==s(),h=()=>{const x=ae();if(!x)return;const M=o(),m=a();ks(`changeFlagColor: name="${t()}" room=${n()} primary=${M} secondary=${m}`),x.http.game.changeFlagColor(n(),t(),M,m).then(()=>ks("changeFlagColor OK")).catch(k=>or("changeFlagColor FAILED:",k))},f=()=>{const x=yn();return(x==null?void 0:x.type)==="moveFlag"&&x.id===r.item.id},u=()=>{if(f()){Mi(null);return}Mi({type:"moveFlag",id:r.item.id,name:t(),room:n(),color:o(),secondaryColor:a()})},p={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var x=vf(),M=x.firstChild;M.firstChild;var m=M.nextSibling;return m.firstChild,g(M,_(vn,{get value(){return o()},onChange:l}),null),g(m,_(vn,{get value(){return a()},onChange:c}),null),g(x,_(W,{get when(){return!ue()},get children(){var k=yf(),A=k.firstChild,w=A.nextSibling;return A.addEventListener("mouseleave",b=>{d()&&(b.currentTarget.style.background="#238636")}),A.addEventListener("mouseenter",b=>{d()&&(b.currentTarget.style.background="#2ea043")}),A.$$click=h,w.addEventListener("mouseleave",b=>{b.currentTarget.style.color=f()?"#c9d1d9":"#8b949e"}),w.addEventListener("mouseenter",b=>{b.currentTarget.style.color="#c9d1d9"}),w.$$click=u,g(w,(()=>{var b=J(()=>!!f());return()=>b()?_(It,{size:13}):_(Mc,{size:13})})()),N(b=>{var C=!d(),P=d()?"#238636":"#161b22",y=d()?"#fff":"#484f58",S=`1px solid ${d()?"#238636":"#30363d"}`,O=d()?"pointer":"not-allowed",v=f()?"Abort move":"Move flag",E=f()?"#30363d":"#21262d",L=f()?"#c9d1d9":"#8b949e",I=`1px solid ${f()?"#8b949e":"#30363d"}`;return C!==b.e&&(A.disabled=b.e=C),P!==b.t&&z(A,"background",b.t=P),y!==b.a&&z(A,"color",b.a=y),S!==b.o&&z(A,"border",b.o=S),O!==b.i&&z(A,"cursor",b.i=O),v!==b.n&&me(w,"title",b.n=v),E!==b.s&&z(w,"background",b.s=E),L!==b.h&&z(w,"color",b.h=L),I!==b.r&&z(w,"border",b.r=I),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,r:void 0}),k}}),null),N(k=>{var A=p,w=p;return k.e=Y(M,A,k.e),k.t=Y(m,w,k.t),k},{e:void 0,t:void 0}),x})()}function Kf(r){const e=()=>r.item.raw,t=()=>typeof e().level=="number"?e().level:0,n=()=>typeof e().progress=="number"?e().progress:null,i=()=>typeof e().progressTotal=="number"?e().progressTotal:Jo[t()]??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,h=()=>{var b;const w=d();return w?((b=hn())==null?void 0:b.username)??w:null},f=()=>{const w=s(),b=Ne();return w!==null&&b!==null?Math.max(0,w-b):null},u=()=>{const w=f();if(w===null)return"—";const b=rf[t()];return b!==void 0&&w>=b?"Max":String(w)},p=()=>{var w;return d()!==null&&d()===((w=Re())==null?void 0:w._id)},[x,M]=G(!1);let m=null;const k=()=>{const w=ae();w&&w.http.game.addObjectIntent(r.item.id,e().room,"activateSafeMode",{}).catch(b=>or("activateSafeMode failed:",b))},A=()=>{if(!x()){M(!0),m=setTimeout(()=>M(!1),3e3);return}m&&(clearTimeout(m),m=null),M(!1);const w=ae();w&&w.http.game.addObjectIntent(r.item.id,e().room,"unclaim",{}).catch(b=>or("unclaim failed:",b))};return(()=>{var w=Tf(),b=w.firstChild,C=b.firstChild,P=C.nextSibling;return g(P,()=>h()??"None"),g(b,_(W,{get when(){return c()},children:y=>[(()=>{var S=Mf();return N(O=>Y(S,le(!0),O)),S})(),(()=>{var S=Ef(),O=S.firstChild,v=O.nextSibling;return v.nextSibling,g(S,()=>y().username,O),g(S,()=>y().ticksToEnd,v),N(E=>Y(S,le(),E)),S})()]}),null),g(b,_(W,{get when(){return t()>0},get children(){return[(()=>{var y=bf();return N(S=>Y(y,le(!0),S)),y})(),(()=>{var y=Ot();return g(y,t),N(S=>Y(y,le(),S)),y})(),(()=>{var y=wf();return N(S=>Y(y,le(!0),S)),y})(),(()=>{var y=Ot();return g(y,o),N(S=>Y(y,le(),S)),y})(),(()=>{var y=xf();return N(S=>Y(y,le(!0),S)),y})(),(()=>{var y=Ot();return g(y,()=>a()?"Enabled":"Disabled"),N(S=>Y(y,le(),S)),y})(),(()=>{var y=_f();return N(S=>Y(y,le(!0),S)),y})(),(()=>{var y=bn();return g(y,u),N(S=>Y(y,{...le(),color:u()==="Max"?"#3fb950":void 0},S)),y})()]}}),null),g(b,_(W,{get when(){return l()!==null},get children(){return[(()=>{var y=$f();return N(S=>Y(y,le(!0),S)),y})(),(()=>{var y=Sf(),S=y.firstChild;return g(y,l,S),N(O=>Y(y,{...le()},O)),y})()]}}),null),g(w,_(W,{get when(){return J(()=>t()>0&&t()<8&&n()!==null)()&&i()!==null},get children(){var y=kf(),S=y.firstChild,O=S.firstChild,v=O.firstChild,E=v.nextSibling;E.nextSibling;var L=O.nextSibling,I=L.firstChild,B=I.nextSibling,D=B.nextSibling,F=D.nextSibling;F.nextSibling;var U=S.nextSibling,Q=U.firstChild;return g(O,t,E),g(O,()=>t()+1,null),g(L,()=>wn(n()),I),g(L,()=>wn(i()),B),g(L,()=>(n()/i()*100).toFixed(1),F),N(K=>z(Q,"width",`${Math.min(100,n()/i()*100)}%`)),y}}),null),g(w,_(W,{get when(){return J(()=>!!p())()&&!ue()},get children(){var y=Cf(),S=y.firstChild,O=S.nextSibling;return S.addEventListener("mouseleave",v=>{o()>0&&(v.currentTarget.style.background="#1f6feb")}),S.addEventListener("mouseenter",v=>{o()>0&&(v.currentTarget.style.background="#388bfd")}),S.$$click=k,O.addEventListener("mouseleave",v=>{x()||(v.currentTarget.style.background="#f85149")}),O.addEventListener("mouseenter",v=>{x()||(v.currentTarget.style.background="#da3633")}),O.$$click=A,g(O,()=>x()?"Confirm unclaim":"Unclaim"),N(v=>{var E=o()===0,L=o()>0?"#1f6feb":"#161b22",I=o()>0?"pointer":"not-allowed",B=o()>0?1:.5,D=x()?"#da3633":"#f85149";return E!==v.e&&(S.disabled=v.e=E),L!==v.t&&z(S,"background",v.t=L),I!==v.a&&z(S,"cursor",v.a=I),B!==v.o&&z(S,"opacity",v.o=B),D!==v.i&&z(O,"background",v.i=D),v},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),y}}),null),N(y=>{var S=Dr,O=le(!0),v=le();return y.e=Y(b,S,y.e),y.t=Y(C,O,y.t),y.a=Y(P,v,y.a),y},{e:void 0,t:void 0,a:void 0}),w})()}function Jf(r){const e=()=>r.item.raw,t=()=>{const d=e().store;return(d==null?void 0:d.energy)??0},n=()=>{const d=e().storeCapacityResource;return(d==null?void 0:d.energy)??0},i=()=>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=Re())==null?void 0:d._id)},c=()=>{const d=ae();d&&d.http.game.addObjectIntent(r.item.id,e().room,"notifyWhenAttacked",{enabled:!o()}).catch(h=>or("notifyWhenAttacked failed:",h))};return(()=>{var d=Of(),h=d.firstChild,f=h.nextSibling,u=f.firstChild;return g(f,t,u),g(f,n,null),g(d,_(W,{get when(){return J(()=>i()!==null)()&&s()!==null},get children(){return[(()=>{var p=Qo();return N(x=>Y(p,le(!0),x)),p})(),(()=>{var p=el(),x=p.firstChild;return g(p,i,x),g(p,s,null),N(M=>Y(p,{...le()},M)),p})()]}}),null),g(d,_(W,{get when(){return J(()=>!!a())()&&!ue()},get children(){return[(()=>{var p=Rf();return N(x=>Y(p,le(!0),x)),p})(),(()=>{var p=Pf(),x=p.firstChild;return x.addEventListener("mouseleave",M=>{M.currentTarget.style.color=o()?"#3fb950":"#484f58"}),x.addEventListener("mouseenter",M=>{M.currentTarget.style.color=o()?"#56d364":"#8b949e"}),x.$$click=c,g(x,(()=>{var M=J(()=>!!o());return()=>M()?_(Ua,{size:12}):_(Fa,{size:12})})()),N(M=>{var m={...le()},k=o()?"Notifications on — click to disable":"Notifications off — click to enable",A=o()?"#3fb950":"#484f58";return M.e=Y(p,m,M.e),k!==M.t&&me(x,"title",M.t=k),A!==M.a&&z(x,"color",M.a=A),M},{e:void 0,t:void 0,a:void 0}),p})()]}}),null),N(p=>{var x=Dr,M=le(!0),m={...le()};return p.e=Y(d,x,p.e),p.t=Y(h,M,p.t),p.a=Y(f,m,p.a),p},{e:void 0,t:void 0,a:void 0}),d})()}function wt(r){const e=()=>r.item.raw,t=()=>typeof e().hits=="number"?e().hits:null,n=()=>typeof e().hitsMax=="number"?e().hitsMax:null,i=()=>e().store,s=()=>{if(typeof e().storeCapacity=="number")return e().storeCapacity;const a=e().storeCapacityResource;if(a){let c=0;for(const d in a)c+=a[d];return c}return null},o=()=>{const a=i();if(!a)return 0;let c=0;for(const d in a)c+=a[d];return c},l=()=>{const a=s();return!a||a===0?0:Math.min(100,o()/a*100)};return(()=>{var a=Ot();return g(a,_(W,{get when(){return J(()=>t()!==null)()&&n()!==null},get children(){var c=Lf(),d=c.firstChild,h=d.nextSibling,f=h.firstChild;return g(h,t,f),g(h,n,null),N(u=>{var p=Dr,x=le(!0),M={...le()};return u.e=Y(c,p,u.e),u.t=Y(d,x,u.t),u.a=Y(h,M,u.a),u},{e:void 0,t:void 0,a:void 0}),c}}),null),g(a,_(W,{get when(){return s()!==null},get children(){var c=Af(),d=c.firstChild,h=d.firstChild,f=h.nextSibling,u=f.firstChild,p=u.nextSibling,x=p.nextSibling,M=x.nextSibling;M.nextSibling;var m=d.nextSibling,k=m.firstChild;return g(f,()=>wn(o()),u),g(f,()=>wn(s()),p),g(f,()=>l().toFixed(1),M),N(A=>z(k,"width",`${l()}%`)),c}}),null),g(a,_(tl,{get store(){return i()},capacity:null}),null),a})()}const Qf={creep:qf,flag:Zf,controller:Kf,extension:Jf,storage:wt,terminal:wt,container:wt,lab:wt,factory:wt,nuker:wt,powerSpawn:wt};function ep(r){const e=()=>Hf[r.item.type]??"#c9d1d9",t=()=>Wf[r.item.type]??r.item.type,n=()=>r.item.type==="creep",i=()=>r.item.type==="flag",s=()=>{var C;if(!n())return!1;const w=r.item.raw,b=typeof w.user=="string"?w.user:null;return b!==null&&b===((C=Re())==null?void 0:C._id)},o=()=>{var C,P,y;if(n()||i()||r.item.type==="controller")return!1;const w=r.item.raw,b=typeof w.user=="string"?w.user:null;return b!==null?b===((C=Re())==null?void 0:C._id):((P=hn())==null?void 0:P.userId)===((y=Re())==null?void 0:y._id)},l=()=>Qf[r.item.type]||Yf,[a,c]=G(!1);let d=null;const[h,f]=G(!1);let u=null;const[p,x]=G(!1);let M=null;const m=w=>{if(w.stopPropagation(),!p()){x(!0),M=setTimeout(()=>x(!1),3e3);return}M&&(clearTimeout(M),M=null),x(!1);const b=ae();if(!b)return;const C=r.item.id,P=r.item.raw;b.http.game.removeFlag(P.room,P.name).then(()=>Yr(C)).catch(()=>{})},k=w=>{var O;if(w.stopPropagation(),!h()){f(!0),u=setTimeout(()=>f(!1),3e3);return}u&&(clearTimeout(u),u=null),f(!1);const b=ae();if(!b)return;const C=r.item.id,P=r.item.raw,y=(typeof P.room=="string"?P.room:null)??qu()??"",S=typeof P.user=="string"?P.user:((O=hn())==null?void 0:O.userId)??"";b.http.game.addObjectIntent("room",y,"destroyStructure",[{id:C,roomName:y,user:S}],No()).then(()=>Yr(C)).catch(v=>or("destroyStructure failed:",v))},A=w=>{if(w.stopPropagation(),!a()){c(!0),d=setTimeout(()=>c(!1),3e3);return}d&&(clearTimeout(d),d=null),c(!1);const b=ae();if(!b)return;const C=r.item.id;b.http.game.addObjectIntent(C,r.item.raw.room,"suicide",{}).then(()=>Yr(C)).catch(P=>or("suicide failed:",P))};return(()=>{var w=Gf(),b=w.firstChild,C=b.firstChild,P=C.nextSibling,y=P.firstChild,S=y.nextSibling,O=S.nextSibling,v=O.nextSibling;v.nextSibling;var E=P.nextSibling;return g(b,_(W,{get when(){return J(()=>!n())()&&!i()},get children(){var L=If();return N(I=>z(L,"background",e())),L}}),C),g(C,_(W,{get when(){return i()},get fallback(){return J(t)},get children(){return _(no,{size:12})}}),null),g(C,_(W,{get when(){return J(()=>typeof r.item.raw.name=="string")()&&r.item.raw.name},children:L=>(()=>{var I=Df();return g(I,()=>L()),I})()}),null),g(P,()=>r.item.raw.x,S),g(P,()=>r.item.raw.y,v),g(b,_(W,{get when(){return J(()=>!!s())()&&!ue()},get children(){return[(()=>{var L=Xn();return L.addEventListener("mouseleave",I=>{a()||(I.currentTarget.style.color="#8b949e")}),L.addEventListener("mouseenter",I=>{a()||(I.currentTarget.style.color="#f85149")}),L.$$click=A,g(L,_(tn,{size:13})),N(I=>{var B=a()?"Click again to confirm suicide":"Suicide",D=a()?"#f85149":"#8b949e";return B!==I.e&&me(L,"title",I.e=B),D!==I.t&&z(L,"color",I.t=D),I},{e:void 0,t:void 0}),L})(),(()=>{var L=Nf();return L.addEventListener("mouseleave",I=>I.currentTarget.style.color="#8b949e"),L.addEventListener("mouseenter",I=>I.currentTarget.style.color="#58a6ff"),L.$$click=()=>{Ch(r.item.id,r.item.raw.name),Uo(!0)},g(L,_(ro,{size:13})),L})()]}}),E),g(b,_(W,{get when(){return J(()=>!!o())()&&!ue()},get children(){var L=Xn();return L.addEventListener("mouseleave",I=>{h()||(I.currentTarget.style.color="#8b949e")}),L.addEventListener("mouseenter",I=>{h()||(I.currentTarget.style.color="#f85149")}),L.$$click=k,g(L,_(tn,{size:13})),N(I=>{var B=h()?"Click again to confirm destruction":"Destroy structure",D=h()?"#f85149":"#8b949e";return B!==I.e&&me(L,"title",I.e=B),D!==I.t&&z(L,"color",I.t=D),I},{e:void 0,t:void 0}),L}}),E),g(b,_(W,{get when(){return J(()=>!!i())()&&!ue()},get children(){var L=Xn();return L.addEventListener("mouseleave",I=>{p()||(I.currentTarget.style.color="#8b949e")}),L.addEventListener("mouseenter",I=>{p()||(I.currentTarget.style.color="#f85149")}),L.$$click=m,g(L,_(tn,{size:13})),N(I=>{var B=p()?"Click again to confirm deletion":"Delete flag",D=p()?"#f85149":"#8b949e";return B!==I.e&&me(L,"title",I.e=B),D!==I.t&&z(L,"color",I.t=D),I},{e:void 0,t:void 0}),L}}),E),E.addEventListener("mouseleave",L=>L.currentTarget.style.color="#8b949e"),E.addEventListener("mouseenter",L=>L.currentTarget.style.color="#fff"),E.$$click=()=>Yr(r.item.id),g(w,_(zs,{get component(){return l()},get item(){return r.item}}),null),g(w,_(W,{get when(){return r.item.id},children:L=>(()=>{var I=zf();return I.$$click=()=>{var B;return(B=navigator.clipboard)==null?void 0:B.writeText(L())},g(I,L),N(()=>me(I,"title",L())),I})()}),null),N(L=>z(w,"border",`1px solid ${s()&&a()||h()||p()?"#f85149":"#30363d"}`)),w})()}function tp(){return(()=>{var r=Bf();return g(r,_(W,{get when(){return nr().length>0},get fallback(){return Ff()},get children(){return _(ye,{get each(){return nr()},children:e=>_(ep,{item:e})})}})),r})()}Se(["click"]);var rp=R('<div style="padding:3px 0;color:#8b949e">RCL'),np=R("<span style=color:#8b949e>(<!>%)"),ip=R('<div style="padding:3px 0;color:#c9d1d9;font-variant-numeric:tabular-nums">'),sp=R('<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"></div></div><label style=display:flex;align-items:center;justify-content:space-between;font-size:11px;color:#c9d1d9;cursor:pointer;margin-top:6px><span>Creep-Namen</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>Room Visuals</span><input type=checkbox></label></div><div style=display:grid;gap:4px;margin-top:8px><button type=button title=History style="padding:5px 8px;border-radius:6px;display:flex;align-items:center;justify-content:center">'),op=R("<span>"),lp=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;display:flex;align-items:center;justify-content:center">');const ap=[{mode:"view",label:"View",icon:()=>_(ro,{size:14})},{mode:"flag",label:"Flag",icon:()=>_(no,{size:14})},{mode:"build",label:"Build",icon:()=>_(fc,{size:14})}];function cp(r){return(()=>{var e=sp(),t=e.firstChild,n=t.firstChild,i=n.nextSibling,s=i.nextSibling,o=s.firstChild,l=o.nextSibling,a=l.nextSibling,c=a.nextSibling,d=c.nextSibling,h=d.nextSibling,f=h.nextSibling,u=f.nextSibling,p=u.nextSibling,x=p.nextSibling,M=s.nextSibling,m=M.firstChild,k=m.nextSibling,A=M.nextSibling,w=A.firstChild,b=w.nextSibling,C=t.nextSibling,P=C.firstChild;return g(i,()=>r.room),g(l,()=>r.shard??"—"),g(c,()=>Ne()??"—"),g(h,(()=>{var y=J(()=>!!ln());return()=>y()?`${ln()}ms`:"—"})()),g(u,()=>Yu()??"—"),g(x,()=>{var y;return((y=hn())==null?void 0:y.username)??"—"}),g(s,_(W,{get when(){return J(()=>Ee()!==null)()&&Ee()>0},get children(){return[rp(),(()=>{var y=ip();return g(y,_(W,{get when(){return J(()=>Ee()<8)()&&fs()!==null},get fallback(){return(()=>{var S=op();return g(S,Ee),S})()},get children(){return[J(()=>Ee())," → ",J(()=>Ee()+1)," ",(()=>{var S=np(),O=S.firstChild,v=O.nextSibling;return v.nextSibling,g(S,()=>(fs()/(Jo[Ee()]??1)*100).toFixed(1),v),S})()]}})),y})()]}}),null),k.addEventListener("change",y=>$o(y.currentTarget.checked)),b.addEventListener("change",y=>Du(y.currentTarget.checked)),g(C,_(W,{get when(){return!Be()},get children(){return _(ye,{each:ap,children:y=>{const S=()=>!ue()&&pt()===y.mode;return(()=>{var O=lp();return O.$$click=()=>{ue()&&pn(),Tt(y.mode)},g(O,()=>y.icon()),N(v=>{var E=y.label,L=`1px solid ${S()?"#58a6ff":"#30363d"}`,I=S()?"#1f6feb33":"#161b22",B=S()?"#c9d1d9":"#8b949e";return E!==v.e&&me(O,"title",v.e=E),L!==v.t&&z(O,"border",v.t=L),I!==v.a&&z(O,"background",v.a=I),B!==v.o&&z(O,"color",v.o=B),v},{e:void 0,t:void 0,a:void 0,o:void 0}),O})()}})}}),P),P.$$click=()=>ue()?pn():Ne()!==null&&Fo(Ne()),g(P,_(nc,{size:14})),N(y=>{var S=`repeat(${Be()?2:4}, 1fr)`,O=!ue()&&Ne()===null,v=Be()?"span 2":void 0,E=`1px solid ${ue()?"#58a6ff":"#30363d"}`,L=ue()?"#1f6feb33":"#161b22",I=ue()?"#c9d1d9":"#8b949e",B=!ue()&&Ne()===null?"not-allowed":"pointer",D=!ue()&&Ne()===null?.4:1;return S!==y.e&&z(C,"grid-template-columns",y.e=S),O!==y.t&&(P.disabled=y.t=O),v!==y.a&&z(P,"grid-column",y.a=v),E!==y.o&&z(P,"border",y.o=E),L!==y.i&&z(P,"background",y.i=L),I!==y.n&&z(P,"color",y.n=I),B!==y.s&&z(P,"cursor",y.s=B),D!==y.h&&z(P,"opacity",y.h=D),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}),N(()=>k.checked=dn()),N(()=>b.checked=Mo()),e})()}Se(["click"]);const[dp,up]=G("owner"),rl="screeps-terrain-v1";async function hp(r,e,t){try{const n=await caches.open(rl),i=`/terrain/${r}_${e}_z${t}.webp`,s=new Request(i),o=await n.match(s);if(o)return await o.blob()}catch{}return null}async function fp(r,e,t,n){try{const i=await caches.open(rl),s=`/terrain/${r}_${e}_z${t}.webp`,o=new Request(s),l=new Response(n);await i.put(o,l)}catch{}}async function pp(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 gp(r){return await createImageBitmap(r)}function mp(r){return new Worker("/_client/terrain.worker-D9zNeJfz.js",{name:r==null?void 0:r.name})}const{warn:yp}=yt("MapRenderer"),nl=3,re=nl*50,vp=[50,60,70,80,90,100,110],wr=1,kt=.5,qr=50,bp=2600,wp=5,jn=.2,Yn=5,xp=Gr,_p=16777215,$p=Rt,Sp=kr,kp=lo,Cp=$t,Tp=4486980,Mp=8921634,Ep=new Set(["w","r","pb","p","s","c","m","k"]),Rp={H:13421772,O:13421772,U:5809919,L:4176208,K:10711543,Z:13801762,X:16273737},Pp=[16,24,32,40];class o0{constructor(e){T(this,"app");T(this,"world");T(this,"boundsGraphics",null);T(this,"selectionGraphics",null);T(this,"safeModeGraphics",null);T(this,"safeModeRooms",new Set);T(this,"activeRooms",new Map);T(this,"roomPool",[]);T(this,"terrainBaked",new Set);T(this,"terrainData",new Map);T(this,"worker");T(this,"pendingBakes",new Map);T(this,"nextBakeId",0);T(this,"currentShard","shard0");T(this,"callbacks");T(this,"resizeObserver",null);T(this,"_destroyed",!1);T(this,"showRoomNames",!1);T(this,"worldBoundsSet",null);T(this,"lastVisibleBounds",null);T(this,"animTargetX",0);T(this,"animTargetY",0);T(this,"isAnimating",!1);T(this,"overlayMode","owner");T(this,"showUnclaimableOverlay",!0);T(this,"isDragging",!1);T(this,"hasDragged",!1);T(this,"dragStartX",0);T(this,"dragStartY",0);T(this,"dragWorldX",0);T(this,"dragWorldY",0);T(this,"isPinching",!1);T(this,"pinchPivotWorldX",0);T(this,"pinchPivotWorldY",0);T(this,"pinchStartDist",0);T(this,"pinchStartScale",0);T(this,"lastVisibleKey","");T(this,"visibleDebounceTimer",null);T(this,"selectedRoom",null);T(this,"currentUserId",null);T(this,"badgeCache",new co);T(this,"lastCheckX",0);T(this,"lastCheckY",0);T(this,"lastCheckScale",0);this.app=new Ns,this.callbacks=e,this.worker=new mp,this.worker.onmessage=t=>{const{id:n,bitmap:i}=t.data,s=this.pendingBakes.get(n);s&&(this.pendingBakes.delete(n),s.resolve(i))}}async init(e){const t=e.parentElement??e,{width:n,height:i}=t.getBoundingClientRect();await this.app.init({canvas:e,width:n,height:i,background:Ld,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 Oe,this.app.stage.addChild(this.world),this.boundsGraphics=new ee,this.world.addChild(this.boundsGraphics),this.selectionGraphics=new ee,this.world.addChild(this.selectionGraphics),this.safeModeGraphics=new ee,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(jn,Math.min(Yn,e)),e===this.world.scale.x))return;const t=this.app.screen.width/2,n=this.app.screen.height/2;this.applyZoomAt(e,t,n)}applyZoomAt(e,t,n){var d,h;const i=this.world.scale.x,s=this.getLOD(),o=this.zoom>=wr,l=this.zoom>=kt,a=(t-this.world.x)/i,c=(n-this.world.y)/i;this.world.scale.set(e),this.world.x=t-a*e,this.world.y=n-c*e,this.getLOD()!==s&&this.applyLOD(),(e>=wr!==o||e>=kt!==l)&&this.updateAllNameLabels(),this.updateAllRoomScales(e),(h=(d=this.callbacks).onZoomChanged)==null||h.call(d,e),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode()}centerOn(e,t,n=!1){const i=e*re+re/2,s=t*re+re/2,o=this.world.scale.x,l=this.app.screen.width/2-i*o,a=this.app.screen.height/2-s*o;n?(this.animTargetX=l,this.animTargetY=a,this.isAnimating=!0):(this.isAnimating=!1,this.world.x=l,this.world.y=a)}async getTerrainBitmap(e,t,n){const i=this.currentShard;try{const s=await hp(i,e,t);if(s)return await gp(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:n});const a=await l;return pp(a).then(c=>{fp(i,e,t,c)}).catch(c=>yp("failed to save to terrainCache:",c)),a}catch{return null}}async setRoomTerrain(e,t){const n=t.raw;let i=!1;for(let c=0;c<n.length;c++)if(n[c]!==0){i=!0;break}if(!i){this.terrainBaked.add(e);return}const s=this.getOrCreate(e),o=this.getLOD();o===0&&this.terrainData.set(e,n);const l=await this.getTerrainBitmap(e,o,n);if(!l)return;if(!this.activeRooms.has(e)){l.close();return}const a=_t.from(l);o===0?(s.texLo&&!s.texLo.destroyed&&(s.terrainSprite.texture===s.texLo&&(s.terrainSprite.texture=_t.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=_t.EMPTY),s.texHi.destroy(!0)),s.texHi=a,this.getLOD()===1&&(s.terrainSprite.texture=a)),s.terrainSprite.width=re,s.terrainSprite.height=re,this.terrainBaked.add(e)}getLOD(){return this.zoom<wr?0:1}async applyLOD(){const e=this.getLOD()===1,t=[];for(const[n,i]of this.activeRooms)if(this.terrainBaked.has(n))if(e&&!i.texHi){const s=this.terrainData.get(n);s&&(this.terrainData.delete(n),t.push(this.getTerrainBitmap(n,1,s).then(o=>{o&&this.activeRooms.has(n)?(i.texHi=_t.from(o),this.getLOD()===1&&(i.terrainSprite.texture=i.texHi)):o&&o.close()})))}else{const s=e?i.texHi:i.texLo;s&&!s.destroyed&&(i.terrainSprite.texture=s)}await Promise.all(t)}setRoomMap2(e,t,n="live"){const i=this.getOrCreate(e);i.lastMap2Data=t,i.lastMap2Source=n,this.drawMap2(i,t,n)}drawMap2(e,t,n){const i=e.map2Graphics;i.alpha=n==="cache"?.6:1;const s=nl;i.clear();const o=t.r??[];for(const[p,x]of o)i.rect(p*s,x*s,s,s);o.length&&i.fill(zi);const l=t.w??[];for(const[p,x]of l)i.rect(p*s+.5,x*s+.5,s-1,s-1);l.length&&i.fill(e.ownerState==="other"?Mp:Tp);const a=t.s??[];for(const[p,x]of a)i.circle((p+.5)*s,(x+.5)*s,2.5);a.length&&i.fill(xp);const c=t.c??[];for(const[p,x]of c)i.circle((p+.5)*s,(x+.5)*s,2);c.length&&i.fill(_p);const d=t.m??[];for(const[p,x]of d)i.circle((p+.5)*s,(x+.5)*s,2);d.length&&i.fill($p);const h=t.k??[];for(const[p,x]of h)i.circle((p+.5)*s,(x+.5)*s,2);h.length&&i.fill(Sp);const f=t.pb??[];for(const[p,x]of f)i.circle((p+.5)*s,(x+.5)*s,1.5);f.length&&i.fill(kr);const u=t;for(const p in u){if(Ep.has(p))continue;const x=u[p];if(!Array.isArray(x)||x.length===0)continue;for(const[m,k]of x)i.circle((m+.5)*s,(k+.5)*s,1);const M=p===this.currentUserId?kp:Cp;i.fill(M)}}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 n=this.activeRooms.get(e);if(!n)return;n.ownerState!==t&&(n.ownerState=t,n.lastMap2Data&&this.drawMap2(n,n.lastMap2Data,n.lastMap2Source??"live"));const i=n.ownerOverlay;i.clear(),t==="other"?(i.rect(0,0,re,re),i.fill({color:10027008,alpha:.18})):t==="own"&&(i.rect(0,0,re,re),i.fill({color:102,alpha:.35})),i.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,n){const i=this.activeRooms.get(e);if(i){if(!t){i.badgeSprite&&(i.container.removeChild(i.badgeSprite),i.badgeSprite.destroy(),i.badgeSprite=void 0),i.badgeLevel=void 0;return}try{const s=await this.badgeCache.getOrCreate(t);if(!this.activeRooms.has(e))return;if(i.badgeSprite){if(i.badgeSprite.texture===s){i.badgeLevel=n,this.applyBadgeSize(i,this.zoom),this.applyOverlayMode(i);return}i.badgeSprite.texture=s}else{const o=new tr(s);o.anchor.set(.5),o.x=re/2,o.y=re/2;const l=i.container.getChildIndex(i.nameLabel);i.container.addChildAt(o,l),i.badgeSprite=o}i.badgeLevel=n,this.applyBadgeSize(i,this.zoom),this.applyOverlayMode(i)}catch{}}}applyBadgeSize(e,t){if(!e.badgeSprite||e.badgeLevel===void 0)return;const i=(vp[e.badgeLevel-1]??24)*Math.min(1,t);e.badgeSprite.width=i/t,e.badgeSprite.height=i/t}setOverlayMode(e){if(this.overlayMode!==e){this.overlayMode=e;for(const t of this.activeRooms.values())this.applyOverlayMode(t)}}setRoomMineral(e,t,n){const i=this.activeRooms.get(e);if(!i)return;if(!t||!n){i.mineralCircle&&(i.container.removeChild(i.mineralCircle),i.mineralCircle.destroy(),i.mineralCircle=void 0),i.mineralLabel&&(i.container.removeChild(i.mineralLabel),i.mineralLabel.destroy(),i.mineralLabel=void 0),i.mineralDensity=void 0;return}const s=Rp[t]??Rt;if(i.mineralDensity=n,i.mineralColor=s,!i.mineralCircle){const o=new ee;o.x=re/2,o.y=re/2;const l=i.container.getChildIndex(i.nameLabel);i.container.addChildAt(o,l),i.mineralCircle=o}if(i.mineralLabel)i.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=re/2,o.y=re/2,i.container.addChild(o),i.mineralLabel=o}this.applyMineralSize(i,this.zoom),this.applyOverlayMode(i)}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 n=Math.max(.5,Math.min(1.5,t)),i=(Pp[e.mineralDensity-1]??24)*n,s=i/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=i*.55/36/t;e.mineralLabel.scale.set(c)}updateNameLabelScale(e,t){const i=.3/Math.sqrt(t),s=12/(36*t);e.nameLabel.scale.set(Math.max(i,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=tt(e);if(!t)return;const n=t.x*re,i=t.y*re;this.selectionGraphics.rect(n,i,re,re);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 n=tt(t);if(!n)continue;const i=n.x*re,s=n.y*re;this.safeModeGraphics.rect(i,s,re,re),this.safeModeGraphics.stroke({color:16776960,width:e,alignment:1,alpha:.5})}this.world.removeChild(this.safeModeGraphics),this.world.addChild(this.safeModeGraphics)}setBounds(e,t,n,i){if(!this.boundsGraphics)return;this.worldBoundsSet={minX:e,maxX:t,minY:n,maxY:i},this.boundsGraphics.clear();const s=e*re,o=n*re,l=(t-e+1)*re,a=(i-n+1)*re;this.boundsGraphics.rect(s,o,l,a),this.boundsGraphics.stroke({color:oo,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=_t.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<bp?this.roomPool.push(t):(this.world.removeChild(t.container),t.container.destroy({children:!0,context:!0})))}clearInvisibleRooms(e){const t=this.lastVisibleBounds;for(const n of[...this.activeRooms.keys()])if(!e.has(n)){if(t){const i=tt(n);if(i&&i.x>=t.rxMin-qr&&i.x<=t.rxMax+qr&&i.y>=t.ryMin-qr&&i.y<=t.ryMax+qr)continue}this.clearRoom(n)}}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 n=tt(e);if(!n)throw new Error(`MapRenderer: invalid room "${e}"`);let i;if(this.roomPool.length>0)i=this.roomPool.pop();else{const s=new Oe;s.cullable=!0;const o=new tr(_t.EMPTY),l=new ee,a=new ee;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),i={container:s,terrainSprite:o,texLo:null,texHi:null,map2Graphics:l,ownerOverlay:a,ownerState:"none",nameLabel:c}}return i.container.x=n.x*re,i.container.y=n.y*re,i.container.visible=!0,i.nameLabel.text=e,i.nameLabel.visible=this.showRoomNames&&this.zoom>=kt&&this.nameLabelShouldShow(n.x,n.y),this.updateNameLabelScale(i,this.zoom),i.badgeSprite&&(i.container.removeChild(i.badgeSprite),i.badgeSprite.destroy(),i.badgeSprite=void 0),i.mineralCircle&&(i.container.removeChild(i.mineralCircle),i.mineralCircle.destroy(),i.mineralCircle=void 0),i.mineralLabel&&(i.container.removeChild(i.mineralLabel),i.mineralLabel.destroy(),i.mineralLabel=void 0),i.mineralDensity=void 0,i.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,i),i}nameLabelShouldShow(e,t){const n=this.worldBoundsSet;return!(n&&(e<n.minX||e>n.maxX||t<n.minY||t>n.maxY))}updateAllNameLabels(){const e=this.showRoomNames&&this.zoom>=kt;for(const[t,n]of this.activeRooms){if(!e){n.nameLabel.visible=!1;continue}const i=tt(t);i&&(n.nameLabel.visible=this.nameLabelShouldShow(i.x,i.y))}}setupInteraction(){const e=this.app.canvas;e.style.touchAction="none",e.style.userSelect="none";const t=new Map;e.addEventListener("pointermove",n=>{var i,s;if(!t.has(n.pointerId)){if(!this.isDragging&&!this.isPinching){const o=e.getBoundingClientRect();this.emitHover(n.clientX-o.left,n.clientY-o.top)}return}if(t.set(n.pointerId,{x:n.clientX,y:n.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),h=Math.max(jn,Math.min(Yn,this.pinchStartScale*(d/this.pinchStartDist))),f=this.getLOD(),u=this.zoom>=wr,p=this.zoom>=kt;this.world.scale.set(h),this.world.x=a-this.pinchPivotWorldX*h,this.world.y=c-this.pinchPivotWorldY*h,this.getLOD()!==f&&this.applyLOD(),(h>=wr!==u||h>=kt!==p)&&this.updateAllNameLabels(),this.updateAllRoomScales(h),(s=(i=this.callbacks).onZoomChanged)==null||s.call(i,h),this.setSelectedRoom(this.selectedRoom),this.redrawSafeMode();return}if(this.isDragging){const o=n.clientX-this.dragStartX,l=n.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,h=d-(a.maxX+1)*re*c,f=this.app.screen.width-d-a.minX*re*c,u=d-(a.maxY+1)*re*c,p=this.app.screen.height-d-a.minY*re*c;this.world.x=this.rubberBand(this.dragWorldX+o,h,f),this.world.y=this.rubberBand(this.dragWorldY+l,u,p)}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",n=>{if(n.preventDefault(),this.isAnimating=!1,t.set(n.pointerId,{x:n.clientX,y:n.clientY}),e.setPointerCapture(n.pointerId),t.size>=2){this.isDragging=!1,this.isPinching=!0;const i=[...t.values()],s=e.getBoundingClientRect(),o=(i[0].x+i[1].x)/2-s.left,l=(i[0].y+i[1].y)/2-s.top;this.pinchStartDist=Math.hypot(i[1].x-i[0].x,i[1].y-i[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=n.clientX,this.dragStartY=n.clientY,this.dragWorldX=this.world.x,this.dragWorldY=this.world.y}),e.addEventListener("pointerup",n=>{if(t.delete(n.pointerId),e.releasePointerCapture(n.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 i=e.getBoundingClientRect(),s=this.screenToRoom(n.clientX-i.left,n.clientY-i.top);s&&this.callbacks.onRoomClick(s)}this.springBack()}}),e.addEventListener("pointercancel",n=>{t.delete(n.pointerId),e.releasePointerCapture(n.pointerId),(this.isPinching||this.isDragging)&&(this.isPinching=!1,this.isDragging=!1,this.springBack())}),e.addEventListener("wheel",n=>{if(n.preventDefault(),this.isDragging||this.isPinching)return;this.isAnimating=!1;const i=this.world.scale.x,s=n.deltaY<0?1.1:.9,o=Math.max(jn,Math.min(Yn,i*s));this.applyZoomAt(o,n.offsetX,n.offsetY)},{passive:!1})}rubberBand(e,t,n){const i=n-t;if(i<=0||e>=t&&e<=n)return e;const s=.55;if(e<t){const l=t-e;return t-(1-1/(l*s/i+1))*i*s}const o=e-n;return n+(1-1/(o*s/i+1))*i*s}springBack(){const e=this.worldBoundsSet;if(!e)return;const t=this.world.scale.x,n=this.app.screen.width,i=this.app.screen.height,s=50,o=this.world.x+e.minX*re*t,l=this.world.x+(e.maxX+1)*re*t,a=this.world.y+e.minY*re*t,c=this.world.y+(e.maxY+1)*re*t;let d=this.world.x,h=this.world.y;l<s?d+=s-l:o>n-s&&(d-=o-(n-s)),c<s?h+=s-c:a>i-s&&(h-=a-(i-s)),(d!==this.world.x||h!==this.world.y)&&(this.animTargetX=d,this.animTargetY=h,this.isAnimating=!0)}screenToRoom(e,t){const n=this.world.scale.x,i=(e-this.world.x)/n,s=(t-this.world.y)/n,o=Math.floor(i/re),l=Math.floor(s/re);return ze(o,l)}emitHover(e,t){this.callbacks.onRoomHover(this.screenToRoom(e,t))}checkVisibleRooms(){const e=this.world.scale.x,t=this.world.x,n=this.world.y;if(this.lastCheckX===t&&this.lastCheckY===n&&this.lastCheckScale===e)return;this.lastCheckX=t,this.lastCheckY=n,this.lastCheckScale=e;const i=-t/e,s=-n/e,o=(this.app.screen.width-t)/e,l=(this.app.screen.height-n)/e,a=Math.floor(i/re)-1,c=Math.ceil(o/re),d=Math.floor(s/re)-1,h=Math.ceil(l/re);this.lastVisibleBounds={rxMin:a,rxMax:c,ryMin:d,ryMax:h};const f=[],u=this.worldBoundsSet,p=u?Math.max(a,u.minX):a,x=u?Math.min(c,u.maxX):c,M=u?Math.max(d,u.minY):d,m=u?Math.min(h,u.maxY):h;for(let A=p;A<=x;A++)for(let w=M;w<=m;w++){const b=ze(A,w);b&&f.push(b)}const k=`${a},${d},${c},${h}`;k!==this.lastVisibleKey&&(this.lastVisibleKey=k,this.visibleDebounceTimer!==null&&clearTimeout(this.visibleDebounceTimer),this.visibleDebounceTimer=setTimeout(()=>{this.visibleDebounceTimer=null,this.callbacks.onVisibleRoomsChanged(f)},wp))}}var Op=R('<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">'),Lp=R('<button type=button style="padding:5px 8px;border-radius:6px;cursor:pointer;font-size:11px;font-weight:600">');const Ap=[{mode:"owner",label:"Owner"},{mode:"mineral",label:"Mineral"},{mode:"none",label:"None"}];function Ip(r){const e=()=>(r.zoom??1)>=kt;return(()=>{var t=Op(),n=t.firstChild,i=n.firstChild,s=i.nextSibling,o=s.firstChild,l=o.nextSibling,a=l.nextSibling,c=a.nextSibling,d=s.nextSibling,h=d.firstChild,f=h.nextSibling,u=d.nextSibling,p=u.firstChild,x=p.nextSibling,M=n.nextSibling;return g(l,()=>{var m;return((m=r.zoom)==null?void 0:m.toFixed(2))??"—"}),g(c,()=>r.subsActive?"Yes":"No"),f.addEventListener("change",m=>ko(m.currentTarget.checked)),x.addEventListener("change",m=>To(m.currentTarget.checked)),g(M,_(ye,{each:Ap,children:m=>{const k=()=>dp()===m.mode;return(()=>{var A=Lp();return A.$$click=()=>up(m.mode),g(A,()=>m.label),N(w=>{var b=`1px solid ${k()?"#58a6ff":"#30363d"}`,C=k()?"#1f6feb33":"#161b22",P=k()?"#c9d1d9":"#8b949e";return b!==w.e&&z(A,"border",w.e=b),C!==w.t&&z(A,"background",w.t=C),P!==w.a&&z(A,"color",w.a=P),w},{e:void 0,t:void 0,a:void 0}),A})()}})),N(m=>{var k=e()?"#c9d1d9":"#484f58",A=e()?"pointer":"default",w=!e();return k!==m.e&&z(d,"color",m.e=k),A!==m.t&&z(d,"cursor",m.t=A),w!==m.a&&(f.disabled=m.a=w),m},{e:void 0,t:void 0,a:void 0}),N(()=>f.checked=So()),N(()=>x.checked=Co()),t})()}Se(["click"]);var Np=R('<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">'),Gp=R('<div style="padding:6px 8px;font-size:11px;color:#484f58;font-style:italic">None'),Dp=R('<div style="padding:3px 8px;color:#8b949e">Mineral'),zp=R('<div style="padding:3px 8px;color:#79c0ff">'),Bp=R('<div style="padding:3px 8px;color:#8b949e">Density'),Fp=R('<div style="padding:3px 8px;color:#c9d1d9">'),Hp=R('<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 Wp=["Low","Medium","High","Ultra"];function Up(r){return Wp[r-1]??String(r)}function Ms(r){return(()=>{var e=Np(),t=e.firstChild;return g(t,()=>r.label),g(e,_(W,{get when(){return r.info},get fallback(){return Gp()},children:n=>(()=>{var i=Hp(),s=i.firstChild,o=s.nextSibling,l=o.firstChild,a=l.nextSibling;return g(s,()=>n().room),g(a,()=>n().owner??"None"),g(o,_(W,{get when(){return n().mineral},get children(){return[Dp(),(()=>{var c=zp();return g(c,()=>n().mineral),c})(),Bp(),(()=>{var c=Fp();return g(c,()=>Up(n().density??0)),c})()]}}),null),i})()}),null),N(n=>{var i=`1px solid ${r.dim?"#21262d":"#30363d"}`,s=r.dim?.6:1;return i!==n.e&&z(e,"border",n.e=i),s!==n.t&&z(e,"opacity",n.t=s),n},{e:void 0,t:void 0}),e})()}var Xp=R("<span style=color:#8b949e;font-size:11px>Checking…"),jp=R('<div style=margin-top:8px><div style="padding:6px 8px;font-size:11px;font-weight:600;color:#c9d1d9;margin-bottom:6px">Your flags'),Yp=R('<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>'),Vp=R("<span style=color:#f85149;font-size:11px>"),qp=R("<div style=margin-top:8px;color:#484f58;font-style:italic;font-size:12px>No flags."),Zp=R('<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:Kp}=yt("flag"),Pi={};for(const[r,e]of Object.entries(Ar))Pi[e]=r;function Jp(){const r=p=>{Ho({...Yt(),...p})},[e,t]=G(null),[n,i]=G(!1);let s=null;de(()=>{if(pt()!=="flag"||Yt().name.trim()!=="")return;const p=ae();p&&p.http.game.genUniqueFlagName().then(x=>{r({name:x.name}),t(null)}).catch(x=>{Kp("gen unique name failed:",x)})});const o=p=>{r({name:p}),t(null),s&&clearTimeout(s);const x=p.trim();if(!x){i(!1);return}i(!0),s=setTimeout(()=>{const M=ae();if(!M){i(!1);return}M.http.game.checkUniqueFlagName(x).then(()=>{t(null)}).catch(m=>{t(m.message)}).finally(()=>{i(!1)})},300)},l=()=>Ar[Yt().color]??1,a=()=>Ar[Yt().secondaryColor]??1,c=p=>{r({color:Pi[p]??"COLOR_WHITE"})},d=p=>{r({secondaryColor:Pi[p]??"COLOR_WHITE"})},h=()=>{const p=Ta(),x=[];for(const[M,m]of Object.entries(p))m&&typeof m=="object"&&"room"in m&&"x"in m&&"y"in m&&x.push([M,m]);return x},f=p=>p===void 0||p<0||p>=Zt.length?"#8b949e":`#${Zt[p].toString(16).padStart(6,"0")}`,u={display:"flex","flex-direction":"column",gap:"5px","font-size":"11px",color:"#8b949e"};return(()=>{var p=Yp(),x=p.firstChild,M=x.firstChild,m=M.nextSibling,k=m.firstChild,A=k.firstChild,w=A.nextSibling,b=k.nextSibling;b.firstChild;var C=b.nextSibling;C.firstChild;var P=C.nextSibling;return w.$$input=y=>o(y.currentTarget.value),g(k,_(W,{get when(){return e()},children:y=>(()=>{var S=Vp();return g(S,y),S})()}),null),g(k,_(W,{get when(){return n()},get children(){return Xp()}}),null),g(b,_(vn,{get value(){return l()},onChange:c}),null),g(C,_(vn,{get value(){return a()},onChange:d}),null),g(P,(()=>{var y=J(()=>!!Pt());return()=>y()?`Marked at x=${Pt().tx}, y=${Pt().ty}. Click again to create the flag, or click elsewhere to move the mark.`:"Click a position in the room to mark it."})()),g(p,_(W,{get when(){return h().length>0},get fallback(){return qp()},get children(){var y=jp();return y.firstChild,g(y,_(ye,{get each(){return h()},children:([S,O])=>(()=>{var v=Zp(),E=v.firstChild,L=E.firstChild,I=L.nextSibling,B=I.nextSibling,D=B.nextSibling,F=D.firstChild,U=F.nextSibling,Q=U.nextSibling,K=Q.nextSibling;return K.nextSibling,g(I,S),g(B,()=>O.room),g(D,()=>O.x,U),g(D,()=>O.y,K),N(H=>z(L,"background",f(O.color))),v})()}),null),y}}),null),N(y=>{var S=u,O=`1px solid ${e()?"#f85149":"#30363d"}`,v=u,E=u;return y.e=Y(k,S,y.e),O!==y.t&&z(w,"border",y.t=O),y.a=Y(b,v,y.a),y.o=Y(C,E,y.o),y},{e:void 0,t:void 0,a:void 0,o:void 0}),N(()=>w.value=Yt().name),p})()}Se(["input"]);var Qp=R("<span style=color:#8b949e>…"),eg=R("<span style=color:#3fb950>✓"),tg=R("<span style=color:#f85149>✗"),rg=R("<div style=font-size:10px;color:#f85149>"),ng=R('<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>'),ig=R('<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>'),sg=R('<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 og(r){const e=Object.keys(mn),[t,n]=G("idle"),[i,s]=G("");let o=null;const l=(p,x)=>{const M=mn[p];return M?At()==="empty"&&p==="spawn"?Math.max(M[x]??0,1):M[x]??0:0},a=(p,x)=>{const M=l(p,x);if(M===2500)return 1/0;const m=fn()[p]??0;return Math.max(0,M-m)},c=()=>rt().structureType==="spawn";de(ul(()=>rt().structureType,p=>{if(p!=="spawn")return;const x=ae();x&&(n("loading"),s(""),x.http.game.genUniqueObjectName("spawn",r.shard).then(M=>{Mt({structureType:"spawn",structureName:M.name}),n("valid")}).catch(()=>{Mt({structureType:"spawn",structureName:"Spawn1"}),n("idle")}))}));const d=p=>{if(o&&clearTimeout(o),!p.trim()){n("invalid"),s("Name cannot be empty");return}n("loading"),s(""),o=setTimeout(()=>{const x=ae();x&&x.http.game.checkUniqueObjectName("spawn",p.trim(),r.shard).then(M=>{M.error?(n("invalid"),s(M.error)):(n("valid"),s(""))}).catch(()=>{n("invalid"),s("Could not validate name")})},400)},h=p=>{Mt({structureType:"spawn",structureName:p}),d(p)},f=p=>{Mt({structureType:p,structureName:""}),n("idle"),s("")},u=()=>{switch(t()){case"loading":return Qp();case"valid":return eg();case"invalid":return tg();default:return null}};return(()=>{var p=ig(),x=p.firstChild,M=x.firstChild;M.firstChild;var m=M.nextSibling,k=x.nextSibling;k.firstChild;var A=k.nextSibling,w=A.firstChild;return g(M,()=>Ee()??"?",null),g(m,()=>{const b=At();return b==="empty"?"World is empty — place a spawn to claim this room.":b==="lost"?"You lost all your spawns — respawn to continue.":Ee()!=null?`RCL ${Ee()} — Select a structure type and click a tile to build.`:"No controller — roads and containers only."}),g(k,_(ye,{each:e,children:b=>{const C=()=>Ee()??0,P=()=>l(b,C()),y=()=>fn()[b]??0,S=()=>rt().structureType===b,O=()=>P()===2500,v=()=>!O()&&a(b,C())<=0;return _(W,{get when(){return P()>0},get children(){var E=sg(),L=E.firstChild,I=L.nextSibling;return E.$$click=()=>!v()&&f(b),g(L,()=>b.replace(/([A-Z])/g," $1").trim(),null),g(L,()=>S()&&" ✓",null),g(I,(()=>{var B=J(()=>!!O());return()=>B()?`${y()}/∞`:`${y()}/${P()}`})(),null),g(I,()=>v()&&" (Max)",null),N(B=>{var D=S()?"#1f3158":"transparent",F=v()?"default":"pointer",U=v()?.5:1;return D!==B.e&&z(E,"background",B.e=D),F!==B.t&&z(E,"cursor",B.t=F),U!==B.a&&z(E,"opacity",B.a=U),B},{e:void 0,t:void 0,a:void 0}),E}})}}),null),g(p,_(W,{get when(){return c()},get children(){var b=ng(),C=b.firstChild,P=C.nextSibling,y=P.firstChild,S=y.firstChild,O=S.nextSibling;return S.$$input=v=>h(v.currentTarget.value),g(O,u),g(P,_(W,{get when(){return J(()=>t()==="invalid")()&&i()},get children(){var v=rg();return g(v,i),v}}),null),N(v=>z(S,"border",`1px solid ${t()==="invalid"?"#f85149":t()==="valid"?"#238636":"#30363d"}`)),N(()=>S.value=rt().structureName??""),b}}),A),g(w,()=>rt().structureType?"Click a tile in the room to build.":"Select a structure type, then click a tile."),p})()}Se(["input","click"]);var lg=R('<div style="padding:8px;border-bottom:1px solid #30363d;flex-shrink:0"><div style=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">'),Es=R("<button type=button>"),ag=R("<option>/s");const cg=[.5,1,2,5,10,20],dg=[{delta:-100,label:"-100"},{delta:-10,label:"-10"}],ug=[{delta:10,label:"+10"},{delta:100,label:"+100"}];function Rs(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 hg(){const r=()=>{const e=Pr(),t=it(),n=ln()??3e3,i=(e-t)*n;return new Date(Date.now()-i).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})};return(()=>{var e=lg(),t=e.firstChild,n=t.firstChild,i=n.firstChild,s=i.nextSibling;s.firstChild;var o=n.nextSibling,l=o.firstChild,a=o.nextSibling,c=a.firstChild,d=c.nextSibling;return g(i,(()=>{var h=J(()=>!!Xe());return()=>h()?"Loading…":`Tick ${it()}`})()),g(s,r,null),g(o,_(ye,{each:dg,children:h=>(()=>{var f=Es();return f.$$click=()=>ms(h.delta),g(f,()=>h.label),N(u=>{var p=Xe(),x=Rs(Xe());return p!==u.e&&(f.disabled=u.e=p),u.t=Y(f,x,u.t),u},{e:void 0,t:void 0}),f})()}),l),Qe(l,"click",eh,!0),g(l,()=>Tr()?"⏸":"▶"),g(o,_(ye,{each:ug,children:h=>(()=>{var f=Es();return f.$$click=()=>ms(h.delta),g(f,()=>h.label),N(u=>{var p=Xe(),x=Rs(Xe());return p!==u.e&&(f.disabled=u.e=p),u.t=Y(f,x,u.t),u},{e:void 0,t:void 0}),f})()}),null),d.addEventListener("change",h=>th(parseFloat(h.currentTarget.value))),g(d,_(ye,{each:cg,children:h=>(()=>{var f=ag(),u=f.firstChild;return f.value=h,g(f,h,u),f})()})),N(h=>{var f=Xe()?"#f0883e":"#c9d1d9",u=Xe(),p=Tr()?"#1a3a2a":"#161b22",x=Tr()?"#3fb950":"#8b949e",M=Xe()?"not-allowed":"pointer";return f!==h.e&&z(i,"color",h.e=f),u!==h.t&&(l.disabled=h.t=u),p!==h.a&&z(l,"background",h.a=p),x!==h.o&&z(l,"color",h.o=x),M!==h.i&&z(l,"cursor",h.i=M),h},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),N(()=>d.value=Ui()),e})()}Se(["click"]);var fg=R("<div style=padding-bottom:8px;overflow:auto;min-height:0>"),pg=R('<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'),gg=R("<button style=background:transparent;border:none;color:#8b949e;font-size:14px;cursor:pointer;padding:4px>"),mg=R("<button style=background:transparent;border:none;color:#8b949e;font-size:11px;cursor:pointer>Collapse");function yg(r){return _(W,{get when(){return pt()==="flag"},get fallback(){return _(W,{get when(){return pt()==="build"},get fallback(){return _(tp,{})},get children(){return _(og,{get shard(){return r.shard}})}})},get children(){return _(Jp,{})}})}function vg(r){const e=()=>{var n;(n=r.onToggle)==null||n.call(r)},t=n=>{var i;n.stopPropagation(),(i=r.onToggle)==null||i.call(r)};return(()=>{var n=pg(),i=n.firstChild,s=i.nextSibling,o=s.firstChild;return o.firstChild,i.$$click=e,g(i,(()=>{var l=J(()=>!!r.onToggle);return()=>l()&&(()=>{var a=gg();return a.$$click=t,g(a,()=>r.isCollapsed?"▶":"◀"),a})()})()),g(o,(()=>{var l=J(()=>!!r.onToggle);return()=>l()&&(()=>{var a=mg();return a.$$click=t,a})()})(),null),g(s,_(W,{get when(){return r.mapMode},get fallback(){return _(cp,{get room(){return r.room??"—"},get shard(){return r.shard??null}})},get children(){return _(Ip,{get zoom(){return r.mapZoom},get subsActive(){return r.mapSubsActive}})}}),null),g(s,_(W,{get when(){return J(()=>!r.mapMode)()&&ue()},get children(){return _(hg,{})}}),null),g(s,_(W,{get when(){return r.mapMode},get fallback(){return _(yg,{get shard(){return r.shard}})},get children(){var l=fg();return g(l,_(Ms,{label:"Selected",get info(){return r.selectedRoomInfo??null}}),null),g(l,_(Ms,{label:"Cursor",get info(){return r.hoveredRoomInfo??null},dim:!0}),null),l}}),null),n})()}Se(["click"]);var bg=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>CPU:</span><span style=color:#c9d1d9>"),wg=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Memory:</span><span style=color:#c9d1d9>"),xg=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Zoom:</span><span style=color:#c9d1d9>%"),_g=R("<div style=display:flex;gap:6px;align-items:center><span style=font-weight:600>Subs:</span><span>"),$g=R('<div style="display:flex;gap:16px;padding:6px 16px;font-size:12px;color:#8b949e;align-items:center">');function Sg(r){const[e,t]=G(null);Nt(()=>{const s=ae();if(!s)return;const o=new Ai;o.add(s.stores.user.subscribe("cpu")),o.add(s.stores.user.on("user:cpu",l=>{t(l)})),Pe(()=>{o.dispose()})});const n=()=>{var l;const s=e();if(!s)return"—";const o=((l=Re())==null?void 0:l.cpu)??"?";return`${s.cpu.toFixed(1)} / ${o}`},i=()=>{const s=e();return s?`${(s.memory/1024).toFixed(1)} KB`:"—"};return(()=>{var s=$g();return g(s,_(W,{get when(){return e()!==null},get children(){return[(()=>{var o=bg(),l=o.firstChild,a=l.nextSibling;return g(a,n),o})(),(()=>{var o=wg(),l=o.firstChild,a=l.nextSibling;return g(a,i),o})()]}}),null),g(s,_(W,{get when(){return J(()=>r.mapZoom!==null)()&&r.mapZoom!==void 0},get children(){return[(()=>{var o=xg(),l=o.firstChild,a=l.nextSibling,c=a.firstChild;return g(a,()=>(r.mapZoom*100).toFixed(0),c),o})(),(()=>{var o=_g(),l=o.firstChild,a=l.nextSibling;return g(a,()=>r.mapSubsActive===!1?"paused":"active"),N(c=>z(a,"color",r.mapSubsActive===!1?"#e3b341":"#3fb950")),o})()]}}),null),s})()}var kg=R('<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">'),Cg=R("<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>"),Tg=R('<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">'),Mg=R("<button style=width:100%;aspect-ratio:1;border-radius:2px;cursor:pointer;padding:0;outline:none>");const il={};for(let r=1;r<=24;r++){const e=xn({type:r,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1});il[r]=`data:image/svg+xml,${encodeURIComponent(e)}`}function xt(r){var e;return typeof r=="string"?r:((e=$r[r])==null?void 0:e.rgb)??"#000000"}function Zr(r){return typeof r=="number"?Math.max(0,Math.min(79,r)):r}const Eg=[{slot:1,label:"Background"},{slot:2,label:"Primary"},{slot:3,label:"Secondary"}],Rg=Array.from({length:24},(r,e)=>e+1),Vn=/^#[0-9a-f]{6}$/i;function Pg(r){const[e,t]=G(ge(()=>typeof r.badge.type=="number"?r.badge.type:1)),[n,i]=G(ge(()=>Zr(r.badge.color1))),[s,o]=G(ge(()=>Zr(r.badge.color2))),[l,a]=G(ge(()=>Zr(r.badge.color3))),[c,d]=G(ge(()=>r.badge.param??0)),[h,f]=G(ge(()=>r.badge.flip??!1)),[u,p]=G(1),[x,M]=G(!1),[m,k]=G(ge(()=>xt(Zr(r.badge.color1)))),A=v=>v===1?n():v===2?s():l(),w=v=>{const E=u();E===1?i(v):E===2?o(v):a(v)};de(()=>{k(xt(A(u())))});const b=v=>{var L;const E=A(u());return typeof E=="number"?E===v:E.toLowerCase()===(((L=$r[v])==null?void 0:L.rgb)??"").toLowerCase()},C=()=>({type:e(),color1:xt(n()),color2:xt(s()),color3:xt(l()),param:c(),flip:h()}),P=Mr(()=>{const v=xn(C());return`data:image/svg+xml,${encodeURIComponent(v)}`}),y=v=>{if(k(v),!Vn.test(v))return;const E=$r.findIndex(L=>L.rgb.toLowerCase()===v.toLowerCase());w(E>=0?E:v)},S=async()=>{var E;const v=ae();if(v){M(!0);try{await v.http.user.badge(C()),await v.stores.user.refreshMe(),r.onClose(),(E=r.onSaved)==null||E.call(r),we("Badge saved","success",3e3)}catch(L){we(`Failed to save badge: ${L instanceof Error?L.message:String(L)}`,"error",5e3)}finally{M(!1)}}},O=v=>{v.target===v.currentTarget&&r.onClose()};return(()=>{var v=kg(),E=v.firstChild,L=E.firstChild,I=L.firstChild,B=I.nextSibling,D=L.nextSibling,F=D.firstChild,U=F.firstChild,Q=U.firstChild,K=Q.nextSibling,H=U.nextSibling,X=H.firstChild,j=X.nextSibling,Z=F.nextSibling,se=Z.firstChild,Le=se.nextSibling,Ye=Le.nextSibling,st=Ye.nextSibling,Ve=st.firstChild,ot=Ve.nextSibling,lt=Z.nextSibling,Ae=lt.firstChild,oe=Ae.firstChild,Te=oe.nextSibling,vt=Ae.nextSibling,zr=lt.nextSibling,cr=zr.firstChild,ie=D.nextSibling,ne=ie.firstChild,ce=ne.nextSibling;return v.$$click=O,B.$$click=()=>r.onClose(),g(B,_(It,{size:18})),g(j,_(ye,{each:Rg,children:V=>(()=>{var q=Cg(),te=q.firstChild;return q.$$click=()=>t(V),N(ve=>{var be=e()===V?"#1f3a2a":"#0d1117",De=`1px solid ${e()===V?"#238636":"#21262d"}`,at=e()===V?P():il[V];return be!==ve.e&&z(q,"background",ve.e=be),De!==ve.t&&z(q,"border",ve.t=De),at!==ve.a&&me(te,"src",ve.a=at),ve},{e:void 0,t:void 0,a:void 0}),q})()})),g(Le,_(ye,{each:Eg,children:({slot:V,label:q})=>(()=>{var te=Tg(),ve=te.firstChild;return te.$$click=()=>p(V),g(te,q,null),N(be=>{var De=`1px solid ${u()===V?"#58a6ff":"#30363d"}`,at=u()===V?"#1c2d47":"transparent",dr=u()===V?"#58a6ff":"#8b949e",ur=xt(A(V));return De!==be.e&&z(te,"border",be.e=De),at!==be.t&&z(te,"background",be.t=at),dr!==be.a&&z(te,"color",be.a=dr),ur!==be.o&&z(ve,"background",be.o=ur),be},{e:void 0,t:void 0,a:void 0,o:void 0}),te})()})),g(Ye,_(ye,{each:$r,children:V=>(()=>{var q=Mg();return q.$$click=()=>w(V.index),N(te=>{var ve=V.rgb,be=V.rgb,De=b(V.index)?"2px solid #fff":"1px solid transparent";return ve!==te.e&&me(q,"title",te.e=ve),be!==te.t&&z(q,"background",te.t=be),De!==te.a&&z(q,"border",te.a=De),te},{e:void 0,t:void 0,a:void 0}),q})()})),ot.$$input=V=>y(V.currentTarget.value),g(Te,c),vt.$$input=V=>d(+V.currentTarget.value),cr.addEventListener("change",V=>f(V.currentTarget.checked)),ne.$$click=()=>r.onClose(),ce.$$click=S,g(ce,()=>x()?"Saving…":"Save Badge"),N(V=>{var q=P(),te=Vn.test(m())?m():xt(A(u())),ve=`1px solid ${Vn.test(m())?"#30363d":"#f85149"}`,be=x(),De=x()?"not-allowed":"pointer",at=x(),dr=x()?"not-allowed":"pointer",ur=x()?.7:1;return q!==V.e&&me(K,"src",V.e=q),te!==V.t&&z(Ve,"background",V.t=te),ve!==V.a&&z(ot,"border",V.a=ve),be!==V.o&&(ne.disabled=V.o=be),De!==V.i&&z(ne,"cursor",V.i=De),at!==V.n&&(ce.disabled=V.n=at),dr!==V.s&&z(ce,"cursor",V.s=dr),ur!==V.h&&z(ce,"opacity",V.h=ur),V},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),N(()=>ot.value=m()),N(()=>vt.value=c()),N(()=>cr.checked=h()),v})()}Se(["click","input"]);var Og=R('<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">'),Lg=R("<div style=font-size:11px;color:#8b949e;margin-top:3px>"),Ag=R("<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>"),Ig=R('<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>'),Ng=R("<img width=40 height=40 style=display:block>"),Gg=R('<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">'),Dg=R('<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">'),zg=R('<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 Bg={type:1,color1:"#4a5060",color2:"#7a9ec0",color3:"#c0daf0",param:0,flip:!1};function xr(r){return(()=>{var e=Og(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild;return g(n,()=>r.label),g(t,(()=>{var o=J(()=>!!r.description);return()=>o()&&(()=>{var l=Lg();return g(l,()=>r.description),l})()})(),null),i.$$click=()=>r.onChange(!r.value),N(o=>{var l=r.value?"#238636":"#30363d",a=r.value?"22px":"2px";return l!==o.e&&z(i,"background",o.e=l),a!==o.t&&z(s,"left",o.t=a),o},{e:void 0,t:void 0}),e})()}function Wt(r){return(()=>{var e=Ag(),t=e.firstChild;return g(t,()=>r.title),g(e,()=>r.children,null),e})()}function Ps(r){return(()=>{var e=Ig(),t=e.firstChild,n=t.nextSibling;return g(t,()=>r.label),g(n,()=>r.value),e})()}function Fg(r){var c;const e=Sa(),t=!Be()&&!((c=Re())!=null&&c.badge),[n,i]=G(t),[s,o]=G(!1),l=Mr(()=>{var f;const d=(f=Re())==null?void 0:f.badge;if(!d)return null;const h=xn(d);return`data:image/svg+xml,${encodeURIComponent(h)}`});async function a(){o(!0);try{await Ca(),we("All caches cleared. Reloading…","success",2e3),setTimeout(()=>window.location.reload(),1500)}catch{we("Failed to clear caches.","error"),o(!1)}}return(()=>{var d=zg(),h=d.firstChild,f=h.firstChild,u=f.nextSibling,p=h.nextSibling,x=p.firstChild;return u.$$click=()=>r.onClose(),g(u,_(It,{size:18})),g(d,_(W,{get when(){return n()},get children(){return _(Pg,{get badge(){var M;return((M=Re())==null?void 0:M.badge)??Bg},onClose:()=>i(!1),onSaved:t?()=>r.onClose():void 0})}}),p),g(x,_(Wt,{title:"Layout",get children(){return _(xr,{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 _o()},onChange:Nu})}}),null),g(x,_(Wt,{title:"Room View",get children(){return[_(xr,{label:"Show creep labels",description:"Display each creep's name above its sprite.",get value(){return dn()},onChange:$o}),_(xr,{label:"Terrain effects",description:"Swamp glow and wall noise texture overlay.",get value(){return sn()},onChange:Gu})]}}),null),g(x,_(Wt,{title:"Map View",get children(){return[_(xr,{label:"Show room names",description:"Render a small room name in the top-left corner of each map tile.",get value(){return So()},onChange:ko}),_(xr,{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 Co()},onChange:To})]}}),null),g(x,_(W,{get when(){return!Be()},get children(){return _(Wt,{title:"Player Badge",get children(){var M=Gg(),m=M.firstChild,k=m.firstChild,A=m.nextSibling;return g(m,_(W,{get when(){return l()},get children(){var w=Ng();return N(()=>me(w,"src",l())),w}}),k),g(k,()=>{var w;return((w=Re())==null?void 0:w.username)??""}),A.$$click=()=>i(!0),g(A,()=>l()?"Edit Badge":"Create Badge"),M}})}}),null),g(x,_(Wt,{title:"Data",get children(){var M=Dg(),m=M.firstChild,k=m.firstChild;k.nextSibling;var A=m.nextSibling;return A.$$click=a,g(A,()=>s()?"Clearing…":"Clear"),N(w=>{var b=s(),C=s()?"#8b949e":"#f85149",P=s()?"default":"pointer",y=s()?.6:1;return b!==w.e&&(A.disabled=w.e=b),C!==w.t&&z(A,"color",w.t=C),P!==w.a&&z(A,"cursor",w.a=P),y!==w.o&&z(A,"opacity",w.o=y),w},{e:void 0,t:void 0,a:void 0,o:void 0}),M}}),null),g(x,_(Wt,{title:"About",get children(){return[_(Ps,{label:"Client version",get value(){return $a()}}),J(()=>e&&_(Ps,{label:"Mod version",get value(){return`${e.version} (${e.kind})`}}))]}}),null),d})()}Se(["click"]);var Hg=R('<button style="padding:7px;border-radius:4px;cursor:pointer;margin:0 4px;display:flex;align-items:center">'),Wg=R('<button style="padding:7px;border-radius:4px;border:1px solid #30363d;background:#21262d;margin:0 2px;display:flex;align-items:center">'),Ug=R("<div style=flex:1;position:relative;overflow:hidden>"),Xg=R('<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>'),jg=R('<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>'),Yg=R("<div style=display:flex;flex:1;overflow:hidden><div style=display:flex;flex-direction:column;flex:1;overflow:hidden>"),Vg=R('<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">'),qg=R("<div style=display:flex;flex-direction:column;flex:1;overflow:hidden><div style=display:flex;flex:1;overflow:hidden>");const Zg=Is(()=>Li(()=>import("./CodePanel-DFEeWiMS.js"),__vite__mapDeps([0,1,2])).then(r=>({default:r.CodePanel}))),Kg=Is(()=>Li(()=>import("./MapViewer-B8jKtgs1.js"),__vite__mapDeps([3,1,2])).then(r=>({default:r.MapViewer})));function qn(){const r=$n(),e=window.location.pathname.match(new RegExp(`^${r}/room/([A-Za-z0-9]+)`));if(!e)return{room:null,shard:null,tick:null};const t=e[1].toUpperCase();if(!tt(t))return{room:null,shard:null,tick:null};const n=new URLSearchParams(window.location.search).get("shard"),i=window.location.hash.match(/tick=(\d+)/),s=i?parseInt(i[1],10):null;return{room:t,shard:n,tick:s}}function Zn(r,e){return`${$n()}/room/${r}${e?`?shard=${encodeURIComponent(e)}`:""}`}function Os(r){return`${$n()}/map${r?`?shard=${encodeURIComponent(r)}`:""}`}function Kn(){return window.location.pathname.startsWith(`${$n()}/map`)?{shard:new URLSearchParams(window.location.search).get("shard")}:null}function Jn(r){return(()=>{var e=Hg();return e.$$click=()=>r.onClick(),g(e,()=>r.children),N(t=>{var n=r.title,i=`1px solid ${r.active?"#388bfd":"#30363d"}`,s=r.active?"#1f3158":"#21262d",o=r.active?"#58a6ff":"#c9d1d9";return n!==t.e&&me(e,"title",t.e=n),i!==t.t&&z(e,"border",t.t=i),s!==t.a&&z(e,"background",t.a=s),o!==t.o&&z(e,"color",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function Ls(r){return(()=>{var e=Wg();return e.$$click=()=>r.onClick(),g(e,()=>r.children),N(t=>{var n=r.title,i=r.disabled,s=r.disabled?"#484f58":"#c9d1d9",o=r.disabled?"default":"pointer";return n!==t.e&&me(e,"title",t.e=n),i!==t.t&&(e.disabled=t.t=i),s!==t.a&&z(e,"color",t.a=s),o!==t.o&&z(e,"cursor",t.o=o),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}function Jg(){var cr;const r=qn(),[e,t]=G(r.room??Tn(fe.room)??"W1N1"),[n,i]=G(r.shard??Tn(fe.shard)),[s,o]=G(Kn()!==null||!r.room),[l,a]=G(!Be()&&!((cr=Re())!=null&&cr.badge)),[c,d]=G(!1),[h,f]=G(!1);de(()=>{c(),f(!0),Promise.resolve().then(()=>f(!1))}),de(()=>{Be()&&Tt("view")}),de(()=>{var ne,ce,V;if(n()!==null||Qs()!==!1)return;const ie=(V=(ce=(ne=Gi())==null?void 0:ne.serverData)==null?void 0:ce.shards)==null?void 0:V[0];ie&&i(ie)});const[u,p]=G(void 0),[x,M]=G(null),[m,k]=G(null),A=Tn(fe.mapZoom),[w,b]=G(r.room&&A?Number(A):null),[C,P]=G(null),[y,S]=G(!1),[O,v]=G(!1);let E=r.tick;de(()=>{const ie=Ne();if(ie===null||E===null)return;const ne=E;E=null,Fo(ie),gn(ne)}),de(()=>{if(s())return;const ie=Zn(e(),n());ue()?history.replaceState(null,"",`${ie}#tick=${it()}`):history.replaceState(null,"",ie)});const[L,I]=G(Br(fe.sidebarWidth,300)),[B,D]=G(Br(fe.sidebarWidth,300)),[F,U]=G(Br(fe.consoleHeight,220)),[Q,K]=G(Br(fe.consoleHeight,220)),[H,X]=G(!1),[j,Z]=G(!1),se=()=>L()<=32,Le=()=>F()<=32,Ye=()=>{L()>32?(D(L()),I(32)):I(B())},st=()=>{F()>32?(K(F()),U(32)):U(Q())},Ve=ie=>{ie.preventDefault(),X(!0);const ne=ie.clientX,ce=L(),V=te=>{const ve=te.clientX-ne;I(Math.max(32,Math.min(500,ce-ve)))},q=()=>{X(!1),Mn(fe.sidebarWidth,L()),window.removeEventListener("pointermove",V),window.removeEventListener("pointerup",q)};window.addEventListener("pointermove",V),window.addEventListener("pointerup",q)},ot=ie=>{ie.preventDefault(),Z(!0);const ne=ie.clientY,ce=F(),V=te=>{const ve=te.clientY-ne;U(Math.max(32,Math.min(500,ce-ve)))},q=()=>{Z(!1),Mn(fe.consoleHeight,F()),window.removeEventListener("pointermove",V),window.removeEventListener("pointerup",q)};window.addEventListener("pointermove",V),window.addEventListener("pointerup",q)},lt=(ie,ne)=>{var ce;(ce=ae())==null||ce.stores.navigation.navigateTo(ie,ne)},Ae=ie=>{p(ie),o(!0),history.pushState(null,"",Os(n()))},oe=()=>{s()?(o(!1),M(null),k(null),history.pushState(null,"",Zn(e(),n()))):Ae(e())};Nt(()=>{var V;!qn().room&&!Kn()&&history.replaceState(null,"",Os(n()));const ie=()=>{const q=Kn();if(q){o(!0),q.shard!==null&&i(q.shard),ge(ue)&&pn();return}const{room:te,shard:ve,tick:be}=qn();te&&(t(te),i(ve),o(!1),be!==null?E=be:ge(ue)&&pn())};window.addEventListener("popstate",ie),Pe(()=>window.removeEventListener("popstate",ie));const ne=(V=ae())==null?void 0:V.stores.navigation;if(ne){const q=ne.on("navigation:change",te=>{te.room!==null&&(t(te.room),i(te.shard),o(!1),M(null),k(null),S(ne.canBack()),v(ne.canForward()),Ji(fe.room,te.room),te.shard?Ji(fe.shard,te.shard):ka(fe.shard),history.pushState(null,"",Zn(te.room,te.shard)))});Pe(()=>q.dispose())}const ce=q=>{if(!Go(q.target)){if(q.key==="o"||q.key==="O"){d(te=>!te),a(!1);return}(q.key==="l"||q.key==="L")&&Xo(),(q.key==="c"||q.key==="C")&&jo(),(q.key==="y"||q.key==="Y")&&Yo(),s()||(q.key==="1"&&Tt("view"),Be()||(q.key==="2"&&Tt("flag"),q.key==="3"&&Tt("build")),q.key==="m"&&Ae(e()))}};window.addEventListener("keydown",ce),Pe(()=>window.removeEventListener("keydown",ce))});const Te=()=>(()=>{var ie=Ug();return g(ie,_(W,{get when(){return l()},get children(){return _(Fg,{onClose:()=>a(!1)})}}),null),g(ie,_(W,{get when(){return c()},get children(){return _(Zg,{onClose:()=>d(!1)})}}),null),g(ie,_(W,{get when(){return!s()},get fallback(){return _(Kg,{get shard(){return n()},get originRoom(){return u()},get initialZoom(){return w()??void 0},onNavigateToRoom:ne=>lt(ne,n()),onHoveredRoomChanged:M,onSelectedRoomChanged:k,onZoomChanged:ne=>{b(ne),Mn(fe.mapZoom,ne)},onSubscriptionStateChanged:P})},get children(){return _(mh,{get room(){return e()},get shard(){return n()},onNavigate:lt})}}),null),ie})(),vt=()=>_(W,{get when(){return!Be()},get children(){var ie=Xg(),ne=ie.firstChild;return ne.$$pointerdown=ot,g(ie,_(tf,{get shard(){return n()},get isCollapsed(){return Le()},onToggle:st}),null),N(ce=>{var V=`${F()}px`,q=j()?"none":"height 0.15s ease";return V!==ce.e&&z(ie,"height",ce.e=V),q!==ce.t&&z(ie,"transition",ce.t=q),ce},{e:void 0,t:void 0}),ie}}),zr=ie=>(()=>{var ne=jg(),ce=ne.firstChild;return ce.$$pointerdown=Ve,g(ne,_(vg,{get isCollapsed(){return se()},onToggle:Ye,get mapMode(){return s()},get hoveredRoomInfo(){return x()},get selectedRoomInfo(){return m()},get room(){return e()},get shard(){return n()},get mapZoom(){return w()},get mapSubsActive(){return C()}}),null),N(V=>{var q=c()?"0":`${L()}px`,te=ie&&!(h()||H())?"width 0.15s ease":"none";return q!==V.e&&z(ne,"width",V.e=q),te!==V.t&&z(ne,"transition",V.t=te),V},{e:void 0,t:void 0}),ne})();return(()=>{var ie=Vg(),ne=ie.firstChild,ce=ne.firstChild,V=ce.nextSibling;return g(ne,_(Td,{}),ce),g(ne,_(W,{get when(){return!Be()||s()},get children(){return _(Sg,{get mapZoom(){return J(()=>!!s())()?w():null},get mapSubsActive(){return J(()=>!!s())()?C():null}})}}),ce),g(ne,_(Ls,{title:"Back",get disabled(){return!y()},onClick:()=>{var q;return(q=ae())==null?void 0:q.stores.navigation.back()},get children(){return _(ec,{size:16})}}),V),g(ne,_(Ls,{title:"Forward",get disabled(){return!O()},onClick:()=>{var q;return(q=ae())==null?void 0:q.stores.navigation.forward()},get children(){return _(to,{size:16})}}),V),g(ne,_(Jn,{get title(){return s()?"Room View":"Map"},get active(){return s()},onClick:oe,get children(){return J(()=>!!s())()?_(mc,{size:16}):_(kc,{size:16})}}),V),g(ne,_(Jn,{title:"Code Editor",get active(){return c()},onClick:()=>{d(q=>!q),a(!1)},get children(){return _(oc,{size:16})}}),V),g(ne,_(Jn,{title:"Settings",get active(){return l()},onClick:()=>{a(q=>!q),d(!1)},get children(){return _(Wc,{size:16})}}),V),Qe(V,"click",Oa,!0),g(V,_(_c,{size:16})),g(ie,_(W,{get when(){return _o()},get fallback(){return(()=>{var q=qg(),te=q.firstChild;return g(te,Te,null),g(te,()=>zr(!0),null),g(q,vt,null),q})()},get children(){var q=Yg(),te=q.firstChild;return g(te,Te,null),g(te,vt,null),g(q,()=>zr(!1),null),q}}),null),g(ie,_(bh,{}),null),ie})()}Se(["click","pointerdown"]);var Qg=R("<div style=width:100%;height:100%>");function e0(){const r=()=>Et()==="connected"&&ae()!==null;return Nt(async()=>{if(Et()==="idle"&&(await Pa().catch(()=>{}),Et()!=="connected")){const e=_n();Ct({url:e,auth:"guest",storage:null}).catch(()=>{})}}),(()=>{var e=Qg();return g(e,(()=>{var t=J(()=>!!r());return()=>t()?_(Jg,{}):_(Sd,{})})()),e})()}const sl=document.getElementById("root");if(!sl)throw new Error("Root element not found");Cl(()=>_(e0,{}),sl);export{o0 as M,we as a,yt as b,ae as c,Se as d,i0 as e,ze as f,s0 as g,ki as h,g as i,Zs as j,So as k,Co as l,dp as m,Ku as n,Re as o,tt as p,z as s,R as t,Vt as u,Rn as w};