buckyos 0.7.205 → 0.7.206
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/cli/dist/cli.mjs +1 -1
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/version.ts +1 -1
- package/dist/app-frame.cjs +1 -1
- package/dist/app-frame.cjs.map +1 -1
- package/dist/app-frame.d.ts +218 -2
- package/dist/app-frame.d.ts.map +1 -1
- package/dist/app-frame.mjs +517 -12
- package/dist/app-frame.mjs.map +1 -1
- package/dist/content.cjs +1 -1
- package/dist/content.cjs.map +1 -1
- package/dist/content.d.ts +2 -0
- package/dist/content.d.ts.map +1 -1
- package/dist/content.mjs +14 -7
- package/dist/content.mjs.map +1 -1
- package/dist/internal/html_tokens.d.ts +13 -0
- package/dist/internal/html_tokens.d.ts.map +1 -0
- package/dist/transfer.cjs +2 -0
- package/dist/transfer.cjs.map +1 -0
- package/dist/transfer.d.ts +148 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/transfer.mjs +655 -0
- package/dist/transfer.mjs.map +1 -0
- package/package.json +6 -1
package/cli/version.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated by scripts/generate-cli-version.mjs. Do not edit.
|
|
2
|
-
export const PACKAGE_VERSION = '0.7.
|
|
2
|
+
export const PACKAGE_VERSION = '0.7.206'
|
|
3
3
|
export const TOOL_VERSION = PACKAGE_VERSION
|
|
4
4
|
export const SDK_VERSION = PACKAGE_VERSION
|
|
5
5
|
export const PROTOCOL_VERSION = '1'
|
package/dist/app-frame.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./content.cjs"),t=require("./open-app.cjs"),i=require("./runtime_env-6396e1eb.js");require("./object_url-88047ee2.js"),require("./ndn_types-5b138882.js");const n=t=>e.SYSTEM_DIALOG_ERROR_CODES.includes(t)?t:"protocol",s=(e,t)=>"string"==typeof e?e.slice(0,t):void 0;function o(e,t){return Array.isArray(e)?e.slice(0,32).flatMap((e=>{const i=e;return!i||"object"!=typeof i||"string"!=typeof i.id||!i.id||i.id.length>128||"string"!=typeof i.label?[]:[t(i,{id:i.id,label:i.label.slice(0,128)})]})):[]}function r(e){const t={},i=s(e.title,256);if(void 0!==i&&(t.title=i),Array.isArray(e.second_row)&&(t.second_row=o(e.second_row,((e,t)=>({...t,...!0===e.active?{active:!0}:{}})))),Array.isArray(e.menu)&&(t.menu=o(e.menu,((e,t)=>({...t,..."string"==typeof e.icon?{icon:e.icon.slice(0,2048)}:{},...!0===e.danger?{danger:!0}:{}})))),null===e.search)t.search=null;else if(e.search&&"object"==typeof e.search){const i=e.search,n=s(i.placeholder,128),o=s(i.value,1024);t.search={...void 0!==n?{placeholder:n}:{},...void 0!==o?{value:o}:{}}}return"boolean"==typeof e.back&&(t.back=e.back),t}function a(e,t){return{post:i=>{var n;return null==(n=e())?void 0:n.postMessage(i,t)},onMessage:i=>{const n=window,s=n=>{n.source===e()&&n.origin===t&&i(n.data)};return n.addEventListener("message",s),()=>n.removeEventListener("message",s)}}}const l=(e,t,i={})=>({protocol:"buckyos.app-frame",version:1,type:e,payload:t,...i}),d=e=>{if(!e||"object"!=typeof e)return!1;const t=e;return"buckyos.app-frame"===t.protocol&&1===t.version&&"string"==typeof t.type&&!!t.payload&&"object"==typeof t.payload},c="buckyos.app-frame:";const p="buckyos.preview-embed",h=(e,t,i=p)=>({protocol:i,version:1,type:e,payload:t}),u=(e,t=p)=>{const i=e;return!!i&&i.protocol===t&&1===i.version&&"string"==typeof i.type&&!!i.payload&&"object"==typeof i.payload},m="/embed/preview";const y="buckyos.sysdlg-embed",g="/embed/sysdlg/select";let f=!1;function w(t,i,s={}){var o,r;if(null==(o=s.signal)?void 0:o.aborted)return Promise.reject(new e.SystemDialogError("closed"));if(f)return Promise.reject(new e.SystemDialogError("busy"));f=!0;const a=new URL(t).origin,l=s.locale??navigator.language??"en",d=s.theme??((null==(r=window.matchMedia)?void 0:r.call(window,"(prefers-color-scheme: dark)").matches)?"dark":"light"),c=l.toLowerCase().startsWith("zh");return new Promise(((t,o)=>{var r;const p=document.body,m=document.documentElement,w=document.activeElement instanceof HTMLElement?document.activeElement:null,b={x:window.scrollX,y:window.scrollY},v={body:p.getAttribute("style"),html:m.getAttribute("style")},E=Array.from(p.children).filter((e=>e instanceof HTMLElement)).map((e=>({el:e,inert:e.inert,hidden:e.getAttribute("aria-hidden")}))),k=document.createElement("div");let O;k.setAttribute("data-buckyos-sysdlg","select"),k.setAttribute("role","dialog"),k.setAttribute("aria-modal","true"),k.setAttribute("aria-label",c?"文件选择器":"File picker"),k.style.cssText="position:fixed;inset:0;height:100vh;height:100dvh;z-index:2147483647;background:rgba(0,0,0,.32);display:flex;align-items:center;justify-content:center";let T,x="",A=!1;const L=e=>{k.contains(e.target)||(e.stopPropagation(),e.preventDefault())},C=["keydown","pointerdown","mousedown","touchstart","wheel"],R=()=>{var e;return!A&&(A=!0,f=!1,clearTimeout(T),window.removeEventListener("message",P),null==(e=s.signal)||e.removeEventListener("abort",S),"inert"in HTMLElement.prototype||C.forEach((e=>document.removeEventListener(e,L,!0))),k.remove(),E.forEach((({el:e,inert:t,hidden:i})=>{e.inert=t,null===i?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",i)})),null===v.body?p.removeAttribute("style"):p.setAttribute("style",v.body),null===v.html?m.removeAttribute("style"):m.setAttribute("style",v.html),window.scrollTo(b.x,b.y),null==w||w.focus({preventScroll:!0}),!0)},I=t=>{R()&&o(new e.SystemDialogError(t))},S=()=>I("closed"),D=()=>{null==O||O.remove(),O=void 0;const e=document.createElement("div");e.setAttribute("role","alert"),e.style.cssText=`max-width:22rem;margin:1rem;padding:1.25rem;border-radius:16px;font:14px/1.6 system-ui,sans-serif;background:${"dark"===d?"#1f2329":"#fff"};color:${"dark"===d?"#f2f3f5":"#1f2329"};box-shadow:0 24px 64px rgba(0,0,0,.24)`;const t=document.createElement("p");t.style.margin="0 0 1rem",t.textContent=c?"无法加载文件选择器":"Unable to load the file picker";const i=document.createElement("div");i.style.cssText="display:flex;gap:.5rem;justify-content:flex-end";const n=(e,t)=>{const n=document.createElement("button");return n.type="button",n.textContent=e,n.style.cssText="min-height:2.25rem;padding:0 1rem;font:inherit;border-radius:999px;border:1px solid currentColor;background:transparent;color:inherit;cursor:pointer",n.addEventListener("click",t),i.append(n),n};n(c?"取消":"Cancel",(()=>I("load_failed")));const s=n(c?"重试":"Retry",(()=>{e.remove(),U()}));e.append(t,i),k.append(e),s.focus()},U=()=>{x=crypto.randomUUID(),O=document.createElement("iframe"),O.title=c?"文件选择器":"File picker",O.style.cssText="position:absolute;inset:0;width:100%;height:100%;border:0;background:transparent;color-scheme:normal",O.setAttribute("allowtransparency","true"),O.addEventListener("error",D),O.src=`${a}${g}#bse=${x}&po=${encodeURIComponent(window.location.origin)}`,k.append(O),T=setTimeout(D,1e4)},P=s=>{var o;if(!O||s.origin!==a||s.source!==O.contentWindow||!u(s.data,y))return;const{type:r,payload:c}=s.data;if("embed.hello"===r){if(c.nonce!==x)return;clearTimeout(T),null==(o=O.contentWindow)||o.postMessage(h("embed.init",{nonce:x,params:i,theme:d,locale:l},y),a),O.focus()}if("embed.error"===r&&I(n(c.code)),"embed.result"===r){const n=e.readSelectDialogResult(c.result,{allowLocal:!0===i.allowLocal});n?(e=>{R()&&t(e)})(n):I("protocol")}};window.addEventListener("message",P),null==(r=s.signal)||r.addEventListener("abort",S,{once:!0}),"inert"in HTMLElement.prototype?E.forEach((({el:e})=>{e.inert=!0})):(E.forEach((({el:e})=>e.setAttribute("aria-hidden","true"))),C.forEach((e=>document.addEventListener(e,L,!0)))),m.style.overflow="hidden",p.style.position="fixed",p.style.top=-b.y+"px",p.style.left=-b.x+"px",p.style.right="0",p.style.overflow="hidden",p.append(k),U()}))}const b="buckyos.conversation-embed",v="/embed/conversation",E=["invalid_params","not_found","denied"],k=["idle","running","interrupted","paused","answer"];exports.AppFrameClient=class{constructor(e){this.options=e,this.header={},this.dialogs=new Map,this.appOpens=new Map;const t=new URL(e.shellOrigin).origin,n=window.parent===window?i.getBuckyApi():void 0;this.native=!!n;const s=window.parent!==window?window.name:"";var o;if(this.nonce=(null==s?void 0:s.startsWith(c))?s.slice(18):new URLSearchParams(window.location.hash.slice(1)).get("bfp")??(n?crypto.randomUUID():null),this.channel=n?(o=n,{post:e=>{Promise.resolve(o.call("frame.post",e)).catch((()=>{}))},onMessage:e=>o.on("frame.message",e)}):a((()=>window.parent),t),this.detach=this.channel.onMessage((e=>{this.receive(e)})),(n||window.parent!==window)&&this.nonce){const t=()=>this.channel.post(l("frame.hello",{nonce:this.nonce,appCapabilities:[...e.onOpen?["open"]:[],...e.onBeforeClose?["beforeClose"]:[],...e.onBack?["back"]:[]]}));t(),this.helloTimer=setInterval(t,250),this.helloDeadline=setTimeout((()=>clearInterval(this.helloTimer)),n?1e4:1500)}}async receive(t){var i,s,o,r,a,c,p,h,u,m,y,g,f,w,b,v,E;if(!d(t))return;const k=t.payload;if("frame.init"===t.type){if(!this.nonce||k.nonce!==this.nonce||"string"!=typeof k.locale||!k.theme||"string"!=typeof k.windowId||k.launch&&!e.isOpenRequest(k.launch))return;return clearInterval(this.helloTimer),clearTimeout(this.helloDeadline),this.init=k,this.title=void 0,this.focused=void 0,Object.keys(this.header).length&&this.send("header.set",this.header),void(null==(s=(i=this.options).onInit)||s.call(i,this.init))}if(!this.init)return;if("sysdlg.openResult"===t.type){const i=t.replyTo?this.dialogs.get(t.replyTo):void 0;if(!i)return;if(this.dialogs.delete(t.replyTo),!0!==k.ok)return i.reject(new e.SystemDialogError(n(k.code)));const s=e.readSelectDialogResult(k.result,{allowLocal:i.allowLocal});return void(s?i.resolve(s):i.reject(new e.SystemDialogError("protocol")))}if("app.openResult"===t.type){const e="not_found"===k.code||"denied"===k.code?k.code:"unsupported";return void(t.replyTo&&(null==(o=this.appOpens.get(t.replyTo))||o(!0===k.ok?{ok:!0}:{ok:!1,code:e})))}if("header.event"===t.type){if("search"!==k.kind&&"item"!==k.kind&&"menu"!==k.kind)return;return void(null==(a=(r=this.options).onHeaderEvent)||a.call(r,{kind:k.kind,..."string"==typeof k.id?{id:k.id}:{},..."string"==typeof k.value?{value:k.value}:{}}))}const O=e=>this.channel.post(l(t.type+"Result",e,{replyTo:t.id}));try{"frame.open"===t.type&&e.isOpenRequest(k.request)&&O(await(null==(p=(c=this.options).onOpen)?void 0:p.call(c,k.request))??{accepted:!1}),"frame.beforeClose"===t.type&&O({decision:await(null==(u=(h=this.options).onBeforeClose)?void 0:u.call(h,k.reason))??"allow"}),"frame.back"===t.type&&O({handled:await(null==(y=(m=this.options).onBack)?void 0:y.call(m))??!1}),"frame.themeChanged"!==t.type||"dark"!==k.mode&&"light"!==k.mode||null==(f=(g=this.options).onTheme)||f.call(g,k),"frame.localeChanged"===t.type&&"string"==typeof k.locale&&(null==(b=(w=this.options).onLocale)||b.call(w,k.locale)),"frame.focusChanged"===t.type&&this.focused!==(!0===k.focused)&&(this.focused=!0===k.focused,null==(E=(v=this.options).onFocus)||E.call(v,this.focused))}catch{"frame.open"===t.type&&O({accepted:!1,fallback:"preview"}),"frame.beforeClose"===t.type&&O({decision:"deny"})}}send(e,t){this.init&&this.channel.post(l(e,t))}setTitle(e,t=!1){const i=JSON.stringify([e,t]);this.init&&i!==this.title&&(this.title=i,this.send("window.setTitle",{title:e,dirty:t}))}requestClose(){this.send("window.requestClose",{})}setHeader(e){this.header={...this.header,...e},this.send("header.set",e)}openApp(e){const i=t.readAppOpenRequest(e);if(!i)return Promise.resolve({ok:!1,code:"denied"});if(this.init){if(!this.init.shellCapabilities.includes("app.open"))return Promise.resolve({ok:!1,code:"unsupported"});const e=crypto.randomUUID();return new Promise((t=>{const n=i=>{clearTimeout(s),this.appOpens.delete(e),t(i)},s=setTimeout((()=>n({ok:!1,code:"unsupported"})),3e4);this.appOpens.set(e,n),this.channel.post(l("app.open",i,{id:e}))}))}return!this.options.systemOrigin||i.zone?Promise.resolve({ok:!1,code:"unsupported"}):(window.open(t.systemOpenAppUrl(this.options.systemOrigin,i),"_blank","noopener"),Promise.resolve({ok:!0}))}openContent(t,i="default",n={}){const s=n.hints??{};return this.init?(this.send("content.open",{request:t,target:i,newWindow:!0===n.newWindow,hints:s}),!0):!!this.options.systemOrigin&&(window.open(e.systemOpenUrl(this.options.systemOrigin,{request:t,target:i,hints:s,from:this.options.appId}),"_blank","noopener"),!0)}selectContent(t={},i={}){var n,s,o;const r=null==(n=this.init)?void 0:n.shellCapabilities.includes(e.SELECT_DIALOG_PATH);if(this.init&&(r||!this.native)){if(!r)return Promise.reject(new e.SystemDialogError("unsupported"));if(this.dialogs.size)return Promise.reject(new e.SystemDialogError("busy"));const i=crypto.randomUUID();return new Promise(((n,s)=>{this.dialogs.set(i,{resolve:n,reject:s,allowLocal:!0===t.allowLocal}),this.channel.post(l("sysdlg.open",{path:e.SELECT_DIALOG_PATH,params:t},{id:i}))}))}if(!this.options.systemOrigin)return Promise.reject(new e.SystemDialogError("unsupported"));const a=this.embedAbort=new AbortController;return null==(s=i.signal)||s.addEventListener("abort",(()=>a.abort()),{once:!0}),(null==(o=i.signal)?void 0:o.aborted)&&a.abort(),w(this.options.systemOrigin,t,{...i,signal:a.signal})}dispose(){var t;clearInterval(this.helloTimer),clearTimeout(this.helloDeadline),this.detach(),this.appOpens.forEach((e=>e({ok:!1,code:"unsupported"}))),this.dialogs.forEach((t=>t.reject(new e.SystemDialogError("closed")))),this.dialogs.clear(),null==(t=this.embedAbort)||t.abort()}},exports.AppFrameHost=class{constructor(e){this.ready=!1,this.capabilities=[],this.header={},this.pending=new Map,this.opens=new Map,this.dialogOpen=!1,this.callbacks=e,this.framed=!e.transport,this.init=e.transport?{...e.init,nonce:""}:e.init,this.channel=e.transport??a(e.target,e.origin),this.detach=this.channel.onMessage((e=>this.receive(e)))}limited(e){const t=(this.opens.get(e)??[]).filter((e=>e>Date.now()-1e4));return this.opens.set(e,t),t.length>=5||(t.push(Date.now()),!1)}async appOpen(e,i){const n=t=>{this.ready&&this.channel.post(l("app.openResult",t,{replyTo:e}))};if(!this.callbacks.onAppOpen)return n({ok:!1,code:"unsupported"});const s=t.readAppOpenRequest(i);if(!s||this.limited("app.open"))return n({ok:!1,code:"denied"});try{n(await this.callbacks.onAppOpen(s))}catch{n({ok:!1,code:"denied"})}}async systemDialog(t,i,n){const s=e=>{this.ready&&this.channel.post(l("sysdlg.openResult",e,{replyTo:t}))};if(!this.callbacks.onSystemDialog||"string"!=typeof i)return s({ok:!1,code:"unsupported"});if(this.dialogOpen)return s({ok:!1,code:"busy"});this.dialogOpen=!0;try{s(await this.callbacks.onSystemDialog(i,n))}catch(o){s({ok:!1,code:o instanceof e.SystemDialogError?o.code:"closed"})}finally{this.dialogOpen=!1}}receive(t){var i,n,s,o,a,l,c,p,h,u,m,y;if(!d(t))return;const g=t.payload;if("frame.hello"===t.type){if(!Array.isArray(g.appCapabilities))return;if(this.framed){if(g.nonce!==this.init.nonce)return}else{if("string"!=typeof g.nonce||!g.nonce||g.nonce.length>128)return;g.nonce!==this.init.nonce&&this.failPending("App frame reloaded"),this.init={...this.init,nonce:g.nonce}}return this.ready=!0,this.capabilities=g.appCapabilities.filter((e=>"string"==typeof e)),this.send("frame.init",this.init),void 0!==this.focused&&this.send("frame.focusChanged",{focused:this.focused}),Object.keys(this.header).length&&(this.header={},null==(n=(i=this.callbacks).onHeader)||n.call(i,{})),void(null==(o=(s=this.callbacks).onReady)||o.call(s))}if(this.ready)if(t.replyTo){const e=this.pending.get(t.replyTo);e&&t.type===e.type+"Result"&&(clearTimeout(e.timer),this.pending.delete(t.replyTo),e.resolve(t.payload))}else if("window.setTitle"===t.type&&"string"==typeof g.title&&(null==(l=(a=this.callbacks).onTitle)||l.call(a,g.title.slice(0,256),!0===g.dirty)),"window.requestClose"===t.type&&(null==(p=(c=this.callbacks).onRequestClose)||p.call(c)),"header.set"===t.type&&(this.header={...this.header,...r(g)},null==(u=(h=this.callbacks).onHeader)||u.call(h,this.header)),"app.open"===t.type&&"string"==typeof t.id&&this.appOpen(t.id,g),"sysdlg.open"===t.type&&"string"==typeof t.id&&this.systemDialog(t.id,g.path,g.params),"content.open"===t.type&&("default"===g.target||"preview"===g.target||"chooser"===g.target)){const t={...g.request,requestId:crypto.randomUUID()};if(!e.isOpenRequest(t)||this.limited("content.open"))return;null==(y=(m=this.callbacks).onContentOpen)||y.call(m,t,g.target,{newWindow:!0===g.newWindow,hints:e.readContentHints(g.hints)})}}update(e){this.init={...this.init,...e}}setFocused(e){this.focused!==e&&(this.focused=e,this.send("frame.focusChanged",{focused:e}))}headerEvent(e){this.send("header.event",e)}send(e,t){this.ready&&this.channel.post(l(e,t))}request(e,t,i=3e3){if(!this.ready)return Promise.reject(new Error("App frame is not ready"));const n=crypto.randomUUID();return new Promise(((s,o)=>{const r=setTimeout((()=>{this.pending.delete(n),o(new Error("App frame timed out"))}),i);this.pending.set(n,{resolve:s,reject:o,timer:r,type:e}),this.channel.post(l(e,t,{id:n}))}))}async open(e){return this.capabilities.includes("open")?await this.request("frame.open",{request:e}):{accepted:!1}}async beforeClose(e="user"){if(!this.ready||!this.capabilities.includes("beforeClose"))return"allow";const t=await this.request("frame.beforeClose",{reason:e});return"allow"===t.decision||"pending"===t.decision?t.decision:"deny"}async back(){return!!this.capabilities.includes("back")&&!0===(await this.request("frame.back",{})).handled}failPending(e){this.pending.forEach((t=>{clearTimeout(t.timer),t.reject(new Error(e))})),this.pending.clear()}dispose(){this.detach(),this.failPending("App frame disposed"),this.ready=!1}},exports.CONVERSATION_EMBED_ERROR_CODES=E,exports.CONVERSATION_EMBED_PATH=v,exports.ConversationEmbed=class{constructor(e){this.options=e,this.nonce=crypto.randomUUID(),this.listener=e=>this.receive(e),this.ready=!1,this.outbox=[],this.origin=new URL(e.systemOrigin).origin,this.init=e.init,this.url=`${this.origin}${v}#bce=${this.nonce}&po=${encodeURIComponent(window.location.origin)}`,window.addEventListener("message",this.listener)}post(e,t){var i,n;null==(n=null==(i=this.options.frame())?void 0:i.contentWindow)||n.postMessage(h(e,t,b),this.origin)}receive(e){var t,i,n,s,o,r,a;if(e.origin!==this.origin||e.source!==(null==(t=this.options.frame())?void 0:t.contentWindow)||!u(e.data,b))return;const{type:l,payload:d}=e.data;if("embed.hello"===l){if(d.nonce!==this.nonce)return;this.ready=!0,this.post("embed.init",{...this.init,nonce:this.nonce});const e=this.outbox;return this.outbox=[],void e.forEach((e=>this.post("embed.send",e)))}"embed.state"!==l||"loading"!==d.status&&"ready"!==d.status&&"error"!==d.status||null==(n=(i=this.options).onState)||n.call(i,{status:d.status,sessionId:"string"==typeof d.sessionId?d.sessionId.slice(0,512):void 0,error:"string"==typeof d.error?d.error.slice(0,128):void 0}),"embed.turn"===l&&k.includes(d.mode)&&(null==(o=(s=this.options).onTurn)||o.call(s,d.mode)),"embed.error"===l&&E.includes(d.code)&&(null==(a=(r=this.options).onError)||a.call(r,d.code))}update(e){this.init={...this.init,...e},this.ready&&this.post("embed.update",e)}send(e){var t;const i={text:e.text,...(null==(t=e.attachments)?void 0:t.length)?{attachments:e.attachments}:{}};this.ready?this.post("embed.send",i):this.outbox.push(i)}dispose(){window.removeEventListener("message",this.listener),this.outbox=[]}},exports.ConversationEmbedHost=class{constructor(e){this.options=e,this.ready=!1,this.listener=e=>this.receive(e);const t=new URLSearchParams(window.location.hash.slice(1));this.nonce=t.get("bce");let i=null;try{i=new URL(t.get("po")??"").origin}catch{}if(this.parentOrigin=window.parent!==window&&this.nonce&&i&&e.accept(i)?i:null,!this.parentOrigin)return;window.addEventListener("message",this.listener);const n=()=>window.parent.postMessage(h("embed.hello",{nonce:this.nonce},b),this.parentOrigin);n(),this.hello=setInterval((()=>{this.ready||n()}),250)}receive(t){var i,n,s,o;if(t.source!==window.parent||t.origin!==this.parentOrigin||!u(t.data,b))return;const{type:r,payload:a}=t.data;if("embed.init"===r){if(this.ready||a.nonce!==this.nonce||"string"!=typeof a.locale)return;return this.ready=!0,clearInterval(this.hello),void this.options.onInit({nonce:String(a.nonce),target:a.target,theme:"dark"===a.theme?"dark":"light",locale:a.locale,..."string"==typeof a.placeholder?{placeholder:a.placeholder.slice(0,200)}:{}})}if(this.ready){if("embed.update"===r){const e={};"dark"!==a.theme&&"light"!==a.theme||(e.theme=a.theme),"string"==typeof a.locale&&(e.locale=a.locale),null==(n=(i=this.options).onUpdate)||n.call(i,e)}if("embed.send"===r){const t=(t=>"string"!=typeof t.text||t.text.length>65536?null:void 0===t.attachments?{text:t.text}:!Array.isArray(t.attachments)||t.attachments.length>32||!t.attachments.every(e.isTransferableRef)?null:{text:t.text,attachments:t.attachments})(a);t?null==(o=(s=this.options).onSend)||o.call(s,t):this.error("invalid_params")}}}post(e,t){this.ready&&this.parentOrigin&&window.parent.postMessage(h(e,t,b),this.parentOrigin)}state(e){this.post("embed.state",e)}turn(e){this.post("embed.turn",{mode:e})}error(e){this.post("embed.error",{code:e})}dispose(){clearInterval(this.hello),window.removeEventListener("message",this.listener)}},exports.PREVIEW_EMBED_PATH=m,exports.PreviewEmbed=class{constructor(e){this.options=e,this.nonce=crypto.randomUUID(),this.listener=e=>this.receive(e),this.ready=!1,this.origin=new URL(e.systemOrigin).origin,this.init=e.init,this.url=`${this.origin}${m}#bpe=${this.nonce}&po=${encodeURIComponent(window.location.origin)}`,window.addEventListener("message",this.listener)}post(e,t){var i,n;null==(n=null==(i=this.options.frame())?void 0:i.contentWindow)||n.postMessage(h(e,t),this.origin)}receive(t){var i,n,s,o,r,a,l;if(t.origin!==this.origin||t.source!==(null==(i=this.options.frame())?void 0:i.contentWindow)||!u(t.data))return;const{type:d,payload:c}=t.data;if("embed.hello"!==d){if("embed.state"===d&&("loading"===c.status||"ready"===c.status||"error"===c.status)){const e=c.error;null==(s=(n=this.options).onState)||s.call(n,{status:c.status,error:e&&"string"==typeof e.kind&&"string"==typeof e.code?{kind:e.kind,code:e.code}:void 0,title:"string"==typeof c.title?c.title.slice(0,256):void 0,mediaType:"string"==typeof c.mediaType?c.mediaType.slice(0,128):void 0})}if("embed.openWith"===d){const t=c.request;t&&e.isTransferableRef(t.source)&&(void 0===t.session||e.isTransferableSession(t.session))&&(null==(r=(o=this.options).onOpenWith)||r.call(o,{request:{source:t.source,session:t.session},hints:e.readContentHints(c.hints)}))}"embed.exit"===d&&(null==(l=(a=this.options).onExit)||l.call(a))}else c.nonce===this.nonce&&(this.ready=!0,this.post("embed.init",{...this.init,nonce:this.nonce}))}update(e){this.init={...this.init,...e},this.ready&&this.post("embed.update",e)}dispose(){window.removeEventListener("message",this.listener)}},exports.PreviewEmbedHost=class{constructor(e){this.options=e,this.ready=!1,this.listener=e=>this.receive(e);const t=new URLSearchParams(window.location.hash.slice(1));this.nonce=t.get("bpe");let i=null;try{i=new URL(t.get("po")??"").origin}catch{}if(this.parentOrigin=window.parent!==window&&this.nonce&&i&&e.accept(i)?i:null,!this.parentOrigin)return;window.addEventListener("message",this.listener);const n=()=>window.parent.postMessage(h("embed.hello",{nonce:this.nonce}),this.parentOrigin);n(),this.hello=setInterval((()=>{this.ready||n()}),250)}receive(t){var i,n;if(t.source!==window.parent||t.origin!==this.parentOrigin||!u(t.data))return;const{type:s,payload:o}=t.data;if("embed.init"===s){if(o.nonce!==this.nonce||(r=o.source,!(e.isTransferableRef(r)||r&&"object"==typeof r&&"blob"===r.kind&&"undefined"!=typeof Blob&&r.blob instanceof Blob&&"string"==typeof r.name))||void 0!==o.session&&!e.isTransferableSession(o.session)||"string"!=typeof o.locale)return;return this.ready=!0,clearInterval(this.hello),void this.options.onInit({nonce:String(o.nonce),source:o.source,session:o.session,theme:"dark"===o.theme?"dark":"light",locale:o.locale})}var r;if("embed.update"===s&&this.ready){const e={};"dark"!==o.theme&&"light"!==o.theme||(e.theme=o.theme),"string"==typeof o.locale&&(e.locale=o.locale),null==(n=(i=this.options).onUpdate)||n.call(i,e)}}post(e,t){this.ready&&this.parentOrigin&&window.parent.postMessage(h(e,t),this.parentOrigin)}state(e){this.post("embed.state",e)}openWith(e){this.post("embed.openWith",e)}exit(){this.post("embed.exit",{})}dispose(){clearInterval(this.hello),window.removeEventListener("message",this.listener)}},exports.SELECT_EMBED_PATH=g,exports.SelectEmbedHost=class{constructor(e){this.options=e,this.ready=!1,this.listener=e=>this.receive(e);const t=new URLSearchParams(window.location.hash.slice(1));this.nonce=t.get("bse");let i=null;try{i=new URL(t.get("po")??"").origin}catch{}if(this.parentOrigin=window.parent!==window&&this.nonce&&i&&e.accept(i)?i:null,!this.parentOrigin)return;window.addEventListener("message",this.listener);const n=()=>window.parent.postMessage(h("embed.hello",{nonce:this.nonce},y),this.parentOrigin);n(),this.hello=setInterval((()=>{this.ready||n()}),250)}receive(e){if(e.source!==window.parent||e.origin!==this.parentOrigin||!u(e.data,y))return;const{type:t,payload:i}=e.data;"embed.init"!==t||this.ready||i.nonce!==this.nonce||"string"!=typeof i.locale||(this.ready=!0,clearInterval(this.hello),this.options.onInit({nonce:String(i.nonce),params:i.params,theme:"dark"===i.theme?"dark":"light",locale:i.locale}))}post(e,t){this.ready&&this.parentOrigin&&window.parent.postMessage(h(e,t,y),this.parentOrigin)}result(e){this.post("embed.result",{result:e})}error(e){this.post("embed.error",{code:e})}dispose(){clearInterval(this.hello),window.removeEventListener("message",this.listener)}},exports.appFrameName=function(e){return c+e},exports.embedderOrigin=function(e){var t;if(window.parent===window)return i.getBuckyApi()&&e(window.location.origin)?window.location.origin:null;const n=[null==(t=window.location.ancestorOrigins)?void 0:t[0],document.referrer];for(const i of n)if(i)try{const t=new URL(i).origin;if(e(t))return t}catch{}return null},exports.openSelectEmbed=w,exports.originInZone=(e,t)=>{try{const i=new URL(e);return i.protocol===window.location.protocol&&(i.hostname===t||i.hostname.endsWith(`.${t}`))}catch{return!1}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./content.cjs"),t=require("./open-app.cjs"),n=require("./runtime_env-6396e1eb.js"),r=require("./transfer.cjs");require("./object_url-88047ee2.js"),require("./ndn_types-5b138882.js");const i=t=>e.SYSTEM_DIALOG_ERROR_CODES.includes(t)?t:"protocol",s=(e,t)=>"string"==typeof e?e.slice(0,t):void 0;function o(e,t){return Array.isArray(e)?e.slice(0,32).flatMap((e=>{const n=e;return!n||"object"!=typeof n||"string"!=typeof n.id||!n.id||n.id.length>128||"string"!=typeof n.label?[]:[t(n,{id:n.id,label:n.label.slice(0,128)})]})):[]}function a(e){const t={},n=s(e.title,256);if(void 0!==n&&(t.title=n),Array.isArray(e.second_row)&&(t.second_row=o(e.second_row,((e,t)=>({...t,...!0===e.active?{active:!0}:{}})))),Array.isArray(e.menu)&&(t.menu=o(e.menu,((e,t)=>({...t,..."string"==typeof e.icon?{icon:e.icon.slice(0,2048)}:{},...!0===e.danger?{danger:!0}:{}})))),null===e.search)t.search=null;else if(e.search&&"object"==typeof e.search){const n=e.search,r=s(n.placeholder,128),i=s(n.value,1024);t.search={...void 0!==r?{placeholder:r}:{},...void 0!==i?{value:i}:{}}}return"boolean"==typeof e.back&&(t.back=e.back),t}function l(e,t){return{post:(n,r)=>{var i;return null==(i=e())?void 0:i.postMessage(n,t,r??[])},onMessage:n=>{const r=window,i=r=>{r.source===e()&&r.origin===t&&n(r.data,r.ports)};return r.addEventListener("message",i),()=>r.removeEventListener("message",i)}}}const d=(e,t,n={})=>({protocol:"buckyos.app-frame",version:1,type:e,payload:t,...n}),c=e=>{if(!e||"object"!=typeof e)return!1;const t=e;return"buckyos.app-frame"===t.protocol&&1===t.version&&"string"==typeof t.type&&!!t.payload&&"object"==typeof t.payload},p="transfer.v1",h=["unsupported","stale","denied"];class u extends Error{constructor(e,t){super(t??`Transfer: ${e}`),this.code=e,this.name="TransferError"}}const f=/^[A-Za-z0-9_-]{16,128}$/,m=/^[A-Za-z0-9_-]{8,128}$/,y=/^(?:files|[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126})$/,g=["zone-file","zone-folder","local-file","text","object"],v=["copy","move","link"],w=["done","accepted","skipped","failed","cancelled"],b=1048576,k=5e3,T=1500,I=1e4,E=15e3,A=3e3,O=e=>!!e&&"object"==typeof e&&!Array.isArray(e),L=e=>"string"==typeof e&&f.test(e),x=e=>"string"==typeof e&&/^(0|[1-9]\d{0,5})$/.test(e),R=e=>"string"==typeof e&&y.test(e),C=e=>{if(Array.isArray(e)&&e.length&&!(e.length>3)&&e.every((e=>v.includes(e))))return[...new Set(e)]},P=e=>Array.isArray(e)&&e.length&&e.length<=32&&e.every(R)?[...new Set(e)]:void 0,S=e=>"focus"===e?"focus":O(e)&&Number.isFinite(e.x)&&Number.isFinite(e.y)?{x:e.x,y:e.y}:void 0,D=(e,t,n)=>{if(!O(e))return;const r=Object.entries(e);return r.length>t||!r.every((([e,t])=>e.length<=128&&"string"==typeof t&&t.length<=n))?void 0:Object.fromEntries(r)},_=e=>h.includes(e)?e:"unsupported";function M(e){if(!O(e)||!L(e.offerId)||!["copy","cut","drag"].includes(e.purpose))return;if(!Number.isSafeInteger(e.generation)||e.generation<0)return;if(!Array.isArray(e.items)||!e.items.length||e.items.length>r.MAX_CONTENT_REFS)return;let t=0;const n=[];for(const r of e.items){if(!O(r)||!g.includes(r.kind))return;const e=P(r.formats),i=C(r.operations);if(!e||!i)return;const s={kind:r.kind,formats:e,operations:i};if(void 0!==r.inline){const n=D(r.inline,32,b);if(!n||!Object.keys(n).every((t=>e.includes(t))))return;if(t+=Object.values(n).reduce(((e,t)=>e+t.length),0),t>b)return;s.inline=n}n.push(s)}const i={offerId:e.offerId,purpose:e.purpose,generation:e.generation,items:n};if(void 0!==e.scope){const t=D(e.scope,8,512);if(!t)return;i.scope=t}return i}function U(e){if(!O(e)||!L(e.operationId)||!Number.isSafeInteger(e.seq))return;const t=function(e){if(!Array.isArray(e)||!e.length||e.length>r.MAX_CONTENT_REFS)return;const t=[];for(const n of e){if(!O(n)||!x(n.itemKey)||!g.includes(n.kind))return;const e=P(n.formats),r=C(n.operations);if(!e||!r)return;t.push({itemKey:n.itemKey,kind:n.kind,formats:e,operations:r})}return t}(e.items),n=S(e.at);return t&&n?{operationId:e.operationId,seq:e.seq,items:t,at:n}:void 0}function j(e,t){if(!O(e)||"string"!=typeof e.targetId||!e.targetId||e.targetId.length>256||!Array.isArray(e.accept))return null;const n=new Map(t.items.map((e=>[e.itemKey,e]))),r=new Set,i=[];for(const s of e.accept){if(!O(s)||"string"!=typeof s.itemKey||r.has(s.itemKey))continue;const e=n.get(s.itemKey);e&&e.formats.includes(s.format)&&e.operations.includes(s.operation)&&(r.add(s.itemKey),i.push({itemKey:s.itemKey,format:s.format,operation:s.operation}))}return i.length?{targetId:e.targetId,accept:i,action:"string"==typeof e.action?e.action.slice(0,200):""}:null}function q(e){if(!(O(e)&&L(e.operationId)&&L(e.offerId)&&Number.isSafeInteger(e.generation)))return;if(!Array.isArray(e.items)||!e.items.length||e.items.length>r.MAX_CONTENT_REFS)return;const t=[];for(const n of e.items){if(!O(n)||!x(n.itemKey)||!R(n.format))return;t.push({itemKey:n.itemKey,format:n.format})}return{operationId:e.operationId,offerId:e.offerId,generation:e.generation,items:t}}function K(t,n){if(t===r.CONTENT_REFS_FORMAT){if("string"==typeof n){const e=r.readContentRefs(n);return 1===(null==e?void 0:e.length)?e[0]:void 0}return e.readZoneContent(n)}return"files"===t?(i=n,"undefined"!=typeof File&&i instanceof File?n:void 0):"string"==typeof n?n.length<=16777216?n:void 0:(e=>"undefined"!=typeof Blob&&e instanceof Blob)(n)&&!t.startsWith("text/")?n:void 0;var i}function $(e){if(!O(e)||!L(e.operationId)||"string"!=typeof e.targetId||!e.targetId||e.targetId.length>256)return;if(!v.includes(e.operation))return;const t=S(e.at),n=function(e){if(!Array.isArray(e)||!e.length||e.length>r.MAX_CONTENT_REFS)return;const t=[];for(const n of e){if(!O(n)||!x(n.itemKey)||!R(n.format))return;const e=K(n.format,n.value);if(void 0===e)return;t.push({itemKey:n.itemKey,format:n.format,value:e})}return t}(e.items);return t&&n?{operationId:e.operationId,targetId:e.targetId,operation:e.operation,at:t,items:n}:void 0}function N(e,t){if(!O(e)||!["done","accepted","cancelled","failed"].includes(e.status)||!Array.isArray(e.items))return;const n=new Map;for(const r of e.items)O(r)&&"string"==typeof r.itemKey&&w.includes(r.status)&&n.set(r.itemKey,{status:r.status,..."string"==typeof r.error?{error:r.error.slice(0,200)}:{}});return{status:e.status,items:t.map((({itemKey:e})=>({itemKey:e,...n.get(e)??{status:"failed",error:"no_result"}})))}}function W(e,t,n){const r=new Map;if(Array.isArray(e))for(const i of e)O(i)&&"string"==typeof i.itemKey&&"string"==typeof i.format&&r.set(`${i.itemKey}\n${i.format}`,i);return t.items.map((({itemKey:e,format:t})=>{const i=r.get(`${e}\n${t}`);if(!i)return{itemKey:e,format:t,error:"failed"};if("error"in i&&void 0!==i.error)return{itemKey:e,format:t,error:"failed"===i.error?"failed":_(i.error)};if("files"===t&&!n.files)return{itemKey:e,format:t,error:"unsupported"};const s=K(t,i.value);return void 0===s?{itemKey:e,format:t,error:"failed"}:{itemKey:e,format:t,value:s}}))}const F=(e,t,n)=>{var r;return t.onmessage=e=>n(e.data),null==(r=t.start)||r.call(t),{documentId:e,post:e=>t.postMessage(e),close:()=>{t.onmessage=null,t.close()}}},H="buckyos.app-frame:";const B="buckyos.preview-embed",z=(e,t,n=B)=>({protocol:n,version:1,type:e,payload:t}),X=(e,t=B)=>{const n=e;return!!n&&n.protocol===t&&1===n.version&&"string"==typeof n.type&&!!n.payload&&"object"==typeof n.payload},V="/embed/preview";const Z="buckyos.sysdlg-embed",G="/embed/sysdlg/select";let Y=!1;function J(t,n,r={}){var s,o;if(null==(s=r.signal)?void 0:s.aborted)return Promise.reject(new e.SystemDialogError("closed"));if(Y)return Promise.reject(new e.SystemDialogError("busy"));Y=!0;const a=new URL(t).origin,l=r.locale??navigator.language??"en",d=r.theme??((null==(o=window.matchMedia)?void 0:o.call(window,"(prefers-color-scheme: dark)").matches)?"dark":"light"),c=l.toLowerCase().startsWith("zh");return new Promise(((t,s)=>{var o;const p=document.body,h=document.documentElement,u=document.activeElement instanceof HTMLElement?document.activeElement:null,f={x:window.scrollX,y:window.scrollY},m={body:p.getAttribute("style"),html:h.getAttribute("style")},y=Array.from(p.children).filter((e=>e instanceof HTMLElement)).map((e=>({el:e,inert:e.inert,hidden:e.getAttribute("aria-hidden")}))),g=document.createElement("div");let v;g.setAttribute("data-buckyos-sysdlg","select"),g.setAttribute("role","dialog"),g.setAttribute("aria-modal","true"),g.setAttribute("aria-label",c?"文件选择器":"File picker"),g.style.cssText="position:fixed;inset:0;height:100vh;height:100dvh;z-index:2147483647;background:rgba(0,0,0,.32);display:flex;align-items:center;justify-content:center";let w,b="",k=!1;const T=e=>{g.contains(e.target)||(e.stopPropagation(),e.preventDefault())},I=["keydown","pointerdown","mousedown","touchstart","wheel"],E=()=>{var e;return!k&&(k=!0,Y=!1,clearTimeout(w),window.removeEventListener("message",R),null==(e=r.signal)||e.removeEventListener("abort",O),"inert"in HTMLElement.prototype||I.forEach((e=>document.removeEventListener(e,T,!0))),g.remove(),y.forEach((({el:e,inert:t,hidden:n})=>{e.inert=t,null===n?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",n)})),null===m.body?p.removeAttribute("style"):p.setAttribute("style",m.body),null===m.html?h.removeAttribute("style"):h.setAttribute("style",m.html),window.scrollTo(f.x,f.y),null==u||u.focus({preventScroll:!0}),!0)},A=t=>{E()&&s(new e.SystemDialogError(t))},O=()=>A("closed"),L=()=>{null==v||v.remove(),v=void 0;const e=document.createElement("div");e.setAttribute("role","alert"),e.style.cssText=`max-width:22rem;margin:1rem;padding:1.25rem;border-radius:16px;font:14px/1.6 system-ui,sans-serif;background:${"dark"===d?"#1f2329":"#fff"};color:${"dark"===d?"#f2f3f5":"#1f2329"};box-shadow:0 24px 64px rgba(0,0,0,.24)`;const t=document.createElement("p");t.style.margin="0 0 1rem",t.textContent=c?"无法加载文件选择器":"Unable to load the file picker";const n=document.createElement("div");n.style.cssText="display:flex;gap:.5rem;justify-content:flex-end";const r=(e,t)=>{const r=document.createElement("button");return r.type="button",r.textContent=e,r.style.cssText="min-height:2.25rem;padding:0 1rem;font:inherit;border-radius:999px;border:1px solid currentColor;background:transparent;color:inherit;cursor:pointer",r.addEventListener("click",t),n.append(r),r};r(c?"取消":"Cancel",(()=>A("load_failed")));const i=r(c?"重试":"Retry",(()=>{e.remove(),x()}));e.append(t,n),g.append(e),i.focus()},x=()=>{b=crypto.randomUUID(),v=document.createElement("iframe"),v.title=c?"文件选择器":"File picker",v.style.cssText="position:absolute;inset:0;width:100%;height:100%;border:0;background:transparent;color-scheme:normal",v.setAttribute("allowtransparency","true"),v.addEventListener("error",L),v.src=`${a}${G}#bse=${b}&po=${encodeURIComponent(window.location.origin)}`,g.append(v),w=setTimeout(L,1e4)},R=r=>{var s;if(!v||r.origin!==a||r.source!==v.contentWindow||!X(r.data,Z))return;const{type:o,payload:c}=r.data;if("embed.hello"===o){if(c.nonce!==b)return;clearTimeout(w),null==(s=v.contentWindow)||s.postMessage(z("embed.init",{nonce:b,params:n,theme:d,locale:l},Z),a),v.focus()}if("embed.error"===o&&A(i(c.code)),"embed.result"===o){const r=e.readSelectDialogResult(c.result,{allowLocal:!0===n.allowLocal});r?(e=>{E()&&t(e)})(r):A("protocol")}};window.addEventListener("message",R),null==(o=r.signal)||o.addEventListener("abort",O,{once:!0}),"inert"in HTMLElement.prototype?y.forEach((({el:e})=>{e.inert=!0})):(y.forEach((({el:e})=>e.setAttribute("aria-hidden","true"))),I.forEach((e=>document.addEventListener(e,T,!0)))),h.style.overflow="hidden",p.style.position="fixed",p.style.top=-f.y+"px",p.style.left=-f.x+"px",p.style.right="0",p.style.overflow="hidden",p.append(g),x()}))}const Q="buckyos.conversation-embed",ee="/embed/conversation",te=["invalid_params","not_found","denied"],ne=["idle","running","interrupted","paused","answer"];exports.AppFrameClient=class{constructor(e){this.options=e,this.header={},this.dialogs=new Map,this.appOpens=new Map,this.documentId=r.newOfferId(),this.transferPending=new Map,this.deliveries=new Map,this.generation=0;const t=new URL(e.shellOrigin).origin,i=window.parent===window?n.getBuckyApi():void 0;this.native=!!i;const s=window.parent!==window?window.name:"";var o;if(this.nonce=(null==s?void 0:s.startsWith(H))?s.slice(18):new URLSearchParams(window.location.hash.slice(1)).get("bfp")??(i?crypto.randomUUID():null),this.channel=i?(o=i,{post:e=>{Promise.resolve(o.call("frame.post",e)).catch((()=>{}))},onMessage:e=>o.on("frame.message",e)}):l((()=>window.parent),t),this.detach=this.channel.onMessage((e=>{this.receive(e)})),(i||window.parent!==window)&&this.nonce){const t=()=>this.channel.post(d("frame.hello",{nonce:this.nonce,appCapabilities:[...e.onOpen?["open"]:[],...e.onBeforeClose?["beforeClose"]:[],...e.onBack?["back"]:[],...e.transfer?[p]:[]],...e.transfer?{documentId:this.documentId}:{}}));t(),this.helloTimer=setInterval(t,250),this.helloDeadline=setTimeout((()=>clearInterval(this.helloTimer)),i?1e4:1500)}}async receive(t){var n,r,s,o,a,l,p,h,u,f,m,y,g,v,w,b,k;if(!c(t))return;const T=t.payload;if("frame.init"===t.type){if(!this.nonce||T.nonce!==this.nonce||"string"!=typeof T.locale||!T.theme||"string"!=typeof T.windowId||T.launch&&!e.isOpenRequest(T.launch))return;return clearInterval(this.helloTimer),clearTimeout(this.helloDeadline),this.init=T,this.title=void 0,this.focused=void 0,Object.keys(this.header).length&&this.send("header.set",this.header),null==(r=(n=this.options).onInit)||r.call(n,this.init),void this.connectTransfer()}if(t.type.startsWith("transfer."))return void(this.native&&this.transferLink&&this.receiveTransfer(t,this.transferLink));if(!this.init)return;if("sysdlg.openResult"===t.type){const n=t.replyTo?this.dialogs.get(t.replyTo):void 0;if(!n)return;if(this.dialogs.delete(t.replyTo),!0!==T.ok)return n.reject(new e.SystemDialogError(i(T.code)));const r=e.readSelectDialogResult(T.result,{allowLocal:n.allowLocal});return void(r?n.resolve(r):n.reject(new e.SystemDialogError("protocol")))}if("app.openResult"===t.type){const e="not_found"===T.code||"denied"===T.code?T.code:"unsupported";return void(t.replyTo&&(null==(s=this.appOpens.get(t.replyTo))||s(!0===T.ok?{ok:!0}:{ok:!1,code:e})))}if("header.event"===t.type){if("search"!==T.kind&&"item"!==T.kind&&"menu"!==T.kind)return;return void(null==(a=(o=this.options).onHeaderEvent)||a.call(o,{kind:T.kind,..."string"==typeof T.id?{id:T.id}:{},..."string"==typeof T.value?{value:T.value}:{}}))}const I=e=>this.channel.post(d(t.type+"Result",e,{replyTo:t.id}));try{"frame.open"===t.type&&e.isOpenRequest(T.request)&&I(await(null==(p=(l=this.options).onOpen)?void 0:p.call(l,T.request))??{accepted:!1}),"frame.beforeClose"===t.type&&I({decision:await(null==(u=(h=this.options).onBeforeClose)?void 0:u.call(h,T.reason))??"allow"}),"frame.back"===t.type&&I({handled:await(null==(m=(f=this.options).onBack)?void 0:m.call(f))??!1}),"frame.themeChanged"!==t.type||"dark"!==T.mode&&"light"!==T.mode||null==(g=(y=this.options).onTheme)||g.call(y,T),"frame.localeChanged"===t.type&&"string"==typeof T.locale&&(null==(w=(v=this.options).onLocale)||w.call(v,T.locale)),"frame.focusChanged"===t.type&&this.focused!==(!0===T.focused)&&(this.focused=!0===T.focused,null==(k=(b=this.options).onFocus)||k.call(b,this.focused))}catch{"frame.open"===t.type&&I({accepted:!1,fallback:"preview"}),"frame.beforeClose"===t.type&&I({decision:"deny"})}}send(e,t){this.init&&this.channel.post(d(e,t))}setTitle(e,t=!1){const n=JSON.stringify([e,t]);this.init&&n!==this.title&&(this.title=n,this.send("window.setTitle",{title:e,dirty:t}))}requestClose(){this.send("window.requestClose",{})}setHeader(e){this.header={...this.header,...e},this.send("header.set",e)}openApp(e){const n=t.readAppOpenRequest(e);if(!n)return Promise.resolve({ok:!1,code:"denied"});if(this.init){if(!this.init.shellCapabilities.includes("app.open"))return Promise.resolve({ok:!1,code:"unsupported"});const e=crypto.randomUUID();return new Promise((t=>{const r=n=>{clearTimeout(i),this.appOpens.delete(e),t(n)},i=setTimeout((()=>r({ok:!1,code:"unsupported"})),3e4);this.appOpens.set(e,r),this.channel.post(d("app.open",n,{id:e}))}))}return!this.options.systemOrigin||n.zone?Promise.resolve({ok:!1,code:"unsupported"}):(window.open(t.systemOpenAppUrl(this.options.systemOrigin,n),"_blank","noopener"),Promise.resolve({ok:!0}))}openContent(t,n="default",r={}){const i=r.hints??{};return this.init?(this.send("content.open",{request:t,target:n,newWindow:!0===r.newWindow,hints:i}),!0):!!this.options.systemOrigin&&(window.open(e.systemOpenUrl(this.options.systemOrigin,{request:t,target:n,hints:i,from:this.options.appId}),"_blank","noopener"),!0)}selectContent(t={},n={}){var r,i,s;const o=null==(r=this.init)?void 0:r.shellCapabilities.includes(e.SELECT_DIALOG_PATH);if(this.init&&(o||!this.native)){if(!o)return Promise.reject(new e.SystemDialogError("unsupported"));if(this.dialogs.size)return Promise.reject(new e.SystemDialogError("busy"));const n=crypto.randomUUID();return new Promise(((r,i)=>{this.dialogs.set(n,{resolve:r,reject:i,allowLocal:!0===t.allowLocal}),this.channel.post(d("sysdlg.open",{path:e.SELECT_DIALOG_PATH,params:t},{id:n}))}))}if(!this.options.systemOrigin)return Promise.reject(new e.SystemDialogError("unsupported"));const a=this.embedAbort=new AbortController;return null==(i=n.signal)||i.addEventListener("abort",(()=>a.abort()),{once:!0}),(null==(s=n.signal)?void 0:s.aborted)&&a.abort(),J(this.options.systemOrigin,t,{...n,signal:a.signal})}get transferAvailable(){return!!this.transferLink}connectTransfer(){var e,t,n;if(!this.options.transfer||this.transferLink||!(null==(e=this.init)?void 0:e.shellCapabilities.includes(p)))return;let r;if(this.native)r={documentId:this.documentId,post:e=>this.channel.post(e),close:()=>{}},this.channel.post(d("transfer.connect",{documentId:this.documentId}));else{const e=new MessageChannel;r=F(this.documentId,e.port1,(e=>{this.receiveTransfer(e,r)})),this.channel.post(d("transfer.connect",{documentId:this.documentId}),[e.port2])}this.transferLink=r;try{null==(n=(t=this.options.transfer).onAvailable)||n.call(t,!0)}catch{}}async receiveTransfer(e,t){var n;if(!c(e)||this.transferLink!==t)return;const r=e.payload;if(e.replyTo){const t=this.transferPending.get(e.replyTo);return void(t&&"transfer.offerResult"===e.type&&(clearTimeout(t.timer),this.transferPending.delete(e.replyTo),t.resolve(e.payload)))}const i=this.options.transfer??{};if("transfer.cancel"===e.type)return void(L(r.operationId)&&(null==(n=i.onCancel)||n.call(i,r.operationId)));if("string"!=typeof e.id)return;const s=n=>{this.transferLink===t&&t.post(d(e.type+"Result",n,{replyTo:e.id}))};try{if("transfer.probe"===e.type){const e=U(r);if(!e||!i.onProbe)return s({ok:!1,code:"unsupported"});const t=await i.onProbe(e);return s({ok:!0,answer:t?j(t,e):null})}if("transfer.read"===e.type){const e=q(r);return e&&i.onRead?s({ok:!0,items:W(await i.onRead(e),e,{files:!this.native})}):s({ok:!1,code:"unsupported"})}if("transfer.deliver"===e.type){const e=$(r);if(!e||!i.onDeliver)return s({ok:!1,code:"unsupported"});let t=this.deliveries.get(e.operationId);if(!t){const n=i.onDeliver;t=Promise.resolve().then((()=>n(e))),this.deliveries.set(e.operationId,t),t.catch((()=>this.deliveries.delete(e.operationId)));for(const e of[...this.deliveries.keys()].slice(0,Math.max(0,this.deliveries.size-64)))this.deliveries.delete(e)}return s({ok:!0,result:N(await t,e.items)})}if("transfer.status"===e.type){if(!L(r.operationId))return s({ok:!1,code:"unsupported"});const e=this.deliveries.get(r.operationId);return s({ok:!0,result:e?await e:null})}s({ok:!1,code:"unsupported"})}catch(o){(e=>{s({ok:!1,code:e instanceof u&&"timeout"!==e.code?e.code:"denied"})})(o)}}offerTransfer(e){const t=this.transferLink;if(!t)return Promise.resolve({ok:!1,code:"unsupported"});const n=M({...e,offerId:r.newOfferId(),generation:e.generation??++this.generation});if(!n)return Promise.resolve({ok:!1,code:"unsupported"});const i=crypto.randomUUID();return new Promise((e=>{const r=setTimeout((()=>{this.transferPending.delete(i),e({ok:!1,code:"unsupported"})}),k);this.transferPending.set(i,{timer:r,resolve:t=>{const r=O(t)?t:{};e(!0===r.ok?{ok:!0,offerId:n.offerId}:{ok:!1,code:_(r.code)})}}),t.post(d("transfer.offer",n,{id:i}))}))}withdrawTransfer(e){var t;L(e)&&(null==(t=this.transferLink)||t.post(d("transfer.cancel",{offerId:e})))}dispose(){var t,n;clearInterval(this.helloTimer),clearTimeout(this.helloDeadline),this.detach(),null==(t=this.transferLink)||t.close(),this.transferLink=void 0,this.transferPending.forEach((e=>{clearTimeout(e.timer),e.resolve({ok:!1,code:"stale"})})),this.transferPending.clear(),this.appOpens.forEach((e=>e({ok:!1,code:"unsupported"}))),this.dialogs.forEach((t=>t.reject(new e.SystemDialogError("closed")))),this.dialogs.clear(),null==(n=this.embedAbort)||n.abort()}},exports.AppFrameHost=class{constructor(e){this.ready=!1,this.capabilities=[],this.header={},this.pending=new Map,this.opens=new Map,this.dialogOpen=!1,this.transferPending=new Map,this.callbacks=e,this.framed=!e.transport,this.init=e.transport?{...e.init,nonce:""}:e.init,this.channel=e.transport??l(e.target,e.origin),this.detach=this.channel.onMessage(((e,t)=>this.receive(e,t)))}get transferDocument(){var e;return null==(e=this.transferLink)?void 0:e.documentId}limited(e){const t=(this.opens.get(e)??[]).filter((e=>e>Date.now()-1e4));return this.opens.set(e,t),t.length>=5||(t.push(Date.now()),!1)}async appOpen(e,n){const r=t=>{this.ready&&this.channel.post(d("app.openResult",t,{replyTo:e}))};if(!this.callbacks.onAppOpen)return r({ok:!1,code:"unsupported"});const i=t.readAppOpenRequest(n);if(!i||this.limited("app.open"))return r({ok:!1,code:"denied"});try{r(await this.callbacks.onAppOpen(i))}catch{r({ok:!1,code:"denied"})}}async systemDialog(t,n,r){const i=e=>{this.ready&&this.channel.post(d("sysdlg.openResult",e,{replyTo:t}))};if(!this.callbacks.onSystemDialog||"string"!=typeof n)return i({ok:!1,code:"unsupported"});if(this.dialogOpen)return i({ok:!1,code:"busy"});this.dialogOpen=!0;try{i(await this.callbacks.onSystemDialog(n,r))}catch(s){i({ok:!1,code:s instanceof e.SystemDialogError?s.code:"closed"})}finally{this.dialogOpen=!1}}receive(t,n){var r,i,s,o,l,d,p,h,u,f,m,y;if(!c(t))return;const g=t.payload;if("frame.hello"===t.type){if(!Array.isArray(g.appCapabilities))return;if(this.framed){if(g.nonce!==this.init.nonce)return}else{if("string"!=typeof g.nonce||!g.nonce||g.nonce.length>128)return;g.nonce!==this.init.nonce&&(this.failPending("App frame reloaded"),this.dropTransfer()),this.init={...this.init,nonce:g.nonce}}return this.transferLink&&this.transferLink.documentId!==g.documentId&&this.dropTransfer(),this.ready=!0,this.capabilities=g.appCapabilities.filter((e=>"string"==typeof e)),this.send("frame.init",this.init),void 0!==this.focused&&this.send("frame.focusChanged",{focused:this.focused}),Object.keys(this.header).length&&(this.header={},null==(i=(r=this.callbacks).onHeader)||i.call(r,{})),void(null==(o=(s=this.callbacks).onReady)||o.call(s))}if(this.ready)if("transfer.connect"!==t.type){if(t.type.startsWith("transfer."))!this.framed&&this.transferLink&&this.receiveTransfer(t,this.transferLink);else if(t.replyTo){const e=this.pending.get(t.replyTo);e&&t.type===e.type+"Result"&&(clearTimeout(e.timer),this.pending.delete(t.replyTo),e.resolve(t.payload))}else if("window.setTitle"===t.type&&"string"==typeof g.title&&(null==(d=(l=this.callbacks).onTitle)||d.call(l,g.title.slice(0,256),!0===g.dirty)),"window.requestClose"===t.type&&(null==(h=(p=this.callbacks).onRequestClose)||h.call(p)),"header.set"===t.type&&(this.header={...this.header,...a(g)},null==(f=(u=this.callbacks).onHeader)||f.call(u,this.header)),"app.open"===t.type&&"string"==typeof t.id&&this.appOpen(t.id,g),"sysdlg.open"===t.type&&"string"==typeof t.id&&this.systemDialog(t.id,g.path,g.params),"content.open"===t.type&&("default"===g.target||"preview"===g.target||"chooser"===g.target)){const t={...g.request,requestId:crypto.randomUUID()};if(!e.isOpenRequest(t)||this.limited("content.open"))return;null==(y=(m=this.callbacks).onContentOpen)||y.call(m,t,g.target,{newWindow:!0===g.newWindow,hints:e.readContentHints(g.hints)})}}else this.connectTransfer(g,n)}update(e){this.init={...this.init,...e}}setFocused(e){this.focused!==e&&(this.focused=e,this.send("frame.focusChanged",{focused:e}))}headerEvent(e){this.send("header.event",e)}send(e,t){this.ready&&this.channel.post(d(e,t))}request(e,t,n=3e3){if(!this.ready)return Promise.reject(new Error("App frame is not ready"));const r=crypto.randomUUID();return new Promise(((i,s)=>{const o=setTimeout((()=>{this.pending.delete(r),s(new Error("App frame timed out"))}),n);this.pending.set(r,{resolve:i,reject:s,timer:o,type:e}),this.channel.post(d(e,t,{id:r}))}))}async open(e){return this.capabilities.includes("open")?await this.request("frame.open",{request:e}):{accepted:!1}}async beforeClose(e="user"){if(!this.ready||!this.capabilities.includes("beforeClose"))return"allow";const t=await this.request("frame.beforeClose",{reason:e});return"allow"===t.decision||"pending"===t.decision?t.decision:"deny"}async back(){return!!this.capabilities.includes("back")&&!0===(await this.request("frame.back",{})).handled}failPending(e){this.pending.forEach((t=>{clearTimeout(t.timer),t.reject(new Error(e))})),this.pending.clear()}connectTransfer(e,t){var n,r;const i=1===(null==t?void 0:t.length)?t[0]:void 0,s=()=>null==t?void 0:t.forEach((e=>e.close()));if(!this.init.shellCapabilities.includes(p)||!this.capabilities.includes(p))return s();if("string"!=typeof e.documentId||!m.test(e.documentId)||(this.framed?!i:null==t?void 0:t.length))return s();this.dropTransfer();const o=e.documentId;let a;a=i?F(o,i,(e=>{this.transferLink===a&&this.receiveTransfer(e,a)})):{documentId:o,post:e=>this.channel.post(e),close:()=>{}},this.transferLink=a,null==(r=(n=this.callbacks).onTransferConnect)||r.call(n,o)}dropTransfer(){var e,t;const n=this.transferLink;n&&(this.transferLink=void 0,n.close(),this.transferPending.forEach((e=>{clearTimeout(e.timer),e.reject(new u("stale","The App document changed"))})),this.transferPending.clear(),null==(t=(e=this.callbacks).onTransferDisconnect)||t.call(e,n.documentId))}receiveTransfer(e,t){var n,r;if(!c(e))return;const i=e.payload;if(e.replyTo){const t=this.transferPending.get(e.replyTo);t&&e.type===t.type+"Result"&&(clearTimeout(t.timer),this.transferPending.delete(e.replyTo),t.resolve(e.payload))}else{if("transfer.offer"===e.type&&"string"==typeof e.id){const n=e.id,r=e=>{this.transferLink===t&&t.post(d("transfer.offerResult",e,{replyTo:n}))},s=M(i);return s&&this.callbacks.onTransferOffer?void Promise.resolve().then((()=>this.callbacks.onTransferOffer(s,t.documentId))).then((e=>r(e.ok?{ok:!0}:{ok:!1,code:_(e.code)})),(()=>r({ok:!1,code:"denied"}))):r({ok:!1,code:"unsupported"})}"transfer.cancel"===e.type&&L(i.offerId)&&(null==(r=(n=this.callbacks).onTransferWithdraw)||r.call(n,i.offerId,t.documentId))}}transferRequest(e,t,n){const r=this.transferLink;if(!this.ready||!r)return Promise.reject(new u("stale","No transfer link"));const i=crypto.randomUUID();return new Promise(((s,o)=>{const a=setTimeout((()=>{this.transferPending.delete(i),o(new u("timeout"))}),n);this.transferPending.set(i,{resolve:s,reject:o,timer:a,type:e}),r.post(d(e,t,{id:i}))})).then((e=>{const t=O(e)?e:{};if(!0!==t.ok)throw new u(_(t.code));return t}))}async transferProbe(e,t=T){const n=await this.transferRequest("transfer.probe",e,t);return null===n.answer?null:j(n.answer,e)}async transferRead(e,t=I){return W((await this.transferRequest("transfer.read",e,t)).items,e,{files:this.framed})}async transferDeliver(e,t=E){if(!this.framed&&e.items.some((e=>"files"===e.format)))throw new u("unsupported","Local files cannot cross the bridge");const n=N((await this.transferRequest("transfer.deliver",e,t)).result,e.items);if(!n)throw new u("unsupported","Invalid delivery result");return n}async transferStatus(e,t,n=A){const r=await this.transferRequest("transfer.status",{operationId:e},n);return null===r.result?null:N(r.result,t)??null}transferCancel(e){var t;null==(t=this.transferLink)||t.post(d("transfer.cancel",{operationId:e}))}dispose(){this.detach(),this.failPending("App frame disposed"),this.dropTransfer(),this.ready=!1}},exports.CONVERSATION_EMBED_ERROR_CODES=te,exports.CONVERSATION_EMBED_PATH=ee,exports.ConversationEmbed=class{constructor(e){this.options=e,this.nonce=crypto.randomUUID(),this.listener=e=>this.receive(e),this.ready=!1,this.outbox=[],this.origin=new URL(e.systemOrigin).origin,this.init=e.init,this.url=`${this.origin}${ee}#bce=${this.nonce}&po=${encodeURIComponent(window.location.origin)}`,window.addEventListener("message",this.listener)}post(e,t){var n,r;null==(r=null==(n=this.options.frame())?void 0:n.contentWindow)||r.postMessage(z(e,t,Q),this.origin)}receive(e){var t,n,r,i,s,o,a;if(e.origin!==this.origin||e.source!==(null==(t=this.options.frame())?void 0:t.contentWindow)||!X(e.data,Q))return;const{type:l,payload:d}=e.data;if("embed.hello"===l){if(d.nonce!==this.nonce)return;this.ready=!0,this.post("embed.init",{...this.init,nonce:this.nonce});const e=this.outbox;return this.outbox=[],void e.forEach((e=>this.post("embed.send",e)))}"embed.state"!==l||"loading"!==d.status&&"ready"!==d.status&&"error"!==d.status||null==(r=(n=this.options).onState)||r.call(n,{status:d.status,sessionId:"string"==typeof d.sessionId?d.sessionId.slice(0,512):void 0,error:"string"==typeof d.error?d.error.slice(0,128):void 0}),"embed.turn"===l&&ne.includes(d.mode)&&(null==(s=(i=this.options).onTurn)||s.call(i,d.mode)),"embed.error"===l&&te.includes(d.code)&&(null==(a=(o=this.options).onError)||a.call(o,d.code))}update(e){this.init={...this.init,...e},this.ready&&this.post("embed.update",e)}send(e){var t;const n={text:e.text,...(null==(t=e.attachments)?void 0:t.length)?{attachments:e.attachments}:{}};this.ready?this.post("embed.send",n):this.outbox.push(n)}dispose(){window.removeEventListener("message",this.listener),this.outbox=[]}},exports.ConversationEmbedHost=class{constructor(e){this.options=e,this.ready=!1,this.listener=e=>this.receive(e);const t=new URLSearchParams(window.location.hash.slice(1));this.nonce=t.get("bce");let n=null;try{n=new URL(t.get("po")??"").origin}catch{}if(this.parentOrigin=window.parent!==window&&this.nonce&&n&&e.accept(n)?n:null,!this.parentOrigin)return;window.addEventListener("message",this.listener);const r=()=>window.parent.postMessage(z("embed.hello",{nonce:this.nonce},Q),this.parentOrigin);r(),this.hello=setInterval((()=>{this.ready||r()}),250)}receive(t){var n,r,i,s;if(t.source!==window.parent||t.origin!==this.parentOrigin||!X(t.data,Q))return;const{type:o,payload:a}=t.data;if("embed.init"===o){if(this.ready||a.nonce!==this.nonce||"string"!=typeof a.locale)return;return this.ready=!0,clearInterval(this.hello),void this.options.onInit({nonce:String(a.nonce),target:a.target,theme:"dark"===a.theme?"dark":"light",locale:a.locale,..."string"==typeof a.placeholder?{placeholder:a.placeholder.slice(0,200)}:{}})}if(this.ready){if("embed.update"===o){const e={};"dark"!==a.theme&&"light"!==a.theme||(e.theme=a.theme),"string"==typeof a.locale&&(e.locale=a.locale),null==(r=(n=this.options).onUpdate)||r.call(n,e)}if("embed.send"===o){const t=(t=>"string"!=typeof t.text||t.text.length>65536?null:void 0===t.attachments?{text:t.text}:!Array.isArray(t.attachments)||t.attachments.length>32||!t.attachments.every(e.isTransferableRef)?null:{text:t.text,attachments:t.attachments})(a);t?null==(s=(i=this.options).onSend)||s.call(i,t):this.error("invalid_params")}}}post(e,t){this.ready&&this.parentOrigin&&window.parent.postMessage(z(e,t,Q),this.parentOrigin)}state(e){this.post("embed.state",e)}turn(e){this.post("embed.turn",{mode:e})}error(e){this.post("embed.error",{code:e})}dispose(){clearInterval(this.hello),window.removeEventListener("message",this.listener)}},exports.PREVIEW_EMBED_PATH=V,exports.PreviewEmbed=class{constructor(e){this.options=e,this.nonce=crypto.randomUUID(),this.listener=e=>this.receive(e),this.ready=!1,this.origin=new URL(e.systemOrigin).origin,this.init=e.init,this.url=`${this.origin}${V}#bpe=${this.nonce}&po=${encodeURIComponent(window.location.origin)}`,window.addEventListener("message",this.listener)}post(e,t){var n,r;null==(r=null==(n=this.options.frame())?void 0:n.contentWindow)||r.postMessage(z(e,t),this.origin)}receive(t){var n,r,i,s,o,a,l;if(t.origin!==this.origin||t.source!==(null==(n=this.options.frame())?void 0:n.contentWindow)||!X(t.data))return;const{type:d,payload:c}=t.data;if("embed.hello"!==d){if("embed.state"===d&&("loading"===c.status||"ready"===c.status||"error"===c.status)){const e=c.error;null==(i=(r=this.options).onState)||i.call(r,{status:c.status,error:e&&"string"==typeof e.kind&&"string"==typeof e.code?{kind:e.kind,code:e.code}:void 0,title:"string"==typeof c.title?c.title.slice(0,256):void 0,mediaType:"string"==typeof c.mediaType?c.mediaType.slice(0,128):void 0})}if("embed.openWith"===d){const t=c.request;t&&e.isTransferableRef(t.source)&&(void 0===t.session||e.isTransferableSession(t.session))&&(null==(o=(s=this.options).onOpenWith)||o.call(s,{request:{source:t.source,session:t.session},hints:e.readContentHints(c.hints)}))}"embed.exit"===d&&(null==(l=(a=this.options).onExit)||l.call(a))}else c.nonce===this.nonce&&(this.ready=!0,this.post("embed.init",{...this.init,nonce:this.nonce}))}update(e){this.init={...this.init,...e},this.ready&&this.post("embed.update",e)}dispose(){window.removeEventListener("message",this.listener)}},exports.PreviewEmbedHost=class{constructor(e){this.options=e,this.ready=!1,this.listener=e=>this.receive(e);const t=new URLSearchParams(window.location.hash.slice(1));this.nonce=t.get("bpe");let n=null;try{n=new URL(t.get("po")??"").origin}catch{}if(this.parentOrigin=window.parent!==window&&this.nonce&&n&&e.accept(n)?n:null,!this.parentOrigin)return;window.addEventListener("message",this.listener);const r=()=>window.parent.postMessage(z("embed.hello",{nonce:this.nonce}),this.parentOrigin);r(),this.hello=setInterval((()=>{this.ready||r()}),250)}receive(t){var n,r;if(t.source!==window.parent||t.origin!==this.parentOrigin||!X(t.data))return;const{type:i,payload:s}=t.data;if("embed.init"===i){if(s.nonce!==this.nonce||(o=s.source,!(e.isTransferableRef(o)||o&&"object"==typeof o&&"blob"===o.kind&&"undefined"!=typeof Blob&&o.blob instanceof Blob&&"string"==typeof o.name))||void 0!==s.session&&!e.isTransferableSession(s.session)||"string"!=typeof s.locale)return;return this.ready=!0,clearInterval(this.hello),void this.options.onInit({nonce:String(s.nonce),source:s.source,session:s.session,theme:"dark"===s.theme?"dark":"light",locale:s.locale})}var o;if("embed.update"===i&&this.ready){const e={};"dark"!==s.theme&&"light"!==s.theme||(e.theme=s.theme),"string"==typeof s.locale&&(e.locale=s.locale),null==(r=(n=this.options).onUpdate)||r.call(n,e)}}post(e,t){this.ready&&this.parentOrigin&&window.parent.postMessage(z(e,t),this.parentOrigin)}state(e){this.post("embed.state",e)}openWith(e){this.post("embed.openWith",e)}exit(){this.post("embed.exit",{})}dispose(){clearInterval(this.hello),window.removeEventListener("message",this.listener)}},exports.SELECT_EMBED_PATH=G,exports.SelectEmbedHost=class{constructor(e){this.options=e,this.ready=!1,this.listener=e=>this.receive(e);const t=new URLSearchParams(window.location.hash.slice(1));this.nonce=t.get("bse");let n=null;try{n=new URL(t.get("po")??"").origin}catch{}if(this.parentOrigin=window.parent!==window&&this.nonce&&n&&e.accept(n)?n:null,!this.parentOrigin)return;window.addEventListener("message",this.listener);const r=()=>window.parent.postMessage(z("embed.hello",{nonce:this.nonce},Z),this.parentOrigin);r(),this.hello=setInterval((()=>{this.ready||r()}),250)}receive(e){if(e.source!==window.parent||e.origin!==this.parentOrigin||!X(e.data,Z))return;const{type:t,payload:n}=e.data;"embed.init"!==t||this.ready||n.nonce!==this.nonce||"string"!=typeof n.locale||(this.ready=!0,clearInterval(this.hello),this.options.onInit({nonce:String(n.nonce),params:n.params,theme:"dark"===n.theme?"dark":"light",locale:n.locale}))}post(e,t){this.ready&&this.parentOrigin&&window.parent.postMessage(z(e,t,Z),this.parentOrigin)}result(e){this.post("embed.result",{result:e})}error(e){this.post("embed.error",{code:e})}dispose(){clearInterval(this.hello),window.removeEventListener("message",this.listener)}},exports.TRANSFER_CAPABILITY=p,exports.TRANSFER_ERROR_CODES=h,exports.TransferError=u,exports.appFrameName=function(e){return H+e},exports.embedderOrigin=function(e){var t;if(window.parent===window)return n.getBuckyApi()&&e(window.location.origin)?window.location.origin:null;const r=[null==(t=window.location.ancestorOrigins)?void 0:t[0],document.referrer];for(const n of r)if(n)try{const t=new URL(n).origin;if(e(t))return t}catch{}return null},exports.openSelectEmbed=J,exports.originInZone=(e,t)=>{try{const n=new URL(e);return n.protocol===window.location.protocol&&(n.hostname===t||n.hostname.endsWith(`.${t}`))}catch{return!1}},exports.readTransferDelivery=$,exports.readTransferDeliveryResult=N,exports.readTransferOffer=M,exports.readTransferProbe=U,exports.readTransferProbeAnswer=j,exports.readTransferReadRequest=q,exports.readTransferValue=K;
|
|
2
2
|
//# sourceMappingURL=app-frame.cjs.map
|