| 1 | /* Generated by tools/gen_ui.py from src/ui.html. Do not edit by hand. */ |
| 2 | #ifndef SX_FILES_UI_HTML_H |
| 3 | #define SX_FILES_UI_HTML_H |
| 4 | |
| 5 | static const char *UI_HTML = |
| 6 | "<!DOCTYPE html>\n" |
| 7 | "<html lang=\"en\"><head><meta charset=\"utf-8\">\n" |
| 8 | "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n" |
| 9 | "<title>files</title>\n" |
| 10 | "\001\n" |
| 11 | "<style>\n" |
| 12 | "*{box-sizing:border-box}\n" |
| 13 | "html,body{margin:0;height:100%}\n" |
| 14 | "body{background:var(--bg);color:var(--text);font-family:var(--font);\n" |
| 15 | " font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased;overflow:hidden}\n" |
| 16 | "#app{display:grid;grid-template-columns:252px minmax(0,1fr);height:100%;min-height:0}\n" |
| 17 | ".pane{min-width:0;min-height:0;display:flex;flex-direction:column}\n" |
| 18 | "#side{background:var(--bg-2);border-right:1px solid var(--line)}\n" |
| 19 | ".side-hd{display:flex;align-items:center;gap:8px;padding:12px 12px 8px}\n" |
| 20 | ".brand{font-size:12px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;\n" |
| 21 | " color:var(--text-2);flex:1}\n" |
| 22 | ".side-ft{display:flex;align-items:center;gap:8px;padding:8px 12px;\n" |
| 23 | " border-top:1px solid var(--line);font-size:11px;color:var(--text-2)}\n" |
| 24 | ".side-ft .grow{flex:1}\n" |
| 25 | ".side-lbl{font-size:10.5px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;\n" |
| 26 | " color:var(--text-2);padding:4px 14px 6px}\n" |
| 27 | ".icon{display:inline-flex;align-items:center;justify-content:center;gap:6px;\n" |
| 28 | " background:var(--surface-2);border:1px solid var(--line);color:var(--text);\n" |
| 29 | " border-radius:9px;width:30px;height:30px;padding:0;cursor:pointer;font-family:inherit;\n" |
| 30 | " font-size:12px;font-weight:600;flex:0 0 auto}\n" |
| 31 | ".icon:hover{background:var(--surface-hover);border-color:var(--line-2)}\n" |
| 32 | ".icon:active{transform:scale(.96)}\n" |
| 33 | ".icon svg{width:15px;height:15px;display:block;fill:none;stroke:currentColor;\n" |
| 34 | " stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}\n" |
| 35 | ".icon.on{background:var(--surface-2);border-color:var(--line-2);color:var(--blue)}\n" |
| 36 | ".rootlist{flex:0 0 auto;padding:0 8px 10px;border-bottom:1px solid var(--line)}\n" |
| 37 | ".root{display:flex;align-items:center;gap:9px;width:100%;text-align:left;\n" |
| 38 | " background:transparent;border:0;border-radius:9px;padding:8px 10px;color:var(--text);\n" |
| 39 | " cursor:pointer;font-family:inherit;font-size:13px;margin-bottom:2px}\n" |
| 40 | ".root:hover{background:var(--surface-hover)}\n" |
| 41 | ".root.sel{background:var(--surface-2);box-shadow:inset 2px 0 0 var(--blue)}\n" |
| 42 | ".root svg{width:14px;height:14px;flex:0 0 auto;fill:none;stroke:currentColor;stroke-width:1.7;\n" |
| 43 | " stroke-linecap:round;stroke-linejoin:round;color:var(--text-2)}\n" |
| 44 | ".root .rl{min-width:0;flex:1}\n" |
| 45 | ".root .rl .n{display:block;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n" |
| 46 | ".root .rl .p{display:block;font-size:10.5px;color:var(--text-2);overflow:hidden;\n" |
| 47 | " text-overflow:ellipsis;white-space:nowrap;font-family:var(--mono)}\n" |
| 48 | "#main{background:var(--bg);min-width:0}\n" |
| 49 | ".toolbar{display:flex;align-items:center;gap:7px;padding:10px 14px;\n" |
| 50 | " border-bottom:1px solid var(--line);flex:0 0 auto;min-width:0}\n" |
| 51 | ".crumbs{flex:1 1 auto;min-width:0;display:flex;align-items:center;gap:2px;\n" |
| 52 | " overflow-x:auto;scrollbar-width:none;white-space:nowrap}\n" |
| 53 | ".crumbs::-webkit-scrollbar{display:none}\n" |
| 54 | ".crumb{background:transparent;border:0;color:var(--text-2);font-family:var(--mono);\n" |
| 55 | " font-size:12px;padding:3px 5px;border-radius:6px;cursor:pointer;flex:0 0 auto}\n" |
| 56 | ".crumb:hover{background:var(--surface-hover);color:var(--text)}\n" |
| 57 | ".crumb.last{color:var(--text);font-weight:600}\n" |
| 58 | ".crumb .sep{color:var(--text-2);opacity:.6;padding:0 1px}\n" |
| 59 | ".body{flex:1 1 auto;display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.15fr);\n" |
| 60 | " min-height:0}\n" |
| 61 | ".body.noprev{grid-template-columns:minmax(0,1fr)}\n" |
| 62 | ".listwrap{min-width:0;min-height:0;display:flex;flex-direction:column;\n" |
| 63 | " border-right:1px solid var(--line)}\n" |
| 64 | ".entries{flex:1 1 auto;overflow-y:auto;padding:6px 8px 20px}\n" |
| 65 | ".row{display:flex;align-items:center;gap:9px;width:100%;text-align:left;\n" |
| 66 | " background:transparent;border:0;border-radius:9px;padding:7px 9px;color:var(--text);\n" |
| 67 | " cursor:pointer;font-family:inherit;font-size:13px}\n" |
| 68 | ".row:hover{background:var(--surface-hover)}\n" |
| 69 | ".row.sel{background:var(--surface-2);box-shadow:inset 2px 0 0 var(--blue)}\n" |
| 70 | ".row .ico{width:16px;height:16px;flex:0 0 auto;color:var(--text-2);display:flex}\n" |
| 71 | ".row .ico svg{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:1.7;\n" |
| 72 | " stroke-linecap:round;stroke-linejoin:round}\n" |
| 73 | ".row.dir .ico{color:var(--blue)}\n" |
| 74 | ".row .nm{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n" |
| 75 | ".row .mt{flex:0 0 auto;font-family:var(--mono);font-size:11px;color:var(--text-2)}\n" |
| 76 | ".empty{padding:22px 14px;color:var(--text-2);font-size:12.5px;text-align:center}\n" |
| 77 | ".hidden{display:none!important}\n" |
| 78 | ".preview{min-width:0;min-height:0;display:flex;flex-direction:column}\n" |
| 79 | ".prev-hd{display:flex;align-items:center;gap:8px;padding:9px 14px;\n" |
| 80 | " border-bottom:1px solid var(--line);flex:0 0 auto;min-width:0}\n" |
| 81 | ".prev-hd .nm{flex:1 1 auto;min-width:0;font-weight:600;font-size:13px;\n" |
| 82 | " overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n" |
| 83 | ".prev-hd .mt{font-family:var(--mono);font-size:11px;color:var(--text-2);white-space:nowrap}\n" |
| 84 | ".prev-body{flex:1 1 auto;overflow:auto;min-height:0}\n" |
| 85 | ".codetxt{margin:0;padding:0;font-family:var(--mono);font-size:12.5px;line-height:1.6;\n" |
| 86 | " display:grid;grid-template-columns:auto minmax(0,1fr);min-width:0}\n" |
| 87 | ".codetxt .ln{color:var(--text-2);text-align:right;padding:0 10px 0 14px;\n" |
| 88 | " user-select:none;background:var(--bg-2);border-right:1px solid var(--line)}\n" |
| 89 | ".codetxt .tx{padding:0 14px;white-space:pre-wrap;word-break:break-word;\n" |
| 90 | " font-family:var(--mono);font-size:12.5px}\n" |
| 91 | ".md{padding:16px 20px 40px;max-width:860px}\n" |
| 92 | ".md h1,.md h2,.md h3,.md h4{line-height:1.25;margin:18px 0 8px;font-weight:650}\n" |
| 93 | ".md h1{font-size:21px}.md h2{font-size:18px}.md h3{font-size:15.5px}.md h4{font-size:14px}\n" |
| 94 | ".md p{margin:0 0 11px}\n" |
| 95 | ".md ul,.md ol{margin:0 0 11px;padding-left:22px}\n" |
| 96 | ".md li{margin:3px 0}\n" |
| 97 | ".md code{font-family:var(--mono);font-size:12px;background:var(--code-bg);\n" |
| 98 | " padding:1px 5px;border-radius:5px}\n" |
| 99 | ".md pre{background:var(--code-bg);border:1px solid var(--line);border-radius:10px;\n" |
| 100 | " padding:11px 13px;overflow-x:auto;margin:0 0 12px}\n" |
| 101 | ".md pre code{background:transparent;padding:0;font-size:12px;line-height:1.55}\n" |
| 102 | ".md hr{border:0;border-top:1px solid var(--line);margin:16px 0}\n" |
| 103 | ".md a{color:var(--blue);text-decoration:none;font-weight:600}\n" |
| 104 | ".md a:hover{text-decoration:underline}\n" |
| 105 | ".md blockquote{margin:0 0 12px;padding:2px 0 2px 13px;border-left:3px solid var(--line-2);\n" |
| 106 | " color:var(--text-2)}\n" |
| 107 | ".imgwrap{padding:16px;display:flex;align-items:flex-start;justify-content:center}\n" |
| 108 | ".imgwrap img{max-width:100%;height:auto;border-radius:10px;border:1px solid var(--line);\n" |
| 109 | " background:var(--bg-2)}\n" |
| 110 | ".note{padding:16px 18px;color:var(--text-2);font-size:12.5px}\n" |
| 111 | ".welcome{flex:1 1 auto;display:flex;flex-direction:column;align-items:center;\n" |
| 112 | " justify-content:center;gap:10px;color:var(--text-2);font-size:13px;padding:24px;\n" |
| 113 | " text-align:center;min-height:0}\n" |
| 114 | ".welcome svg{width:34px;height:34px;fill:none;stroke:currentColor;stroke-width:1.4;\n" |
| 115 | " stroke-linecap:round;stroke-linejoin:round;opacity:.55}\n" |
| 116 | ".toast{position:fixed;left:50%;bottom:18px;transform:translateX(-50%);\n" |
| 117 | " background:var(--modal-bg);border:1px solid var(--line-2);color:var(--text);\n" |
| 118 | " padding:8px 14px;border-radius:999px;font-size:12.5px;box-shadow:var(--shadow-lg);\n" |
| 119 | " opacity:0;pointer-events:none;transition:opacity .16s var(--ease);z-index:9;\n" |
| 120 | " max-width:calc(100% - 24px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n" |
| 121 | ".toast.show{opacity:1}\n" |
| 122 | "@media (max-width:1100px){\n" |
| 123 | " #app{grid-template-columns:216px minmax(0,1fr)}\n" |
| 124 | " .body{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}\n" |
| 125 | "}\n" |
| 126 | "@media (max-width:820px){\n" |
| 127 | " body{overflow:hidden}\n" |
| 128 | " #app{grid-template-columns:minmax(0,1fr)}\n" |
| 129 | " #side,#main{grid-column:1;grid-row:1}\n" |
| 130 | " #app[data-view=\"browse\"] #side{display:none}\n" |
| 131 | " #app[data-view=\"roots\"] #main{display:none}\n" |
| 132 | " .body{grid-template-columns:minmax(0,1fr)}\n" |
| 133 | " #app[data-view=\"browse\"] .body{grid-template-columns:minmax(0,1fr)}\n" |
| 134 | " #app[data-view=\"browse\"] .preview{display:none}\n" |
| 135 | " #app[data-view=\"preview\"] .listwrap{display:none}\n" |
| 136 | " #app[data-view=\"preview\"] .body{grid-template-columns:minmax(0,1fr)}\n" |
| 137 | " .back{display:inline-flex!important}\n" |
| 138 | " .toolbar{padding:8px 10px;gap:6px}\n" |
| 139 | " .md{padding:12px 14px 32px}\n" |
| 140 | " .codetxt .tx{padding:0 10px}\n" |
| 141 | "}\n" |
| 142 | "@media (min-width:821px){.back{display:none!important}}\n" |
| 143 | "</style>\n" |
| 144 | "</head><body>\n" |
| 145 | "<div id=\"app\" data-view=\"roots\">\n" |
| 146 | " <aside id=\"side\" class=\"pane\">\n" |
| 147 | " <div class=\"side-hd\">\n" |
| 148 | " <span class=\"brand\">files</span>\n" |
| 149 | " <button id=\"btnUp\" class=\"icon\" title=\"Up one level\" aria-label=\"Up one level\">\n" |
| 150 | " <svg viewBox=\"0 0 24 24\"><path d=\"M12 19V5M5 12l7-7 7 7\"/></svg></button>\n" |
| 151 | " <button id=\"btnRefresh\" class=\"icon\" title=\"Refresh\" aria-label=\"Refresh\">\n" |
| 152 | " <svg viewBox=\"0 0 24 24\"><path d=\"M20 11a8 8 0 1 0-2.3 5.7\"/><path d=\"M20 4v7h-7\"/></svg></button>\n" |
| 153 | " </div>\n" |
| 154 | " <div class=\"side-lbl\">Roots</div>\n" |
| 155 | " <div id=\"roots\" class=\"rootlist\"></div>\n" |
| 156 | " <div class=\"side-ft\">\n" |
| 157 | " <span id=\"count\">0 items</span><span class=\"grow\"></span>\n" |
| 158 | " <button id=\"btnHidden\" class=\"icon\" title=\"Show hidden files\" aria-label=\"Show hidden files\">\n" |
| 159 | " <svg viewBox=\"0 0 24 24\"><path d=\"M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12z\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/></svg></button>\n" |
| 160 | " <button id=\"btnTheme\" class=\"icon embed-hide\" title=\"Toggle appearance\" aria-label=\"Toggle appearance\">\n" |
| 161 | " <svg viewBox=\"0 0 24 24\"><circle cx=\"12\" cy=\"12\" r=\"4.5\"/><path d=\"M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M19.1 4.9l-1.4 1.4M6.3 17.7l-1.4 1.4\"/></svg></button>\n" |
| 162 | " </div>\n" |
| 163 | " </aside>\n" |
| 164 | " <main id=\"main\" class=\"pane\">\n" |
| 165 | " <div class=\"toolbar\">\n" |
| 166 | " <button id=\"btnBack\" class=\"icon back\" title=\"Back to list\" aria-label=\"Back to list\">\n" |
| 167 | " <svg viewBox=\"0 0 24 24\"><path d=\"M15 5l-7 7 7 7\"/></svg></button>\n" |
| 168 | " <div id=\"crumbs\" class=\"crumbs\"></div>\n" |
| 169 | " <button id=\"btnDownload\" class=\"icon\" title=\"Download file\" aria-label=\"Download file\">\n" |
| 170 | " <svg viewBox=\"0 0 24 24\"><path d=\"M12 3v12M7 11l5 5 5-5M4 21h16\"/></svg></button>\n" |
| 171 | " </div>\n" |
| 172 | " <div id=\"body\" class=\"body\">\n" |
| 173 | " <div class=\"listwrap\">\n" |
| 174 | " <div id=\"entries\" class=\"entries\"></div>\n" |
| 175 | " <div id=\"empty\" class=\"empty hidden\">This directory is empty.</div>\n" |
| 176 | " </div>\n" |
| 177 | " <div id=\"preview\" class=\"preview\">\n" |
| 178 | " <div id=\"prevHd\" class=\"prev-hd hidden\">\n" |
| 179 | " <span id=\"prevName\" class=\"nm\"></span>\n" |
| 180 | " <span id=\"prevMeta\" class=\"mt\"></span>\n" |
| 181 | " </div>\n" |
| 182 | " <div id=\"prevBody\" class=\"prev-body\">\n" |
| 183 | " <div id=\"welcome\" class=\"welcome\">\n" |
| 184 | " <svg viewBox=\"0 0 24 24\"><path d=\"M3 7h6l2 2h10v11H3z\"/></svg>\n" |
| 185 | " <div>Pick a root, then open a file to preview it.</div>\n" |
| 186 | " <div style=\"font-size:11.5px\">Arrows move · Enter opens · Backspace goes up</div>\n" |
| 187 | " </div>\n" |
| 188 | " </div>\n" |
| 189 | " </div>\n" |
| 190 | " </div>\n" |
| 191 | " </main>\n" |
| 192 | "</div>\n" |
| 193 | "<div id=\"toast\" class=\"toast\"></div>\n" |
| 194 | "<script>\n" |
| 195 | "(function(){\n" |
| 196 | "\"use strict\";\n" |
| 197 | "var app=document.getElementById('app');\n" |
| 198 | "var rootsEl=document.getElementById('roots');\n" |
| 199 | "var entriesEl=document.getElementById('entries');\n" |
| 200 | "var emptyEl=document.getElementById('empty');\n" |
| 201 | "var countEl=document.getElementById('count');\n" |
| 202 | "var crumbsEl=document.getElementById('crumbs');\n" |
| 203 | "var bodyEl=document.getElementById('body');\n" |
| 204 | "var prevEl=document.getElementById('preview');\n" |
| 205 | "var prevHd=document.getElementById('prevHd');\n" |
| 206 | "var prevName=document.getElementById('prevName');\n" |
| 207 | "var prevMeta=document.getElementById('prevMeta');\n" |
| 208 | "var prevBody=document.getElementById('prevBody');\n" |
| 209 | "var toastEl=document.getElementById('toast');\n" |
| 210 | "var btnHidden=document.getElementById('btnHidden');\n" |
| 211 | "var btnDownload=document.getElementById('btnDownload');\n" |
| 212 | "\n" |
| 213 | "var q=new URLSearchParams(location.search);\n" |
| 214 | "var node=q.get('node')||'';\n" |
| 215 | "var sid=q.get('id')||'';\n" |
| 216 | "var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))||\n" |
| 217 | " localStorage.getItem('bot_active_pwd')||'';\n" |
| 218 | "var HUB=q.get('plugin')||'';\n" |
| 219 | "\n" |
| 220 | "var roots=[], entries=[], curPath='', curParent=null, curRoot=null;\n" |
| 221 | "var selIndex=-1, showHidden=false, curFile=null;\n" |
| 222 | "\n" |
| 223 | "/* Two call routes, and getting this wrong is the most common plugin bug:\n" |
| 224 | " * page served through the hub (bot.scorpiox.net/plugins?plugin=plugin_files&node=..)\n" |
| 225 | " * -> call the hub proxy back: /plugins?plugin=plugin_files&action=..\n" |
| 226 | " * opened directly on the node\n" |
| 227 | " * -> the plugin itself is the route: /plugin_files?action=..\n" |
| 228 | " * Calling /plugins?plugin= on the node returns the discovery list, not us. */\n" |
| 229 | "function url(action,extra){\n" |
| 230 | " var u=(HUB?'/plugins?plugin='+encodeURIComponent(HUB):'/plugin_files')+\n" |
| 231 | " '?action='+encodeURIComponent(action)+\n" |
| 232 | " (extra?('&'+extra):'')+\n" |
| 233 | " (node?'&node='+encodeURIComponent(node):'')+\n" |
| 234 | " (sid?'&id='+encodeURIComponent(sid):'')+\n" |
| 235 | " (pwd?'&pwd='+encodeURIComponent(pwd):'');\n" |
| 236 | " return u;\n" |
| 237 | "}\n" |
| 238 | "function hdr(extra){\n" |
| 239 | " var h=extra||{};\n" |
| 240 | " if(pwd)h['X-Bot-Password']=pwd;\n" |
| 241 | " return h;\n" |
| 242 | "}\n" |
| 243 | "function api(action,extra){\n" |
| 244 | " return fetch(url(action,extra),{headers:hdr({})}).then(function(r){\n" |
| 245 | " if(!r.ok)throw new Error('HTTP '+r.status);\n" |
| 246 | " return r.json();\n" |
| 247 | " });\n" |
| 248 | "}\n" |
| 249 | "\n" |
| 250 | "function toast(msg){\n" |
| 251 | " toastEl.textContent=msg;\n" |
| 252 | " toastEl.classList.add('show');\n" |
| 253 | " clearTimeout(toast._t);\n" |
| 254 | " toast._t=setTimeout(function(){toastEl.classList.remove('show');},2000);\n" |
| 255 | "}\n" |
| 256 | "function setView(v){app.setAttribute('data-view',v);}\n" |
| 257 | "\n" |
| 258 | "function fmtSize(n){\n" |
| 259 | " if(n===null||n===undefined)return '';\n" |
| 260 | " if(n<1024)return n+' B';\n" |
| 261 | " if(n<1048576)return (n/1024).toFixed(1)+' KB';\n" |
| 262 | " if(n<1073741824)return (n/1048576).toFixed(1)+' MB';\n" |
| 263 | " return (n/1073741824).toFixed(1)+' GB';\n" |
| 264 | "}\n" |
| 265 | "function fmtTime(iso){\n" |
| 266 | " if(!iso)return '';\n" |
| 267 | " try{\n" |
| 268 | " var d=new Date(iso),now=new Date(),diff=(now-d)/1000;\n" |
| 269 | " if(diff<60)return 'just now';\n" |
| 270 | " if(diff<3600)return Math.floor(diff/60)+'m ago';\n" |
| 271 | " if(diff<86400)return Math.floor(diff/3600)+'h ago';\n" |
| 272 | " if(diff<604800)return Math.floor(diff/86400)+'d ago';\n" |
| 273 | " return d.toLocaleDateString();\n" |
| 274 | " }catch(e){return ''}\n" |
| 275 | "}\n" |
| 276 | "\n" |
| 277 | "var SVG={\n" |
| 278 | " dir:'<svg viewBox=\"0 0 24 24\"><path d=\"M3 7h6l2 2h10v11H3z\"/></svg>',\n" |
| 279 | " file:'<svg viewBox=\"0 0 24 24\"><path d=\"M6 3h9l5 5v13H6z\"/><path d=\"M14 3v5h5\"/></svg>',\n" |
| 280 | " link:'<svg viewBox=\"0 0 24 24\"><path d=\"M10 13a4 4 0 0 0 6 .5l2.5-2.5a4 4 0 0 0-6-6L11 6.5\"/><path d=\"M14 11a4 4 0 0 0-6-.5L5.5 13a4 4 0 0 0 6 6L13 17.5\"/></svg>',\n" |
| 281 | " img:'<svg viewBox=\"0 0 24 24\"><rect x=\"3\" y=\"5\" width=\"18\" height=\"14\" rx=\"2\"/><circle cx=\"8.5\" cy=\"10\" r=\"1.6\"/><path d=\"M21 16l-5-5-6 6\"/></svg>',\n" |
| 282 | " root:'<svg viewBox=\"0 0 24 24\"><path d=\"M3 7h6l2 2h10v11H3z\"/></svg>'\n" |
| 283 | "};\n" |
| 284 | "\n" |
| 285 | "function renderRoots(){\n" |
| 286 | " while(rootsEl.firstChild)rootsEl.removeChild(rootsEl.firstChild);\n" |
| 287 | " roots.forEach(function(r,i){\n" |
| 288 | " var b=document.createElement('button');\n" |
| 289 | " b.className='root'+(curRoot===r.path?' sel':'');\n" |
| 290 | " var ic=document.createElement('span');ic.innerHTML=SVG.root;\n" |
| 291 | " var wrap=document.createElement('span');wrap.className='rl';\n" |
| 292 | " var n=document.createElement('span');n.className='n';n.textContent=r.name;\n" |
| 293 | " var p=document.createElement('span');p.className='p';p.textContent=r.path;\n" |
| 294 | " wrap.appendChild(n);wrap.appendChild(p);\n" |
| 295 | " b.appendChild(ic);b.appendChild(wrap);\n" |
| 296 | " b.onclick=function(){openDir(r.path);setView('browse');};\n" |
| 297 | " rootsEl.appendChild(b);\n" |
| 298 | " });\n" |
| 299 | "}\n" |
| 300 | "\n" |
| 301 | "function renderCrumbs(){\n" |
| 302 | " while(crumbsEl.firstChild)crumbsEl.removeChild(crumbsEl.firstChild);\n" |
| 303 | " if(!curPath){\n" |
| 304 | " var hint=document.createElement('span');hint.className='crumb last';\n" |
| 305 | " hint.textContent='Select a root';crumbsEl.appendChild(hint);return;\n" |
| 306 | " }\n" |
| 307 | " var base=curRoot||'';\n" |
| 308 | " var rel=curPath;\n" |
| 309 | " if(base&&curPath.indexOf(base)===0)rel=curPath.slice(base.length);\n" |
| 310 | " var parts=rel.split(/[\\/\\\\]+/).filter(function(s){return s.length;});\n" |
| 311 | " var b0=document.createElement('button');\n" |
| 312 | " b0.className='crumb'+(parts.length?'':' last');\n" |
| 313 | " b0.textContent=base.split(/[\\/\\\\]+/).filter(Boolean).pop()||base||'/';\n" |
| 314 | " b0.title=base;\n" |
| 315 | " b0.onclick=function(){openDir(base);};\n" |
| 316 | " crumbsEl.appendChild(b0);\n" |
| 317 | " var acc=base;\n" |
| 318 | " parts.forEach(function(p,i){\n" |
| 319 | " var sp=document.createElement('span');sp.className='sep';sp.textContent='/';\n" |
| 320 | " crumbsEl.appendChild(sp);\n" |
| 321 | " acc+=(acc&&acc[acc.length-1]!=='/'&&acc[acc.length-1]!=='\\\\'?'/':'')+p;\n" |
| 322 | " var b=document.createElement('button');\n" |
| 323 | " b.className='crumb'+(i===parts.length-1?' last':'');\n" |
| 324 | " b.textContent=p;b.title=acc;\n" |
| 325 | " var target=acc;\n" |
| 326 | " b.onclick=function(){openDir(target);};\n" |
| 327 | " crumbsEl.appendChild(b);\n" |
| 328 | " });\n" |
| 329 | "}\n" |
| 330 | "\n" |
| 331 | "function isImage(name){\n" |
| 332 | " return /\\.(png|jpe?g|gif|webp|bmp|ico|svg)$/i.test(name||'');\n" |
| 333 | "}\n" |
| 334 | "function isMarkdown(name){\n" |
| 335 | " return /\\.(md|markdown)$/i.test(name||'');\n" |
| 336 | "}\n" |
| 337 | "function isTextish(name){\n" |
| 338 | " return /\\.(txt|md|markdown|json|js|ts|css|html?|c|h|cpp|hpp|py|sh|yml|yaml|toml|ini|conf|log|csv|xml|sql|go|rs|java|rb|php|gitignore|env)$/i.test(name||'');\n" |
| 339 | "}\n" |
| 340 | "\n" |
| 341 | "function renderEntries(){\n" |
| 342 | " while(entriesEl.firstChild)entriesEl.removeChild(entriesEl.firstChild);\n" |
| 343 | " if(selIndex>=entries.length)selIndex=entries.length?entries.length-1:-1;\n" |
| 344 | " entries.forEach(function(e,i){\n" |
| 345 | " var b=document.createElement('button');\n" |
| 346 | " b.className='row'+(e.type==='dir'?' dir':'')+(i===selIndex?' sel':'');\n" |
| 347 | " var ic=document.createElement('span');ic.className='ico';\n" |
| 348 | " ic.innerHTML = e.link?SVG.link : (e.type==='dir'?SVG.dir : (isImage(e.name)?SVG.img:SVG.file));\n" |
| 349 | " var nm=document.createElement('span');nm.className='nm';nm.textContent=e.name;\n" |
| 350 | " var mt=document.createElement('span');mt.className='mt';\n" |
| 351 | " mt.textContent=(e.type==='dir'?'':fmtSize(e.size));\n" |
| 352 | " b.appendChild(ic);b.appendChild(nm);b.appendChild(mt);\n" |
| 353 | " b.onclick=function(){selIndex=i;renderEntries();activate(e);};\n" |
| 354 | " entriesEl.appendChild(b);\n" |
| 355 | " });\n" |
| 356 | " emptyEl.classList.toggle('hidden',entries.length>0);\n" |
| 357 | " countEl.textContent=entries.length+(entries.length===1?' item':' items');\n" |
| 358 | " var sel=entriesEl.querySelector('.row.sel');\n" |
| 359 | " if(sel&&sel.scrollIntoView)sel.scrollIntoView({block:'nearest'});\n" |
| 360 | "}\n" |
| 361 | "\n" |
| 362 | "function openDir(path){\n" |
| 363 | " return api('ls','path='+encodeURIComponent(path)+(showHidden?'&hidden=1':''))\n" |
| 364 | " .then(function(d){\n" |
| 365 | " if(!d||!d.ok)throw new Error((d&&d.error)||'failed');\n" |
| 366 | " curPath=d.path;curParent=d.parent;curRoot=d.root;\n" |
| 367 | " entries=d.entries||[];selIndex=entries.length?0:-1;\n" |
| 368 | " renderCrumbs();renderEntries();\n" |
| 369 | " if(!entries.length){clearPreview();}\n" |
| 370 | " else if(window.matchMedia('(max-width:820px)').matches){setView('browse');}\n" |
| 371 | " return d;\n" |
| 372 | " }).catch(function(e){toast('Cannot open folder: '+e.message);});\n" |
| 373 | "}\n" |
| 374 | "\n" |
| 375 | "function clearPreview(){\n" |
| 376 | " prevHd.classList.add('hidden');\n" |
| 377 | " while(prevBody.firstChild)prevBody.removeChild(prevBody.firstChild);\n" |
| 378 | " var w=document.createElement('div');w.className='welcome';\n" |
| 379 | " w.innerHTML='<svg viewBox=\"0 0 24 24\"><path d=\"M3 7h6l2 2h10v11H3z\"/></svg>'+\n" |
| 380 | " '<div>Pick a root, then open a file to preview it.</div>'+\n" |
| 381 | " '<div style=\"font-size:11.5px\">Arrows move · Enter opens · Backspace goes up</div>';\n" |
| 382 | " prevBody.appendChild(w);\n" |
| 383 | " curFile=null;\n" |
| 384 | " btnDownload.classList.add('hidden');\n" |
| 385 | "}\n" |
| 386 | "\n" |
| 387 | "function activate(e){\n" |
| 388 | " if(e.type==='dir'){openDir(joinPath(curPath,e.name));setView('browse');return;}\n" |
| 389 | " previewFile(joinPath(curPath,e.name),e);\n" |
| 390 | "}\n" |
| 391 | "function joinPath(dir,name){\n" |
| 392 | " if(!dir)return name;\n" |
| 393 | " var last=dir[dir.length-1];\n" |
| 394 | " return dir+(last==='/'||last==='\\\\'?'':'/')+name;\n" |
| 395 | "}\n" |
| 396 | "\n" |
| 397 | "function setHd(name,meta){\n" |
| 398 | " prevHd.classList.remove('hidden');\n" |
| 399 | " prevName.textContent=name;\n" |
| 400 | " prevMeta.textContent=meta||'';\n" |
| 401 | " btnDownload.classList.remove('hidden');\n" |
| 402 | "}\n" |
| 403 | "\n" |
| 404 | "function previewFile(path,ent){\n" |
| 405 | " curFile=path;\n" |
| 406 | " setView('preview');\n" |
| 407 | " prevHd.classList.remove('hidden');\n" |
| 408 | " prevName.textContent=ent&&ent.name?ent.name:path.split(/[\\/\\\\]/).pop();\n" |
| 409 | " prevMeta.textContent=ent?fmtSize(ent.size):'';\n" |
| 410 | " btnDownload.classList.remove('hidden');\n" |
| 411 | " while(prevBody.firstChild)prevBody.removeChild(prevBody.firstChild);\n" |
| 412 | " prevBody.scrollTop=0;\n" |
| 413 | "\n" |
| 414 | " var name=prevName.textContent;\n" |
| 415 | " if(isImage(name)){\n" |
| 416 | " var wrap=document.createElement('div');wrap.className='imgwrap';\n" |
| 417 | " var img=document.createElement('img');\n" |
| 418 | " img.alt=name;\n" |
| 419 | " img.src=url('raw','path='+encodeURIComponent(path));\n" |
| 420 | " img.onerror=function(){\n" |
| 421 | " wrap.innerHTML='';\n" |
| 422 | " var n=document.createElement('div');n.className='note';\n" |
| 423 | " n.textContent='This image could not be displayed.';\n" |
| 424 | " wrap.appendChild(n);\n" |
| 425 | " };\n" |
| 426 | " wrap.appendChild(img);prevBody.appendChild(wrap);\n" |
| 427 | " return;\n" |
| 428 | " }\n" |
| 429 | "\n" |
| 430 | " api('read','path='+encodeURIComponent(path)).then(function(d){\n" |
| 431 | " if(!d||!d.ok)throw new Error((d&&d.error)||'failed');\n" |
| 432 | " prevMeta.textContent=fmtSize(d.size)+(d.truncated?' (first 1 MB)':'');\n" |
| 433 | " if(d.binary){\n" |
| 434 | " var n=document.createElement('div');n.className='note';\n" |
| 435 | " n.textContent='Binary file ('+fmtSize(d.size)+') - use Download to inspect it locally.';\n" |
| 436 | " prevBody.appendChild(n);return;\n" |
| 437 | " }\n" |
| 438 | " if(!isTextish(name)&&!isMarkdown(name)){\n" |
| 439 | " prevMeta.textContent=fmtSize(d.size)+(d.truncated?' (first 1 MB)':'')+' · plain text';\n" |
| 440 | " }\n" |
| 441 | " if(isMarkdown(name))renderMarkdown(d.text||'',prevBody);\n" |
| 442 | " else renderCode(d.text||'',prevBody);\n" |
| 443 | " }).catch(function(e){\n" |
| 444 | " while(prevBody.firstChild)prevBody.removeChild(prevBody.firstChild);\n" |
| 445 | " var n=document.createElement('div');n.className='note';\n" |
| 446 | " n.textContent='Cannot preview this file: '+e.message;\n" |
| 447 | " prevBody.appendChild(n);\n" |
| 448 | " });\n" |
| 449 | "}\n" |
| 450 | "\n" |
| 451 | "/* Line numbers + text. Every line is a text node, so file content can never\n" |
| 452 | " * become markup. */\n" |
| 453 | "function renderCode(text,host){\n" |
| 454 | " var lines=text.split('\\n');\n" |
| 455 | " if(lines.length&&lines[lines.length-1]==='')lines.pop();\n" |
| 456 | " var pre=document.createElement('div');pre.className='codetxt';\n" |
| 457 | " var ln=document.createElement('div');ln.className='ln';\n" |
| 458 | " var tx=document.createElement('div');tx.className='tx';\n" |
| 459 | " var nums=[],body=[];\n" |
| 460 | " for(var i=0;i<lines.length;i++){nums.push(String(i+1));body.push(lines[i]);}\n" |
| 461 | " ln.textContent=nums.join('\\n');\n" |
| 462 | " tx.textContent=body.join('\\n');\n" |
| 463 | " pre.appendChild(ln);pre.appendChild(tx);\n" |
| 464 | " host.appendChild(pre);\n" |
| 465 | "}\n" |
| 466 | "\n" |
| 467 | "/* Tiny markdown renderer: headings, lists, fenced code, blockquote, hr,\n" |
| 468 | " * inline code/bold/italic/links. No CDN, no innerHTML with file content. */\n" |
| 469 | "function renderMarkdown(text,host){\n" |
| 470 | " var box=document.createElement('div');box.className='md';\n" |
| 471 | " var lines=text.split('\\n');\n" |
| 472 | " var i=0,para=[],list=null;\n" |
| 473 | "\n" |
| 474 | " function flushPara(){\n" |
| 475 | " if(!para.length)return;\n" |
| 476 | " var p=document.createElement('p');\n" |
| 477 | " inline(para.join(' '),p);\n" |
| 478 | " box.appendChild(p);para=[];\n" |
| 479 | " }\n" |
| 480 | " function flushList(){\n" |
| 481 | " if(!list)return;\n" |
| 482 | " box.appendChild(list);list=null;\n" |
| 483 | " }\n" |
| 484 | " function inline(s,parent){\n" |
| 485 | " var re=/(`[^`]*`)|(\\*\\*[^*]+\\*\\*)|(\\*[^*]+\\*)|(\\[[^\\]]+\\]\\([^)]+\\))/g;\n" |
| 486 | " var last=0,m;\n" |
| 487 | " while((m=re.exec(s))!==null){\n" |
| 488 | " if(m.index>last)parent.appendChild(document.createTextNode(s.slice(last,m.index)));\n" |
| 489 | " var tok=m[0];\n" |
| 490 | " if(tok[0]==='`'){\n" |
| 491 | " var c=document.createElement('code');c.textContent=tok.slice(1,-1);parent.appendChild(c);\n" |
| 492 | " }else if(tok.slice(0,2)==='**'){\n" |
| 493 | " var b=document.createElement('strong');b.textContent=tok.slice(2,-2);parent.appendChild(b);\n" |
| 494 | " }else if(tok[0]==='*'){\n" |
| 495 | " var em=document.createElement('em');em.textContent=tok.slice(1,-1);parent.appendChild(em);\n" |
| 496 | " }else{\n" |
| 497 | " var mm=/^\\[([^\\]]+)\\]\\(([^)]+)\\)$/.exec(tok);\n" |
| 498 | " if(mm&&/^(https?:\\/\\/|\\/|#|mailto:)/i.test(mm[2])){\n" |
| 499 | " var a=document.createElement('a');\n" |
| 500 | " a.textContent=mm[1];a.href=mm[2];\n" |
| 501 | " a.target='_blank';a.rel='noopener noreferrer';\n" |
| 502 | " parent.appendChild(a);\n" |
| 503 | " }else if(mm){\n" |
| 504 | " parent.appendChild(document.createTextNode(mm[1]));\n" |
| 505 | " }\n" |
| 506 | " }\n" |
| 507 | " last=m.index+tok.length;\n" |
| 508 | " }\n" |
| 509 | " if(last<s.length)parent.appendChild(document.createTextNode(s.slice(last)));\n" |
| 510 | " }\n" |
| 511 | "\n" |
| 512 | " while(i<lines.length){\n" |
| 513 | " var line=lines[i];\n" |
| 514 | " if(/^```/.test(line)){\n" |
| 515 | " flushPara();flushList();\n" |
| 516 | " var buf=[];i++;\n" |
| 517 | " while(i<lines.length&&!/^```/.test(lines[i])){buf.push(lines[i]);i++;}\n" |
| 518 | " i++;\n" |
| 519 | " var pre=document.createElement('pre');\n" |
| 520 | " var code=document.createElement('code');code.textContent=buf.join('\\n');\n" |
| 521 | " pre.appendChild(code);box.appendChild(pre);\n" |
| 522 | " continue;\n" |
| 523 | " }\n" |
| 524 | " if(/^\\s*$/.test(line)){flushPara();flushList();i++;continue;}\n" |
| 525 | " var h=/^(#{1,4})\\s+(.*)$/.exec(line);\n" |
| 526 | " if(h){\n" |
| 527 | " flushPara();flushList();\n" |
| 528 | " var el=document.createElement('h'+h[1].length);\n" |
| 529 | " inline(h[2],el);box.appendChild(el);i++;continue;\n" |
| 530 | " }\n" |
| 531 | " if(/^\\s*([-*+]|\\d+\\.)\\s+/.test(line)){\n" |
| 532 | " flushPara();\n" |
| 533 | " var ordered=/^\\s*\\d+\\.\\s+/.test(line);\n" |
| 534 | " if(!list||list.tagName.toLowerCase()!==(ordered?'ol':'ul')){\n" |
| 535 | " flushList();list=document.createElement(ordered?'ol':'ul');\n" |
| 536 | " }\n" |
| 537 | " var li=document.createElement('li');\n" |
| 538 | " inline(line.replace(/^\\s*([-*+]|\\d+\\.)\\s+/,''),li);\n" |
| 539 | " list.appendChild(li);i++;continue;\n" |
| 540 | " }\n" |
| 541 | " if(/^>\\s?/.test(line)){\n" |
| 542 | " flushPara();flushList();\n" |
| 543 | " var bq=document.createElement('blockquote');\n" |
| 544 | " inline(line.replace(/^>\\s?/,''),bq);\n" |
| 545 | " box.appendChild(bq);i++;continue;\n" |
| 546 | " }\n" |
| 547 | " if(/^(-{3,}|\\*{3,}|_{3,})$/.test(line.trim())){\n" |
| 548 | " flushPara();flushList();\n" |
| 549 | " box.appendChild(document.createElement('hr'));i++;continue;\n" |
| 550 | " }\n" |
| 551 | " para.push(line);i++;\n" |
| 552 | " }\n" |
| 553 | " flushPara();flushList();\n" |
| 554 | " host.appendChild(box);\n" |
| 555 | "}\n" |
| 556 | "\n" |
| 557 | "/* --- wiring ------------------------------------------------------- */\n" |
| 558 | "\n" |
| 559 | "document.getElementById('btnRefresh').onclick=function(){\n" |
| 560 | " if(curPath)openDir(curPath);else loadRoots();\n" |
| 561 | "};\n" |
| 562 | "document.getElementById('btnUp').onclick=function(){\n" |
| 563 | " if(curParent)openDir(curParent);\n" |
| 564 | " else if(curPath&&curRoot&&curPath!==curRoot)openDir(curRoot);\n" |
| 565 | " else toast('Already at the root');\n" |
| 566 | "};\n" |
| 567 | "document.getElementById('btnBack').onclick=function(){setView('browse');};\n" |
| 568 | "document.getElementById('btnTheme').onclick=function(){\n" |
| 569 | " if(window.sxApplyTheme)window.sxApplyTheme(window.sxTheme&&window.sxTheme()==='dark'?'light':'dark');\n" |
| 570 | "};\n" |
| 571 | "btnHidden.onclick=function(){\n" |
| 572 | " showHidden=!showHidden;\n" |
| 573 | " btnHidden.classList.toggle('on',showHidden);\n" |
| 574 | " btnHidden.title=showHidden?'Hide hidden files':'Show hidden files';\n" |
| 575 | " if(curPath)openDir(curPath);\n" |
| 576 | "};\n" |
| 577 | "btnDownload.onclick=function(){\n" |
| 578 | " if(!curFile)return;\n" |
| 579 | " var a=document.createElement('a');\n" |
| 580 | " a.href=url('raw','path='+encodeURIComponent(curFile)+'&download=1');\n" |
| 581 | " a.rel='noopener';\n" |
| 582 | " document.body.appendChild(a);a.click();document.body.removeChild(a);\n" |
| 583 | "};\n" |
| 584 | "\n" |
| 585 | "document.addEventListener('keydown',function(ev){\n" |
| 586 | " var tag=(ev.target&&ev.target.tagName||'').toLowerCase();\n" |
| 587 | " if(tag==='input'||tag==='textarea')return;\n" |
| 588 | " if(ev.key==='ArrowDown'||ev.key==='ArrowUp'){\n" |
| 589 | " if(!entries.length)return;\n" |
| 590 | " ev.preventDefault();\n" |
| 591 | " selIndex+=(ev.key==='ArrowDown'?1:-1);\n" |
| 592 | " if(selIndex<0)selIndex=0;\n" |
| 593 | " if(selIndex>=entries.length)selIndex=entries.length-1;\n" |
| 594 | " renderEntries();\n" |
| 595 | " }else if(ev.key==='Enter'){\n" |
| 596 | " if(selIndex>=0&&entries[selIndex]){ev.preventDefault();activate(entries[selIndex]);}\n" |
| 597 | " }else if(ev.key==='Backspace'){\n" |
| 598 | " if(curParent){ev.preventDefault();openDir(curParent);}\n" |
| 599 | " }else if(ev.key==='/'&&ev.ctrlKey===false){\n" |
| 600 | " return;\n" |
| 601 | " }\n" |
| 602 | "});\n" |
| 603 | "\n" |
| 604 | "function loadRoots(){\n" |
| 605 | " return api('roots').then(function(d){\n" |
| 606 | " roots=(d&&d.roots)||[];\n" |
| 607 | " renderRoots();\n" |
| 608 | " /* Wide screens open the first root straight away; a phone keeps the root\n" |
| 609 | " * list on screen, because a hidden sidebar there means an empty page. */\n" |
| 610 | " if(roots.length&&!curPath&&window.matchMedia('(min-width:821px)').matches){\n" |
| 611 | " openDir(roots[0].path);\n" |
| 612 | " }\n" |
| 613 | " }).catch(function(e){toast('Cannot list roots: '+e.message);});\n" |
| 614 | "}\n" |
| 615 | "\n" |
| 616 | "loadRoots();\n" |
| 617 | "})();\n" |
| 618 | "</script>\n" |
| 619 | "\002</body></html>\n" |
| 620 | ; |
| 621 | |
| 622 | #endif /* SX_FILES_UI_HTML_H */ |