@fkn/lib 0.9.19 → 0.9.21
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/account.cjs +1 -1
- package/account.js +24 -17
- package/{api-DnO1DsJC.d.ts → api-B0qRPCcX.d.ts} +36 -37
- package/api-BqRjtWm_.js +311 -0
- package/api-CKO3Hw-O.cjs +3 -0
- package/busy-Bp1E3JPT.js +24 -0
- package/busy-Dv8wzE5M.cjs +1 -0
- package/cloud/dgram.cjs +1 -1
- package/cloud/dgram.js +1 -1
- package/cloud/fetch.cjs +1 -1
- package/cloud/fetch.d.ts +1 -1
- package/cloud/fetch.js +1 -1
- package/cloud/fs.cjs +1 -1
- package/cloud/fs.js +2 -2
- package/cloud/net.cjs +1 -1
- package/cloud/net.d.ts +1 -1
- package/cloud/net.js +1 -1
- package/cloud-BCQTex58.cjs +1 -0
- package/{cloud-uE4g-WqI.d.ts → cloud-BTpJn4jy.d.ts} +3 -3
- package/cloud-BlR1He17.js +212 -0
- package/cloud.cjs +1 -1
- package/cloud.d.ts +3 -3
- package/cloud.js +4 -4
- package/dgram-9hn582qO.cjs +1 -0
- package/{dgram-DlGl_ho1.js → dgram-TB03kqMr.js} +55 -49
- package/dgram.cjs +1 -1
- package/dgram.d.ts +2 -1
- package/dgram.js +1 -1
- package/dns.cjs +1 -1
- package/dns.js +1 -1
- package/extension-BI2NxGtC.js +78 -0
- package/{extension-CN9oFZ0Q.d.ts → extension-CMPZjuaV.d.ts} +1 -1
- package/extension-rFQQpEqJ.cjs +1 -0
- package/extension.cjs +1 -1
- package/extension.d.ts +2 -2
- package/extension.js +3 -3
- package/fs/promises.cjs +1 -1
- package/fs/promises.js +1 -1
- package/fs-BUcpl9k4.cjs +1 -0
- package/fs-bpb3Ysdd.js +347 -0
- package/fs.cjs +1 -1
- package/fs.js +1 -1
- package/http.cjs +1 -1
- package/http.d.ts +1 -1
- package/http.js +1 -1
- package/{index-DLaonjpx.d.ts → index-DY8WjklJ.d.ts} +82 -0
- package/index.cjs +1 -1
- package/index.d.ts +12 -18
- package/index.js +92 -39
- package/lib-DbiVHPXE.cjs +53 -0
- package/{lib-CegQxwDI.js → lib-k3lstfa4.js} +178 -131
- package/net-C2fIMWFr.cjs +1 -0
- package/{net-l7JVHsIR.d.ts → net-CnYxw_sB.d.ts} +3 -1
- package/{net-BbmQeMpt.js → net-Ct8ywVAk.js} +52 -41
- package/net.cjs +1 -1
- package/net.d.ts +1 -1
- package/net.js +1 -1
- package/node-fs-BZCQUmeE.js +404 -0
- package/node-fs-DZPGCYWg.cjs +1 -0
- package/opfs.cjs +1 -1
- package/opfs.js +1 -1
- package/package.json +1 -1
- package/{packages-vX-1yfRK.d.ts → packages-Cn8S-Hkn.d.ts} +20 -20
- package/packages.cjs +1 -1
- package/packages.d.ts +1 -1
- package/packages.js +165 -149
- package/proxy--aljNHvG.js +69 -0
- package/{proxy-7ib45Uo-.d.ts → proxy-CuXtzxSQ.d.ts} +1 -1
- package/proxy-oHfEx1cn.cjs +1 -0
- package/{storage-C8hBot2f.js → storage-C1nW5Tvh.js} +1 -1
- package/{storage-BW-jDLUL.cjs → storage-rXHvV2FU.cjs} +1 -1
- package/api-DQ-V4Lls.js +0 -220
- package/api-kHMHDGar.cjs +0 -3
- package/cloud-BQoppUw4.cjs +0 -1
- package/cloud-C8CeqUht.js +0 -130
- package/dgram-D2Or5f2e.cjs +0 -1
- package/extension-4BM5hKrn.cjs +0 -1
- package/extension-DVO10P3i.js +0 -78
- package/fs-BW5mVMmu.js +0 -340
- package/fs-DJm0bhjg.cjs +0 -1
- package/lib-ulyxIbTr.cjs +0 -53
- package/net-COzDDBnS.cjs +0 -1
- package/node-fs-BMR2yCEt.cjs +0 -1
- package/node-fs-DKfokOlh.js +0 -401
- package/proxy-B0gNjT8-.cjs +0 -1
- package/proxy-BpqvCJmA.js +0 -43
package/opfs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import { Remote } from "osra";
|
|
2
2
|
|
|
3
|
+
//#region src/api/packages/identity.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A connection's identity. `id` is the normalized package uri when the other end runs on a sandbox
|
|
6
|
+
* tenant origin (e.g. 'npm:@banou/stub'), otherwise its plain page origin. Version-pinned tenant
|
|
7
|
+
* origins normalize to the version-free id, so a package keeps one identity (and one set of install
|
|
8
|
+
* records) across its own updates, for every handler rather than only for npm.
|
|
9
|
+
*/
|
|
10
|
+
type Caller = {
|
|
11
|
+
id: string;
|
|
12
|
+
origin: string; /** a package's display name, when provenance knew it. Attribution only, never an identity. */
|
|
13
|
+
name?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Set when PROVENANCE established this caller is a package, which is the only way to know it for a
|
|
16
|
+
* connection whose `origin` is this realm's own (a broker nested inside a tenant we mounted). Every
|
|
17
|
+
* other package caller is recognised from its browser-set tenant origin instead.
|
|
18
|
+
*/
|
|
19
|
+
isPackage?: boolean;
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
3
22
|
//#region src/api/packages/types.d.ts
|
|
4
23
|
type PackageQuery = {
|
|
5
24
|
/** package kind, e.g. 'plugin' - becomes the keyword `fkn-type:<type>` */type: string; /** host app scope, e.g. 'stub' - becomes the keyword `fkn-<type>--<id>` */
|
|
@@ -61,25 +80,6 @@ type PackagesFail = {
|
|
|
61
80
|
message: string;
|
|
62
81
|
};
|
|
63
82
|
//#endregion
|
|
64
|
-
//#region src/api/packages/identity.d.ts
|
|
65
|
-
/**
|
|
66
|
-
* A connection's identity. `id` is the normalized package uri when the other end runs on a sandbox
|
|
67
|
-
* tenant origin (e.g. 'npm:@banou/stub'), otherwise its plain page origin. Version-pinned tenant
|
|
68
|
-
* origins normalize to the version-free id, so a package keeps one identity (and one set of install
|
|
69
|
-
* records) across its own updates, for every handler rather than only for npm.
|
|
70
|
-
*/
|
|
71
|
-
type Caller = {
|
|
72
|
-
id: string;
|
|
73
|
-
origin: string; /** a package's display name, when provenance knew it. Attribution only, never an identity. */
|
|
74
|
-
name?: string;
|
|
75
|
-
/**
|
|
76
|
-
* Set when PROVENANCE established this caller is a package, which is the only way to know it for a
|
|
77
|
-
* connection whose `origin` is this realm's own (a broker nested inside a tenant we mounted). Every
|
|
78
|
-
* other package caller is recognised from its browser-set tenant origin instead.
|
|
79
|
-
*/
|
|
80
|
-
isPackage?: boolean;
|
|
81
|
-
};
|
|
82
|
-
//#endregion
|
|
83
83
|
//#region src/api/packages/host.d.ts
|
|
84
84
|
type MountDescriptor = {
|
|
85
85
|
/** where to point the iframe: the tenant origin plus the package's path */url: string; /** the tenant origin alone, which is what a `postMessage` to that frame must target */
|
|
@@ -214,4 +214,4 @@ declare const onVisibilityChange: (handler: (visible: boolean) => void) => {
|
|
|
214
214
|
unsubscribe: () => void;
|
|
215
215
|
};
|
|
216
216
|
//#endregion
|
|
217
|
-
export {
|
|
217
|
+
export { InstalledPackage as A, pick as C, MountDescriptor as D, uninstall as E, PickOptions as F, Placement as I, Radii as L, PackageResult as M, PackagesErrorCode as N, ConnectOptions as O, PackagesFail as P, SurfaceRect as R, packages_d_exports as S, show as T, isVisible as _, IncomingConnectionInfo as a, onConnect as b, PackageConnection as c, RawPackageConnection as d, ShowOptions as f, install as g, hide as h, IncomingConnection as i, PackageQuery as j, InstallOptions as k, PackageView as l, connect as m, Connect as n, MountOptions as o, attach as p, ConnectPayload as r, MountedPackage as s, AppConnectOptions as t, PackagesError as u, list as v, search as w, onVisibilityChange as x, mount as y, Caller as z };
|
package/packages.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-CKO3Hw-O.cjs"),n=require("./busy-Dv8wzE5M.cjs");let r=require("osra");var i=e.t({attach:()=>j,connect:()=>T,hide:()=>w,install:()=>p,isVisible:()=>G,list:()=>m,mount:()=>A,onConnect:()=>W,onVisibilityChange:()=>K,pick:()=>f,search:()=>d,show:()=>C,uninstall:()=>h}),a=`fkn-packages-connection`,o=3e4,s=(e,t)=>Object.assign(Error(t),{code:e}),c=async()=>{if(!t.o)throw s(`unavailable`,`packages: no FKN transport in this realm - use relayWorker to bridge workers`);return t.r},l=(e,t,n)=>(0,r.expose)(e??{},{transport:t,key:a,unregisterSignal:n}),u=async(e,t,n={})=>{let{signal:r,closed:i}=n;if(r?.aborted)throw s(`unavailable`,`packages.connect: aborted before connecting`);let a=new AbortController;r&&r.addEventListener(`abort`,()=>a.abort(r.reason),{once:!0});let c=new AbortController,u=new Promise((e,n)=>{let a=setTimeout(()=>n(s(`timeout`,`packages.connect: the package did not complete the connection`)),o);c.signal.addEventListener(`abort`,()=>clearTimeout(a),{once:!0}),t.addEventListener(`message`,e=>{if(e.data?.type===`fkn-packages-nack`){let t=e.data.message;n(s(`unavailable`,typeof t==`string`&&t?t:`packages.connect: the package refused the connection`))}},{signal:c.signal}),t.start(),r&&r.addEventListener(`abort`,()=>n(s(`unavailable`,`packages.connect: aborted before connecting`)),{once:!0,signal:c.signal}),i?.then(()=>n(s(`unavailable`,`packages.connect: the package closed before connecting`)))});try{return await Promise.race([l(e,t,a.signal),u])}catch(e){a.abort(e);try{t.close()}catch{}throw e}finally{c.abort()}},d=async e=>{let t=await(await c()).packages.search(e);if(`error`in t)throw s(t.error,t.message);return t.results},f=async(e,t)=>{let n=await(await c()).packages.pick(e,t);if(`error`in n)throw s(n.error,n.message);return`declined`in n?[]:n.results},p=async(e,t)=>{let n=await(await c()).packages.install(e,t);if(`error`in n)throw s(n.error,n.message);return`declined`in n?null:n.installed},m=async()=>(await(await c()).packages.list()).results,h=async e=>{let t=await(await c()).packages.uninstall(e);if(`error`in t)throw s(t.error,t.message)},g=({x:e,y:t,width:n,height:r})=>({x:Math.round(e),y:Math.round(t),width:Math.round(n),height:Math.round(r)}),_=(e,t)=>{let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y);return{x:n,y:r,width:Math.max(0,Math.min(e.x+e.width,t.x+t.width)-n),height:Math.max(0,Math.min(e.y+e.height,t.y+t.height)-r)}},v=(e,t)=>{let n=t;for(let t=e.parentElement;t;t=t.parentElement){let e=getComputedStyle(t);if(!(e.overflowX===`visible`&&e.overflowY===`visible`)&&(n=_(n,g(t.getBoundingClientRect())),n.width===0||n.height===0))break}return n},y=e=>{let t=getComputedStyle(e),n=[t.borderTopLeftRadius,t.borderTopRightRadius,t.borderBottomRightRadius,t.borderBottomLeftRadius];if(n.some(e=>e.includes(`%`)||e.includes(` `)))return;let r=n.map(e=>{let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:0});return r.some(e=>e>0)?r:void 0},b=(e,t)=>{if(!e)return!1;let n=(e,t)=>e===t||!!e&&!!t&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height;return n(e.rect,t.rect)&&n(e.clip,t.clip)&&((e,t)=>e===t||!!e&&!!t&&e.every((e,n)=>e===t[n]))(e.radius,t.radius)},x=new Map;n.r(`package view`,()=>x.size>0);var S=async(e,t)=>{let n=x.get(e);if(n){for(let e of n)t&&e.element!==t||(e.stop(),n.delete(e));if(n.size>0)return;x.delete(e)}let r=await(await c()).packages.hide(e);if(`error`in r)throw s(r.error,r.message)},C=async(e,t)=>{let{element:n,rect:r}=t;if(!n&&!r)throw s(`invalid`,`packages.show: pass an element or a rect`);let i=(await c()).packages,a=()=>{if(!n)return{rect:g(r)};let e=g(n.getBoundingClientRect());return{rect:e,clip:v(n,e),radius:y(n)}},o=!0,l,u=0,d=async t=>{l=t;let n=await i.show(e,t);if(`error`in n)throw o=!1,s(n.error,n.message)};await d(a());let f=()=>{if(!o)return;let e=a();b(l,e)||d(e).catch(()=>{}),u=requestAnimationFrame(f)};n&&(u=requestAnimationFrame(f));let p={element:n,stop:()=>{o=!1,cancelAnimationFrame(u)}},m=x.get(e)??new Set;return m.add(p),x.set(e,m),{hide:()=>{S(e,n).catch(()=>{})},refresh:()=>{if(!o)return;let e=a();b(l,e)||d(e).catch(()=>{})}}},w=async(e,t={})=>S(e,t.element),T=(async(e,r={})=>{let i=await(await c()).packages.connect(e,{protocol:r.protocol});if(`error`in i)throw s(i.error,i.message);let a=n.t(`package connection`),o=t.a()?.epoch??0,l=t.s((e,t)=>{t!==o&&(a(),l())});Promise.resolve(i.closed).then(()=>{a(),l()},()=>{a(),l()});let{port:d,closed:f}=i;if(r.raw)return{closed:f,port:d};let p=await u(r.payload,d,{signal:r.signal,closed:f});return r.signal&&r.signal.addEventListener(`abort`,()=>{try{d.postMessage({type:`fkn-packages-disconnect`})}catch{}},{once:!0}),{remote:p,closed:f,port:d}}),E=[`allow-scripts`,`allow-same-origin`],D=e=>{let t=e.getAttribute(`sandbox`);if(t!==null){let e=new Set(t.toLowerCase().split(/\s+/).filter(Boolean)),n=E.filter(t=>!e.has(t));if(n.length)throw s(`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 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`)},O=3e4,k=(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(s(`unavailable`,typeof r.message==`string`&&r.message?r.message:`packages.mount: the package failed to boot`))},o=setTimeout(()=>i(s(`timeout`,`packages.mount: the package did not register a connection handler`)),O);window.addEventListener(`message`,a)}),A=async(e,t)=>{let{iframe:r}=t;if(!(r instanceof HTMLIFrameElement))throw s(`invalid`,`packages.mount: pass the iframe to load the package into`);if(!r.isConnected)throw s(`invalid`,`packages.mount: the iframe must be in the document before mounting into it`);D(r);let i=await(await c()).packages.frame(e);if(`error`in i)throw s(i.error,i.message);r.src=i.url;let a={done:!1},o=()=>{},l=new Promise(e=>{o=e}),d=n.t(`mounted package`),f=()=>{if(!a.done){a.done=!0,d();try{r.contentWindow?.postMessage({type:`fkn-packages-close`},i.origin)}catch{}r.src=`about:blank`,o()}};try{await k(r,i.origin)}catch(e){throw f(),e}let p=new MessageChannel,m=r.contentWindow;if(!m)throw f(),s(`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:l,port:p.port1,frame:r,unmount:f};try{return{remote:await u(t.payload,p.port1,{signal:t.signal,closed:l}),closed:l,port:p.port1,frame:r,unmount:f}}catch(e){throw f(),e}},j=(e,t,n)=>u(t,e,{signal:n?.signal}),M=null,N=!1,P=new Set,F=[],I=new Map,L=!1,R=!1,z=e=>{let t=I.get(e);t&&(I.delete(e),t())},B=(e,t)=>{try{e.postMessage({type:`fkn-packages-nack`,message:t})}catch{}try{e.close()}catch{}},V=async(e,t)=>{let{port:n,...r}=e;e.port.addEventListener(`message`,t=>{t.data?.type===`fkn-packages-disconnect`&&z(e.port)});let i;try{i=await t.createPayload(r)}catch(t){throw B(e.port,t instanceof Error?t.message:`the package failed to produce a connection`),t}let a=new Promise(t=>I.set(e.port,t)),o=await l(i,e.port);t.handler?.({...r,remote:o,closed:a,port:e.port})},H=()=>{L||typeof window>`u`||window.parent===window||(L=!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:``};M?V(r,M).catch(e=>console.warn(`packages.onConnect:`,e)):F.push(r)}if(t?.type===`fkn-packages-close`)for(let e of[...I.keys()])z(e);if(t?.type===`fkn-packages-visibility`){N=t.visible===!0;for(let e of P)try{e(N)}catch{}}}))},U=()=>{R||typeof window>`u`||window.parent===window||(R=!0,window.parent.postMessage({type:`fkn-packages-ready`},`*`))},W=(e,t)=>{if(typeof window>`u`)return{unsubscribe:()=>{}};H();let n={createPayload:e,handler:t};for(M=n,U();F.length&&M===n;)V(F.shift(),n).catch(e=>console.warn(`packages.onConnect:`,e));return{unsubscribe:()=>{M===n&&(M=null)}}},G=()=>N,K=e=>{if(typeof window>`u`)return{unsubscribe:()=>{}};H(),P.add(e);try{e(N)}catch{}return{unsubscribe:()=>{P.delete(e)}}};exports.attach=j,exports.connect=T,exports.hide=w,exports.install=p,exports.isVisible=G,exports.list=m,exports.mount=A,exports.onConnect=W,exports.onVisibilityChange=K,exports.pick=f,exports.search=d,exports.show=C,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}}),exports.uninstall=h;
|
package/packages.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as InstalledPackage, C as pick, E as uninstall, F as PickOptions, I as Placement, L as Radii, M as PackageResult, N as PackagesErrorCode, O as ConnectOptions, R as SurfaceRect, 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 PackageQuery, k as InstallOptions, 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 } from "./packages-Cn8S-Hkn.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
|
@@ -1,47 +1,48 @@
|
|
|
1
1
|
import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { a as t, o as n, r, s as i } from "./api-BqRjtWm_.js";
|
|
3
|
+
import { r as a, t as o } from "./busy-Bp1E3JPT.js";
|
|
4
|
+
import { expose as s } from "osra";
|
|
4
5
|
//#region src/lib/packages.ts
|
|
5
|
-
var
|
|
6
|
-
attach: () =>
|
|
7
|
-
connect: () =>
|
|
8
|
-
hide: () =>
|
|
9
|
-
install: () =>
|
|
10
|
-
isVisible: () =>
|
|
11
|
-
list: () =>
|
|
12
|
-
mount: () =>
|
|
13
|
-
onConnect: () =>
|
|
14
|
-
onVisibilityChange: () =>
|
|
15
|
-
pick: () =>
|
|
16
|
-
search: () =>
|
|
17
|
-
show: () =>
|
|
18
|
-
uninstall: () =>
|
|
19
|
-
}),
|
|
20
|
-
if (!
|
|
21
|
-
return
|
|
22
|
-
},
|
|
6
|
+
var c = /* @__PURE__ */ e({
|
|
7
|
+
attach: () => F,
|
|
8
|
+
connect: () => k,
|
|
9
|
+
hide: () => O,
|
|
10
|
+
install: () => _,
|
|
11
|
+
isVisible: () => Y,
|
|
12
|
+
list: () => v,
|
|
13
|
+
mount: () => P,
|
|
14
|
+
onConnect: () => J,
|
|
15
|
+
onVisibilityChange: () => X,
|
|
16
|
+
pick: () => g,
|
|
17
|
+
search: () => h,
|
|
18
|
+
show: () => D,
|
|
19
|
+
uninstall: () => y
|
|
20
|
+
}), l = "fkn-packages-connection", u = 3e4, d = (e, t) => Object.assign(Error(t), { code: e }), f = async () => {
|
|
21
|
+
if (!n) throw d("unavailable", "packages: no FKN transport in this realm - use relayWorker to bridge workers");
|
|
22
|
+
return r;
|
|
23
|
+
}, p = (e, t, n) => s(e ?? {}, {
|
|
23
24
|
transport: t,
|
|
24
|
-
key:
|
|
25
|
+
key: l,
|
|
25
26
|
unregisterSignal: n
|
|
26
|
-
}),
|
|
27
|
+
}), m = async (e, t, n = {}) => {
|
|
27
28
|
let { signal: r, closed: i } = n;
|
|
28
|
-
if (r?.aborted) throw
|
|
29
|
+
if (r?.aborted) throw d("unavailable", "packages.connect: aborted before connecting");
|
|
29
30
|
let a = new AbortController();
|
|
30
31
|
r && r.addEventListener("abort", () => a.abort(r.reason), { once: !0 });
|
|
31
|
-
let
|
|
32
|
-
let a = setTimeout(() => n(
|
|
33
|
-
|
|
32
|
+
let o = new AbortController(), s = new Promise((e, n) => {
|
|
33
|
+
let a = setTimeout(() => n(d("timeout", "packages.connect: the package did not complete the connection")), u);
|
|
34
|
+
o.signal.addEventListener("abort", () => clearTimeout(a), { once: !0 }), t.addEventListener("message", (e) => {
|
|
34
35
|
if (e.data?.type === "fkn-packages-nack") {
|
|
35
36
|
let t = e.data.message;
|
|
36
|
-
n(
|
|
37
|
+
n(d("unavailable", typeof t == "string" && t ? t : "packages.connect: the package refused the connection"));
|
|
37
38
|
}
|
|
38
|
-
}, { signal:
|
|
39
|
+
}, { signal: o.signal }), t.start(), r && r.addEventListener("abort", () => n(d("unavailable", "packages.connect: aborted before connecting")), {
|
|
39
40
|
once: !0,
|
|
40
|
-
signal:
|
|
41
|
-
}), i?.then(() => n(
|
|
41
|
+
signal: o.signal
|
|
42
|
+
}), i?.then(() => n(d("unavailable", "packages.connect: the package closed before connecting")));
|
|
42
43
|
});
|
|
43
44
|
try {
|
|
44
|
-
return await Promise.race([
|
|
45
|
+
return await Promise.race([p(e, t, a.signal), s]);
|
|
45
46
|
} catch (e) {
|
|
46
47
|
a.abort(e);
|
|
47
48
|
try {
|
|
@@ -49,29 +50,29 @@ var i = /* @__PURE__ */ e({
|
|
|
49
50
|
} catch {}
|
|
50
51
|
throw e;
|
|
51
52
|
} finally {
|
|
52
|
-
|
|
53
|
+
o.abort();
|
|
53
54
|
}
|
|
54
|
-
},
|
|
55
|
-
let t = await (await
|
|
56
|
-
if ("error" in t) throw
|
|
55
|
+
}, h = async (e) => {
|
|
56
|
+
let t = await (await f()).packages.search(e);
|
|
57
|
+
if ("error" in t) throw d(t.error, t.message);
|
|
57
58
|
return t.results;
|
|
58
|
-
},
|
|
59
|
-
let n = await (await
|
|
60
|
-
if ("error" in n) throw
|
|
59
|
+
}, g = async (e, t) => {
|
|
60
|
+
let n = await (await f()).packages.pick(e, t);
|
|
61
|
+
if ("error" in n) throw d(n.error, n.message);
|
|
61
62
|
return "declined" in n ? [] : n.results;
|
|
62
|
-
},
|
|
63
|
-
let n = await (await
|
|
64
|
-
if ("error" in n) throw
|
|
63
|
+
}, _ = async (e, t) => {
|
|
64
|
+
let n = await (await f()).packages.install(e, t);
|
|
65
|
+
if ("error" in n) throw d(n.error, n.message);
|
|
65
66
|
return "declined" in n ? null : n.installed;
|
|
66
|
-
},
|
|
67
|
-
let t = await (await
|
|
68
|
-
if ("error" in t) throw
|
|
69
|
-
},
|
|
67
|
+
}, v = async () => (await (await f()).packages.list()).results, y = async (e) => {
|
|
68
|
+
let t = await (await f()).packages.uninstall(e);
|
|
69
|
+
if ("error" in t) throw d(t.error, t.message);
|
|
70
|
+
}, b = ({ x: e, y: t, width: n, height: r }) => ({
|
|
70
71
|
x: Math.round(e),
|
|
71
72
|
y: Math.round(t),
|
|
72
73
|
width: Math.round(n),
|
|
73
74
|
height: Math.round(r)
|
|
74
|
-
}),
|
|
75
|
+
}), x = (e, t) => {
|
|
75
76
|
let n = Math.max(e.x, t.x), r = Math.max(e.y, t.y);
|
|
76
77
|
return {
|
|
77
78
|
x: n,
|
|
@@ -79,14 +80,14 @@ var i = /* @__PURE__ */ e({
|
|
|
79
80
|
width: Math.max(0, Math.min(e.x + e.width, t.x + t.width) - n),
|
|
80
81
|
height: Math.max(0, Math.min(e.y + e.height, t.y + t.height) - r)
|
|
81
82
|
};
|
|
82
|
-
},
|
|
83
|
+
}, S = (e, t) => {
|
|
83
84
|
let n = t;
|
|
84
85
|
for (let t = e.parentElement; t; t = t.parentElement) {
|
|
85
86
|
let e = getComputedStyle(t);
|
|
86
|
-
if (!(e.overflowX === "visible" && e.overflowY === "visible") && (n =
|
|
87
|
+
if (!(e.overflowX === "visible" && e.overflowY === "visible") && (n = x(n, b(t.getBoundingClientRect())), n.width === 0 || n.height === 0)) break;
|
|
87
88
|
}
|
|
88
89
|
return n;
|
|
89
|
-
},
|
|
90
|
+
}, C = (e) => {
|
|
90
91
|
let t = getComputedStyle(e), n = [
|
|
91
92
|
t.borderTopLeftRadius,
|
|
92
93
|
t.borderTopRightRadius,
|
|
@@ -99,109 +100,119 @@ var i = /* @__PURE__ */ e({
|
|
|
99
100
|
return Number.isFinite(t) && t > 0 ? t : 0;
|
|
100
101
|
});
|
|
101
102
|
return r.some((e) => e > 0) ? r : void 0;
|
|
102
|
-
},
|
|
103
|
+
}, w = (e, t) => {
|
|
103
104
|
if (!e) return !1;
|
|
104
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;
|
|
105
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);
|
|
106
|
-
},
|
|
107
|
-
|
|
107
|
+
}, T = /* @__PURE__ */ new Map();
|
|
108
|
+
a("package view", () => T.size > 0);
|
|
109
|
+
var E = async (e, t) => {
|
|
110
|
+
let n = T.get(e);
|
|
108
111
|
if (n) {
|
|
109
112
|
for (let e of n) t && e.element !== t || (e.stop(), n.delete(e));
|
|
110
113
|
if (n.size > 0) return;
|
|
111
|
-
|
|
114
|
+
T.delete(e);
|
|
112
115
|
}
|
|
113
|
-
let r = await (await
|
|
114
|
-
if ("error" in r) throw
|
|
115
|
-
},
|
|
116
|
+
let r = await (await f()).packages.hide(e);
|
|
117
|
+
if ("error" in r) throw d(r.error, r.message);
|
|
118
|
+
}, D = async (e, t) => {
|
|
116
119
|
let { element: n, rect: r } = t;
|
|
117
|
-
if (!n && !r) throw
|
|
118
|
-
let i = (await
|
|
119
|
-
if (!n) return { rect:
|
|
120
|
-
let e =
|
|
120
|
+
if (!n && !r) throw d("invalid", "packages.show: pass an element or a rect");
|
|
121
|
+
let i = (await f()).packages, a = () => {
|
|
122
|
+
if (!n) return { rect: b(r) };
|
|
123
|
+
let e = b(n.getBoundingClientRect());
|
|
121
124
|
return {
|
|
122
125
|
rect: e,
|
|
123
|
-
clip:
|
|
124
|
-
radius:
|
|
126
|
+
clip: S(n, e),
|
|
127
|
+
radius: C(n)
|
|
125
128
|
};
|
|
126
|
-
}, o = !0,
|
|
127
|
-
|
|
129
|
+
}, o = !0, s, c = 0, l = async (t) => {
|
|
130
|
+
s = t;
|
|
128
131
|
let n = await i.show(e, t);
|
|
129
|
-
if ("error" in n) throw o = !1,
|
|
132
|
+
if ("error" in n) throw o = !1, d(n.error, n.message);
|
|
130
133
|
};
|
|
131
|
-
await
|
|
132
|
-
let
|
|
134
|
+
await l(a());
|
|
135
|
+
let u = () => {
|
|
133
136
|
if (!o) return;
|
|
134
137
|
let e = a();
|
|
135
|
-
|
|
138
|
+
w(s, e) || l(e).catch(() => {}), c = requestAnimationFrame(u);
|
|
136
139
|
};
|
|
137
|
-
n && (
|
|
140
|
+
n && (c = requestAnimationFrame(u));
|
|
138
141
|
let p = {
|
|
139
142
|
element: n,
|
|
140
143
|
stop: () => {
|
|
141
|
-
o = !1, cancelAnimationFrame(
|
|
144
|
+
o = !1, cancelAnimationFrame(c);
|
|
142
145
|
}
|
|
143
|
-
}, m =
|
|
144
|
-
return m.add(p),
|
|
146
|
+
}, m = T.get(e) ?? /* @__PURE__ */ new Set();
|
|
147
|
+
return m.add(p), T.set(e, m), {
|
|
145
148
|
hide: () => {
|
|
146
|
-
|
|
149
|
+
E(e, n).catch(() => {});
|
|
147
150
|
},
|
|
148
151
|
refresh: () => {
|
|
149
152
|
if (!o) return;
|
|
150
153
|
let e = a();
|
|
151
|
-
|
|
154
|
+
w(s, e) || l(e).catch(() => {});
|
|
152
155
|
}
|
|
153
156
|
};
|
|
154
|
-
},
|
|
155
|
-
let
|
|
156
|
-
if ("error" in
|
|
157
|
-
let
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
}, O = async (e, t = {}) => E(e, t.element), k = (async (e, n = {}) => {
|
|
158
|
+
let r = await (await f()).packages.connect(e, { protocol: n.protocol });
|
|
159
|
+
if ("error" in r) throw d(r.error, r.message);
|
|
160
|
+
let a = o("package connection"), s = t()?.epoch ?? 0, c = i((e, t) => {
|
|
161
|
+
t !== s && (a(), c());
|
|
162
|
+
});
|
|
163
|
+
Promise.resolve(r.closed).then(() => {
|
|
164
|
+
a(), c();
|
|
165
|
+
}, () => {
|
|
166
|
+
a(), c();
|
|
167
|
+
});
|
|
168
|
+
let { port: l, closed: u } = r;
|
|
169
|
+
if (n.raw) return {
|
|
170
|
+
closed: u,
|
|
171
|
+
port: l
|
|
161
172
|
};
|
|
162
|
-
let
|
|
163
|
-
signal:
|
|
164
|
-
closed:
|
|
173
|
+
let p = await m(n.payload, l, {
|
|
174
|
+
signal: n.signal,
|
|
175
|
+
closed: u
|
|
165
176
|
});
|
|
166
|
-
return
|
|
177
|
+
return n.signal && n.signal.addEventListener("abort", () => {
|
|
167
178
|
try {
|
|
168
|
-
|
|
179
|
+
l.postMessage({ type: "fkn-packages-disconnect" });
|
|
169
180
|
} catch {}
|
|
170
181
|
}, { once: !0 }), {
|
|
171
|
-
remote:
|
|
172
|
-
closed:
|
|
173
|
-
port:
|
|
182
|
+
remote: p,
|
|
183
|
+
closed: u,
|
|
184
|
+
port: l
|
|
174
185
|
};
|
|
175
|
-
}),
|
|
186
|
+
}), A = ["allow-scripts", "allow-same-origin"], j = (e) => {
|
|
176
187
|
let t = e.getAttribute("sandbox");
|
|
177
188
|
if (t !== null) {
|
|
178
|
-
let e = new Set(t.toLowerCase().split(/\s+/).filter(Boolean)), n =
|
|
179
|
-
if (n.length) throw
|
|
189
|
+
let e = new Set(t.toLowerCase().split(/\s+/).filter(Boolean)), n = A.filter((t) => !e.has(t));
|
|
190
|
+
if (n.length) throw d("invalid", `packages.mount: the iframe's sandbox attribute must include ${n.join(" and ")}, or the package cannot start`);
|
|
180
191
|
}
|
|
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
|
|
182
|
-
},
|
|
192
|
+
if (globalThis.crossOriginIsolated && !new Set((e.getAttribute("allow") ?? "").toLowerCase().split(";").map((e) => e.trim().split(/\s+/)[0]).filter(Boolean)).has("cross-origin-isolated")) throw d("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");
|
|
193
|
+
}, M = 3e4, N = (e, t) => new Promise((n, r) => {
|
|
183
194
|
let i = (e) => {
|
|
184
195
|
clearTimeout(o), window.removeEventListener("message", a), e ? r(e) : n();
|
|
185
196
|
}, a = (n) => {
|
|
186
197
|
if (n.source !== e.contentWindow || n.origin !== t) return;
|
|
187
198
|
let r = n.data;
|
|
188
199
|
if (r?.type === "fkn-packages-ready") return i();
|
|
189
|
-
r?.type === "fkn-packages-failed" && i(
|
|
190
|
-
}, o = setTimeout(() => i(
|
|
200
|
+
r?.type === "fkn-packages-failed" && i(d("unavailable", typeof r.message == "string" && r.message ? r.message : "packages.mount: the package failed to boot"));
|
|
201
|
+
}, o = setTimeout(() => i(d("timeout", "packages.mount: the package did not register a connection handler")), M);
|
|
191
202
|
window.addEventListener("message", a);
|
|
192
|
-
}),
|
|
203
|
+
}), P = async (e, t) => {
|
|
193
204
|
let { iframe: n } = t;
|
|
194
|
-
if (!(n instanceof HTMLIFrameElement)) throw
|
|
195
|
-
if (!n.isConnected) throw
|
|
196
|
-
|
|
197
|
-
let r = await (await
|
|
198
|
-
if ("error" in r) throw
|
|
205
|
+
if (!(n instanceof HTMLIFrameElement)) throw d("invalid", "packages.mount: pass the iframe to load the package into");
|
|
206
|
+
if (!n.isConnected) throw d("invalid", "packages.mount: the iframe must be in the document before mounting into it");
|
|
207
|
+
j(n);
|
|
208
|
+
let r = await (await f()).packages.frame(e);
|
|
209
|
+
if ("error" in r) throw d(r.error, r.message);
|
|
199
210
|
n.src = r.url;
|
|
200
|
-
let i = { done: !1 }, a = () => {},
|
|
211
|
+
let i = { done: !1 }, a = () => {}, s = new Promise((e) => {
|
|
201
212
|
a = e;
|
|
202
|
-
}), l = () => {
|
|
213
|
+
}), c = o("mounted package"), l = () => {
|
|
203
214
|
if (!i.done) {
|
|
204
|
-
i.done = !0;
|
|
215
|
+
i.done = !0, c();
|
|
205
216
|
try {
|
|
206
217
|
n.contentWindow?.postMessage({ type: "fkn-packages-close" }, r.origin);
|
|
207
218
|
} catch {}
|
|
@@ -209,45 +220,50 @@ var i = /* @__PURE__ */ e({
|
|
|
209
220
|
}
|
|
210
221
|
};
|
|
211
222
|
try {
|
|
212
|
-
await
|
|
223
|
+
await N(n, r.origin);
|
|
213
224
|
} catch (e) {
|
|
214
225
|
throw l(), e;
|
|
215
226
|
}
|
|
216
|
-
let
|
|
217
|
-
if (!
|
|
218
|
-
|
|
227
|
+
let u = new MessageChannel(), p = n.contentWindow;
|
|
228
|
+
if (!p) throw l(), d("unavailable", "packages.mount: the frame was detached before it could connect");
|
|
229
|
+
p.postMessage({
|
|
219
230
|
type: "fkn-packages-port",
|
|
220
231
|
from: r.from,
|
|
221
232
|
protocol: t.protocol,
|
|
222
233
|
uri: r.uri,
|
|
223
234
|
name: r.name,
|
|
224
235
|
version: r.version
|
|
225
|
-
}, r.origin, [
|
|
236
|
+
}, r.origin, [u.port2]);
|
|
226
237
|
try {
|
|
227
|
-
|
|
238
|
+
p.postMessage({
|
|
228
239
|
type: "fkn-packages-visibility",
|
|
229
240
|
visible: !0
|
|
230
241
|
}, r.origin);
|
|
231
242
|
} catch {}
|
|
232
|
-
|
|
233
|
-
closed:
|
|
234
|
-
port:
|
|
235
|
-
frame: n,
|
|
236
|
-
unmount: l
|
|
237
|
-
} : {
|
|
238
|
-
remote: await u(t.payload, d.port1, {
|
|
239
|
-
signal: t.signal,
|
|
240
|
-
closed: o
|
|
241
|
-
}),
|
|
242
|
-
closed: o,
|
|
243
|
-
port: d.port1,
|
|
243
|
+
if (t.raw) return {
|
|
244
|
+
closed: s,
|
|
245
|
+
port: u.port1,
|
|
244
246
|
frame: n,
|
|
245
247
|
unmount: l
|
|
246
248
|
};
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
try {
|
|
250
|
+
return {
|
|
251
|
+
remote: await m(t.payload, u.port1, {
|
|
252
|
+
signal: t.signal,
|
|
253
|
+
closed: s
|
|
254
|
+
}),
|
|
255
|
+
closed: s,
|
|
256
|
+
port: u.port1,
|
|
257
|
+
frame: n,
|
|
258
|
+
unmount: l
|
|
259
|
+
};
|
|
260
|
+
} catch (e) {
|
|
261
|
+
throw l(), e;
|
|
262
|
+
}
|
|
263
|
+
}, F = (e, t, n) => m(t, e, { signal: n?.signal }), I = null, L = !1, R = /* @__PURE__ */ new Set(), z = [], B = /* @__PURE__ */ new Map(), V = !1, H = !1, U = (e) => {
|
|
264
|
+
let t = B.get(e);
|
|
265
|
+
t && (B.delete(e), t());
|
|
266
|
+
}, W = (e, t) => {
|
|
251
267
|
try {
|
|
252
268
|
e.postMessage({
|
|
253
269
|
type: "fkn-packages-nack",
|
|
@@ -257,26 +273,26 @@ var i = /* @__PURE__ */ e({
|
|
|
257
273
|
try {
|
|
258
274
|
e.close();
|
|
259
275
|
} catch {}
|
|
260
|
-
},
|
|
276
|
+
}, G = async (e, t) => {
|
|
261
277
|
let { port: n, ...r } = e;
|
|
262
278
|
e.port.addEventListener("message", (t) => {
|
|
263
|
-
t.data?.type === "fkn-packages-disconnect" &&
|
|
279
|
+
t.data?.type === "fkn-packages-disconnect" && U(e.port);
|
|
264
280
|
});
|
|
265
281
|
let i;
|
|
266
282
|
try {
|
|
267
283
|
i = await t.createPayload(r);
|
|
268
284
|
} catch (t) {
|
|
269
|
-
throw
|
|
285
|
+
throw W(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
|
|
270
286
|
}
|
|
271
|
-
let a = new Promise((t) =>
|
|
287
|
+
let a = new Promise((t) => B.set(e.port, t)), o = await p(i, e.port);
|
|
272
288
|
t.handler?.({
|
|
273
289
|
...r,
|
|
274
290
|
remote: o,
|
|
275
291
|
closed: a,
|
|
276
292
|
port: e.port
|
|
277
293
|
});
|
|
278
|
-
},
|
|
279
|
-
|
|
294
|
+
}, K = () => {
|
|
295
|
+
V || typeof window > "u" || window.parent === window || (V = !0, window.addEventListener("message", (e) => {
|
|
280
296
|
if (e.source !== window.parent) return;
|
|
281
297
|
let t = e.data;
|
|
282
298
|
if (t?.type === "fkn-packages-port") {
|
|
@@ -290,38 +306,38 @@ var i = /* @__PURE__ */ e({
|
|
|
290
306
|
name: typeof t.name == "string" ? t.name : "",
|
|
291
307
|
version: typeof t.version == "string" ? t.version : ""
|
|
292
308
|
};
|
|
293
|
-
|
|
309
|
+
I ? G(r, I).catch((e) => console.warn("packages.onConnect:", e)) : z.push(r);
|
|
294
310
|
}
|
|
295
|
-
if (t?.type === "fkn-packages-close") for (let e of [...
|
|
311
|
+
if (t?.type === "fkn-packages-close") for (let e of [...B.keys()]) U(e);
|
|
296
312
|
if (t?.type === "fkn-packages-visibility") {
|
|
297
|
-
|
|
298
|
-
for (let e of
|
|
299
|
-
e(
|
|
313
|
+
L = t.visible === !0;
|
|
314
|
+
for (let e of R) try {
|
|
315
|
+
e(L);
|
|
300
316
|
} catch {}
|
|
301
317
|
}
|
|
302
318
|
}));
|
|
303
|
-
},
|
|
304
|
-
|
|
305
|
-
},
|
|
319
|
+
}, q = () => {
|
|
320
|
+
H || typeof window > "u" || window.parent === window || (H = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, "*"));
|
|
321
|
+
}, J = (e, t) => {
|
|
306
322
|
if (typeof window > "u") return { unsubscribe: () => {} };
|
|
307
|
-
|
|
323
|
+
K();
|
|
308
324
|
let n = {
|
|
309
325
|
createPayload: e,
|
|
310
326
|
handler: t
|
|
311
327
|
};
|
|
312
|
-
for (
|
|
328
|
+
for (I = n, q(); z.length && I === n;) G(z.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
|
|
313
329
|
return { unsubscribe: () => {
|
|
314
|
-
|
|
330
|
+
I === n && (I = null);
|
|
315
331
|
} };
|
|
316
|
-
},
|
|
332
|
+
}, Y = () => L, X = (e) => {
|
|
317
333
|
if (typeof window > "u") return { unsubscribe: () => {} };
|
|
318
|
-
|
|
334
|
+
K(), R.add(e);
|
|
319
335
|
try {
|
|
320
|
-
e(
|
|
336
|
+
e(L);
|
|
321
337
|
} catch {}
|
|
322
338
|
return { unsubscribe: () => {
|
|
323
|
-
|
|
339
|
+
R.delete(e);
|
|
324
340
|
} };
|
|
325
341
|
};
|
|
326
342
|
//#endregion
|
|
327
|
-
export {
|
|
343
|
+
export { F as attach, k as connect, O as hide, _ as install, Y as isVisible, v as list, P as mount, J as onConnect, X as onVisibilityChange, g as pick, h as search, D as show, c as t, y as uninstall };
|