{"version":3,"file":"main.mjs","sources":["../../node_modules/sockette/dist/sockette.mjs","../lib/main.ts"],"sourcesContent":["function noop() {}\n\nexport default function (url, opts) {\n\topts = opts || {};\n\n\tvar ws, num=0, timer=1, $={};\n\tvar max = opts.maxAttempts || Infinity;\n\n\t$.open = function () {\n\t\tws = new WebSocket(url, opts.protocols || []);\n\n\t\tws.onmessage = opts.onmessage || noop;\n\n\t\tws.onopen = function (e) {\n\t\t\t(opts.onopen || noop)(e);\n\t\t\tnum = 0;\n\t\t};\n\n\t\tws.onclose = function (e) {\n\t\t\te.code === 1e3 || e.code === 1001 || e.code === 1005 || $.reconnect(e);\n\t\t\t(opts.onclose || noop)(e);\n\t\t};\n\n\t\tws.onerror = function (e) {\n\t\t\t(e && e.code==='ECONNREFUSED') ? $.reconnect(e) : (opts.onerror || noop)(e);\n\t\t};\n\t};\n\n\t$.reconnect = function (e) {\n\t\tif (timer && num++ < max) {\n\t\t\ttimer = setTimeout(function () {\n\t\t\t\t(opts.onreconnect || noop)(e);\n\t\t\t\t$.open();\n\t\t\t}, opts.timeout || 1e3);\n\t\t} else {\n\t\t\t(opts.onmaximum || noop)(e);\n\t\t}\n\t};\n\n\t$.json = function (x) {\n\t\tws.send(JSON.stringify(x));\n\t};\n\n\t$.send = function (x) {\n\t\tws.send(x);\n\t};\n\n\t$.close = function (x, y) {\n\t\ttimer = clearTimeout(timer);\n\t\tws.close(x || 1e3, y);\n\t};\n\n\t$.open(); // init\n\n\treturn $;\n}\n","import Sockette from \"sockette\";\n\nconst reload = function () {\n  location.reload(true);\n};\n\nlet errorEl;\nconst showErrors = function (errors: string[]) {\n  if (!errorEl) {\n    errorEl = document.createElement(\"div\");\n    errorEl.style.zIndex = 10000;\n    errorEl.style.backgroundColor = \"#000D\";\n    errorEl.style.color = \"#FFF\";\n    errorEl.style.fontSize = \"1.2rem\";\n    errorEl.style.minWidth = \"100%\";\n    errorEl.style.minHeight = \"100%\";\n    errorEl.style.top = 0;\n    errorEl.style.left = 0;\n    errorEl.style.margin = 0;\n    errorEl.style.padding = 0;\n    errorEl.style.position = \"absolute\";\n    document.body.appendChild(errorEl);\n  }\n\n  errorEl.textContent = \"\";\n\n  errors.forEach(function (error) {\n    const errorMsgEl = document.createElement(\"pre\");\n    errorMsgEl.style.margin = \"30px\";\n    errorMsgEl.textContent = error;\n    errorEl.appendChild(errorMsgEl);\n  });\n};\n\nexport const init = function () {\n  let connected = false;\n\n  new Sockette(\"ws://\" + location.host + \"/sosse-dev\", {\n    onopen() {\n      if (connected) {\n        reload();\n        return;\n      }\n\n      console.info(\"Connected to Sosse Dev Server\");\n      connected = true;\n    },\n    onmessage(msg) {\n      const data = JSON.parse(msg.data);\n\n      if (data.type === \"error\") {\n        showErrors(data.errors);\n      }\n\n      if (data.type === \"reload\") {\n        reload();\n      }\n    },\n  });\n};\n"],"names":["noop","url","opts","ws","num","timer","$","max","maxAttempts","Infinity","open","WebSocket","protocols","onmessage","onopen","e","onclose","code","reconnect","onerror","setTimeout","onreconnect","timeout","onmaximum","json","x","send","JSON","stringify","close","y","clearTimeout","errorEl","reload","location","init","connected","Sockette","host","console","info","msg","errors","data","parse","type","document","createElement","style","zIndex","backgroundColor","color","fontSize","minWidth","minHeight","top","left","margin","padding","position","body","appendChild","textContent","forEach","error","errorMsgEl"],"mappings":"AAAA,SAASA,KAEM,WAAUC,EAAKC,GAG7B,IAAIC,EAAIC,EAAI,EAAGC,EAAM,EAAGC,EAAE,GACtBC,GAHJL,EAAOA,GAAQ,IAGAM,aAAeC,SAgD9B,OA9CAH,EAAEI,KAAO,YACRP,EAAK,IAAIQ,UAAUV,EAAKC,EAAKU,WAAa,KAEvCC,UAAYX,EAAKW,WAAab,EAEjCG,EAAGW,OAAS,SAAUC,IACpBb,EAAKY,QAAUd,GAAMe,GACtBX,EAAM,GAGPD,EAAGa,QAAU,SAAUD,GACX,MAAXA,EAAEE,MAA2B,OAAXF,EAAEE,MAA4B,OAAXF,EAAEE,MAAiBX,EAAEY,UAAUH,I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