@fkn/lib 0.9.9 → 0.9.10

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,4 +1,4 @@
1
- import { D as InstalledPackage, E as InstallOptions, M as PickOptions, N as Placement, O as PackageQuery, T as ConnectOptions, j as PackagesFail, k as PackageResult, w as Caller } from "./packages-BtbLwrrW.js";
1
+ import { A as InstallOptions, D as MountDescriptor, F as PackagesFail, I as PickOptions, L as Placement, M as PackageQuery, N as PackageResult, O as Caller, j as InstalledPackage, k as ConnectOptions } from "./packages-B03jnjRB.js";
2
2
  import { t as AddressLookupResult } from "./lookup-BtwWaCZJ.js";
3
3
  //#region src/api/storage.d.ts
4
4
  type StorageEntry = {
@@ -559,7 +559,7 @@ type DataPlane = typeof dataPlane;
559
559
  //#endregion
560
560
  //#region src/api/index.d.ts
561
561
  type Cloud = DataPlane['cloud'];
562
- declare const makeResolvers: (callerOf: () => Caller | undefined) => {
562
+ declare const makeResolvers: (callerOf: () => Caller | undefined, ownsOverlay?: boolean) => {
563
563
  readonly cloud: {
564
564
  readonly fetch: (input: Parameters<Cloud['fetch']>[0], init: Parameters<Cloud['fetch']>[1]) => Promise<Response>;
565
565
  readonly quota: () => Promise<Quota>;
@@ -675,6 +675,7 @@ declare const makeResolvers: (callerOf: () => Caller | undefined) => {
675
675
  } | {
676
676
  declined: true;
677
677
  }>;
678
+ frame: (uri: string) => Promise<MountDescriptor | PackagesFail>;
678
679
  list: () => Promise<{
679
680
  results: InstalledPackage[];
680
681
  }>;
package/cloud/fetch.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { t as cloudFetch } from "../proxy-BypE6RbM.js";
1
+ import { t as cloudFetch } from "../proxy-DasMm1_q.js";
2
2
  export { cloudFetch as fetch };
package/cloud/net.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as createConnection, c as isIP, i as connect, l as isIPv4, n as Socket, o as createServer, r as _default, t as Server, u as isIPv6 } from "../net-BKkf8QK3.js";
1
+ import { a as createConnection, c as isIP, i as connect, l as isIPv4, n as Socket, o as createServer, r as _default, t as Server, u as isIPv6 } from "../net-Q7SIsTHJ.js";
2
2
  export { Server, Socket, _default, _default as default, connect, createConnection, createServer, isIP, isIPv4, isIPv6 };
@@ -1,8 +1,8 @@
1
- import { t as cloudFetch } from "./proxy-BypE6RbM.js";
1
+ import { t as cloudFetch } from "./proxy-DasMm1_q.js";
2
2
  import { d as Frame, u as AttachFrameOptions } from "./index-DQfP-Uhy.js";
3
3
  import { t as dns_d_exports } from "./dns.js";
4
4
  import { n as fs_d_exports } from "./fs-DTmSCXwa.js";
5
- import { s as net_d_exports } from "./net-BKkf8QK3.js";
5
+ import { s as net_d_exports } from "./net-Q7SIsTHJ.js";
6
6
  import { t as dgram_d_exports } from "./dgram.js";
7
7
  import { t as http_d_exports } from "./http.js";
8
8
 
package/cloud.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { t as cloudFetch } from "./proxy-BypE6RbM.js";
2
- import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-CWJO6Q8h.js";
1
+ import { t as cloudFetch } from "./proxy-DasMm1_q.js";
2
+ import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-DJARSquk.js";
3
3
  import { t as dns_d_exports } from "./dns.js";
4
4
  import { n as fs_d_exports } from "./fs-DTmSCXwa.js";
5
- import { s as net_d_exports } from "./net-BKkf8QK3.js";
5
+ import { s as net_d_exports } from "./net-Q7SIsTHJ.js";
6
6
  import { t as dgram_d_exports } from "./dgram.js";
7
7
  import { t as http_d_exports } from "./http.js";
8
8
  export { type QuotaStatus, attachFrame, available, dgram_d_exports as dgram, dns_d_exports as dns, cloudFetch as fetch, fs_d_exports as fs, http_d_exports as http, net_d_exports as net, quota };
package/dgram.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as UdpSocketOption, t as Resolvers } from "./api-BYRsWdwB.js";
1
+ import { n as UdpSocketOption, t as Resolvers } from "./api-Dn793vCK.js";
2
2
  import { Buffer } from "buffer";
3
3
  import { AddressInfo } from "net";
4
4
  import { EventEmitter } from "events";
package/http.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as Socket, t as Server$1 } from "./net-BKkf8QK3.js";
1
+ import { n as Socket, t as Server$1 } from "./net-Q7SIsTHJ.js";
2
2
  import { Buffer } from "buffer";
3
3
  import { Stream } from "stream";
4
4
  import { IncomingHttpHeaders, OutgoingHttpHeaders, RequestOptions } from "http";
package/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { t as account_d_exports } from "./account.js";
2
- import { y as packages_d_exports } from "./packages-BtbLwrrW.js";
2
+ import { S as packages_d_exports } from "./packages-B03jnjRB.js";
3
3
  import { A as LOCATOR_DENIED, B as SelectorPart, C as RemoteVideoElement, D as isType, E as createVideoElementHandle, F as isTerminalError, G as setRequestHeaderRule, H as RequestHeaderRule, I as Executor, J as cookies, K as CookieDetails, L as Gate, M as LOCATOR_UNSUPPORTED, N as isLocatorDenied, O as revive, P as isLocatorUnsupported, Q as assertFetchableUrl, R as GateTools, S as BoxedVideoElement, T as box, U as modifyRequestHeadersPermission, V as HeaderOperation, W as removeRequestHeaderRule, X as FetchInit, Y as readCookiePermission, Z as ProxyFetchRequest, _ as gotoPermission, a as PermissionGrant, at as FORGEABLE_HEADERS, b as isBlockedFrameUrl, c as ATTACH_FRAME_EVENT_KEY, ct as hasForgedCookie, d as Frame, et as fetchCredentialedPermission, f as FrameBackend, g as createFrame, h as attachFramePermission, i as waitForExtensionExposure, it as isLocalNetworkUrl, j as LOCATOR_ERROR, k as type, m as Locator, n as isExtensionExposed, nt as fetchPermission, o as PermissionRequest, ot as assertForgeableHeaders, p as GotoOptions, q as SiteCookie, r as setMissingExtensionHandler, rt as isBlockedFetchUrl, s as permissions, st as assertOneCookieIdentity, tt as fetchLocalPermission, u as AttachFrameOptions, v as assertAttachableFrameUrl, w as VideoElementState, x as handleRevivableModules, y as assertLockdownApplicable, z as OperationRequest } from "./index-DQfP-Uhy.js";
4
- import { n as cloud_d_exports } from "./cloud-CWJO6Q8h.js";
4
+ import { n as cloud_d_exports } from "./cloud-DJARSquk.js";
5
5
  import { t as dns_d_exports } from "./dns.js";
6
- import { s as net_d_exports } from "./net-BKkf8QK3.js";
6
+ import { s as net_d_exports } from "./net-Q7SIsTHJ.js";
7
7
  import { t as dgram_d_exports } from "./dgram.js";
8
8
  import { t as http_d_exports } from "./http.js";
9
9
  import { t as desktop_d_exports } from "./desktop.js";
@@ -1,4 +1,4 @@
1
- import { i as TcpSocketOption, r as LocalTcpSocket, t as Resolvers } from "./api-BYRsWdwB.js";
1
+ import { i as TcpSocketOption, r as LocalTcpSocket, t as Resolvers } from "./api-Dn793vCK.js";
2
2
  import { AddressInfo, ListenOptions, Server, ServerOpts, Socket, SocketConnectOpts, SocketConstructorOpts } from "net";
3
3
  import { DuplexOptions, Stream } from "stream";
4
4
  import { EventEmitter } from "events";
package/net.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as createConnection, c as isIP, i as connect, l as isIPv4, n as Socket, o as createServer, r as _default, t as Server, u as isIPv6 } from "./net-BKkf8QK3.js";
1
+ import { a as createConnection, c as isIP, i as connect, l as isIPv4, n as Socket, o as createServer, r as _default, t as Server, u as isIPv6 } from "./net-Q7SIsTHJ.js";
2
2
  export { Server, Socket, _default, _default as default, connect, createConnection, createServer, isIP, isIPv4, isIPv6 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fkn/lib",
3
- "version": "0.9.9",
3
+ "version": "0.9.10",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",
@@ -70,10 +70,27 @@ type PackagesFail = {
70
70
  */
71
71
  type Caller = {
72
72
  id: string;
73
- origin: string;
73
+ origin: string; /** a package's display name, when provenance knew it. Attribution only, never an identity. */
74
+ name?: string;
75
+ /**
76
+ * Set when PROVENANCE established this caller is a package, which is the only way to know it for a
77
+ * connection whose `origin` is this realm's own (a broker nested inside a tenant we mounted). Every
78
+ * other package caller is recognised from its browser-set tenant origin instead.
79
+ */
80
+ isPackage?: boolean;
81
+ };
82
+ //#endregion
83
+ //#region src/api/packages/host.d.ts
84
+ type MountDescriptor = {
85
+ /** where to point the iframe: the tenant origin plus the package's path */url: string; /** the tenant origin alone, which is what a `postMessage` to that frame must target */
86
+ origin: string; /** the version-free identity, echoed to the package in the port message */
87
+ uri: string;
88
+ name: string;
89
+ version: string | null; /** the connecting app, as the BROKER knows it */
90
+ from: string;
74
91
  };
75
92
  declare namespace packages_d_exports {
76
- export { AppConnectOptions, Connect, ConnectOptions, ConnectPayload, IncomingConnection, IncomingConnectionInfo, InstallOptions, InstalledPackage, PackageConnection, PackageQuery, PackageResult, PackageView, PackagesError, PackagesErrorCode, PickOptions, Placement, Radii, RawPackageConnection, ShowOptions, SurfaceRect, attach, connect, hide, install, isVisible, list, onConnect, onVisibilityChange, pick, search, show, uninstall };
93
+ export { AppConnectOptions, Connect, ConnectOptions, ConnectPayload, IncomingConnection, IncomingConnectionInfo, InstallOptions, InstalledPackage, MountOptions, MountedPackage, PackageConnection, PackageQuery, PackageResult, PackageView, PackagesError, PackagesErrorCode, PickOptions, Placement, Radii, RawPackageConnection, ShowOptions, SurfaceRect, attach, connect, hide, install, isVisible, list, mount, onConnect, onVisibilityChange, pick, search, show, uninstall };
77
94
  }
78
95
  type PackagesError = Error & {
79
96
  code: PackagesErrorCode;
@@ -135,6 +152,24 @@ type Connect = {
135
152
  };
136
153
  /** Connect to an installed package. Throws a PackagesError with code 'not-installed' when it is not. */
137
154
  declare const connect: Connect;
155
+ type MountOptions = AppConnectOptions & {
156
+ /** where the package's frame goes; it is appended here and fills it */element: Element;
157
+ };
158
+ type MountedPackage<T = unknown> = PackageConnection<T> & {
159
+ /** the frame in YOUR document. Style it, move it, fullscreen it: the broker does not own it */frame: HTMLIFrameElement; /** remove the frame and settle `closed` */
160
+ unmount: () => void;
161
+ };
162
+ /**
163
+ * Mount a package's frame in YOUR document and connect to it, instead of positioning a frame the broker
164
+ * owns and clipping the overlay to it the way `show()` does.
165
+ *
166
+ * The frame is an ordinary element: it lays out, scrolls, stacks and fullscreens with the rest of your
167
+ * page, and there is no geometry to translate, which is what makes this work from an app that is itself
168
+ * embedded. The package still gets its own origin and its own broker connection.
169
+ *
170
+ * Needs a package built against this version of the lib: an older one only accepts a port from fkn.app.
171
+ */
172
+ declare const mount: <T = unknown>(uri: string, options: MountOptions) => Promise<MountedPackage<T>>;
138
173
  /** Run this end of an already-brokered connection port, e.g. after transferring it into a worker. */
139
174
  declare const attach: <T = unknown>(port: MessagePort, payload?: unknown, options?: {
140
175
  signal?: AbortSignal;
@@ -167,4 +202,4 @@ declare const onVisibilityChange: (handler: (visible: boolean) => void) => {
167
202
  unsubscribe: () => void;
168
203
  };
169
204
  //#endregion
170
- export { PackagesErrorCode as A, uninstall as C, InstalledPackage as D, InstallOptions as E, SurfaceRect as F, PickOptions as M, Placement as N, PackageQuery as O, Radii as P, show as S, ConnectOptions as T, onConnect as _, IncomingConnectionInfo as a, pick as b, PackagesError as c, attach as d, connect as f, list as g, isVisible as h, IncomingConnection as i, PackagesFail as j, PackageResult as k, RawPackageConnection as l, install as m, Connect as n, PackageConnection as o, hide as p, ConnectPayload as r, PackageView as s, AppConnectOptions as t, ShowOptions as u, onVisibilityChange as v, Caller as w, search as x, packages_d_exports as y };
205
+ export { InstallOptions as A, pick as C, MountDescriptor as D, uninstall as E, PackagesFail as F, PickOptions as I, Placement as L, PackageQuery as M, PackageResult as N, Caller as O, PackagesErrorCode as P, Radii as R, packages_d_exports as S, show as T, isVisible as _, IncomingConnectionInfo as a, onConnect as b, PackageConnection as c, RawPackageConnection as d, ShowOptions as f, install as g, hide as h, IncomingConnection as i, InstalledPackage as j, ConnectOptions as k, PackageView as l, connect as m, Connect as n, MountOptions as o, attach as p, ConnectPayload as r, MountedPackage as s, AppConnectOptions as t, PackagesError as u, list as v, search as w, onVisibilityChange as x, mount as y, SurfaceRect as z };
package/packages.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-dp9SlXVw.cjs");let n=require("osra");var r=e.t({attach:()=>E,connect:()=>T,hide:()=>w,install:()=>p,isVisible:()=>B,list:()=>m,onConnect:()=>z,onVisibilityChange:()=>V,pick:()=>f,search:()=>d,show:()=>C,uninstall:()=>h}),i=`https://fkn.app`,a=`fkn-packages-connection`,o=3e4,s=(e,t)=>Object.assign(Error(t),{code:e}),c=async()=>{if(!t.r)throw s(`unavailable`,`packages: no FKN transport in this realm - use relayWorker to bridge workers`);return t.t},l=(e,t,r)=>(0,n.expose)(e??{},{transport:t,key:a,unregisterSignal:r}),u=async(e,t,n={})=>{let{signal:r,closed:i}=n;if(r?.aborted)throw s(`unavailable`,`packages.connect: aborted before connecting`);let a=new AbortController;r&&r.addEventListener(`abort`,()=>a.abort(r.reason),{once:!0});let c=new AbortController,u=new Promise((e,n)=>{let a=setTimeout(()=>n(s(`timeout`,`packages.connect: the package did not complete the connection`)),o);c.signal.addEventListener(`abort`,()=>clearTimeout(a),{once:!0}),t.addEventListener(`message`,e=>{if(e.data?.type===`fkn-packages-nack`){let t=e.data.message;n(s(`unavailable`,typeof t==`string`&&t?t:`packages.connect: the package refused the connection`))}},{signal:c.signal}),t.start(),r&&r.addEventListener(`abort`,()=>n(s(`unavailable`,`packages.connect: aborted before connecting`)),{once:!0,signal:c.signal}),i?.then(()=>n(s(`unavailable`,`packages.connect: the package closed before connecting`)))});try{return await Promise.race([l(e,t,a.signal),u])}catch(e){a.abort(e);try{t.close()}catch{}throw e}finally{c.abort()}},d=async e=>{let t=await(await c()).packages.search(e);if(`error`in t)throw s(t.error,t.message);return t.results},f=async(e,t)=>{let n=await(await c()).packages.pick(e,t);if(`error`in n)throw s(n.error,n.message);return`declined`in n?[]:n.results},p=async(e,t)=>{let n=await(await c()).packages.install(e,t);if(`error`in n)throw s(n.error,n.message);return`declined`in n?null:n.installed},m=async()=>(await(await c()).packages.list()).results,h=async e=>{let t=await(await c()).packages.uninstall(e);if(`error`in t)throw s(t.error,t.message)},g=({x:e,y:t,width:n,height:r})=>({x:Math.round(e),y:Math.round(t),width:Math.round(n),height:Math.round(r)}),_=(e,t)=>{let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y);return{x:n,y:r,width:Math.max(0,Math.min(e.x+e.width,t.x+t.width)-n),height:Math.max(0,Math.min(e.y+e.height,t.y+t.height)-r)}},v=(e,t)=>{let n=t;for(let t=e.parentElement;t;t=t.parentElement){let e=getComputedStyle(t);if(!(e.overflowX===`visible`&&e.overflowY===`visible`)&&(n=_(n,g(t.getBoundingClientRect())),n.width===0||n.height===0))break}return n},y=e=>{let t=getComputedStyle(e),n=[t.borderTopLeftRadius,t.borderTopRightRadius,t.borderBottomRightRadius,t.borderBottomLeftRadius];if(n.some(e=>e.includes(`%`)||e.includes(` `)))return;let r=n.map(e=>{let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:0});return r.some(e=>e>0)?r:void 0},b=(e,t)=>{if(!e)return!1;let n=(e,t)=>e===t||!!e&&!!t&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height;return n(e.rect,t.rect)&&n(e.clip,t.clip)&&((e,t)=>e===t||!!e&&!!t&&e.every((e,n)=>e===t[n]))(e.radius,t.radius)},x=new Map,S=async(e,t)=>{let n=x.get(e);if(n){for(let e of n)t&&e.element!==t||(e.stop(),n.delete(e));if(n.size>0)return;x.delete(e)}let r=await(await c()).packages.hide(e);if(`error`in r)throw s(r.error,r.message)},C=async(e,t)=>{let{element:n,rect:r}=t;if(!n&&!r)throw s(`invalid`,`packages.show: pass an element or a rect`);let i=(await c()).packages,a=()=>{if(!n)return{rect:g(r)};let e=g(n.getBoundingClientRect());return{rect:e,clip:v(n,e),radius:y(n)}},o=!0,l,u=0,d=async t=>{l=t;let n=await i.show(e,t);if(`error`in n)throw o=!1,s(n.error,n.message)};await d(a());let f=()=>{if(!o)return;let e=a();b(l,e)||d(e).catch(()=>{}),u=requestAnimationFrame(f)};n&&(u=requestAnimationFrame(f));let p={element:n,stop:()=>{o=!1,cancelAnimationFrame(u)}},m=x.get(e)??new Set;return m.add(p),x.set(e,m),{hide:()=>{S(e,n).catch(()=>{})},refresh:()=>{if(!o)return;let e=a();b(l,e)||d(e).catch(()=>{})}}},w=async(e,t={})=>S(e,t.element),T=(async(e,t={})=>{let n=await(await c()).packages.connect(e,{protocol:t.protocol});if(`error`in n)throw s(n.error,n.message);let{port:r,closed:i}=n;if(t.raw)return{closed:i,port:r};let a=await u(t.payload,r,{signal:t.signal,closed:i});return t.signal&&t.signal.addEventListener(`abort`,()=>{try{r.postMessage({type:`fkn-packages-disconnect`})}catch{}},{once:!0}),{remote:a,closed:i,port:r}}),E=(e,t,n)=>u(t,e,{signal:n?.signal}),D=null,O=!1,k=new Set,A=[],j=new Map,M=!1,N=!1,P=e=>{let t=j.get(e);t&&(j.delete(e),t())},F=(e,t)=>{try{e.postMessage({type:`fkn-packages-nack`,message:t})}catch{}try{e.close()}catch{}},I=async(e,t)=>{let{port:n,...r}=e;e.port.addEventListener(`message`,t=>{t.data?.type===`fkn-packages-disconnect`&&P(e.port)});let i;try{i=await t.createPayload(r)}catch(t){throw F(e.port,t instanceof Error?t.message:`the package failed to produce a connection`),t}let a=new Promise(t=>j.set(e.port,t)),o=await l(i,e.port);t.handler?.({...r,remote:o,closed:a,port:e.port})},L=()=>{M||typeof window>`u`||window.parent===window||(M=!0,window.addEventListener(`message`,e=>{if(e.source!==window.parent||e.origin!==i)return;let t=e.data;if(t?.type===`fkn-packages-port`){let n=e.ports[0];if(!n)return;let r={port:n,from:typeof t.from==`string`?t.from:``,protocol:typeof t.protocol==`string`?t.protocol:null,uri:typeof t.uri==`string`?t.uri:``,name:typeof t.name==`string`?t.name:``,version:typeof t.version==`string`?t.version:``};D?I(r,D).catch(e=>console.warn(`packages.onConnect:`,e)):A.push(r)}if(t?.type===`fkn-packages-close`)for(let e of[...j.keys()])P(e);if(t?.type===`fkn-packages-visibility`){O=t.visible===!0;for(let e of k)try{e(O)}catch{}}}))},R=()=>{N||typeof window>`u`||window.parent===window||(N=!0,window.parent.postMessage({type:`fkn-packages-ready`},i))},z=(e,t)=>{if(typeof window>`u`)return{unsubscribe:()=>{}};L();let n={createPayload:e,handler:t};for(D=n,R();A.length&&D===n;)I(A.shift(),n).catch(e=>console.warn(`packages.onConnect:`,e));return{unsubscribe:()=>{D===n&&(D=null)}}},B=()=>O,V=e=>{if(typeof window>`u`)return{unsubscribe:()=>{}};L(),k.add(e);try{e(O)}catch{}return{unsubscribe:()=>{k.delete(e)}}};exports.attach=E,exports.connect=T,exports.hide=w,exports.install=p,exports.isVisible=B,exports.list=m,exports.onConnect=z,exports.onVisibilityChange=V,exports.pick=f,exports.search=d,exports.show=C,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}}),exports.uninstall=h;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-dp9SlXVw.cjs");let n=require("osra");var r=e.t({attach:()=>O,connect:()=>w,hide:()=>C,install:()=>f,isVisible:()=>H,list:()=>p,mount:()=>D,onConnect:()=>V,onVisibilityChange:()=>U,pick:()=>d,search:()=>u,show:()=>S,uninstall:()=>m}),i=`fkn-packages-connection`,a=3e4,o=(e,t)=>Object.assign(Error(t),{code:e}),s=async()=>{if(!t.r)throw o(`unavailable`,`packages: no FKN transport in this realm - use relayWorker to bridge workers`);return t.t},c=(e,t,r)=>(0,n.expose)(e??{},{transport:t,key:i,unregisterSignal:r}),l=async(e,t,n={})=>{let{signal:r,closed:i}=n;if(r?.aborted)throw o(`unavailable`,`packages.connect: aborted before connecting`);let s=new AbortController;r&&r.addEventListener(`abort`,()=>s.abort(r.reason),{once:!0});let l=new AbortController,u=new Promise((e,n)=>{let s=setTimeout(()=>n(o(`timeout`,`packages.connect: the package did not complete the connection`)),a);l.signal.addEventListener(`abort`,()=>clearTimeout(s),{once:!0}),t.addEventListener(`message`,e=>{if(e.data?.type===`fkn-packages-nack`){let t=e.data.message;n(o(`unavailable`,typeof t==`string`&&t?t:`packages.connect: the package refused the connection`))}},{signal:l.signal}),t.start(),r&&r.addEventListener(`abort`,()=>n(o(`unavailable`,`packages.connect: aborted before connecting`)),{once:!0,signal:l.signal}),i?.then(()=>n(o(`unavailable`,`packages.connect: the package closed before connecting`)))});try{return await Promise.race([c(e,t,s.signal),u])}catch(e){s.abort(e);try{t.close()}catch{}throw e}finally{l.abort()}},u=async e=>{let t=await(await s()).packages.search(e);if(`error`in t)throw o(t.error,t.message);return t.results},d=async(e,t)=>{let n=await(await s()).packages.pick(e,t);if(`error`in n)throw o(n.error,n.message);return`declined`in n?[]:n.results},f=async(e,t)=>{let n=await(await s()).packages.install(e,t);if(`error`in n)throw o(n.error,n.message);return`declined`in n?null:n.installed},p=async()=>(await(await s()).packages.list()).results,m=async e=>{let t=await(await s()).packages.uninstall(e);if(`error`in t)throw o(t.error,t.message)},h=({x:e,y:t,width:n,height:r})=>({x:Math.round(e),y:Math.round(t),width:Math.round(n),height:Math.round(r)}),g=(e,t)=>{let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y);return{x:n,y:r,width:Math.max(0,Math.min(e.x+e.width,t.x+t.width)-n),height:Math.max(0,Math.min(e.y+e.height,t.y+t.height)-r)}},_=(e,t)=>{let n=t;for(let t=e.parentElement;t;t=t.parentElement){let e=getComputedStyle(t);if(!(e.overflowX===`visible`&&e.overflowY===`visible`)&&(n=g(n,h(t.getBoundingClientRect())),n.width===0||n.height===0))break}return n},v=e=>{let t=getComputedStyle(e),n=[t.borderTopLeftRadius,t.borderTopRightRadius,t.borderBottomRightRadius,t.borderBottomLeftRadius];if(n.some(e=>e.includes(`%`)||e.includes(` `)))return;let r=n.map(e=>{let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:0});return r.some(e=>e>0)?r:void 0},y=(e,t)=>{if(!e)return!1;let n=(e,t)=>e===t||!!e&&!!t&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height;return n(e.rect,t.rect)&&n(e.clip,t.clip)&&((e,t)=>e===t||!!e&&!!t&&e.every((e,n)=>e===t[n]))(e.radius,t.radius)},b=new Map,x=async(e,t)=>{let n=b.get(e);if(n){for(let e of n)t&&e.element!==t||(e.stop(),n.delete(e));if(n.size>0)return;b.delete(e)}let r=await(await s()).packages.hide(e);if(`error`in r)throw o(r.error,r.message)},S=async(e,t)=>{let{element:n,rect:r}=t;if(!n&&!r)throw o(`invalid`,`packages.show: pass an element or a rect`);let i=(await s()).packages,a=()=>{if(!n)return{rect:h(r)};let e=h(n.getBoundingClientRect());return{rect:e,clip:_(n,e),radius:v(n)}},c=!0,l,u=0,d=async t=>{l=t;let n=await i.show(e,t);if(`error`in n)throw c=!1,o(n.error,n.message)};await d(a());let f=()=>{if(!c)return;let e=a();y(l,e)||d(e).catch(()=>{}),u=requestAnimationFrame(f)};n&&(u=requestAnimationFrame(f));let p={element:n,stop:()=>{c=!1,cancelAnimationFrame(u)}},m=b.get(e)??new Set;return m.add(p),b.set(e,m),{hide:()=>{x(e,n).catch(()=>{})},refresh:()=>{if(!c)return;let e=a();y(l,e)||d(e).catch(()=>{})}}},C=async(e,t={})=>x(e,t.element),w=(async(e,t={})=>{let n=await(await s()).packages.connect(e,{protocol:t.protocol});if(`error`in n)throw o(n.error,n.message);let{port:r,closed:i}=n;if(t.raw)return{closed:i,port:r};let a=await l(t.payload,r,{signal:t.signal,closed:i});return t.signal&&t.signal.addEventListener(`abort`,()=>{try{r.postMessage({type:`fkn-packages-disconnect`})}catch{}},{once:!0}),{remote:a,closed:i,port:r}}),T=3e4,E=(e,t)=>new Promise((n,r)=>{let i=e=>{clearTimeout(s),window.removeEventListener(`message`,a),e?r(e):n()},a=n=>{if(n.source!==e.contentWindow||n.origin!==t)return;let r=n.data;if(r?.type===`fkn-packages-ready`)return i();r?.type===`fkn-packages-failed`&&i(o(`unavailable`,typeof r.message==`string`&&r.message?r.message:`packages.mount: the package failed to boot`))},s=setTimeout(()=>i(o(`timeout`,`packages.mount: the package did not register a connection handler`)),T);window.addEventListener(`message`,a)}),D=async(e,t)=>{let{element:n}=t;if(!n)throw o(`invalid`,`packages.mount: pass an element to mount into`);let r=await(await s()).packages.frame(e);if(`error`in r)throw o(r.error,r.message);let i=document.createElement(`iframe`);i.setAttribute(`sandbox`,`allow-scripts allow-same-origin`),i.setAttribute(`allow`,`cross-origin-isolated`),i.style.border=`none`,i.style.width=`100%`,i.style.height=`100%`,i.src=r.url,n.append(i);let a={done:!1},c=()=>{},u=new Promise(e=>{c=e}),d=()=>{if(!a.done){a.done=!0;try{i.contentWindow?.postMessage({type:`fkn-packages-close`},r.origin)}catch{}i.remove(),c()}};try{await E(i,r.origin)}catch(e){throw d(),e}let f=new MessageChannel,p=i.contentWindow;if(!p)throw d(),o(`unavailable`,`packages.mount: the frame was detached before it could connect`);p.postMessage({type:`fkn-packages-port`,from:r.from,protocol:t.protocol,uri:r.uri,name:r.name,version:r.version},r.origin,[f.port2]);try{p.postMessage({type:`fkn-packages-visibility`,visible:!0},r.origin)}catch{}return t.raw?{closed:u,port:f.port1,frame:i,unmount:d}:{remote:await l(t.payload,f.port1,{signal:t.signal,closed:u}),closed:u,port:f.port1,frame:i,unmount:d}},O=(e,t,n)=>l(t,e,{signal:n?.signal}),k=null,A=!1,j=new Set,M=[],N=new Map,P=!1,F=!1,I=e=>{let t=N.get(e);t&&(N.delete(e),t())},L=(e,t)=>{try{e.postMessage({type:`fkn-packages-nack`,message:t})}catch{}try{e.close()}catch{}},R=async(e,t)=>{let{port:n,...r}=e;e.port.addEventListener(`message`,t=>{t.data?.type===`fkn-packages-disconnect`&&I(e.port)});let i;try{i=await t.createPayload(r)}catch(t){throw L(e.port,t instanceof Error?t.message:`the package failed to produce a connection`),t}let a=new Promise(t=>N.set(e.port,t)),o=await c(i,e.port);t.handler?.({...r,remote:o,closed:a,port:e.port})},z=()=>{P||typeof window>`u`||window.parent===window||(P=!0,window.addEventListener(`message`,e=>{if(e.source!==window.parent)return;let t=e.data;if(t?.type===`fkn-packages-port`){let n=e.ports[0];if(!n)return;let r={port:n,from:typeof t.from==`string`?t.from:``,protocol:typeof t.protocol==`string`?t.protocol:null,uri:typeof t.uri==`string`?t.uri:``,name:typeof t.name==`string`?t.name:``,version:typeof t.version==`string`?t.version:``};k?R(r,k).catch(e=>console.warn(`packages.onConnect:`,e)):M.push(r)}if(t?.type===`fkn-packages-close`)for(let e of[...N.keys()])I(e);if(t?.type===`fkn-packages-visibility`){A=t.visible===!0;for(let e of j)try{e(A)}catch{}}}))},B=()=>{F||typeof window>`u`||window.parent===window||(F=!0,window.parent.postMessage({type:`fkn-packages-ready`},`*`))},V=(e,t)=>{if(typeof window>`u`)return{unsubscribe:()=>{}};z();let n={createPayload:e,handler:t};for(k=n,B();M.length&&k===n;)R(M.shift(),n).catch(e=>console.warn(`packages.onConnect:`,e));return{unsubscribe:()=>{k===n&&(k=null)}}},H=()=>A,U=e=>{if(typeof window>`u`)return{unsubscribe:()=>{}};z(),j.add(e);try{e(A)}catch{}return{unsubscribe:()=>{j.delete(e)}}};exports.attach=O,exports.connect=w,exports.hide=C,exports.install=f,exports.isVisible=H,exports.list=p,exports.mount=D,exports.onConnect=V,exports.onVisibilityChange=U,exports.pick=d,exports.search=u,exports.show=S,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}}),exports.uninstall=m;
package/packages.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as PackagesErrorCode, C as uninstall, D as InstalledPackage, E as InstallOptions, F as SurfaceRect, M as PickOptions, N as Placement, O as PackageQuery, P as Radii, S as show, T as ConnectOptions, _ as onConnect, a as IncomingConnectionInfo, b as pick, c as PackagesError, d as attach, f as connect, g as list, h as isVisible, i as IncomingConnection, k as PackageResult, l as RawPackageConnection, m as install, n as Connect, o as PackageConnection, p as hide, r as ConnectPayload, s as PackageView, t as AppConnectOptions, u as ShowOptions, v as onVisibilityChange, x as search } from "./packages-BtbLwrrW.js";
2
- export { AppConnectOptions, Connect, type ConnectOptions, ConnectPayload, IncomingConnection, IncomingConnectionInfo, type InstallOptions, type InstalledPackage, PackageConnection, type PackageQuery, type PackageResult, PackageView, PackagesError, type PackagesErrorCode, type PickOptions, type Placement, type Radii, RawPackageConnection, ShowOptions, type SurfaceRect, attach, connect, hide, install, isVisible, list, onConnect, onVisibilityChange, pick, search, show, uninstall };
1
+ import { A as InstallOptions, C as pick, E as uninstall, I as PickOptions, L as Placement, M as PackageQuery, N as PackageResult, P as PackagesErrorCode, R as Radii, T as show, _ as isVisible, a as IncomingConnectionInfo, b as onConnect, c as PackageConnection, d as RawPackageConnection, f as ShowOptions, g as install, h as hide, i as IncomingConnection, j as InstalledPackage, k as ConnectOptions, l as PackageView, m as connect, n as Connect, o as MountOptions, p as attach, r as ConnectPayload, s as MountedPackage, t as AppConnectOptions, u as PackagesError, v as list, w as search, x as onVisibilityChange, y as mount, z as SurfaceRect } from "./packages-B03jnjRB.js";
2
+ export { AppConnectOptions, Connect, type ConnectOptions, ConnectPayload, IncomingConnection, IncomingConnectionInfo, type InstallOptions, type InstalledPackage, MountOptions, MountedPackage, PackageConnection, type PackageQuery, type PackageResult, PackageView, PackagesError, type PackagesErrorCode, type PickOptions, type Placement, type Radii, RawPackageConnection, ShowOptions, type SurfaceRect, attach, connect, hide, install, isVisible, list, mount, onConnect, onVisibilityChange, pick, search, show, uninstall };
package/packages.js CHANGED
@@ -3,44 +3,45 @@ import { r as t, t as n } from "./api-B53pjQqI.js";
3
3
  import { expose as r } from "osra";
4
4
  //#region src/lib/packages.ts
5
5
  var i = /* @__PURE__ */ e({
6
- attach: () => D,
7
- connect: () => E,
8
- hide: () => T,
9
- install: () => m,
10
- isVisible: () => V,
11
- list: () => h,
12
- onConnect: () => B,
13
- onVisibilityChange: () => H,
14
- pick: () => p,
15
- search: () => f,
16
- show: () => w,
17
- uninstall: () => g
18
- }), a = "https://fkn.app", o = "fkn-packages-connection", s = 3e4, c = (e, t) => Object.assign(Error(t), { code: e }), l = async () => {
19
- if (!t) throw c("unavailable", "packages: no FKN transport in this realm - use relayWorker to bridge workers");
6
+ attach: () => k,
7
+ connect: () => T,
8
+ hide: () => w,
9
+ install: () => p,
10
+ isVisible: () => U,
11
+ list: () => m,
12
+ mount: () => O,
13
+ onConnect: () => H,
14
+ onVisibilityChange: () => W,
15
+ pick: () => f,
16
+ search: () => d,
17
+ show: () => C,
18
+ uninstall: () => h
19
+ }), a = "fkn-packages-connection", o = 3e4, s = (e, t) => Object.assign(Error(t), { code: e }), c = async () => {
20
+ if (!t) throw s("unavailable", "packages: no FKN transport in this realm - use relayWorker to bridge workers");
20
21
  return n;
21
- }, u = (e, t, n) => r(e ?? {}, {
22
+ }, l = (e, t, n) => r(e ?? {}, {
22
23
  transport: t,
23
- key: o,
24
+ key: a,
24
25
  unregisterSignal: n
25
- }), d = async (e, t, n = {}) => {
26
+ }), u = async (e, t, n = {}) => {
26
27
  let { signal: r, closed: i } = n;
27
- if (r?.aborted) throw c("unavailable", "packages.connect: aborted before connecting");
28
+ if (r?.aborted) throw s("unavailable", "packages.connect: aborted before connecting");
28
29
  let a = new AbortController();
29
30
  r && r.addEventListener("abort", () => a.abort(r.reason), { once: !0 });
30
- let o = new AbortController(), l = new Promise((e, n) => {
31
- let a = setTimeout(() => n(c("timeout", "packages.connect: the package did not complete the connection")), s);
32
- o.signal.addEventListener("abort", () => clearTimeout(a), { once: !0 }), t.addEventListener("message", (e) => {
31
+ let c = new AbortController(), u = new Promise((e, n) => {
32
+ let a = setTimeout(() => n(s("timeout", "packages.connect: the package did not complete the connection")), o);
33
+ c.signal.addEventListener("abort", () => clearTimeout(a), { once: !0 }), t.addEventListener("message", (e) => {
33
34
  if (e.data?.type === "fkn-packages-nack") {
34
35
  let t = e.data.message;
35
- n(c("unavailable", typeof t == "string" && t ? t : "packages.connect: the package refused the connection"));
36
+ n(s("unavailable", typeof t == "string" && t ? t : "packages.connect: the package refused the connection"));
36
37
  }
37
- }, { signal: o.signal }), t.start(), r && r.addEventListener("abort", () => n(c("unavailable", "packages.connect: aborted before connecting")), {
38
+ }, { signal: c.signal }), t.start(), r && r.addEventListener("abort", () => n(s("unavailable", "packages.connect: aborted before connecting")), {
38
39
  once: !0,
39
- signal: o.signal
40
- }), i?.then(() => n(c("unavailable", "packages.connect: the package closed before connecting")));
40
+ signal: c.signal
41
+ }), i?.then(() => n(s("unavailable", "packages.connect: the package closed before connecting")));
41
42
  });
42
43
  try {
43
- return await Promise.race([u(e, t, a.signal), l]);
44
+ return await Promise.race([l(e, t, a.signal), u]);
44
45
  } catch (e) {
45
46
  a.abort(e);
46
47
  try {
@@ -48,29 +49,29 @@ var i = /* @__PURE__ */ e({
48
49
  } catch {}
49
50
  throw e;
50
51
  } finally {
51
- o.abort();
52
+ c.abort();
52
53
  }
53
- }, f = async (e) => {
54
- let t = await (await l()).packages.search(e);
55
- if ("error" in t) throw c(t.error, t.message);
54
+ }, d = async (e) => {
55
+ let t = await (await c()).packages.search(e);
56
+ if ("error" in t) throw s(t.error, t.message);
56
57
  return t.results;
57
- }, p = async (e, t) => {
58
- let n = await (await l()).packages.pick(e, t);
59
- if ("error" in n) throw c(n.error, n.message);
58
+ }, f = async (e, t) => {
59
+ let n = await (await c()).packages.pick(e, t);
60
+ if ("error" in n) throw s(n.error, n.message);
60
61
  return "declined" in n ? [] : n.results;
61
- }, m = async (e, t) => {
62
- let n = await (await l()).packages.install(e, t);
63
- if ("error" in n) throw c(n.error, n.message);
62
+ }, p = async (e, t) => {
63
+ let n = await (await c()).packages.install(e, t);
64
+ if ("error" in n) throw s(n.error, n.message);
64
65
  return "declined" in n ? null : n.installed;
65
- }, h = async () => (await (await l()).packages.list()).results, g = async (e) => {
66
- let t = await (await l()).packages.uninstall(e);
67
- if ("error" in t) throw c(t.error, t.message);
68
- }, _ = ({ x: e, y: t, width: n, height: r }) => ({
66
+ }, m = async () => (await (await c()).packages.list()).results, h = async (e) => {
67
+ let t = await (await c()).packages.uninstall(e);
68
+ if ("error" in t) throw s(t.error, t.message);
69
+ }, g = ({ x: e, y: t, width: n, height: r }) => ({
69
70
  x: Math.round(e),
70
71
  y: Math.round(t),
71
72
  width: Math.round(n),
72
73
  height: Math.round(r)
73
- }), v = (e, t) => {
74
+ }), _ = (e, t) => {
74
75
  let n = Math.max(e.x, t.x), r = Math.max(e.y, t.y);
75
76
  return {
76
77
  x: n,
@@ -78,14 +79,14 @@ var i = /* @__PURE__ */ e({
78
79
  width: Math.max(0, Math.min(e.x + e.width, t.x + t.width) - n),
79
80
  height: Math.max(0, Math.min(e.y + e.height, t.y + t.height) - r)
80
81
  };
81
- }, y = (e, t) => {
82
+ }, v = (e, t) => {
82
83
  let n = t;
83
84
  for (let t = e.parentElement; t; t = t.parentElement) {
84
85
  let e = getComputedStyle(t);
85
- if (!(e.overflowX === "visible" && e.overflowY === "visible") && (n = v(n, _(t.getBoundingClientRect())), n.width === 0 || n.height === 0)) break;
86
+ if (!(e.overflowX === "visible" && e.overflowY === "visible") && (n = _(n, g(t.getBoundingClientRect())), n.width === 0 || n.height === 0)) break;
86
87
  }
87
88
  return n;
88
- }, b = (e) => {
89
+ }, y = (e) => {
89
90
  let t = getComputedStyle(e), n = [
90
91
  t.borderTopLeftRadius,
91
92
  t.borderTopRightRadius,
@@ -98,40 +99,40 @@ var i = /* @__PURE__ */ e({
98
99
  return Number.isFinite(t) && t > 0 ? t : 0;
99
100
  });
100
101
  return r.some((e) => e > 0) ? r : void 0;
101
- }, x = (e, t) => {
102
+ }, b = (e, t) => {
102
103
  if (!e) return !1;
103
104
  let n = (e, t) => e === t || !!e && !!t && e.x === t.x && e.y === t.y && e.width === t.width && e.height === t.height;
104
105
  return n(e.rect, t.rect) && n(e.clip, t.clip) && ((e, t) => e === t || !!e && !!t && e.every((e, n) => e === t[n]))(e.radius, t.radius);
105
- }, S = /* @__PURE__ */ new Map(), C = async (e, t) => {
106
- let n = S.get(e);
106
+ }, x = /* @__PURE__ */ new Map(), S = async (e, t) => {
107
+ let n = x.get(e);
107
108
  if (n) {
108
109
  for (let e of n) t && e.element !== t || (e.stop(), n.delete(e));
109
110
  if (n.size > 0) return;
110
- S.delete(e);
111
+ x.delete(e);
111
112
  }
112
- let r = await (await l()).packages.hide(e);
113
- if ("error" in r) throw c(r.error, r.message);
114
- }, w = async (e, t) => {
113
+ let r = await (await c()).packages.hide(e);
114
+ if ("error" in r) throw s(r.error, r.message);
115
+ }, C = async (e, t) => {
115
116
  let { element: n, rect: r } = t;
116
- if (!n && !r) throw c("invalid", "packages.show: pass an element or a rect");
117
- let i = (await l()).packages, a = () => {
118
- if (!n) return { rect: _(r) };
119
- let e = _(n.getBoundingClientRect());
117
+ if (!n && !r) throw s("invalid", "packages.show: pass an element or a rect");
118
+ let i = (await c()).packages, a = () => {
119
+ if (!n) return { rect: g(r) };
120
+ let e = g(n.getBoundingClientRect());
120
121
  return {
121
122
  rect: e,
122
- clip: y(n, e),
123
- radius: b(n)
123
+ clip: v(n, e),
124
+ radius: y(n)
124
125
  };
125
- }, o = !0, s, u = 0, d = async (t) => {
126
- s = t;
126
+ }, o = !0, l, u = 0, d = async (t) => {
127
+ l = t;
127
128
  let n = await i.show(e, t);
128
- if ("error" in n) throw o = !1, c(n.error, n.message);
129
+ if ("error" in n) throw o = !1, s(n.error, n.message);
129
130
  };
130
131
  await d(a());
131
132
  let f = () => {
132
133
  if (!o) return;
133
134
  let e = a();
134
- x(s, e) || d(e).catch(() => {}), u = requestAnimationFrame(f);
135
+ b(l, e) || d(e).catch(() => {}), u = requestAnimationFrame(f);
135
136
  };
136
137
  n && (u = requestAnimationFrame(f));
137
138
  let p = {
@@ -139,26 +140,26 @@ var i = /* @__PURE__ */ e({
139
140
  stop: () => {
140
141
  o = !1, cancelAnimationFrame(u);
141
142
  }
142
- }, m = S.get(e) ?? /* @__PURE__ */ new Set();
143
- return m.add(p), S.set(e, m), {
143
+ }, m = x.get(e) ?? /* @__PURE__ */ new Set();
144
+ return m.add(p), x.set(e, m), {
144
145
  hide: () => {
145
- C(e, n).catch(() => {});
146
+ S(e, n).catch(() => {});
146
147
  },
147
148
  refresh: () => {
148
149
  if (!o) return;
149
150
  let e = a();
150
- x(s, e) || d(e).catch(() => {});
151
+ b(l, e) || d(e).catch(() => {});
151
152
  }
152
153
  };
153
- }, T = async (e, t = {}) => C(e, t.element), E = (async (e, t = {}) => {
154
- let n = await (await l()).packages.connect(e, { protocol: t.protocol });
155
- if ("error" in n) throw c(n.error, n.message);
154
+ }, w = async (e, t = {}) => S(e, t.element), T = (async (e, t = {}) => {
155
+ let n = await (await c()).packages.connect(e, { protocol: t.protocol });
156
+ if ("error" in n) throw s(n.error, n.message);
156
157
  let { port: r, closed: i } = n;
157
158
  if (t.raw) return {
158
159
  closed: i,
159
160
  port: r
160
161
  };
161
- let a = await d(t.payload, r, {
162
+ let a = await u(t.payload, r, {
162
163
  signal: t.signal,
163
164
  closed: i
164
165
  });
@@ -171,10 +172,74 @@ var i = /* @__PURE__ */ e({
171
172
  closed: i,
172
173
  port: r
173
174
  };
174
- }), D = (e, t, n) => d(t, e, { signal: n?.signal }), O = null, k = !1, A = /* @__PURE__ */ new Set(), j = [], M = /* @__PURE__ */ new Map(), N = !1, P = !1, F = (e) => {
175
- let t = M.get(e);
176
- t && (M.delete(e), t());
177
- }, I = (e, t) => {
175
+ }), E = 3e4, D = (e, t) => new Promise((n, r) => {
176
+ let i = (e) => {
177
+ clearTimeout(o), window.removeEventListener("message", a), e ? r(e) : n();
178
+ }, a = (n) => {
179
+ if (n.source !== e.contentWindow || n.origin !== t) return;
180
+ let r = n.data;
181
+ if (r?.type === "fkn-packages-ready") return i();
182
+ r?.type === "fkn-packages-failed" && i(s("unavailable", typeof r.message == "string" && r.message ? r.message : "packages.mount: the package failed to boot"));
183
+ }, o = setTimeout(() => i(s("timeout", "packages.mount: the package did not register a connection handler")), E);
184
+ window.addEventListener("message", a);
185
+ }), O = async (e, t) => {
186
+ let { element: n } = t;
187
+ if (!n) throw s("invalid", "packages.mount: pass an element to mount into");
188
+ let r = await (await c()).packages.frame(e);
189
+ if ("error" in r) throw s(r.error, r.message);
190
+ let i = document.createElement("iframe");
191
+ i.setAttribute("sandbox", "allow-scripts allow-same-origin"), i.setAttribute("allow", "cross-origin-isolated"), i.style.border = "none", i.style.width = "100%", i.style.height = "100%", i.src = r.url, n.append(i);
192
+ let a = { done: !1 }, o = () => {}, l = new Promise((e) => {
193
+ o = e;
194
+ }), d = () => {
195
+ if (!a.done) {
196
+ a.done = !0;
197
+ try {
198
+ i.contentWindow?.postMessage({ type: "fkn-packages-close" }, r.origin);
199
+ } catch {}
200
+ i.remove(), o();
201
+ }
202
+ };
203
+ try {
204
+ await D(i, r.origin);
205
+ } catch (e) {
206
+ throw d(), e;
207
+ }
208
+ let f = new MessageChannel(), p = i.contentWindow;
209
+ if (!p) throw d(), s("unavailable", "packages.mount: the frame was detached before it could connect");
210
+ p.postMessage({
211
+ type: "fkn-packages-port",
212
+ from: r.from,
213
+ protocol: t.protocol,
214
+ uri: r.uri,
215
+ name: r.name,
216
+ version: r.version
217
+ }, r.origin, [f.port2]);
218
+ try {
219
+ p.postMessage({
220
+ type: "fkn-packages-visibility",
221
+ visible: !0
222
+ }, r.origin);
223
+ } catch {}
224
+ return t.raw ? {
225
+ closed: l,
226
+ port: f.port1,
227
+ frame: i,
228
+ unmount: d
229
+ } : {
230
+ remote: await u(t.payload, f.port1, {
231
+ signal: t.signal,
232
+ closed: l
233
+ }),
234
+ closed: l,
235
+ port: f.port1,
236
+ frame: i,
237
+ unmount: d
238
+ };
239
+ }, k = (e, t, n) => u(t, e, { signal: n?.signal }), A = null, j = !1, M = /* @__PURE__ */ new Set(), N = [], P = /* @__PURE__ */ new Map(), F = !1, I = !1, L = (e) => {
240
+ let t = P.get(e);
241
+ t && (P.delete(e), t());
242
+ }, R = (e, t) => {
178
243
  try {
179
244
  e.postMessage({
180
245
  type: "fkn-packages-nack",
@@ -184,27 +249,27 @@ var i = /* @__PURE__ */ e({
184
249
  try {
185
250
  e.close();
186
251
  } catch {}
187
- }, L = async (e, t) => {
252
+ }, z = async (e, t) => {
188
253
  let { port: n, ...r } = e;
189
254
  e.port.addEventListener("message", (t) => {
190
- t.data?.type === "fkn-packages-disconnect" && F(e.port);
255
+ t.data?.type === "fkn-packages-disconnect" && L(e.port);
191
256
  });
192
257
  let i;
193
258
  try {
194
259
  i = await t.createPayload(r);
195
260
  } catch (t) {
196
- throw I(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
261
+ throw R(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
197
262
  }
198
- let a = new Promise((t) => M.set(e.port, t)), o = await u(i, e.port);
263
+ let a = new Promise((t) => P.set(e.port, t)), o = await l(i, e.port);
199
264
  t.handler?.({
200
265
  ...r,
201
266
  remote: o,
202
267
  closed: a,
203
268
  port: e.port
204
269
  });
205
- }, R = () => {
206
- N || typeof window > "u" || window.parent === window || (N = !0, window.addEventListener("message", (e) => {
207
- if (e.source !== window.parent || e.origin !== a) return;
270
+ }, B = () => {
271
+ F || typeof window > "u" || window.parent === window || (F = !0, window.addEventListener("message", (e) => {
272
+ if (e.source !== window.parent) return;
208
273
  let t = e.data;
209
274
  if (t?.type === "fkn-packages-port") {
210
275
  let n = e.ports[0];
@@ -217,38 +282,38 @@ var i = /* @__PURE__ */ e({
217
282
  name: typeof t.name == "string" ? t.name : "",
218
283
  version: typeof t.version == "string" ? t.version : ""
219
284
  };
220
- O ? L(r, O).catch((e) => console.warn("packages.onConnect:", e)) : j.push(r);
285
+ A ? z(r, A).catch((e) => console.warn("packages.onConnect:", e)) : N.push(r);
221
286
  }
222
- if (t?.type === "fkn-packages-close") for (let e of [...M.keys()]) F(e);
287
+ if (t?.type === "fkn-packages-close") for (let e of [...P.keys()]) L(e);
223
288
  if (t?.type === "fkn-packages-visibility") {
224
- k = t.visible === !0;
225
- for (let e of A) try {
226
- e(k);
289
+ j = t.visible === !0;
290
+ for (let e of M) try {
291
+ e(j);
227
292
  } catch {}
228
293
  }
229
294
  }));
230
- }, z = () => {
231
- P || typeof window > "u" || window.parent === window || (P = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, a));
232
- }, B = (e, t) => {
295
+ }, V = () => {
296
+ I || typeof window > "u" || window.parent === window || (I = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, "*"));
297
+ }, H = (e, t) => {
233
298
  if (typeof window > "u") return { unsubscribe: () => {} };
234
- R();
299
+ B();
235
300
  let n = {
236
301
  createPayload: e,
237
302
  handler: t
238
303
  };
239
- for (O = n, z(); j.length && O === n;) L(j.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
304
+ for (A = n, V(); N.length && A === n;) z(N.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
240
305
  return { unsubscribe: () => {
241
- O === n && (O = null);
306
+ A === n && (A = null);
242
307
  } };
243
- }, V = () => k, H = (e) => {
308
+ }, U = () => j, W = (e) => {
244
309
  if (typeof window > "u") return { unsubscribe: () => {} };
245
- R(), A.add(e);
310
+ B(), M.add(e);
246
311
  try {
247
- e(k);
312
+ e(j);
248
313
  } catch {}
249
314
  return { unsubscribe: () => {
250
- A.delete(e);
315
+ M.delete(e);
251
316
  } };
252
317
  };
253
318
  //#endregion
254
- export { D as attach, E as connect, T as hide, m as install, V as isVisible, h as list, B as onConnect, H as onVisibilityChange, p as pick, f as search, w as show, i as t, g as uninstall };
319
+ export { k as attach, T as connect, w as hide, p as install, U as isVisible, m as list, O as mount, H as onConnect, W as onVisibilityChange, f as pick, d as search, C as show, i as t, h as uninstall };
@@ -1,4 +1,4 @@
1
- import { t as Resolvers } from "./api-BYRsWdwB.js";
1
+ import { t as Resolvers } from "./api-Dn793vCK.js";
2
2
 
3
3
  //#region src/lib/proxy.d.ts
4
4
  type ProxyFetch = Resolvers['cloud']['fetch'];