screeps-client 0.4.0 → 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.
- package/dist/embedded/{assets/CodePanel-DkDYXbQL.js → _client/CodePanel-CQz186KT.js} +1 -1
- package/dist/embedded/{assets/MapViewer-CoCRN8TR.js → _client/MapViewer-CvJfxsK0.js} +1 -1
- package/dist/embedded/{assets/index-DTRa3SgN.js → _client/index-RlhG0JKu.js} +3 -3
- package/dist/embedded/index.html +3 -3
- package/dist/standalone/{assets/CodePanel-C0efW9c6.js → _client/CodePanel-U6dyPwU0.js} +1 -1
- package/dist/standalone/{assets/MapViewer-BN8i0uFB.js → _client/MapViewer-BlPsc-Ax.js} +1 -1
- package/dist/standalone/{assets/index-Cd5zMBNk.js → _client/index-BQrrXAc2.js} +3 -3
- package/dist/standalone/index.html +3 -3
- package/dist/xxscreeps-mod/{assets/CodePanel-OjDhyKF-.js → _client/CodePanel-DFEeWiMS.js} +1 -1
- package/dist/xxscreeps-mod/{assets/MapViewer-B7WO94rt.js → _client/MapViewer-B8jKtgs1.js} +1 -1
- package/dist/xxscreeps-mod/{assets/index-D5eNG4b5.js → _client/index-63TVlkxt.js} +3 -3
- package/dist/xxscreeps-mod/index.html +3 -3
- package/package.json +1 -1
- /package/dist/embedded/{assets → _client}/terrain.worker-D9zNeJfz.js +0 -0
- /package/dist/embedded/{assets → _client}/vendor-codemirror-D3PB7yT8.js +0 -0
- /package/dist/embedded/{assets → _client}/vendor-pixi-Do7-_WYv.js +0 -0
- /package/dist/standalone/{assets → _client}/terrain.worker-D9zNeJfz.js +0 -0
- /package/dist/standalone/{assets → _client}/vendor-codemirror-D3PB7yT8.js +0 -0
- /package/dist/standalone/{assets → _client}/vendor-pixi-CXkRT4gi.js +0 -0
- /package/dist/xxscreeps-mod/{assets → _client}/terrain.worker-D9zNeJfz.js +0 -0
- /package/dist/xxscreeps-mod/{assets → _client}/vendor-codemirror-D3PB7yT8.js +0 -0
- /package/dist/xxscreeps-mod/{assets → _client}/vendor-pixi-CXkRT4gi.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["
|
|
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
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.0"}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)}/**
|
|
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
4
|
* @license lucide-solid v0.513.0 - ISC
|
|
5
5
|
*
|
|
6
6
|
* This source code is licensed under the ISC license.
|
|
@@ -21,4 +21,4 @@ var ol=Object.defineProperty;var ll=(r,e,t)=>e in r?ol(r,e,{enumerable:!0,config
|
|
|
21
21
|
.console-scroll::-webkit-scrollbar-thumb:hover {
|
|
22
22
|
background: #6e7681;
|
|
23
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("/assets/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-OjDhyKF-.js"),__vite__mapDeps([0,1,2])).then(r=>({default:r.CodePanel}))),Kg=Is(()=>Li(()=>import("./MapViewer-B7WO94rt.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};
|
|
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};
|