@fkn/lib 0.9.7 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { C as PackageResult, E as PickOptions, S as PackageQuery, T as PackagesFail, b as InstallOptions, v as Caller, x as InstalledPackage, y as ConnectOptions } from "./packages-CSZGUtem.js";
1
+ import { D as InstalledPackage, E as InstallOptions, M as PickOptions, N as SurfaceRect, O as PackageQuery, T as ConnectOptions, j as PackagesFail, k as PackageResult, w as Caller } from "./packages-DU1D-pr4.js";
2
2
  import { t as AddressLookupResult } from "./lookup-BtwWaCZJ.js";
3
3
  //#region src/api/storage.d.ts
4
4
  type StorageEntry = {
@@ -684,6 +684,12 @@ declare const makeResolvers: (callerOf: () => Caller | undefined) => {
684
684
  port: MessagePort;
685
685
  closed: Promise<void>;
686
686
  }>;
687
+ show: (uri: string, rect: SurfaceRect) => Promise<PackagesFail | {
688
+ ok: true;
689
+ }>;
690
+ hide: (uri: string) => Promise<PackagesFail | {
691
+ ok: true;
692
+ }>;
687
693
  };
688
694
  readonly account: {
689
695
  readonly info: () => Promise<Account | null>;
package/cloud/fetch.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { t as cloudFetch } from "../proxy-pCTWR0E6.js";
1
+ import { t as cloudFetch } from "../proxy-CsFzuq-x.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-BDjZxAEZ.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-BVC0ImHf.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-pCTWR0E6.js";
1
+ import { t as cloudFetch } from "./proxy-CsFzuq-x.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-BDjZxAEZ.js";
5
+ import { s as net_d_exports } from "./net-BVC0ImHf.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-pCTWR0E6.js";
2
- import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-wrRNWHAn.js";
1
+ import { t as cloudFetch } from "./proxy-CsFzuq-x.js";
2
+ import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-C002L8iN.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-BDjZxAEZ.js";
5
+ import { s as net_d_exports } from "./net-BVC0ImHf.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-9O1SM4CR.js";
1
+ import { n as UdpSocketOption, t as Resolvers } from "./api-BdGpFv2D.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-BDjZxAEZ.js";
1
+ import { n as Socket, t as Server$1 } from "./net-BVC0ImHf.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 { m as packages_d_exports } from "./packages-CSZGUtem.js";
2
+ import { y as packages_d_exports } from "./packages-DU1D-pr4.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-wrRNWHAn.js";
4
+ import { n as cloud_d_exports } from "./cloud-C002L8iN.js";
5
5
  import { t as dns_d_exports } from "./dns.js";
6
- import { s as net_d_exports } from "./net-BDjZxAEZ.js";
6
+ import { s as net_d_exports } from "./net-BVC0ImHf.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-9O1SM4CR.js";
1
+ import { i as TcpSocketOption, r as LocalTcpSocket, t as Resolvers } from "./api-BdGpFv2D.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-BDjZxAEZ.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-BVC0ImHf.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.7",
3
+ "version": "0.9.8",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",
@@ -41,6 +41,13 @@ type InstallOptions = {
41
41
  type ConnectOptions = {
42
42
  /** opaque contract tag delivered to the package's onConnect, e.g. 'stub-source@1' */protocol?: string;
43
43
  };
44
+ /** viewport coordinates, the space both the app and the broker frame measure in */
45
+ type SurfaceRect = {
46
+ x: number;
47
+ y: number;
48
+ width: number;
49
+ height: number;
50
+ };
44
51
  type PackagesErrorCode = 'invalid' | 'not-installed' | 'unaddressable' | 'timeout' | 'unavailable' | 'denied';
45
52
  type PackagesFail = {
46
53
  error: PackagesErrorCode;
@@ -59,7 +66,7 @@ type Caller = {
59
66
  origin: string;
60
67
  };
61
68
  declare namespace packages_d_exports {
62
- export { AppConnectOptions, Connect, ConnectOptions, ConnectPayload, IncomingConnection, IncomingConnectionInfo, InstallOptions, InstalledPackage, PackageConnection, PackageQuery, PackageResult, PackagesError, PackagesErrorCode, PickOptions, RawPackageConnection, attach, connect, install, list, onConnect, pick, search, uninstall };
69
+ export { AppConnectOptions, Connect, ConnectOptions, ConnectPayload, IncomingConnection, IncomingConnectionInfo, InstallOptions, InstalledPackage, PackageConnection, PackageQuery, PackageResult, PackageView, PackagesError, PackagesErrorCode, PickOptions, RawPackageConnection, ShowOptions, SurfaceRect, attach, connect, hide, install, isVisible, list, onConnect, onVisibilityChange, pick, search, show, uninstall };
63
70
  }
64
71
  type PackagesError = Error & {
65
72
  code: PackagesErrorCode;
@@ -74,6 +81,27 @@ declare const install: (uri: string, options?: InstallOptions) => Promise<Instal
74
81
  declare const list: () => Promise<InstalledPackage[]>;
75
82
  /** Uninstall a package from this app; its frames and connections are torn down. */
76
83
  declare const uninstall: (uri: string) => Promise<void>;
84
+ type ShowOptions = {
85
+ /** the package frame is kept aligned to this element's viewport rect until the view is released */element?: HTMLElement; /** an explicit viewport rect, for a caller that tracks placement itself */
86
+ rect?: SurfaceRect;
87
+ };
88
+ type PackageView = {
89
+ /** release this view; equivalent to `packages.hide(uri, { element })` */hide: () => void; /** force a re-measure, e.g. right after a layout change the tracker cannot observe */
90
+ refresh: () => void;
91
+ };
92
+ /**
93
+ * Show an installed, connected package's frame over this page, aligned to `element` (or an explicit
94
+ * `rect`). The package renders its own UI there; the app keeps the space in its own layout. Take it
95
+ * back down with `hide()` on the returned view, or with `packages.hide(uri)`. Throws a PackagesError
96
+ * with code 'not-installed' when the package has not been connected by this app.
97
+ */
98
+ declare const show: (uri: string, options: ShowOptions) => Promise<PackageView>;
99
+ /**
100
+ * Hide a package's frame again, the counterpart to `show()`. Pass the same `element` to release only
101
+ * the view bound to it; with no element every view of this package is released. The connection is
102
+ * untouched, so the package can be shown again.
103
+ */
104
+ declare const hide: (uri: string, options?: ShowOptions) => Promise<void>;
77
105
  type PackageConnection<T = unknown> = {
78
106
  /** the package's exposed payload */remote: Remote<T>; /** settles when the package side of the connection dies (uninstall, reload, crash) - reconnect by calling connect() again */
79
107
  closed: Promise<void>; /** the raw channel under `remote`, for direct messaging (osra envelopes ride it too - filter by your own message shape) */
@@ -117,5 +145,14 @@ type ConnectPayload = (info: IncomingConnectionInfo) => unknown;
117
145
  declare const onConnect: <T = unknown>(createPayload: ConnectPayload, handler?: (connection: IncomingConnection<T>) => void) => {
118
146
  unsubscribe: () => void;
119
147
  };
148
+ /** True while a host app is showing this package's frame. Packages start hidden. */
149
+ declare const isVisible: () => boolean;
150
+ /**
151
+ * Observe whether a host app is showing this package's frame, so it can render its UI only while on
152
+ * screen. The handler is called immediately with the current state, and on every change after.
153
+ */
154
+ declare const onVisibilityChange: (handler: (visible: boolean) => void) => {
155
+ unsubscribe: () => void;
156
+ };
120
157
  //#endregion
121
- export { PackageResult as C, PickOptions as E, PackageQuery as S, PackagesFail as T, uninstall as _, IncomingConnectionInfo as a, InstallOptions as b, RawPackageConnection as c, install as d, list as f, search as g, pick as h, IncomingConnection as i, attach as l, packages_d_exports as m, Connect as n, PackageConnection as o, onConnect as p, ConnectPayload as r, PackagesError as s, AppConnectOptions as t, connect as u, Caller as v, PackagesErrorCode as w, InstalledPackage as x, ConnectOptions as y };
158
+ export { PackagesErrorCode as A, uninstall as C, InstalledPackage as D, InstallOptions as E, PickOptions as M, SurfaceRect as N, PackageQuery as O, 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 };
package/packages.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-C9Mh5v0z.cjs");let n=require("osra");var r=e.t({attach:()=>_,connect:()=>g,install:()=>p,list:()=>m,onConnect:()=>O,pick:()=>f,search:()=>d,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=(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,t,n)=>u(t,e,{signal:n?.signal}),v=null,y=[],b=new Map,x=!1,S=!1,C=e=>{let t=b.get(e);t&&(b.delete(e),t())},w=(e,t)=>{try{e.postMessage({type:`fkn-packages-nack`,message:t})}catch{}try{e.close()}catch{}},T=async(e,t)=>{let{port:n,...r}=e;e.port.addEventListener(`message`,t=>{t.data?.type===`fkn-packages-disconnect`&&C(e.port)});let i;try{i=await t.createPayload(r)}catch(t){throw w(e.port,t instanceof Error?t.message:`the package failed to produce a connection`),t}let a=new Promise(t=>b.set(e.port,t)),o=await l(i,e.port);t.handler?.({...r,remote:o,closed:a,port:e.port})},E=()=>{x||typeof window>`u`||window.parent===window||(x=!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:``};v?T(r,v).catch(e=>console.warn(`packages.onConnect:`,e)):y.push(r)}if(t?.type===`fkn-packages-close`)for(let e of[...b.keys()])C(e)}))},D=()=>{S||typeof window>`u`||window.parent===window||(S=!0,window.parent.postMessage({type:`fkn-packages-ready`},i))},O=(e,t)=>{if(typeof window>`u`)return{unsubscribe:()=>{}};E();let n={createPayload:e,handler:t};for(v=n,D();y.length&&v===n;)T(y.shift(),n).catch(e=>console.warn(`packages.onConnect:`,e));return{unsubscribe:()=>{v===n&&(v=null)}}};exports.attach=_,exports.connect=g,exports.install=p,exports.list=m,exports.onConnect=O,exports.pick=f,exports.search=d,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-C9Mh5v0z.cjs");let n=require("osra");var r=e.t({attach:()=>C,connect:()=>S,hide:()=>x,install:()=>p,isVisible:()=>L,list:()=>m,onConnect:()=>I,onVisibilityChange:()=>R,pick:()=>f,search:()=>d,show:()=>b,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=(e,t)=>!!e&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,_=({x:e,y:t,width:n,height:r})=>({x:Math.round(e),y:Math.round(t),width:Math.round(n),height:Math.round(r)}),v=new Map,y=async(e,t)=>{let n=v.get(e);if(n){for(let e of n)t&&e.element!==t||(e.stop(),n.delete(e));if(n.size>0)return;v.delete(e)}let r=await(await c()).packages.hide(e);if(`error`in r)throw s(r.error,r.message)},b=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=()=>_(n?n.getBoundingClientRect():r),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();g(l,e)||d(e).catch(()=>{}),u=requestAnimationFrame(f)};n&&(u=requestAnimationFrame(f));let p={element:n,stop:()=>{o=!1,cancelAnimationFrame(u)}},m=v.get(e)??new Set;return m.add(p),v.set(e,m),{hide:()=>{y(e,n).catch(()=>{})},refresh:()=>{if(!o)return;let e=a();g(l,e)||d(e).catch(()=>{})}}},x=async(e,t={})=>y(e,t.element),S=(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}}),C=(e,t,n)=>u(t,e,{signal:n?.signal}),w=null,T=!1,E=new Set,D=[],O=new Map,k=!1,A=!1,j=e=>{let t=O.get(e);t&&(O.delete(e),t())},M=(e,t)=>{try{e.postMessage({type:`fkn-packages-nack`,message:t})}catch{}try{e.close()}catch{}},N=async(e,t)=>{let{port:n,...r}=e;e.port.addEventListener(`message`,t=>{t.data?.type===`fkn-packages-disconnect`&&j(e.port)});let i;try{i=await t.createPayload(r)}catch(t){throw M(e.port,t instanceof Error?t.message:`the package failed to produce a connection`),t}let a=new Promise(t=>O.set(e.port,t)),o=await l(i,e.port);t.handler?.({...r,remote:o,closed:a,port:e.port})},P=()=>{k||typeof window>`u`||window.parent===window||(k=!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:``};w?N(r,w).catch(e=>console.warn(`packages.onConnect:`,e)):D.push(r)}if(t?.type===`fkn-packages-close`)for(let e of[...O.keys()])j(e);if(t?.type===`fkn-packages-visibility`){T=t.visible===!0;for(let e of E)try{e(T)}catch{}}}))},F=()=>{A||typeof window>`u`||window.parent===window||(A=!0,window.parent.postMessage({type:`fkn-packages-ready`},i))},I=(e,t)=>{if(typeof window>`u`)return{unsubscribe:()=>{}};P();let n={createPayload:e,handler:t};for(w=n,F();D.length&&w===n;)N(D.shift(),n).catch(e=>console.warn(`packages.onConnect:`,e));return{unsubscribe:()=>{w===n&&(w=null)}}},L=()=>T,R=e=>{if(typeof window>`u`)return{unsubscribe:()=>{}};P(),E.add(e);try{e(T)}catch{}return{unsubscribe:()=>{E.delete(e)}}};exports.attach=C,exports.connect=S,exports.hide=x,exports.install=p,exports.isVisible=L,exports.list=m,exports.onConnect=I,exports.onVisibilityChange=R,exports.pick=f,exports.search=d,exports.show=b,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}}),exports.uninstall=h;
package/packages.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as PackageResult, E as PickOptions, S as PackageQuery, _ as uninstall, a as IncomingConnectionInfo, b as InstallOptions, c as RawPackageConnection, d as install, f as list, g as search, h as pick, i as IncomingConnection, l as attach, n as Connect, o as PackageConnection, p as onConnect, r as ConnectPayload, s as PackagesError, t as AppConnectOptions, u as connect, w as PackagesErrorCode, x as InstalledPackage, y as ConnectOptions } from "./packages-CSZGUtem.js";
2
- export { AppConnectOptions, Connect, type ConnectOptions, ConnectPayload, IncomingConnection, IncomingConnectionInfo, type InstallOptions, type InstalledPackage, PackageConnection, type PackageQuery, type PackageResult, PackagesError, type PackagesErrorCode, type PickOptions, RawPackageConnection, attach, connect, install, list, onConnect, pick, search, uninstall };
1
+ import { A as PackagesErrorCode, C as uninstall, D as InstalledPackage, E as InstallOptions, M as PickOptions, N as SurfaceRect, O as PackageQuery, 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-DU1D-pr4.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, RawPackageConnection, ShowOptions, type SurfaceRect, attach, connect, hide, install, isVisible, list, onConnect, onVisibilityChange, pick, search, show, uninstall };
package/packages.js CHANGED
@@ -3,13 +3,17 @@ import { r as t, t as n } from "./api-BU8zNmQI.js";
3
3
  import { expose as r } from "osra";
4
4
  //#region src/lib/packages.ts
5
5
  var i = /* @__PURE__ */ e({
6
- attach: () => v,
7
- connect: () => _,
6
+ attach: () => w,
7
+ connect: () => C,
8
+ hide: () => S,
8
9
  install: () => m,
10
+ isVisible: () => R,
9
11
  list: () => h,
10
- onConnect: () => k,
12
+ onConnect: () => L,
13
+ onVisibilityChange: () => z,
11
14
  pick: () => p,
12
15
  search: () => f,
16
+ show: () => x,
13
17
  uninstall: () => g
14
18
  }), a = "https://fkn.app", o = "fkn-packages-connection", s = 3e4, c = (e, t) => Object.assign(Error(t), { code: e }), l = async () => {
15
19
  if (!t) throw c("unavailable", "packages: no FKN transport in this realm - use relayWorker to bridge workers");
@@ -61,7 +65,52 @@ var i = /* @__PURE__ */ e({
61
65
  }, h = async () => (await (await l()).packages.list()).results, g = async (e) => {
62
66
  let t = await (await l()).packages.uninstall(e);
63
67
  if ("error" in t) throw c(t.error, t.message);
64
- }, _ = (async (e, t = {}) => {
68
+ }, _ = (e, t) => !!e && e.x === t.x && e.y === t.y && e.width === t.width && e.height === t.height, v = ({ x: e, y: t, width: n, height: r }) => ({
69
+ x: Math.round(e),
70
+ y: Math.round(t),
71
+ width: Math.round(n),
72
+ height: Math.round(r)
73
+ }), y = /* @__PURE__ */ new Map(), b = async (e, t) => {
74
+ let n = y.get(e);
75
+ if (n) {
76
+ for (let e of n) t && e.element !== t || (e.stop(), n.delete(e));
77
+ if (n.size > 0) return;
78
+ y.delete(e);
79
+ }
80
+ let r = await (await l()).packages.hide(e);
81
+ if ("error" in r) throw c(r.error, r.message);
82
+ }, x = async (e, t) => {
83
+ let { element: n, rect: r } = t;
84
+ if (!n && !r) throw c("invalid", "packages.show: pass an element or a rect");
85
+ let i = (await l()).packages, a = () => v(n ? n.getBoundingClientRect() : r), o = !0, s, u = 0, d = async (t) => {
86
+ s = t;
87
+ let n = await i.show(e, t);
88
+ if ("error" in n) throw o = !1, c(n.error, n.message);
89
+ };
90
+ await d(a());
91
+ let f = () => {
92
+ if (!o) return;
93
+ let e = a();
94
+ _(s, e) || d(e).catch(() => {}), u = requestAnimationFrame(f);
95
+ };
96
+ n && (u = requestAnimationFrame(f));
97
+ let p = {
98
+ element: n,
99
+ stop: () => {
100
+ o = !1, cancelAnimationFrame(u);
101
+ }
102
+ }, m = y.get(e) ?? /* @__PURE__ */ new Set();
103
+ return m.add(p), y.set(e, m), {
104
+ hide: () => {
105
+ b(e, n).catch(() => {});
106
+ },
107
+ refresh: () => {
108
+ if (!o) return;
109
+ let e = a();
110
+ _(s, e) || d(e).catch(() => {});
111
+ }
112
+ };
113
+ }, S = async (e, t = {}) => b(e, t.element), C = (async (e, t = {}) => {
65
114
  let n = await (await l()).packages.connect(e, { protocol: t.protocol });
66
115
  if ("error" in n) throw c(n.error, n.message);
67
116
  let { port: r, closed: i } = n;
@@ -82,10 +131,10 @@ var i = /* @__PURE__ */ e({
82
131
  closed: i,
83
132
  port: r
84
133
  };
85
- }), v = (e, t, n) => d(t, e, { signal: n?.signal }), y = null, b = [], x = /* @__PURE__ */ new Map(), S = !1, C = !1, w = (e) => {
86
- let t = x.get(e);
87
- t && (x.delete(e), t());
88
- }, T = (e, t) => {
134
+ }), w = (e, t, n) => d(t, e, { signal: n?.signal }), T = null, E = !1, D = /* @__PURE__ */ new Set(), O = [], k = /* @__PURE__ */ new Map(), A = !1, j = !1, M = (e) => {
135
+ let t = k.get(e);
136
+ t && (k.delete(e), t());
137
+ }, N = (e, t) => {
89
138
  try {
90
139
  e.postMessage({
91
140
  type: "fkn-packages-nack",
@@ -95,26 +144,26 @@ var i = /* @__PURE__ */ e({
95
144
  try {
96
145
  e.close();
97
146
  } catch {}
98
- }, E = async (e, t) => {
147
+ }, P = async (e, t) => {
99
148
  let { port: n, ...r } = e;
100
149
  e.port.addEventListener("message", (t) => {
101
- t.data?.type === "fkn-packages-disconnect" && w(e.port);
150
+ t.data?.type === "fkn-packages-disconnect" && M(e.port);
102
151
  });
103
152
  let i;
104
153
  try {
105
154
  i = await t.createPayload(r);
106
155
  } catch (t) {
107
- throw T(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
156
+ throw N(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
108
157
  }
109
- let a = new Promise((t) => x.set(e.port, t)), o = await u(i, e.port);
158
+ let a = new Promise((t) => k.set(e.port, t)), o = await u(i, e.port);
110
159
  t.handler?.({
111
160
  ...r,
112
161
  remote: o,
113
162
  closed: a,
114
163
  port: e.port
115
164
  });
116
- }, D = () => {
117
- S || typeof window > "u" || window.parent === window || (S = !0, window.addEventListener("message", (e) => {
165
+ }, F = () => {
166
+ A || typeof window > "u" || window.parent === window || (A = !0, window.addEventListener("message", (e) => {
118
167
  if (e.source !== window.parent || e.origin !== a) return;
119
168
  let t = e.data;
120
169
  if (t?.type === "fkn-packages-port") {
@@ -128,23 +177,38 @@ var i = /* @__PURE__ */ e({
128
177
  name: typeof t.name == "string" ? t.name : "",
129
178
  version: typeof t.version == "string" ? t.version : ""
130
179
  };
131
- y ? E(r, y).catch((e) => console.warn("packages.onConnect:", e)) : b.push(r);
180
+ T ? P(r, T).catch((e) => console.warn("packages.onConnect:", e)) : O.push(r);
181
+ }
182
+ if (t?.type === "fkn-packages-close") for (let e of [...k.keys()]) M(e);
183
+ if (t?.type === "fkn-packages-visibility") {
184
+ E = t.visible === !0;
185
+ for (let e of D) try {
186
+ e(E);
187
+ } catch {}
132
188
  }
133
- if (t?.type === "fkn-packages-close") for (let e of [...x.keys()]) w(e);
134
189
  }));
135
- }, O = () => {
136
- C || typeof window > "u" || window.parent === window || (C = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, a));
137
- }, k = (e, t) => {
190
+ }, I = () => {
191
+ j || typeof window > "u" || window.parent === window || (j = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, a));
192
+ }, L = (e, t) => {
138
193
  if (typeof window > "u") return { unsubscribe: () => {} };
139
- D();
194
+ F();
140
195
  let n = {
141
196
  createPayload: e,
142
197
  handler: t
143
198
  };
144
- for (y = n, O(); b.length && y === n;) E(b.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
199
+ for (T = n, I(); O.length && T === n;) P(O.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
200
+ return { unsubscribe: () => {
201
+ T === n && (T = null);
202
+ } };
203
+ }, R = () => E, z = (e) => {
204
+ if (typeof window > "u") return { unsubscribe: () => {} };
205
+ F(), D.add(e);
206
+ try {
207
+ e(E);
208
+ } catch {}
145
209
  return { unsubscribe: () => {
146
- y === n && (y = null);
210
+ D.delete(e);
147
211
  } };
148
212
  };
149
213
  //#endregion
150
- export { v as attach, _ as connect, m as install, h as list, k as onConnect, p as pick, f as search, i as t, g as uninstall };
214
+ export { w as attach, C as connect, S as hide, m as install, R as isVisible, h as list, L as onConnect, z as onVisibilityChange, p as pick, f as search, x as show, i as t, g as uninstall };
@@ -1,4 +1,4 @@
1
- import { t as Resolvers } from "./api-9O1SM4CR.js";
1
+ import { t as Resolvers } from "./api-BdGpFv2D.js";
2
2
 
3
3
  //#region src/lib/proxy.d.ts
4
4
  type ProxyFetch = Resolvers['cloud']['fetch'];