@fkn/lib 0.9.9 → 0.9.11

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-vX-1yfRK.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-CAjDHzfq.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-BhNzd0mR.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-CAjDHzfq.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-BhNzd0mR.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-CAjDHzfq.js";
2
+ import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-DRzA41UW.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-BhNzd0mR.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-VR2xHGZu.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-BhNzd0mR.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-vX-1yfRK.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-DRzA41UW.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-BhNzd0mR.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-VR2xHGZu.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-BhNzd0mR.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.11",
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,36 @@ 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
+ /**
157
+ * the iframe the package is loaded into. YOU create it and YOU own it: its attributes, its styles and
158
+ * its place in your layout are yours, and `mount` only navigates it.
159
+ *
160
+ * Set `allow` yourself for anything the package needs delegated, e.g. `allow="fullscreen; autoplay"`.
161
+ * Permissions policy is not inherited, so a capability this frame is not granted cannot be recovered
162
+ * by the package or by anything it nests inside itself.
163
+ */
164
+ iframe: HTMLIFrameElement;
165
+ };
166
+ type MountedPackage<T = unknown> = PackageConnection<T> & {
167
+ /** the iframe you passed in, unchanged apart from its `src` */frame: HTMLIFrameElement; /** blank the frame and settle `closed`; the element stays in your layout because it is yours */
168
+ unmount: () => void;
169
+ };
170
+ /**
171
+ * Load a package into an iframe of YOUR OWN and connect to it, instead of positioning a frame the broker
172
+ * owns and clipping the overlay to it the way `show()` does.
173
+ *
174
+ * You pass the iframe, the same way `cloud.attachFrame` takes one. It lays out, scrolls, stacks and
175
+ * fullscreens with the rest of your page, there is no geometry to translate, and every attribute on it
176
+ * stays exactly as you set it: `mount` reads `sandbox` and `allow` to check the package can boot, then
177
+ * writes nothing but `src`. The package still gets its own origin and its own broker connection.
178
+ *
179
+ * Grant capabilities through the iframe's own `allow`, before calling this. Permissions policy is read
180
+ * at navigation and is not inherited, so it cannot be added afterwards on the frame handed back.
181
+ *
182
+ * Needs a package built against this version of the lib: an older one only accepts a port from fkn.app.
183
+ */
184
+ declare const mount: <T = unknown>(uri: string, options: MountOptions) => Promise<MountedPackage<T>>;
138
185
  /** Run this end of an already-brokered connection port, e.g. after transferring it into a worker. */
139
186
  declare const attach: <T = unknown>(port: MessagePort, payload?: unknown, options?: {
140
187
  signal?: AbortSignal;
@@ -167,4 +214,4 @@ declare const onVisibilityChange: (handler: (visible: boolean) => void) => {
167
214
  unsubscribe: () => void;
168
215
  };
169
216
  //#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 };
217
+ 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:()=>A,connect:()=>w,hide:()=>C,install:()=>f,isVisible:()=>W,list:()=>p,mount:()=>k,onConnect:()=>U,onVisibilityChange:()=>G,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=[`allow-scripts`,`allow-same-origin`],E=e=>{let t=e.getAttribute(`sandbox`);if(t!==null){let e=new Set(t.toLowerCase().split(/\s+/).filter(Boolean)),n=T.filter(t=>!e.has(t));if(n.length)throw o(`invalid`,`packages.mount: the iframe's sandbox attribute must include ${n.join(` and `)}, or the package cannot start`)}if(globalThis.crossOriginIsolated&&!new Set((e.getAttribute(`allow`)??``).toLowerCase().split(`;`).map(e=>e.trim().split(/\s+/)[0]).filter(Boolean)).has(`cross-origin-isolated`))throw o(`invalid`,`packages.mount: this page is cross-origin isolated, so the iframe's allow attribute must include 'cross-origin-isolated' to hand that down to the package`)},D=3e4,O=(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`)),D);window.addEventListener(`message`,a)}),k=async(e,t)=>{let{iframe:n}=t;if(!(n instanceof HTMLIFrameElement))throw o(`invalid`,`packages.mount: pass the iframe to load the package into`);if(!n.isConnected)throw o(`invalid`,`packages.mount: the iframe must be in the document before mounting into it`);E(n);let r=await(await s()).packages.frame(e);if(`error`in r)throw o(r.error,r.message);n.src=r.url;let i={done:!1},a=()=>{},c=new Promise(e=>{a=e}),u=()=>{if(!i.done){i.done=!0;try{n.contentWindow?.postMessage({type:`fkn-packages-close`},r.origin)}catch{}n.src=`about:blank`,a()}};try{await O(n,r.origin)}catch(e){throw u(),e}let d=new MessageChannel,f=n.contentWindow;if(!f)throw u(),o(`unavailable`,`packages.mount: the frame was detached before it could connect`);f.postMessage({type:`fkn-packages-port`,from:r.from,protocol:t.protocol,uri:r.uri,name:r.name,version:r.version},r.origin,[d.port2]);try{f.postMessage({type:`fkn-packages-visibility`,visible:!0},r.origin)}catch{}return t.raw?{closed:c,port:d.port1,frame:n,unmount:u}:{remote:await l(t.payload,d.port1,{signal:t.signal,closed:c}),closed:c,port:d.port1,frame:n,unmount:u}},A=(e,t,n)=>l(t,e,{signal:n?.signal}),j=null,M=!1,N=new Set,P=[],F=new Map,I=!1,L=!1,R=e=>{let t=F.get(e);t&&(F.delete(e),t())},z=(e,t)=>{try{e.postMessage({type:`fkn-packages-nack`,message:t})}catch{}try{e.close()}catch{}},B=async(e,t)=>{let{port:n,...r}=e;e.port.addEventListener(`message`,t=>{t.data?.type===`fkn-packages-disconnect`&&R(e.port)});let i;try{i=await t.createPayload(r)}catch(t){throw z(e.port,t instanceof Error?t.message:`the package failed to produce a connection`),t}let a=new Promise(t=>F.set(e.port,t)),o=await c(i,e.port);t.handler?.({...r,remote:o,closed:a,port:e.port})},V=()=>{I||typeof window>`u`||window.parent===window||(I=!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:``};j?B(r,j).catch(e=>console.warn(`packages.onConnect:`,e)):P.push(r)}if(t?.type===`fkn-packages-close`)for(let e of[...F.keys()])R(e);if(t?.type===`fkn-packages-visibility`){M=t.visible===!0;for(let e of N)try{e(M)}catch{}}}))},H=()=>{L||typeof window>`u`||window.parent===window||(L=!0,window.parent.postMessage({type:`fkn-packages-ready`},`*`))},U=(e,t)=>{if(typeof window>`u`)return{unsubscribe:()=>{}};V();let n={createPayload:e,handler:t};for(j=n,H();P.length&&j===n;)B(P.shift(),n).catch(e=>console.warn(`packages.onConnect:`,e));return{unsubscribe:()=>{j===n&&(j=null)}}},W=()=>M,G=e=>{if(typeof window>`u`)return{unsubscribe:()=>{}};V(),N.add(e);try{e(M)}catch{}return{unsubscribe:()=>{N.delete(e)}}};exports.attach=A,exports.connect=w,exports.hide=C,exports.install=f,exports.isVisible=W,exports.list=p,exports.mount=k,exports.onConnect=U,exports.onVisibilityChange=G,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-vX-1yfRK.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: () => j,
7
+ connect: () => T,
8
+ hide: () => w,
9
+ install: () => p,
10
+ isVisible: () => G,
11
+ list: () => m,
12
+ mount: () => A,
13
+ onConnect: () => W,
14
+ onVisibilityChange: () => K,
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,82 @@ 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 = ["allow-scripts", "allow-same-origin"], D = (e) => {
176
+ let t = e.getAttribute("sandbox");
177
+ if (t !== null) {
178
+ let e = new Set(t.toLowerCase().split(/\s+/).filter(Boolean)), n = E.filter((t) => !e.has(t));
179
+ if (n.length) throw s("invalid", `packages.mount: the iframe's sandbox attribute must include ${n.join(" and ")}, or the package cannot start`);
180
+ }
181
+ if (globalThis.crossOriginIsolated && !new Set((e.getAttribute("allow") ?? "").toLowerCase().split(";").map((e) => e.trim().split(/\s+/)[0]).filter(Boolean)).has("cross-origin-isolated")) throw s("invalid", "packages.mount: this page is cross-origin isolated, so the iframe's allow attribute must include 'cross-origin-isolated' to hand that down to the package");
182
+ }, O = 3e4, k = (e, t) => new Promise((n, r) => {
183
+ let i = (e) => {
184
+ clearTimeout(o), window.removeEventListener("message", a), e ? r(e) : n();
185
+ }, a = (n) => {
186
+ if (n.source !== e.contentWindow || n.origin !== t) return;
187
+ let r = n.data;
188
+ if (r?.type === "fkn-packages-ready") return i();
189
+ r?.type === "fkn-packages-failed" && i(s("unavailable", typeof r.message == "string" && r.message ? r.message : "packages.mount: the package failed to boot"));
190
+ }, o = setTimeout(() => i(s("timeout", "packages.mount: the package did not register a connection handler")), O);
191
+ window.addEventListener("message", a);
192
+ }), A = async (e, t) => {
193
+ let { iframe: n } = t;
194
+ if (!(n instanceof HTMLIFrameElement)) throw s("invalid", "packages.mount: pass the iframe to load the package into");
195
+ if (!n.isConnected) throw s("invalid", "packages.mount: the iframe must be in the document before mounting into it");
196
+ D(n);
197
+ let r = await (await c()).packages.frame(e);
198
+ if ("error" in r) throw s(r.error, r.message);
199
+ n.src = r.url;
200
+ let i = { done: !1 }, a = () => {}, o = new Promise((e) => {
201
+ a = e;
202
+ }), l = () => {
203
+ if (!i.done) {
204
+ i.done = !0;
205
+ try {
206
+ n.contentWindow?.postMessage({ type: "fkn-packages-close" }, r.origin);
207
+ } catch {}
208
+ n.src = "about:blank", a();
209
+ }
210
+ };
211
+ try {
212
+ await k(n, r.origin);
213
+ } catch (e) {
214
+ throw l(), e;
215
+ }
216
+ let d = new MessageChannel(), f = n.contentWindow;
217
+ if (!f) throw l(), s("unavailable", "packages.mount: the frame was detached before it could connect");
218
+ f.postMessage({
219
+ type: "fkn-packages-port",
220
+ from: r.from,
221
+ protocol: t.protocol,
222
+ uri: r.uri,
223
+ name: r.name,
224
+ version: r.version
225
+ }, r.origin, [d.port2]);
226
+ try {
227
+ f.postMessage({
228
+ type: "fkn-packages-visibility",
229
+ visible: !0
230
+ }, r.origin);
231
+ } catch {}
232
+ return t.raw ? {
233
+ closed: o,
234
+ port: d.port1,
235
+ frame: n,
236
+ unmount: l
237
+ } : {
238
+ remote: await u(t.payload, d.port1, {
239
+ signal: t.signal,
240
+ closed: o
241
+ }),
242
+ closed: o,
243
+ port: d.port1,
244
+ frame: n,
245
+ unmount: l
246
+ };
247
+ }, j = (e, t, n) => u(t, e, { signal: n?.signal }), M = null, N = !1, P = /* @__PURE__ */ new Set(), F = [], I = /* @__PURE__ */ new Map(), L = !1, R = !1, z = (e) => {
248
+ let t = I.get(e);
249
+ t && (I.delete(e), t());
250
+ }, B = (e, t) => {
178
251
  try {
179
252
  e.postMessage({
180
253
  type: "fkn-packages-nack",
@@ -184,27 +257,27 @@ var i = /* @__PURE__ */ e({
184
257
  try {
185
258
  e.close();
186
259
  } catch {}
187
- }, L = async (e, t) => {
260
+ }, V = async (e, t) => {
188
261
  let { port: n, ...r } = e;
189
262
  e.port.addEventListener("message", (t) => {
190
- t.data?.type === "fkn-packages-disconnect" && F(e.port);
263
+ t.data?.type === "fkn-packages-disconnect" && z(e.port);
191
264
  });
192
265
  let i;
193
266
  try {
194
267
  i = await t.createPayload(r);
195
268
  } catch (t) {
196
- throw I(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
269
+ throw B(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
197
270
  }
198
- let a = new Promise((t) => M.set(e.port, t)), o = await u(i, e.port);
271
+ let a = new Promise((t) => I.set(e.port, t)), o = await l(i, e.port);
199
272
  t.handler?.({
200
273
  ...r,
201
274
  remote: o,
202
275
  closed: a,
203
276
  port: e.port
204
277
  });
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;
278
+ }, H = () => {
279
+ L || typeof window > "u" || window.parent === window || (L = !0, window.addEventListener("message", (e) => {
280
+ if (e.source !== window.parent) return;
208
281
  let t = e.data;
209
282
  if (t?.type === "fkn-packages-port") {
210
283
  let n = e.ports[0];
@@ -217,38 +290,38 @@ var i = /* @__PURE__ */ e({
217
290
  name: typeof t.name == "string" ? t.name : "",
218
291
  version: typeof t.version == "string" ? t.version : ""
219
292
  };
220
- O ? L(r, O).catch((e) => console.warn("packages.onConnect:", e)) : j.push(r);
293
+ M ? V(r, M).catch((e) => console.warn("packages.onConnect:", e)) : F.push(r);
221
294
  }
222
- if (t?.type === "fkn-packages-close") for (let e of [...M.keys()]) F(e);
295
+ if (t?.type === "fkn-packages-close") for (let e of [...I.keys()]) z(e);
223
296
  if (t?.type === "fkn-packages-visibility") {
224
- k = t.visible === !0;
225
- for (let e of A) try {
226
- e(k);
297
+ N = t.visible === !0;
298
+ for (let e of P) try {
299
+ e(N);
227
300
  } catch {}
228
301
  }
229
302
  }));
230
- }, z = () => {
231
- P || typeof window > "u" || window.parent === window || (P = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, a));
232
- }, B = (e, t) => {
303
+ }, U = () => {
304
+ R || typeof window > "u" || window.parent === window || (R = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, "*"));
305
+ }, W = (e, t) => {
233
306
  if (typeof window > "u") return { unsubscribe: () => {} };
234
- R();
307
+ H();
235
308
  let n = {
236
309
  createPayload: e,
237
310
  handler: t
238
311
  };
239
- for (O = n, z(); j.length && O === n;) L(j.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
312
+ for (M = n, U(); F.length && M === n;) V(F.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
240
313
  return { unsubscribe: () => {
241
- O === n && (O = null);
314
+ M === n && (M = null);
242
315
  } };
243
- }, V = () => k, H = (e) => {
316
+ }, G = () => N, K = (e) => {
244
317
  if (typeof window > "u") return { unsubscribe: () => {} };
245
- R(), A.add(e);
318
+ H(), P.add(e);
246
319
  try {
247
- e(k);
320
+ e(N);
248
321
  } catch {}
249
322
  return { unsubscribe: () => {
250
- A.delete(e);
323
+ P.delete(e);
251
324
  } };
252
325
  };
253
326
  //#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 };
327
+ export { j as attach, T as connect, w as hide, p as install, G as isVisible, m as list, A as mount, W as onConnect, K 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-VR2xHGZu.js";
2
2
 
3
3
  //#region src/lib/proxy.d.ts
4
4
  type ProxyFetch = Resolvers['cloud']['fetch'];