@fkn/lib 0.9.64 → 0.9.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/account-Bm7uIcQo.d.ts +39 -0
- package/account-Uh0-1Cbp.js +22 -0
- package/{account-generation-BiZxPztj.cjs → account-generation-ACCBzaI-.cjs} +1 -1
- package/{account-generation-DvRuJDa2.js → account-generation-BKHNe-jL.js} +2 -3
- package/account-m2iCmNui.cjs +1 -0
- package/{account-storage-D8CBG1cv.js → account-storage-BmCVutNL.js} +4 -5
- package/{account-storage-Co9IvkPr.d.ts → account-storage-UmSfF63A.d.ts} +1 -66
- package/{account-storage-DpHBgeX5.cjs → account-storage-dYWDpqsr.cjs} +1 -1
- package/account.cjs +1 -1
- package/account.d.ts +3 -40
- package/account.js +1 -23
- package/{api-xh6lzApn.d.ts → api-0Yp9uZcV.d.ts} +3 -7
- package/{api-BvJu2X1L.js → api-DRglK7ft.js} +19 -21
- package/{api-CrUO33y-.cjs → api-DrvhPN56.cjs} +1 -1
- package/api.cjs +1 -1
- package/api.d.ts +2 -2
- package/api.js +1 -2
- package/attach-policy.d.ts +0 -4
- package/attach-policy.js +2 -3
- package/{broker-frame-B31OXcnH.js → broker-frame-vjSpBa8d.js} +1 -2
- package/broker-frame.d.ts +1 -3
- package/broker-frame.js +1 -2
- package/{busy-DsMWrSzc.js → busy-C1JPjoZ_.js} +1 -2
- package/cloud/dgram.cjs +1 -1
- package/cloud/dgram.d.ts +1 -1
- package/cloud/dgram.js +1 -2
- package/cloud/dns.cjs +1 -1
- package/cloud/dns.d.ts +2 -2
- package/cloud/dns.js +1 -2
- package/cloud/fetch.cjs +1 -1
- package/cloud/fetch.d.ts +1 -1
- package/cloud/fetch.js +1 -2
- package/cloud/fs/promises.cjs +1 -1
- package/cloud/fs/promises.d.ts +3 -5
- package/cloud/fs/promises.js +2 -3
- package/cloud/fs.cjs +1 -1
- package/cloud/fs.d.ts +4 -4
- package/cloud/fs.js +4 -34
- package/cloud/http.cjs +1 -1
- package/cloud/http.d.ts +1 -1
- package/cloud/http.js +1 -2
- package/cloud/net.cjs +1 -1
- package/cloud/net.d.ts +1 -1
- package/cloud/net.js +3 -3
- package/{cloud-CI7FFRMC.d.ts → cloud-BoH54gaM.d.ts} +7 -11
- package/{cloud-FW59_g8F.js → cloud-C7StNncS.js} +15 -16
- package/cloud-TN0eDUy3.cjs +1 -0
- package/cloud.cjs +1 -1
- package/cloud.d.ts +7 -7
- package/cloud.js +7 -7
- package/connect-button-2FmOM8ai.d.ts +2 -0
- package/{connect-button-DtsN3X1J.js → connect-button-C1wKkIhh.js} +1 -2
- package/{contract-BGMJVvTg.d.ts → contract-0rua6Wsh.d.ts} +11 -6
- package/contract.d.ts +3 -3
- package/contract.js +1 -2
- package/desktop-DOubT4ES.d.ts +57 -0
- package/desktop-vXKU4wEK.cjs +1 -0
- package/desktop-xTT7ciGX.js +50 -0
- package/desktop.cjs +1 -1
- package/desktop.d.ts +2 -58
- package/desktop.js +1 -51
- package/dgram-BBbLokVF.js +397 -0
- package/dgram-BYk-QDHW.d.ts +118 -0
- package/dgram-D9ljiUFh.cjs +1 -0
- package/dgram.cjs +1 -1
- package/dgram.d.ts +2 -119
- package/dgram.js +1 -410
- package/dns-2v96zoEh.cjs +1 -0
- package/dns-DyB4K2oE.d.ts +9 -0
- package/dns-o8DLFjP1.js +5 -0
- package/dns.cjs +1 -1
- package/dns.d.ts +3 -10
- package/dns.js +1 -6
- package/extension-BXBjpypy.cjs +1 -0
- package/{extension-Chmpunqf.js → extension-D5UMnEmQ.js} +9 -11
- package/{extension-C1bcizcn.d.ts → extension-D98KM8W7.d.ts} +1 -27
- package/extension.cjs +1 -1
- package/extension.d.ts +2 -2
- package/extension.js +2 -2
- package/fs/promises.cjs +1 -1
- package/fs/promises.d.ts +2 -4
- package/fs/promises.js +2 -3
- package/fs--MLHvMW-.cjs +1 -0
- package/fs-BX_ghRy0.cjs +1 -0
- package/fs-BnWXGRik.js +33 -0
- package/{fs-DCJAYoYy.d.ts → fs-ChOYC6VD.d.ts} +3 -4
- package/{fs-Djuaj5pQ.js → fs-Cw7CcUhx.js} +17 -41
- package/fs.cjs +1 -1
- package/fs.d.ts +4 -4
- package/fs.js +2 -2
- package/{hosts-t7CKGTRz.js → hosts-HUfgMimI.js} +1 -2
- package/http-BE3UBktN.cjs +9 -0
- package/http-CDhG4bUc.d.ts +187 -0
- package/http-DIDjdm08.js +523 -0
- package/http.cjs +1 -9
- package/http.d.ts +2 -188
- package/http.js +1 -542
- package/index-CUWTpQKP.d.ts +87 -0
- package/{index-BQgZVQl7.d.ts → index-CcVwh9yz.d.ts} +0 -2
- package/{index-C5DdoMGo.d.ts → index-Cu5EcdK0.d.ts} +0 -59
- package/{index-57lTXnoe.d.ts → index-D6GPJ4Ow.d.ts} +29 -26
- package/index.cjs +1 -1
- package/index.d.ts +17 -25
- package/index.js +22 -27
- package/lib-Bs-g5jyp.cjs +53 -0
- package/{lib-BrsqpUkv.js → lib-CtJaID_y.js} +7 -31
- package/{messages-AdPfdoLV.d.ts → messages-B9dOXntM.d.ts} +0 -2
- package/messages.d.ts +1 -1
- package/messages.js +1 -2
- package/net-COkJw8lV.js +286 -0
- package/net-Dk2kqtgE.cjs +1 -0
- package/{net-BpyIeQ8r.d.ts → net-mVAYXs8e.d.ts} +5 -7
- package/net.cjs +1 -1
- package/net.d.ts +1 -1
- package/net.js +3 -323
- package/{node-fs-DY2fO5zd.js → node-fs-B4pY08Kc.js} +3 -10
- package/node-fs-DN0ejGTL.cjs +1 -0
- package/opfs/promises.cjs +1 -1
- package/opfs/promises.d.ts +2 -4
- package/opfs/promises.js +2 -3
- package/{opfs-D0goLAQW.js → opfs-CzCfVam3.js} +2 -3
- package/opfs-D3pYzYRc.js +35 -0
- package/opfs-DuXvTgIl.cjs +1 -0
- package/opfs.cjs +1 -1
- package/opfs.d.ts +3 -88
- package/opfs.js +1 -36
- package/package.json +1 -1
- package/packages-BEadIy_h.d.ts +155 -0
- package/packages-Cws_rcgf.js +346 -0
- package/packages-DT8vPB5_.cjs +1 -0
- package/packages.cjs +1 -1
- package/packages.d.ts +3 -156
- package/packages.js +1 -347
- package/{proxy-C4sYkxB5.js → proxy-BBAQxJmP.js} +5 -6
- package/{proxy-Dz60YyYy.d.ts → proxy-BP40IXYD.d.ts} +2 -4
- package/{proxy-jdE5tCwz.cjs → proxy-DVgGp6A8.cjs} +1 -1
- package/react.cjs +1 -1
- package/react.d.ts +16 -4
- package/react.js +96 -7
- package/{relay-choice-BGwXRC5d.js → relay-choice-Bb3oP2gw.js} +1 -2
- package/{relay-choice-5yUPI-tJ.d.ts → relay-choice-DOUttUnL.d.ts} +2 -4
- package/{rolldown-runtime-Dy4uBu1J.js → rolldown-runtime-CGnMp29N.js} +1 -2
- package/rooms-C6mbannC.d.ts +227 -0
- package/rooms-DHFS9cwA.cjs +1 -0
- package/rooms-DP5stTEr.js +300 -0
- package/rooms.cjs +1 -1
- package/rooms.d.ts +3 -228
- package/rooms.js +1 -301
- package/storage-BCjYihUO.cjs +1 -0
- package/storage-BhfImh_2.js +136 -0
- package/storage-DpCLksAa.d.ts +68 -0
- package/storage.cjs +1 -1
- package/storage.d.ts +3 -69
- package/storage.js +1 -137
- package/{utils-Cyq8uJiy.js → utils-DtWP-E9x.js} +1 -2
- package/{wire-Fk5pJaoy.d.ts → wire-DhmLnYEU.d.ts} +0 -2
- package/wire.d.ts +1 -1
- package/wire.js +1 -2
- package/cloud-DcgY8Xfp.cjs +0 -1
- package/connect-button-Cp0NS95-.d.ts +0 -4
- package/extension-I2Ziv2pk.cjs +0 -1
- package/fs-DeyJwJ3w.cjs +0 -1
- package/lib-C_X3WR4G.cjs +0 -53
- package/node-fs-vsWuoMGa.cjs +0 -1
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { E as InstalledPackage, F as PackageResult, I as PackagesErrorCode, J as Radii, P as PackageQuery, R as PickOptions, Rt as SurfaceRect, T as InstallOptions, m as ConnectOptions, z as Placement } from "./contract-0rua6Wsh.js";
|
|
2
|
+
import { Remote } from "osra";
|
|
3
|
+
declare namespace packages_d_exports {
|
|
4
|
+
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 };
|
|
5
|
+
}
|
|
6
|
+
type PackagesError = Error & {
|
|
7
|
+
code: PackagesErrorCode;
|
|
8
|
+
};
|
|
9
|
+
/** Search npm for FKN packages, e.g. `search({ type: 'plugin', id: 'stub' })`. */
|
|
10
|
+
declare const search: (query: PackageQuery) => Promise<PackageResult[]>;
|
|
11
|
+
/** FKN-rendered picker over the same search; resolves the user's selection, already installed. [] on cancel. */
|
|
12
|
+
declare const pick: (query: PackageQuery, options?: PickOptions) => Promise<PackageResult[]>;
|
|
13
|
+
/** Install a package for this app behind an FKN-rendered confirm, or with `{ noConfirm: true }` for a notice instead of a prompt. Resolves null when the user declines. */
|
|
14
|
+
declare const install: (uri: string, options?: InstallOptions) => Promise<InstalledPackage | null>;
|
|
15
|
+
/** The packages installed by this app. */
|
|
16
|
+
declare const list: () => Promise<InstalledPackage[]>;
|
|
17
|
+
/** Uninstall a package from this app; its frames and connections are torn down. */
|
|
18
|
+
declare const uninstall: (uri: string) => Promise<void>;
|
|
19
|
+
type ShowOptions = {
|
|
20
|
+
/**
|
|
21
|
+
* A placeholder the package frame is aligned to for as long as the view lives. The frame tracks its
|
|
22
|
+
* rect every animation frame, is clipped by its scrolling ancestors, and follows its border-radius,
|
|
23
|
+
* so it reads as inline content even though it renders in FKN's overlay.
|
|
24
|
+
*/
|
|
25
|
+
element?: HTMLElement;
|
|
26
|
+
/** an explicit viewport rect, for a caller that tracks placement itself */
|
|
27
|
+
rect?: SurfaceRect;
|
|
28
|
+
};
|
|
29
|
+
type PackageView = {
|
|
30
|
+
/** release this view; equivalent to `packages.hide(uri, { element })` */
|
|
31
|
+
hide: () => void;
|
|
32
|
+
/** force a re-measure, e.g. right after a layout change the tracker cannot observe */
|
|
33
|
+
refresh: () => void;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Show an installed, connected package's frame over this page, aligned to `element` (or an explicit
|
|
37
|
+
* `rect`). The package renders its own UI there; the app keeps the space in its own layout. Take it
|
|
38
|
+
* back down with `hide()` on the returned view, or with `packages.hide(uri)`. Throws a PackagesError
|
|
39
|
+
* with code 'not-installed' when the package has not been connected by this app.
|
|
40
|
+
*/
|
|
41
|
+
declare const show: (uri: string, options: ShowOptions) => Promise<PackageView>;
|
|
42
|
+
/**
|
|
43
|
+
* Hide a package's frame again, the counterpart to `show()`. Pass the same `element` to release only
|
|
44
|
+
* the view bound to it; with no element every view of this package is released. The connection is
|
|
45
|
+
* untouched, so the package can be shown again.
|
|
46
|
+
*/
|
|
47
|
+
declare const hide: (uri: string, options?: ShowOptions) => Promise<void>;
|
|
48
|
+
type PackageConnection<T = unknown> = {
|
|
49
|
+
/** the package's exposed payload */
|
|
50
|
+
remote: Remote<T>;
|
|
51
|
+
/** settles when the package side of the connection dies (uninstall, reload, crash) - reconnect by calling connect() again */
|
|
52
|
+
closed: Promise<void>;
|
|
53
|
+
/** the raw channel under `remote`, for direct messaging (osra envelopes ride it too - filter by your own message shape) */
|
|
54
|
+
port: MessagePort;
|
|
55
|
+
};
|
|
56
|
+
type AppConnectOptions = ConnectOptions & {
|
|
57
|
+
/** exposed to the package as ITS `remote` */
|
|
58
|
+
payload?: unknown;
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
/** skip the osra handshake and hand back the untouched port - e.g. to transfer it into a worker and attach() there */
|
|
61
|
+
raw?: boolean;
|
|
62
|
+
};
|
|
63
|
+
type RawPackageConnection = Omit<PackageConnection<never>, 'remote'>;
|
|
64
|
+
type Connect = {
|
|
65
|
+
<T = unknown>(uri: string, options?: AppConnectOptions & {
|
|
66
|
+
raw?: false;
|
|
67
|
+
}): Promise<PackageConnection<T>>;
|
|
68
|
+
(uri: string, options: AppConnectOptions & {
|
|
69
|
+
raw: true;
|
|
70
|
+
}): Promise<RawPackageConnection>;
|
|
71
|
+
};
|
|
72
|
+
/** Connect to an installed package. Throws a PackagesError with code 'not-installed' when it is not. */
|
|
73
|
+
declare const connect: Connect;
|
|
74
|
+
type MountOptions = AppConnectOptions & {
|
|
75
|
+
/**
|
|
76
|
+
* the iframe the package is loaded into. YOU create it and YOU own it: its attributes, its styles and
|
|
77
|
+
* its place in your layout are yours, and `mount` only navigates it.
|
|
78
|
+
*
|
|
79
|
+
* Set `allow` yourself for anything the package needs delegated, e.g. `allow="fullscreen; autoplay"`.
|
|
80
|
+
* Permissions policy is not inherited, so a capability this frame is not granted cannot be recovered
|
|
81
|
+
* by the package or by anything it nests inside itself.
|
|
82
|
+
*/
|
|
83
|
+
iframe: HTMLIFrameElement;
|
|
84
|
+
};
|
|
85
|
+
type MountedPackage<T = unknown> = PackageConnection<T> & {
|
|
86
|
+
/** the iframe you passed in, unchanged apart from its `src` */
|
|
87
|
+
frame: HTMLIFrameElement;
|
|
88
|
+
/** blank the frame and settle `closed`; the element stays in your layout because it is yours */
|
|
89
|
+
unmount: () => void;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Load a package into an iframe of YOUR OWN and connect to it, instead of positioning a frame the broker
|
|
93
|
+
* owns and clipping the overlay to it the way `show()` does.
|
|
94
|
+
*
|
|
95
|
+
* You pass the iframe, the same way `cloud.attachFrame` takes one. It lays out, scrolls, stacks and
|
|
96
|
+
* fullscreens with the rest of your page, there is no geometry to translate, and every attribute on it
|
|
97
|
+
* stays exactly as you set it: `mount` reads `sandbox` and `allow` to check the package can boot, then
|
|
98
|
+
* writes nothing but `src`. The package still gets its own origin and its own broker connection.
|
|
99
|
+
*
|
|
100
|
+
* Grant capabilities through the iframe's own `allow`, before calling this. Permissions policy is read
|
|
101
|
+
* at navigation and is not inherited, so it cannot be added afterwards on the frame handed back.
|
|
102
|
+
*
|
|
103
|
+
* Needs a package built against this version of the lib: an older one only accepts a port from fkn.app.
|
|
104
|
+
* The package reads `brokered: false`.
|
|
105
|
+
*/
|
|
106
|
+
declare const mount: <T = unknown>(uri: string, options: MountOptions) => Promise<MountedPackage<T>>;
|
|
107
|
+
/** Run this end of an already-brokered connection port, e.g. after transferring it into a worker. */
|
|
108
|
+
declare const attach: <T = unknown>(port: MessagePort, payload?: unknown, options?: {
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
}) => Promise<Remote<T>>;
|
|
111
|
+
type IncomingConnectionInfo = {
|
|
112
|
+
/**
|
|
113
|
+
* The connecting app's identity: its package uri when it runs on a sandbox origin, else its page
|
|
114
|
+
* origin. Proof of nothing unless `brokered` is true: under `packages.mount`, or in any page that
|
|
115
|
+
* frames this package's url itself, the embedder writes whatever it likes here.
|
|
116
|
+
*/
|
|
117
|
+
from: string;
|
|
118
|
+
/**
|
|
119
|
+
* True only when fkn.app's broker made this connection (`packages.connect`), so `from` is the app the
|
|
120
|
+
* broker identified by its browser-set origin. False under `packages.mount` and for any other embedder.
|
|
121
|
+
* Worked out here from the origin of the message that carried the port, never read from the message.
|
|
122
|
+
* Key what a connection is allowed (a grant you stored, an app named to the person) to `from` only
|
|
123
|
+
* when this is true. A package built on a lib older than this field gets none, so test `=== true`.
|
|
124
|
+
*/
|
|
125
|
+
brokered: boolean;
|
|
126
|
+
/** the contract tag the app passed to connect(), e.g. 'stub-source@1' */
|
|
127
|
+
protocol: string | null;
|
|
128
|
+
/** this package's normalized uri per the connecting app's install record, e.g. 'npm:@banou/stub-source-example' */
|
|
129
|
+
uri: string;
|
|
130
|
+
/** this package's npm name */
|
|
131
|
+
name: string;
|
|
132
|
+
/** the exact version this frame runs - the pin is encoded into the sandbox origin, immutable per version */
|
|
133
|
+
version: string;
|
|
134
|
+
};
|
|
135
|
+
type IncomingConnection<T = unknown> = IncomingConnectionInfo & PackageConnection<T>;
|
|
136
|
+
/** produces the payload exposed to a connecting app - called once per incoming connection */
|
|
137
|
+
type ConnectPayload = (info: IncomingConnectionInfo) => unknown;
|
|
138
|
+
/**
|
|
139
|
+
* Serve connections from apps that installed this package. The first argument is called once per
|
|
140
|
+
* incoming connection with the connection info and returns the payload exposed to that app (its
|
|
141
|
+
* `remote`). The latest registration receives new connections; existing connections are unaffected.
|
|
142
|
+
*/
|
|
143
|
+
declare const onConnect: <T = unknown>(createPayload: ConnectPayload, handler?: (connection: IncomingConnection<T>) => void) => {
|
|
144
|
+
unsubscribe: () => void;
|
|
145
|
+
};
|
|
146
|
+
/** True while a host app is showing this package's frame. Packages start hidden. */
|
|
147
|
+
declare const isVisible: () => boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Observe whether a host app is showing this package's frame, so it can render its UI only while on
|
|
150
|
+
* screen. The handler is called immediately with the current state, and on every change after.
|
|
151
|
+
*/
|
|
152
|
+
declare const onVisibilityChange: (handler: (visible: boolean) => void) => {
|
|
153
|
+
unsubscribe: () => void;
|
|
154
|
+
};
|
|
155
|
+
export { pick as C, uninstall as E, 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, 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 };
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { t as e } from "./rolldown-runtime-CGnMp29N.js";
|
|
2
|
+
import { c as t, l as n, o as r, u as i } from "./api-DRglK7ft.js";
|
|
3
|
+
import { i as a, t as o } from "./busy-C1JPjoZ_.js";
|
|
4
|
+
import { expose as s } from "osra";
|
|
5
|
+
// src/packages.ts
|
|
6
|
+
var c = /* @__PURE__ */ e({
|
|
7
|
+
attach: () => I,
|
|
8
|
+
connect: () => A,
|
|
9
|
+
hide: () => k,
|
|
10
|
+
install: () => v,
|
|
11
|
+
isVisible: () => X,
|
|
12
|
+
list: () => y,
|
|
13
|
+
mount: () => F,
|
|
14
|
+
onConnect: () => Y,
|
|
15
|
+
onVisibilityChange: () => Z,
|
|
16
|
+
pick: () => _,
|
|
17
|
+
search: () => g,
|
|
18
|
+
show: () => O,
|
|
19
|
+
uninstall: () => b
|
|
20
|
+
}), l = "fkn-packages-connection", u = "https://fkn.app", d = 3e4, f = (e, t) => Object.assign(Error(t), { code: e }), p = async () => {
|
|
21
|
+
if (!n) throw f("unavailable", "packages: no FKN transport in this realm - use relayWorker to bridge workers");
|
|
22
|
+
return r;
|
|
23
|
+
}, m = (e, t, n) => s(e ?? {}, {
|
|
24
|
+
transport: t,
|
|
25
|
+
key: l,
|
|
26
|
+
unregisterSignal: n
|
|
27
|
+
}), h = async (e, t, n = {}) => {
|
|
28
|
+
let { signal: r, closed: i } = n;
|
|
29
|
+
if (r?.aborted) throw f("unavailable", "packages.connect: aborted before connecting");
|
|
30
|
+
let a = new AbortController();
|
|
31
|
+
r && r.addEventListener("abort", () => a.abort(r.reason), { once: !0 });
|
|
32
|
+
let o = new AbortController(), s = new Promise((e, n) => {
|
|
33
|
+
let a = setTimeout(() => n(f("timeout", "packages.connect: the package did not complete the connection")), d);
|
|
34
|
+
o.signal.addEventListener("abort", () => clearTimeout(a), { once: !0 }), t.addEventListener("message", (e) => {
|
|
35
|
+
if (e.data?.type === "fkn-packages-nack") {
|
|
36
|
+
let t = e.data.message;
|
|
37
|
+
n(f("unavailable", typeof t == "string" && t ? t : "packages.connect: the package refused the connection"));
|
|
38
|
+
}
|
|
39
|
+
}, { signal: o.signal }), t.start(), r && r.addEventListener("abort", () => n(f("unavailable", "packages.connect: aborted before connecting")), {
|
|
40
|
+
once: !0,
|
|
41
|
+
signal: o.signal
|
|
42
|
+
}), i?.then(() => n(f("unavailable", "packages.connect: the package closed before connecting")));
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
return await Promise.race([m(e, t, a.signal), s]);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
a.abort(e);
|
|
48
|
+
try {
|
|
49
|
+
t.close();
|
|
50
|
+
} catch {}
|
|
51
|
+
throw e;
|
|
52
|
+
} finally {
|
|
53
|
+
o.abort();
|
|
54
|
+
}
|
|
55
|
+
}, g = async (e) => {
|
|
56
|
+
let t = await (await p()).packages.search(e);
|
|
57
|
+
if ("error" in t) throw f(t.error, t.message);
|
|
58
|
+
return t.results;
|
|
59
|
+
}, _ = async (e, t) => {
|
|
60
|
+
let n = await (await p()).packages.pick(e, t);
|
|
61
|
+
if ("error" in n) throw f(n.error, n.message);
|
|
62
|
+
return "declined" in n ? [] : n.results;
|
|
63
|
+
}, v = async (e, t) => {
|
|
64
|
+
let n = await (await p()).packages.install(e, t);
|
|
65
|
+
if ("error" in n) throw f(n.error, n.message);
|
|
66
|
+
return "declined" in n ? null : n.installed;
|
|
67
|
+
}, y = async () => (await (await p()).packages.list()).results, b = async (e) => {
|
|
68
|
+
let t = await (await p()).packages.uninstall(e);
|
|
69
|
+
if ("error" in t) throw f(t.error, t.message);
|
|
70
|
+
}, x = ({ x: e, y: t, width: n, height: r }) => ({
|
|
71
|
+
x: Math.round(e),
|
|
72
|
+
y: Math.round(t),
|
|
73
|
+
width: Math.round(n),
|
|
74
|
+
height: Math.round(r)
|
|
75
|
+
}), S = (e, t) => {
|
|
76
|
+
let n = Math.max(e.x, t.x), r = Math.max(e.y, t.y);
|
|
77
|
+
return {
|
|
78
|
+
x: n,
|
|
79
|
+
y: r,
|
|
80
|
+
width: Math.max(0, Math.min(e.x + e.width, t.x + t.width) - n),
|
|
81
|
+
height: Math.max(0, Math.min(e.y + e.height, t.y + t.height) - r)
|
|
82
|
+
};
|
|
83
|
+
}, C = (e, t) => {
|
|
84
|
+
let n = t;
|
|
85
|
+
for (let t = e.parentElement; t; t = t.parentElement) {
|
|
86
|
+
let e = getComputedStyle(t);
|
|
87
|
+
if ((e.overflowX !== "visible" || e.overflowY !== "visible") && (n = S(n, x(t.getBoundingClientRect())), n.width === 0 || n.height === 0)) break;
|
|
88
|
+
}
|
|
89
|
+
return n;
|
|
90
|
+
}, w = (e) => {
|
|
91
|
+
let t = getComputedStyle(e), n = [
|
|
92
|
+
t.borderTopLeftRadius,
|
|
93
|
+
t.borderTopRightRadius,
|
|
94
|
+
t.borderBottomRightRadius,
|
|
95
|
+
t.borderBottomLeftRadius
|
|
96
|
+
];
|
|
97
|
+
if (n.some((e) => e.includes("%") || e.includes(" "))) return;
|
|
98
|
+
let r = n.map((e) => {
|
|
99
|
+
let t = Number.parseFloat(e);
|
|
100
|
+
return Number.isFinite(t) && t > 0 ? t : 0;
|
|
101
|
+
});
|
|
102
|
+
return r.some((e) => e > 0) ? r : void 0;
|
|
103
|
+
}, T = (e, t) => {
|
|
104
|
+
if (!e) return !1;
|
|
105
|
+
let n = (e, t) => e === t || !!e && !!t && e.x === t.x && e.y === t.y && e.width === t.width && e.height === t.height;
|
|
106
|
+
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);
|
|
107
|
+
}, E = /* @__PURE__ */ new Map();
|
|
108
|
+
a("package view", () => E.size > 0);
|
|
109
|
+
var D = async (e, t) => {
|
|
110
|
+
let n = E.get(e);
|
|
111
|
+
if (n) {
|
|
112
|
+
for (let e of n) t && e.element !== t || (e.stop(), n.delete(e));
|
|
113
|
+
if (n.size > 0) return;
|
|
114
|
+
E.delete(e);
|
|
115
|
+
}
|
|
116
|
+
let r = await (await p()).packages.hide(e);
|
|
117
|
+
if ("error" in r) throw f(r.error, r.message);
|
|
118
|
+
}, O = async (e, t) => {
|
|
119
|
+
let { element: n, rect: r } = t;
|
|
120
|
+
if (!n && !r) throw f("invalid", "packages.show: pass an element or a rect");
|
|
121
|
+
let i = (await p()).packages, a = () => {
|
|
122
|
+
if (!n) return { rect: x(r) };
|
|
123
|
+
let e = x(n.getBoundingClientRect());
|
|
124
|
+
return {
|
|
125
|
+
rect: e,
|
|
126
|
+
clip: C(n, e),
|
|
127
|
+
radius: w(n)
|
|
128
|
+
};
|
|
129
|
+
}, o = !0, s, c = 0, l = async (t) => {
|
|
130
|
+
s = t;
|
|
131
|
+
let n = await i.show(e, t);
|
|
132
|
+
if ("error" in n) throw o = !1, f(n.error, n.message);
|
|
133
|
+
};
|
|
134
|
+
await l(a());
|
|
135
|
+
let u = () => {
|
|
136
|
+
if (!o) return;
|
|
137
|
+
let e = a();
|
|
138
|
+
T(s, e) || l(e).catch(() => {}), c = requestAnimationFrame(u);
|
|
139
|
+
};
|
|
140
|
+
n && (c = requestAnimationFrame(u));
|
|
141
|
+
let d = {
|
|
142
|
+
element: n,
|
|
143
|
+
stop: () => {
|
|
144
|
+
o = !1, cancelAnimationFrame(c);
|
|
145
|
+
}
|
|
146
|
+
}, m = E.get(e) ?? /* @__PURE__ */ new Set();
|
|
147
|
+
return m.add(d), E.set(e, m), {
|
|
148
|
+
hide: () => {
|
|
149
|
+
D(e, n).catch(() => {});
|
|
150
|
+
},
|
|
151
|
+
refresh: () => {
|
|
152
|
+
if (!o) return;
|
|
153
|
+
let e = a();
|
|
154
|
+
T(s, e) || l(e).catch(() => {});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}, k = async (e, t = {}) => D(e, t.element), A = (async (e, n = {}) => {
|
|
158
|
+
let r = await (await p()).packages.connect(e, {
|
|
159
|
+
protocol: n.protocol,
|
|
160
|
+
...n.path === void 0 ? {} : { path: n.path }
|
|
161
|
+
});
|
|
162
|
+
if ("error" in r) throw f(r.error, r.message);
|
|
163
|
+
let a = o("package connection"), s = t()?.epoch ?? 0, c = i((e, t) => {
|
|
164
|
+
t !== s && (a(), c());
|
|
165
|
+
});
|
|
166
|
+
Promise.resolve(r.closed).then(() => {
|
|
167
|
+
a(), c();
|
|
168
|
+
}, () => {
|
|
169
|
+
a(), c();
|
|
170
|
+
});
|
|
171
|
+
let { port: l, closed: u } = r;
|
|
172
|
+
if (n.raw) return {
|
|
173
|
+
closed: u,
|
|
174
|
+
port: l
|
|
175
|
+
};
|
|
176
|
+
let d = await h(n.payload, l, {
|
|
177
|
+
signal: n.signal,
|
|
178
|
+
closed: u
|
|
179
|
+
});
|
|
180
|
+
return n.signal && n.signal.addEventListener("abort", () => {
|
|
181
|
+
try {
|
|
182
|
+
l.postMessage({ type: "fkn-packages-disconnect" });
|
|
183
|
+
} catch {}
|
|
184
|
+
}, { once: !0 }), {
|
|
185
|
+
remote: d,
|
|
186
|
+
closed: u,
|
|
187
|
+
port: l
|
|
188
|
+
};
|
|
189
|
+
}), j = ["allow-scripts", "allow-same-origin"], M = (e) => {
|
|
190
|
+
let t = e.getAttribute("sandbox");
|
|
191
|
+
if (t !== null) {
|
|
192
|
+
let e = new Set(t.toLowerCase().split(/\s+/).filter(Boolean)), n = j.filter((t) => !e.has(t));
|
|
193
|
+
if (n.length) throw f("invalid", `packages.mount: the iframe's sandbox attribute must include ${n.join(" and ")}, or the package cannot start`);
|
|
194
|
+
}
|
|
195
|
+
if (globalThis.crossOriginIsolated && !new Set((e.getAttribute("allow") ?? "").toLowerCase().split(";").map((e) => e.trim().split(/\s+/)[0]).filter(Boolean)).has("cross-origin-isolated")) throw f("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");
|
|
196
|
+
}, N = 3e4, P = (e, t) => new Promise((n, r) => {
|
|
197
|
+
let i = (e) => {
|
|
198
|
+
clearTimeout(o), window.removeEventListener("message", a), e ? r(e) : n();
|
|
199
|
+
}, a = (n) => {
|
|
200
|
+
if (n.source !== e.contentWindow || n.origin !== t) return;
|
|
201
|
+
let r = n.data;
|
|
202
|
+
if (r?.type === "fkn-packages-ready") return i();
|
|
203
|
+
r?.type === "fkn-packages-failed" && i(f("unavailable", typeof r.message == "string" && r.message ? r.message : "packages.mount: the package failed to boot"));
|
|
204
|
+
}, o = setTimeout(() => i(f("timeout", "packages.mount: the package did not register a connection handler")), N);
|
|
205
|
+
window.addEventListener("message", a);
|
|
206
|
+
}), F = async (e, t) => {
|
|
207
|
+
let { iframe: n } = t;
|
|
208
|
+
if (!(n instanceof HTMLIFrameElement)) throw f("invalid", "packages.mount: pass the iframe to load the package into");
|
|
209
|
+
if (!n.isConnected) throw f("invalid", "packages.mount: the iframe must be in the document before mounting into it");
|
|
210
|
+
M(n);
|
|
211
|
+
let r = await (await p()).packages.frame(e);
|
|
212
|
+
if ("error" in r) throw f(r.error, r.message);
|
|
213
|
+
n.src = r.url;
|
|
214
|
+
let i = { done: !1 }, a = () => {}, s = new Promise((e) => {
|
|
215
|
+
a = e;
|
|
216
|
+
}), c = o("mounted package"), l = () => {
|
|
217
|
+
if (!i.done) {
|
|
218
|
+
i.done = !0, c();
|
|
219
|
+
try {
|
|
220
|
+
n.contentWindow?.postMessage({ type: "fkn-packages-close" }, r.origin);
|
|
221
|
+
} catch {}
|
|
222
|
+
n.src = "about:blank", a();
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
try {
|
|
226
|
+
await P(n, r.origin);
|
|
227
|
+
} catch (e) {
|
|
228
|
+
throw l(), e;
|
|
229
|
+
}
|
|
230
|
+
let u = new MessageChannel(), d = n.contentWindow;
|
|
231
|
+
if (!d) throw l(), f("unavailable", "packages.mount: the frame was detached before it could connect");
|
|
232
|
+
d.postMessage({
|
|
233
|
+
type: "fkn-packages-port",
|
|
234
|
+
from: r.from,
|
|
235
|
+
protocol: t.protocol,
|
|
236
|
+
uri: r.uri,
|
|
237
|
+
name: r.name,
|
|
238
|
+
version: r.version
|
|
239
|
+
}, r.origin, [u.port2]);
|
|
240
|
+
try {
|
|
241
|
+
d.postMessage({
|
|
242
|
+
type: "fkn-packages-visibility",
|
|
243
|
+
visible: !0
|
|
244
|
+
}, r.origin);
|
|
245
|
+
} catch {}
|
|
246
|
+
if (t.raw) return {
|
|
247
|
+
closed: s,
|
|
248
|
+
port: u.port1,
|
|
249
|
+
frame: n,
|
|
250
|
+
unmount: l
|
|
251
|
+
};
|
|
252
|
+
try {
|
|
253
|
+
return {
|
|
254
|
+
remote: await h(t.payload, u.port1, {
|
|
255
|
+
signal: t.signal,
|
|
256
|
+
closed: s
|
|
257
|
+
}),
|
|
258
|
+
closed: s,
|
|
259
|
+
port: u.port1,
|
|
260
|
+
frame: n,
|
|
261
|
+
unmount: l
|
|
262
|
+
};
|
|
263
|
+
} catch (e) {
|
|
264
|
+
throw l(), e;
|
|
265
|
+
}
|
|
266
|
+
}, I = (e, t, n) => h(t, e, { signal: n?.signal }), L = null, R = !1, z = /* @__PURE__ */ new Set(), B = [], V = /* @__PURE__ */ new Map(), H = !1, U = !1, W = (e) => {
|
|
267
|
+
let t = V.get(e);
|
|
268
|
+
t && (V.delete(e), t());
|
|
269
|
+
}, G = (e, t) => {
|
|
270
|
+
try {
|
|
271
|
+
e.postMessage({
|
|
272
|
+
type: "fkn-packages-nack",
|
|
273
|
+
message: t
|
|
274
|
+
});
|
|
275
|
+
} catch {}
|
|
276
|
+
try {
|
|
277
|
+
e.close();
|
|
278
|
+
} catch {}
|
|
279
|
+
}, K = async (e, t) => {
|
|
280
|
+
let { port: n, ...r } = e;
|
|
281
|
+
e.port.addEventListener("message", (t) => {
|
|
282
|
+
t.data?.type === "fkn-packages-disconnect" && W(e.port);
|
|
283
|
+
});
|
|
284
|
+
let i;
|
|
285
|
+
try {
|
|
286
|
+
i = await t.createPayload(r);
|
|
287
|
+
} catch (t) {
|
|
288
|
+
throw G(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
|
|
289
|
+
}
|
|
290
|
+
let a = new Promise((t) => V.set(e.port, t)), o = await m(i, e.port);
|
|
291
|
+
t.handler?.({
|
|
292
|
+
...r,
|
|
293
|
+
remote: o,
|
|
294
|
+
closed: a,
|
|
295
|
+
port: e.port
|
|
296
|
+
});
|
|
297
|
+
}, q = () => {
|
|
298
|
+
H || typeof window > "u" || window.parent === window || (H = !0, window.addEventListener("message", (e) => {
|
|
299
|
+
if (e.source !== window.parent) return;
|
|
300
|
+
let t = e.data;
|
|
301
|
+
if (t?.type === "fkn-packages-port") {
|
|
302
|
+
let n = e.ports[0];
|
|
303
|
+
if (!n) return;
|
|
304
|
+
let r = {
|
|
305
|
+
port: n,
|
|
306
|
+
from: typeof t.from == "string" ? t.from : "",
|
|
307
|
+
brokered: e.origin === u,
|
|
308
|
+
protocol: typeof t.protocol == "string" ? t.protocol : null,
|
|
309
|
+
uri: typeof t.uri == "string" ? t.uri : "",
|
|
310
|
+
name: typeof t.name == "string" ? t.name : "",
|
|
311
|
+
version: typeof t.version == "string" ? t.version : ""
|
|
312
|
+
};
|
|
313
|
+
L ? K(r, L).catch((e) => console.warn("packages.onConnect:", e)) : B.push(r);
|
|
314
|
+
}
|
|
315
|
+
if (t?.type === "fkn-packages-close") for (let e of [...V.keys()]) W(e);
|
|
316
|
+
if (t?.type === "fkn-packages-visibility") {
|
|
317
|
+
R = t.visible === !0;
|
|
318
|
+
for (let e of z) try {
|
|
319
|
+
e(R);
|
|
320
|
+
} catch {}
|
|
321
|
+
}
|
|
322
|
+
}));
|
|
323
|
+
}, J = () => {
|
|
324
|
+
U || typeof window > "u" || window.parent === window || (U = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, "*"));
|
|
325
|
+
}, Y = (e, t) => {
|
|
326
|
+
if (typeof window > "u") return { unsubscribe: () => {} };
|
|
327
|
+
q();
|
|
328
|
+
let n = {
|
|
329
|
+
createPayload: e,
|
|
330
|
+
handler: t
|
|
331
|
+
};
|
|
332
|
+
for (L = n, J(); B.length && L === n;) K(B.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
|
|
333
|
+
return { unsubscribe: () => {
|
|
334
|
+
L === n && (L = null);
|
|
335
|
+
} };
|
|
336
|
+
}, X = () => R, Z = (e) => {
|
|
337
|
+
if (typeof window > "u") return { unsubscribe: () => {} };
|
|
338
|
+
q(), z.add(e);
|
|
339
|
+
try {
|
|
340
|
+
e(R);
|
|
341
|
+
} catch {}
|
|
342
|
+
return { unsubscribe: () => {
|
|
343
|
+
z.delete(e);
|
|
344
|
+
} };
|
|
345
|
+
};
|
|
346
|
+
export { X as a, Y as c, _ as d, g as f, v as i, Z as l, b as m, A as n, y as o, O as p, k as r, F as s, I as t, c as u };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-DrvhPN56.cjs"),n=require("./busy-BXbVH595.cjs");let r=require("osra");var i=e.t({attach:()=>M,connect:()=>E,hide:()=>T,install:()=>m,isVisible:()=>K,list:()=>h,mount:()=>j,onConnect:()=>G,onVisibilityChange:()=>q,pick:()=>p,search:()=>f,show:()=>w,uninstall:()=>g}),a=`fkn-packages-connection`,o=`https://fkn.app`,s=3e4,c=(e,t)=>Object.assign(Error(t),{code:e}),l=async()=>{if(!t.l)throw c(`unavailable`,`packages: no FKN transport in this realm - use relayWorker to bridge workers`);return t.o},u=(e,t,n)=>(0,r.expose)(e??{},{transport:t,key:a,unregisterSignal:n}),d=async(e,t,n={})=>{let{signal:r,closed:i}=n;if(r?.aborted)throw c(`unavailable`,`packages.connect: aborted before connecting`);let a=new AbortController;r&&r.addEventListener(`abort`,()=>a.abort(r.reason),{once:!0});let o=new AbortController,l=new Promise((e,n)=>{let a=setTimeout(()=>n(c(`timeout`,`packages.connect: the package did not complete the connection`)),s);o.signal.addEventListener(`abort`,()=>clearTimeout(a),{once:!0}),t.addEventListener(`message`,e=>{if(e.data?.type===`fkn-packages-nack`){let t=e.data.message;n(c(`unavailable`,typeof t==`string`&&t?t:`packages.connect: the package refused the connection`))}},{signal:o.signal}),t.start(),r&&r.addEventListener(`abort`,()=>n(c(`unavailable`,`packages.connect: aborted before connecting`)),{once:!0,signal:o.signal}),i?.then(()=>n(c(`unavailable`,`packages.connect: the package closed before connecting`)))});try{return await Promise.race([u(e,t,a.signal),l])}catch(e){a.abort(e);try{t.close()}catch{}throw e}finally{o.abort()}},f=async e=>{let t=await(await l()).packages.search(e);if(`error`in t)throw c(t.error,t.message);return t.results},p=async(e,t)=>{let n=await(await l()).packages.pick(e,t);if(`error`in n)throw c(n.error,n.message);return`declined`in n?[]:n.results},m=async(e,t)=>{let n=await(await l()).packages.install(e,t);if(`error`in n)throw c(n.error,n.message);return`declined`in n?null:n.installed},h=async()=>(await(await l()).packages.list()).results,g=async e=>{let t=await(await l()).packages.uninstall(e);if(`error`in t)throw c(t.error,t.message)},_=({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=(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)}},y=(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=v(n,_(t.getBoundingClientRect())),n.width===0||n.height===0))break}return n},b=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},x=(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)},S=new Map;n.i(`package view`,()=>S.size>0);var C=async(e,t)=>{let n=S.get(e);if(n){for(let e of n)t&&e.element!==t||(e.stop(),n.delete(e));if(n.size>0)return;S.delete(e)}let r=await(await l()).packages.hide(e);if(`error`in r)throw c(r.error,r.message)},w=async(e,t)=>{let{element:n,rect:r}=t;if(!n&&!r)throw c(`invalid`,`packages.show: pass an element or a rect`);let i=(await l()).packages,a=()=>{if(!n)return{rect:_(r)};let e=_(n.getBoundingClientRect());return{rect:e,clip:y(n,e),radius:b(n)}},o=!0,s,u=0,d=async t=>{s=t;let n=await i.show(e,t);if(`error`in n)throw o=!1,c(n.error,n.message)};await d(a());let f=()=>{if(!o)return;let e=a();x(s,e)||d(e).catch(()=>{}),u=requestAnimationFrame(f)};n&&(u=requestAnimationFrame(f));let p={element:n,stop:()=>{o=!1,cancelAnimationFrame(u)}},m=S.get(e)??new Set;return m.add(p),S.set(e,m),{hide:()=>{C(e,n).catch(()=>{})},refresh:()=>{if(!o)return;let e=a();x(s,e)||d(e).catch(()=>{})}}},T=async(e,t={})=>C(e,t.element),E=(async(e,r={})=>{let i=await(await l()).packages.connect(e,{protocol:r.protocol,...r.path===void 0?{}:{path:r.path}});if(`error`in i)throw c(i.error,i.message);let a=n.t(`package connection`),o=t.c()?.epoch??0,s=t.u((e,t)=>{t!==o&&(a(),s())});Promise.resolve(i.closed).then(()=>{a(),s()},()=>{a(),s()});let{port:u,closed:f}=i;if(r.raw)return{closed:f,port:u};let p=await d(r.payload,u,{signal:r.signal,closed:f});return r.signal&&r.signal.addEventListener(`abort`,()=>{try{u.postMessage({type:`fkn-packages-disconnect`})}catch{}},{once:!0}),{remote:p,closed:f,port:u}}),D=[`allow-scripts`,`allow-same-origin`],O=e=>{let t=e.getAttribute(`sandbox`);if(t!==null){let e=new Set(t.toLowerCase().split(/\s+/).filter(Boolean)),n=D.filter(t=>!e.has(t));if(n.length)throw c(`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 c(`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`)},k=3e4,A=(e,t)=>new Promise((n,r)=>{let i=e=>{clearTimeout(o),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(c(`unavailable`,typeof r.message==`string`&&r.message?r.message:`packages.mount: the package failed to boot`))},o=setTimeout(()=>i(c(`timeout`,`packages.mount: the package did not register a connection handler`)),k);window.addEventListener(`message`,a)}),j=async(e,t)=>{let{iframe:r}=t;if(!(r instanceof HTMLIFrameElement))throw c(`invalid`,`packages.mount: pass the iframe to load the package into`);if(!r.isConnected)throw c(`invalid`,`packages.mount: the iframe must be in the document before mounting into it`);O(r);let i=await(await l()).packages.frame(e);if(`error`in i)throw c(i.error,i.message);r.src=i.url;let a={done:!1},o=()=>{},s=new Promise(e=>{o=e}),u=n.t(`mounted package`),f=()=>{if(!a.done){a.done=!0,u();try{r.contentWindow?.postMessage({type:`fkn-packages-close`},i.origin)}catch{}r.src=`about:blank`,o()}};try{await A(r,i.origin)}catch(e){throw f(),e}let p=new MessageChannel,m=r.contentWindow;if(!m)throw f(),c(`unavailable`,`packages.mount: the frame was detached before it could connect`);m.postMessage({type:`fkn-packages-port`,from:i.from,protocol:t.protocol,uri:i.uri,name:i.name,version:i.version},i.origin,[p.port2]);try{m.postMessage({type:`fkn-packages-visibility`,visible:!0},i.origin)}catch{}if(t.raw)return{closed:s,port:p.port1,frame:r,unmount:f};try{return{remote:await d(t.payload,p.port1,{signal:t.signal,closed:s}),closed:s,port:p.port1,frame:r,unmount:f}}catch(e){throw f(),e}},M=(e,t,n)=>d(t,e,{signal:n?.signal}),N=null,P=!1,F=new Set,I=[],L=new Map,R=!1,z=!1,B=e=>{let t=L.get(e);t&&(L.delete(e),t())},V=(e,t)=>{try{e.postMessage({type:`fkn-packages-nack`,message:t})}catch{}try{e.close()}catch{}},H=async(e,t)=>{let{port:n,...r}=e;e.port.addEventListener(`message`,t=>{t.data?.type===`fkn-packages-disconnect`&&B(e.port)});let i;try{i=await t.createPayload(r)}catch(t){throw V(e.port,t instanceof Error?t.message:`the package failed to produce a connection`),t}let a=new Promise(t=>L.set(e.port,t)),o=await u(i,e.port);t.handler?.({...r,remote:o,closed:a,port:e.port})},U=()=>{R||typeof window>`u`||window.parent===window||(R=!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:``,brokered:e.origin===o,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:``};N?H(r,N).catch(e=>console.warn(`packages.onConnect:`,e)):I.push(r)}if(t?.type===`fkn-packages-close`)for(let e of[...L.keys()])B(e);if(t?.type===`fkn-packages-visibility`){P=t.visible===!0;for(let e of F)try{e(P)}catch{}}}))},W=()=>{z||typeof window>`u`||window.parent===window||(z=!0,window.parent.postMessage({type:`fkn-packages-ready`},`*`))},G=(e,t)=>{if(typeof window>`u`)return{unsubscribe:()=>{}};U();let n={createPayload:e,handler:t};for(N=n,W();I.length&&N===n;)H(I.shift(),n).catch(e=>console.warn(`packages.onConnect:`,e));return{unsubscribe:()=>{N===n&&(N=null)}}},K=()=>P,q=e=>{if(typeof window>`u`)return{unsubscribe:()=>{}};U(),F.add(e);try{e(P)}catch{}return{unsubscribe:()=>{F.delete(e)}}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return i}});
|
package/packages.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./packages-DT8vPB5_.cjs");exports.attach=e.t,exports.connect=e.n,exports.hide=e.r,exports.install=e.i,exports.isVisible=e.a,exports.list=e.o,exports.mount=e.s,exports.onConnect=e.c,exports.onVisibilityChange=e.l,exports.pick=e.d,exports.search=e.f,exports.show=e.p,exports.uninstall=e.m;
|