@fkn/lib 0.4.3 → 0.4.8

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.
package/index.js CHANGED
@@ -1,37 +1,38 @@
1
- import { d as e, f as t, g as n, i as r, l as i, m as a, p as o, r as s, t as c, u as l } from "./locator-DUbu14FW.js";
2
- import { createTypedEventTarget as u, expose as ee, relay as te } from "osra";
3
- import { Stream as d } from "stream";
4
- import { EventEmitter as ne } from "events";
5
- import { Address4 as f, Address6 as p } from "ip-address";
6
- import { Buffer as m } from "buffer";
1
+ import { d as e, f as t, g as n, i as r, l as i, m as a, p as o, r as s, t as c, u as l } from "./locator-Q5m8i40Z.js";
2
+ import { createTypedEventTarget as u, expose as d, relay as ee } from "osra";
3
+ import { Stream as f } from "stream";
4
+ import { EventEmitter as te } from "events";
5
+ import { Address4 as p, Address6 as m } from "ip-address";
6
+ import { Buffer as h } from "buffer";
7
+ import { createElement as ne } from "react";
7
8
  //#region node_modules/@mfkn/web-extension/lib/utils/extension.js
8
- var re = "FKN_WEB_EXTENSION_MAIN_WORLD_CONTENT_SCRIPT_ENABLED_EVENT_KEY", ie = "fknExtension", h = u();
9
- typeof document < "u" && document.addEventListener(re, (e) => {
10
- h.dispatchEvent(new CustomEvent("statuschange", { detail: { enabled: e.detail.enabled } }));
9
+ var re = "FKN_WEB_EXTENSION_MAIN_WORLD_CONTENT_SCRIPT_ENABLED_EVENT_KEY", ie = "fknExtension", g = u();
10
+ typeof document < "u" && document.addEventListener(re, () => {
11
+ g.dispatchEvent(new CustomEvent("statuschange", { detail: { enabled: _() } }));
11
12
  });
12
- var g = () => typeof document > "u" ? !1 : document.documentElement.dataset[ie] === "true", _ = null, v = (e) => {
13
- _ = e;
14
- }, ae = 150, y = (e = 1e3) => new Promise((t, n) => {
15
- if (g()) return t();
13
+ var _ = () => typeof document > "u" ? !1 : document.documentElement.dataset[ie] === "true", v = null, y = (e) => {
14
+ v = e;
15
+ }, ae = 150, b = (e = 1e3) => new Promise((t, n) => {
16
+ if (_()) return t();
16
17
  let r, i = (e) => {
17
18
  clearTimeout(r), s.disconnect(), document.removeEventListener("readystatechange", c), e();
18
19
  }, a = () => i(async () => {
19
- if (_ && (await _().catch(() => {}), g())) return t();
20
+ if (v && (await v().catch(() => {}), _())) return t();
20
21
  n(/* @__PURE__ */ Error("The FKN WebExtension is not installed, enabled or not exposed on this page."));
21
22
  }), o = () => {
22
- clearTimeout(r), r = setTimeout(() => g() ? i(t) : a(), ae);
23
+ clearTimeout(r), r = setTimeout(() => _() ? i(t) : a(), ae);
23
24
  }, s = new MutationObserver(() => {
24
- g() && i(t);
25
+ _() && i(t);
25
26
  }), c = () => {
26
- document.readyState === "complete" && !g() && o();
27
+ document.readyState === "complete" && !_() && o();
27
28
  };
28
29
  if (r = setTimeout(a, e), s.observe(document.documentElement, {
29
30
  attributes: !0,
30
31
  attributeFilter: ["data-fkn-extension"]
31
32
  }), document.addEventListener("readystatechange", c), document.readyState === "complete") return o();
32
- g() && i(t);
33
- }), oe, b = new Proxy({}, { get: (e, t) => async (...e) => {
34
- await y(), oe ??= ee({}, {
33
+ _() && i(t);
34
+ }), oe, x = new Proxy({}, { get: (e, t) => async (...e) => {
35
+ await b(), oe ??= d({}, {
35
36
  transport: window,
36
37
  revivableModules: i
37
38
  });
@@ -71,7 +72,7 @@ var g = () => typeof document > "u" ? !1 : document.documentElement.dataset[ie]
71
72
  }
72
73
  let n = t.hostname.replace(/^\[|\]$/g, "").toLowerCase().replace(/\.$/, "");
73
74
  return n === "localhost" || n.endsWith(".localhost") || n.endsWith(".local") || n.endsWith(".internal") || n.endsWith(".home.arpa") ? !0 : n.includes(":") ? n === "::" || n === "::1" || n.startsWith("fc") || n.startsWith("fd") || /^fe[89ab]/.test(n) || n.startsWith("::ffff:") : ue(n);
74
- }, fe = ["fkn.app", "fkn.dev"], x = (e) => {
75
+ }, fe = ["fkn.app", "fkn.dev"], S = (e) => {
75
76
  let t;
76
77
  try {
77
78
  t = new URL(e);
@@ -81,8 +82,8 @@ var g = () => typeof document > "u" ? !1 : document.documentElement.dataset[ie]
81
82
  if (t.protocol === "chrome-extension:" || t.protocol === "moz-extension:") return !0;
82
83
  let n = t.hostname;
83
84
  return fe.some((e) => n === e || n.endsWith(`.${e}`));
84
- }, S = (e) => {
85
- if (x(e)) throw Error("fetch: refusing to target the extension's own pages or FKN platform domains");
85
+ }, C = (e) => {
86
+ if (S(e)) throw Error("fetch: refusing to target the extension's own pages or FKN platform domains");
86
87
  }, pe = ["origin", "referer"], me = (e) => {
87
88
  if (!e?.headers) return;
88
89
  let t = new Headers(e.headers), n = pe.map((e) => {
@@ -90,11 +91,11 @@ var g = () => typeof document > "u" ? !1 : document.documentElement.dataset[ie]
90
91
  return n === null ? void 0 : [e, n];
91
92
  }).filter((e) => e !== void 0);
92
93
  return n.length ? n : void 0;
93
- }, C = async (e, t) => {
94
+ }, he = async (e, t) => {
94
95
  let n = new Request(e, t);
95
- S(n.url);
96
+ C(n.url);
96
97
  let r = n.body ? await n.arrayBuffer() : null;
97
- return b.proxyFetch({
98
+ return x.proxyFetch({
98
99
  url: n.url,
99
100
  method: n.method,
100
101
  headers: [...n.headers],
@@ -105,21 +106,21 @@ var g = () => typeof document > "u" ? !1 : document.documentElement.dataset[ie]
105
106
  reason: t?.reason,
106
107
  signal: t?.signal ?? void 0
107
108
  });
108
- }, he = {
109
+ }, ge = {
109
110
  scope: "network.readCookie",
110
111
  category: "network",
111
112
  severity: 3,
112
113
  unsafe: !0,
113
114
  title: "Read a site’s cookie",
114
115
  description: "Lets the app read a named cookie from another site, which can include the login token only that site should see."
115
- }, ge = { get: (e) => b.getCookie(e) }, _e = {
116
+ }, _e = { get: (e) => x.getCookie(e) }, ve = {
116
117
  scope: "network.modifyRequestHeaders",
117
118
  category: "network",
118
119
  severity: 2,
119
120
  unsafe: !0,
120
121
  title: "Rewrite request headers to other sites",
121
122
  description: "Lets the app set or remove headers (like Origin and Referer) on this page’s own requests to the listed sites."
122
- }, ve = (e) => b.setRequestHeaderRule(e), ye = (e) => b.removeRequestHeaderRule({ ruleId: e });
123
+ }, ye = (e) => x.setRequestHeaderRule(e), be = (e) => x.removeRequestHeaderRule({ ruleId: e });
123
124
  (() => {
124
125
  let e = {}, t = [...c.selectorModules, ...r.selectorModules];
125
126
  for (let n of t) n.render && !(n.type in e) && (e[n.type] = n.render);
@@ -141,50 +142,59 @@ var w = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", T = (e) => {
141
142
  return n === "fkn.app" || n.endsWith(".fkn.app");
142
143
  }, E = (e) => {
143
144
  if (T(e)) throw Error("attachFrame: refusing to target the extension's own pages or fkn.app");
144
- }, be = {
145
+ }, xe = {
145
146
  scope: "embed.iframe",
146
147
  category: "embed",
147
148
  severity: 0,
148
149
  title: "Load another website inside this app",
149
150
  description: "Lets the app embed external pages directly inside its own view."
150
- }, xe = {
151
+ }, Se = {
151
152
  scope: "embed.open",
152
153
  category: "embed",
153
154
  severity: 0,
154
155
  title: "Open a website inside this app",
155
156
  description: "Lets the app navigate to another site without leaving its window."
156
- }, Se = async ({ iframe: e, domains: t = [] }) => {
157
- let n = crypto.randomUUID();
158
- if (E(e.src), await y(), !e.isConnected) throw Error("attachFrame: the iframe must be connected to the document before attaching");
159
- e.dispatchEvent(new CustomEvent(w, { detail: n }));
160
- let { executeLocator: r, ensureLocatorPermission: i, goto: a } = await b.attachFrame({
161
- marker: n,
162
- domains: t
163
- }), o = s(r, i), c = (e, t = {}) => (E(e), a({
157
+ }, Ce = {
158
+ scope: "embed.evaluate",
159
+ category: "embed",
160
+ severity: 0,
161
+ title: "Run app code inside an embedded frame",
162
+ description: "Lets the app execute its own code inside a page it embedded, to read back a computed result."
163
+ }, we = async ({ iframe: e, domains: t = [], syncCookies: n = !0, lockdown: r = !1 }) => {
164
+ let i = crypto.randomUUID();
165
+ if (E(e.src), await b(), !e.isConnected) throw Error("attachFrame: the iframe must be connected to the document before attaching");
166
+ e.dispatchEvent(new CustomEvent(w, { detail: i }));
167
+ let { executeLocator: a, ensureLocatorPermission: o, goto: c, evaluate: l } = await x.attachFrame({
168
+ marker: i,
169
+ domains: t,
170
+ syncCookies: n,
171
+ lockdown: r
172
+ }), u = s(a, o), d = (e, t = {}) => (E(e), c({
164
173
  url: e,
165
174
  ...t
166
- })), l = () => e.src;
175
+ })), ee = ((e, t) => l(e, t)), f = () => e.src;
167
176
  return {
168
- ...o,
169
- goto: c,
170
- url: l
177
+ ...u,
178
+ goto: d,
179
+ evaluate: ee,
180
+ url: f
171
181
  };
172
- }, Ce = { request: (e) => b.requestPermissions(e.map((e) => ({
182
+ }, Te = { request: (e) => x.requestPermissions(e.map((e) => ({
173
183
  key: e.key,
174
184
  scope: e.scope ?? "",
175
185
  reason: e.reason
176
- }))) }, we = 32, Te = typeof CSS < "u" && CSS.supports("clip-path", "path('M0 0H1V1H0Z')"), Ee = (e) => {
186
+ }))) }, Ee = 32, De = typeof CSS < "u" && CSS.supports("clip-path", "path('M0 0H1V1H0Z')"), Oe = (e) => {
177
187
  let t = e.style;
178
188
  t.setProperty("display", "block", "important"), t.setProperty("position", "fixed", "important"), t.setProperty("top", "0", "important"), t.setProperty("left", "0", "important"), t.setProperty("width", "100%", "important"), t.setProperty("height", "100%", "important"), t.setProperty("border", "none", "important"), t.setProperty("clip-path", "inset(100%)", "important"), t.setProperty("background", "transparent"), t.setProperty("color-scheme", "normal"), t.setProperty("z-index", "2147483647"), e.setAttribute("title", "FKN");
179
- }, De = ({ x: e, y: t, width: n, height: r }) => `M${e} ${t}h${n}v${r}h${-n}Z`, Oe = (e, { modal: t, rects: n }) => {
180
- if (!Te) {
189
+ }, ke = ({ x: e, y: t, width: n, height: r }) => `M${e} ${t}h${n}v${r}h${-n}Z`, Ae = (e, { modal: t, rects: n }) => {
190
+ if (!De) {
181
191
  let r = t || n.length > 0;
182
192
  e.style.setProperty("pointer-events", r ? "auto" : "none", "important"), e.style.setProperty("visibility", r ? "visible" : "hidden", "important");
183
193
  return;
184
194
  }
185
- let r = t ? "none" : n.length === 0 ? "inset(100%)" : `path('${n.map(De).join("")}')`, i = r === "none" || CSS.supports("clip-path", r) ? r : "inset(100%)";
195
+ let r = t ? "none" : n.length === 0 ? "inset(100%)" : `path('${n.map(ke).join("")}')`, i = r === "none" || CSS.supports("clip-path", r) ? r : "inset(100%)";
186
196
  e.style.setProperty("clip-path", i, "important");
187
- }, ke = (e) => {
197
+ }, je = (e) => {
188
198
  if (typeof e != "object" || !e) return null;
189
199
  let { x: t, y: n, width: r, height: i } = e;
190
200
  if (![
@@ -200,45 +210,45 @@ var w = "FKN_WEB_EXTENSION_ATTACH_FRAME_EVENT_KEY", T = (e) => {
200
210
  width: l - s,
201
211
  height: u - c
202
212
  };
203
- }, Ae = (e) => {
213
+ }, Me = (e) => {
204
214
  if (typeof e != "object" || !e) return null;
205
- let t = e, n = (Array.isArray(t.rects) ? t.rects.slice(0, we) : []).map(ke).filter((e) => e !== null && e.width > 0 && e.height > 0);
215
+ let t = e, n = (Array.isArray(t.rects) ? t.rects.slice(0, Ee) : []).map(je).filter((e) => e !== null && e.width > 0 && e.height > 0);
206
216
  return {
207
217
  modal: t.modal === !0,
208
218
  rects: n
209
219
  };
210
- }, D = null, je = () => D !== null, Me = (e) => {
211
- Ee(e), Oe(e, {
220
+ }, D = null, Ne = () => D !== null, Pe = (e) => {
221
+ Oe(e), Ae(e, {
212
222
  modal: !1,
213
223
  rects: []
214
224
  }), D = e;
215
- }, Ne = (e) => {
225
+ }, Fe = (e) => {
216
226
  if (!D) return;
217
- let t = Ae(e);
218
- t && Oe(D, t);
219
- }, Pe = "https://fkn.app", O = typeof globalThis < "u" && globalThis.document ? globalThis.document : void 0, Fe = O?.querySelector(`iframe[src="${Pe}/api"]`) ?? null, k = O?.createElement("iframe") ?? null;
220
- !Fe && k && O && (k.src = `${Pe}/api`, O.body.appendChild(k));
221
- var A = Fe ?? k, Ie = A?.contentWindow ?? null;
222
- A && O && Me(A);
227
+ let t = Me(e);
228
+ t && Ae(D, t);
229
+ }, Ie = "https://fkn.app", O = typeof globalThis < "u" && globalThis.document ? globalThis.document : void 0, Le = O?.querySelector(`iframe[src="${Ie}/api"]`) ?? null, k = O?.createElement("iframe") ?? null;
230
+ !Le && k && O && (k.src = `${Ie}/api`, O.body.appendChild(k));
231
+ var A = Le ?? k, Re = A?.contentWindow ?? null;
232
+ A && O && Pe(A);
223
233
  var j = (() => {
224
- if (typeof window < "u") return Ie ? {
234
+ if (typeof window < "u") return Re ? {
225
235
  receive: window,
226
- emit: Ie
236
+ emit: Re
227
237
  } : void 0;
228
238
  if (typeof self < "u") return {
229
239
  receive: self,
230
240
  emit: self
231
241
  };
232
- })(), Le = j !== void 0, M = j ? ee({}, {
242
+ })(), ze = j !== void 0, M = j ? d({}, {
233
243
  key: "fkn-api",
234
244
  transport: j
235
245
  }) : new Promise(() => {});
236
246
  M.then((e) => {
237
- je() && e.overlay.setHost(Ne);
247
+ Ne() && e.overlay.setHost(Fe);
238
248
  }, () => {});
239
249
  //#endregion
240
250
  //#region src/lib/fkn-target.ts
241
- var Re = ["fkn.app", "fkn.dev"], ze = (e) => {
251
+ var Be = ["fkn.app", "fkn.dev"], Ve = (e) => {
242
252
  let t = typeof e == "string" ? e : e instanceof URL ? e.href : e.url, n;
243
253
  try {
244
254
  n = new URL(t);
@@ -246,8 +256,8 @@ var Re = ["fkn.app", "fkn.dev"], ze = (e) => {
246
256
  return;
247
257
  }
248
258
  let r = n.hostname;
249
- if (Re.some((e) => r === e || r.endsWith(`.${e}`))) throw Error(`fetch refuses FKN platform domains (${r})`);
250
- }, Be = (e, t) => (ze(e), M.then((n) => n.cloud.fetch(e, t))), Ve = async () => {
259
+ if (Be.some((e) => r === e || r.endsWith(`.${e}`))) throw Error(`fetch refuses FKN platform domains (${r})`);
260
+ }, He = (e, t) => (Ve(e), M.then((n) => n.cloud.fetch(e, t))), Ue = async () => {
251
261
  let e = await M.then((e) => e.cloud.quota());
252
262
  return {
253
263
  premium: e.premium,
@@ -259,9 +269,9 @@ var Re = ["fkn.app", "fkn.dev"], ze = (e) => {
259
269
  bytesPerSecond: e.bytesPerSecond,
260
270
  bitsPerSecond: e.bytesPerSecond * 8
261
271
  };
262
- }, He = /* @__PURE__ */ n({ lookup: () => Ue }), Ue = (e, t) => M.then((n) => n.cloud.dns.lookup(e, t)), We = new TextEncoder();
272
+ }, We = /* @__PURE__ */ n({ lookup: () => Ge }), Ge = (e, t) => M.then((n) => n.cloud.dns.lookup(e, t)), Ke = new TextEncoder();
263
273
  new TextDecoder();
264
- var N = (e) => f.isValid(e), P = (e) => p.isValid(e), Ge = (e) => N(e) ? 4 : P(e) ? 6 : 0, Ke = (...e) => {
274
+ var N = (e) => p.isValid(e), P = (e) => m.isValid(e), qe = (e) => N(e) ? 4 : P(e) ? 6 : 0, Je = (...e) => {
265
275
  if (typeof e[0] == "string") throw Error("FKN WebVPN does not support IPC connections");
266
276
  let t = typeof e.at(-1) == "function" ? e.at(-1) : void 0;
267
277
  return e[0] && typeof e[0] == "object" ? {
@@ -272,7 +282,7 @@ var N = (e) => f.isValid(e), P = (e) => p.isValid(e), Ge = (e) => N(e) ? 4 : P(e
272
282
  host: typeof e[1] == "string" ? e[1] : void 0,
273
283
  callback: t
274
284
  };
275
- }, qe = (...e) => {
285
+ }, Ye = (...e) => {
276
286
  let t = typeof e.at(-1) == "function" ? e.at(-1) : void 0, n = e[0] ?? 0, r = typeof e[1] == "string" ? e[1] : void 0;
277
287
  return typeof e[0] == "object" ? {
278
288
  ...e[0],
@@ -284,7 +294,7 @@ var N = (e) => f.isValid(e), P = (e) => p.isValid(e), Ge = (e) => N(e) ? 4 : P(e
284
294
  port: n,
285
295
  callback: t
286
296
  };
287
- }, Je = (...e) => {
297
+ }, Xe = (...e) => {
288
298
  let t = typeof e.at(-1) == "function" ? e.at(-1) : void 0, n = e[0];
289
299
  if (typeof e[2] == "number") return {
290
300
  message: n,
@@ -309,18 +319,18 @@ var N = (e) => f.isValid(e), P = (e) => p.isValid(e), Ge = (e) => N(e) ? 4 : P(e
309
319
  new TextEncoder(), new TextDecoder();
310
320
  //#endregion
311
321
  //#region src/lib/webvpn/net.ts
312
- var Ye = /* @__PURE__ */ n({
322
+ var Ze = /* @__PURE__ */ n({
313
323
  Server: () => I,
314
324
  Socket: () => F,
315
- _default: () => $e,
316
- connect: () => Xe,
317
- createConnection: () => Ze,
318
- createServer: () => Qe,
319
- default: () => $e,
320
- isIP: () => Ge,
325
+ _default: () => tt,
326
+ connect: () => Qe,
327
+ createConnection: () => $e,
328
+ createServer: () => et,
329
+ default: () => tt,
330
+ isIP: () => qe,
321
331
  isIPv4: () => N,
322
332
  isIPv6: () => P
323
- }), F = class extends d.Duplex {
333
+ }), F = class extends f.Duplex {
324
334
  _localAddress;
325
335
  _remoteAddress;
326
336
  _webVPNTcpSocketPromise;
@@ -380,7 +390,7 @@ var Ye = /* @__PURE__ */ n({
380
390
  }).catch(n);
381
391
  }
382
392
  connect(...e) {
383
- let t = Ke(...e), n = this.__webvpn_tcp_socket_init__(M.then((e) => e.cloud.webvpn.tcpSocket({
393
+ let t = Je(...e), n = this.__webvpn_tcp_socket_init__(M.then((e) => e.cloud.webvpn.tcpSocket({
384
394
  remoteAddress: t.host ?? "localhost",
385
395
  remotePort: t.port
386
396
  })));
@@ -507,7 +517,7 @@ var Ye = /* @__PURE__ */ n({
507
517
  return this._remoteAddress.family;
508
518
  }
509
519
  timeout;
510
- }, I = class extends ne {
520
+ }, I = class extends te {
511
521
  _localAddress;
512
522
  _webVPNTcpSocketListenerPromise;
513
523
  constructor(e, t) {
@@ -525,7 +535,7 @@ var Ye = /* @__PURE__ */ n({
525
535
  }), this._webVPNTcpSocketListenerPromise;
526
536
  }
527
537
  listen(...e) {
528
- let t = Ke(...e), n = (e) => {
538
+ let t = Je(...e), n = (e) => {
529
539
  let t = new F({ connection: Promise.resolve(e) });
530
540
  this.emit("connection", t);
531
541
  }, r = (e) => M.then((r) => r.cloud.webvpn.tcpSocketListener({
@@ -562,23 +572,23 @@ var Ye = /* @__PURE__ */ n({
562
572
  connections;
563
573
  listening;
564
574
  async [Symbol.asyncDispose]() {}
565
- }, Xe = (e, t) => new F().connect(e, t), Ze = (e, t) => new F().connect(e, t), Qe = (e, t) => {
575
+ }, Qe = (e, t) => new F().connect(e, t), $e = (e, t) => new F().connect(e, t), et = (e, t) => {
566
576
  typeof e == "function" && (t = e, e = void 0);
567
577
  let n = new I(e);
568
578
  return t && n.on("connection", t), n;
569
- }, $e = {
579
+ }, tt = {
570
580
  Socket: F,
571
581
  Server: I,
572
- connect: Xe,
573
- createConnection: Ze,
574
- createServer: Qe,
575
- isIP: Ge,
582
+ connect: Qe,
583
+ createConnection: $e,
584
+ createServer: et,
585
+ isIP: qe,
576
586
  isIPv4: N,
577
587
  isIPv6: P
578
- }, et = /* @__PURE__ */ n({
579
- Socket: () => tt,
580
- createSocket: () => it
581
- }), tt = class extends ne {
588
+ }, nt = /* @__PURE__ */ n({
589
+ Socket: () => rt,
590
+ createSocket: () => ot
591
+ }), rt = class extends te {
582
592
  _type;
583
593
  _localAddress;
584
594
  _remoteAddress;
@@ -639,7 +649,7 @@ var Ye = /* @__PURE__ */ n({
639
649
  a += n.byteLength, l = t.getUint16(a), a += 2;
640
650
  }
641
651
  let u = t.getUint32(a);
642
- a += 4, this.emit("message", m.from(e.slice(a, a + u)), {
652
+ a += 4, this.emit("message", h.from(e.slice(a, a + u)), {
643
653
  address: s,
644
654
  family: c,
645
655
  port: l,
@@ -648,10 +658,10 @@ var Ye = /* @__PURE__ */ n({
648
658
  }
649
659
  }
650
660
  _peerTail(e, t) {
651
- if (e === void 0 || t === void 0) return nt;
661
+ if (e === void 0 || t === void 0) return it;
652
662
  let n = `${e}|${t}`, r = this._peerTailCache.get(n);
653
663
  if (r) return r;
654
- let i = f.isValid(e) ? L(e) : R(e), a = new Uint8Array(1 + i.byteLength + 2);
664
+ let i = p.isValid(e) ? L(e) : R(e), a = new Uint8Array(1 + i.byteLength + 2);
655
665
  return a[0] = i.byteLength === 4 ? 0 : 1, a.set(i, 1), new DataView(a.buffer).setUint16(1 + i.byteLength, t), this._peerTailCache.set(n, a), a;
656
666
  }
657
667
  _portSend(e, t, n) {
@@ -666,8 +676,8 @@ var Ye = /* @__PURE__ */ n({
666
676
  }));
667
677
  }
668
678
  addMembership(e, t) {
669
- if (f.isValid(e)) {
670
- let n = L(e), r = t && f.isValid(t) ? L(t) : new Uint8Array([
679
+ if (p.isValid(e)) {
680
+ let n = L(e), r = t && p.isValid(t) ? L(t) : new Uint8Array([
671
681
  0,
672
682
  0,
673
683
  0,
@@ -678,7 +688,7 @@ var Ye = /* @__PURE__ */ n({
678
688
  group: n,
679
689
  interface: r
680
690
  });
681
- } else if (p.isValid(e)) {
691
+ } else if (m.isValid(e)) {
682
692
  let t = R(e);
683
693
  this._setUdpOption({
684
694
  type: 7,
@@ -692,7 +702,7 @@ var Ye = /* @__PURE__ */ n({
692
702
  return this._localAddress;
693
703
  }
694
704
  bind(...e) {
695
- let t = qe(...e), n = this._type === "udp6" ? "::" : "0.0.0.0";
705
+ let t = Ye(...e), n = this._type === "udp6" ? "::" : "0.0.0.0";
696
706
  return this._webVPNUdpSocketPromise = M.then((e) => e.cloud.webvpn.udpSocket({
697
707
  type: this._type,
698
708
  address: t.address ?? n,
@@ -703,7 +713,7 @@ var Ye = /* @__PURE__ */ n({
703
713
  else {
704
714
  let t = e.dataReadableStream.getReader(), n = async () => {
705
715
  let { value: e, done: r } = await t.read();
706
- r || (this.emit("message", m.from(e.data), {
716
+ r || (this.emit("message", h.from(e.data), {
707
717
  address: e.address,
708
718
  family: e.family,
709
719
  port: e.port,
@@ -758,8 +768,8 @@ var Ye = /* @__PURE__ */ n({
758
768
  });
759
769
  }
760
770
  dropMembership(e, t) {
761
- if (f.isValid(e)) {
762
- let n = L(e), r = t && f.isValid(t) ? L(t) : new Uint8Array([
771
+ if (p.isValid(e)) {
772
+ let n = L(e), r = t && p.isValid(t) ? L(t) : new Uint8Array([
763
773
  0,
764
774
  0,
765
775
  0,
@@ -770,7 +780,7 @@ var Ye = /* @__PURE__ */ n({
770
780
  group: n,
771
781
  interface: r
772
782
  });
773
- } else if (p.isValid(e)) {
783
+ } else if (m.isValid(e)) {
774
784
  let t = R(e);
775
785
  this._setUdpOption({
776
786
  type: 8,
@@ -804,12 +814,12 @@ var Ye = /* @__PURE__ */ n({
804
814
  }
805
815
  send(...e) {
806
816
  this._webVPNUdpSocketPromise || this.bind();
807
- let t = Je(...e), n = this._type === "udp6" ? "::1" : "127.0.0.1";
817
+ let t = Xe(...e), n = this._type === "udp6" ? "::1" : "127.0.0.1";
808
818
  if (!this._webVPNUdpSocketPromise) throw Error("Socket not bound");
809
819
  this._webVPNUdpSocketPromise.then((e) => {
810
820
  if (!e) throw Error("Socket not bound");
811
- let r = rt(t.message), i = t.callback, a = t.address ?? n, o = this._remoteAddress !== void 0 && t.address === void 0;
812
- if (this._dataPort && (o || f.isValid(a) || p.isValid(a))) {
821
+ let r = at(t.message), i = t.callback, a = t.address ?? n, o = this._remoteAddress !== void 0 && t.address === void 0;
822
+ if (this._dataPort && (o || p.isValid(a) || m.isValid(a))) {
813
823
  this._portSend(r, o ? void 0 : a, o ? void 0 : t.port), i?.call(this, null, r.byteLength);
814
824
  return;
815
825
  }
@@ -870,12 +880,12 @@ var Ye = /* @__PURE__ */ n({
870
880
  this.close(e);
871
881
  });
872
882
  }
873
- }, nt = new Uint8Array([2]), rt = (e) => {
874
- if (typeof e == "string") return We.encode(e);
883
+ }, it = new Uint8Array([2]), at = (e) => {
884
+ if (typeof e == "string") return Ke.encode(e);
875
885
  if (e instanceof Uint8Array) return e;
876
886
  if (ArrayBuffer.isView(e)) return new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
877
887
  if (Array.isArray(e)) {
878
- let t = e.map(rt), n = new Uint8Array(t.reduce((e, t) => e + t.byteLength, 0)), r = 0;
888
+ let t = e.map(at), n = new Uint8Array(t.reduce((e, t) => e + t.byteLength, 0)), r = 0;
879
889
  for (let e of t) n.set(e, r), r += e.byteLength;
880
890
  return n;
881
891
  }
@@ -885,28 +895,28 @@ var Ye = /* @__PURE__ */ n({
885
895
  if (t.length !== 4 || t.some((e) => Number.isNaN(e) || e < 0 || e > 255)) throw Error(`Invalid IPv4 address: ${e}`);
886
896
  return new Uint8Array(t);
887
897
  }, R = (e) => {
888
- let t = new p(e).getBitsBase16(0, 128).match(/.{2}/g);
898
+ let t = new m(e).getBitsBase16(0, 128).match(/.{2}/g);
889
899
  if (!t || t.length !== 16) throw Error(`Invalid IPv6 address: ${e}`);
890
900
  return new Uint8Array(t.map((e) => parseInt(e, 16)));
891
- }, it = (e, t) => {
892
- let n = new tt(typeof e == "string" ? { type: e } : e);
901
+ }, ot = (e, t) => {
902
+ let n = new rt(typeof e == "string" ? { type: e } : e);
893
903
  return t && n.on("message", t), n;
894
- }, at = /* @__PURE__ */ n({
904
+ }, st = /* @__PURE__ */ n({
895
905
  Agent: () => Y,
896
906
  ClientRequest: () => q,
897
907
  HTTPParser: () => U,
898
908
  IncomingMessage: () => W,
899
- METHODS: () => st,
909
+ METHODS: () => lt,
900
910
  STATUS_CODES: () => z,
901
911
  Server: () => J,
902
912
  ServerResponse: () => K,
903
- _default: () => vt,
904
- createServer: () => _t,
905
- default: () => vt,
906
- get: () => gt,
907
- globalAgent: () => ht,
913
+ _default: () => bt,
914
+ createServer: () => yt,
915
+ default: () => bt,
916
+ get: () => vt,
917
+ globalAgent: () => _t,
908
918
  request: () => X
909
- }), ot = new TextDecoder("latin1"), st = /* @__PURE__ */ "ACL.BIND.CHECKOUT.CONNECT.COPY.DELETE.GET.HEAD.LINK.LOCK.M-SEARCH.MERGE.MKACTIVITY.MKCALENDAR.MKCOL.MOVE.NOTIFY.OPTIONS.PATCH.POST.PROPFIND.PROPPATCH.PURGE.PUT.REBIND.REPORT.SEARCH.SOURCE.SUBSCRIBE.TRACE.UNBIND.UNLINK.UNLOCK.UNSUBSCRIBE".split("."), z = {
919
+ }), ct = new TextDecoder("latin1"), lt = /* @__PURE__ */ "ACL.BIND.CHECKOUT.CONNECT.COPY.DELETE.GET.HEAD.LINK.LOCK.M-SEARCH.MERGE.MKACTIVITY.MKCALENDAR.MKCOL.MOVE.NOTIFY.OPTIONS.PATCH.POST.PROPFIND.PROPPATCH.PURGE.PUT.REBIND.REPORT.SEARCH.SOURCE.SUBSCRIBE.TRACE.UNBIND.UNLINK.UNLOCK.UNSUBSCRIBE".split("."), z = {
910
920
  100: "Continue",
911
921
  101: "Switching Protocols",
912
922
  102: "Processing",
@@ -970,7 +980,7 @@ var Ye = /* @__PURE__ */ n({
970
980
  509: "Bandwidth Limit Exceeded",
971
981
  510: "Not Extended",
972
982
  511: "Network Authentication Required"
973
- }, ct = new Set([
983
+ }, ut = new Set([
974
984
  "content-type",
975
985
  "content-length",
976
986
  "user-agent",
@@ -989,15 +999,15 @@ var Ye = /* @__PURE__ */ n({
989
999
  "server",
990
1000
  "age",
991
1001
  "expires"
992
- ]), B = 13, V = 10, lt = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/, H = (e, t) => (e.code = t, e), ut = (e, t) => {
1002
+ ]), B = 13, V = 10, dt = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/, H = (e, t) => (e.code = t, e), ft = (e, t) => {
993
1003
  if (e.length === 0) return t;
994
1004
  if (t.length === 0) return e;
995
1005
  let n = new Uint8Array(e.length + t.length);
996
1006
  return n.set(e, 0), n.set(t, e.length), n;
997
- }, dt = (e, t) => {
1007
+ }, pt = (e, t) => {
998
1008
  for (let n = t; n + 1 < e.length; n++) if (e[n] === B && e[n + 1] === V) return n;
999
1009
  return -1;
1000
- }, ft = (e) => {
1010
+ }, mt = (e) => {
1001
1011
  for (let t = 0; t + 3 < e.length; t++) if (e[t] === B && e[t + 1] === V && e[t + 2] === B && e[t + 3] === V) return t;
1002
1012
  return -1;
1003
1013
  }, U = class {
@@ -1011,10 +1021,10 @@ var Ye = /* @__PURE__ */ n({
1011
1021
  this.mode = e, this.handlers = t;
1012
1022
  }
1013
1023
  execute(e) {
1014
- this.buf = ut(this.buf, e);
1024
+ this.buf = ft(this.buf, e);
1015
1025
  let t = !0;
1016
1026
  for (; t;) if (t = !1, this.state === "HEAD") {
1017
- let e = ft(this.buf);
1027
+ let e = mt(this.buf);
1018
1028
  if (e === -1) return;
1019
1029
  let n = this.buf.subarray(0, e);
1020
1030
  this.buf = this.buf.subarray(e + 4);
@@ -1029,7 +1039,7 @@ var Ye = /* @__PURE__ */ n({
1029
1039
  this.state = "HEAD", this.framing = "none", this.bodyRemaining = 0, this.chunkState = "size", this.skipBody = !1;
1030
1040
  }
1031
1041
  parseHead(e) {
1032
- let t = ot.decode(e).split("\r\n"), n = t.shift() ?? "", r = [];
1042
+ let t = ct.decode(e).split("\r\n"), n = t.shift() ?? "", r = [];
1033
1043
  for (let e of t) (e.startsWith(" ") || e.startsWith(" ")) && r.length > 0 ? r[r.length - 1] += " " + e.trim() : r.push(e);
1034
1044
  let i = [], a = {};
1035
1045
  for (let e of r) {
@@ -1067,7 +1077,7 @@ var Ye = /* @__PURE__ */ n({
1067
1077
  return;
1068
1078
  }
1069
1079
  let i = e[r];
1070
- i === void 0 ? e[r] = n : ct.has(r) || (e[r] = `${i}, ${n}`);
1080
+ i === void 0 ? e[r] = n : ut.has(r) || (e[r] = `${i}, ${n}`);
1071
1081
  }
1072
1082
  setupBody(e) {
1073
1083
  if (this.skipBody) {
@@ -1100,9 +1110,9 @@ var Ye = /* @__PURE__ */ n({
1100
1110
  }
1101
1111
  consumeChunked() {
1102
1112
  for (;;) if (this.chunkState === "size") {
1103
- let e = dt(this.buf, 0);
1113
+ let e = pt(this.buf, 0);
1104
1114
  if (e === -1) return !1;
1105
- let t = ot.decode(this.buf.subarray(0, e)), n = parseInt(t.split(";")[0].trim(), 16);
1115
+ let t = ct.decode(this.buf.subarray(0, e)), n = parseInt(t.split(";")[0].trim(), 16);
1106
1116
  if (this.buf = this.buf.subarray(e + 2), Number.isNaN(n)) return !0;
1107
1117
  n === 0 ? this.chunkState = "trailer" : (this.bodyRemaining = n, this.chunkState = "data");
1108
1118
  } else if (this.chunkState === "data") {
@@ -1113,13 +1123,13 @@ var Ye = /* @__PURE__ */ n({
1113
1123
  if (this.buf.length < 2) return !1;
1114
1124
  this.buf = this.buf.subarray(2), this.chunkState = "size";
1115
1125
  } else {
1116
- let e = dt(this.buf, 0);
1126
+ let e = pt(this.buf, 0);
1117
1127
  if (e === -1) return !1;
1118
1128
  let t = e === 0;
1119
1129
  if (this.buf = this.buf.subarray(e + 2), t) return !0;
1120
1130
  }
1121
1131
  }
1122
- }, pt = (e, t) => m.isBuffer(e) ? e : typeof e == "string" ? m.from(e, t ?? "utf8") : e instanceof Uint8Array ? m.from(e) : e instanceof ArrayBuffer ? m.from(new Uint8Array(e)) : m.from(String(e)), W = class extends d.Readable {
1132
+ }, ht = (e, t) => h.isBuffer(e) ? e : typeof e == "string" ? h.from(e, t ?? "utf8") : e instanceof Uint8Array ? h.from(e) : e instanceof ArrayBuffer ? h.from(new Uint8Array(e)) : h.from(String(e)), W = class extends f.Readable {
1123
1133
  httpVersion = "1.1";
1124
1134
  httpVersionMajor = 1;
1125
1135
  httpVersionMinor = 1;
@@ -1146,7 +1156,7 @@ var Ye = /* @__PURE__ */ n({
1146
1156
  setTimeout(e, t) {
1147
1157
  return this.socket.setTimeout(e, t), this;
1148
1158
  }
1149
- }, G = class extends d.Writable {
1159
+ }, G = class extends f.Writable {
1150
1160
  _headerStore = /* @__PURE__ */ new Map();
1151
1161
  headersSent = !1;
1152
1162
  chunkedEncoding = !1;
@@ -1154,7 +1164,7 @@ var Ye = /* @__PURE__ */ n({
1154
1164
  _bodyWritten = !1;
1155
1165
  setHeader(e, t) {
1156
1166
  if (this.headersSent) throw H(/* @__PURE__ */ Error("Cannot set headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
1157
- if (typeof e != "string" || !lt.test(e)) throw H(/* @__PURE__ */ TypeError(`Header name must be a valid HTTP token [${JSON.stringify(String(e))}]`), "ERR_INVALID_HTTP_TOKEN");
1167
+ if (typeof e != "string" || !dt.test(e)) throw H(/* @__PURE__ */ TypeError(`Header name must be a valid HTTP token [${JSON.stringify(String(e))}]`), "ERR_INVALID_HTTP_TOKEN");
1158
1168
  if (t === void 0) throw H(/* @__PURE__ */ TypeError(`Invalid value "undefined" for header "${e}"`), "ERR_HTTP_INVALID_HEADER_VALUE");
1159
1169
  return this._headerStore.set(e.toLowerCase(), [e, Array.isArray(t) ? [...t] : t]), this;
1160
1170
  }
@@ -1195,25 +1205,25 @@ var Ye = /* @__PURE__ */ n({
1195
1205
  return this._bodyWritten = !0, super.write(e, t, n);
1196
1206
  }
1197
1207
  _write(e, t, n) {
1198
- let r = pt(e), i = [];
1199
- if (this.headersSent ||= (this._implicitHeader(), i.push(m.from(this._headBlock, "latin1")), !0), this.chunkedEncoding ? r.length > 0 && (i.push(m.from(`${r.length.toString(16)}\r\n`, "latin1")), i.push(r), i.push(m.from("\r\n", "latin1"))) : i.push(r), i.length === 0) {
1208
+ let r = ht(e), i = [];
1209
+ if (this.headersSent ||= (this._implicitHeader(), i.push(h.from(this._headBlock, "latin1")), !0), this.chunkedEncoding ? r.length > 0 && (i.push(h.from(`${r.length.toString(16)}\r\n`, "latin1")), i.push(r), i.push(h.from("\r\n", "latin1"))) : i.push(r), i.length === 0) {
1200
1210
  n();
1201
1211
  return;
1202
1212
  }
1203
- this._writeToSocket(m.concat(i), n);
1213
+ this._writeToSocket(h.concat(i), n);
1204
1214
  }
1205
1215
  _final(e) {
1206
1216
  let t = [];
1207
- if (this.headersSent ||= (!this.chunkedEncoding && !this.hasHeader("content-length") && this.setHeader("Content-Length", 0), this._implicitHeader(), t.push(m.from(this._headBlock, "latin1")), !0), this.chunkedEncoding && t.push(m.from("0\r\n\r\n", "latin1")), this.finished = !0, t.length === 0) {
1217
+ if (this.headersSent ||= (!this.chunkedEncoding && !this.hasHeader("content-length") && this.setHeader("Content-Length", 0), this._implicitHeader(), t.push(h.from(this._headBlock, "latin1")), !0), this.chunkedEncoding && t.push(h.from("0\r\n\r\n", "latin1")), this.finished = !0, t.length === 0) {
1208
1218
  e();
1209
1219
  return;
1210
1220
  }
1211
- this._writeToSocket(m.concat(t), e);
1221
+ this._writeToSocket(h.concat(t), e);
1212
1222
  }
1213
1223
  end(e, t, n) {
1214
1224
  if (e != null && typeof e != "function" && !this._bodyWritten && !this.headersSent && !this.chunkedEncoding && !this.hasHeader("content-length")) {
1215
1225
  let n = typeof t == "string" ? t : void 0;
1216
- this.setHeader("Content-Length", pt(e, n).length);
1226
+ this.setHeader("Content-Length", ht(e, n).length);
1217
1227
  }
1218
1228
  return super.end(e, t, n);
1219
1229
  }
@@ -1257,12 +1267,12 @@ var Ye = /* @__PURE__ */ n({
1257
1267
  this.sendDate && !this.hasHeader("date") && this.setHeader("Date", (/* @__PURE__ */ new Date()).toUTCString()), this.hasHeader("connection") || this.setHeader("Connection", this._keepAlive ? "keep-alive" : "close"), this._headBlock = this._storeHeader(`HTTP/1.1 ${this.statusCode} ${e}`);
1258
1268
  }
1259
1269
  writeContinue() {
1260
- this._writeToSocket(m.from("HTTP/1.1 100 Continue\r\n\r\n", "latin1"), () => {});
1270
+ this._writeToSocket(h.from("HTTP/1.1 100 Continue\r\n\r\n", "latin1"), () => {});
1261
1271
  }
1262
1272
  setTimeout(e, t) {
1263
1273
  return this.socket?.setTimeout(e, t), this;
1264
1274
  }
1265
- }, mt = (...e) => {
1275
+ }, gt = (...e) => {
1266
1276
  let t = {}, n = {}, r, i = [...e], a = i.shift();
1267
1277
  if (typeof a == "string" || a instanceof URL) {
1268
1278
  let e = typeof a == "string" ? new URL(a) : a;
@@ -1306,7 +1316,7 @@ var Ye = /* @__PURE__ */ n({
1306
1316
  let e = this.protocol === "https:" && r === 443 || this.protocol !== "https:" && r === 80;
1307
1317
  this.setHeader("Host", e ? n : `${n}:${r}`);
1308
1318
  }
1309
- e.auth && !this.hasHeader("authorization") && this.setHeader("Authorization", `Basic ${m.from(e.auth).toString("base64")}`), this.socket = new F(), this.emit("socket", this.socket), this.socket.on("error", (e) => {
1319
+ e.auth && !this.hasHeader("authorization") && this.setHeader("Authorization", `Basic ${h.from(e.auth).toString("base64")}`), this.socket = new F(), this.emit("socket", this.socket), this.socket.on("error", (e) => {
1310
1320
  this._aborted || this.emit("error", e);
1311
1321
  }), this._attachResponseParser(), this.socket.connect({
1312
1322
  host: n,
@@ -1327,7 +1337,7 @@ var Ye = /* @__PURE__ */ n({
1327
1337
  e._applyHead(n), this.method === "HEAD" && (t.skipBody = !0), this.res = e, this.emit("response", e);
1328
1338
  },
1329
1339
  onBody: (t) => {
1330
- e.push(m.from(t));
1340
+ e.push(h.from(t));
1331
1341
  },
1332
1342
  onComplete: () => {
1333
1343
  e.complete = !0, e.push(null);
@@ -1381,7 +1391,7 @@ var Ye = /* @__PURE__ */ n({
1381
1391
  }), this.emit("request", t, i);
1382
1392
  },
1383
1393
  onBody: (e) => {
1384
- t?.push(m.from(e));
1394
+ t?.push(h.from(e));
1385
1395
  },
1386
1396
  onComplete: () => {
1387
1397
  t && (t.complete = !0, t.push(null)), t = null;
@@ -1403,115 +1413,116 @@ var Ye = /* @__PURE__ */ n({
1403
1413
  return `${e.host ?? "localhost"}:${e.port ?? ""}:${e.localAddress ?? ""}`;
1404
1414
  }
1405
1415
  destroy() {}
1406
- }, ht = new Y(), X = (...e) => {
1407
- let { options: t, callback: n } = mt(...e);
1416
+ }, _t = new Y(), X = (...e) => {
1417
+ let { options: t, callback: n } = gt(...e);
1408
1418
  return new q(t, n);
1409
- }, gt = (...e) => {
1419
+ }, vt = (...e) => {
1410
1420
  let t = X(...e);
1411
1421
  return t.end(), t;
1412
- }, _t = (e, t) => new J(e, t), vt = {
1413
- METHODS: st,
1422
+ }, yt = (e, t) => new J(e, t), bt = {
1423
+ METHODS: lt,
1414
1424
  STATUS_CODES: z,
1415
1425
  Agent: Y,
1416
- globalAgent: ht,
1426
+ globalAgent: _t,
1417
1427
  Server: J,
1418
1428
  ServerResponse: K,
1419
1429
  IncomingMessage: W,
1420
1430
  ClientRequest: q,
1421
1431
  OutgoingMessage: G,
1422
- createServer: _t,
1432
+ createServer: yt,
1423
1433
  request: X,
1424
- get: gt
1425
- }, yt = /* @__PURE__ */ n({
1426
- available: () => bt,
1427
- dgram: () => et,
1428
- dns: () => He,
1429
- fetch: () => Be,
1430
- http: () => at,
1431
- net: () => Ye,
1432
- quota: () => Ve
1433
- }), bt = () => Le, Z = async (e) => {
1434
+ get: vt
1435
+ }, xt = /* @__PURE__ */ n({
1436
+ available: () => St,
1437
+ dgram: () => nt,
1438
+ dns: () => We,
1439
+ fetch: () => He,
1440
+ http: () => st,
1441
+ net: () => Ze,
1442
+ quota: () => Ue
1443
+ }), St = () => ze, Z = async (e) => {
1434
1444
  if (typeof window > "u") return !1;
1435
- if (g()) return !0;
1445
+ if (_()) return !0;
1436
1446
  let t = await M, n = null, r = new Promise((e) => {
1437
1447
  n = () => {
1438
- g() && e(!0);
1439
- }, h.addEventListener("statuschange", n);
1448
+ _() && e(!0);
1449
+ }, g.addEventListener("statuschange", n);
1440
1450
  }), i = t.installPrompt.show(e).then(() => !1), a = await Promise.race([r, i]);
1441
- return n && h.removeEventListener("statuschange", n), await t.installPrompt.hide().catch(() => {}), a;
1451
+ return n && g.removeEventListener("statuschange", n), await t.installPrompt.hide().catch(() => {}), a;
1442
1452
  }, Q = null;
1443
- v(() => (Q ||= Z().then(() => void 0).finally(() => {
1453
+ y(() => (Q ||= Z().then(() => void 0).finally(() => {
1444
1454
  Q = null;
1445
1455
  }), Q));
1446
1456
  //#endregion
1447
1457
  //#region src/lib/desktop.ts
1448
- var xt = /* @__PURE__ */ n({
1449
- available: () => St,
1450
- dgram: () => Et,
1451
- dns: () => wt,
1452
- fetch: () => Ct,
1453
- fs: () => Dt,
1454
- net: () => Tt
1455
- }), St = () => !1, $ = (e) => (...t) => {
1458
+ var Ct = /* @__PURE__ */ n({
1459
+ available: () => wt,
1460
+ dgram: () => Ot,
1461
+ dns: () => Et,
1462
+ fetch: () => Tt,
1463
+ fs: () => kt,
1464
+ net: () => Dt
1465
+ }), wt = () => !1, $ = (e) => (...t) => {
1456
1466
  throw Error(`The FKN desktop app is not connected, desktop.${e} is unavailable`);
1457
- }, Ct = $("fetch"), wt = { lookup: $("dns.lookup") }, Tt = {
1467
+ }, Tt = $("fetch"), Et = { lookup: $("dns.lookup") }, Dt = {
1458
1468
  connect: $("net.connect"),
1459
1469
  createConnection: $("net.createConnection"),
1460
1470
  createServer: $("net.createServer")
1461
- }, Et = { createSocket: $("dgram.createSocket") }, Dt = {
1471
+ }, Ot = { createSocket: $("dgram.createSocket") }, kt = {
1462
1472
  isLocalDirectorySupported: () => !1,
1463
1473
  pickLocalDirectory: $("fs.pickLocalDirectory"),
1464
1474
  queryDirectoryPermission: $("fs.queryDirectoryPermission"),
1465
1475
  ensureDirectoryPermission: $("fs.ensureDirectoryPermission")
1466
- }, Ot = () => typeof document < "u" && g(), kt = async (e, t) => {
1467
- if (ze(e), t?.credentials === "include") {
1476
+ }, At = () => typeof document < "u" && _(), jt = async (e, t) => {
1477
+ if (Ve(e), t?.credentials === "include") {
1468
1478
  if (typeof document > "u") throw Error("fetch with credentials needs the FKN extension, which only exists in window realms");
1469
- return C(e, t);
1479
+ return he(e, t);
1470
1480
  }
1471
- return Ot() ? C(e, {
1481
+ return At() ? he(e, {
1472
1482
  ...t,
1473
1483
  credentials: "omit"
1474
- }) : St() ? Ct(e, t) : Be(e, t);
1475
- }, At = /* @__PURE__ */ n({
1484
+ }) : wt() ? Tt(e, t) : He(e, t);
1485
+ }, Mt = /* @__PURE__ */ n({
1476
1486
  ATTACH_FRAME_EVENT_KEY: () => w,
1477
1487
  assertAttachableFrameUrl: () => E,
1478
- assertFetchableUrl: () => S,
1479
- attachFrame: () => Se,
1480
- attachFramePermission: () => be,
1481
- available: () => Ot,
1488
+ assertFetchableUrl: () => C,
1489
+ attachFrame: () => we,
1490
+ attachFramePermission: () => xe,
1491
+ available: () => At,
1482
1492
  box: () => l,
1483
- cookies: () => ge,
1493
+ cookies: () => _e,
1484
1494
  createVideoElementHandle: () => e,
1485
- events: () => h,
1486
- extension: () => h,
1487
- fetch: () => C,
1495
+ evaluatePermission: () => Ce,
1496
+ events: () => g,
1497
+ extension: () => g,
1498
+ fetch: () => he,
1488
1499
  fetchCredentialedPermission: () => ce,
1489
1500
  fetchLocalPermission: () => le,
1490
1501
  fetchPermission: () => se,
1491
- gotoPermission: () => xe,
1502
+ gotoPermission: () => Se,
1492
1503
  handleRevivableModules: () => i,
1493
- isBlockedFetchUrl: () => x,
1504
+ isBlockedFetchUrl: () => S,
1494
1505
  isBlockedFrameUrl: () => T,
1495
- isExtensionExposed: () => g,
1506
+ isExtensionExposed: () => _,
1496
1507
  isLocalNetworkUrl: () => de,
1497
1508
  isType: () => t,
1498
- modifyRequestHeadersPermission: () => _e,
1499
- permissions: () => Ce,
1509
+ modifyRequestHeadersPermission: () => ve,
1510
+ permissions: () => Te,
1500
1511
  promptInstall: () => Z,
1501
- readCookiePermission: () => he,
1502
- removeRequestHeaderRule: () => ye,
1512
+ readCookiePermission: () => ge,
1513
+ removeRequestHeaderRule: () => be,
1503
1514
  revive: () => o,
1504
- setMissingExtensionHandler: () => v,
1505
- setRequestHeaderRule: () => ve,
1515
+ setMissingExtensionHandler: () => y,
1516
+ setRequestHeaderRule: () => ye,
1506
1517
  type: () => a,
1507
- waitForExtensionExposure: () => y
1508
- }), jt = /* @__PURE__ */ n({
1509
- ensureDirectoryPermission: () => Ft,
1510
- isLocalDirectorySupported: () => Mt,
1511
- pickLocalDirectory: () => Nt,
1512
- queryDirectoryPermission: () => Pt
1513
- }), Mt = () => typeof window < "u" && "showDirectoryPicker" in window, Nt = async (e = {}) => {
1514
- if (!Mt()) return;
1518
+ waitForExtensionExposure: () => b
1519
+ }), Nt = /* @__PURE__ */ n({
1520
+ ensureDirectoryPermission: () => Lt,
1521
+ isLocalDirectorySupported: () => Pt,
1522
+ pickLocalDirectory: () => Ft,
1523
+ queryDirectoryPermission: () => It
1524
+ }), Pt = () => typeof window < "u" && "showDirectoryPicker" in window, Ft = async (e = {}) => {
1525
+ if (!Pt()) return;
1515
1526
  let t = window.showDirectoryPicker;
1516
1527
  return t({
1517
1528
  mode: "readwrite",
@@ -1519,25 +1530,59 @@ var xt = /* @__PURE__ */ n({
1519
1530
  }).catch((e) => {
1520
1531
  if (e?.name !== "AbortError") throw e;
1521
1532
  });
1522
- }, Pt = async (e, t = "readwrite") => {
1533
+ }, It = async (e, t = "readwrite") => {
1523
1534
  let { queryPermission: n } = e;
1524
1535
  return await n?.call(e, { mode: t }) ?? "granted";
1525
- }, Ft = async (e, t = "readwrite") => {
1526
- if (await Pt(e, t) === "granted") return !0;
1536
+ }, Lt = async (e, t = "readwrite") => {
1537
+ if (await It(e, t) === "granted") return !0;
1527
1538
  let { requestPermission: n } = e;
1528
1539
  return await n?.call(e, { mode: t }) === "granted";
1529
- }, It = "https://fkn.app", Lt = (e, t) => {
1540
+ }, Rt = "https://fkn.app", zt = (e, t) => {
1530
1541
  if (typeof window > "u") throw Error("FKN @fkn/lib: relayWorker must be called from the main thread");
1531
1542
  if (!A?.contentWindow) throw Error("FKN @fkn/lib: relayWorker called before the FKN iframe was injected");
1532
- te({
1543
+ ee({
1533
1544
  receive: window,
1534
1545
  emit: A.contentWindow
1535
1546
  }, e, {
1536
1547
  key: "fkn-api",
1537
- originA: t?.originA ?? It,
1548
+ originA: t?.originA ?? Rt,
1538
1549
  originB: t?.originB ?? "*",
1539
1550
  unregisterSignal: t?.unregisterSignal
1540
1551
  });
1541
- }, Rt = async () => typeof window > "u" ? !1 : (await M).connect.prompt(location.origin).catch(() => !1);
1552
+ }, Bt = async () => typeof window > "u" ? !1 : (await M).connect.prompt(location.origin).catch(() => !1), Vt = /* @__PURE__ */ n({
1553
+ info: () => Wt,
1554
+ login: () => Ht,
1555
+ logout: () => Ut,
1556
+ onChange: () => Gt
1557
+ }), Ht = async () => typeof window > "u" ? !1 : (await M).account.login(location.origin).catch(() => !1), Ut = async () => {
1558
+ typeof window > "u" || await (await M).account.logout().catch(() => {});
1559
+ }, Wt = async () => {
1560
+ if (typeof window > "u") return null;
1561
+ let e = await M.then((e) => e.account.info()).catch(() => null);
1562
+ return e ? {
1563
+ name: e.name,
1564
+ image: e.image,
1565
+ premium: e.premium,
1566
+ premiumUntil: e.premiumUntil ? Date.parse(e.premiumUntil) : null
1567
+ } : null;
1568
+ }, Gt = async (e) => {
1569
+ if (typeof window > "u") return () => {};
1570
+ let t = await M.catch(() => null);
1571
+ if (!t) return () => {};
1572
+ let n = await t.account.onChange(e).catch(() => null);
1573
+ return typeof n == "function" ? n : () => {};
1574
+ }, Kt = "https://fkn.app", qt = (e = location.origin) => `${Kt}/connect-button?origin=${encodeURIComponent(e)}`, Jt = ({ className: e, style: t } = {}) => ne("iframe", {
1575
+ src: qt(),
1576
+ title: "Connect your FKN account",
1577
+ className: e,
1578
+ style: {
1579
+ border: "none",
1580
+ width: 150,
1581
+ height: 40,
1582
+ background: "transparent",
1583
+ colorScheme: "normal",
1584
+ ...t
1585
+ }
1586
+ });
1542
1587
  //#endregion
1543
- export { w as ATTACH_FRAME_EVENT_KEY, E as assertAttachableFrameUrl, S as assertFetchableUrl, Se as attachFrame, be as attachFramePermission, l as box, yt as cloud, Rt as connect, ge as cookies, e as createVideoElementHandle, xt as desktop, et as dgram, He as dns, At as extension, kt as fetch, ce as fetchCredentialedPermission, le as fetchLocalPermission, se as fetchPermission, jt as fs, xe as gotoPermission, i as handleRevivableModules, at as http, x as isBlockedFetchUrl, T as isBlockedFrameUrl, g as isExtensionExposed, de as isLocalNetworkUrl, t as isType, _e as modifyRequestHeadersPermission, Ye as net, Ce as permissions, Z as promptInstall, he as readCookiePermission, Lt as relayWorker, ye as removeRequestHeaderRule, o as revive, v as setMissingExtensionHandler, ve as setRequestHeaderRule, a as type, y as waitForExtensionExposure };
1588
+ export { w as ATTACH_FRAME_EVENT_KEY, Jt as ConnectButton, Vt as account, E as assertAttachableFrameUrl, C as assertFetchableUrl, we as attachFrame, xe as attachFramePermission, l as box, xt as cloud, Bt as connect, qt as connectButtonUrl, _e as cookies, e as createVideoElementHandle, Ct as desktop, nt as dgram, We as dns, Ce as evaluatePermission, Mt as extension, jt as fetch, ce as fetchCredentialedPermission, le as fetchLocalPermission, se as fetchPermission, Nt as fs, Se as gotoPermission, i as handleRevivableModules, st as http, S as isBlockedFetchUrl, T as isBlockedFrameUrl, _ as isExtensionExposed, de as isLocalNetworkUrl, t as isType, ve as modifyRequestHeadersPermission, Ze as net, Te as permissions, Z as promptInstall, ge as readCookiePermission, zt as relayWorker, be as removeRequestHeaderRule, o as revive, y as setMissingExtensionHandler, ye as setRequestHeaderRule, a as type, b as waitForExtensionExposure };