@fkn/lib 0.9.10 → 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.
- package/{api-Dn793vCK.d.ts → api-VR2xHGZu.d.ts} +1 -1
- package/cloud/fetch.d.ts +1 -1
- package/cloud/net.d.ts +1 -1
- package/{cloud-DJARSquk.d.ts → cloud-DRzA41UW.d.ts} +2 -2
- package/cloud.d.ts +3 -3
- package/dgram.d.ts +1 -1
- package/http.d.ts +1 -1
- package/index.d.ts +3 -3
- package/{net-Q7SIsTHJ.d.ts → net-BhNzd0mR.d.ts} +1 -1
- package/net.d.ts +1 -1
- package/package.json +1 -1
- package/{packages-B03jnjRB.d.ts → packages-vX-1yfRK.d.ts} +18 -6
- package/packages.cjs +1 -1
- package/packages.d.ts +1 -1
- package/packages.js +70 -62
- package/{proxy-DasMm1_q.d.ts → proxy-CAjDHzfq.d.ts} +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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 = {
|
package/cloud/fetch.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as cloudFetch } from "../proxy-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
2
|
-
import { a as attachFrame, i as quota, r as QuotaStatus, t as available } from "./cloud-
|
|
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-
|
|
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
package/http.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Socket, t as Server$1 } from "./net-
|
|
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 { S as packages_d_exports } from "./packages-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
@@ -153,19 +153,31 @@ type Connect = {
|
|
|
153
153
|
/** Connect to an installed package. Throws a PackagesError with code 'not-installed' when it is not. */
|
|
154
154
|
declare const connect: Connect;
|
|
155
155
|
type MountOptions = AppConnectOptions & {
|
|
156
|
-
/**
|
|
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;
|
|
157
165
|
};
|
|
158
166
|
type MountedPackage<T = unknown> = PackageConnection<T> & {
|
|
159
|
-
/** the
|
|
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 */
|
|
160
168
|
unmount: () => void;
|
|
161
169
|
};
|
|
162
170
|
/**
|
|
163
|
-
*
|
|
171
|
+
* Load a package into an iframe of YOUR OWN and connect to it, instead of positioning a frame the broker
|
|
164
172
|
* owns and clipping the overlay to it the way `show()` does.
|
|
165
173
|
*
|
|
166
|
-
*
|
|
167
|
-
* page,
|
|
168
|
-
*
|
|
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.
|
|
169
181
|
*
|
|
170
182
|
* Needs a package built against this version of the lib: an older one only accepts a port from fkn.app.
|
|
171
183
|
*/
|
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:()=>
|
|
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 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-
|
|
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
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,15 +3,15 @@ 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: () =>
|
|
6
|
+
attach: () => j,
|
|
7
7
|
connect: () => T,
|
|
8
8
|
hide: () => w,
|
|
9
9
|
install: () => p,
|
|
10
|
-
isVisible: () =>
|
|
10
|
+
isVisible: () => G,
|
|
11
11
|
list: () => m,
|
|
12
|
-
mount: () =>
|
|
13
|
-
onConnect: () =>
|
|
14
|
-
onVisibilityChange: () =>
|
|
12
|
+
mount: () => A,
|
|
13
|
+
onConnect: () => W,
|
|
14
|
+
onVisibilityChange: () => K,
|
|
15
15
|
pick: () => f,
|
|
16
16
|
search: () => d,
|
|
17
17
|
show: () => C,
|
|
@@ -172,7 +172,14 @@ var i = /* @__PURE__ */ e({
|
|
|
172
172
|
closed: i,
|
|
173
173
|
port: r
|
|
174
174
|
};
|
|
175
|
-
}), E =
|
|
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) => {
|
|
176
183
|
let i = (e) => {
|
|
177
184
|
clearTimeout(o), window.removeEventListener("message", a), e ? r(e) : n();
|
|
178
185
|
}, a = (n) => {
|
|
@@ -180,66 +187,67 @@ var i = /* @__PURE__ */ e({
|
|
|
180
187
|
let r = n.data;
|
|
181
188
|
if (r?.type === "fkn-packages-ready") return i();
|
|
182
189
|
r?.type === "fkn-packages-failed" && i(s("unavailable", typeof r.message == "string" && r.message ? r.message : "packages.mount: the package failed to boot"));
|
|
183
|
-
}, o = setTimeout(() => i(s("timeout", "packages.mount: the package did not register a connection handler")),
|
|
190
|
+
}, o = setTimeout(() => i(s("timeout", "packages.mount: the package did not register a connection handler")), O);
|
|
184
191
|
window.addEventListener("message", a);
|
|
185
|
-
}),
|
|
186
|
-
let {
|
|
187
|
-
if (!n) throw s("invalid", "packages.mount: pass
|
|
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);
|
|
188
197
|
let r = await (await c()).packages.frame(e);
|
|
189
198
|
if ("error" in r) throw s(r.error, r.message);
|
|
190
|
-
|
|
191
|
-
i
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
a.done = !0;
|
|
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;
|
|
197
205
|
try {
|
|
198
|
-
|
|
206
|
+
n.contentWindow?.postMessage({ type: "fkn-packages-close" }, r.origin);
|
|
199
207
|
} catch {}
|
|
200
|
-
|
|
208
|
+
n.src = "about:blank", a();
|
|
201
209
|
}
|
|
202
210
|
};
|
|
203
211
|
try {
|
|
204
|
-
await
|
|
212
|
+
await k(n, r.origin);
|
|
205
213
|
} catch (e) {
|
|
206
|
-
throw
|
|
214
|
+
throw l(), e;
|
|
207
215
|
}
|
|
208
|
-
let
|
|
209
|
-
if (!
|
|
210
|
-
|
|
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({
|
|
211
219
|
type: "fkn-packages-port",
|
|
212
220
|
from: r.from,
|
|
213
221
|
protocol: t.protocol,
|
|
214
222
|
uri: r.uri,
|
|
215
223
|
name: r.name,
|
|
216
224
|
version: r.version
|
|
217
|
-
}, r.origin, [
|
|
225
|
+
}, r.origin, [d.port2]);
|
|
218
226
|
try {
|
|
219
|
-
|
|
227
|
+
f.postMessage({
|
|
220
228
|
type: "fkn-packages-visibility",
|
|
221
229
|
visible: !0
|
|
222
230
|
}, r.origin);
|
|
223
231
|
} catch {}
|
|
224
232
|
return t.raw ? {
|
|
225
|
-
closed:
|
|
226
|
-
port:
|
|
227
|
-
frame:
|
|
228
|
-
unmount:
|
|
233
|
+
closed: o,
|
|
234
|
+
port: d.port1,
|
|
235
|
+
frame: n,
|
|
236
|
+
unmount: l
|
|
229
237
|
} : {
|
|
230
|
-
remote: await u(t.payload,
|
|
238
|
+
remote: await u(t.payload, d.port1, {
|
|
231
239
|
signal: t.signal,
|
|
232
|
-
closed:
|
|
240
|
+
closed: o
|
|
233
241
|
}),
|
|
234
|
-
closed:
|
|
235
|
-
port:
|
|
236
|
-
frame:
|
|
237
|
-
unmount:
|
|
242
|
+
closed: o,
|
|
243
|
+
port: d.port1,
|
|
244
|
+
frame: n,
|
|
245
|
+
unmount: l
|
|
238
246
|
};
|
|
239
|
-
},
|
|
240
|
-
let t =
|
|
241
|
-
t && (
|
|
242
|
-
},
|
|
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) => {
|
|
243
251
|
try {
|
|
244
252
|
e.postMessage({
|
|
245
253
|
type: "fkn-packages-nack",
|
|
@@ -249,26 +257,26 @@ var i = /* @__PURE__ */ e({
|
|
|
249
257
|
try {
|
|
250
258
|
e.close();
|
|
251
259
|
} catch {}
|
|
252
|
-
},
|
|
260
|
+
}, V = async (e, t) => {
|
|
253
261
|
let { port: n, ...r } = e;
|
|
254
262
|
e.port.addEventListener("message", (t) => {
|
|
255
|
-
t.data?.type === "fkn-packages-disconnect" &&
|
|
263
|
+
t.data?.type === "fkn-packages-disconnect" && z(e.port);
|
|
256
264
|
});
|
|
257
265
|
let i;
|
|
258
266
|
try {
|
|
259
267
|
i = await t.createPayload(r);
|
|
260
268
|
} catch (t) {
|
|
261
|
-
throw
|
|
269
|
+
throw B(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
|
|
262
270
|
}
|
|
263
|
-
let a = new Promise((t) =>
|
|
271
|
+
let a = new Promise((t) => I.set(e.port, t)), o = await l(i, e.port);
|
|
264
272
|
t.handler?.({
|
|
265
273
|
...r,
|
|
266
274
|
remote: o,
|
|
267
275
|
closed: a,
|
|
268
276
|
port: e.port
|
|
269
277
|
});
|
|
270
|
-
},
|
|
271
|
-
|
|
278
|
+
}, H = () => {
|
|
279
|
+
L || typeof window > "u" || window.parent === window || (L = !0, window.addEventListener("message", (e) => {
|
|
272
280
|
if (e.source !== window.parent) return;
|
|
273
281
|
let t = e.data;
|
|
274
282
|
if (t?.type === "fkn-packages-port") {
|
|
@@ -282,38 +290,38 @@ var i = /* @__PURE__ */ e({
|
|
|
282
290
|
name: typeof t.name == "string" ? t.name : "",
|
|
283
291
|
version: typeof t.version == "string" ? t.version : ""
|
|
284
292
|
};
|
|
285
|
-
|
|
293
|
+
M ? V(r, M).catch((e) => console.warn("packages.onConnect:", e)) : F.push(r);
|
|
286
294
|
}
|
|
287
|
-
if (t?.type === "fkn-packages-close") for (let e of [...
|
|
295
|
+
if (t?.type === "fkn-packages-close") for (let e of [...I.keys()]) z(e);
|
|
288
296
|
if (t?.type === "fkn-packages-visibility") {
|
|
289
|
-
|
|
290
|
-
for (let e of
|
|
291
|
-
e(
|
|
297
|
+
N = t.visible === !0;
|
|
298
|
+
for (let e of P) try {
|
|
299
|
+
e(N);
|
|
292
300
|
} catch {}
|
|
293
301
|
}
|
|
294
302
|
}));
|
|
295
|
-
},
|
|
296
|
-
|
|
297
|
-
},
|
|
303
|
+
}, U = () => {
|
|
304
|
+
R || typeof window > "u" || window.parent === window || (R = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, "*"));
|
|
305
|
+
}, W = (e, t) => {
|
|
298
306
|
if (typeof window > "u") return { unsubscribe: () => {} };
|
|
299
|
-
|
|
307
|
+
H();
|
|
300
308
|
let n = {
|
|
301
309
|
createPayload: e,
|
|
302
310
|
handler: t
|
|
303
311
|
};
|
|
304
|
-
for (
|
|
312
|
+
for (M = n, U(); F.length && M === n;) V(F.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
|
|
305
313
|
return { unsubscribe: () => {
|
|
306
|
-
|
|
314
|
+
M === n && (M = null);
|
|
307
315
|
} };
|
|
308
|
-
},
|
|
316
|
+
}, G = () => N, K = (e) => {
|
|
309
317
|
if (typeof window > "u") return { unsubscribe: () => {} };
|
|
310
|
-
|
|
318
|
+
H(), P.add(e);
|
|
311
319
|
try {
|
|
312
|
-
e(
|
|
320
|
+
e(N);
|
|
313
321
|
} catch {}
|
|
314
322
|
return { unsubscribe: () => {
|
|
315
|
-
|
|
323
|
+
P.delete(e);
|
|
316
324
|
} };
|
|
317
325
|
};
|
|
318
326
|
//#endregion
|
|
319
|
-
export {
|
|
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 };
|