@fkn/lib 0.0.2 → 0.0.3

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,3 @@
1
1
  export declare const isWorker: boolean;
2
- export declare const createdIframe: HTMLIFrameElement;
3
- export declare const foundIframe: HTMLIFrameElement;
4
2
  export declare const iframe: HTMLIFrameElement;
5
3
  export declare const targetWindow: Window | null;
package/build/index.js CHANGED
@@ -1,35 +1,35 @@
1
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) {
2
+ let f, o;
3
+ const h = () => (o = new Promise((e, t) => {
4
+ f = e;
5
+ }), o), T = h(), m = async (e) => {
6
+ e === T && h(), f(await e);
7
+ }, g = "https://fkn.app", b = globalThis.window === void 0, c = globalThis?.document.querySelector(`iframe[src="${g}/sandbox-api"]`), a = globalThis.document?.createElement("iframe");
8
+ !c && a && (a.src = `${g}/sandbox-api`, a.style.display = "none", document.body.appendChild(a));
9
+ const y = c || a, p = y?.contentWindow, k = (e) => m(e), w = () => o, u = async () => d(await w(), { key: "fkn-sandbox-api" })("API_PORT", {});
10
+ if (b) {
11
11
  let e = !1;
12
- a.then(() => {
12
+ o.then(() => {
13
13
  e = !0;
14
14
  }), setTimeout(() => {
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 (!c)
18
+ if (!y)
19
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
- });
20
+ const e = setInterval(
21
+ () => d(p, { key: "fkn-sandbox" })("APP_READY", {}).then(() => {
22
+ m(p), clearInterval(e);
23
+ }).catch(() => {
24
+ console.warn("Failed to connect to sandbox, trying again in 10ms");
25
+ }),
26
+ 10
27
+ );
28
28
  }
29
29
  const l = (e, t) => w().then(
30
30
  (s) => d(s, { key: "fkn-sandbox-api" })(e, t)
31
31
  ), E = async (e, t) => {
32
- const s = e, o = t, { body: i, ...n } = await l("SERVER_PROXY_FETCH", { input: s, init: o });
32
+ const s = e, r = t, { body: i, ...n } = await l("SERVER_PROXY_FETCH", { input: s, init: r });
33
33
  return new Response(
34
34
  i,
35
35
  {
@@ -42,8 +42,8 @@ const l = (e, t) => w().then(
42
42
  }
43
43
  }
44
44
  );
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 });
45
+ }, P = async ({ magnet: e, path: t, offset: s, end: r }) => {
46
+ const { body: i, ...n } = await l("TORRENT", { magnet: e, path: t, offset: s, end: r });
47
47
  return new Response(
48
48
  i,
49
49
  {
@@ -51,7 +51,7 @@ const l = (e, t) => w().then(
51
51
  headers: Object.fromEntries(n.headers)
52
52
  }
53
53
  );
54
- }, u = async ({ magnet: e }) => {
54
+ }, I = async ({ magnet: e }) => {
55
55
  const { body: t, ...s } = await l("TORRENT_FILE", { magnet: e });
56
56
  return new Response(
57
57
  t,
@@ -63,9 +63,9 @@ const l = (e, t) => w().then(
63
63
  };
64
64
  export {
65
65
  w as getApiTarget,
66
- k as getApiTargetPort,
66
+ u as getApiTargetPort,
67
67
  E as serverProxyFetch,
68
- b as setApiTarget,
68
+ k as setApiTarget,
69
69
  P as torrent,
70
- u as torrentFile
70
+ I as torrentFile
71
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fkn/lib",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "build/index.js",
5
5
  "types": "build/index.d.ts",
6
6
  "type": "module",
@@ -17,6 +17,7 @@
17
17
  "scripts": {
18
18
  "dev": "concurrently \"vite build --watch --mode development\" \"tsc --watch\"",
19
19
  "build": "vite build && tsc",
20
+ "build-watch": "vite build --watch --mode production && tsc",
20
21
  "build-dev": "vite build --mode development && tsc",
21
22
  "dev-watch": "vite build --watch --mode development",
22
23
  "build-types": "tsc"