9remote 2.0.1 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,358 +0,0 @@
1
- import chalk from "chalk";
2
- import { readFileSync, writeFileSync, existsSync, unlinkSync } from "fs";
3
- import { fileURLToPath } from "url";
4
- import { spawn, execSync } from "child_process";
5
- import path from "path";
6
- import os from "os";
7
- import { browserFetch } from "../../lib/constants.js";
8
- import { killAll as killAllPids, getPidsDir } from "./pids.js";
9
-
10
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
- const PACKAGE_NAME = "9remote";
12
- const NPM_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
13
- const UPDATE_CHECK_TIMEOUT = 3000;
14
- const SAFETY_TIMEOUT = 8000;
15
- const SERVER_PORT = 2208;
16
- // Legacy path from pre-pids.js installs — clean up once so old instances
17
- // can still be killed during upgrade from older versions.
18
- const LEGACY_CLOUDFLARED_PID_FILE = path.join(os.homedir(), ".9remote", "cloudflared.pid");
19
-
20
- /**
21
- * Kill all 9remote-related child processes to release file locks before npm install.
22
- *
23
- * Critical on Windows: node.exe / tray helper / cloudflared.exe lock files inside
24
- * node_modules\9remote\dist, so `npm i -g` fails with EBUSY when trying to rename
25
- * the old dist folder.
26
- *
27
- * We kill ONLY by PID (from ~/.9remote/pids/) — never by image name (taskkill /IM)
28
- * or by commandline match, because those would also kill unrelated apps on the
29
- * machine that happen to use cloudflared.exe, tray_windows_release.exe, or node.exe.
30
- */
31
- function cleanupBeforeUpdate() {
32
- // 1. Kill tracked processes (cloudflared + agent tree) via pids.js.
33
- // Agent kill with taskkill /F /T sweeps its server child + tray helper.
34
- try { killAllPids(); } catch {}
35
-
36
- // 2. Legacy: older versions stored cloudflared PID at a different path.
37
- try {
38
- if (existsSync(LEGACY_CLOUDFLARED_PID_FILE)) {
39
- const pid = parseInt(readFileSync(LEGACY_CLOUDFLARED_PID_FILE, "utf8"));
40
- if (Number.isFinite(pid)) { try { process.kill(pid); } catch {} }
41
- try { unlinkSync(LEGACY_CLOUDFLARED_PID_FILE); } catch {}
42
- }
43
- } catch {}
44
-
45
- // 3. Safety net for stale server on SERVER_PORT (e.g. crashed without clearing PID).
46
- // Scoped to one specific port, so we only touch 9remote's own server.
47
- try {
48
- if (process.platform === "win32") {
49
- execSync(`for /f "tokens=5" %a in ('netstat -aon ^| findstr :${SERVER_PORT}') do taskkill /F /PID %a`, { stdio: "ignore", windowsHide: true });
50
- } else {
51
- execSync(`lsof -ti:${SERVER_PORT} | xargs kill -9 2>/dev/null || true`, { stdio: "ignore" });
52
- }
53
- } catch {}
54
-
55
- // 4. Give Windows a moment to release file handles before npm tries to rename.
56
- if (process.platform === "win32") {
57
- const end = Date.now() + 1500;
58
- while (Date.now() < end) { /* spin-wait; Atomics.wait not worth importing */ }
59
- }
60
- }
61
-
62
- /**
63
- * Get current version
64
- */
65
- function getCurrentVersion() {
66
- // When bundled, version is injected at build time
67
- if (typeof __CLI_VERSION__ !== "undefined") {
68
- return __CLI_VERSION__;
69
- }
70
-
71
- // Dev mode: read from package.json
72
- try {
73
- const packagePath = path.resolve(__dirname, "../package.json");
74
- const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
75
- return packageJson.version;
76
- } catch {
77
- return null;
78
- }
79
- }
80
-
81
- /**
82
- * Compare semver versions
83
- * Returns true if latest > current
84
- */
85
- export function isNewerVersion(current, latest) {
86
- const currentParts = current.split(".").map(Number);
87
- const latestParts = latest.split(".").map(Number);
88
-
89
- for (let i = 0; i < 3; i++) {
90
- if (latestParts[i] > currentParts[i]) return true;
91
- if (latestParts[i] < currentParts[i]) return false;
92
- }
93
- return false;
94
- }
95
-
96
- /**
97
- * Check if running in restricted environment (Codespaces, Docker)
98
- */
99
- function isRestrictedEnvironment() {
100
- if (process.env.CODESPACES === "true" || process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN) {
101
- return "GitHub Codespaces";
102
- }
103
- if (existsSync("/.dockerenv")) {
104
- return "Docker";
105
- }
106
- return null;
107
- }
108
-
109
- /**
110
- * Check for npm updates (non-blocking, notification only)
111
- */
112
- /**
113
- * Kill running 9remote processes so user can safely run `npm i -g 9remote@latest`.
114
- * Called when user chooses manual update from startup menu.
115
- */
116
- export function stopRunningInstances() {
117
- cleanupBeforeUpdate();
118
- }
119
-
120
- export async function checkForUpdates() {
121
- try {
122
- const currentVersion = getCurrentVersion();
123
- if (!currentVersion) return;
124
-
125
- const response = await browserFetch(NPM_REGISTRY_URL, {
126
- signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT)
127
- });
128
-
129
- if (!response.ok) return;
130
-
131
- const data = await response.json();
132
- const latestVersion = data.version;
133
-
134
- if (latestVersion && isNewerVersion(currentVersion, latestVersion)) {
135
- console.log(
136
- chalk.yellow(`\n⬆️ New version ${chalk.green(latestVersion)} available (current: ${currentVersion})`)
137
- );
138
- console.log(chalk.gray(` Run: npm i -g ${PACKAGE_NAME}\n`));
139
- }
140
- } catch {
141
- // Silent fail - don't block CLI
142
- }
143
- }
144
-
145
- /**
146
- * Check if a newer version exists — returns { current, latest } or null.
147
- * Silent fail, no auto-update, no spinner.
148
- */
149
- export async function checkLatestVersion() {
150
- try {
151
- const currentVersion = getCurrentVersion();
152
- if (!currentVersion) return null;
153
- const response = await browserFetch(NPM_REGISTRY_URL, {
154
- signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT)
155
- });
156
- if (!response.ok) return null;
157
- const { version: latestVersion } = await response.json();
158
- if (latestVersion && isNewerVersion(currentVersion, latestVersion)) {
159
- return { current: currentVersion, latest: latestVersion };
160
- }
161
- return null;
162
- } catch {
163
- return null;
164
- }
165
- }
166
-
167
- /**
168
- * Check and auto-update if new version available
169
- * Returns true if update started (process will exit), false otherwise
170
- */
171
- export async function checkAndUpdate(skipUpdate = false) {
172
- if (skipUpdate) return false;
173
-
174
- const currentVersion = getCurrentVersion();
175
- if (!currentVersion) return false;
176
-
177
- // Spinner frames
178
- const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
179
- let frameIndex = 0;
180
- let spinnerInterval = null;
181
-
182
- const startSpinner = (text) => {
183
- if (process.stdout.isTTY) {
184
- process.stdout.write(`\r${frames[0]} ${text}`);
185
- spinnerInterval = setInterval(() => {
186
- process.stdout.write(`\r${frames[frameIndex++ % frames.length]} ${text}`);
187
- }, 80);
188
- }
189
- };
190
-
191
- const stopSpinner = () => {
192
- if (spinnerInterval) {
193
- clearInterval(spinnerInterval);
194
- spinnerInterval = null;
195
- }
196
- if (process.stdout.isTTY) {
197
- process.stdout.write("\r\x1b[K");
198
- }
199
- };
200
-
201
- return new Promise((resolve) => {
202
- let resolved = false;
203
-
204
- const safeResolve = (value) => {
205
- if (!resolved) {
206
- resolved = true;
207
- stopSpinner();
208
- resolve(value);
209
- }
210
- };
211
-
212
- // Safety timeout to prevent hanging
213
- const safetyTimer = setTimeout(() => safeResolve(false), SAFETY_TIMEOUT);
214
-
215
- startSpinner("Checking for updates...");
216
-
217
- browserFetch(NPM_REGISTRY_URL, { signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT) })
218
- .then((res) => res.json())
219
- .then((data) => {
220
- if (resolved) return;
221
- clearTimeout(safetyTimer);
222
-
223
- const latestVersion = data.version;
224
- if (!latestVersion || !isNewerVersion(currentVersion, latestVersion)) {
225
- safeResolve(false);
226
- return;
227
- }
228
-
229
- stopSpinner();
230
- console.log(chalk.green(`✅ New version available: ${currentVersion} → ${latestVersion}`));
231
-
232
- // Check restricted environment
233
- const restrictedEnv = isRestrictedEnvironment();
234
- if (restrictedEnv) {
235
- console.log(chalk.yellow(` ⚠️ ${restrictedEnv} detected - manual update required`));
236
- console.log(chalk.gray(` Run: npm install -g ${PACKAGE_NAME}@latest\n`));
237
- safeResolve(false);
238
- return;
239
- }
240
-
241
- console.log(chalk.yellow("🔄 Auto-updating...\n"));
242
-
243
- // Build update script
244
- const args = process.argv.slice(2).filter((a) => a !== "--skip-update");
245
- const argsStr = args.join(" ");
246
- const platform = process.platform;
247
-
248
- let scriptPath, shellCmd;
249
-
250
- // The update script must kill our tracked processes by PID ONLY.
251
- // Never use `taskkill /IM <image>` or `pkill -f <name>` — those match
252
- // by binary name / commandline and would nuke unrelated apps on the
253
- // machine (other cloudflared tunnels, other tray apps, any node.exe).
254
- const pidsDir = getPidsDir();
255
-
256
- if (platform === "win32") {
257
- const script = `@echo off
258
- echo 📥 Downloading update...
259
- echo ⏳ Stopping 9remote processes...
260
-
261
- REM Kill cloudflared first so it stops reconnecting, then kill the agent
262
- REM tree (/T also terminates its server child + tray helper). PID-based so
263
- REM we never touch unrelated node.exe / cloudflared.exe on this machine.
264
- REM ptyDaemon is intentionally NOT killed — keep terminal sessions alive.
265
- for %%N in (cloudflared agent) do (
266
- if exist "${pidsDir}\\%%N.pid" (
267
- for /f %%P in ('type "${pidsDir}\\%%N.pid"') do taskkill /F /T /PID %%P >nul 2>&1
268
- del /f /q "${pidsDir}\\%%N.pid" >nul 2>&1
269
- )
270
- )
271
-
272
- REM Safety net: kill anything still bound to our server port.
273
- for /f "tokens=5" %%a in ('netstat -aon ^| findstr :${SERVER_PORT}') do taskkill /F /PID %%a >nul 2>&1
274
-
275
- REM Let Windows flush file handles before npm renames node_modules\\9remote.
276
- timeout /t 3 /nobreak >nul
277
-
278
- echo 🔄 Installing new version...
279
- call npm cache clean --force >nul 2>&1
280
- call npm install -g ${PACKAGE_NAME}@latest --prefer-online
281
-
282
- if %ERRORLEVEL% EQU 0 (
283
- echo ✅ Update completed successfully
284
- echo 🚀 Restarting with new version...
285
- ${PACKAGE_NAME} ${argsStr} --skip-update
286
- ) else (
287
- echo ❌ Update failed
288
- echo 💡 Try manually: npm install -g ${PACKAGE_NAME}
289
- echo 🔄 Starting with current version...
290
- ${PACKAGE_NAME} ${argsStr} --skip-update
291
- )
292
- `;
293
- scriptPath = path.join(os.tmpdir(), `${PACKAGE_NAME}-update.bat`);
294
- writeFileSync(scriptPath, script);
295
- shellCmd = ["cmd.exe", ["/c", scriptPath]];
296
- } else {
297
- const script = `#!/bin/bash
298
- echo "📥 Downloading update..."
299
- echo "⏳ Stopping 9remote processes..."
300
-
301
- # Kill cloudflared first, then the agent (children die with the agent on
302
- # POSIX once the parent process exits and systemd/init reaps them, or here
303
- # because we SIGKILL them via kill -9). PID-based so unrelated apps are safe.
304
- # ptyDaemon is intentionally NOT killed — keep terminal sessions alive.
305
- for name in cloudflared agent; do
306
- f="${pidsDir}/\${name}.pid"
307
- if [ -f "$f" ]; then
308
- pid=$(cat "$f" 2>/dev/null)
309
- [ -n "$pid" ] && kill -9 "$pid" 2>/dev/null || true
310
- rm -f "$f"
311
- fi
312
- done
313
-
314
- # Safety net: kill anything still bound to our server port.
315
- lsof -ti:${SERVER_PORT} | xargs kill -9 2>/dev/null || true
316
- sleep 2
317
-
318
- echo "🔄 Installing new version..."
319
- npm cache clean --force 2>/dev/null
320
-
321
- # Try to install with full output for debugging
322
- npm install -g ${PACKAGE_NAME}@latest --prefer-online 2>&1
323
- EXIT_CODE=$?
324
-
325
- if [ $EXIT_CODE -eq 0 ]; then
326
- echo "✅ Update completed successfully"
327
- echo "🚀 Restarting with new version..."
328
- ${PACKAGE_NAME} ${argsStr} --skip-update
329
- else
330
- echo "❌ Update failed (exit code: $EXIT_CODE)"
331
- echo "💡 Update manually: npm install -g ${PACKAGE_NAME}@latest"
332
- echo "🔄 Starting with current version..."
333
- ${PACKAGE_NAME} ${argsStr} --skip-update
334
- fi
335
- `;
336
- scriptPath = path.join(os.tmpdir(), `${PACKAGE_NAME}-update.sh`);
337
- writeFileSync(scriptPath, script, { mode: 0o755 });
338
- shellCmd = ["sh", [scriptPath]];
339
- }
340
-
341
- // Cleanup child processes to release file locks before npm install
342
- cleanupBeforeUpdate();
343
-
344
- // Execute update script in background
345
- const child = spawn(shellCmd[0], shellCmd[1], {
346
- detached: true,
347
- stdio: "inherit"
348
- });
349
- child.unref();
350
-
351
- process.exit(0);
352
- })
353
- .catch(() => {
354
- clearTimeout(safetyTimer);
355
- safeResolve(false);
356
- });
357
- });
358
- }
@@ -1,8 +0,0 @@
1
- (function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))i(n);new MutationObserver(n=>{for(const r of n)if(r.type==="childList")for(const s of r.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&i(s)}).observe(document,{childList:!0,subtree:!0});function o(n){const r={};return n.integrity&&(r.integrity=n.integrity),n.referrerPolicy&&(r.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?r.credentials="include":n.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(n){if(n.ep)return;n.ep=!0;const r=o(n);fetch(n.href,r)}})();var Ne,D,Zt,X,at,$t,en,ke,_e,le,tn,nt,Xe,Ze,ve={},be=[],yn=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Ce=Array.isArray;function J(e,t){for(var o in t)e[o]=t[o];return e}function rt(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function vn(e,t,o){var i,n,r,s={};for(r in t)r=="key"?i=t[r]:r=="ref"?n=t[r]:s[r]=t[r];if(arguments.length>2&&(s.children=arguments.length>3?Ne.call(arguments,2):o),typeof e=="function"&&e.defaultProps!=null)for(r in e.defaultProps)s[r]===void 0&&(s[r]=e.defaultProps[r]);return pe(e,s,i,n,null)}function pe(e,t,o,i,n){var r={type:e,props:t,key:o,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:n??++Zt,__i:-1,__u:0};return n==null&&D.vnode!=null&&D.vnode(r),r}function Z(e){return e.children}function ge(e,t){this.props=e,this.context=t}function re(e,t){if(t==null)return e.__?re(e.__,e.__i+1):null;for(var o;t<e.__k.length;t++)if((o=e.__k[t])!=null&&o.__e!=null)return o.__e;return typeof e.type=="function"?re(e):null}function bn(e){if(e.__P&&e.__d){var t=e.__v,o=t.__e,i=[],n=[],r=J({},t);r.__v=t.__v+1,D.vnode&&D.vnode(r),ot(e.__P,r,t,e.__n,e.__P.namespaceURI,32&t.__u?[o]:null,i,o??re(t),!!(32&t.__u),n),r.__v=t.__v,r.__.__k[r.__i]=r,sn(i,r,n),t.__e=t.__=null,r.__e!=o&&nn(r)}}function nn(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),nn(e)}function ct(e){(!e.__d&&(e.__d=!0)&&X.push(e)&&!we.__r++||at!=D.debounceRendering)&&((at=D.debounceRendering)||$t)(we)}function we(){try{for(var e,t=1;X.length;)X.length>t&&X.sort(en),e=X.shift(),t=X.length,bn(e)}finally{X.length=we.__r=0}}function rn(e,t,o,i,n,r,s,l,a,d,m){var u,h,f,g,x,I,_,y=i&&i.__k||be,C=t.length;for(a=wn(o,t,y,a,C),u=0;u<C;u++)(f=o.__k[u])!=null&&(h=f.__i!=-1&&y[f.__i]||ve,f.__i=u,I=ot(e,f,h,n,r,s,l,a,d,m),g=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&it(h.ref,null,f),m.push(f.ref,f.__c||g,f)),x==null&&g!=null&&(x=g),(_=!!(4&f.__u))||h.__k===f.__k?(a=on(f,a,e,_),_&&h.__e&&(h.__e=null)):typeof f.type=="function"&&I!==void 0?a=I:g&&(a=g.nextSibling),f.__u&=-7);return o.__e=x,a}function wn(e,t,o,i,n){var r,s,l,a,d,m=o.length,u=m,h=0;for(e.__k=new Array(n),r=0;r<n;r++)(s=t[r])!=null&&typeof s!="boolean"&&typeof s!="function"?(typeof s=="string"||typeof s=="number"||typeof s=="bigint"||s.constructor==String?s=e.__k[r]=pe(null,s,null,null,null):Ce(s)?s=e.__k[r]=pe(Z,{children:s},null,null,null):s.constructor===void 0&&s.__b>0?s=e.__k[r]=pe(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):e.__k[r]=s,a=r+h,s.__=e,s.__b=e.__b+1,l=null,(d=s.__i=xn(s,o,a,u))!=-1&&(u--,(l=o[d])&&(l.__u|=2)),l==null||l.__v==null?(d==-1&&(n>m?h--:n<m&&h++),typeof s.type!="function"&&(s.__u|=4)):d!=a&&(d==a-1?h--:d==a+1?h++:(d>a?h--:h++,s.__u|=4))):e.__k[r]=null;if(u)for(r=0;r<m;r++)(l=o[r])!=null&&(2&l.__u)==0&&(l.__e==i&&(i=re(l)),an(l,l));return i}function on(e,t,o,i){var n,r;if(typeof e.type=="function"){for(n=e.__k,r=0;n&&r<n.length;r++)n[r]&&(n[r].__=e,t=on(n[r],t,o,i));return t}e.__e!=t&&(i&&(t&&e.type&&!t.parentNode&&(t=re(e)),o.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function xn(e,t,o,i){var n,r,s,l=e.key,a=e.type,d=t[o],m=d!=null&&(2&d.__u)==0;if(d===null&&l==null||m&&l==d.key&&a==d.type)return o;if(i>(m?1:0)){for(n=o-1,r=o+1;n>=0||r<t.length;)if((d=t[s=n>=0?n--:r++])!=null&&(2&d.__u)==0&&l==d.key&&a==d.type)return s}return-1}function ut(e,t,o){t[0]=="-"?e.setProperty(t,o??""):e[t]=o==null?"":typeof o!="number"||yn.test(t)?o:o+"px"}function fe(e,t,o,i,n){var r,s;e:if(t=="style")if(typeof o=="string")e.style.cssText=o;else{if(typeof i=="string"&&(e.style.cssText=i=""),i)for(t in i)o&&t in o||ut(e.style,t,"");if(o)for(t in o)i&&o[t]==i[t]||ut(e.style,t,o[t])}else if(t[0]=="o"&&t[1]=="n")r=t!=(t=t.replace(tn,"$1")),s=t.toLowerCase(),t=s in e||t=="onFocusOut"||t=="onFocusIn"?s.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+r]=o,o?i?o[le]=i[le]:(o[le]=nt,e.addEventListener(t,r?Ze:Xe,r)):e.removeEventListener(t,r?Ze:Xe,r);else{if(n=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=o??"";break e}catch{}typeof o=="function"||(o==null||o===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&o==1?"":o))}}function dt(e){return function(t){if(this.l){var o=this.l[t.type+e];if(t[_e]==null)t[_e]=nt++;else if(t[_e]<o[le])return;return o(D.event?D.event(t):t)}}}function ot(e,t,o,i,n,r,s,l,a,d){var m,u,h,f,g,x,I,_,y,C,v,M,b,N,k,p=t.type;if(t.constructor!==void 0)return null;128&o.__u&&(a=!!(32&o.__u),r=[l=t.__e=o.__e]),(m=D.__b)&&m(t);e:if(typeof p=="function")try{if(_=t.props,y=p.prototype&&p.prototype.render,C=(m=p.contextType)&&i[m.__c],v=m?C?C.props.value:m.__:i,o.__c?I=(u=t.__c=o.__c).__=u.__E:(y?t.__c=u=new p(_,v):(t.__c=u=new ge(_,v),u.constructor=p,u.render=Cn),C&&C.sub(u),u.state||(u.state={}),u.__n=i,h=u.__d=!0,u.__h=[],u._sb=[]),y&&u.__s==null&&(u.__s=u.state),y&&p.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=J({},u.__s)),J(u.__s,p.getDerivedStateFromProps(_,u.__s))),f=u.props,g=u.state,u.__v=t,h)y&&p.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),y&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(y&&p.getDerivedStateFromProps==null&&_!==f&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(_,v),t.__v==o.__v||!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(_,u.__s,v)===!1){t.__v!=o.__v&&(u.props=_,u.state=u.__s,u.__d=!1),t.__e=o.__e,t.__k=o.__k,t.__k.some(function(S){S&&(S.__=t)}),be.push.apply(u.__h,u._sb),u._sb=[],u.__h.length&&s.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(_,u.__s,v),y&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,g,x)})}if(u.context=v,u.props=_,u.__P=e,u.__e=!1,M=D.__r,b=0,y)u.state=u.__s,u.__d=!1,M&&M(t),m=u.render(u.props,u.state,u.context),be.push.apply(u.__h,u._sb),u._sb=[];else do u.__d=!1,M&&M(t),m=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++b<25);u.state=u.__s,u.getChildContext!=null&&(i=J(J({},i),u.getChildContext())),y&&!h&&u.getSnapshotBeforeUpdate!=null&&(x=u.getSnapshotBeforeUpdate(f,g)),N=m!=null&&m.type===Z&&m.key==null?ln(m.props.children):m,l=rn(e,Ce(N)?N:[N],t,o,i,n,r,s,l,a,d),u.base=t.__e,t.__u&=-161,u.__h.length&&s.push(u),I&&(u.__E=u.__=null)}catch(S){if(t.__v=null,a||r!=null)if(S.then){for(t.__u|=a?160:128;l&&l.nodeType==8&&l.nextSibling;)l=l.nextSibling;r[r.indexOf(l)]=null,t.__e=l}else{for(k=r.length;k--;)rt(r[k]);$e(t)}else t.__e=o.__e,t.__k=o.__k,S.then||$e(t);D.__e(S,t,o)}else r==null&&t.__v==o.__v?(t.__k=o.__k,t.__e=o.__e):l=t.__e=Nn(o.__e,t,o,i,n,r,s,a,d);return(m=D.diffed)&&m(t),128&t.__u?void 0:l}function $e(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some($e))}function sn(e,t,o){for(var i=0;i<o.length;i++)it(o[i],o[++i],o[++i]);D.__c&&D.__c(t,e),e.some(function(n){try{e=n.__h,n.__h=[],e.some(function(r){r.call(n)})}catch(r){D.__e(r,n.__v)}})}function ln(e){return typeof e!="object"||e==null||e.__b>0?e:Ce(e)?e.map(ln):J({},e)}function Nn(e,t,o,i,n,r,s,l,a){var d,m,u,h,f,g,x,I=o.props||ve,_=t.props,y=t.type;if(y=="svg"?n="http://www.w3.org/2000/svg":y=="math"?n="http://www.w3.org/1998/Math/MathML":n||(n="http://www.w3.org/1999/xhtml"),r!=null){for(d=0;d<r.length;d++)if((f=r[d])&&"setAttribute"in f==!!y&&(y?f.localName==y:f.nodeType==3)){e=f,r[d]=null;break}}if(e==null){if(y==null)return document.createTextNode(_);e=document.createElementNS(n,y,_.is&&_),l&&(D.__m&&D.__m(t,r),l=!1),r=null}if(y==null)I===_||l&&e.data==_||(e.data=_);else{if(r=r&&Ne.call(e.childNodes),!l&&r!=null)for(I={},d=0;d<e.attributes.length;d++)I[(f=e.attributes[d]).name]=f.value;for(d in I)f=I[d],d=="dangerouslySetInnerHTML"?u=f:d=="children"||d in _||d=="value"&&"defaultValue"in _||d=="checked"&&"defaultChecked"in _||fe(e,d,null,f,n);for(d in _)f=_[d],d=="children"?h=f:d=="dangerouslySetInnerHTML"?m=f:d=="value"?g=f:d=="checked"?x=f:l&&typeof f!="function"||I[d]===f||fe(e,d,f,I[d],n);if(m)l||u&&(m.__html==u.__html||m.__html==e.innerHTML)||(e.innerHTML=m.__html),t.__k=[];else if(u&&(e.innerHTML=""),rn(t.type=="template"?e.content:e,Ce(h)?h:[h],t,o,i,y=="foreignObject"?"http://www.w3.org/1999/xhtml":n,r,s,r?r[0]:o.__k&&re(o,0),l,a),r!=null)for(d=r.length;d--;)rt(r[d]);l||(d="value",y=="progress"&&g==null?e.removeAttribute("value"):g!=null&&(g!==e[d]||y=="progress"&&!g||y=="option"&&g!=I[d])&&fe(e,d,g,I[d],n),d="checked",x!=null&&x!=e[d]&&fe(e,d,x,I[d],n))}return e}function it(e,t,o){try{if(typeof e=="function"){var i=typeof e.__u=="function";i&&e.__u(),i&&t==null||(e.__u=e(t))}else e.current=t}catch(n){D.__e(n,o)}}function an(e,t,o){var i,n;if(D.unmount&&D.unmount(e),(i=e.ref)&&(i.current&&i.current!=e.__e||it(i,null,t)),(i=e.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(r){D.__e(r,t)}i.base=i.__P=null}if(i=e.__k)for(n=0;n<i.length;n++)i[n]&&an(i[n],t,o||typeof e.type!="function");o||rt(e.__e),e.__c=e.__=e.__e=void 0}function Cn(e,t,o){return this.constructor(e,o)}function kn(e,t,o){var i,n,r,s;t==document&&(t=document.documentElement),D.__&&D.__(e,t),n=(i=!1)?null:t.__k,r=[],s=[],ot(t,e=t.__k=vn(Z,null,[e]),n||ve,ve,t.namespaceURI,n?null:t.firstChild?Ne.call(t.childNodes):null,r,n?n.__e:t.firstChild,i,s),sn(r,e,s)}Ne=be.slice,D={__e:function(e,t,o,i){for(var n,r,s;t=t.__;)if((n=t.__c)&&!n.__)try{if((r=n.constructor)&&r.getDerivedStateFromError!=null&&(n.setState(r.getDerivedStateFromError(e)),s=n.__d),n.componentDidCatch!=null&&(n.componentDidCatch(e,i||{}),s=n.__d),s)return n.__E=n}catch(l){e=l}throw e}},Zt=0,ge.prototype.setState=function(e,t){var o;o=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=J({},this.state),typeof e=="function"&&(e=e(J({},o),this.props)),e&&J(o,e),e!=null&&this.__v&&(t&&this._sb.push(t),ct(this))},ge.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),ct(this))},ge.prototype.render=Z,X=[],$t=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,en=function(e,t){return e.__v.__b-t.__v.__b},we.__r=0,ke=Math.random().toString(8),_e="__d"+ke,le="__a"+ke,tn=/(PointerCapture)$|Capture$/i,nt=0,Xe=dt(!1),Ze=dt(!0);var Sn=0;function c(e,t,o,i,n,r){t||(t={});var s,l,a=t;if("ref"in a)for(l in a={},t)l=="ref"?s=t[l]:a[l]=t[l];var d={type:e,props:a,key:o,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Sn,__i:-1,__u:0,__source:n,__self:r};if(typeof e=="function"&&(s=e.defaultProps))for(l in s)a[l]===void 0&&(a[l]=s[l]);return D.vnode&&D.vnode(d),d}var ce,U,Se,ft,xe=0,cn=[],q=D,ht=q.__b,mt=q.__r,_t=q.diffed,pt=q.__c,gt=q.unmount,yt=q.__;function st(e,t){q.__h&&q.__h(U,e,xe||t),xe=0;var o=U.__H||(U.__H={__:[],__h:[]});return e>=o.__.length&&o.__.push({}),o.__[e]}function F(e){return xe=1,En(fn,e)}function En(e,t,o){var i=st(ce++,2);if(i.t=e,!i.__c&&(i.__=[fn(void 0,t),function(l){var a=i.__N?i.__N[0]:i.__[0],d=i.t(a,l);a!==d&&(i.__N=[d,i.__[1]],i.__c.setState({}))}],i.__c=U,!U.__f)){var n=function(l,a,d){if(!i.__c.__H)return!0;var m=i.__c.__H.__.filter(function(h){return h.__c});if(m.every(function(h){return!h.__N}))return!r||r.call(this,l,a,d);var u=i.__c.props!==l;return m.some(function(h){if(h.__N){var f=h.__[0];h.__=h.__N,h.__N=void 0,f!==h.__[0]&&(u=!0)}}),r&&r.call(this,l,a,d)||u};U.__f=!0;var r=U.shouldComponentUpdate,s=U.componentWillUpdate;U.componentWillUpdate=function(l,a,d){if(this.__e){var m=r;r=void 0,n(l,a,d),r=m}s&&s.call(this,l,a,d)},U.shouldComponentUpdate=n}return i.__N||i.__}function ue(e,t){var o=st(ce++,3);!q.__s&&dn(o.__H,t)&&(o.__=e,o.u=t,U.__H.__h.push(o))}function un(e){return xe=5,Tn(function(){return{current:e}},[])}function Tn(e,t){var o=st(ce++,7);return dn(o.__H,t)&&(o.__=e(),o.__H=t,o.__h=e),o.__}function An(){for(var e;e=cn.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(ye),t.__h.some(et),t.__h=[]}catch(o){t.__h=[],q.__e(o,e.__v)}}}q.__b=function(e){U=null,ht&&ht(e)},q.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),yt&&yt(e,t)},q.__r=function(e){mt&&mt(e),ce=0;var t=(U=e.__c).__H;t&&(Se===U?(t.__h=[],U.__h=[],t.__.some(function(o){o.__N&&(o.__=o.__N),o.u=o.__N=void 0})):(t.__h.some(ye),t.__h.some(et),t.__h=[],ce=0)),Se=U},q.diffed=function(e){_t&&_t(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(cn.push(t)!==1&&ft===q.requestAnimationFrame||((ft=q.requestAnimationFrame)||Rn)(An)),t.__H.__.some(function(o){o.u&&(o.__H=o.u),o.u=void 0})),Se=U=null},q.__c=function(e,t){t.some(function(o){try{o.__h.some(ye),o.__h=o.__h.filter(function(i){return!i.__||et(i)})}catch(i){t.some(function(n){n.__h&&(n.__h=[])}),t=[],q.__e(i,o.__v)}}),pt&&pt(e,t)},q.unmount=function(e){gt&&gt(e);var t,o=e.__c;o&&o.__H&&(o.__H.__.some(function(i){try{ye(i)}catch(n){t=n}}),o.__H=void 0,t&&q.__e(t,o.__v))};var vt=typeof requestAnimationFrame=="function";function Rn(e){var t,o=function(){clearTimeout(i),vt&&cancelAnimationFrame(t),setTimeout(e)},i=setTimeout(o,35);vt&&(t=requestAnimationFrame(o))}function ye(e){var t=U,o=e.__c;typeof o=="function"&&(e.__c=void 0,o()),U=t}function et(e){var t=U;e.__c=e.__(),U=t}function dn(e,t){return!e||e.length!==t.length||t.some(function(o,i){return o!==e[i]})}function fn(e,t){return typeof t=="function"?t(e):t}const Pn=[{icon:"download",label:"Preparing",desc:"Checking tunnel binary"},{icon:"cloud_sync",label:"Connecting",desc:"Creating session"},{icon:"lan",label:"Tunneling",desc:"Starting secure tunnel"},{icon:"verified",label:"Verifying",desc:"Health check"},{icon:"check_circle",label:"Ready",desc:"Connected"}],In=3;function Bn({currentStep:e,activeDesc:t="",healthCheck:o}){var r;const i=e-1,n=(r=o==null?void 0:o.logs)!=null&&r.length?o.logs[o.logs.length-1]:null;return c("div",{className:"glass-card p-5 flex flex-col gap-4",children:[c("span",{className:"text-xs font-medium uppercase tracking-wider",style:{color:"var(--text-muted)"},children:"Setting up connection"}),c("div",{className:"flex flex-col gap-3",children:Pn.map((s,l)=>{const a=l<i,d=l===i,m=d&&l===In;let u=d&&t?t:s.desc,h="var(--text-muted)";if(m&&n){const f=/^\d{3}$/.test(String(n.status));u=`#${n.attempt} → ${n.status}`,h=n.ok||n.waiting?"#22c55e":f?"#eab308":"#ef4444"}return c("div",{className:"flex items-center gap-3",children:[c("div",{className:"w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0",style:{background:a?"var(--brand-500)":d?"rgba(255,87,10,0.15)":"var(--glass-bg)",border:d?"1.5px solid var(--brand-500)":"1.5px solid transparent"},children:a?c("span",{className:"material-symbols-outlined text-white",style:{fontSize:16},children:"check"}):d?c("span",{className:"flex gap-0.5 items-center",children:[0,1,2].map(f=>c("span",{className:"w-1 h-1 rounded-full bg-orange-400 dot-bounce",style:{animationDelay:`${f*.18}s`}},f))}):c("span",{className:"material-symbols-outlined",style:{fontSize:16,color:"var(--text-muted)",opacity:.3},children:s.icon})}),c("div",{className:"flex-1 min-w-0",children:[c("p",{className:"text-sm font-medium",style:{color:a?"var(--text-muted)":d?"var(--text-main)":"var(--text-muted)",opacity:a||d?1:.4},children:s.label}),c("p",{className:"text-xs mt-0.5 truncate",style:{color:h,opacity:d?m&&n?.95:.7:.4,fontFamily:m&&n?"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace":void 0},children:u})]}),a&&c("span",{className:"text-xs flex-shrink-0",style:{color:"var(--text-muted)"},children:"Done"}),d&&c("span",{className:"text-xs flex-shrink-0 px-2 py-0.5 rounded-full",style:{background:"rgba(255,87,10,0.15)",color:"var(--brand-400)"},children:"Running"})]},l)})})]})}function Mn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ne={},Ee,bt;function Dn(){return bt||(bt=1,Ee=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),Ee}var Te={},W={},wt;function ee(){if(wt)return W;wt=1;let e;const t=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return W.getSymbolSize=function(i){if(!i)throw new Error('"version" cannot be null or undefined');if(i<1||i>40)throw new Error('"version" should be in range from 1 to 40');return i*4+17},W.getSymbolTotalCodewords=function(i){return t[i]},W.getBCHDigit=function(o){let i=0;for(;o!==0;)i++,o>>>=1;return i},W.setToSJISFunction=function(i){if(typeof i!="function")throw new Error('"toSJISFunc" is not a valid function.');e=i},W.isKanjiModeEnabled=function(){return typeof e<"u"},W.toSJIS=function(i){return e(i)},W}var Ae={},xt;function lt(){return xt||(xt=1,(function(e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.toLowerCase()){case"l":case"low":return e.L;case"m":case"medium":return e.M;case"q":case"quartile":return e.Q;case"h":case"high":return e.H;default:throw new Error("Unknown EC Level: "+o)}}e.isValid=function(i){return i&&typeof i.bit<"u"&&i.bit>=0&&i.bit<4},e.from=function(i,n){if(e.isValid(i))return i;try{return t(i)}catch{return n}}})(Ae)),Ae}var Re,Nt;function Ln(){if(Nt)return Re;Nt=1;function e(){this.buffer=[],this.length=0}return e.prototype={get:function(t){const o=Math.floor(t/8);return(this.buffer[o]>>>7-t%8&1)===1},put:function(t,o){for(let i=0;i<o;i++)this.putBit((t>>>o-i-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(t){const o=Math.floor(this.length/8);this.buffer.length<=o&&this.buffer.push(0),t&&(this.buffer[o]|=128>>>this.length%8),this.length++}},Re=e,Re}var Pe,Ct;function Un(){if(Ct)return Pe;Ct=1;function e(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}return e.prototype.set=function(t,o,i,n){const r=t*this.size+o;this.data[r]=i,n&&(this.reservedBit[r]=!0)},e.prototype.get=function(t,o){return this.data[t*this.size+o]},e.prototype.xor=function(t,o,i){this.data[t*this.size+o]^=i},e.prototype.isReserved=function(t,o){return this.reservedBit[t*this.size+o]},Pe=e,Pe}var Ie={},kt;function qn(){return kt||(kt=1,(function(e){const t=ee().getSymbolSize;e.getRowColCoords=function(i){if(i===1)return[];const n=Math.floor(i/7)+2,r=t(i),s=r===145?26:Math.ceil((r-13)/(2*n-2))*2,l=[r-7];for(let a=1;a<n-1;a++)l[a]=l[a-1]-s;return l.push(6),l.reverse()},e.getPositions=function(i){const n=[],r=e.getRowColCoords(i),s=r.length;for(let l=0;l<s;l++)for(let a=0;a<s;a++)l===0&&a===0||l===0&&a===s-1||l===s-1&&a===0||n.push([r[l],r[a]]);return n}})(Ie)),Ie}var Be={},St;function Fn(){if(St)return Be;St=1;const e=ee().getSymbolSize,t=7;return Be.getPositions=function(i){const n=e(i);return[[0,0],[n-t,0],[0,n-t]]},Be}var Me={},Et;function jn(){return Et||(Et=1,(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(n){return n!=null&&n!==""&&!isNaN(n)&&n>=0&&n<=7},e.from=function(n){return e.isValid(n)?parseInt(n,10):void 0},e.getPenaltyN1=function(n){const r=n.size;let s=0,l=0,a=0,d=null,m=null;for(let u=0;u<r;u++){l=a=0,d=m=null;for(let h=0;h<r;h++){let f=n.get(u,h);f===d?l++:(l>=5&&(s+=t.N1+(l-5)),d=f,l=1),f=n.get(h,u),f===m?a++:(a>=5&&(s+=t.N1+(a-5)),m=f,a=1)}l>=5&&(s+=t.N1+(l-5)),a>=5&&(s+=t.N1+(a-5))}return s},e.getPenaltyN2=function(n){const r=n.size;let s=0;for(let l=0;l<r-1;l++)for(let a=0;a<r-1;a++){const d=n.get(l,a)+n.get(l,a+1)+n.get(l+1,a)+n.get(l+1,a+1);(d===4||d===0)&&s++}return s*t.N2},e.getPenaltyN3=function(n){const r=n.size;let s=0,l=0,a=0;for(let d=0;d<r;d++){l=a=0;for(let m=0;m<r;m++)l=l<<1&2047|n.get(d,m),m>=10&&(l===1488||l===93)&&s++,a=a<<1&2047|n.get(m,d),m>=10&&(a===1488||a===93)&&s++}return s*t.N3},e.getPenaltyN4=function(n){let r=0;const s=n.data.length;for(let a=0;a<s;a++)r+=n.data[a];return Math.abs(Math.ceil(r*100/s/5)-10)*t.N4};function o(i,n,r){switch(i){case e.Patterns.PATTERN000:return(n+r)%2===0;case e.Patterns.PATTERN001:return n%2===0;case e.Patterns.PATTERN010:return r%3===0;case e.Patterns.PATTERN011:return(n+r)%3===0;case e.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2===0;case e.Patterns.PATTERN101:return n*r%2+n*r%3===0;case e.Patterns.PATTERN110:return(n*r%2+n*r%3)%2===0;case e.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2===0;default:throw new Error("bad maskPattern:"+i)}}e.applyMask=function(n,r){const s=r.size;for(let l=0;l<s;l++)for(let a=0;a<s;a++)r.isReserved(a,l)||r.xor(a,l,o(n,a,l))},e.getBestMask=function(n,r){const s=Object.keys(e.Patterns).length;let l=0,a=1/0;for(let d=0;d<s;d++){r(d),e.applyMask(d,n);const m=e.getPenaltyN1(n)+e.getPenaltyN2(n)+e.getPenaltyN3(n)+e.getPenaltyN4(n);e.applyMask(d,n),m<a&&(a=m,l=d)}return l}})(Me)),Me}var he={},Tt;function hn(){if(Tt)return he;Tt=1;const e=lt(),t=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],o=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return he.getBlocksCount=function(n,r){switch(r){case e.L:return t[(n-1)*4+0];case e.M:return t[(n-1)*4+1];case e.Q:return t[(n-1)*4+2];case e.H:return t[(n-1)*4+3];default:return}},he.getTotalCodewordsCount=function(n,r){switch(r){case e.L:return o[(n-1)*4+0];case e.M:return o[(n-1)*4+1];case e.Q:return o[(n-1)*4+2];case e.H:return o[(n-1)*4+3];default:return}},he}var De={},se={},At;function On(){if(At)return se;At=1;const e=new Uint8Array(512),t=new Uint8Array(256);return(function(){let i=1;for(let n=0;n<255;n++)e[n]=i,t[i]=n,i<<=1,i&256&&(i^=285);for(let n=255;n<512;n++)e[n]=e[n-255]})(),se.log=function(i){if(i<1)throw new Error("log("+i+")");return t[i]},se.exp=function(i){return e[i]},se.mul=function(i,n){return i===0||n===0?0:e[t[i]+t[n]]},se}var Rt;function Hn(){return Rt||(Rt=1,(function(e){const t=On();e.mul=function(i,n){const r=new Uint8Array(i.length+n.length-1);for(let s=0;s<i.length;s++)for(let l=0;l<n.length;l++)r[s+l]^=t.mul(i[s],n[l]);return r},e.mod=function(i,n){let r=new Uint8Array(i);for(;r.length-n.length>=0;){const s=r[0];for(let a=0;a<n.length;a++)r[a]^=t.mul(n[a],s);let l=0;for(;l<r.length&&r[l]===0;)l++;r=r.slice(l)}return r},e.generateECPolynomial=function(i){let n=new Uint8Array([1]);for(let r=0;r<i;r++)n=e.mul(n,new Uint8Array([1,t.exp(r)]));return n}})(De)),De}var Le,Pt;function zn(){if(Pt)return Le;Pt=1;const e=Hn();function t(o){this.genPoly=void 0,this.degree=o,this.degree&&this.initialize(this.degree)}return t.prototype.initialize=function(i){this.degree=i,this.genPoly=e.generateECPolynomial(this.degree)},t.prototype.encode=function(i){if(!this.genPoly)throw new Error("Encoder not initialized");const n=new Uint8Array(i.length+this.degree);n.set(i);const r=e.mod(n,this.genPoly),s=this.degree-r.length;if(s>0){const l=new Uint8Array(this.degree);return l.set(r,s),l}return r},Le=t,Le}var Ue={},qe={},Fe={},It;function mn(){return It||(It=1,Fe.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40}),Fe}var K={},Bt;function _n(){if(Bt)return K;Bt=1;const e="[0-9]+",t="[A-Z $%*+\\-./:]+";let o="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";o=o.replace(/u/g,"\\u");const i="(?:(?![A-Z0-9 $%*+\\-./:]|"+o+`)(?:.|[\r
2
- ]))+`;K.KANJI=new RegExp(o,"g"),K.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),K.BYTE=new RegExp(i,"g"),K.NUMERIC=new RegExp(e,"g"),K.ALPHANUMERIC=new RegExp(t,"g");const n=new RegExp("^"+o+"$"),r=new RegExp("^"+e+"$"),s=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return K.testKanji=function(a){return n.test(a)},K.testNumeric=function(a){return r.test(a)},K.testAlphanumeric=function(a){return s.test(a)},K}var Mt;function te(){return Mt||(Mt=1,(function(e){const t=mn(),o=_n();e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(r,s){if(!r.ccBits)throw new Error("Invalid mode: "+r);if(!t.isValid(s))throw new Error("Invalid version: "+s);return s>=1&&s<10?r.ccBits[0]:s<27?r.ccBits[1]:r.ccBits[2]},e.getBestModeForData=function(r){return o.testNumeric(r)?e.NUMERIC:o.testAlphanumeric(r)?e.ALPHANUMERIC:o.testKanji(r)?e.KANJI:e.BYTE},e.toString=function(r){if(r&&r.id)return r.id;throw new Error("Invalid mode")},e.isValid=function(r){return r&&r.bit&&r.ccBits};function i(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+n)}}e.from=function(r,s){if(e.isValid(r))return r;try{return i(r)}catch{return s}}})(qe)),qe}var Dt;function Kn(){return Dt||(Dt=1,(function(e){const t=ee(),o=hn(),i=lt(),n=te(),r=mn(),s=7973,l=t.getBCHDigit(s);function a(h,f,g){for(let x=1;x<=40;x++)if(f<=e.getCapacity(x,g,h))return x}function d(h,f){return n.getCharCountIndicator(h,f)+4}function m(h,f){let g=0;return h.forEach(function(x){const I=d(x.mode,f);g+=I+x.getBitsLength()}),g}function u(h,f){for(let g=1;g<=40;g++)if(m(h,g)<=e.getCapacity(g,f,n.MIXED))return g}e.from=function(f,g){return r.isValid(f)?parseInt(f,10):g},e.getCapacity=function(f,g,x){if(!r.isValid(f))throw new Error("Invalid QR Code version");typeof x>"u"&&(x=n.BYTE);const I=t.getSymbolTotalCodewords(f),_=o.getTotalCodewordsCount(f,g),y=(I-_)*8;if(x===n.MIXED)return y;const C=y-d(x,f);switch(x){case n.NUMERIC:return Math.floor(C/10*3);case n.ALPHANUMERIC:return Math.floor(C/11*2);case n.KANJI:return Math.floor(C/13);case n.BYTE:default:return Math.floor(C/8)}},e.getBestVersionForData=function(f,g){let x;const I=i.from(g,i.M);if(Array.isArray(f)){if(f.length>1)return u(f,I);if(f.length===0)return 1;x=f[0]}else x=f;return a(x.mode,x.getLength(),I)},e.getEncodedBits=function(f){if(!r.isValid(f)||f<7)throw new Error("Invalid QR Code version");let g=f<<12;for(;t.getBCHDigit(g)-l>=0;)g^=s<<t.getBCHDigit(g)-l;return f<<12|g}})(Ue)),Ue}var je={},Lt;function Vn(){if(Lt)return je;Lt=1;const e=ee(),t=1335,o=21522,i=e.getBCHDigit(t);return je.getEncodedBits=function(r,s){const l=r.bit<<3|s;let a=l<<10;for(;e.getBCHDigit(a)-i>=0;)a^=t<<e.getBCHDigit(a)-i;return(l<<10|a)^o},je}var Oe={},He,Ut;function Jn(){if(Ut)return He;Ut=1;const e=te();function t(o){this.mode=e.NUMERIC,this.data=o.toString()}return t.getBitsLength=function(i){return 10*Math.floor(i/3)+(i%3?i%3*3+1:0)},t.prototype.getLength=function(){return this.data.length},t.prototype.getBitsLength=function(){return t.getBitsLength(this.data.length)},t.prototype.write=function(i){let n,r,s;for(n=0;n+3<=this.data.length;n+=3)r=this.data.substr(n,3),s=parseInt(r,10),i.put(s,10);const l=this.data.length-n;l>0&&(r=this.data.substr(n),s=parseInt(r,10),i.put(s,l*3+1))},He=t,He}var ze,qt;function Yn(){if(qt)return ze;qt=1;const e=te(),t=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function o(i){this.mode=e.ALPHANUMERIC,this.data=i}return o.getBitsLength=function(n){return 11*Math.floor(n/2)+6*(n%2)},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(n){let r;for(r=0;r+2<=this.data.length;r+=2){let s=t.indexOf(this.data[r])*45;s+=t.indexOf(this.data[r+1]),n.put(s,11)}this.data.length%2&&n.put(t.indexOf(this.data[r]),6)},ze=o,ze}var Ke,Ft;function Gn(){if(Ft)return Ke;Ft=1;const e=te();function t(o){this.mode=e.BYTE,typeof o=="string"?this.data=new TextEncoder().encode(o):this.data=new Uint8Array(o)}return t.getBitsLength=function(i){return i*8},t.prototype.getLength=function(){return this.data.length},t.prototype.getBitsLength=function(){return t.getBitsLength(this.data.length)},t.prototype.write=function(o){for(let i=0,n=this.data.length;i<n;i++)o.put(this.data[i],8)},Ke=t,Ke}var Ve,jt;function Qn(){if(jt)return Ve;jt=1;const e=te(),t=ee();function o(i){this.mode=e.KANJI,this.data=i}return o.getBitsLength=function(n){return n*13},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(i){let n;for(n=0;n<this.data.length;n++){let r=t.toSJIS(this.data[n]);if(r>=33088&&r<=40956)r-=33088;else if(r>=57408&&r<=60351)r-=49472;else throw new Error("Invalid SJIS character: "+this.data[n]+`
3
- Make sure your charset is UTF-8`);r=(r>>>8&255)*192+(r&255),i.put(r,13)}},Ve=o,Ve}var Je={exports:{}},Ot;function Wn(){return Ot||(Ot=1,(function(e){var t={single_source_shortest_paths:function(o,i,n){var r={},s={};s[i]=0;var l=t.PriorityQueue.make();l.push(i,0);for(var a,d,m,u,h,f,g,x,I;!l.empty();){a=l.pop(),d=a.value,u=a.cost,h=o[d]||{};for(m in h)h.hasOwnProperty(m)&&(f=h[m],g=u+f,x=s[m],I=typeof s[m]>"u",(I||x>g)&&(s[m]=g,l.push(m,g),r[m]=d))}if(typeof n<"u"&&typeof s[n]>"u"){var _=["Could not find a path from ",i," to ",n,"."].join("");throw new Error(_)}return r},extract_shortest_path_from_predecessor_list:function(o,i){for(var n=[],r=i;r;)n.push(r),o[r],r=o[r];return n.reverse(),n},find_path:function(o,i,n){var r=t.single_source_shortest_paths(o,i,n);return t.extract_shortest_path_from_predecessor_list(r,n)},PriorityQueue:{make:function(o){var i=t.PriorityQueue,n={},r;o=o||{};for(r in i)i.hasOwnProperty(r)&&(n[r]=i[r]);return n.queue=[],n.sorter=o.sorter||i.default_sorter,n},default_sorter:function(o,i){return o.cost-i.cost},push:function(o,i){var n={value:o,cost:i};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=t})(Je)),Je.exports}var Ht;function Xn(){return Ht||(Ht=1,(function(e){const t=te(),o=Jn(),i=Yn(),n=Gn(),r=Qn(),s=_n(),l=ee(),a=Wn();function d(_){return unescape(encodeURIComponent(_)).length}function m(_,y,C){const v=[];let M;for(;(M=_.exec(C))!==null;)v.push({data:M[0],index:M.index,mode:y,length:M[0].length});return v}function u(_){const y=m(s.NUMERIC,t.NUMERIC,_),C=m(s.ALPHANUMERIC,t.ALPHANUMERIC,_);let v,M;return l.isKanjiModeEnabled()?(v=m(s.BYTE,t.BYTE,_),M=m(s.KANJI,t.KANJI,_)):(v=m(s.BYTE_KANJI,t.BYTE,_),M=[]),y.concat(C,v,M).sort(function(N,k){return N.index-k.index}).map(function(N){return{data:N.data,mode:N.mode,length:N.length}})}function h(_,y){switch(y){case t.NUMERIC:return o.getBitsLength(_);case t.ALPHANUMERIC:return i.getBitsLength(_);case t.KANJI:return r.getBitsLength(_);case t.BYTE:return n.getBitsLength(_)}}function f(_){return _.reduce(function(y,C){const v=y.length-1>=0?y[y.length-1]:null;return v&&v.mode===C.mode?(y[y.length-1].data+=C.data,y):(y.push(C),y)},[])}function g(_){const y=[];for(let C=0;C<_.length;C++){const v=_[C];switch(v.mode){case t.NUMERIC:y.push([v,{data:v.data,mode:t.ALPHANUMERIC,length:v.length},{data:v.data,mode:t.BYTE,length:v.length}]);break;case t.ALPHANUMERIC:y.push([v,{data:v.data,mode:t.BYTE,length:v.length}]);break;case t.KANJI:y.push([v,{data:v.data,mode:t.BYTE,length:d(v.data)}]);break;case t.BYTE:y.push([{data:v.data,mode:t.BYTE,length:d(v.data)}])}}return y}function x(_,y){const C={},v={start:{}};let M=["start"];for(let b=0;b<_.length;b++){const N=_[b],k=[];for(let p=0;p<N.length;p++){const S=N[p],E=""+b+p;k.push(E),C[E]={node:S,lastCount:0},v[E]={};for(let T=0;T<M.length;T++){const w=M[T];C[w]&&C[w].node.mode===S.mode?(v[w][E]=h(C[w].lastCount+S.length,S.mode)-h(C[w].lastCount,S.mode),C[w].lastCount+=S.length):(C[w]&&(C[w].lastCount=S.length),v[w][E]=h(S.length,S.mode)+4+t.getCharCountIndicator(S.mode,y))}}M=k}for(let b=0;b<M.length;b++)v[M[b]].end=0;return{map:v,table:C}}function I(_,y){let C;const v=t.getBestModeForData(_);if(C=t.from(y,v),C!==t.BYTE&&C.bit<v.bit)throw new Error('"'+_+'" cannot be encoded with mode '+t.toString(C)+`.
4
- Suggested mode is: `+t.toString(v));switch(C===t.KANJI&&!l.isKanjiModeEnabled()&&(C=t.BYTE),C){case t.NUMERIC:return new o(_);case t.ALPHANUMERIC:return new i(_);case t.KANJI:return new r(_);case t.BYTE:return new n(_)}}e.fromArray=function(y){return y.reduce(function(C,v){return typeof v=="string"?C.push(I(v,null)):v.data&&C.push(I(v.data,v.mode)),C},[])},e.fromString=function(y,C){const v=u(y,l.isKanjiModeEnabled()),M=g(v),b=x(M,C),N=a.find_path(b.map,"start","end"),k=[];for(let p=1;p<N.length-1;p++)k.push(b.table[N[p]].node);return e.fromArray(f(k))},e.rawSplit=function(y){return e.fromArray(u(y,l.isKanjiModeEnabled()))}})(Oe)),Oe}var zt;function Zn(){if(zt)return Te;zt=1;const e=ee(),t=lt(),o=Ln(),i=Un(),n=qn(),r=Fn(),s=jn(),l=hn(),a=zn(),d=Kn(),m=Vn(),u=te(),h=Xn();function f(b,N){const k=b.size,p=r.getPositions(N);for(let S=0;S<p.length;S++){const E=p[S][0],T=p[S][1];for(let w=-1;w<=7;w++)if(!(E+w<=-1||k<=E+w))for(let P=-1;P<=7;P++)T+P<=-1||k<=T+P||(w>=0&&w<=6&&(P===0||P===6)||P>=0&&P<=6&&(w===0||w===6)||w>=2&&w<=4&&P>=2&&P<=4?b.set(E+w,T+P,!0,!0):b.set(E+w,T+P,!1,!0))}}function g(b){const N=b.size;for(let k=8;k<N-8;k++){const p=k%2===0;b.set(k,6,p,!0),b.set(6,k,p,!0)}}function x(b,N){const k=n.getPositions(N);for(let p=0;p<k.length;p++){const S=k[p][0],E=k[p][1];for(let T=-2;T<=2;T++)for(let w=-2;w<=2;w++)T===-2||T===2||w===-2||w===2||T===0&&w===0?b.set(S+T,E+w,!0,!0):b.set(S+T,E+w,!1,!0)}}function I(b,N){const k=b.size,p=d.getEncodedBits(N);let S,E,T;for(let w=0;w<18;w++)S=Math.floor(w/3),E=w%3+k-8-3,T=(p>>w&1)===1,b.set(S,E,T,!0),b.set(E,S,T,!0)}function _(b,N,k){const p=b.size,S=m.getEncodedBits(N,k);let E,T;for(E=0;E<15;E++)T=(S>>E&1)===1,E<6?b.set(E,8,T,!0):E<8?b.set(E+1,8,T,!0):b.set(p-15+E,8,T,!0),E<8?b.set(8,p-E-1,T,!0):E<9?b.set(8,15-E-1+1,T,!0):b.set(8,15-E-1,T,!0);b.set(p-8,8,1,!0)}function y(b,N){const k=b.size;let p=-1,S=k-1,E=7,T=0;for(let w=k-1;w>0;w-=2)for(w===6&&w--;;){for(let P=0;P<2;P++)if(!b.isReserved(S,w-P)){let j=!1;T<N.length&&(j=(N[T]>>>E&1)===1),b.set(S,w-P,j),E--,E===-1&&(T++,E=7)}if(S+=p,S<0||k<=S){S-=p,p=-p;break}}}function C(b,N,k){const p=new o;k.forEach(function(P){p.put(P.mode.bit,4),p.put(P.getLength(),u.getCharCountIndicator(P.mode,b)),P.write(p)});const S=e.getSymbolTotalCodewords(b),E=l.getTotalCodewordsCount(b,N),T=(S-E)*8;for(p.getLengthInBits()+4<=T&&p.put(0,4);p.getLengthInBits()%8!==0;)p.putBit(0);const w=(T-p.getLengthInBits())/8;for(let P=0;P<w;P++)p.put(P%2?17:236,8);return v(p,b,N)}function v(b,N,k){const p=e.getSymbolTotalCodewords(N),S=l.getTotalCodewordsCount(N,k),E=p-S,T=l.getBlocksCount(N,k),w=p%T,P=T-w,j=Math.floor(p/T),V=Math.floor(E/T),oe=V+1,Y=j-V,B=new a(Y);let R=0;const A=new Array(T),G=new Array(T);let z=0;const de=new Uint8Array(b.buffer);for(let L=0;L<T;L++){const $=L<P?V:oe;A[L]=de.slice(R,R+$),G[L]=B.encode(A[L]),R+=$,z=Math.max(z,$)}const ie=new Uint8Array(p);let Q=0,H,O;for(H=0;H<z;H++)for(O=0;O<T;O++)H<A[O].length&&(ie[Q++]=A[O][H]);for(H=0;H<Y;H++)for(O=0;O<T;O++)ie[Q++]=G[O][H];return ie}function M(b,N,k,p){let S;if(Array.isArray(b))S=h.fromArray(b);else if(typeof b=="string"){let j=N;if(!j){const V=h.rawSplit(b);j=d.getBestVersionForData(V,k)}S=h.fromString(b,j||40)}else throw new Error("Invalid data");const E=d.getBestVersionForData(S,k);if(!E)throw new Error("The amount of data is too big to be stored in a QR Code");if(!N)N=E;else if(N<E)throw new Error(`
5
- The chosen QR Code version cannot contain this amount of data.
6
- Minimum version required to store current data is: `+E+`.
7
- `);const T=C(N,k,S),w=e.getSymbolSize(N),P=new i(w);return f(P,N),g(P),x(P,N),_(P,k,0),N>=7&&I(P,N),y(P,T),isNaN(p)&&(p=s.getBestMask(P,_.bind(null,P,k))),s.applyMask(p,P),_(P,k,p),{modules:P,version:N,errorCorrectionLevel:k,maskPattern:p,segments:S}}return Te.create=function(N,k){if(typeof N>"u"||N==="")throw new Error("No input text");let p=t.M,S,E;return typeof k<"u"&&(p=t.from(k.errorCorrectionLevel,t.M),S=d.from(k.version),E=s.from(k.maskPattern),k.toSJISFunc&&e.setToSJISFunction(k.toSJISFunc)),M(N,S,p,E)},Te}var Ye={},Ge={},Kt;function pn(){return Kt||(Kt=1,(function(e){function t(o){if(typeof o=="number"&&(o=o.toString()),typeof o!="string")throw new Error("Color should be defined as hex string");let i=o.slice().replace("#","").split("");if(i.length<3||i.length===5||i.length>8)throw new Error("Invalid hex color: "+o);(i.length===3||i.length===4)&&(i=Array.prototype.concat.apply([],i.map(function(r){return[r,r]}))),i.length===6&&i.push("F","F");const n=parseInt(i.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:n&255,hex:"#"+i.slice(0,6).join("")}}e.getOptions=function(i){i||(i={}),i.color||(i.color={});const n=typeof i.margin>"u"||i.margin===null||i.margin<0?4:i.margin,r=i.width&&i.width>=21?i.width:void 0,s=i.scale||4;return{width:r,scale:r?4:s,margin:n,color:{dark:t(i.color.dark||"#000000ff"),light:t(i.color.light||"#ffffffff")},type:i.type,rendererOpts:i.rendererOpts||{}}},e.getScale=function(i,n){return n.width&&n.width>=i+n.margin*2?n.width/(i+n.margin*2):n.scale},e.getImageWidth=function(i,n){const r=e.getScale(i,n);return Math.floor((i+n.margin*2)*r)},e.qrToImageData=function(i,n,r){const s=n.modules.size,l=n.modules.data,a=e.getScale(s,r),d=Math.floor((s+r.margin*2)*a),m=r.margin*a,u=[r.color.light,r.color.dark];for(let h=0;h<d;h++)for(let f=0;f<d;f++){let g=(h*d+f)*4,x=r.color.light;if(h>=m&&f>=m&&h<d-m&&f<d-m){const I=Math.floor((h-m)/a),_=Math.floor((f-m)/a);x=u[l[I*s+_]?1:0]}i[g++]=x.r,i[g++]=x.g,i[g++]=x.b,i[g]=x.a}}})(Ge)),Ge}var Vt;function $n(){return Vt||(Vt=1,(function(e){const t=pn();function o(n,r,s){n.clearRect(0,0,r.width,r.height),r.style||(r.style={}),r.height=s,r.width=s,r.style.height=s+"px",r.style.width=s+"px"}function i(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}e.render=function(r,s,l){let a=l,d=s;typeof a>"u"&&(!s||!s.getContext)&&(a=s,s=void 0),s||(d=i()),a=t.getOptions(a);const m=t.getImageWidth(r.modules.size,a),u=d.getContext("2d"),h=u.createImageData(m,m);return t.qrToImageData(h.data,r,a),o(u,d,m),u.putImageData(h,0,0),d},e.renderToDataURL=function(r,s,l){let a=l;typeof a>"u"&&(!s||!s.getContext)&&(a=s,s=void 0),a||(a={});const d=e.render(r,s,a),m=a.type||"image/png",u=a.rendererOpts||{};return d.toDataURL(m,u.quality)}})(Ye)),Ye}var Qe={},Jt;function er(){if(Jt)return Qe;Jt=1;const e=pn();function t(n,r){const s=n.a/255,l=r+'="'+n.hex+'"';return s<1?l+" "+r+'-opacity="'+s.toFixed(2).slice(1)+'"':l}function o(n,r,s){let l=n+r;return typeof s<"u"&&(l+=" "+s),l}function i(n,r,s){let l="",a=0,d=!1,m=0;for(let u=0;u<n.length;u++){const h=Math.floor(u%r),f=Math.floor(u/r);!h&&!d&&(d=!0),n[u]?(m++,u>0&&h>0&&n[u-1]||(l+=d?o("M",h+s,.5+f+s):o("m",a,0),a=0,d=!1),h+1<r&&n[u+1]||(l+=o("h",m),m=0)):a++}return l}return Qe.render=function(r,s,l){const a=e.getOptions(s),d=r.modules.size,m=r.modules.data,u=d+a.margin*2,h=a.color.light.a?"<path "+t(a.color.light,"fill")+' d="M0 0h'+u+"v"+u+'H0z"/>':"",f="<path "+t(a.color.dark,"stroke")+' d="'+i(m,d,a.margin)+'"/>',g='viewBox="0 0 '+u+" "+u+'"',I='<svg xmlns="http://www.w3.org/2000/svg" '+(a.width?'width="'+a.width+'" height="'+a.width+'" ':"")+g+' shape-rendering="crispEdges">'+h+f+`</svg>
8
- `;return typeof l=="function"&&l(null,I),I},Qe}var Yt;function tr(){if(Yt)return ne;Yt=1;const e=Dn(),t=Zn(),o=$n(),i=er();function n(r,s,l,a,d){const m=[].slice.call(arguments,1),u=m.length,h=typeof m[u-1]=="function";if(!h&&!e())throw new Error("Callback required as last argument");if(h){if(u<2)throw new Error("Too few arguments provided");u===2?(d=l,l=s,s=a=void 0):u===3&&(s.getContext&&typeof d>"u"?(d=a,a=void 0):(d=a,a=l,l=s,s=void 0))}else{if(u<1)throw new Error("Too few arguments provided");return u===1?(l=s,s=a=void 0):u===2&&!s.getContext&&(a=l,l=s,s=void 0),new Promise(function(f,g){try{const x=t.create(l,a);f(r(x,s,a))}catch(x){g(x)}})}try{const f=t.create(l,a);d(null,r(f,s,a))}catch(f){d(f)}}return ne.create=t.create,ne.toCanvas=n.bind(null,o.render),ne.toDataURL=n.bind(null,o.renderToDataURL),ne.toString=n.bind(null,function(r,s,l){return i.render(r,l)}),ne}var nr=tr();const rr=Mn(nr);function ae({message:e,confirmLabel:t="Confirm",confirmDanger:o=!1,onConfirm:i,onCancel:n}){return c("div",{className:"fixed inset-0 z-50 flex items-center justify-center",style:{background:"rgba(0,0,0,0.6)"},children:c("div",{className:"glass-card p-5 flex flex-col gap-4 w-72",children:[c("p",{className:"text-sm text-center",style:{color:"var(--text-main)"},children:e}),c("div",{className:"flex gap-2",children:[c("button",{onClick:n,className:"glass-btn flex-1 py-2 text-sm",style:{color:"var(--text-muted)"},children:"Cancel"}),c("button",{onClick:i,className:"flex-1 py-2 text-sm font-semibold rounded-xl",style:{background:o?"rgba(220,53,69,0.8)":"var(--brand-500)",color:"#fff"},children:t})]})]})})}const Gt="9remote.cc";function or(e){if(e<=0)return"Expired";const t=Math.floor(e/1e3),o=Math.floor(t/60),i=t%60;return`${String(o).padStart(2,"0")}:${String(i).padStart(2,"0")}`}function me({icon:e,onClick:t,title:o,danger:i}){return c("button",{onClick:t,title:o,className:"glass-btn w-7 h-7 flex items-center justify-center flex-shrink-0",style:i?{color:"rgba(255,100,100,0.7)"}:{color:"var(--text-muted)"},children:c("span",{className:"material-symbols-outlined",style:{fontSize:15},children:e})})}function Qt({qrUrl:e,oneTimeKey:t,oneTimeKeyExpiresAt:o,permanentKey:i,onGenerateOneTimeKey:n,onRegenerateKey:r}){const s=un(null),[l,a]=F(null),[d,m]=F(null),[u,h]=F(null);ue(()=>{!e||!s.current||rr.toCanvas(s.current,e,{width:160,margin:1,color:{dark:"#0f1923",light:"#ffffff"}}).catch(()=>{})},[e]),ue(()=>{if(!o){a(null);return}const g=()=>a(o-Date.now());g();const x=setInterval(g,1e3);return()=>clearInterval(x)},[o]);const f=(g,x)=>{navigator.clipboard.writeText(g).catch(()=>{}),m(x),setTimeout(()=>m(null),2e3)};return c(Z,{children:[u==="oneTime"&&c(ae,{message:"Generate a new one-time key? The current one will expire immediately.",confirmLabel:"Generate",onConfirm:()=>{h(null),n==null||n()},onCancel:()=>h(null)}),u==="regen"&&c(ae,{message:"Regenerate permanent key? All existing sessions will be disconnected.",confirmLabel:"Regenerate",confirmDanger:!0,onConfirm:()=>{h(null),r==null||r()},onCancel:()=>h(null)}),c("div",{className:"glass-card p-5 flex flex-col items-center gap-4",children:[c("div",{className:"w-44 h-44 rounded-xl overflow-hidden bg-white p-2 flex items-center justify-center flex-shrink-0",children:e?c("canvas",{ref:s}):c("span",{className:"material-symbols-outlined text-gray-300 text-6xl",children:"qr_code_2"})}),c("div",{className:"flex flex-col items-center gap-1",children:[c("span",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Scan QR or open link to sign in"}),c("a",{href:`https://${Gt}/login`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 hover:underline transition-opacity",children:[c("span",{className:"w-2 h-2 rounded-full bg-green-400 flex-shrink-0"}),c("span",{className:"text-sm font-bold",style:{color:"var(--brand-500)"},children:[Gt,"/login"]}),c("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:14,color:"var(--brand-500)"},children:"open_in_new"})]})]}),c("div",{className:"w-full h-px",style:{background:"var(--border)"}}),c("div",{className:"w-full flex flex-col gap-1.5",children:[c("div",{className:"flex items-center justify-between px-0.5",children:[c("span",{className:"text-xs font-medium",style:{color:"var(--text-muted)"},children:"One-Time Key"}),c("span",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Single use · expires"})]}),c("div",{className:"w-full flex items-center gap-2 dark-card px-3 py-2.5",children:[c("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:16,color:"var(--text-muted)"},children:"timer"}),c("span",{className:"flex-1 font-mono font-bold tracking-[0.18em] text-base truncate",style:{color:t?"var(--brand-500)":"var(--border)"},children:t||"• • • • • •"}),l!==null&&c("span",{className:`text-xs font-mono flex-shrink-0 ${l<=0?"text-red-400":""}`,style:l>0?{color:"var(--text-muted)"}:{},children:or(l)}),t&&c(me,{icon:d==="oneTime"?"check":"content_copy",onClick:()=>f(t,"oneTime"),title:"Copy one-time key"}),c(me,{icon:"refresh",onClick:()=>h("oneTime"),title:"New one-time key"})]})]}),c("div",{className:"w-full flex flex-col gap-1.5",children:[c("div",{className:"flex items-center justify-between px-0.5",children:[c("span",{className:"text-xs font-medium",style:{color:"var(--text-muted)"},children:"Permanent Key"}),c("span",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Reusable · no expiry"})]}),c("div",{className:"w-full flex items-center gap-2 dark-card px-3 py-2.5",children:[c("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:16,color:"var(--text-muted)"},children:"key"}),c("span",{className:"flex-1 font-mono text-xs truncate",style:{color:"var(--text-muted)"},children:i||"— not set —"}),i&&c(me,{icon:d==="permanent"?"check":"content_copy",onClick:()=>f(i,"permanent"),title:"Copy permanent key"}),c(me,{icon:"autorenew",onClick:()=>h("regen"),title:"Regenerate permanent key",danger:!0})]})]})]})]})}const ir="https://docs.9remote.cc/",gn={screenRecording:{label:"Screen Recording",icon:"screenshot_monitor",desc:"Capture screen content"},accessibility:{label:"Accessibility",icon:"accessibility_new",desc:"Control mouse & keyboard"}};function sr({type:e,granted:t,onRequest:o}){const i=gn[e]||{label:e,desc:""};return c("div",{className:"flex items-center gap-3 py-2 border-b last:border-0",style:{borderColor:"var(--border)"},children:[c("span",{className:`material-symbols-outlined flex-shrink-0 ${t?"text-green-400":""}`,style:{fontSize:18,color:t?void 0:"var(--text-muted)"},children:t?"check_circle":"cancel"}),c("div",{className:"flex-1 min-w-0",children:[c("p",{className:"text-xs font-medium",style:{color:t?"var(--text-main)":"var(--text-muted)"},children:i.label}),c("p",{className:"text-[10px] leading-4",style:{color:"var(--text-muted)"},children:i.desc})]}),!t&&c("button",{onClick:()=>o(e),title:"Click to grant permission",className:"flex-shrink-0 w-11 h-6 rounded-full transition-all relative",style:{background:"var(--border)",cursor:"pointer"},children:c("span",{className:"absolute top-0.5 w-5 h-5 rounded-full bg-white transition-all",style:{left:"2px",boxShadow:"0 1px 3px rgba(0,0,0,0.3)"}})})]})}function lr({desktopEnabled:e,onDesktopToggle:t,permissions:o,onRequestPermission:i}){const n=Object.entries(gn),s=!n.every(([l])=>!!(o!=null&&o[l]))&&!e;return c("div",{className:"glass-card p-4 flex flex-col gap-3",children:[c("div",{className:"flex items-center gap-3",children:[c("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:"rgba(255,87,10,0.15)"},children:c("span",{className:"material-symbols-outlined",style:{fontSize:20,color:"var(--brand-400)"},children:"terminal"})}),c("div",{className:"flex-1 min-w-0",children:[c("p",{className:"text-sm font-semibold",style:{color:"var(--text-main)"},children:"Remote Terminal"}),c("p",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Full shell access · always on"})]}),c("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-full",style:{background:"rgba(74,222,128,0.1)"},children:[c("span",{className:"w-1.5 h-1.5 rounded-full bg-green-400"}),c("span",{className:"text-xs text-green-400 font-medium",children:"On"})]})]}),c("div",{className:"w-full h-px",style:{background:"var(--border)"}}),c("div",{className:"flex items-center gap-3",children:[c("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:e?"rgba(255,87,10,0.15)":"var(--glass-bg)"},children:c("span",{className:"material-symbols-outlined",style:{fontSize:20,color:e?"var(--brand-400)":"var(--text-muted)"},children:"desktop_windows"})}),c("div",{className:"flex-1 min-w-0",children:[c("p",{className:"text-sm font-semibold",style:{color:"var(--text-main)"},children:"Remote Desktop"}),c("p",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Control screen, mouse & keyboard"})]}),c("button",{onClick:s?void 0:t,disabled:s,title:s?"Grant all permissions below to enable":"",className:"flex-shrink-0 w-11 h-6 rounded-full transition-all relative",style:{background:e?"var(--brand-500)":"var(--border)",opacity:s?.5:1,cursor:s?"not-allowed":"pointer"},children:c("span",{className:"absolute top-0.5 w-5 h-5 rounded-full bg-white transition-all",style:{left:e?"calc(100% - 22px)":"2px",boxShadow:"0 1px 3px rgba(0,0,0,0.3)"}})})]}),c("div",{className:"flex flex-col border-t pt-2",style:{borderColor:"var(--border)"},children:[c("p",{className:"text-[10px] uppercase tracking-wider mb-1",style:{color:"var(--text-muted)"},children:"System Permissions"}),n.map(([l])=>c(sr,{type:l,granted:(o==null?void 0:o[l])??!1,onRequest:i},l))]})]})}function ar({version:e}){return e?c("div",{className:"px-5 py-2 flex items-center gap-2 border-b",style:{background:"rgba(255,87,10,0.08)",borderColor:"rgba(255,87,10,0.2)"},children:[c("span",{className:"material-symbols-outlined text-sm flex-shrink-0",style:{color:"var(--brand-400)"},children:"system_update"}),c("span",{className:"text-xs flex-1",style:{color:"var(--brand-400)"},children:["Version ",e," available"]}),c("button",{onClick:()=>fetch("/api/update",{method:"POST"}).catch(()=>{}),className:"flex-shrink-0 text-xs px-2 py-0.5 rounded font-medium",style:{background:"rgba(255,87,10,0.15)",color:"var(--brand-400)"},children:"Update"})]}):null}const cr=[{icon:"terminal",label:"Terminal",desc:"Full shell access"},{icon:"desktop_windows",label:"Desktop",desc:"Remote screen control"},{icon:"folder_open",label:"Files",desc:"Browse & edit files"}],ur=[{icon:"qr_code_scanner",text:"Scan QR to connect instantly"},{icon:"wifi_off",text:"No port forwarding needed"},{icon:"devices",text:"Works on any device"}];function dr({onStart:e}){const[t,o]=F(!1),i=()=>{o(!0),e()};return c("div",{className:"flex-1 flex flex-col items-center justify-between px-6 py-6 overflow-y-auto",children:[c("div",{className:"flex flex-col items-center gap-2 text-center mt-2",children:[c("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center mb-1",style:{background:"var(--brand-500)",boxShadow:"0 8px 32px rgba(255,87,10,0.35)"},children:c("span",{className:"material-symbols-outlined text-white",style:{fontSize:30},children:"terminal"})}),c("h1",{className:"text-lg font-bold tracking-tight",style:{color:"var(--text-main)"},children:"9Remote"}),c("p",{className:"text-xs leading-5 max-w-[220px]",style:{color:"var(--text-muted)"},children:"Access your terminal, desktop & files from anywhere"})]}),c("div",{className:"flex gap-2 w-full mt-5",children:cr.map(n=>c("div",{className:"flex-1 dark-card flex flex-col items-center gap-1.5 py-3 px-1",children:[c("span",{className:"material-symbols-outlined",style:{fontSize:22,color:"var(--brand-400)"},children:n.icon}),c("p",{className:"text-xs font-semibold",style:{color:"var(--text-main)"},children:n.label}),c("p",{className:"text-[10px] text-center leading-4",style:{color:"var(--text-muted)"},children:n.desc})]},n.label))}),c("div",{className:"flex flex-col gap-2 w-full mt-4",children:ur.map(n=>c("div",{className:"flex items-center gap-2.5",children:[c("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:16,color:"var(--brand-400)"},children:n.icon}),c("span",{className:"text-xs",style:{color:"var(--text-muted)"},children:n.text})]},n.text))}),c("button",{onClick:t?void 0:i,disabled:t,className:"btn-primary w-full py-3.5 flex items-center justify-center gap-2 text-sm font-semibold mt-6",style:{borderRadius:"var(--radius-brand)",opacity:t?.7:1},children:t?c(Z,{children:[c("span",{className:"flex gap-0.5 items-center",children:[0,1,2].map(n=>c("span",{className:"w-1.5 h-1.5 rounded-full bg-white dot-bounce",style:{animationDelay:`${n*.18}s`}},n))}),"Connecting..."]}):c(Z,{children:[c("span",{className:"material-symbols-outlined text-base",children:"play_arrow"}),"Connect"]})})]})}function fr(e,t,o=[]){const i=new Map;for(const l of t){if(!l.deviceId)continue;const a=i.get(l.deviceId);(!a||l.connectedAt&&l.connectedAt<a.connectedAt)&&i.set(l.deviceId,l)}const n=e.map(l=>{const a=i.get(l.deviceId);return{deviceId:l.deviceId,status:a?"online":"offline",ip:(a==null?void 0:a.ip)||null,connectedAt:(a==null?void 0:a.connectedAt)||null,approvedAt:l.approvedAt||null}}),r=o.map(l=>({deviceId:l.deviceId,status:"pending",ip:l.ip||null,connectedAt:null,approvedAt:null,rejectedAt:l.rejectedAt||null})),s={online:0,pending:1,offline:2};return[...n,...r].sort((l,a)=>s[l.status]-s[a.status])}const Wt={online:{color:"#4ade80",icon:"wifi",title:"Online"},offline:{color:"var(--text-muted)",icon:"wifi_off",title:"Offline"},pending:{color:"#f59e0b",icon:"hourglass_top",title:"Pending approval"}};function hr({client:e,onRemove:t,onApprove:o}){const i=`${e.deviceId.slice(0,8)}...`,n=Wt[e.status]||Wt.offline,r=e.status==="online"?`Connected · ${e.connectedAt?new Date(e.connectedAt).toLocaleTimeString():""}`:e.status==="pending"?"Pending · waiting for approval":e.approvedAt?`Offline · approved ${new Date(e.approvedAt).toLocaleDateString()}`:"Offline",s=e.status==="online"?"Disconnect":"Remove";return c("div",{className:"flex items-center gap-3 py-2 border-b last:border-0",style:{borderColor:"var(--border)"},children:[c("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:18,color:n.color},title:n.title,children:n.icon}),c("div",{className:"flex-1 min-w-0",children:[c("p",{className:"text-xs font-medium font-mono truncate",style:{color:"var(--text-main)"},children:[i,e.ip?` · ${e.ip}`:""]}),c("p",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:r})]}),e.status==="pending"&&c("button",{onClick:()=>o==null?void 0:o(e),className:"flex-shrink-0 text-xs px-2 py-1 rounded-lg font-medium",style:{background:"rgba(74,222,128,0.15)",color:"#4ade80"},title:"Approve this device",children:"Approve"}),c("button",{onClick:()=>t(e),className:"flex-shrink-0 text-xs px-2 py-1 rounded-lg font-medium",style:{background:"rgba(220,53,69,0.15)",color:"#dc3545"},title:"Disconnect and remove this device",children:s})]})}function mr({step:e,stepDesc:t="",healthCheck:o,tunnelUrl:i,oneTimeKey:n,oneTimeKeyExpiresAt:r,permanentKey:s,qrUrl:l,permissions:a,desktopEnabled:d,updateVersion:m,connections:u=[],version:h="",onRequestPermission:f,onDesktopToggle:g,onStop:x,onStart:I,onShutdown:_,onGenerateOneTimeKey:y,onRegenerateKey:C,logs:v=[],theme:M,onToggleTheme:b,pendingDevice:N,onDeviceApprove:k,onDeviceReject:p,approvedDevices:S=[],rejectedDevices:E=[],onDeviceRemove:T,onFetchDevices:w,onDeviceApproveRejected:P}){var O;const[j,V]=F("connect"),[oe,Y]=F(!1),[B,R]=F(!1),[A,G]=F(null),z=un(null),de=e===0,ie=e>0&&e<5;ue(()=>{var L;j==="log"&&((L=z.current)==null||L.scrollIntoView({behavior:"smooth"})),j==="connect"&&(w==null||w())},[v,j,u.length]);const Q=fr(S,u,E),H=Q.filter(L=>L.status==="online").length;return c("div",{className:"h-full flex flex-col relative overflow-hidden",style:{background:"var(--bg-body)"},children:[c("div",{className:"flex-1 flex flex-col w-full min-h-0 dot-grid-bg overflow-hidden md:max-w-5xl p-3",style:{margin:"0 auto"},children:[c("div",{className:"flex items-center justify-between px-5 py-4",style:{boxShadow:"var(--header-shadow)",backdropFilter:"blur(10px)"},children:[c("div",{className:"flex items-center gap-3",children:[c("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{background:"var(--brand-500)"},children:c("span",{className:"material-symbols-outlined text-white text-base",children:"terminal"})}),c("div",{className:"flex flex-col leading-tight",children:[c("span",{className:"brand-text text-xs",children:"9Remote"}),h&&c("span",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:["v",h]})]})]}),c("div",{className:"flex items-center gap-2",children:[c("button",{onClick:b,className:"glass-btn w-7 h-7 flex items-center justify-center",style:{color:"var(--text-muted)"},title:M==="dark"?"Switch to light mode":"Switch to dark mode",children:c("span",{className:"material-symbols-outlined text-sm",children:M==="dark"?"light_mode":"dark_mode"})}),c("button",{onClick:()=>window.open(ir,"_blank"),className:"glass-btn w-7 h-7 flex items-center justify-center",style:{color:"var(--text-muted)"},children:c("span",{className:"material-symbols-outlined text-sm",children:"help_outline"})}),!de&&c("button",{onClick:()=>Y(!0),className:"btn-danger px-3 h-7 flex items-center gap-1.5 text-xs font-medium",children:[c("span",{className:"material-symbols-outlined text-sm",children:"stop_circle"}),"Disconnect"]}),c("button",{onClick:()=>R(!0),className:"glass-btn w-7 h-7 flex items-center justify-center",style:{color:"var(--text-muted)"},title:"Shutdown 9Remote (stop server, tunnel and quit)",children:c("span",{className:"material-symbols-outlined text-sm",children:"power_settings_new"})})]})]}),c(ar,{version:m}),de?c(dr,{onStart:I,connecting:!1}):ie?c("div",{className:"flex-1 overflow-y-auto px-5 py-4 flex flex-col gap-4 max-w-2xl mx-auto w-full",children:c(Bn,{currentStep:e,activeDesc:t,healthCheck:o})}):c("div",{className:"flex-1 flex flex-col md:flex-row min-h-0",children:[c("div",{className:"hidden md:flex md:flex-col sidebar w-96 flex-shrink-0 overflow-y-auto p-5 gap-4",children:c(Qt,{qrUrl:l,oneTimeKey:n,oneTimeKeyExpiresAt:r,permanentKey:s,tunnelUrl:i,onGenerateOneTimeKey:y,onRegenerateKey:C})}),c("div",{className:"flex-1 flex flex-col min-h-0",children:[c("div",{className:"flex px-5 pt-3 gap-3",style:{borderColor:"var(--border)"},children:[{id:"connect",label:"Connection"},{id:"log",label:"Logs"}].map(L=>c("button",{onClick:()=>V(L.id),className:"py-2 text-xs font-medium border-b-2 transition-colors",style:j===L.id?{borderColor:"var(--brand-500)",color:"var(--brand-500)"}:{borderColor:"transparent",color:"var(--text-muted)"},children:L.label},L.id))}),c("div",{className:"flex-1 overflow-y-auto px-5 py-4 flex flex-col gap-4",children:[j==="connect"&&c(Z,{children:[c("div",{className:"md:hidden",children:c(Qt,{qrUrl:l,oneTimeKey:n,oneTimeKeyExpiresAt:r,permanentKey:s,tunnelUrl:i,onGenerateOneTimeKey:y,onRegenerateKey:C})}),c(lr,{desktopEnabled:d,onDesktopToggle:g,permissions:a,onRequestPermission:f}),c("div",{className:"glass-card p-4 flex flex-col gap-1",children:[c("p",{className:"text-xs font-medium uppercase tracking-wider mb-2",style:{color:"var(--text-muted)"},children:["Clients",Q.length>0?` (${H}/${Q.length} online)`:""]}),Q.length===0?c("p",{className:"text-xs text-center py-3",style:{color:"var(--text-muted)"},children:"No clients yet"}):Q.map(L=>c(hr,{client:L,onRemove:G,onApprove:$=>P==null?void 0:P($.deviceId)},L.deviceId))]})]}),j==="log"&&c("div",{className:"flex-1 flex flex-col",children:v.length===0?c("p",{className:"text-xs text-center mt-8",style:{color:"var(--text-muted)"},children:"No logs yet"}):c("div",{className:"flex flex-col gap-0.5",children:[v.map((L,$)=>c("p",{className:"text-xs font-mono leading-5 break-all",style:{color:"var(--text-muted)"},children:L},$)),c("div",{ref:z})]})})]})]})]})]}),oe&&c(ae,{message:"Disconnect and stop the tunnel? Remote clients will be disconnected.",confirmLabel:"Disconnect",confirmDanger:!0,onConfirm:()=>{Y(!1),x==null||x()},onCancel:()=>Y(!1)}),B&&c(ae,{message:"Shutdown 9Remote completely? This will stop the server, close the tunnel and quit the app.",confirmLabel:"Shutdown",confirmDanger:!0,onConfirm:()=>{R(!1),_==null||_()},onCancel:()=>R(!1)}),A&&c(ae,{message:A.status==="online"?`Disconnect and remove device ${A.deviceId.slice(0,8)}...? The client will be disconnected and need approval again next time.`:A.status==="pending"?`Remove pending device ${A.deviceId.slice(0,8)}...? It will need a fresh approval request to connect again.`:`Remove device ${A.deviceId.slice(0,8)}...? It will need approval again next time.`,confirmLabel:A.status==="online"?"Disconnect & Remove":"Remove",confirmDanger:!0,onConfirm:()=>{T==null||T(A),G(null)},onCancel:()=>G(null)}),N&&c("div",{className:"fixed inset-0 z-50 flex items-center justify-center",style:{background:"rgba(0,0,0,0.6)"},children:c("div",{className:"glass-card p-5 flex flex-col gap-4 w-80",children:[c("div",{className:"flex items-center gap-2",children:[c("span",{className:"material-symbols-outlined",style:{color:"var(--brand-500)",fontSize:24},children:"devices"}),c("span",{className:"text-sm font-semibold",style:{color:"var(--text-main)"},children:"New Device Connection"})]}),c("div",{className:"flex flex-col gap-1 text-xs",style:{color:"var(--text-muted)"},children:[c("span",{children:["Device: ",c("span",{style:{color:"var(--text-main)"},children:[(O=N.deviceId)==null?void 0:O.slice(0,8),"..."]})]}),c("span",{children:["IP: ",c("span",{style:{color:"var(--text-main)"},children:N.ip})]})]}),c("div",{className:"flex gap-2",children:[c("button",{onClick:p,className:"glass-btn flex-1 py-2 text-sm",style:{color:"var(--text-muted)"},children:"Reject"}),c("button",{onClick:k,className:"flex-1 py-2 text-sm font-semibold rounded-xl",style:{background:"var(--brand-500)",color:"#fff"},children:"Approve"})]})]})})]})}const tt={running:!1,timeoutMs:0,startedAt:null,logs:[]},We={step:0,stepDesc:"",tunnelUrl:"",oneTimeKey:"",oneTimeKeyExpiresAt:null,permanentKey:"",qrUrl:"",latency:null,uptime:null,healthCheck:tt},_r={screenRecording:!1,accessibility:!1},Xt=200;function pr(){const[e,t]=F(We),[o,i]=F(_r),[n,r]=F(!1),[s,l]=F([]),[a,d]=F(null),[m,u]=F([]),[h,f]=F(null),[g,x]=F([]),[I,_]=F([]),[y,C]=F(""),[v,M]=F(()=>localStorage.getItem("9remote-theme")||"dark");ue(()=>{document.documentElement.setAttribute("data-theme",v),localStorage.setItem("9remote-theme",v)},[v]);const b=()=>{M(B=>B==="dark"?"light":"dark")};ue(()=>{fetch("/api/version").then(R=>R.json()).then(R=>C(R.version??"")).catch(()=>{}),fetch("/api/ui/state").then(R=>R.json()).then(R=>{t({step:R.step??0,stepDesc:R.stepDesc??"",tunnelUrl:R.tunnelUrl??"",oneTimeKey:R.oneTimeKey??"",oneTimeKeyExpiresAt:R.oneTimeKeyExpiresAt??null,permanentKey:R.permanentKey??"",qrUrl:R.qrUrl??"",latency:R.latency??null,uptime:R.uptime??null,healthCheck:R.healthCheck??tt}),i({screenRecording:R.screenRecording??!1,accessibility:R.accessibility??!1}),R.desktopEnabled!==void 0&&r(R.desktopEnabled),R.theme&&(R.theme==="light"||R.theme==="dark")&&M(R.theme)}).catch(()=>{});const B=new EventSource("/api/ui/events");return B.onmessage=R=>{try{const A=JSON.parse(R.data);A.type==="state"?t({step:A.step??0,stepDesc:A.stepDesc??"",tunnelUrl:A.tunnelUrl??"",oneTimeKey:A.oneTimeKey??"",oneTimeKeyExpiresAt:A.oneTimeKeyExpiresAt??null,permanentKey:A.permanentKey??"",qrUrl:A.qrUrl??"",latency:A.latency??null,uptime:A.uptime??null,healthCheck:A.healthCheck??tt}):A.type==="log"?l(G=>{const z=[...G,A.message];return z.length>Xt?z.slice(-Xt):z}):A.type==="updateAvailable"?d(A.version):A.type==="permissions"?(i({screenRecording:A.screenRecording,accessibility:A.accessibility}),A.desktopEnabled!==void 0&&r(A.desktopEnabled)):A.type==="connections"?u(A.connections??[]):A.type==="deviceApproval"&&A.action==="pending"?f({socketId:A.socketId,deviceId:A.deviceId,ip:A.ip}):A.type==="deviceApproval"&&A.action==="refresh"&&w()}catch{}},B.onerror=()=>{},()=>B.close()},[]);const N=async B=>{await fetch("/api/permissions/request",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:B})}).catch(()=>{})},k=()=>{fetch("/api/ui/stop",{method:"POST"}).catch(()=>{}),t(We)},p=()=>{fetch("/api/ui/start",{method:"POST"}).catch(()=>{})},S=()=>{fetch("/api/ui/shutdown",{method:"POST"}).catch(()=>{}),t(We)},E=async()=>{const B=await fetch("/api/key/one-time",{method:"POST"}).catch(()=>null);if(!(B!=null&&B.ok))return;const R=await B.json().catch(()=>null);R!=null&&R.oneTimeKey&&t(A=>({...A,oneTimeKey:R.oneTimeKey,oneTimeKeyExpiresAt:R.expiresAt,qrUrl:R.qrUrl??A.qrUrl}))},T=async()=>{const B=!n;r(B),await fetch("/api/desktop/toggle",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:B})}).catch(()=>{})},w=async()=>{try{const[B,R]=await Promise.all([fetch("/api/device/approved"),fetch("/api/device/rejected")]);if(B.ok){const A=await B.json();x(A.devices||[])}if(R.ok){const A=await R.json();_(A.rejected||[])}}catch{}},P=async B=>{const R=B.status==="pending"?"/api/device/clear-rejected":"/api/device/remove";await fetch(R,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceId:B.deviceId})}).catch(()=>{}),w()},j=async()=>{h&&(await fetch("/api/device/approve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({socketId:h.socketId})}).catch(()=>{}),f(null),w())},V=async()=>{h&&(await fetch("/api/device/reject",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({socketId:h.socketId})}).catch(()=>{}),f(null),w())},oe=async B=>{await fetch("/api/device/approve-rejected",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceId:B})}).catch(()=>{}),w()},Y=async()=>{const B=await fetch("/api/key/regenerate",{method:"POST"}).catch(()=>null);if(!(B!=null&&B.ok))return;const R=await B.json().catch(()=>null);R!=null&&R.permanentKey&&t(A=>({...A,permanentKey:R.permanentKey}))};return c(mr,{step:e.step,stepDesc:e.stepDesc,healthCheck:e.healthCheck,tunnelUrl:e.tunnelUrl,oneTimeKey:e.oneTimeKey,oneTimeKeyExpiresAt:e.oneTimeKeyExpiresAt,permanentKey:e.permanentKey,qrUrl:e.qrUrl,permissions:o,desktopEnabled:n,updateVersion:a,connections:m,onRequestPermission:N,onDesktopToggle:T,onStop:k,onStart:p,onShutdown:S,onGenerateOneTimeKey:E,onRegenerateKey:Y,logs:s,version:y,theme:v,onToggleTheme:b,pendingDevice:h,onDeviceApprove:j,onDeviceReject:V,approvedDevices:g,rejectedDevices:I,onDeviceRemove:P,onFetchDevices:w,onDeviceApproveRejected:oe})}kn(c(pr,{}),document.getElementById("root"));