function g(i){let t;return i?(t=i.toIterable)?t.call(i):i:[]}var j=Symbol.for("#type"),O=Symbol.for("#__listeners__");function x(i,t=null){let s={},o=/\$\$\d+\$\$/,l=function(r){return s[r]||(s[r]=t?t(r):{})},c=function(r,n){if(typeof n=="string"){if(n[0]=="$"&&o.test(n))return l(n)}else if(typeof r=="string"&&r[0]=="$"&&o.test(r)){let a=l(r);return Object.assign(a,n),a}return n};return JSON.parse(i,c)}function y(i,t){var s,o,l,c;let u={},r={added:[],changed:[],removed:[],all:[],urls:{}};if(i.assets)for(let n=0,a=g(i.assets),h=a.length;n<h;n++){let e=a[n],f=e.originalPath||e.path;u[f]=e,e.url&&((s=t.urls)[o=e.url]||(s[o]=e))}for(let n=0,a=g(t.assets||[]),h=a.length;n<h;n++){let e=a[n],f=e.originalPath||e.path,p=u[f];e.url&&i.urls&&(i.urls[e.url]=e),p?(p.hash!=e.hash&&(p.invalidated=Date.now(),p.replacedBy=e,e.replaces=p,r.changed.push(e),r.all.push(e),p==i.main&&(r.main=e)),l=u[f],delete u[f]):(r.added.push(e),r.all.push(e))}for(let n=0,a=Object.keys(u),h=a.length,e,f;n<h;n++)e=a[n],f=u[e],f.removed=Date.now(),r.all.push(f);for(let n=0,a=g(r.all),h=a.length;n<h;n++){let e=a[n];(r[c=e.type]||(r[c]=[])).push(e)}return r.removed=Object.values(u),t.changes=r,t}function m(i){let t;return i?(t=i.toIterable)?t.call(i):i:[]}var d=globalThis.document,b=class{constructor(){this.data={}}get changes(){return this.data.changes||{}}get inputs(){return this.data.inputs}get outputs(){return this.data.outputs}get urls(){return this.data.urls}get main(){return this.data.main}init(t){return this.update(t)}update(t){return typeof t=="string"&&(t=x(t)),this.data=y(this.data,t),this.data.changes}},$=class{constructor(){this.start(),this.manifest=new b({}),this.debug=!1}log(...t){if(!!this.debug)return console.log(...t)}refresh(t){let s={css:[],js:[]};for(let o of m(d.styleSheets)){let l,c=o.ownerNode.getAttribute("href");(l=this.manifest.urls[c])&&l.replacedBy&&(o.ownerNode.href=l.replacedBy.url)}for(let o of m(d.querySelectorAll("script[src]"))){let l;(l=this.manifest.urls[o.getAttribute("src")])&&l.replacedBy&&s.js.push(l)}return s.js.length&&(this.log("js changed - reload?",s.js),d.location.reload()),this}start(){var t=this;if(!this.socket)return this.socket=new EventSource("/__hmr__"),this.socket.onmessage=function(s){return t.log("sse.onmessage",s)},this.socket.addEventListener("paused",function(s){return t.log("server paused"),!0}),this.socket.addEventListener("state",function(s){let o=JSON.parse(s.data);return t.log("server state",o)}),this.socket.addEventListener("init",function(s){let o=JSON.parse(s.data);return t.manifest.init(o),t.log("hmr init",t.manifest.data)}),this.socket.addEventListener("errors",function(s){let o=JSON.parse(s.data);for(let l=0,c=m(o),u=c.length;l<u;l++){let r=c[l];console.error("error in "+r.location.file+": "+r.location.lineText+" ("+r.text+")")}}),this.socket.addEventListener("manifest",function(s){let o=JSON.parse(s.data),l=t.manifest.update(o);return t.refresh(l)}),this.socket.addEventListener("reload",function(s){return t.log("asked to reload by server"),d.location.reload()}),this.socket.onerror=function(s){return t.log("hmr disconnected",s)}}};globalThis.imba_devtools=new $;
