{
  "schema": 1,
  "id": "ext.liveserver",
  "name": "Live Server",
  "version": "1.0.0",
  "category": "tool",
  "description": "Startet einen lokalen Server für HTML, PHP und statische Dateien im Projektordner und lädt die Seite im Browser neu, sobald sich eine Datei ändert (CSS ohne Neuladen). PHP läuft über php -S. Bringt Programmcode mit.",
  "author": "Lumen",
  "icon": "Lv",
  "color": "#ff8a3d",
  "license": "MIT",
  "minAppVersion": "0.5.0",
  "keywords": [
    "live server",
    "liveserver",
    "live reload",
    "html",
    "php",
    "preview",
    "server",
    "browser"
  ],
  "readme": "# Live Server\n\nEin lokaler Server für den Projektordner — HTML, PHP und alles Statische — der\ndie Seite im Browser neu lädt, sobald sich eine Datei ändert.\n\n- **Go Live** in der Statusleiste (oder der Befehl *Live Server: Starten / Stoppen*) startet den Server und öffnet die aktive Datei im Browser.\n- **HTML** bekommt ein kleines Skript eingefügt; Änderungen an **CSS** tauschen nur die Stile aus, alles andere lädt neu.\n- **PHP** läuft über `php -S` (PHP muss installiert sein); die Ausgabe wird durch den Live-Server geleitet, sodass auch PHP-Seiten neu laden.\n- Ordner ohne `index.html` zeigen eine Dateiliste. Der Port, die Adresse, ein Unterordner (`dist`, `public`), die beobachteten Dateitypen und ignorierte Ordner stehen in den Einstellungen.\n\n## Befehle\n\n| Befehl | Was er tut |\n|---|---|\n| Live Server: Starten / Stoppen | schaltet den Server um |\n| Live Server: Aktive Datei im Browser öffnen | öffnet die Datei unter der Server-Adresse |\n| Live Server: Startseite im Browser öffnen | öffnet die Wurzel des Servers |\n\n---\n\nServes the project folder over HTTP — HTML, PHP and static files — and reloads\nthe page in the browser when a file changes. CSS changes are swapped in without\na reload. PHP runs through `php -S`. Settings: port, address, subfolder, the\nfile types that trigger a reload, ignored folders and the path to `php`.\n",
  "settings": [
    {
      "key": "port",
      "label": "Port",
      "type": "number",
      "default": "5500",
      "min": 1024,
      "max": 65000,
      "hint": "Ist er belegt, nimmt der Server den nächsten freien.",
      "section": "Server",
      "i18n": {
        "en": {
          "label": "Port",
          "hint": "If it is taken, the server uses the next free one.",
          "section": "Server"
        }
      }
    },
    {
      "key": "host",
      "label": "Adresse",
      "type": "text",
      "default": "127.0.0.1",
      "hint": "127.0.0.1 = nur dieser Rechner; 0.0.0.0 = auch im Netzwerk (z. B. Handy).",
      "section": "Server",
      "i18n": {
        "en": {
          "label": "Address",
          "hint": "127.0.0.1 = this machine only; 0.0.0.0 = the network too (a phone, say).",
          "section": "Server"
        }
      }
    },
    {
      "key": "subfolder",
      "label": "Unterordner",
      "type": "text",
      "default": "",
      "placeholder": "z. B. public oder dist",
      "hint": "Relativ zum Projektordner. Leer = der Projektordner selbst.",
      "section": "Server",
      "i18n": {
        "en": {
          "label": "Subfolder",
          "placeholder": "e.g. public or dist",
          "hint": "Relative to the project folder. Empty = the project folder itself.",
          "section": "Server"
        }
      }
    },
    {
      "key": "openBrowser",
      "label": "Browser beim Start öffnen",
      "type": "toggle",
      "default": "true",
      "section": "Server",
      "i18n": {
        "en": {
          "label": "Open the browser on start",
          "section": "Server"
        }
      }
    },
    {
      "key": "liveReload",
      "label": "Automatisch neu laden",
      "type": "toggle",
      "default": "true",
      "hint": "Fügt den Seiten ein kleines Skript hinzu; CSS-Änderungen tauschen nur die Stile aus.",
      "section": "Neuladen",
      "i18n": {
        "en": {
          "label": "Reload automatically",
          "hint": "Adds a small script to pages; CSS changes swap the styles only.",
          "section": "Reloading"
        }
      }
    },
    {
      "key": "reloadOn",
      "label": "Dateitypen, die neu laden",
      "type": "text",
      "default": "html,htm,php,js,mjs,json,svg,xml,md,txt,twig,phtml",
      "hint": "Kommagetrennt, ohne Punkt. CSS wird immer live getauscht.",
      "section": "Neuladen",
      "i18n": {
        "en": {
          "label": "File types that reload",
          "hint": "Comma-separated, without the dot. CSS is always swapped live.",
          "section": "Reloading"
        }
      }
    },
    {
      "key": "ignore",
      "label": "Ordner ignorieren",
      "type": "text",
      "default": "node_modules,.git,vendor,.idea,.vscode",
      "hint": "Kommagetrennte Ordnernamen, die nicht beobachtet werden.",
      "section": "Neuladen",
      "i18n": {
        "en": {
          "label": "Ignored folders",
          "hint": "Comma-separated folder names that are not watched.",
          "section": "Reloading"
        }
      }
    },
    {
      "key": "php",
      "label": "PHP ausführen",
      "type": "toggle",
      "default": "true",
      "hint": "Startet php -S im Projektordner, sofern PHP gefunden wird.",
      "section": "PHP",
      "i18n": {
        "en": {
          "label": "Run PHP",
          "hint": "Starts php -S in the project folder when PHP is found.",
          "section": "PHP"
        }
      }
    },
    {
      "key": "phpPath",
      "label": "Pfad zu php",
      "type": "path",
      "pathKind": "file",
      "default": "",
      "placeholder": "php aus dem PATH",
      "hint": "Leer lassen, um php im PATH zu verwenden.",
      "section": "PHP",
      "when": "php",
      "i18n": {
        "en": {
          "label": "Path to php",
          "placeholder": "php from PATH",
          "hint": "Leave empty to use php from the PATH.",
          "section": "PHP"
        }
      }
    }
  ],
  "pages": [],
  "agents": [],
  "views": [],
  "commands": [
    {
      "id": "liveserver.toggle",
      "title": "Live Server: Starten / Stoppen",
      "category": "Live Server",
      "icon": "radio",
      "i18n": {
        "en": {
          "title": "Live Server: Start / Stop"
        }
      }
    },
    {
      "id": "liveserver.start",
      "title": "Live Server: Starten",
      "category": "Live Server",
      "icon": "radio",
      "i18n": {
        "en": {
          "title": "Live Server: Start"
        }
      }
    },
    {
      "id": "liveserver.stop",
      "title": "Live Server: Stoppen",
      "category": "Live Server",
      "icon": "square",
      "i18n": {
        "en": {
          "title": "Live Server: Stop"
        }
      }
    },
    {
      "id": "liveserver.open",
      "title": "Live Server: Aktive Datei im Browser öffnen",
      "category": "Live Server",
      "icon": "globe",
      "i18n": {
        "en": {
          "title": "Live Server: Open active file in browser"
        }
      }
    },
    {
      "id": "liveserver.open-root",
      "title": "Live Server: Startseite im Browser öffnen",
      "category": "Live Server",
      "icon": "globe",
      "i18n": {
        "en": {
          "title": "Live Server: Open the site in the browser"
        }
      }
    }
  ],
  "code": {
    "main": "import { createRequire as __lumenRequire } from 'node:module'; const require = __lumenRequire(import.meta.url);\nimport _ from\"node:path\";import O from\"node:fs\";import k from\"node:fs/promises\";import U from\"node:http\";import Z from\"node:net\";import P from\"node:path\";import{spawn as G}from\"node:child_process\";var M=\"/__lumen_livereload\",X=\"/__lumen_livereload.js\",A={\".html\":\"text/html; charset=utf-8\",\".htm\":\"text/html; charset=utf-8\",\".xhtml\":\"application/xhtml+xml; charset=utf-8\",\".css\":\"text/css; charset=utf-8\",\".js\":\"text/javascript; charset=utf-8\",\".mjs\":\"text/javascript; charset=utf-8\",\".json\":\"application/json; charset=utf-8\",\".map\":\"application/json; charset=utf-8\",\".xml\":\"application/xml; charset=utf-8\",\".svg\":\"image/svg+xml\",\".txt\":\"text/plain; charset=utf-8\",\".md\":\"text/plain; charset=utf-8\",\".png\":\"image/png\",\".jpg\":\"image/jpeg\",\".jpeg\":\"image/jpeg\",\".gif\":\"image/gif\",\".webp\":\"image/webp\",\".avif\":\"image/avif\",\".ico\":\"image/x-icon\",\".woff\":\"font/woff\",\".woff2\":\"font/woff2\",\".ttf\":\"font/ttf\",\".otf\":\"font/otf\",\".mp4\":\"video/mp4\",\".webm\":\"video/webm\",\".mp3\":\"audio/mpeg\",\".wav\":\"audio/wav\",\".pdf\":\"application/pdf\",\".wasm\":\"application/wasm\"},q=[\"index.html\",\"index.htm\",\"index.php\"],ee=`(() => {\n  const source = new EventSource('${M}')\n  source.addEventListener('reload', () => location.reload())\n  source.addEventListener('css', () => {\n    for (const link of document.querySelectorAll('link[rel~=\"stylesheet\"][href]')) {\n      const url = new URL(link.href, location.href)\n      if (url.origin !== location.origin) continue\n      url.searchParams.set('__lumen', Date.now())\n      const fresh = link.cloneNode()\n      fresh.href = url.href\n      fresh.onload = () => link.remove()\n      link.after(fresh)\n    }\n  })\n})()\n`,W=`<script src=\"${X}\"></script>`;function D(e){let n=e.search(/<\\/body\\s*>/i);return n===-1?e+W:e.slice(0,n)+W+e.slice(n)}function te(e,n){let i=P.relative(e,n);return i===\"\"||!i.startsWith(\"..\")&&!P.isAbsolute(i)}function b(e){return e.replace(/[&<>\"]/g,n=>({\"&\":\"&amp;\",\"<\":\"&lt;\",\">\":\"&gt;\",'\"':\"&quot;\"})[n])}function x(e,n,i=200){let a=`<!doctype html><meta charset=\"utf-8\"><title>${b(e)}</title>\n<style>body{font:14px/1.5 system-ui,sans-serif;max-width:52rem;margin:2rem auto;padding:0 1rem;color:#222}a{color:#2563eb;text-decoration:none}a:hover{text-decoration:underline}li{list-style:none;padding:.1rem 0}code{background:#eee;padding:.1rem .3rem;border-radius:4px}</style>\n${n}`;return{status:i,html:D(a)}}async function ne(e,n){return new Promise(i=>{let a=Z.createServer();a.once(\"error\",()=>i(!1)),a.once(\"listening\",()=>a.close(()=>i(!0))),a.listen(e,n)})}async function z(e,n,i=20){for(let a=e;a<e+i;a+=1)if(await ne(a,n))return a;throw new Error(`No free port from ${e} to ${e+i-1}`)}async function oe(e){return new Promise(n=>{let i=G(e,[\"-v\"],{stdio:\"ignore\"});i.once(\"error\",()=>n(!1)),i.once(\"exit\",a=>n(a===0))})}async function K(e){let{root:n,host:i,liveReload:a,ignore:L,log:g}=e,E=new Set(e.reloadOn),y=new Set,h=e.php&&await oe(e.phpPath),$=h?await z(e.port+1e3,\"127.0.0.1\"):0,j=h?G(e.phpPath,[\"-S\",`127.0.0.1:${$}`,\"-t\",n],{cwd:n,stdio:[\"ignore\",\"ignore\",\"pipe\"]}):null;j?.stderr.on(\"data\",o=>{for(let t of String(o).split(`\n`))/(Warning|Fatal|Parse error|Notice|Deprecated)/i.test(t)&&g(t.trim())}),j?.on(\"error\",o=>g(`php: ${o.message}`)),e.php&&!h&&g(`php not found (${e.phpPath}) \\u2014 .php files are not run`);let w=(o,t,s,p)=>{o.writeHead(t,{\"cache-control\":\"no-store\",...s}),o.end(p)},d=(o,t)=>w(o,t.status,{\"content-type\":A[\".html\"]},t.html);function I(o,t){let s={...o.headers,\"accept-encoding\":\"identity\",host:`127.0.0.1:${$}`},p=U.request({host:\"127.0.0.1\",port:$,path:o.url,method:o.method,headers:s},l=>{let S=String(l.headers[\"content-type\"]??\"\");if(!a||!S.includes(\"text/html\")){t.writeHead(l.statusCode??502,l.headers),l.pipe(t);return}let m=[];l.on(\"data\",v=>m.push(v)),l.on(\"end\",()=>{let v=D(Buffer.concat(m).toString(\"utf8\")),{\"content-length\":B,...Y}=l.headers;t.writeHead(l.statusCode??502,Y),t.end(v)})});p.on(\"error\",l=>d(t,x(\"PHP\",`<h1>PHP</h1><p>${b(l.message)}</p>`,502))),o.pipe(p)}async function C(o,t,s){let l=(await k.readdir(t,{withFileTypes:!0})).filter(m=>!m.name.startsWith(\".\")).sort((m,v)=>Number(v.isDirectory())-Number(m.isDirectory())||m.name.localeCompare(v.name)).map(m=>{let v=m.name+(m.isDirectory()?\"/\":\"\");return`<li><a href=\"${encodeURI(P.posix.join(s,v))}\">${b(v)}</a></li>`}),S=s===\"/\"?\"\":'<li><a href=\"../\">../</a></li>';d(o,x(s,`<h1>${b(s)}</h1><ul>${S}${l.join(\"\")}</ul>`))}async function H(o,t,s){let p=P.extname(t).toLowerCase(),l=A[p]??\"application/octet-stream\";if(p===\".php\"){d(o,x(\"PHP\",`<h1>PHP is not available</h1><p>Install PHP or set its path in the extension's settings \\u2014 <code>${b(P.basename(t))}</code> was not run.</p>`,501));return}if(a&&(p===\".html\"||p===\".htm\"||p===\".xhtml\")){w(o,200,{\"content-type\":l},D(await k.readFile(t,\"utf8\")));return}let S=await k.stat(t);if(o.writeHead(200,{\"content-type\":l,\"content-length\":S.size,\"cache-control\":\"no-store\"}),s.method===\"HEAD\"){o.end();return}O.createReadStream(t).on(\"error\",()=>o.destroy()).pipe(o)}async function r(o,t){let s=new URL(o.url??\"/\",\"http://localhost\");if(s.pathname===M){t.writeHead(200,{\"content-type\":\"text/event-stream\",\"cache-control\":\"no-store\",connection:\"keep-alive\"}),t.write(`retry: 800\n\n`),y.add(t),o.on(\"close\",()=>y.delete(t));return}if(s.pathname===X){w(t,200,{\"content-type\":A[\".js\"]},ee);return}if(h){I(o,t);return}let p;try{p=decodeURIComponent(s.pathname)}catch{d(t,x(\"400\",\"<h1>Bad request</h1>\",400));return}let l=P.resolve(n,`.${p}`);if(!te(n,l)){d(t,x(\"403\",\"<h1>Forbidden</h1>\",403));return}let S=await k.stat(l).catch(()=>null);if(!S){d(t,x(\"404\",`<h1>404</h1><p><code>${b(p)}</code> was not found.</p>`,404));return}if(!S.isDirectory()){await H(t,l,o);return}if(!p.endsWith(\"/\")){w(t,301,{location:`${s.pathname}/${s.search}`},\"\");return}for(let m of q){let v=P.join(l,m);if(await k.stat(v).then(B=>B.isFile(),()=>!1)){await H(t,v,o);return}}await C(t,l,p)}let u=U.createServer((o,t)=>{r(o,t).catch(s=>{if(t.headersSent){t.destroy();return}d(t,x(\"500\",`<h1>500</h1><pre>${b(String(s?.stack??s))}</pre>`,500))})}),c=await z(e.port,i);await new Promise((o,t)=>{u.once(\"error\",t),u.listen(c,i,o)});let f=null,N=\"css\",F=o=>{a&&(o===\"reload\"&&(N=\"reload\"),!f&&(f=setTimeout(()=>{f=null;for(let t of y)t.write(`event: ${N}\ndata: ${Date.now()}\n\n`);N=\"css\"},80)))},J=new Set(L),T=o=>{if(o.split(/[\\\\/]/).some(p=>J.has(p)))return;let s=P.extname(o).toLowerCase();if(s===\".css\"){F(\"css\");return}E.has(s)&&F(\"reload\")},R=null;try{R=O.watch(n,{recursive:!0},(o,t)=>{t&&T(String(t))}),R.on(\"error\",()=>{})}catch(o){g(`Watching ${n} failed (${o.message}) \\u2014 pages reload on save only`)}let Q=setInterval(()=>{for(let o of y)o.write(`: ping\n\n`)},2e4);return{port:c,host:i,phpEnabled:h,changed:T,async stop(){clearInterval(Q),f&&clearTimeout(f),R?.close();for(let o of y)o.end();j?.kill(),await new Promise(o=>{u.close(o),u.closeAllConnections?.()})}}}var re=new Set([\".html\",\".htm\",\".xhtml\",\".php\",\".phtml\",\".svg\",\".md\",\".xml\"]),V=e=>String(e??\"\").split(\",\").map(n=>n.trim()).filter(Boolean);function de(e){let n=null,i=!1,a=e.events.last(\"project\")?.root??e.workspace.root()??null,L=e.events.last(\"activeFile\")?.path??null,g=(r,u=\"\")=>{let c=e.settings.get(r);return c==null||c===\"\"?u:String(c)},E=(r,u)=>{let c=e.settings.get(r);return c==null||c===\"\"?u:c===!0||c===\"true\"},y=()=>{if(!a)return null;let r=g(\"subfolder\");return r?_.resolve(a,r):a},h=()=>`http://${n.host===\"0.0.0.0\"?\"localhost\":n.host}:${n.port}`;function $(){if(i){e.statusBar.set(\"live\",{text:\"Live\\u2026\",icon:\"loader\",tooltip:\"Live Server\",command:\"liveserver.toggle\",priority:50});return}if(!n){e.statusBar.set(\"live\",{text:\"Go Live\",icon:\"radio\",tooltip:\"Live Server starten\",command:\"liveserver.toggle\",priority:50});return}e.statusBar.set(\"live\",{text:`Port ${n.port}`,icon:\"radio-tower\",tone:\"success\",tooltip:`${h()} \\u2014 klicken zum Stoppen`,command:\"liveserver.toggle\",priority:50})}function j(r){let u=y();if(!n||!u)return null;if(!r)return`${h()}/`;let c=_.relative(u,r);if(c.startsWith(\"..\")||_.isAbsolute(c)||!re.has(_.extname(r).toLowerCase()))return null;let f=c.split(_.sep).map(encodeURIComponent).join(\"/\");return`${h()}/${f}`}async function w({open:r=E(\"openBrowser\",!0)}={}){if(n||i)return;let u=y();if(!u){e.ui.notify(\"Live Server: Kein Projekt ge\\xF6ffnet.\",\"warning\");return}i=!0,$();try{n=await K({root:u,port:Number(g(\"port\",\"5500\"))||5500,host:g(\"host\",\"127.0.0.1\"),liveReload:E(\"liveReload\",!0),php:E(\"php\",!0),phpPath:g(\"phpPath\",\"php\"),ignore:V(g(\"ignore\",\"node_modules,.git,vendor,.idea,.vscode\")),reloadOn:V(g(\"reloadOn\",\"html,htm,php,js,mjs,json,svg,xml,md,txt,twig,phtml\")).map(f=>`.${f.replace(/^\\./,\"\").toLowerCase()}`),log:f=>e.log(f)})}catch(f){n=null,e.ui.notify(`Live Server: ${f.message}`,\"error\");return}finally{i=!1,$()}let c=n.phpEnabled?\" (mit PHP)\":\"\";e.ui.notify(`Live Server l\\xE4uft auf ${h()}${c}`,\"success\"),r&&await e.openExternal(j(L)??`${h()}/`)}async function d({quiet:r=!1}={}){if(!n)return;let u=n;n=null,$(),await u.stop().catch(()=>{}),r||e.ui.notify(\"Live Server gestoppt\",\"info\")}async function I(){if(n||await w({open:!1}),!n)return;let r=j(L);if(!r){e.ui.notify(\"Live Server: Die aktive Datei liegt nicht im bedienten Ordner oder ist keine Seite.\",\"warning\");return}await e.openExternal(r)}async function C(){n||await w({open:!1}),n&&await e.openExternal(`${h()}/`)}let H={\"liveserver.toggle\":()=>n?d():w(),\"liveserver.start\":()=>w(),\"liveserver.stop\":()=>d(),\"liveserver.open\":()=>I(),\"liveserver.open-root\":()=>C()};for(let[r,u]of Object.entries(H))e.commands.register(r,u);return e.events.on(\"project\",r=>{(r.root??null)!==a&&(a=r.root??null,n&&d({quiet:!0}))}),e.events.on(\"activeFile\",r=>{L=r.path??null}),e.events.on(\"fileSaved\",r=>n?.changed(r.path)),$(),()=>{d({quiet:!0}),e.statusBar.set(\"live\",null)}}export{de as activate};\n"
  },
  "addon": {
    "schema": 1,
    "languages": [],
    "themes": [],
    "commands": [],
    "events": [],
    "templates": [],
    "projectKinds": [],
    "snippets": [],
    "id": "ext.liveserver",
    "name": "Live Server",
    "version": "1.0.0",
    "description": "Startet einen lokalen Server für HTML, PHP und statische Dateien im Projektordner und lädt die Seite im Browser neu, sobald sich eine Datei ändert (CSS ohne Neuladen). PHP läuft über php -S. Bringt Programmcode mit.",
    "author": "Lumen",
    "icon": "Lv",
    "color": "#ff8a3d",
    "category": "tool"
  }
}
