@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.
Files changed (86) hide show
  1. package/account.cjs +1 -1
  2. package/account.js +24 -17
  3. package/{api-DnO1DsJC.d.ts → api-B0qRPCcX.d.ts} +36 -37
  4. package/api-BqRjtWm_.js +311 -0
  5. package/api-CKO3Hw-O.cjs +3 -0
  6. package/busy-Bp1E3JPT.js +24 -0
  7. package/busy-Dv8wzE5M.cjs +1 -0
  8. package/cloud/dgram.cjs +1 -1
  9. package/cloud/dgram.js +1 -1
  10. package/cloud/fetch.cjs +1 -1
  11. package/cloud/fetch.d.ts +1 -1
  12. package/cloud/fetch.js +1 -1
  13. package/cloud/fs.cjs +1 -1
  14. package/cloud/fs.js +2 -2
  15. package/cloud/net.cjs +1 -1
  16. package/cloud/net.d.ts +1 -1
  17. package/cloud/net.js +1 -1
  18. package/cloud-BCQTex58.cjs +1 -0
  19. package/{cloud-uE4g-WqI.d.ts → cloud-BTpJn4jy.d.ts} +3 -3
  20. package/cloud-BlR1He17.js +212 -0
  21. package/cloud.cjs +1 -1
  22. package/cloud.d.ts +3 -3
  23. package/cloud.js +4 -4
  24. package/dgram-9hn582qO.cjs +1 -0
  25. package/{dgram-DlGl_ho1.js → dgram-TB03kqMr.js} +55 -49
  26. package/dgram.cjs +1 -1
  27. package/dgram.d.ts +2 -1
  28. package/dgram.js +1 -1
  29. package/dns.cjs +1 -1
  30. package/dns.js +1 -1
  31. package/extension-BI2NxGtC.js +78 -0
  32. package/{extension-CN9oFZ0Q.d.ts → extension-CMPZjuaV.d.ts} +1 -1
  33. package/extension-rFQQpEqJ.cjs +1 -0
  34. package/extension.cjs +1 -1
  35. package/extension.d.ts +2 -2
  36. package/extension.js +3 -3
  37. package/fs/promises.cjs +1 -1
  38. package/fs/promises.js +1 -1
  39. package/fs-BUcpl9k4.cjs +1 -0
  40. package/fs-bpb3Ysdd.js +347 -0
  41. package/fs.cjs +1 -1
  42. package/fs.js +1 -1
  43. package/http.cjs +1 -1
  44. package/http.d.ts +1 -1
  45. package/http.js +1 -1
  46. package/{index-DLaonjpx.d.ts → index-DY8WjklJ.d.ts} +82 -0
  47. package/index.cjs +1 -1
  48. package/index.d.ts +12 -18
  49. package/index.js +92 -39
  50. package/lib-DbiVHPXE.cjs +53 -0
  51. package/{lib-CegQxwDI.js → lib-k3lstfa4.js} +178 -131
  52. package/net-C2fIMWFr.cjs +1 -0
  53. package/{net-l7JVHsIR.d.ts → net-CnYxw_sB.d.ts} +3 -1
  54. package/{net-BbmQeMpt.js → net-Ct8ywVAk.js} +52 -41
  55. package/net.cjs +1 -1
  56. package/net.d.ts +1 -1
  57. package/net.js +1 -1
  58. package/node-fs-BZCQUmeE.js +404 -0
  59. package/node-fs-DZPGCYWg.cjs +1 -0
  60. package/opfs.cjs +1 -1
  61. package/opfs.js +1 -1
  62. package/package.json +1 -1
  63. package/{packages-vX-1yfRK.d.ts → packages-Cn8S-Hkn.d.ts} +20 -20
  64. package/packages.cjs +1 -1
  65. package/packages.d.ts +1 -1
  66. package/packages.js +165 -149
  67. package/proxy--aljNHvG.js +69 -0
  68. package/{proxy-7ib45Uo-.d.ts → proxy-CuXtzxSQ.d.ts} +1 -1
  69. package/proxy-oHfEx1cn.cjs +1 -0
  70. package/{storage-C8hBot2f.js → storage-C1nW5Tvh.js} +1 -1
  71. package/{storage-BW-jDLUL.cjs → storage-rXHvV2FU.cjs} +1 -1
  72. package/api-DQ-V4Lls.js +0 -220
  73. package/api-kHMHDGar.cjs +0 -3
  74. package/cloud-BQoppUw4.cjs +0 -1
  75. package/cloud-C8CeqUht.js +0 -130
  76. package/dgram-D2Or5f2e.cjs +0 -1
  77. package/extension-4BM5hKrn.cjs +0 -1
  78. package/extension-DVO10P3i.js +0 -78
  79. package/fs-BW5mVMmu.js +0 -340
  80. package/fs-DJm0bhjg.cjs +0 -1
  81. package/lib-ulyxIbTr.cjs +0 -53
  82. package/net-COzDDBnS.cjs +0 -1
  83. package/node-fs-BMR2yCEt.cjs +0 -1
  84. package/node-fs-DKfokOlh.js +0 -401
  85. package/proxy-B0gNjT8-.cjs +0 -1
  86. package/proxy-BpqvCJmA.js +0 -43
package/opfs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
2
- import { t } from "./node-fs-DKfokOlh.js";
2
+ import { t } from "./node-fs-BZCQUmeE.js";
3
3
  import { r as n } from "./opfs-BibrNGF0.js";
4
4
  //#region src/lib/opfs/index.ts
5
5
  var r = /* @__PURE__ */ e({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fkn/lib",
3
- "version": "0.9.19",
3
+ "version": "0.9.21",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",
@@ -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 { InstallOptions as A, pick as C, MountDescriptor as D, uninstall as E, PackagesFail as F, PickOptions as I, Placement as L, PackageQuery as M, PackageResult as N, Caller as O, PackagesErrorCode as P, Radii as R, packages_d_exports as S, show as T, isVisible as _, IncomingConnectionInfo as a, onConnect as b, PackageConnection as c, RawPackageConnection as d, ShowOptions as f, install as g, hide as h, IncomingConnection as i, InstalledPackage as j, ConnectOptions as k, PackageView as l, connect as m, Connect as n, MountOptions as o, attach as p, ConnectPayload as r, MountedPackage as s, AppConnectOptions as t, PackagesError as u, list as v, search as w, onVisibilityChange as x, mount as y, SurfaceRect as z };
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-kHMHDGar.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;
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 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";
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 { r as t, t as n } from "./api-DQ-V4Lls.js";
3
- import { expose as r } from "osra";
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 i = /* @__PURE__ */ e({
6
- attach: () => j,
7
- connect: () => T,
8
- hide: () => w,
9
- install: () => p,
10
- isVisible: () => G,
11
- list: () => m,
12
- mount: () => A,
13
- onConnect: () => W,
14
- onVisibilityChange: () => K,
15
- pick: () => f,
16
- search: () => d,
17
- show: () => C,
18
- uninstall: () => h
19
- }), a = "fkn-packages-connection", o = 3e4, s = (e, t) => Object.assign(Error(t), { code: e }), c = async () => {
20
- if (!t) throw s("unavailable", "packages: no FKN transport in this realm - use relayWorker to bridge workers");
21
- return n;
22
- }, l = (e, t, n) => r(e ?? {}, {
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: a,
25
+ key: l,
25
26
  unregisterSignal: n
26
- }), u = async (e, t, n = {}) => {
27
+ }), m = async (e, t, n = {}) => {
27
28
  let { signal: r, closed: i } = n;
28
- if (r?.aborted) throw s("unavailable", "packages.connect: aborted before connecting");
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 c = new AbortController(), u = new Promise((e, n) => {
32
- let a = setTimeout(() => n(s("timeout", "packages.connect: the package did not complete the connection")), o);
33
- c.signal.addEventListener("abort", () => clearTimeout(a), { once: !0 }), t.addEventListener("message", (e) => {
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(s("unavailable", typeof t == "string" && t ? t : "packages.connect: the package refused the connection"));
37
+ n(d("unavailable", typeof t == "string" && t ? t : "packages.connect: the package refused the connection"));
37
38
  }
38
- }, { signal: c.signal }), t.start(), r && r.addEventListener("abort", () => n(s("unavailable", "packages.connect: aborted before connecting")), {
39
+ }, { signal: o.signal }), t.start(), r && r.addEventListener("abort", () => n(d("unavailable", "packages.connect: aborted before connecting")), {
39
40
  once: !0,
40
- signal: c.signal
41
- }), i?.then(() => n(s("unavailable", "packages.connect: the package closed before connecting")));
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([l(e, t, a.signal), u]);
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
- c.abort();
53
+ o.abort();
53
54
  }
54
- }, d = async (e) => {
55
- let t = await (await c()).packages.search(e);
56
- if ("error" in t) throw s(t.error, t.message);
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
- }, f = async (e, t) => {
59
- let n = await (await c()).packages.pick(e, t);
60
- if ("error" in n) throw s(n.error, n.message);
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
- }, p = async (e, t) => {
63
- let n = await (await c()).packages.install(e, t);
64
- if ("error" in n) throw s(n.error, n.message);
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
- }, m = async () => (await (await c()).packages.list()).results, h = async (e) => {
67
- let t = await (await c()).packages.uninstall(e);
68
- if ("error" in t) throw s(t.error, t.message);
69
- }, g = ({ x: e, y: t, width: n, height: r }) => ({
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
- }), _ = (e, t) => {
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
- }, v = (e, t) => {
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 = _(n, g(t.getBoundingClientRect())), n.width === 0 || n.height === 0)) break;
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
- }, y = (e) => {
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
- }, b = (e, t) => {
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
- }, x = /* @__PURE__ */ new Map(), S = async (e, t) => {
107
- let n = x.get(e);
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
- x.delete(e);
114
+ T.delete(e);
112
115
  }
113
- let r = await (await c()).packages.hide(e);
114
- if ("error" in r) throw s(r.error, r.message);
115
- }, C = async (e, t) => {
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 s("invalid", "packages.show: pass an element or a rect");
118
- let i = (await c()).packages, a = () => {
119
- if (!n) return { rect: g(r) };
120
- let e = g(n.getBoundingClientRect());
120
+ 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: v(n, e),
124
- radius: y(n)
126
+ clip: S(n, e),
127
+ radius: C(n)
125
128
  };
126
- }, o = !0, l, u = 0, d = async (t) => {
127
- l = t;
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, s(n.error, n.message);
132
+ if ("error" in n) throw o = !1, d(n.error, n.message);
130
133
  };
131
- await d(a());
132
- let f = () => {
134
+ await l(a());
135
+ let u = () => {
133
136
  if (!o) return;
134
137
  let e = a();
135
- b(l, e) || d(e).catch(() => {}), u = requestAnimationFrame(f);
138
+ w(s, e) || l(e).catch(() => {}), c = requestAnimationFrame(u);
136
139
  };
137
- n && (u = requestAnimationFrame(f));
140
+ n && (c = requestAnimationFrame(u));
138
141
  let p = {
139
142
  element: n,
140
143
  stop: () => {
141
- o = !1, cancelAnimationFrame(u);
144
+ o = !1, cancelAnimationFrame(c);
142
145
  }
143
- }, m = x.get(e) ?? /* @__PURE__ */ new Set();
144
- return m.add(p), x.set(e, m), {
146
+ }, m = T.get(e) ?? /* @__PURE__ */ new Set();
147
+ return m.add(p), T.set(e, m), {
145
148
  hide: () => {
146
- S(e, n).catch(() => {});
149
+ E(e, n).catch(() => {});
147
150
  },
148
151
  refresh: () => {
149
152
  if (!o) return;
150
153
  let e = a();
151
- b(l, e) || d(e).catch(() => {});
154
+ w(s, e) || l(e).catch(() => {});
152
155
  }
153
156
  };
154
- }, w = async (e, t = {}) => S(e, t.element), T = (async (e, t = {}) => {
155
- let n = await (await c()).packages.connect(e, { protocol: t.protocol });
156
- if ("error" in n) throw s(n.error, n.message);
157
- let { port: r, closed: i } = n;
158
- if (t.raw) return {
159
- closed: i,
160
- port: r
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 a = await u(t.payload, r, {
163
- signal: t.signal,
164
- closed: i
173
+ let p = await m(n.payload, l, {
174
+ signal: n.signal,
175
+ closed: u
165
176
  });
166
- return t.signal && t.signal.addEventListener("abort", () => {
177
+ return n.signal && n.signal.addEventListener("abort", () => {
167
178
  try {
168
- r.postMessage({ type: "fkn-packages-disconnect" });
179
+ l.postMessage({ type: "fkn-packages-disconnect" });
169
180
  } catch {}
170
181
  }, { once: !0 }), {
171
- remote: a,
172
- closed: i,
173
- port: r
182
+ remote: p,
183
+ closed: u,
184
+ port: l
174
185
  };
175
- }), E = ["allow-scripts", "allow-same-origin"], D = (e) => {
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 = 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`);
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 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) => {
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(s("unavailable", typeof r.message == "string" && r.message ? r.message : "packages.mount: the package failed to boot"));
190
- }, o = setTimeout(() => i(s("timeout", "packages.mount: the package did not register a connection handler")), O);
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
- }), A = async (e, t) => {
203
+ }), P = async (e, t) => {
193
204
  let { iframe: n } = t;
194
- if (!(n instanceof HTMLIFrameElement)) throw s("invalid", "packages.mount: pass the iframe to load the package into");
195
- if (!n.isConnected) throw s("invalid", "packages.mount: the iframe must be in the document before mounting into it");
196
- D(n);
197
- let r = await (await c()).packages.frame(e);
198
- if ("error" in r) throw s(r.error, r.message);
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 = () => {}, o = new Promise((e) => {
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 k(n, r.origin);
223
+ await N(n, r.origin);
213
224
  } catch (e) {
214
225
  throw l(), e;
215
226
  }
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({
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, [d.port2]);
236
+ }, r.origin, [u.port2]);
226
237
  try {
227
- f.postMessage({
238
+ p.postMessage({
228
239
  type: "fkn-packages-visibility",
229
240
  visible: !0
230
241
  }, r.origin);
231
242
  } catch {}
232
- return t.raw ? {
233
- closed: o,
234
- port: d.port1,
235
- frame: n,
236
- unmount: l
237
- } : {
238
- remote: await u(t.payload, d.port1, {
239
- signal: t.signal,
240
- closed: o
241
- }),
242
- closed: o,
243
- port: d.port1,
243
+ if (t.raw) return {
244
+ closed: s,
245
+ port: u.port1,
244
246
  frame: n,
245
247
  unmount: l
246
248
  };
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) => {
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
- }, V = async (e, t) => {
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" && z(e.port);
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 B(e.port, t instanceof Error ? t.message : "the package failed to produce a connection"), t;
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) => I.set(e.port, t)), o = await l(i, e.port);
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
- }, H = () => {
279
- L || typeof window > "u" || window.parent === window || (L = !0, window.addEventListener("message", (e) => {
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
- M ? V(r, M).catch((e) => console.warn("packages.onConnect:", e)) : F.push(r);
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 [...I.keys()]) z(e);
311
+ if (t?.type === "fkn-packages-close") for (let e of [...B.keys()]) U(e);
296
312
  if (t?.type === "fkn-packages-visibility") {
297
- N = t.visible === !0;
298
- for (let e of P) try {
299
- e(N);
313
+ L = t.visible === !0;
314
+ for (let e of R) try {
315
+ e(L);
300
316
  } catch {}
301
317
  }
302
318
  }));
303
- }, U = () => {
304
- R || typeof window > "u" || window.parent === window || (R = !0, window.parent.postMessage({ type: "fkn-packages-ready" }, "*"));
305
- }, W = (e, t) => {
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
- H();
323
+ K();
308
324
  let n = {
309
325
  createPayload: e,
310
326
  handler: t
311
327
  };
312
- for (M = n, U(); F.length && M === n;) V(F.shift(), n).catch((e) => console.warn("packages.onConnect:", e));
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
- M === n && (M = null);
330
+ I === n && (I = null);
315
331
  } };
316
- }, G = () => N, K = (e) => {
332
+ }, Y = () => L, X = (e) => {
317
333
  if (typeof window > "u") return { unsubscribe: () => {} };
318
- H(), P.add(e);
334
+ K(), R.add(e);
319
335
  try {
320
- e(N);
336
+ e(L);
321
337
  } catch {}
322
338
  return { unsubscribe: () => {
323
- P.delete(e);
339
+ R.delete(e);
324
340
  } };
325
341
  };
326
342
  //#endregion
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 };
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 };