@fkn/lib 0.0.1 → 0.0.2

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/build/dom.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare const isWorker: boolean;
2
- export declare const foundIframe: HTMLIFrameElement | null;
3
- export declare const createdIframe: HTMLIFrameElement | undefined;
4
- export declare const iframe: HTMLIFrameElement | undefined;
5
- export declare const targetWindow: Window | null | undefined;
2
+ export declare const createdIframe: HTMLIFrameElement;
3
+ export declare const foundIframe: HTMLIFrameElement;
4
+ export declare const iframe: HTMLIFrameElement;
5
+ export declare const targetWindow: Window | null;
package/build/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import { call as w } from "osra";
2
- let f, a;
3
- const g = () => (a = new Promise((e, t) => {
4
- f = e;
5
- }), a), m = g(), l = async (e) => {
6
- e === m && g(), f(await e);
7
- }, T = "https://fkn.app", y = globalThis.window === void 0, h = globalThis.document?.body.querySelector(`iframe[src="${`${T}/sandbox-api`}"]`), s = h ? void 0 : globalThis.document?.createElement("iframe");
8
- s && (s.src = `${T}/sandbox-api`, s.style.display = "none", document.body.appendChild(s));
9
- const c = globalThis.window?.parent === globalThis.window ? h ?? s : void 0, r = globalThis.window?.parent === globalThis.window ? c?.contentWindow : globalThis.window?.parent, k = (e) => l(e), b = () => a, E = async () => w(await b(), { key: "fkn-sandbox-api" })("API_PORT", {});
10
- if (y) {
1
+ import { call as d } from "osra";
2
+ let h, a;
3
+ const f = () => (a = new Promise((e, t) => {
4
+ h = e;
5
+ }), a), y = f(), m = async (e) => {
6
+ e === y && f(), h(await e);
7
+ }, g = "https://fkn.app", T = globalThis.window === void 0, r = globalThis.document?.createElement("iframe");
8
+ r && (r.src = `${g}/sandbox-api`, r.style.display = "none", document.body.appendChild(r));
9
+ const c = r, p = c?.contentWindow, b = (e) => m(e), w = () => a, k = async () => d(await w(), { key: "fkn-sandbox-api" })("API_PORT", {});
10
+ if (T) {
11
11
  let e = !1;
12
12
  a.then(() => {
13
13
  e = !0;
@@ -15,62 +15,57 @@ if (y) {
15
15
  e || console.warn("@fkn/lib's api target has not resolved after 250ms while in a worker, make sure to call `setApiTarget(messagePort)`");
16
16
  }, 250);
17
17
  } else {
18
- if (!r)
19
- throw new Error("Missing target window on non worker thread");
20
- if (window.parent === window && !h) {
21
- if (!c)
22
- throw new Error("Missing appended iframe");
23
- c.addEventListener("load", () => {
24
- const e = setInterval(
25
- () => w(r, { key: "fkn-sandbox" })("APP_READY", {}).then(() => {
26
- l(r), clearInterval(e);
27
- }),
28
- 10
29
- );
30
- });
31
- } else
32
- l(r);
18
+ if (!c)
19
+ throw new Error("Missing appended iframe");
20
+ c.addEventListener("load", () => {
21
+ const e = setInterval(
22
+ () => d(p, { key: "fkn-sandbox" })("APP_READY", {}).then(() => {
23
+ m(p), clearInterval(e);
24
+ }),
25
+ 10
26
+ );
27
+ });
33
28
  }
34
- const p = (e, t) => b().then(
35
- (n) => w(n, { key: "fkn-sandbox-api" })(e, t)
36
- ), u = async (e, t) => {
37
- const n = e, i = t, { body: d, ...o } = await p("SERVER_PROXY_FETCH", { input: n, init: i });
29
+ const l = (e, t) => w().then(
30
+ (s) => d(s, { key: "fkn-sandbox-api" })(e, t)
31
+ ), E = async (e, t) => {
32
+ const s = e, o = t, { body: i, ...n } = await l("SERVER_PROXY_FETCH", { input: s, init: o });
38
33
  return new Response(
39
- d,
34
+ i,
40
35
  {
41
- ...o,
36
+ ...n,
42
37
  headers: {
43
- ...o.headers,
44
- ...o.headers && {
45
- setCookie: o.headers["set-cookie"]
38
+ ...n.headers,
39
+ ...n.headers && {
40
+ setCookie: n.headers["set-cookie"]
46
41
  }
47
42
  }
48
43
  }
49
44
  );
50
- }, v = async ({ magnet: e, path: t, offset: n, end: i }) => {
51
- const { body: d, ...o } = await p("TORRENT", { magnet: e, path: t, offset: n, end: i });
45
+ }, P = async ({ magnet: e, path: t, offset: s, end: o }) => {
46
+ const { body: i, ...n } = await l("TORRENT", { magnet: e, path: t, offset: s, end: o });
52
47
  return new Response(
53
- d,
48
+ i,
54
49
  {
55
- ...o,
56
- headers: Object.fromEntries(o.headers)
50
+ ...n,
51
+ headers: Object.fromEntries(n.headers)
57
52
  }
58
53
  );
59
- }, P = async ({ magnet: e }) => {
60
- const { body: t, ...n } = await p("TORRENT_FILE", { magnet: e });
54
+ }, u = async ({ magnet: e }) => {
55
+ const { body: t, ...s } = await l("TORRENT_FILE", { magnet: e });
61
56
  return new Response(
62
57
  t,
63
58
  {
64
- ...n,
65
- headers: Object.fromEntries(n.headers)
59
+ ...s,
60
+ headers: Object.fromEntries(s.headers)
66
61
  }
67
62
  );
68
63
  };
69
64
  export {
70
- b as getApiTarget,
71
- E as getApiTargetPort,
72
- u as serverProxyFetch,
73
- k as setApiTarget,
74
- v as torrent,
75
- P as torrentFile
65
+ w as getApiTarget,
66
+ k as getApiTargetPort,
67
+ E as serverProxyFetch,
68
+ b as setApiTarget,
69
+ P as torrent,
70
+ u as torrentFile
76
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fkn/lib",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "main": "build/index.js",
5
5
  "types": "build/index.d.ts",
6
6
  "type": "module",