"use strict";var Le=Object.create;var S=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var ke=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty;var P=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),De=(e,t)=>{for(var r in t)S(e,r,{get:t[r],enumerable:!0})},J=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of $e(t))!_e.call(e,i)&&i!==r&&S(e,i,{get:()=>t[i],enumerable:!(n=Ne(t,i))||n.enumerable});return e};var m=(e,t,r)=>(r=e!=null?Le(ke(e)):{},J(t||!e||!e.__esModule?S(r,"default",{value:e,enumerable:!0}):r,e)),We=e=>J(S({},"__esModule",{value:!0}),e);var W=P((Tt,ce)=>{var R=require("fs"),ae=require("path"),Qe=require("os");function _(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"}function D(e,t){try{return t(e)}catch(r){if(/^(ENOENT|EPERM|EACCES)$/.test(r.code))return r.code!=="ENOENT"&&console.warn("Warning: Cannot access %s",e),!1;throw r}}var Ze={nil:function(e){return e==null},array:function(e){return Array.isArray(e)},emptyObject:function(e){for(var t in e)return!1;return!0},buffer:function(e){return Buffer.isBuffer(e)},regExp:function(e){return _(e,"RegExp")},string:function(e){return _(e,"String")},func:function(e){return typeof e=="function"},number:function(e){return _(e,"Number")},exists:function(e){return R.existsSync(e)},file:function(e){return D(e,function(t){return R.statSync(t).isFile()})},samePath:function(e,t){return ae.resolve(e)===ae.resolve(t)},directory:function(e){return D(e,function(t){return R.statSync(t).isDirectory()})},symbolicLink:function(e){return D(e,function(t){return R.lstatSync(t).isSymbolicLink()})},windows:function(){return Qe.platform()==="win32"}};ce.exports=Ze});var me=P((jt,fe)=>{var b=require("fs"),le=require("os"),I=require("path"),O=W(),x,qe=le.tmpdir&&le.tmpdir()||process.env.TMPDIR||process.env.TEMP||process.cwd();function de(){this.stack=[]}de.prototype={create:function(e,t){var r=I.join(t,"node-watch-"+Math.random().toString(16).substr(2));return this.stack.push({name:r,type:e}),r},write:function(){for(var e=0;e{var he=require("fs"),E=require("path"),ge=require("util"),ve=require("events"),we=me(),u=W(),et="update",ye="remove",pe=Symbol("skip");function tt(e){return e.some(function(t,r,n){return n.indexOf(t)!==r})}function F(e){return e.filter(function(t,r,n){return n.indexOf(t)===r})}function rt(e){return e.reduce(function(t,r){return t.concat(r)},[])}function nt(e){if(e&&e!=="buffer"&&!Buffer.isEncoding(e))throw new Error("Unknown encoding: "+e)}function it(e){return u.func(e)?function(t,r){e(t,!1)&&r()}:u.regExp(e)?function(t,r){e.test(t)&&r()}:function(t,r){r()}}function ot(e){return e.map(function(t){return u.exists(t)?[et,t]:[ye,t]})}function st(e){var t=F(e),r=/~$|^\.#|^##$/g,n=e.some(function(o){return r.test(o)});if(n){var i=tt(e.map(function(o){return o.replace(r,"")}));i&&(t=t.filter(function(o){return u.exists(o)}))}return ot(t)}function at(e,t){var r,n=[],i=e.options.encoding,o=e.options.delay;u.number(o)||(o=200);function a(){st(n).forEach(function(s){s[1]=Buffer.from(s[1]),i!=="buffer"&&(s[1]=s[1].toString(i)),t.apply(null,s)}),r=null,n=[]}return function(s,c){n.push(c),r||(r=setTimeout(a,o))}}function xe(){var e={};return function(t){return function(r,n){e[r+n]=[r,n],setTimeout(function(){Object.keys(e).forEach(function(i){t.apply(null,e[i])}),e={}})}}}function be(e,t,r){try{return he.watch(t,r)}catch(n){process.nextTick(function(){e.emit("error",n)})}}function Ee(e,t,r=function(){}){u.directory(e)?he.readdir(e,function(n,i){if(n)if(/^(EPERM|EACCES)$/.test(n.code))console.warn("Warning: Cannot access %s.",e);else throw n;else i.forEach(function(o){var a=E.join(e,o);u.directory(a)&&t(a)}),r()}):r()}function ct(e){var t=0;return function(){return t++,function(){t--,t===0&&e()}}}function lt(){return function(){}}function Se(e,t){return!u.func(t)||t(e,pe)!==pe}var Re=ge.deprecate(function(){},"(node-watch) First param in callback function is replaced with event name since 0.5.0, use `(evt, filename) => {}` if you want to get the filename");function g(){ve.EventEmitter.call(this),this.watchers={},this._isReady=!1,this._isClosed=!1}ge.inherits(g,ve.EventEmitter);g.prototype.expose=function(){var e={},t=this,r=["on","emit","once","close","isClosed","listeners","setMaxListeners","getMaxListeners","getWatchedPaths"];return r.forEach(function(n){e[n]=function(){return t[n].apply(t,arguments)}}),e};g.prototype.isClosed=function(){return this._isClosed};g.prototype.close=function(e){var t=this;if(e){var r=this.watchers[e];r&&r.close&&(r.close(),delete t.watchers[e]),Ee(e,function(n){t.close(n)})}else Object.keys(t.watchers).forEach(function(n){var i=t.watchers[n];i&&i.close&&i.close()}),this.watchers={};u.emptyObject(t.watchers)&&(this._isClosed||(this._isClosed=!0,process.nextTick(Oe,this)))};g.prototype.getWatchedPaths=function(e){if(u.func(e)){var t=this;t._isReady?e(Object.keys(t.watchers)):t.on("ready",function(){e(Object.keys(t.watchers))})}};function A(e){e._isReady||(e._isReady=!0,process.nextTick(function(){e.emit("ready")}))}function Oe(e){e.emit("close")}g.prototype.add=function(e,t){var r=this;t=t||{fpath:""};var n=E.resolve(t.fpath);this.watchers[n]=e;var i=function(a,s){if(!r.isClosed()){var c=s;u.nil(c)&&(c=""),c=E.join(t.fpath,c),t.options.recursive&&we(function(l){if(!l){var d=E.resolve(c);if(!u.exists(c))r.close(d);else{var p=u.directory(c)&&!r.watchers[d]&&Se(c,t.options.filter);p&&r.watchDirectory(c,t.options)}}}),o(a,c)}},o=at(t,function(a,s){if(t.compareName)t.compareName(s)&&r.emit("change",a,s);else{var c=it(t.options.filter);c(s,function(){r.flag?r.flag="":r.emit("change",a,s)})}});e.on("error",function(a){r.isClosed()||(u.windows()&&a.code==="EPERM"?(e.emit("change",ye,t.fpath&&""),r.flag="windows-error",r.close(n)):r.emit("error",a))}),e.on("change",i)};g.prototype.watchFile=function(e,t,r){var n=E.join(e,"../"),i=Object.assign({},t,{filter:null,encoding:"utf8"});delete i.recursive;var o=be(this,n,i);o&&(this.add(o,{type:"file",fpath:n,options:Object.assign({},i,{encoding:t.encoding}),compareName:function(a){return u.samePath(a,e)}}),u.func(r)&&(r.length===1&&Re(),this.on("change",r)))};g.prototype.watchDirectory=function(e,t,r,n=lt){var i=this,o=n();we(function(a){t.recursive=!!t.recursive;var s=Object.assign({},t,{encoding:"utf8"});if(a||delete s.recursive,i._isClosed)return o(),i.close();var c=be(i,e,s);if(!c){o();return}i.add(c,{type:"dir",fpath:e,options:t}),u.func(r)&&(r.length===1&&Re(),i.on("change",r)),t.recursive&&!a&&Ee(e,function(l){Se(l,t.filter)&&i.watchDirectory(l,t,null,n)},n()),o()})};function ut(e){var t=new g,r=xe(),n=e.length;return e.forEach(function(i){i.on("change",r(function(o,a){t.emit("change",o,a)})),i.on("error",function(o){t.emit("error",o)}),i.on("ready",function(){--n||A(t)})}),t.close=function(){e.forEach(function(i){i.close()}),process.nextTick(Oe,t)},t.getWatchedPaths=function(i){if(u.func(i)){var o=e.map(function(a){return new Promise(function(s){a.getWatchedPaths(s)})});Promise.all(o).then(function(a){var s=F(rt(a));i(s)})}},t.expose()}function M(e,t,r){var n=new g;if(u.buffer(e)&&(e=e.toString()),!u.array(e)&&!u.exists(e)&&process.nextTick(function(){n.emit("error",new Error(e+" does not exist."))}),u.string(t)&&(t={encoding:t}),u.func(t)&&(r=t,t={}),arguments.length<2&&(t={}),t.encoding?nt(t.encoding):t.encoding="utf8",u.array(e)){if(e.length===1)return M(e[0],t,r);var i=xe();return ut(F(e).map(function(a){var s=M(a,t);return u.func(r)&&s.on("change",i(r)),s}))}if(u.file(e))n.watchFile(e,t,r),A(n);else if(u.directory(e)){var o=ct(function(){A(n)});n.watchDirectory(e,t,r,o)}return n.expose()}U.exports=M;U.exports.default=M});var mt={};De(mt,{createRemote:()=>Z,derver:()=>ft});module.exports=We(mt);function B(e){return function(t,r){let n;function i(){if(window.EventSource){let l=function(d){return JSON.parse(d.data)};var c=l,s=new EventSource(t);s.addEventListener("refresh",function(d){window.location.reload(!0)},!1),s.addEventListener("console",function(d){console.log(l(d).text)},!1),s.addEventListener("srverror",function(d){let p=l(d);o(p.header,p.text)},!1),s.addEventListener("open",function(d){n&&location.reload(),console.log("[LiveReload] Ready")},!1),s.addEventListener("error",function(d){d.eventPhase==EventSource.CLOSED&&s.close(),d.target.readyState==EventSource.CLOSED?(console.log("[LiveReload] Disconnected! Retry in 5s..."),!n&&o("Disconnected!","Connection with server was lost."),n=setTimeout(i,5e3)):d.target.readyState==EventSource.CONNECTING&&console.log("[LiveReload] Connecting...")},!1)}else console.error("[LiveReload] Can't start LiveReload! Your browser doesn't support SSE")}function o(s,c){let l=document.createElement("div");l.innerHTML=`
\xD7
${s}
${c}
`,document.body.append(l)}function a(){let s=Number.parseInt(sessionStorage.getItem("_ds_x")||"0"),c=Number.parseInt(sessionStorage.getItem("_ds_y")||"0");setTimeout(()=>window.scrollTo(s,c),r),window.addEventListener("scroll",()=>{sessionStorage.setItem("_ds_x",window.scrollX),sessionStorage.setItem("_ds_y",window.scrollY)})}i(),r&&a()}.toString()}var Y=m(require("node:http")),K=m(require("node:path")),T=m(require("node:fs")),V=m(require("node:os")),X="/derver-livereload-events",Q="/derver-livereload-remote",j=new Set;function w(e,t,r){j.forEach(n=>{typeof n[e]=="function"&&n[e](t,r)})}function Z(e){let t=typeof e=="string"?e:!1,r="localhost",n=7e3;t||(e&&e.host&&(r=e.host),e&&e.port&&(n=e.port));function i(o,a){return new Promise(s=>{let c,l=t?Ie(t):void 0;l&&l.host&&(c=l.host),l&&l.port&&(n=l.port);let d=Y.default.request({hostname:l&&l.host||r,port:l&&l.port||n,path:Q,method:"POST",headers:{"Content-Type":"application/json"}},p=>{p.on("data",C=>{C.toString()==="REMOTE OK"?s("OK"):(console.log("[Derver remote]: Warning: wrong command "+o),s("WARNING"))})});d.on("error",p=>{console.log("[Derver remote]: Warning:"+p.message),s("WARNING")}),d.write(JSON.stringify({command:o,data:a||{}})),d.end()})}return{reload(){return i("reload")},console(o){return i("console",{text:o})},error(o,a){return i("error",{text:o,header:a})}}}function q(e){return!e.watch&&!e.remote?null:(r,n,i)=>{if(r.url==X){let o=(s,c)=>n.write(`event: ${s} data: ${JSON.stringify(c||{})} `),a={reload:()=>o("refresh"),console:s=>o("console",{text:s}),error:(s,c)=>o("srverror",{text:s,header:c||"Error"})};j.add(a),n.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),n.on("close",function(){j.delete(a)}),n.write(`data: connected `)}else if(e.remote&&r.url==Q)if(r.method=="POST"){let o="";r.on("data",a=>{o+=a.toString()}),r.on("end",()=>{let a=JSON.parse(o||"{}");if(a.command=="reload")w("reload");else if(a.command=="console")w("console",a.data.text);else if(a.command=="error")w("error",a.data.text,a.data.header);else return n.end("REMOTE WRONG COMMAND");n.end("REMOTE OK")})}else i();else i()}}function ee(e){return!e.watch&&!e.remote?null:(r,n,i)=>{[".html",".htm"].includes(r.extname)&&(n.body=Buffer.from(n.body.toString("utf-8").replace(/(<\/body>)/,` $1`))),i()}}function Ie(e){let t=V.default.tmpdir(),r=K.default.join(t,"derver_"+e);return T.default.existsSync(r)?JSON.parse(T.default.readFileSync(r,"utf-8")):!1}var te="0.0.2";var $=m(require("node:process")),y=m(require("node:fs/promises")),ne=m(require("node:http")),h=m(require("node:path")),k=m(require("node:zlib"));var v=(e,t,r)=>`\x1B[${t}m${e}\x1B[${r}m`,f={blue:e=>v(e,34,39),red:e=>v(e,31,39),green:e=>v(e,32,39),yellow:e=>v(e,33,39),magenta:e=>v(e,35,39),cyan:e=>v(e,36,39),gray:e=>v(e,90,39),bold:e=>v(e,1,22),italic:e=>v(e,3,23)};function L(){let e=2,t=[],r={line:(n="",i,o)=>{let a=n.length;return a+2>e&&(e=a+2),i&&(n=f[i](n)),o&&(n=f[o](n)),t.push([n,a]),r},print:(n=0,i)=>{let o=" ".repeat(n),a=2,s=" ".repeat(a),c=`${o}\u256D${"\u2500".repeat(e+2*a)}\u256E`,l=`${o}\u2502${s}`,d=`${s}\u2502`,p=`${o}\u2570${"\u2500".repeat(e+2*a)}\u256F`;i&&(c=f[i](c),p=f[i](p),l=f[i](l),d=f[i](d)),console.log(c);for(let[C,z]of t){let G=Math.floor((e-z)/2),je=e-z-G;console.log(`${l}${" ".repeat(G)}${C}${" ".repeat(je)}${d}`)}return console.log(p),r}};return r}var Fe={".htm":"text/html",".html":"text/html",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".png":"image/png",".svg":"image/svg+xml",".js":"text/javascript",".json":"application/json",".css":"text/css",".ico":"image/x-icon"},N=Fe;var ie=m(require("node:os"));function oe(e){let t=e.watch===!1&&e.cache&&e.compress;return new Promise(async(r,n)=>{let i=await Xe(e),o=ne.default.createServer((s,c)=>{let l=[He(e),Ge(e),Je(e)];l.push(...e.middlewares.list()),e.dir&&l.push(q(e),ze(e),Be(e),ee(e)),l.push(Ye(e),Ke(e)),Ue(l,s,c)});o.on("listening",()=>{r(o),e.banner&&L().line(t?"Derver server started":"Development server started","bold").line("on").line(`http://${e.host}:${e.port}`,"cyan").print(5,"blue")}),o.on("error",s=>{let c=s.toString();console.log(f.bold(` Server starting error:`)),console.log(` ${f.red(c)} `),n(c)}),o.listen(e.port,e.host);let a=async()=>{await i(),o.close()};$.default.on("SIGTERM",a),$.default.on("exit",a)})}function se(){let e=[];function t(i){for(let o of i.middlewares)e.push((a,s,c)=>{if(i.method&&i.method!==a.method)return c();if(i.pattern&&i.pattern!==""){let l=Ve(i.pattern,a.URL.pathname);if(!l||i.exact&&!l.exact)return c();a.params=l.params}o(a,s,c)})}function r(i,o,a=""){let s=Array.from(i),c=s.length>0&&typeof s[0]=="string"?s.shift():null;return c&&!c.startsWith("/")&&(c="/"+c),{method:o=="use"?null:o.toUpperCase(),pattern:a+(c||""),exact:!(a&&!c),middlewares:s.filter(l=>typeof l=="function")}}function n(i=""){let o=new Proxy({},{get(a,s){return s=="list"?()=>e:s=="sub"?()=>{let c=Array.from(arguments),l=i+c.shift();c.forEach(d=>d(n(l)))}:()=>(t(r(arguments,s,i)),o)}});return o}return n()}function Ue(e,t,r){e.push((i,o)=>o.end(o.body||""));let n=()=>{let i;for(;!i&&e.length>0;)i=e.shift();i&&i(t,r,n)};n()}function He(e){return(r,n,i)=>{let o=new URL(r.url||"/","http://"+(r.headers.host||"derver.tld"));r.URL=o,r.query=Array.from(o.searchParams).reduce((a,[s,c])=>(a[s]=c,a),{}),i()}}function ze(e){return async(r,n,i)=>{if(r.file=h.default.join(e.dir,r.URL.pathname),r.extname=h.default.extname(r.file),r.extname===""&&(r.file=h.default.join(r.file,e.index),r.extname=h.default.extname(r.file)),r.exists=await re(r.file),e.spa&&!r.exists&&r.extname===h.default.extname(e.index)){console.log();let o=h.default.dirname(r.file);do if(o=h.default.dirname(o),r.file=h.default.join(o,e.index),r.exists=await re(r.file))break;while(o!==".")}i()}}function Ge(e){return(r,n,i)=>{n.send=o=>{let a="text/plain";typeof o=="object"&&(o=JSON.stringify(o),a="application/json"),n.writeHead(200,{"Content-Type":a}),n.end(o)},i()}}function Je(e){return(r,n,i)=>{n.setHeader("Server","Derver/"+te),i()}}function Be(e){return async(r,n,i)=>{if(!r.exists)return e.log&&console.log(f.gray(" [web] ")+r.url+" - "+f.red("404 Not Found")),n.writeHead(404,{"Content-Type":"text/plain"}),n.end("Not found");N[r.extname]&&n.setHeader("Content-Type",N[r.extname]),n.body=await y.default.readFile(r.file),e.log&&console.log(f.gray(" [web] ")+r.url+" - "+f.green("200 OK")),i()}}function Ye(e){return e.compress?(r,n,i)=>{r.headers["accept-encoding"]&&(r.headers["accept-encoding"].includes("br")?(n.setHeader("Content-Encoding","br"),n.body=k.default.brotliCompressSync(n.body)):r.headers["accept-encoding"].includes("gzip")&&(n.setHeader("Content-Encoding","gzip"),n.body=k.default.gzipSync(n.body))),i()}:null}function Ke(e){return e.cache?(r,n,i)=>{typeof e.cache!="number"&&(e.cache=31536e3),n.setHeader("Cache-Control","max-age="+e.cache),i()}:null}function Ve(e,t){e=e.endsWith("/")?e:e+"/",t=t.endsWith("/")?t:t+"/";let r=[],n={},i=e.split("/").map(s=>s.startsWith(":")?(r.push(s.slice(1)),"([^\\/]+)"):s).join("\\/"),o=!0,a=t.match(new RegExp(`^${i}$`));return a?(r.forEach((s,c)=>n[s]=a[c+1]),{exact:o,params:n,part:a[0].slice(0,-1)}):(o=!1,a=t.match(new RegExp(`^${i}`)),null)}async function Xe(e){let t=ie.default.tmpdir();if(typeof e.remote!="string")return()=>{};let r=h.default.join(t,"derver_"+e.remote);return await y.default.writeFile(r,JSON.stringify({host:e.host,port:e.port})),()=>y.default.unlink(r)}async function re(e){try{return await y.default.stat(e),!0}catch{return!1}}var Ce=m(Me());var H=m(require("node:process"));function Pe(e){if(typeof e.watch=="string"&&(e.watch=[e.watch]),e.watch){console.log(f.yellow(` Waiting for changes... `));let t=[];H.default.on("SIGTERM",()=>t.forEach(i=>i.close())),H.default.on("exit",()=>t.forEach(i=>i.close()));let r=new Set,n=(i,o)=>{r.has(i)||(r.add(i),setTimeout(()=>r.delete(i),100),o())};for(let i of e.watch)t.push((0,Ce.default)(i,{recursive:!0},async function(o,a){n(i,()=>console.log(`${f.gray("[watch]")} Changes in ${f.blue(i)}`));let s=!0;typeof e.onWatch=="function"&&await e.onWatch({prevent:()=>s=!1,reload:()=>w("reload"),consoleLog:c=>w("console",c),error:(c,l)=>w("error",c,l)},i,a,o),s&&w("reload")}))}}var Te=m(require("node:process")),dt={port:7e3,host:"localhost",index:"index.html",dir:"public",compress:!1,cache:!1,spa:!1,watch:void 0,onWatch:void 0,remote:!1,preserveScroll:!1,banner:!0,log:!0};function ft(e){let t=Object.assign(dt,e,{middlewares:se()});return(async()=>{t.dir&&t.watch!==!1&&(t.watch=[t.dir]);try{await oe(t)}catch(r){console.log(r.message),Te.default.exit(1)}Pe(t)})(),t.middlewares}0&&(module.exports={createRemote,derver});