const fs = require('fs'); const js = fs.readFileSync('c:/dev/git/python/ObsiGate/frontend/app.js', 'utf8'); const extractManager = (name) => { const regex = new RegExp('const ' + name + ' = \\{[\\s\\S]*?\\n \\};'); const match = regex.exec(js); return match ? match[0] : ''; }; // Also we need variables const vars = 'let rightSidebarVisible = false;\nlet rightSidebarWidth = 280;\nlet headingsCache = [];\nlet activeHeadingId = null;'; const utils = 'function el(tag, attrs, children) {\n const e = document.createElement(tag);\n if (attrs) { for (let k in attrs) { if (k === "class") e.className = attrs[k]; else e.setAttribute(k, attrs[k]); } }\n if (children) { children.forEach(c => { if (typeof c === "string") e.appendChild(document.createTextNode(c)); else e.appendChild(c); }); }\n return e;\n}'; const safeCreateIcons = 'function safeCreateIcons() { if (window.lucide) window.lucide.createIcons(); }'; const code = [ vars, utils, safeCreateIcons, extractManager('OutlineManager'), extractManager('ScrollSpyManager'), extractManager('ReadingProgressManager'), extractManager('RightSidebarManager') ].join('\n\n'); let html = fs.readFileSync('c:/dev/git/python/ObsiGate/frontend/popout.html', 'utf8'); // replace body layout html = html.replace('