@trimjs/web-app 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,7 +52,6 @@ await app.setExitPageTips({
52
52
  });
53
53
 
54
54
  const files = await app.pickFile({
55
- multiple: true,
56
55
  accept: ['.pdf', '.doc', '.docx'],
57
56
  title: 'Select files',
58
57
  });
@@ -238,7 +237,6 @@ Opens the host file picker.
238
237
 
239
238
  ```ts
240
239
  const files = await app.pickFile({
241
- multiple: true,
242
240
  accept: ['.pdf', '.jpg', '.jpeg', '.png', '.gif', '.webp'],
243
241
  sidebarGroup: ['myFiles', 'external'],
244
242
  title: 'Select files',
@@ -267,7 +265,6 @@ Common `FilePickerParams` fields:
267
265
 
268
266
  | Field | Type | Description |
269
267
  | --------------- | ---------- | --------------------------------------------------- |
270
- | `multiple` | `boolean` | Allows selecting multiple files. |
271
268
  | `directory` | `boolean` | Allows selecting folders instead of files. |
272
269
  | `accept` | `string[]` | Accepted file extensions, each prefixed with `.`. |
273
270
  | `sidebarGroup` | `string[]` | Sidebar groups to show, in display order. |
@@ -330,6 +327,7 @@ openAppAuth(
330
327
  ```
331
328
 
332
329
  Starts an App Auth route flow. The returned string is the URL that was opened.
330
+ This route-based flow is only available on web platforms. Calling `openAppAuth()` in a mobile app throws without opening a URL.
333
331
 
334
332
  ```ts
335
333
  await app.openAppAuth('pickFile', {
@@ -577,3 +575,18 @@ For route-based App Auth flows, use `openAppAuth()` to start the flow and `parse
577
575
  ## License
578
576
 
579
577
  MIT
578
+ ## Desktop 官方应用会话凭据(0.5.0 候选)
579
+
580
+ `getHostCapabilities()` 返回宿主运行环境和协议能力,不代表应用已获授权。
581
+ `getSessionCredentials()` 无授权参数,仅支持 Desktop 中通过宿主核验的官方内嵌应用。
582
+ 每次调用读取所属账号的当前会话,返回 `{ code: 0, msg: '', data: { secret, token? } }`。
583
+ 应用应仅在当前请求中使用结果,不缓存、不打印、不写入 localStorage。
584
+
585
+ 失败返回 `code: 1`、`data: null` 和稳定 `error`:`NOT_SUPPORTED`、`FORBIDDEN`、
586
+ `SESSION_UNAVAILABLE` 或 `CONNECTION_CLOSED`。握手及调用超时有界;Desktop 失败不得回退
587
+ 到浏览器存储。普通 Web 继续使用原有存储方案,手机仍使用 `getUserMessage`。
588
+ 认证和静默续期由 Desktop 负责,SDK 不新增自动保存、重试或登录提示。
589
+
590
+ 本能力需要新版 Desktop 宿主;旧宿主、独立浏览器和手机不提供本能力。
591
+ 旧 SDK 可继续使用新版宿主已有方法,但不会自动获得新的保存能力。
592
+ 0.5.0 当前为本地候选版本,需在发布后再供下游正式安装。
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,r||"default");if("object"!=e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==e(r)?r:r+""}function r(e,r,n){return(r=t(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var n=new class{constructor(){r(this,"debug",!1)}setDebug(e){this.debug=e}isDebug(){return this.debug}log(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.log("[Trim App]",...t)}}warn(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.warn("[Trim App]",...t)}}error(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.error("[Trim App]",...t)}}info(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.info("[Trim App]",...t)}}};var i=()=>function(e){const t=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,r={};let n;for(;null!==(n=t.exec(e));)n[1]&&(r.fnOSVersion=n[1]),n[2]&&(r.fnAppType=n[2]),n[3]&&(r.fnAppVersion=n[3]);return r}(navigator.userAgent).fnAppVersion;function o(e,t,r,n,i,o,s){try{var l=e[o](s),a=l.value}catch(e){return void r(e)}l.done?t(a):Promise.resolve(a).then(n,i)}function s(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var s=e.apply(t,r);function l(e){o(s,n,i,l,a,"next",e)}function a(e){o(s,n,i,l,a,"throw",e)}l(void 0)})}}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var u=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{u=!0});var p=/(iPad|iPhone|iPod|Macintosh|Mac OS X)/i.test(navigator.userAgent),c=function(){var e=s(function*(e,t){for(var r=arguments.length,i=new Array(r>2?r-2:0),o=2;o<r;o++)i[o-2]=arguments[o];n.log(`callHandler: ${t}, params: ${i.map(e=>String(e)).join(", ")}`);const s=yield e.callHandler(t,...i);if(s)try{const e=JSON.parse(s);n.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return n.log(`appMessage: ${JSON.stringify(t)}`),t}catch(l){return n.error(`error: ${l}`),null}return null});return function(t,r){return e.apply(this,arguments)}}(),d=new Map,f=class{constructor(e){r(this,"subscribeFn",void 0),this.subscribeFn=e}subscribe(e,t,r){var n;const i="function"==typeof e?{next:e,error:t,complete:r}:null!=e?e:{};let o=!1;const s=null!==(n=this.subscribeFn({next:e=>{var t;o||(null===(t=i.next)||void 0===t||t.call(i,e))},error:e=>{var t;o||(o=!0,null===(t=i.error)||void 0===t||t.call(i,e))},complete:()=>{var e;o||(o=!0,null===(e=i.complete)||void 0===e||e.call(i))}}))&&void 0!==n?n:()=>{};return{unsubscribe:()=>{o||(o=!0,s())}}}},h=new Map;function v(){window._flutter_onAppObservableQueryResult=e=>{n.log("_flutter_onAppObservableQueryResult",e);const t=function(e){var t,r;const n="string"==typeof e?JSON.parse(e):e,i=null!==(t=n.reqid)&&void 0!==t?t:n.reqId;return a(a({},n),{},{reqId:null!==(r=n.reqId)&&void 0!==r?r:i,reqid:i})}(e),r=h.get(t.reqId);if(r)if(t.result&&"doing"!==t.result){if("succ"===t.result)return r.next(t),r.complete(),void h.delete(t.reqId);r.error(t),h.delete(t.reqId)}else r.next(t);else n.log("_flutter_onAppObservableQueryResult observer not found",t)}}function y(){return(y=s(function*(e,t){return new Promise((r,i)=>{null==e||e.callHandler("openFolder",JSON.stringify(t)).then(e=>{if(n.log("pickFilePromise callback registered",{reqId:e,params:t}),e){d.set(e,function(e){r(e.result)})}else i(new Error("openFolder failed"))})})})).apply(this,arguments)}i()&&(window.fnAppMessage=e=>{n.log("app-message",e);const t=JSON.parse(e),r=d.get(t.reqId);r&&(r(t),d.delete(t.reqId))}),i()&&v();var g=function(e){return e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e}({}),b=function(e){return e.Fulfilled="fulfilled",e.Rejected="rejected",e}({}),m=function(e){return e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e}({}),w=function(e){return e.DataCloneError="DataCloneError",e}({}),A=function(e){return e.Message="message",e}({}),S=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),P=(e,t,r)=>{let{localName:n,local:i,remote:o,originForSending:s,originForReceiving:l}=e,a=!1,u=e=>{if(e.source!==o||e.data.penpal!==g.Call)return;if("*"!==l&&e.origin!==l)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${l}`);let{methodName:i,args:u,id:p}=e.data;r(`${n}: Received ${i}() call`);let c=e=>t=>{if(r(`${n}: Sending ${i}() reply`),a)return void r(`${n}: Unable to send ${i}() reply due to destroyed connection`);let l={penpal:g.Reply,id:p,resolution:e,returnValue:t};e===b.Rejected&&t instanceof Error&&(l.returnValue=S(t),l.returnValueIsError=!0);try{o.postMessage(l,s)}catch(e){let r=e instanceof Error?e:Error(String(e));if(r.name===w.DataCloneError){let e={penpal:g.Reply,id:p,resolution:b.Rejected,returnValue:S(r),returnValueIsError:!0};o.postMessage(e,s)}throw e}};new Promise(e=>e(t[i].apply(t,u))).then(c(b.Fulfilled),c(b.Rejected))};return i.addEventListener(A.Message,u),()=>{a=!0,i.removeEventListener(A.Message,u)}},O=0,M=()=>++O,E=e=>e?e.split("."):[],F=(e,t,r)=>{let n=E(t);return n.reduce((e,t,i)=>(void 0===e[t]&&(e[t]={}),i===n.length-1&&(e[t]=r),e[t]),e),e},$=(e,t)=>{let r={};return Object.keys(e).forEach(n=>{let i=e[n],o=((e,t)=>{let r=E(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof i&&Object.assign(r,$(i,o)),"function"==typeof i&&(r[o]=i)}),r},_=(e,t,r,n,i)=>{let{localName:o,local:s,remote:l,originForSending:a,originForReceiving:u}=t,p=!1;i(`${o}: Connecting call sender`);let c=e=>(...t)=>{let r;i(`${o}: Sending ${e}() call`);try{l.closed&&(r=!0)}catch(g){r=!0}if(r&&n(),p){let t=Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=m.ConnectionDestroyed,t}return new Promise((r,n)=>{let p=M(),c=t=>{if(t.source!==l||t.data.penpal!==g.Reply||t.data.id!==p)return;if("*"!==u&&t.origin!==u)return void i(`${o} received message from origin ${t.origin} which did not match expected origin ${u}`);let a=t.data;i(`${o}: Received ${e}() reply`),s.removeEventListener(A.Message,c);let d=a.returnValue;a.returnValueIsError&&(d=(e=>{let t=Error();return Object.assign(t,e),t})(d)),(a.resolution===b.Fulfilled?r:n)(d)};s.addEventListener(A.Message,c);let d={penpal:g.Call,id:p,methodName:e,args:t};l.postMessage(d,a)})},d=r.reduce((e,t)=>(e[t]=c(t),e),{});return Object.assign(e,(e=>{let t={};for(let r in e)F(t,r,e[r]);return t})(d)),()=>{p=!0}},j=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout(()=>{let r=Error(`Connection timed out after ${e}ms`);r.code=m.ConnectionTimeout,t(r)},e)),()=>{clearTimeout(r)}};function k(e){return k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},k(e)}function W(e){var t=function(e,t){if("object"!=k(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=k(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==k(t)?t:t+""}function x(e,t,r){return(t=W(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function q(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function T(e){for(var t=1;t<arguments.length;t++){var r=null==arguments[t]?{}:arguments[t];t%2?q(Object(r),!0).forEach(function(t){x(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):q(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var N=(e,t,r,n,i)=>{let{destroy:o,onDestroy:s}=n;return n=>{if(!(e instanceof RegExp?e.test(n.origin):"*"===e||e===n.origin))return void i(`Child: Handshake - Received SYN-ACK from origin ${n.origin} which did not match expected origin ${e}`);i("Child: Handshake - Received SYN-ACK, responding with ACK");let l="null"===n.origin?"*":n.origin,a={penpal:g.Ack,methodNames:Object.keys(t),config:r};window.parent.postMessage(a,l);let u={localName:"Child",local:window,remote:window.parent,originForSending:l,originForReceiving:n.origin},p=P(u,t,i);s(p);let c={},d=_(c,u,n.data.methodNames,o,i);return s(d),c}};function I(e,t){var r;null==(r=console)||r.warn(`[fnApp warn]: ${e}`,t)}function C(e,t){var r;null==(r=console)||r.error(`[fnApp error]: ${e}`,t)}var V="_fn_all_event",U="事件订阅数量为空";function R(e){return R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},R(e)}function D(e){var t=function(e,t){if("object"!=R(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=R(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==R(t)?t:t+""}function z(e,t,r){return(t=D(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var L=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map,J=class{constructor(e,t){z(this,"id",void 0),z(this,"appName",void 0),z(this,"eventObj",void 0),z(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),L.get(this.id)||L.set(this.id,{}),this.eventObj=L.get(this.id)}$on(e,t){let r=this.eventObj[e];return r?(r.includes(t)||r.push(t),this):(this.eventObj[e]=[t],this)}$onAll(e){return this.$on(V,e)}$once(e,t){t.$__once=!0,this.$on(e,t)}$off(e,t){let r=this.eventObj[e];if(!e||!r||!r.length)return I(`${e} ${U}`),this;let n,i=r.length;for(;i--;)if(n=r[i],n===t){r.splice(i,1);break}return this}$offAll(e){return this.$off(V,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let r=0;return L.forEach(n=>{if(n[e])for(let i=n[e].length-1;i>=0;i--){r++;let o=n[e][i];o.$__once&&n[e].splice(i,1);try{o(...t)}catch(e){C(e)}}if(n._fn_all_event)for(let i=n[V].length-1;i>=0;i--){r++;let o=n[V][i];o.$__once&&n[V].splice(i,1);try{o(...t)}catch(e){C(e)}}}),(!e||0===r)&&I(`${e} ${U}`),this}$clear(){var e;let t=null==(e=L.get(this.id))?{}:e;return Object.keys(t).forEach(e=>delete t[e]),this}},H=function(e,t){return H=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},H(e,t)};function Q(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}H(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function B(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Y(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}function G(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)(n||!(i in t))&&(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}function K(e){return"function"==typeof e}var X=function(e){var t=e(function(e){Error.call(e),e.stack=Error().stack});return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}(function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map(function(e,t){return t+1+") "+e.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}});function Z(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var ee=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var e,t,r,n,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var s=B(o),l=s.next();!l.done;l=s.next())l.value.remove(this)}catch(t){e={error:t}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else o.remove(this);var a=this.initialTeardown;if(K(a))try{a()}catch(e){i=e instanceof X?e.errors:[e]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var p=B(u),c=p.next();!c.done;c=p.next()){var d=c.value;try{re(d)}catch(e){i=null==i?[]:i,e instanceof X?i=G(G([],Y(i)),Y(e.errors)):i.push(e)}}}catch(e){r={error:e}}finally{try{c&&!c.done&&(n=p.return)&&n.call(p)}finally{if(r)throw r.error}}}if(i)throw new X(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)re(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null==(r=this._finalizers)?[]:r).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&Z(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&Z(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();function te(e){return e instanceof ee||e&&"closed"in e&&K(e.remove)&&K(e.add)&&K(e.unsubscribe)}function re(e){K(e)?e():e.unsubscribe()}ee.EMPTY;var ne=null,ie=null,oe=void 0,se=!1,le=!1,ae={setTimeout:function(e,t){var r=[...arguments].slice(2),n=ae.delegate;return null!=n&&n.setTimeout?n.setTimeout.apply(n,G([e,t],Y(r))):setTimeout.apply(void 0,G([e,t],Y(r)))},clearTimeout:function(e){var t=ae.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function ue(){}var pe=ce("C",void 0,void 0);function ce(e,t,r){return{kind:e,value:t,error:r}}var de=null;var fe=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,te(t)&&t.add(r)):r.destination=we,r}return Q(t,e),t.create=function(e,t,r){return new ge(e,t,r)},t.prototype.next=function(e){this.isStopped?me(function(e){return ce("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?me(function(e){return ce("E",void 0,e)}(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?me(pe,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(ee),he=Function.prototype.bind;function ve(e,t){return he.call(e,t)}var ye=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){be(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){be(e)}else be(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){be(e)}},e}(),ge=function(e){function t(t,r,n){var i,o,s=e.call(this)||this;K(t)||!t?i={next:null==t?void 0:t,error:null==r?void 0:r,complete:null==n?void 0:n}:s&&le?((o=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&ve(t.next,o),error:t.error&&ve(t.error,o),complete:t.complete&&ve(t.complete,o)}):i=t;return s.destination=new ye(i),s}return Q(t,e),t}(fe);function be(e){se?function(e){se&&de&&(de.errorThrown=!0,de.error=e)}(e):function(e){ae.setTimeout(function(){if(!ne)throw e;ne(e)})}(e)}function me(e,t){var r=ie;r&&ae.setTimeout(function(){return r(e,t)})}var we={closed:!0,next:ue,error:function(e){throw e},complete:ue},Ae="function"==typeof Symbol&&Symbol.observable||"@@observable";function Se(e){return e}var Pe=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(e,t,r){var n=this,i=function(e){return e&&e instanceof fe||function(e){return e&&K(e.next)&&K(e.error)&&K(e.complete)}(e)&&te(e)}(e)?e:new ge(e,t,r);return function(e){if(se){var t=!de;if(t&&(de={errorThrown:!1,error:null}),e(),t){var r=de,n=r.errorThrown,i=r.error;if(de=null,n)throw i}}else e()}(function(){var e=n,t=e.operator,r=e.source;i.add(t?t.call(i,r):r?n._subscribe(i):n._trySubscribe(i))}),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(b){e.error(b)}},e.prototype.forEach=function(e,t){var r=this;return new(t=Oe(t))(function(t,n){var i=new ge({next:function(t){try{e(t)}catch(e){n(e),i.unsubscribe()}},error:n,complete:t});r.subscribe(i)})},e.prototype._subscribe=function(e){var t;return null==(t=this.source)?void 0:t.subscribe(e)},e.prototype[Ae]=function(){return this},e.prototype.pipe=function(){return function(e){return 0===e.length?Se:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)}}([...arguments])(this)},e.prototype.toPromise=function(e){var t=this;return new(e=Oe(e))(function(e,r){var n;t.subscribe(function(e){return n=e},function(e){return r(e)},function(){return e(n)})})},e.create=function(t){return new e(t)},e}();function Oe(e){var t;return null==(t=null==e?oe:e)?Promise:t}function Me(e,t,r,n,i,o,s){try{var l=e[o](s),a=l.value}catch(e){return void r(e)}l.done?t(a):Promise.resolve(a).then(n,i)}function Ee(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var o=e.apply(t,r);function s(e){Me(o,n,i,s,l,"next",e)}function l(e){Me(o,n,i,s,l,"throw",e)}s(void 0)})}}var Fe=(e={})=>{let{parentOrigin:t="*",timeout:r,debug:n=!1,config:i={}}=e,o=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(n),s=((e,t)=>{let r=[],n=!1;return{destroy(i){n||(n=!0,t(`${e}: Destroying connection`),r.forEach(e=>{e(i)}))},onDestroy(e){n?e():r.push(e)}}})("App",o),{destroy:l,onDestroy:a}=s;return{promise:new Promise((e,n)=>{let u=j(r,l),p=r=>{if((()=>{try{clearTimeout(void 0)}catch(g){return!1}return!0})()&&r.source===parent&&r.data&&r.data.penpal===g.SynAck){let n=r.data,l=new J(n.id,n.appName),a=new J(n.id+"/api",n.appName),c=n.id,d={},f=e=>"api/"+e,h={$emit:(e,...t)=>{l.getEventCallBackLength(e)>0?l.$pureEmit(e,...t):null==d||d.$off(e,()=>{},!0)},onQueryResult:e=>{a.$pureEmit(f(e.reqid),e)},onOsNotify:e=>{}},v=e=>function(t){let r=f(e);a.$on(r,function e(n){t.next(n),n.reqid&&"succ"===n.result&&(t.complete(),a.$off(r,e))})},y=$(h),g=N(t,y,T(T({},i),{},{postmateVersion:"0.1.3"}),s,o)(r),b={},m=g.bus;if(m){let e=(e,t,r)=>{r?(t.$__once=!0,l.$once(e,t)):l.$on(e,t),b[e]?b[e].push(t):(b[e]=[t],m.$on(e,c))};Object.assign(d,m,{$on:e,$off:(e,t,r)=>{var n;if(b[e]){let r=b[e].indexOf(t);r>-1&&(b[e].splice(r,1),l.$off(e,t))}r&&delete b[e],null!=(n=b[e])&&n.length||(m.$off(e,c),delete b[e])},$once:(t,r)=>{e(t,r,!0)}})}let w=T(T({},g),{},{bus:d,query:function(){var e=Ee(function*(e,t){let r=(null==e?void 0:e.reqid)||(yield g.genReqId());return new Promise((n,i)=>{g.query(T(T({},e),{},{reqid:r}),t).then(e=>{"succ"===(null==e?void 0:e.result)?n(e):i(e)})})});return function(t,r){return e.apply(this,arguments)}}(),createObservableQuery:function(){var e=Ee(function*(e,t={}){let r=(null==e?void 0:e.reqid)||(yield g.genReqId()),n=new Pe(v(r));return g.query(T(T({},e),{},{reqid:r}),T(T({},t),{},{observable:!0})),n});return function(t){return e.apply(this,arguments)}}()});g&&(window.removeEventListener(A.Message,p),u(),e({methods:w,config:r.data.config}))}};window.addEventListener(A.Message,p),(()=>{o("Child: Handshake - Sending SYN");let e={penpal:g.Syn},r=t instanceof RegExp?"*":t;window.parent.postMessage(e,r)})(),a(e=>{window.removeEventListener(A.Message,p),e&&n(e)})}),destroy(){l()}}},$e="trimjs-extension-host";function _e(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`web-ext-${Date.now()}-${Math.random().toString(16).slice(2)}`}function je(e){if(!e||"object"!=typeof e)return!1;const t=e;return t.source===$e&&1===t.version&&"string"==typeof t.requestId&&("request"===t.kind||"response"===t.kind||"event"===t.kind)}function ke(e){const t=new Error(`NotSupportedInExtensionHost: ${e}`);throw t.code="NotSupportedInExtensionHost",t}function We(e){var t;const r=null!==(t=null==e?void 0:e.timeoutMs)&&void 0!==t?t:1500,n=new Map,i=new Set,o=e=>{if(je(t=e.data)&&"response"===t.kind){const t=n.get(e.data.requestId);if(!t)return;return n.delete(e.data.requestId),clearTimeout(t.timeoutId),void t.resolve(e.data)}var t;(function(e){return je(e)&&"event"===e.kind})(e.data)&&i.forEach(t=>{t(e.data)})};return window.addEventListener("message",o),{request:(e,t,i)=>s(function*(){const o=function(e,t){return{source:$e,version:1,kind:"request",requestId:_e(),payload:{method:e,params:t}}}(e,t),s=yield new Promise((t,s)=>{let l;const a=i&&"timeoutMs"in i?i.timeoutMs:r;"number"==typeof a&&a>=0&&(l=setTimeout(()=>{n.delete(o.requestId),s(new Error(`Extension host timeout while calling ${e}`))},a)),n.set(o.requestId,{resolve:t,reject:s,timeoutId:l}),window.postMessage(o,"*")});var l,a;if(!s.payload.ok)throw new Error(null!==(l=null===(a=s.payload.error)||void 0===a?void 0:a.message)&&void 0!==l?l:`Extension host request failed: ${e}`);return s.payload.result})(),onEvent:e=>(i.add(e),()=>{i.delete(e)}),destroy(){window.removeEventListener("message",o),n.forEach(e=>{clearTimeout(e.timeoutId),e.reject(new Error("Extension bridge destroyed"))}),n.clear(),i.clear()}}}function xe(){return(xe=s(function*(e){const t=We();try{var r;const i=yield t.request("handshake",{debug:null!==(r=null==e?void 0:e.debug)&&void 0!==r&&r},{timeoutMs:5e3});return n.log("Extension host probe response:",i),!0===i.available}catch(i){return n.log("Extension host probe failed:",i),!1}finally{t.destroy()}})).apply(this,arguments)}function qe(){return qe=s(function*(){const e=We(),t=new Map;e.onEvent(e=>{const r=t.get(e.payload.event);null==r||r.forEach(t=>{t(e.payload.data)})}),yield e.request("handshake",{},{timeoutMs:5e3});const r=yield e.request("getPlatformConfig",{}),n={bus:{$on(r,n){var i;const o=null!==(i=t.get(r))&&void 0!==i?i:new Set,s=0===o.size;o.add(n),t.set(r,o),s&&e.request("subscribe",{event:r})},$off(r,n){const i=t.get(r);i&&(i.delete(n),0===i.size&&(t.delete(r),e.request("unsubscribe",{event:r})))},$once(e,t){const r=function(){n.bus.$off(e,r),t(...arguments)};n.bus.$on(e,r)},$emit(){ke("bus.$emit")}},genReqId:()=>_e(),query:(t,r)=>e.request("query",{params:t,config:r}),createObservableQuery:(o=s(function*(){return ke("createObservableQuery")}),function(){return o.apply(this,arguments)}),openApp:()=>ke("openApp"),openAppSetting:()=>ke("openAppSetting"),openCustomApp:()=>ke("openCustomApp"),setTitle:()=>ke("setTitle"),pickFile:t=>e.request("pickFile",t,{timeoutMs:null}),pickUserFile:()=>ke("pickUserFile"),pickSharedFile:()=>ke("pickSharedFile"),showFileDetails:(e,t)=>ke("showFileDetails"),authorizeUserFile:e=>ke("authorizeUserFile"),authorizeSharedFile:e=>ke("authorizeSharedFile"),close:(i=s(function*(){e.destroy()}),function(){return i.apply(this,arguments)}),refreshToken:()=>e.request("refreshToken",{}),setExitPageTips:()=>ke("setExitPageTips"),openFileManagerApp:()=>ke("openFileManagerApp"),openFileManager:()=>ke("openFileManager"),openFile:()=>ke("openFile"),getPlatformConfig:()=>Promise.resolve(r),getHostSnapshot:()=>e.request("getHostSnapshot",{})};var i,o,l;return{methods:n,config:(l=r,{appName:"extension-host",os:{version:l.systemVersion,theme:l.theme,language:l.language,format:{date:{date:l.format.date,time:l.format.time}}}})}}),qe.apply(this,arguments)}var Te=null;function Ne(){return(Ne=s(function*(e){const t=Fe({debug:null==e?void 0:e.debug,timeout:1500});try{const e=yield t.promise;return e}catch(r){return t.destroy(),n.log("Native OS connection probe failed:",r),null}})).apply(this,arguments)}var Ie=e=>Te||(Te=s(function*(){if("undefined"!=typeof window&&window.parent!==window){const t=yield function(e){return Ne.apply(this,arguments)}(e);if(t)return t}return(yield function(e){return xe.apply(this,arguments)}(e))?function(){return qe.apply(this,arguments)}():Fe({debug:null==e?void 0:e.debug}).promise})()),Ce={pickFile:"pick-file",pickUserFile:"pick-user-file",pickSharedFile:"pick-shared-file",authorizeUserFile:"authorize-user-file",authorizeSharedFile:"authorize-shared-file"};var Ve=class{constructor(){r(this,"options",void 0),r(this,"flutterInAppWebView",null),r(this,"osConnector",null),r(this,"initPromise",void 0),r(this,"appApiVersion",void 0),r(this,"isWeb",!0),r(this,"isStandaloneWeb",!1);let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,e.debug&&(n.setDebug(!0),n.log("Trim App initialized with debug mode")),n.log("Options:",e),this.initPromise=this.init()}init(){var e=this;return s(function*(){return n.log("Starting initialization..."),new Promise(t=>{if(i())e.isWeb=!1,n.log("Initializing mobile platform..."),new Promise(e=>{var t;(p?window.flutter_inappwebview:u||(null===(t=window.flutter_inappwebview)||void 0===t?void 0:t._platformReady))?(n.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{n.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)})}).then((r=s(function*(r){yield e.initMobileAppApi(r),n.log("Mobile platform initialized"),t()}),function(e){return r.apply(this,arguments)}));else{if(e.isWeb=!0,e.isStandaloneWeb="undefined"!=typeof window&&window.parent===window,e.isStandaloneWeb)return n.log("Standalone web platform detected; host bridge initialization skipped"),void t();n.log("Initializing web platform..."),Ie().then(r=>{e.osConnector=r,n.log("Web platform initialized"),t()})}var r})})()}getWebMethods(){var e;const t=null===(e=this.osConnector)||void 0===e?void 0:e.methods;if(!t)throw new Error("Host bridge is not available outside iframe or app runtime");return t}loadAppMessage(){var e=this;return s(function*(){return e.callAppMethod("getAppMessage")})()}initMobileAppApi(e){var t=this;return s(function*(){t.flutterInAppWebView=e;try{const e=yield t.loadAppMessage();t.appApiVersion=null==e?void 0:e.appApi}catch(r){n.log("Failed to load mobile appApi version:",r),t.appApiVersion=void 0}})()}assertMobileAppApi(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"v1.0";if(!this.isAtLeastVersion(this.appApiVersion,t))throw new Error(`${e} requires appApi >= ${t}`)}isAtLeastVersion(e,t){if(!e)return!1;const r=this.parseVersion(e),n=this.parseVersion(t),i=Math.max(r.length,n.length);for(let l=0;l<i;l+=1){var o,s;const e=null!==(o=r[l])&&void 0!==o?o:0,t=null!==(s=n[l])&&void 0!==s?s:0;if(e>t)return!0;if(e<t)return!1}return!0}parseVersion(e){return e.replace(/^v/i,"").split(".").map(e=>Number.parseInt(e,10)||0)}callAppMethod(e){var t=arguments,r=this;return s(function*(){if(!r.flutterInAppWebView)return null;for(var n=t.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=t[o];return c(r.flutterInAppWebView,e,...i)})()}ready(){var e=this;return s(function*(){return e.initPromise})()}getOptions(){return this.options}setOptions(e){this.options=a(a({},this.options),e),void 0!==e.debug&&n.setDebug(e.debug),n.log("Options updated:",this.options)}getPlatformConfig(){var e=this;return s(function*(){if(yield e.initPromise,e.isWeb){const t=yield e.getWebMethods().getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}if(e.appApiVersion){const t=yield e.callAppMethod("getPlatformConfig");if(!t)throw new Error("Failed to get platform config");return t}const t=yield e.loadAppMessage();if(!t)throw new Error("Failed to get platform config");return e.appApiVersion=t.appApi,{theme:t.nightMode,language:t.language,appVersion:t.appVersion,systemVersion:t.systemVersion,format:{date:t.dateFormat,time:t.timeFormat}}})()}getHostSnapshot(){var e=this;return s(function*(){if(yield e.initPromise,!e.isWeb)throw new Error("getHostSnapshot is not supported on mobile platform");const t=yield e.getWebMethods().getHostSnapshot();if(!t)throw new Error("Failed to get host snapshot");return t})()}getAppAuthBaseUrl(){var e=this;return s(function*(){if("undefined"!=typeof window&&window.parent!==window){const e=document.referrer;if(e)try{return new URL(e).origin}catch(t){n.log("Failed to derive app auth base url from document.referrer:",t)}}if("undefined"!=typeof window)return window.location.origin;if(yield e.initPromise,e.isWeb)try{const t=yield e.getHostSnapshot();if(t.host)return t.host}catch(t){n.log("Failed to derive app auth host snapshot:",t)}throw new Error("Failed to derive app auth base url")})()}buildAppAuthUrl(e,t){var r=this;return s(function*(){return function(e,t,r,n){var i,o;const s=new URL(e,null!==(i=null!=n?n:null===(o=globalThis.location)||void 0===o?void 0:o.origin)&&void 0!==i?i:"http://localhost"),l=Ce[t];if(s.pathname=function(e){return`/app-auth/${e}`}(l),s.searchParams.set("appName",r.appName),r.redirectUri&&s.searchParams.set("redirectUri",r.redirectUri),r.state&&s.searchParams.set("state",r.state),"pickFile"===t||"pickUserFile"===t||"pickSharedFile"===t){var a;const e=r;"pickSharedFile"!==t&&e.directory&&s.searchParams.set("directory","true");const n="pickSharedFile"!==t?e.accept:void 0;(null==n?void 0:n.length)&&s.searchParams.set("accept",n.join(",")),(null===(a=e.sidebarGroup)||void 0===a?void 0:a.length)&&s.searchParams.set("sidebarGroup",e.sidebarGroup.join(","))}else s.searchParams.set("path",r.path);return s.toString()}(yield r.getAppAuthBaseUrl(),e,t,window.location.origin)})()}openAppAuth(e,t,r){var n=this;return s(function*(){const i=yield n.buildAppAuthUrl(e,t);return"_self"===(null==r?void 0:r.target)&&"undefined"!=typeof window?(window.location.assign(i),i):(yield n.openURL(i,null==r?void 0:r.target,null==r?void 0:r.features),i)})()}parseAppAuthCallback(e){return function(e){var t,r,n,i;const o=e instanceof URLSearchParams?e:e instanceof URL?e.searchParams:"string"==typeof e?new URL(e,null!==(t=null===(r=globalThis.location)||void 0===r?void 0:r.origin)&&void 0!==t?t:"http://localhost").searchParams:new URLSearchParams(null!==(n=null===(i=globalThis.location)||void 0===i?void 0:i.search)&&void 0!==n?n:""),s=o.get("method"),l=s&&Object.prototype.hasOwnProperty.call(Ce,s)?s:void 0,a=o.get("path");let u;if(a)try{const e=JSON.parse(a);Array.isArray(e)&&e.every(e=>"string"==typeof e)&&(u=e)}catch(p){u=void 0}return{status:o.get("status")||void 0,error:o.get("error")||void 0,method:l,appName:o.get("appName")||void 0,state:o.get("state")||void 0,path:u}}(e)}setTitle(e){var t=this;return s(function*(){if(yield t.initPromise,n.log("Setting title:",e),document.title=e,t.isWeb)return t.getWebMethods().setTitle(e)})()}setExitPageTips(e){var t=this;return s(function*(){return yield t.initPromise,t.isWeb?t.getWebMethods().setExitPageTips(e):t.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})()}openFile(e){var t=this;return s(function*(){return yield t.initPromise,n.log("Opening file:",e),t.isWeb?t.getWebMethods().openFile(e):t.callAppMethod("openFile",e)})()}openFileManager(e){var t=this;return s(function*(){if(yield t.initPromise,n.log("Opening file manager:",e),t.isWeb){const r=t.getWebMethods();return(r.openFileManager||r.openFileManagerApp)(e)}return t.assertMobileAppApi("openFileManager"),t.callAppMethod("openFileManager",e)})()}showFileDetails(e,t){var r=this;return s(function*(){return yield r.initPromise,r.isWeb?r.getWebMethods().showFileDetails(e,t):(r.assertMobileAppApi("showFileDetails"),r.callAppMethod("showFileDetails",JSON.stringify({paths:e,options:t})))})()}authorizeUserFile(e){var t=this;return s(function*(){var r;return yield t.initPromise,t.isWeb?t.getWebMethods().authorizeUserFile(e):(t.assertMobileAppApi("authorizeUserFile"),null!==(r=yield t.callAppMethod("authorizeUserFile",JSON.stringify({path:e})))&&void 0!==r?r:void 0)})()}authorizeSharedFile(e){var t=this;return s(function*(){var r;return yield t.initPromise,t.isWeb?t.getWebMethods().authorizeSharedFile(e):(t.assertMobileAppApi("authorizeSharedFile"),null!==(r=yield t.callAppMethod("authorizeSharedFile",JSON.stringify({path:e})))&&void 0!==r?r:void 0)})()}openAppSetting(){var e=this;return s(function*(){return yield e.initPromise,n.log("Opening app setting"),e.isWeb?e.getWebMethods().openAppSetting():(e.assertMobileAppApi("openAppSetting"),e.callAppMethod("openAppSetting"))})()}openApp(e){var t=this;return s(function*(){return yield t.initPromise,n.log("Opening app:",e),t.isWeb?t.getWebMethods().openApp(e):!!i()&&t.callAppMethod("openAppPage",e)})()}openCustomApp(e,t){var r=this;return s(function*(){if(yield r.initPromise,n.log("Opening custom app:",e,t),r.isWeb)return r.getWebMethods().openCustomApp(e,t);throw new Error("openCustomApp is not supported on mobile platform")})()}openURL(e,t,r){var i=this;return s(function*(){if(yield i.initPromise,n.log("Opening URL:",e,t,r),!i.isWeb)return i.callAppMethod("openSystemBrowser",e);if("_self"===t)return void window.location.assign(e);if(!r)return void window.open(e,t,r);const o=window.open("",t,r);o&&(o.location.href=e)})()}close(){var e=this;return s(function*(){return yield e.initPromise,e.isWeb?e.getWebMethods().close():e.callAppMethod("exitPage")})()}query(e,t){var r=this;return s(function*(){if(yield r.initPromise,r.isWeb){if(null==t?void 0:t.observable)return r.getWebMethods().createObservableQuery(e,t);const n=yield r.getWebMethods().query(e,t);if(!n)throw new Error("Failed to query");return n}if(r.assertMobileAppApi("query"),null==t?void 0:t.observable){if(!r.flutterInAppWebView)throw new Error("Failed to start observable query");return function(e,t,r){return v(),new f(n=>{let i,o=!1;return c(e,"wsQuery",null==t?void 0:t.req,JSON.stringify(t),void 0===r?void 0:JSON.stringify(r)).then(e=>{(null==e?void 0:e.reqId)?(i=e.reqId,o||h.set(i,n)):n.error(new Error("Failed to start observable query"))},e=>{n.error(e)}),()=>{o=!0,i&&h.delete(i)}})}(r.flutterInAppWebView,e,t)}const n=yield r.callAppMethod("wsQuery",null==e?void 0:e.req,JSON.stringify(e),void 0===t?void 0:JSON.stringify(t));if(!n)throw new Error("Failed to query");if("succ"!==n.result)throw n;return n})()}refreshToken(){var e=this;return s(function*(){if(yield e.initPromise,!e.isWeb)throw new Error("refreshToken is not supported on mobile platform");return e.getWebMethods().refreshToken()})()}$on(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$on is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$on(e,t)})()}$off(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$off is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$off(e,t)})()}$once(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$once is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$once(e,t)})()}pickFile(e){var t=this;return s(function*(){var r,n;return yield t.initPromise,t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.pickFile(e):t.isAtLeastVersion(t.appApiVersion,"v1.0")?null!==(n=yield t.callAppMethod("pickFile",JSON.stringify(e)))&&void 0!==n?n:void 0:t.flutterInAppWebView?function(e,t){return y.apply(this,arguments)}(t.flutterInAppWebView,e):void 0})()}pickUserFile(){var e=arguments,t=this;return s(function*(){var r;let n=e.length>0&&void 0!==e[0]?e[0]:{};return yield t.initPromise,t.isWeb?t.getWebMethods().pickUserFile(n):(t.assertMobileAppApi("pickUserFile"),null!==(r=yield t.callAppMethod("pickUserFile",JSON.stringify(n)))&&void 0!==r?r:void 0)})()}pickSharedFile(){var e=arguments,t=this;return s(function*(){var r;let n=e.length>0&&void 0!==e[0]?e[0]:{};return yield t.initPromise,t.isWeb?t.getWebMethods().pickSharedFile(n):(t.assertMobileAppApi("pickSharedFile"),null!==(r=yield t.callAppMethod("pickSharedFile",JSON.stringify(n)))&&void 0!==r?r:void 0)})()}};exports.TrimApp=Ve,exports.default=Ve;
1
+ function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,r||"default");if("object"!=e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==e(r)?r:r+""}function r(e,r,n){return(r=t(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var n=new class{constructor(){r(this,"debug",!1)}setDebug(e){this.debug=e}isDebug(){return this.debug}log(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.log("[Trim App]",...t)}}warn(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.warn("[Trim App]",...t)}}error(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.error("[Trim App]",...t)}}info(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.info("[Trim App]",...t)}}};var i=()=>function(e){const t=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,r={};let n;for(;null!==(n=t.exec(e));)n[1]&&(r.fnOSVersion=n[1]),n[2]&&(r.fnAppType=n[2]),n[3]&&(r.fnAppVersion=n[3]);return r}(navigator.userAgent).fnAppVersion;function o(e,t,r,n,i,o,s){try{var l=e[o](s),a=l.value}catch(e){return void r(e)}l.done?t(a):Promise.resolve(a).then(n,i)}function s(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var s=e.apply(t,r);function l(e){o(s,n,i,l,a,"next",e)}function a(e){o(s,n,i,l,a,"throw",e)}l(void 0)})}}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var u=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{u=!0});var p=/(iPad|iPhone|iPod|Macintosh|Mac OS X)/i.test(navigator.userAgent),c=function(){var e=s(function*(e,t){for(var r=arguments.length,i=new Array(r>2?r-2:0),o=2;o<r;o++)i[o-2]=arguments[o];n.log(`callHandler: ${t}, params: ${i.map(e=>String(e)).join(", ")}`);const s=yield e.callHandler(t,...i);if(s)try{const e=JSON.parse(s);n.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return n.log(`appMessage: ${JSON.stringify(t)}`),t}catch(l){return n.error(`error: ${l}`),null}return null});return function(t,r){return e.apply(this,arguments)}}(),d=new Map,f=class{constructor(e){r(this,"subscribeFn",void 0),this.subscribeFn=e}subscribe(e,t,r){var n;const i="function"==typeof e?{next:e,error:t,complete:r}:null!=e?e:{};let o=!1;const s=null!==(n=this.subscribeFn({next:e=>{var t;o||(null===(t=i.next)||void 0===t||t.call(i,e))},error:e=>{var t;o||(o=!0,null===(t=i.error)||void 0===t||t.call(i,e))},complete:()=>{var e;o||(o=!0,null===(e=i.complete)||void 0===e||e.call(i))}}))&&void 0!==n?n:()=>{};return{unsubscribe:()=>{o||(o=!0,s())}}}},h=new Map;function v(){window._flutter_onAppObservableQueryResult=e=>{n.log("_flutter_onAppObservableQueryResult",e);const t=function(e){var t,r;const n="string"==typeof e?JSON.parse(e):e,i=null!==(t=n.reqid)&&void 0!==t?t:n.reqId;return a(a({},n),{},{reqId:null!==(r=n.reqId)&&void 0!==r?r:i,reqid:i})}(e),r=h.get(t.reqId);if(r)if(t.result&&"doing"!==t.result){if("succ"===t.result)return r.next(t),r.complete(),void h.delete(t.reqId);r.error(t),h.delete(t.reqId)}else r.next(t);else n.log("_flutter_onAppObservableQueryResult observer not found",t)}}function y(){return(y=s(function*(e,t){return new Promise((r,i)=>{null==e||e.callHandler("openFolder",JSON.stringify(t)).then(e=>{if(n.log("pickFilePromise callback registered",{reqId:e,params:t}),e){d.set(e,function(e){r(e.result)})}else i(new Error("openFolder failed"))})})})).apply(this,arguments)}i()&&(window.fnAppMessage=e=>{n.log("app-message",e);const t=JSON.parse(e),r=d.get(t.reqId);r&&(r(t),d.delete(t.reqId))}),i()&&v();var g=function(e){return e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e}({}),b=function(e){return e.Fulfilled="fulfilled",e.Rejected="rejected",e}({}),m=function(e){return e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e}({}),w=function(e){return e.DataCloneError="DataCloneError",e}({}),A=function(e){return e.Message="message",e}({}),S=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),O=(e,t,r)=>{let{localName:n,local:i,remote:o,originForSending:s,originForReceiving:l}=e,a=!1,u=e=>{if(e.source!==o||e.data.penpal!==g.Call)return;if("*"!==l&&e.origin!==l)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${l}`);let{methodName:i,args:u,id:p}=e.data;r(`${n}: Received ${i}() call`);let c=e=>t=>{if(r(`${n}: Sending ${i}() reply`),a)return void r(`${n}: Unable to send ${i}() reply due to destroyed connection`);let l={penpal:g.Reply,id:p,resolution:e,returnValue:t};e===b.Rejected&&t instanceof Error&&(l.returnValue=S(t),l.returnValueIsError=!0);try{o.postMessage(l,s)}catch(e){let r=e instanceof Error?e:Error(String(e));if(r.name===w.DataCloneError){let e={penpal:g.Reply,id:p,resolution:b.Rejected,returnValue:S(r),returnValueIsError:!0};o.postMessage(e,s)}throw e}};new Promise(e=>e(t[i].apply(t,u))).then(c(b.Fulfilled),c(b.Rejected))};return i.addEventListener(A.Message,u),()=>{a=!0,i.removeEventListener(A.Message,u)}},P=0,E=()=>++P,M=e=>e?e.split("."):[],F=(e,t,r)=>{let n=M(t);return n.reduce((e,t,i)=>(void 0===e[t]&&(e[t]={}),i===n.length-1&&(e[t]=r),e[t]),e),e},$=(e,t)=>{let r={};return Object.keys(e).forEach(n=>{let i=e[n],o=((e,t)=>{let r=M(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof i&&Object.assign(r,$(i,o)),"function"==typeof i&&(r[o]=i)}),r},_=(e,t,r,n,i)=>{let{localName:o,local:s,remote:l,originForSending:a,originForReceiving:u}=t,p=!1,c=new Set;i(`${o}: Connecting call sender`);let d=e=>(...r)=>{let d;i(`${o}: Sending ${e}() call`);try{l.closed&&(d=!0)}catch(g){d=!0}if(d&&n(),p){let t=Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=m.ConnectionDestroyed,t}return new Promise((n,p)=>{var d;let f,h=E(),v=()=>{s.removeEventListener(A.Message,m),void 0!==f&&clearTimeout(f),c.delete(y)},y=()=>{v(),p(Error("Connection closed"))},m=t=>{var r;if(t.source!==l||(null==(r=t.data)?void 0:r.penpal)!==g.Reply||t.data.id!==h)return;if("*"!==u&&t.origin!==u)return void i(`${o} received message from origin ${t.origin} which did not match expected origin ${u}`);let s=t.data;i(`${o}: Received ${e}() reply`),v();let a=s.returnValue;s.returnValueIsError&&(a=(e=>{let t=Error();return Object.assign(t,e),t})(a)),(s.resolution===b.Fulfilled?n:p)(a)};s.addEventListener(A.Message,m),c.add(y);let w=null==(d=t.callTimeouts)?void 0:d[e];void 0!==w&&(f=setTimeout(y,w));let S={penpal:g.Call,id:h,methodName:e,args:r};try{l.postMessage(S,a)}catch(g){v(),p(g)}})},f=r.reduce((e,t)=>(e[t]=d(t),e),{});return Object.assign(e,(e=>{let t={};for(let r in e)F(t,r,e[r]);return t})(f)),()=>{p=!0;for(let e of c)e()}},k=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout(()=>{let r=Error(`Connection timed out after ${e}ms`);r.code=m.ConnectionTimeout,t(r)},e)),()=>{clearTimeout(r)}};function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function j(e){var t=function(e,t){if("object"!=T(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=T(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==T(t)?t:t+""}function N(e,t,r){return(t=j(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function W(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function C(e){for(var t=1;t<arguments.length;t++){var r=null==arguments[t]?{}:arguments[t];t%2?W(Object(r),!0).forEach(function(t){N(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):W(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var x=(e,t,r,n,i,o)=>{let{destroy:s,onDestroy:l}=n;return n=>{if(!(e instanceof RegExp?e.test(n.origin):"*"===e||e===n.origin))return void i(`Child: Handshake - Received SYN-ACK from origin ${n.origin} which did not match expected origin ${e}`);i("Child: Handshake - Received SYN-ACK, responding with ACK");let a="null"===n.origin?"*":n.origin,u={penpal:g.Ack,methodNames:Object.keys(t),config:r};window.parent.postMessage(u,a);let p={callTimeouts:o,localName:"Child",local:window,remote:window.parent,originForSending:a,originForReceiving:n.origin},c=O(p,t,i);l(c);let d={},f=_(d,p,n.data.methodNames,s,i);return l(f),d}};function q(e,t){var r;null==(r=console)||r.warn(`[fnApp warn]: ${e}`,t)}function I(e,t){var r;null==(r=console)||r.error(`[fnApp error]: ${e}`,t)}var U="_fn_all_event",V="事件订阅数量为空";function R(e){return R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},R(e)}function D(e){var t=function(e,t){if("object"!=R(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=R(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==R(t)?t:t+""}function z(e,t,r){return(t=D(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var L=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map,J=class{constructor(e,t){z(this,"id",void 0),z(this,"appName",void 0),z(this,"eventObj",void 0),z(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),L.get(this.id)||L.set(this.id,{}),this.eventObj=L.get(this.id)}$on(e,t){let r=this.eventObj[e];return r?(r.includes(t)||r.push(t),this):(this.eventObj[e]=[t],this)}$onAll(e){return this.$on(U,e)}$once(e,t){t.$__once=!0,this.$on(e,t)}$off(e,t){let r=this.eventObj[e];if(!e||!r||!r.length)return q(`${e} ${V}`),this;let n,i=r.length;for(;i--;)if(n=r[i],n===t){r.splice(i,1);break}return this}$offAll(e){return this.$off(U,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let r=0;return L.forEach(n=>{if(n[e])for(let i=n[e].length-1;i>=0;i--){r++;let o=n[e][i];o.$__once&&n[e].splice(i,1);try{o(...t)}catch(e){I(e)}}if(n._fn_all_event)for(let i=n[U].length-1;i>=0;i--){r++;let o=n[U][i];o.$__once&&n[U].splice(i,1);try{o(...t)}catch(e){I(e)}}}),(!e||0===r)&&q(`${e} ${V}`),this}$clear(){var e;let t=null==(e=L.get(this.id))?{}:e;return Object.keys(t).forEach(e=>delete t[e]),this}},H=function(e,t){return H=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},H(e,t)};function Q(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}H(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function B(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Y(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}function G(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)(n||!(i in t))&&(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}function K(e){return"function"==typeof e}var X=function(e){var t=e(function(e){Error.call(e),e.stack=Error().stack});return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}(function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map(function(e,t){return t+1+") "+e.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}});function Z(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var ee=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var e,t,r,n,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var s=B(o),l=s.next();!l.done;l=s.next())l.value.remove(this)}catch(t){e={error:t}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else o.remove(this);var a=this.initialTeardown;if(K(a))try{a()}catch(e){i=e instanceof X?e.errors:[e]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var p=B(u),c=p.next();!c.done;c=p.next()){var d=c.value;try{re(d)}catch(e){i=null==i?[]:i,e instanceof X?i=G(G([],Y(i)),Y(e.errors)):i.push(e)}}}catch(e){r={error:e}}finally{try{c&&!c.done&&(n=p.return)&&n.call(p)}finally{if(r)throw r.error}}}if(i)throw new X(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)re(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null==(r=this._finalizers)?[]:r).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&Z(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&Z(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();function te(e){return e instanceof ee||e&&"closed"in e&&K(e.remove)&&K(e.add)&&K(e.unsubscribe)}function re(e){K(e)?e():e.unsubscribe()}ee.EMPTY;var ne=null,ie=null,oe=void 0,se=!1,le=!1,ae={setTimeout:function(e,t){var r=[...arguments].slice(2),n=ae.delegate;return null!=n&&n.setTimeout?n.setTimeout.apply(n,G([e,t],Y(r))):setTimeout.apply(void 0,G([e,t],Y(r)))},clearTimeout:function(e){var t=ae.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function ue(){}var pe=ce("C",void 0,void 0);function ce(e,t,r){return{kind:e,value:t,error:r}}var de=null;var fe=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,te(t)&&t.add(r)):r.destination=we,r}return Q(t,e),t.create=function(e,t,r){return new ge(e,t,r)},t.prototype.next=function(e){this.isStopped?me(function(e){return ce("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?me(function(e){return ce("E",void 0,e)}(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?me(pe,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(ee),he=Function.prototype.bind;function ve(e,t){return he.call(e,t)}var ye=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){be(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){be(e)}else be(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){be(e)}},e}(),ge=function(e){function t(t,r,n){var i,o,s=e.call(this)||this;K(t)||!t?i={next:null==t?void 0:t,error:null==r?void 0:r,complete:null==n?void 0:n}:s&&le?((o=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&ve(t.next,o),error:t.error&&ve(t.error,o),complete:t.complete&&ve(t.complete,o)}):i=t;return s.destination=new ye(i),s}return Q(t,e),t}(fe);function be(e){se?function(e){se&&de&&(de.errorThrown=!0,de.error=e)}(e):function(e){ae.setTimeout(function(){if(!ne)throw e;ne(e)})}(e)}function me(e,t){var r=ie;r&&ae.setTimeout(function(){return r(e,t)})}var we={closed:!0,next:ue,error:function(e){throw e},complete:ue},Ae="function"==typeof Symbol&&Symbol.observable||"@@observable";function Se(e){return e}var Oe=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(e,t,r){var n=this,i=function(e){return e&&e instanceof fe||function(e){return e&&K(e.next)&&K(e.error)&&K(e.complete)}(e)&&te(e)}(e)?e:new ge(e,t,r);return function(e){if(se){var t=!de;if(t&&(de={errorThrown:!1,error:null}),e(),t){var r=de,n=r.errorThrown,i=r.error;if(de=null,n)throw i}}else e()}(function(){var e=n,t=e.operator,r=e.source;i.add(t?t.call(i,r):r?n._subscribe(i):n._trySubscribe(i))}),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(b){e.error(b)}},e.prototype.forEach=function(e,t){var r=this;return new(t=Pe(t))(function(t,n){var i=new ge({next:function(t){try{e(t)}catch(e){n(e),i.unsubscribe()}},error:n,complete:t});r.subscribe(i)})},e.prototype._subscribe=function(e){var t;return null==(t=this.source)?void 0:t.subscribe(e)},e.prototype[Ae]=function(){return this},e.prototype.pipe=function(){return function(e){return 0===e.length?Se:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)}}([...arguments])(this)},e.prototype.toPromise=function(e){var t=this;return new(e=Pe(e))(function(e,r){var n;t.subscribe(function(e){return n=e},function(e){return r(e)},function(){return e(n)})})},e.create=function(t){return new e(t)},e}();function Pe(e){var t;return null==(t=null==e?oe:e)?Promise:t}function Ee(e,t,r,n,i,o,s){try{var l=e[o](s),a=l.value}catch(e){return void r(e)}l.done?t(a):Promise.resolve(a).then(n,i)}function Me(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var o=e.apply(t,r);function s(e){Ee(o,n,i,s,l,"next",e)}function l(e){Ee(o,n,i,s,l,"throw",e)}s(void 0)})}}var Fe=(e={})=>{let{parentOrigin:t="*",timeout:r,debug:n=!1,config:i={}}=e,o=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(n),s=((e,t)=>{let r=[],n=!1;return{destroy(i){n||(n=!0,t(`${e}: Destroying connection`),r.forEach(e=>{e(i)}))},onDestroy(e){n?e():r.push(e)}}})("App",o),{destroy:l,onDestroy:a}=s;return{promise:new Promise((n,u)=>{let p=k(r,l),c=r=>{if((()=>{try{clearTimeout(void 0)}catch(g){return!1}return!0})()&&r.source===parent&&r.data&&r.data.penpal===g.SynAck){let l=r.data,a=new J(l.id,l.appName),u=new J(l.id+"/api",l.appName),d=l.id,f={},h=e=>"api/"+e,v={$emit:(e,...t)=>{a.getEventCallBackLength(e)>0?a.$pureEmit(e,...t):null==f||f.$off(e,()=>{},!0)},onQueryResult:e=>{u.$pureEmit(h(e.reqid),e)},onOsNotify:e=>{}},y=e=>function(t){let r=h(e);u.$on(r,function e(n){t.next(n),n.reqid&&"succ"===n.result&&(t.complete(),u.$off(r,e))})},g=$(v),b=x(t,g,C(C({},i),{},{postmateVersion:"0.1.5"}),s,o,e.callTimeouts)(r),m={},w=b.bus;if(w){let e=(e,t,r)=>{r?(t.$__once=!0,a.$once(e,t)):a.$on(e,t),m[e]?m[e].push(t):(m[e]=[t],w.$on(e,d))};Object.assign(f,w,{$on:e,$off:(e,t,r)=>{var n;if(m[e]){let r=m[e].indexOf(t);r>-1&&(m[e].splice(r,1),a.$off(e,t))}r&&delete m[e],null!=(n=m[e])&&n.length||(w.$off(e,d),delete m[e])},$once:(t,r)=>{e(t,r,!0)}})}let S=C(C({},b),{},{bus:f,query:function(){var e=Me(function*(e,t){let r=(null==e?void 0:e.reqid)||(yield b.genReqId());return new Promise((n,i)=>{b.query(C(C({},e),{},{reqid:r}),t).then(e=>{"succ"===(null==e?void 0:e.result)?n(e):i(e)})})});return function(t,r){return e.apply(this,arguments)}}(),createObservableQuery:function(){var e=Me(function*(e,t={}){let r=(null==e?void 0:e.reqid)||(yield b.genReqId()),n=new Oe(y(r));return b.query(C(C({},e),{},{reqid:r}),C(C({},t),{},{observable:!0})),n});return function(t){return e.apply(this,arguments)}}()});b&&(window.removeEventListener(A.Message,c),p(),n({methods:S,config:r.data.config}))}};window.addEventListener(A.Message,c),(()=>{o("Child: Handshake - Sending SYN");let e={penpal:g.Syn},r=t instanceof RegExp?"*":t;window.parent.postMessage(e,r)})(),a(e=>{window.removeEventListener(A.Message,c),e&&u(e)})}),destroy(){l()}}},$e="trimjs-extension-host";function _e(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`web-ext-${Date.now()}-${Math.random().toString(16).slice(2)}`}function ke(e){if(!e||"object"!=typeof e)return!1;const t=e;return t.source===$e&&1===t.version&&"string"==typeof t.requestId&&("request"===t.kind||"response"===t.kind||"event"===t.kind)}function Te(e){const t=new Error(`NotSupportedInExtensionHost: ${e}`);throw t.code="NotSupportedInExtensionHost",t}function je(e){var t;const r=null!==(t=null==e?void 0:e.timeoutMs)&&void 0!==t?t:1500,n=new Map,i=new Set,o=e=>{if(ke(t=e.data)&&"response"===t.kind){const t=n.get(e.data.requestId);if(!t)return;return n.delete(e.data.requestId),clearTimeout(t.timeoutId),void t.resolve(e.data)}var t;(function(e){return ke(e)&&"event"===e.kind})(e.data)&&i.forEach(t=>{t(e.data)})};return window.addEventListener("message",o),{request:(e,t,i)=>s(function*(){const o=function(e,t){return{source:$e,version:1,kind:"request",requestId:_e(),payload:{method:e,params:t}}}(e,t),s=yield new Promise((t,s)=>{let l;const a=i&&"timeoutMs"in i?i.timeoutMs:r;"number"==typeof a&&a>=0&&(l=setTimeout(()=>{n.delete(o.requestId),s(new Error(`Extension host timeout while calling ${e}`))},a)),n.set(o.requestId,{resolve:t,reject:s,timeoutId:l}),window.postMessage(o,"*")});var l,a;if(!s.payload.ok)throw new Error(null!==(l=null===(a=s.payload.error)||void 0===a?void 0:a.message)&&void 0!==l?l:`Extension host request failed: ${e}`);return s.payload.result})(),onEvent:e=>(i.add(e),()=>{i.delete(e)}),destroy(){window.removeEventListener("message",o),n.forEach(e=>{clearTimeout(e.timeoutId),e.reject(new Error("Extension bridge destroyed"))}),n.clear(),i.clear()}}}function Ne(){return(Ne=s(function*(e){const t=je();try{var r;const i=yield t.request("handshake",{debug:null!==(r=null==e?void 0:e.debug)&&void 0!==r&&r},{timeoutMs:5e3});return n.log("Extension host probe response:",i),!0===i.available}catch(i){return n.log("Extension host probe failed:",i),!1}finally{t.destroy()}})).apply(this,arguments)}function We(){return We=s(function*(){const e=je(),t=new Map;e.onEvent(e=>{const r=t.get(e.payload.event);null==r||r.forEach(t=>{t(e.payload.data)})}),yield e.request("handshake",{},{timeoutMs:5e3});const r=yield e.request("getPlatformConfig",{}),n={bus:{$on(r,n){var i;const o=null!==(i=t.get(r))&&void 0!==i?i:new Set,s=0===o.size;o.add(n),t.set(r,o),s&&e.request("subscribe",{event:r})},$off(r,n){const i=t.get(r);i&&(i.delete(n),0===i.size&&(t.delete(r),e.request("unsubscribe",{event:r})))},$once(e,t){const r=function(){n.bus.$off(e,r),t(...arguments)};n.bus.$on(e,r)},$emit(){Te("bus.$emit")}},genReqId:()=>_e(),query:(t,r)=>e.request("query",{params:t,config:r}),createObservableQuery:(o=s(function*(){return Te("createObservableQuery")}),function(){return o.apply(this,arguments)}),openApp:()=>Te("openApp"),openAppSetting:()=>Te("openAppSetting"),openCustomApp:()=>Te("openCustomApp"),setTitle:()=>Te("setTitle"),pickFile:t=>e.request("pickFile",t,{timeoutMs:null}),pickUserFile:()=>Te("pickUserFile"),pickSharedFile:()=>Te("pickSharedFile"),showFileDetails:(e,t)=>Te("showFileDetails"),authorizeUserFile:e=>Te("authorizeUserFile"),authorizeSharedFile:e=>Te("authorizeSharedFile"),close:(i=s(function*(){e.destroy()}),function(){return i.apply(this,arguments)}),refreshToken:()=>e.request("refreshToken",{}),setExitPageTips:()=>Te("setExitPageTips"),openFileManagerApp:()=>Te("openFileManagerApp"),openFileManager:()=>Te("openFileManager"),openFile:()=>Te("openFile"),getPlatformConfig:()=>Promise.resolve(r),getHostSnapshot:()=>e.request("getHostSnapshot",{})};var i,o,l;return{methods:n,config:(l=r,{appName:"extension-host",os:{version:l.systemVersion,theme:l.theme,language:l.language,format:{date:{date:l.format.date,time:l.format.time}}}})}}),We.apply(this,arguments)}var Ce=null;function xe(){return(xe=s(function*(e){const t=Fe({callTimeouts:{getSessionCredentials:5e3},debug:null==e?void 0:e.debug,timeout:1500});try{const e=yield t.promise;return e}catch(r){return t.destroy(),n.log("Native OS connection probe failed:",r),null}})).apply(this,arguments)}var qe=e=>Ce||(Ce=s(function*(){if("undefined"!=typeof window&&window.parent!==window){const t=yield function(e){return xe.apply(this,arguments)}(e);if(t)return t}return(yield function(e){return Ne.apply(this,arguments)}(e))?function(){return We.apply(this,arguments)}():Fe({callTimeouts:{getSessionCredentials:5e3},debug:null==e?void 0:e.debug}).promise})()),Ie={pickFile:"pick-file",pickUserFile:"pick-user-file",pickSharedFile:"pick-shared-file",authorizeUserFile:"authorize-user-file",authorizeSharedFile:"authorize-shared-file"};var Ue=class{constructor(){r(this,"options",void 0),r(this,"flutterInAppWebView",null),r(this,"osConnector",null),r(this,"initPromise",void 0),r(this,"appApiVersion",void 0),r(this,"isWeb",!0),r(this,"isStandaloneWeb",!1);let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,e.debug&&(n.setDebug(!0),n.log("Trim App initialized with debug mode")),n.log("Options:",e),this.initPromise=this.init()}init(){var e=this;return s(function*(){return n.log("Starting initialization..."),new Promise(t=>{if(i())e.isWeb=!1,n.log("Initializing mobile platform..."),new Promise(e=>{var t;(p?window.flutter_inappwebview:u||(null===(t=window.flutter_inappwebview)||void 0===t?void 0:t._platformReady))?(n.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{n.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)})}).then((r=s(function*(r){yield e.initMobileAppApi(r),n.log("Mobile platform initialized"),t()}),function(e){return r.apply(this,arguments)}));else{if(e.isWeb=!0,e.isStandaloneWeb="undefined"!=typeof window&&window.parent===window,e.isStandaloneWeb)return n.log("Standalone web platform detected; host bridge initialization skipped"),void t();n.log("Initializing web platform..."),qe().then(r=>{e.osConnector=r,n.log("Web platform initialized"),t()})}var r})})()}getWebMethods(){var e;const t=null===(e=this.osConnector)||void 0===e?void 0:e.methods;if(!t)throw new Error("Host bridge is not available outside iframe or app runtime");return t}loadAppMessage(){var e=this;return s(function*(){return e.callAppMethod("getAppMessage")})()}initMobileAppApi(e){var t=this;return s(function*(){t.flutterInAppWebView=e;try{const e=yield t.loadAppMessage();t.appApiVersion=null==e?void 0:e.appApi}catch(r){n.log("Failed to load mobile appApi version:",r),t.appApiVersion=void 0}})()}assertMobileAppApi(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"v1.0";if(!this.isAtLeastVersion(this.appApiVersion,t))throw new Error(`${e} requires appApi >= ${t}`)}isAtLeastVersion(e,t){if(!e)return!1;const r=this.parseVersion(e),n=this.parseVersion(t),i=Math.max(r.length,n.length);for(let l=0;l<i;l+=1){var o,s;const e=null!==(o=r[l])&&void 0!==o?o:0,t=null!==(s=n[l])&&void 0!==s?s:0;if(e>t)return!0;if(e<t)return!1}return!0}parseVersion(e){return e.replace(/^v/i,"").split(".").map(e=>Number.parseInt(e,10)||0)}callAppMethod(e){var t=arguments,r=this;return s(function*(){if(!r.flutterInAppWebView)return null;for(var n=t.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=t[o];return c(r.flutterInAppWebView,e,...i)})()}ready(){var e=this;return s(function*(){return e.initPromise})()}getHostCapabilities(){var e=this;return s(function*(){var t;let r;try{yield Promise.race([e.initPromise,new Promise((e,t)=>{r=setTimeout(()=>t(new Error("Host connection unavailable")),5e3)})])}finally{void 0!==r&&clearTimeout(r)}if(!e.isWeb)return{runtime:"mobile"};const n=null===(t=e.osConnector)||void 0===t||null===(t=t.config)||void 0===t?void 0:t.host;return"desktop"===(null==n?void 0:n.runtime)?a({runtime:"desktop"},1===n.sessionCredentials?{sessionCredentials:1}:{}):{runtime:"web"===(null==n?void 0:n.runtime)?"web":"unknown"}})()}getSessionCredentials(){var e=this;return s(function*(){const t=e=>({code:1,msg:e,error:e,data:null});try{var r,n;const i=yield e.getHostCapabilities(),o=null===(r=e.osConnector)||void 0===r?void 0:r.methods.getSessionCredentials;if("desktop"!==i.runtime||1!==i.sessionCredentials||!o)return t("NOT_SUPPORTED");const s=yield o();return 0===(null==s?void 0:s.code)&&"string"==typeof(null===(n=s.data)||void 0===n?void 0:n.secret)&&s.data.secret?{code:0,msg:"",data:a({secret:s.data.secret},"string"==typeof s.data.token&&s.data.token?{token:s.data.token}:{})}:1===(null==s?void 0:s.code)&&["NOT_SUPPORTED","FORBIDDEN","SESSION_UNAVAILABLE","CONNECTION_CLOSED"].includes(s.error)?t(s.error):t("SESSION_UNAVAILABLE")}catch(i){return t("CONNECTION_CLOSED")}})()}getOptions(){return this.options}setOptions(e){this.options=a(a({},this.options),e),void 0!==e.debug&&n.setDebug(e.debug),n.log("Options updated:",this.options)}getPlatformConfig(){var e=this;return s(function*(){if(yield e.initPromise,e.isWeb){const t=yield e.getWebMethods().getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}if(e.appApiVersion){const t=yield e.callAppMethod("getPlatformConfig");if(!t)throw new Error("Failed to get platform config");return t}const t=yield e.loadAppMessage();if(!t)throw new Error("Failed to get platform config");return e.appApiVersion=t.appApi,{theme:t.nightMode,language:t.language,appVersion:t.appVersion,systemVersion:t.systemVersion,format:{date:t.dateFormat,time:t.timeFormat}}})()}getHostSnapshot(){var e=this;return s(function*(){if(yield e.initPromise,!e.isWeb)throw new Error("getHostSnapshot is not supported on mobile platform");const t=yield e.getWebMethods().getHostSnapshot();if(!t)throw new Error("Failed to get host snapshot");return t})()}getAppAuthBaseUrl(){var e=this;return s(function*(){if("undefined"!=typeof window&&window.parent!==window){const e=document.referrer;if(e)try{return new URL(e).origin}catch(t){n.log("Failed to derive app auth base url from document.referrer:",t)}}if("undefined"!=typeof window)return window.location.origin;if(yield e.initPromise,e.isWeb)try{const t=yield e.getHostSnapshot();if(t.host)return t.host}catch(t){n.log("Failed to derive app auth host snapshot:",t)}throw new Error("Failed to derive app auth base url")})()}buildAppAuthUrl(e,t){var r=this;return s(function*(){return function(e,t,r,n){var i,o;const s=new URL(e,null!==(i=null!=n?n:null===(o=globalThis.location)||void 0===o?void 0:o.origin)&&void 0!==i?i:"http://localhost"),l=Ie[t];if(s.pathname=function(e){return`/app-auth/${e}`}(l),s.searchParams.set("appName",r.appName),r.redirectUri&&s.searchParams.set("redirectUri",r.redirectUri),r.state&&s.searchParams.set("state",r.state),"pickFile"===t||"pickUserFile"===t||"pickSharedFile"===t){var a;const e=r;"pickSharedFile"!==t&&e.directory&&s.searchParams.set("directory","true");const n="pickSharedFile"!==t?e.accept:void 0;(null==n?void 0:n.length)&&s.searchParams.set("accept",n.join(",")),(null===(a=e.sidebarGroup)||void 0===a?void 0:a.length)&&s.searchParams.set("sidebarGroup",e.sidebarGroup.join(","))}else s.searchParams.set("path",r.path);return s.toString()}(yield r.getAppAuthBaseUrl(),e,t,window.location.origin)})()}openAppAuth(e,t,r){var n=this;return s(function*(){if(yield n.initPromise,!n.isWeb)throw new Error("openAppAuth is not supported on mobile platform");const i=yield n.buildAppAuthUrl(e,t);return"_self"===(null==r?void 0:r.target)&&"undefined"!=typeof window?(window.location.assign(i),i):(yield n.openURL(i,null==r?void 0:r.target,null==r?void 0:r.features),i)})()}parseAppAuthCallback(e){return function(e){var t,r,n,i;const o=e instanceof URLSearchParams?e:e instanceof URL?e.searchParams:"string"==typeof e?new URL(e,null!==(t=null===(r=globalThis.location)||void 0===r?void 0:r.origin)&&void 0!==t?t:"http://localhost").searchParams:new URLSearchParams(null!==(n=null===(i=globalThis.location)||void 0===i?void 0:i.search)&&void 0!==n?n:""),s=o.get("method"),l=s&&Object.prototype.hasOwnProperty.call(Ie,s)?s:void 0,a=o.get("path");let u;if(a)try{const e=JSON.parse(a);Array.isArray(e)&&e.every(e=>"string"==typeof e)&&(u=e)}catch(p){u=void 0}return{status:o.get("status")||void 0,error:o.get("error")||void 0,method:l,appName:o.get("appName")||void 0,state:o.get("state")||void 0,path:u}}(e)}setTitle(e){var t=this;return s(function*(){if(yield t.initPromise,n.log("Setting title:",e),document.title=e,t.isWeb)return t.getWebMethods().setTitle(e)})()}setExitPageTips(e){var t=this;return s(function*(){return yield t.initPromise,t.isWeb?t.getWebMethods().setExitPageTips(e):t.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})()}openFile(e){var t=this;return s(function*(){return yield t.initPromise,n.log("Opening file:",e),t.isWeb?t.getWebMethods().openFile(e):t.callAppMethod("openFile",e)})()}openFileManager(e){var t=this;return s(function*(){if(yield t.initPromise,n.log("Opening file manager:",e),t.isWeb){const r=t.getWebMethods();return(r.openFileManager||r.openFileManagerApp)(e)}return t.assertMobileAppApi("openFileManager"),t.callAppMethod("openFileManager",e)})()}showFileDetails(e,t){var r=this;return s(function*(){return yield r.initPromise,r.isWeb?r.getWebMethods().showFileDetails(e,t):(r.assertMobileAppApi("showFileDetails"),r.callAppMethod("showFileDetails",JSON.stringify({paths:e,options:t})))})()}authorizeUserFile(e){var t=this;return s(function*(){var r;return yield t.initPromise,t.isWeb?t.getWebMethods().authorizeUserFile(e):(t.assertMobileAppApi("authorizeUserFile"),null!==(r=yield t.callAppMethod("authorizeUserFile",JSON.stringify({path:e})))&&void 0!==r?r:void 0)})()}authorizeSharedFile(e){var t=this;return s(function*(){var r;return yield t.initPromise,t.isWeb?t.getWebMethods().authorizeSharedFile(e):(t.assertMobileAppApi("authorizeSharedFile"),null!==(r=yield t.callAppMethod("authorizeSharedFile",JSON.stringify({path:e})))&&void 0!==r?r:void 0)})()}openAppSetting(){var e=this;return s(function*(){return yield e.initPromise,n.log("Opening app setting"),e.isWeb?e.getWebMethods().openAppSetting():(e.assertMobileAppApi("openAppSetting"),e.callAppMethod("openAppSetting"))})()}openApp(e){var t=this;return s(function*(){return yield t.initPromise,n.log("Opening app:",e),t.isWeb?t.getWebMethods().openApp(e):!!i()&&t.callAppMethod("openAppPage",e)})()}openCustomApp(e,t){var r=this;return s(function*(){if(yield r.initPromise,n.log("Opening custom app:",e,t),r.isWeb)return r.getWebMethods().openCustomApp(e,t);throw new Error("openCustomApp is not supported on mobile platform")})()}openURL(e,t,r){var i=this;return s(function*(){if(yield i.initPromise,n.log("Opening URL:",e,t,r),!i.isWeb)return i.callAppMethod("openSystemBrowser",e);if("_self"===t)return void window.location.assign(e);if(!r)return void window.open(e,t,r);const o=window.open("",t,r);o&&(o.location.href=e)})()}close(){var e=this;return s(function*(){return yield e.initPromise,e.isWeb?e.getWebMethods().close():e.callAppMethod("exitPage")})()}query(e,t){var r=this;return s(function*(){if(yield r.initPromise,r.isWeb){if(null==t?void 0:t.observable)return r.getWebMethods().createObservableQuery(e,t);const n=yield r.getWebMethods().query(e,t);if(!n)throw new Error("Failed to query");return n}if(r.assertMobileAppApi("query"),null==t?void 0:t.observable){if(!r.flutterInAppWebView)throw new Error("Failed to start observable query");return function(e,t,r){return v(),new f(n=>{let i,o=!1;return c(e,"wsQuery",null==t?void 0:t.req,JSON.stringify(t),void 0===r?void 0:JSON.stringify(r)).then(e=>{(null==e?void 0:e.reqId)?(i=e.reqId,o||h.set(i,n)):n.error(new Error("Failed to start observable query"))},e=>{n.error(e)}),()=>{o=!0,i&&h.delete(i)}})}(r.flutterInAppWebView,e,t)}const n=yield r.callAppMethod("wsQuery",null==e?void 0:e.req,JSON.stringify(e),void 0===t?void 0:JSON.stringify(t));if(!n)throw new Error("Failed to query");if("succ"!==n.result)throw n;return n})()}refreshToken(){var e=this;return s(function*(){if(yield e.initPromise,!e.isWeb)throw new Error("refreshToken is not supported on mobile platform");return e.getWebMethods().refreshToken()})()}$on(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$on is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$on(e,t)})()}$off(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$off is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$off(e,t)})()}$once(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$once is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$once(e,t)})()}pickFile(e){var t=this;return s(function*(){var r,n;return yield t.initPromise,t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.pickFile(e):t.isAtLeastVersion(t.appApiVersion,"v1.0")?null!==(n=yield t.callAppMethod("pickFile",JSON.stringify(e)))&&void 0!==n?n:void 0:t.flutterInAppWebView?function(e,t){return y.apply(this,arguments)}(t.flutterInAppWebView,e):void 0})()}pickUserFile(){var e=arguments,t=this;return s(function*(){var r;let n=e.length>0&&void 0!==e[0]?e[0]:{};return yield t.initPromise,t.isWeb?t.getWebMethods().pickUserFile(n):(t.assertMobileAppApi("pickUserFile"),null!==(r=yield t.callAppMethod("pickUserFile",JSON.stringify(n)))&&void 0!==r?r:void 0)})()}pickSharedFile(){var e=arguments,t=this;return s(function*(){var r;let n=e.length>0&&void 0!==e[0]?e[0]:{};return yield t.initPromise,t.isWeb?t.getWebMethods().pickSharedFile(n):(t.assertMobileAppApi("pickSharedFile"),null!==(r=yield t.callAppMethod("pickSharedFile",JSON.stringify(n)))&&void 0!==r?r:void 0)})()}};exports.TrimApp=Ue,exports.default=Ue;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AuthorizeFileResult, FileDetailsOptions, HostSnapshot, PlatformConfig, TrimAppOptions } from './types';
1
+ import { AuthorizeFileResult, FileDetailsOptions, HostSnapshot, PlatformConfig, TrimAppOptions, HostCapabilities, SessionCredentialsResult } from './types';
2
2
  import { AppAuthMethod, AppAuthParams, AppAuthResult } from './app-auth';
3
3
  import { ObservableLike } from './mobile/index';
4
4
  import { AppBridgeResponse, OpenAppParams, ResponseData, FilePickerParams, QueryConfig } from '@fn/micro-app-postmate';
@@ -10,6 +10,7 @@ export type { FilePickerParams, QueryConfig, ResponseData } from '@fn/micro-app-
10
10
  */
11
11
  export type { PlatformConfig, TrimAppOptions } from './types';
12
12
  export type { HostSnapshot } from './types';
13
+ export type { HostCapabilities, SessionCredentialsResult } from './types';
13
14
  export type { AppBridgeResponse, AuthorizeFileResult, FileDetailsOptions } from './types';
14
15
  export type { AppAuthAuthorizeParams, AppAuthBaseParams, AppAuthCallbackError, AppAuthCallbackStatus, AppAuthMethod, AppAuthMethodParamsMap, AppAuthParams, AppAuthPickFileParams, AppAuthPickSharedFileParams, AppAuthResult, } from './types';
15
16
  /**
@@ -38,6 +39,10 @@ export declare class TrimApp {
38
39
  * @returns Promise
39
40
  */
40
41
  ready(): Promise<void>;
42
+ /** Reads host protocol support, never an application's authorization status. */
43
+ getHostCapabilities(): Promise<HostCapabilities>;
44
+ /** Reads only this official application's Desktop session; never caches credentials. */
45
+ getSessionCredentials(): Promise<SessionCredentialsResult>;
41
46
  /**
42
47
  * 获取配置
43
48
  */
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,r||"default");if("object"!=e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==e(r)?r:r+""}function r(e,r,n){return(r=t(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}var n=new class{constructor(){r(this,"debug",!1)}setDebug(e){this.debug=e}isDebug(){return this.debug}log(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.log("[Trim App]",...t)}}warn(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.warn("[Trim App]",...t)}}error(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.error("[Trim App]",...t)}}info(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.info("[Trim App]",...t)}}};var i=()=>function(e){const t=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,r={};let n;for(;null!==(n=t.exec(e));)n[1]&&(r.fnOSVersion=n[1]),n[2]&&(r.fnAppType=n[2]),n[3]&&(r.fnAppVersion=n[3]);return r}(navigator.userAgent).fnAppVersion;function o(e,t,r,n,i,o,s){try{var l=e[o](s),a=l.value}catch(e){return void r(e)}l.done?t(a):Promise.resolve(a).then(n,i)}function s(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var s=e.apply(t,r);function l(e){o(s,n,i,l,a,"next",e)}function a(e){o(s,n,i,l,a,"throw",e)}l(void 0)})}}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var u=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{u=!0});var p=/(iPad|iPhone|iPod|Macintosh|Mac OS X)/i.test(navigator.userAgent),c=/* @__PURE__ */function(){var e=s(function*(e,t){for(var r=arguments.length,i=new Array(r>2?r-2:0),o=2;o<r;o++)i[o-2]=arguments[o];n.log(`callHandler: ${t}, params: ${i.map(e=>String(e)).join(", ")}`);const s=yield e.callHandler(t,...i);if(s)try{const e=JSON.parse(s);n.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return n.log(`appMessage: ${JSON.stringify(t)}`),t}catch(l){return n.error(`error: ${l}`),null}return null});return function(t,r){return e.apply(this,arguments)}}(),d=/* @__PURE__ */new Map,f=class{constructor(e){r(this,"subscribeFn",void 0),this.subscribeFn=e}subscribe(e,t,r){var n;const i="function"==typeof e?{next:e,error:t,complete:r}:null!=e?e:{};let o=!1;const s=null!==(n=this.subscribeFn({next:e=>{var t;o||(null===(t=i.next)||void 0===t||t.call(i,e))},error:e=>{var t;o||(o=!0,null===(t=i.error)||void 0===t||t.call(i,e))},complete:()=>{var e;o||(o=!0,null===(e=i.complete)||void 0===e||e.call(i))}}))&&void 0!==n?n:()=>{};return{unsubscribe:()=>{o||(o=!0,s())}}}},h=/* @__PURE__ */new Map;function v(){window._flutter_onAppObservableQueryResult=e=>{n.log("_flutter_onAppObservableQueryResult",e);const t=function(e){var t,r;const n="string"==typeof e?JSON.parse(e):e,i=null!==(t=n.reqid)&&void 0!==t?t:n.reqId;return a(a({},n),{},{reqId:null!==(r=n.reqId)&&void 0!==r?r:i,reqid:i})}(e),r=h.get(t.reqId);if(r)if(t.result&&"doing"!==t.result){if("succ"===t.result)return r.next(t),r.complete(),void h.delete(t.reqId);r.error(t),h.delete(t.reqId)}else r.next(t);else n.log("_flutter_onAppObservableQueryResult observer not found",t)}}function y(){return(y=s(function*(e,t){return new Promise((r,i)=>{null==e||e.callHandler("openFolder",JSON.stringify(t)).then(e=>{if(n.log("pickFilePromise callback registered",{reqId:e,params:t}),e){function o(e){r(e.result)}d.set(e,o)}else i(/* @__PURE__ */new Error("openFolder failed"))})})})).apply(this,arguments)}i()&&(window.fnAppMessage=e=>{n.log("app-message",e);const t=JSON.parse(e),r=d.get(t.reqId);r&&(r(t),d.delete(t.reqId))}),i()&&v();var g=/* @__PURE__ */function(e){return e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e}({}),b=/* @__PURE__ */function(e){return e.Fulfilled="fulfilled",e.Rejected="rejected",e}({}),m=/* @__PURE__ */function(e){return e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e}({}),w=/* @__PURE__ */function(e){return e.DataCloneError="DataCloneError",e}({}),A=/* @__PURE__ */function(e){return e.Message="message",e}({}),S=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),P=(e,t,r)=>{let{localName:n,local:i,remote:o,originForSending:s,originForReceiving:l}=e,a=!1,u=e=>{if(e.source!==o||e.data.penpal!==g.Call)return;if("*"!==l&&e.origin!==l)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${l}`);let{methodName:i,args:u,id:p}=e.data;r(`${n}: Received ${i}() call`);let c=e=>t=>{if(r(`${n}: Sending ${i}() reply`),a)return void r(`${n}: Unable to send ${i}() reply due to destroyed connection`);let l={penpal:g.Reply,id:p,resolution:e,returnValue:t};e===b.Rejected&&t instanceof Error&&(l.returnValue=S(t),l.returnValueIsError=!0);try{o.postMessage(l,s)}catch(e){let r=e instanceof Error?e:Error(String(e));if(r.name===w.DataCloneError){let e={penpal:g.Reply,id:p,resolution:b.Rejected,returnValue:S(r),returnValueIsError:!0};o.postMessage(e,s)}throw e}};new Promise(e=>e(t[i].apply(t,u))).then(c(b.Fulfilled),c(b.Rejected))};return i.addEventListener(A.Message,u),()=>{a=!0,i.removeEventListener(A.Message,u)}},O=0,M=()=>++O,E=e=>e?e.split("."):[],F=(e,t,r)=>{let n=E(t);return n.reduce((e,t,i)=>(void 0===e[t]&&(e[t]={}),i===n.length-1&&(e[t]=r),e[t]),e),e},$=(e,t)=>{let r={};return Object.keys(e).forEach(n=>{let i=e[n],o=((e,t)=>{let r=E(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof i&&Object.assign(r,$(i,o)),"function"==typeof i&&(r[o]=i)}),r},_=(e,t,r,n,i)=>{let{localName:o,local:s,remote:l,originForSending:a,originForReceiving:u}=t,p=!1;i(`${o}: Connecting call sender`);let c=e=>(...t)=>{let r;i(`${o}: Sending ${e}() call`);try{l.closed&&(r=!0)}catch(g){r=!0}if(r&&n(),p){let t=/* @__PURE__ */Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=m.ConnectionDestroyed,t}return new Promise((r,n)=>{let p=M(),c=t=>{if(t.source!==l||t.data.penpal!==g.Reply||t.data.id!==p)return;if("*"!==u&&t.origin!==u)return void i(`${o} received message from origin ${t.origin} which did not match expected origin ${u}`);let a=t.data;i(`${o}: Received ${e}() reply`),s.removeEventListener(A.Message,c);let d=a.returnValue;a.returnValueIsError&&(d=(e=>{let t=/* @__PURE__ */Error();return Object.assign(t,e),t})(d)),(a.resolution===b.Fulfilled?r:n)(d)};s.addEventListener(A.Message,c);let d={penpal:g.Call,id:p,methodName:e,args:t};l.postMessage(d,a)})},d=r.reduce((e,t)=>(e[t]=c(t),e),{});return Object.assign(e,(e=>{let t={};for(let r in e)F(t,r,e[r]);return t})(d)),()=>{p=!0}},j=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout(()=>{let r=/* @__PURE__ */Error(`Connection timed out after ${e}ms`);r.code=m.ConnectionTimeout,t(r)},e)),()=>{clearTimeout(r)}};function k(e){return k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},k(e)}function W(e){var t=function(e,t){if("object"!=k(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=k(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==k(t)?t:t+""}function q(e,t,r){return(t=W(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function x(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function N(e){for(var t=1;t<arguments.length;t++){var r=null==arguments[t]?{}:arguments[t];t%2?x(Object(r),!0).forEach(function(t){q(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):x(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var T=(e,t,r,n,i)=>{let{destroy:o,onDestroy:s}=n;return n=>{if(!(e instanceof RegExp?e.test(n.origin):"*"===e||e===n.origin))return void i(`Child: Handshake - Received SYN-ACK from origin ${n.origin} which did not match expected origin ${e}`);i("Child: Handshake - Received SYN-ACK, responding with ACK");let l="null"===n.origin?"*":n.origin,a={penpal:g.Ack,methodNames:Object.keys(t),config:r};window.parent.postMessage(a,l);let u={localName:"Child",local:window,remote:window.parent,originForSending:l,originForReceiving:n.origin},p=P(u,t,i);s(p);let c={},d=_(c,u,n.data.methodNames,o,i);return s(d),c}};function I(e,t){var r;null==(r=console)||r.warn(`[fnApp warn]: ${e}`,t)}function C(e,t){var r;null==(r=console)||r.error(`[fnApp error]: ${e}`,t)}var V="_fn_all_event",U="事件订阅数量为空";function R(e){return R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},R(e)}function D(e){var t=function(e,t){if("object"!=R(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=R(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==R(t)?t:t+""}function z(e,t,r){return(t=D(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var L=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:/* @__PURE__ */new Map,J=class{constructor(e,t){z(this,"id",void 0),z(this,"appName",void 0),z(this,"eventObj",void 0),z(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),L.get(this.id)||L.set(this.id,{}),this.eventObj=L.get(this.id)}$on(e,t){let r=this.eventObj[e];return r?(r.includes(t)||r.push(t),this):(this.eventObj[e]=[t],this)}$onAll(e){return this.$on(V,e)}$once(e,t){t.$__once=!0,this.$on(e,t)}$off(e,t){let r=this.eventObj[e];if(!e||!r||!r.length)return I(`${e} ${U}`),this;let n,i=r.length;for(;i--;)if(n=r[i],n===t){r.splice(i,1);break}return this}$offAll(e){return this.$off(V,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let r=0;return L.forEach(n=>{if(n[e])for(let i=n[e].length-1;i>=0;i--){r++;let o=n[e][i];o.$__once&&n[e].splice(i,1);try{o(...t)}catch(e){C(e)}}if(n._fn_all_event)for(let i=n[V].length-1;i>=0;i--){r++;let o=n[V][i];o.$__once&&n[V].splice(i,1);try{o(...t)}catch(e){C(e)}}}),(!e||0===r)&&I(`${e} ${U}`),this}$clear(){var e;let t=null==(e=L.get(this.id))?{}:e;return Object.keys(t).forEach(e=>delete t[e]),this}},H=function(e,t){return H=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},H(e,t)};function Q(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}H(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function B(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Y(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}function G(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)(n||!(i in t))&&(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}function K(e){return"function"==typeof e}var X=function(e){var t=e(function(e){Error.call(e),e.stack=/* @__PURE__ */Error().stack});return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}(function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map(function(e,t){return t+1+") "+e.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}});function Z(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var ee=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var e,t,r,n,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var s=B(o),l=s.next();!l.done;l=s.next())l.value.remove(this)}catch(t){e={error:t}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else o.remove(this);var a=this.initialTeardown;if(K(a))try{a()}catch(e){i=e instanceof X?e.errors:[e]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var p=B(u),c=p.next();!c.done;c=p.next()){var d=c.value;try{re(d)}catch(e){i=null==i?[]:i,e instanceof X?i=G(G([],Y(i)),Y(e.errors)):i.push(e)}}}catch(e){r={error:e}}finally{try{c&&!c.done&&(n=p.return)&&n.call(p)}finally{if(r)throw r.error}}}if(i)throw new X(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)re(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null==(r=this._finalizers)?[]:r).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&Z(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&Z(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();function te(e){return e instanceof ee||e&&"closed"in e&&K(e.remove)&&K(e.add)&&K(e.unsubscribe)}function re(e){K(e)?e():e.unsubscribe()}ee.EMPTY;var ne=null,ie=null,oe=void 0,se=!1,le=!1,ae={setTimeout:function(e,t){var r=[...arguments].slice(2),n=ae.delegate;return null!=n&&n.setTimeout?n.setTimeout.apply(n,G([e,t],Y(r))):setTimeout.apply(void 0,G([e,t],Y(r)))},clearTimeout:function(e){var t=ae.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function ue(){}var pe=ce("C",void 0,void 0);function ce(e,t,r){return{kind:e,value:t,error:r}}var de=null;var fe=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,te(t)&&t.add(r)):r.destination=we,r}return Q(t,e),t.create=function(e,t,r){return new ge(e,t,r)},t.prototype.next=function(e){this.isStopped?me(function(e){return ce("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?me(function(e){return ce("E",void 0,e)}(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?me(pe,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(ee),he=Function.prototype.bind;function ve(e,t){return he.call(e,t)}var ye=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){be(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){be(e)}else be(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){be(e)}},e}(),ge=function(e){function t(t,r,n){var i,o,s=e.call(this)||this;K(t)||!t?i={next:null==t?void 0:t,error:null==r?void 0:r,complete:null==n?void 0:n}:s&&le?((o=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&ve(t.next,o),error:t.error&&ve(t.error,o),complete:t.complete&&ve(t.complete,o)}):i=t;return s.destination=new ye(i),s}return Q(t,e),t}(fe);function be(e){se?function(e){se&&de&&(de.errorThrown=!0,de.error=e)}(e):function(e){ae.setTimeout(function(){if(!ne)throw e;ne(e)})}(e)}function me(e,t){var r=ie;r&&ae.setTimeout(function(){return r(e,t)})}var we={closed:!0,next:ue,error:function(e){throw e},complete:ue},Ae="function"==typeof Symbol&&Symbol.observable||"@@observable";function Se(e){return e}var Pe=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(e,t,r){var n=this,i=function(e){return e&&e instanceof fe||function(e){return e&&K(e.next)&&K(e.error)&&K(e.complete)}(e)&&te(e)}(e)?e:new ge(e,t,r);return function(e){if(se){var t=!de;if(t&&(de={errorThrown:!1,error:null}),e(),t){var r=de,n=r.errorThrown,i=r.error;if(de=null,n)throw i}}else e()}(function(){var e=n,t=e.operator,r=e.source;i.add(t?t.call(i,r):r?n._subscribe(i):n._trySubscribe(i))}),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(b){e.error(b)}},e.prototype.forEach=function(e,t){var r=this;return new(t=Oe(t))(function(t,n){var i=new ge({next:function(t){try{e(t)}catch(e){n(e),i.unsubscribe()}},error:n,complete:t});r.subscribe(i)})},e.prototype._subscribe=function(e){var t;return null==(t=this.source)?void 0:t.subscribe(e)},e.prototype[Ae]=function(){return this},e.prototype.pipe=function(){return function(e){return 0===e.length?Se:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)}}([...arguments])(this)},e.prototype.toPromise=function(e){var t=this;return new(e=Oe(e))(function(e,r){var n;t.subscribe(function(e){return n=e},function(e){return r(e)},function(){return e(n)})})},e.create=function(t){return new e(t)},e}();function Oe(e){var t;return null==(t=null==e?oe:e)?Promise:t}function Me(e,t,r,n,i,o,s){try{var l=e[o](s),a=l.value}catch(e){return void r(e)}l.done?t(a):Promise.resolve(a).then(n,i)}function Ee(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var o=e.apply(t,r);function s(e){Me(o,n,i,s,l,"next",e)}function l(e){Me(o,n,i,s,l,"throw",e)}s(void 0)})}}var Fe=(e={})=>{let{parentOrigin:t="*",timeout:r,debug:n=!1,config:i={}}=e,o=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(n),s=((e,t)=>{let r=[],n=!1;return{destroy(i){n||(n=!0,t(`${e}: Destroying connection`),r.forEach(e=>{e(i)}))},onDestroy(e){n?e():r.push(e)}}})("App",o),{destroy:l,onDestroy:a}=s;return{promise:new Promise((e,n)=>{let u=j(r,l),p=r=>{if((()=>{try{clearTimeout(void 0)}catch(g){return!1}return!0})()&&r.source===parent&&r.data&&r.data.penpal===g.SynAck){let n=r.data,l=new J(n.id,n.appName),a=new J(n.id+"/api",n.appName),c=n.id,d={},f=e=>"api/"+e,h={$emit:(e,...t)=>{l.getEventCallBackLength(e)>0?l.$pureEmit(e,...t):null==d||d.$off(e,()=>{},!0)},onQueryResult:e=>{a.$pureEmit(f(e.reqid),e)},onOsNotify:e=>{}},v=e=>function(t){let r=f(e);a.$on(r,function e(n){t.next(n),n.reqid&&"succ"===n.result&&(t.complete(),a.$off(r,e))})},y=$(h),g=T(t,y,N(N({},i),{},{postmateVersion:"0.1.3"}),s,o)(r),b={},m=g.bus;if(m){let e=(e,t,r)=>{r?(t.$__once=!0,l.$once(e,t)):l.$on(e,t),b[e]?b[e].push(t):(b[e]=[t],m.$on(e,c))};Object.assign(d,m,{$on:e,$off:(e,t,r)=>{var n;if(b[e]){let r=b[e].indexOf(t);r>-1&&(b[e].splice(r,1),l.$off(e,t))}r&&delete b[e],null!=(n=b[e])&&n.length||(m.$off(e,c),delete b[e])},$once:(t,r)=>{e(t,r,!0)}})}let w=N(N({},g),{},{bus:d,query:function(){var e=Ee(function*(e,t){let r=(null==e?void 0:e.reqid)||(yield g.genReqId());return new Promise((n,i)=>{g.query(N(N({},e),{},{reqid:r}),t).then(e=>{"succ"===(null==e?void 0:e.result)?n(e):i(e)})})});return function(t,r){return e.apply(this,arguments)}}(),createObservableQuery:function(){var e=Ee(function*(e,t={}){let r=(null==e?void 0:e.reqid)||(yield g.genReqId()),n=new Pe(v(r));return g.query(N(N({},e),{},{reqid:r}),N(N({},t),{},{observable:!0})),n});return function(t){return e.apply(this,arguments)}}()});g&&(window.removeEventListener(A.Message,p),u(),e({methods:w,config:r.data.config}))}};window.addEventListener(A.Message,p),(()=>{o("Child: Handshake - Sending SYN");let e={penpal:g.Syn},r=t instanceof RegExp?"*":t;window.parent.postMessage(e,r)})(),a(e=>{window.removeEventListener(A.Message,p),e&&n(e)})}),destroy(){l()}}},$e="trimjs-extension-host";function _e(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`web-ext-${Date.now()}-${Math.random().toString(16).slice(2)}`}function je(e){if(!e||"object"!=typeof e)return!1;const t=e;return t.source===$e&&1===t.version&&"string"==typeof t.requestId&&("request"===t.kind||"response"===t.kind||"event"===t.kind)}function ke(e){const t=/* @__PURE__ */new Error(`NotSupportedInExtensionHost: ${e}`);throw t.code="NotSupportedInExtensionHost",t}function We(e){var t;const r=null!==(t=null==e?void 0:e.timeoutMs)&&void 0!==t?t:1500,n=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set,o=e=>{if(je(t=e.data)&&"response"===t.kind){const t=n.get(e.data.requestId);if(!t)return;return n.delete(e.data.requestId),clearTimeout(t.timeoutId),void t.resolve(e.data)}var t;(function(e){return je(e)&&"event"===e.kind})(e.data)&&i.forEach(t=>{t(e.data)})};return window.addEventListener("message",o),{request:(e,t,i)=>s(function*(){const o=function(e,t){return{source:$e,version:1,kind:"request",requestId:_e(),payload:{method:e,params:t}}}(e,t),s=yield new Promise((t,s)=>{let l;const a=i&&"timeoutMs"in i?i.timeoutMs:r;"number"==typeof a&&a>=0&&(l=setTimeout(()=>{n.delete(o.requestId),s(/* @__PURE__ */new Error(`Extension host timeout while calling ${e}`))},a)),n.set(o.requestId,{resolve:t,reject:s,timeoutId:l}),window.postMessage(o,"*")});var l,a;if(!s.payload.ok)throw new Error(null!==(l=null===(a=s.payload.error)||void 0===a?void 0:a.message)&&void 0!==l?l:`Extension host request failed: ${e}`);return s.payload.result})(),onEvent:e=>(i.add(e),()=>{i.delete(e)}),destroy(){window.removeEventListener("message",o),n.forEach(e=>{clearTimeout(e.timeoutId),e.reject(/* @__PURE__ */new Error("Extension bridge destroyed"))}),n.clear(),i.clear()}}}function qe(){return(qe=s(function*(e){const t=We();try{var r;const i=yield t.request("handshake",{debug:null!==(r=null==e?void 0:e.debug)&&void 0!==r&&r},{timeoutMs:5e3});return n.log("Extension host probe response:",i),!0===i.available}catch(i){return n.log("Extension host probe failed:",i),!1}finally{t.destroy()}})).apply(this,arguments)}function xe(){return xe=s(function*(){const e=We(),t=/* @__PURE__ */new Map;e.onEvent(e=>{const r=t.get(e.payload.event);null==r||r.forEach(t=>{t(e.payload.data)})}),yield e.request("handshake",{},{timeoutMs:5e3});const r=yield e.request("getPlatformConfig",{}),n={bus:{$on(r,n){var i;const o=null!==(i=t.get(r))&&void 0!==i?i:/* @__PURE__ */new Set,s=0===o.size;o.add(n),t.set(r,o),s&&e.request("subscribe",{event:r})},$off(r,n){const i=t.get(r);i&&(i.delete(n),0===i.size&&(t.delete(r),e.request("unsubscribe",{event:r})))},$once(e,t){const r=function(){n.bus.$off(e,r),t(...arguments)};n.bus.$on(e,r)},$emit(){ke("bus.$emit")}},genReqId:()=>_e(),query:(t,r)=>e.request("query",{params:t,config:r}),createObservableQuery:(o=s(function*(){return ke("createObservableQuery")}),function(){return o.apply(this,arguments)}),openApp:()=>ke("openApp"),openAppSetting:()=>ke("openAppSetting"),openCustomApp:()=>ke("openCustomApp"),setTitle:()=>ke("setTitle"),pickFile:t=>e.request("pickFile",t,{timeoutMs:null}),pickUserFile:()=>ke("pickUserFile"),pickSharedFile:()=>ke("pickSharedFile"),showFileDetails:(e,t)=>ke("showFileDetails"),authorizeUserFile:e=>ke("authorizeUserFile"),authorizeSharedFile:e=>ke("authorizeSharedFile"),close:(i=s(function*(){e.destroy()}),function(){return i.apply(this,arguments)}),refreshToken:()=>e.request("refreshToken",{}),setExitPageTips:()=>ke("setExitPageTips"),openFileManagerApp:()=>ke("openFileManagerApp"),openFileManager:()=>ke("openFileManager"),openFile:()=>ke("openFile"),getPlatformConfig:()=>Promise.resolve(r),getHostSnapshot:()=>e.request("getHostSnapshot",{})};var i,o,l;return{methods:n,config:(l=r,{appName:"extension-host",os:{version:l.systemVersion,theme:l.theme,language:l.language,format:{date:{date:l.format.date,time:l.format.time}}}})}}),xe.apply(this,arguments)}var Ne=null;function Te(){return(Te=s(function*(e){const t=Fe({debug:null==e?void 0:e.debug,timeout:1500});try{const e=yield t.promise;return e}catch(r){return t.destroy(),n.log("Native OS connection probe failed:",r),null}})).apply(this,arguments)}var Ie=e=>Ne||(Ne=s(function*(){if("undefined"!=typeof window&&window.parent!==window){const t=yield function(e){return Te.apply(this,arguments)}(e);if(t)return t}return(yield function(e){return qe.apply(this,arguments)}(e))?function(){return xe.apply(this,arguments)}():Fe({debug:null==e?void 0:e.debug}).promise})()),Ce={pickFile:"pick-file",pickUserFile:"pick-user-file",pickSharedFile:"pick-shared-file",authorizeUserFile:"authorize-user-file",authorizeSharedFile:"authorize-shared-file"};var Ve=class{constructor(){r(this,"options",void 0),r(this,"flutterInAppWebView",null),r(this,"osConnector",null),r(this,"initPromise",void 0),r(this,"appApiVersion",void 0),r(this,"isWeb",!0),r(this,"isStandaloneWeb",!1);let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,e.debug&&(n.setDebug(!0),n.log("Trim App initialized with debug mode")),n.log("Options:",e),this.initPromise=this.init()}init(){var e=this;return s(function*(){return n.log("Starting initialization..."),new Promise(t=>{if(i())e.isWeb=!1,n.log("Initializing mobile platform..."),new Promise(e=>{var t;(p?window.flutter_inappwebview:u||(null===(t=window.flutter_inappwebview)||void 0===t?void 0:t._platformReady))?(n.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{n.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)})}).then((r=s(function*(r){yield e.initMobileAppApi(r),n.log("Mobile platform initialized"),t()}),function(e){return r.apply(this,arguments)}));else{if(e.isWeb=!0,e.isStandaloneWeb="undefined"!=typeof window&&window.parent===window,e.isStandaloneWeb)return n.log("Standalone web platform detected; host bridge initialization skipped"),void t();n.log("Initializing web platform..."),Ie().then(r=>{e.osConnector=r,n.log("Web platform initialized"),t()})}var r})})()}getWebMethods(){var e;const t=null===(e=this.osConnector)||void 0===e?void 0:e.methods;if(!t)throw new Error("Host bridge is not available outside iframe or app runtime");return t}loadAppMessage(){var e=this;return s(function*(){return e.callAppMethod("getAppMessage")})()}initMobileAppApi(e){var t=this;return s(function*(){t.flutterInAppWebView=e;try{const e=yield t.loadAppMessage();t.appApiVersion=null==e?void 0:e.appApi}catch(r){n.log("Failed to load mobile appApi version:",r),t.appApiVersion=void 0}})()}assertMobileAppApi(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"v1.0";if(!this.isAtLeastVersion(this.appApiVersion,t))throw new Error(`${e} requires appApi >= ${t}`)}isAtLeastVersion(e,t){if(!e)return!1;const r=this.parseVersion(e),n=this.parseVersion(t),i=Math.max(r.length,n.length);for(let l=0;l<i;l+=1){var o,s;const e=null!==(o=r[l])&&void 0!==o?o:0,t=null!==(s=n[l])&&void 0!==s?s:0;if(e>t)return!0;if(e<t)return!1}return!0}parseVersion(e){return e.replace(/^v/i,"").split(".").map(e=>Number.parseInt(e,10)||0)}callAppMethod(e){var t=arguments,r=this;return s(function*(){if(!r.flutterInAppWebView)return null;for(var n=t.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=t[o];return c(r.flutterInAppWebView,e,...i)})()}ready(){var e=this;return s(function*(){return e.initPromise})()}getOptions(){return this.options}setOptions(e){this.options=a(a({},this.options),e),void 0!==e.debug&&n.setDebug(e.debug),n.log("Options updated:",this.options)}getPlatformConfig(){var e=this;return s(function*(){if(yield e.initPromise,e.isWeb){const t=yield e.getWebMethods().getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}if(e.appApiVersion){const t=yield e.callAppMethod("getPlatformConfig");if(!t)throw new Error("Failed to get platform config");return t}const t=yield e.loadAppMessage();if(!t)throw new Error("Failed to get platform config");return e.appApiVersion=t.appApi,{theme:t.nightMode,language:t.language,appVersion:t.appVersion,systemVersion:t.systemVersion,format:{date:t.dateFormat,time:t.timeFormat}}})()}getHostSnapshot(){var e=this;return s(function*(){if(yield e.initPromise,!e.isWeb)throw new Error("getHostSnapshot is not supported on mobile platform");const t=yield e.getWebMethods().getHostSnapshot();if(!t)throw new Error("Failed to get host snapshot");return t})()}getAppAuthBaseUrl(){var e=this;return s(function*(){if("undefined"!=typeof window&&window.parent!==window){const e=document.referrer;if(e)try{return new URL(e).origin}catch(t){n.log("Failed to derive app auth base url from document.referrer:",t)}}if("undefined"!=typeof window)return window.location.origin;if(yield e.initPromise,e.isWeb)try{const t=yield e.getHostSnapshot();if(t.host)return t.host}catch(t){n.log("Failed to derive app auth host snapshot:",t)}throw new Error("Failed to derive app auth base url")})()}buildAppAuthUrl(e,t){var r=this;return s(function*(){return function(e,t,r,n){var i,o;const s=new URL(e,null!==(i=null!=n?n:null===(o=globalThis.location)||void 0===o?void 0:o.origin)&&void 0!==i?i:"http://localhost"),l=Ce[t];if(s.pathname=function(e){return`/app-auth/${e}`}(l),s.searchParams.set("appName",r.appName),r.redirectUri&&s.searchParams.set("redirectUri",r.redirectUri),r.state&&s.searchParams.set("state",r.state),"pickFile"===t||"pickUserFile"===t||"pickSharedFile"===t){var a;const e=r;"pickSharedFile"!==t&&e.directory&&s.searchParams.set("directory","true");const n="pickSharedFile"!==t?e.accept:void 0;(null==n?void 0:n.length)&&s.searchParams.set("accept",n.join(",")),(null===(a=e.sidebarGroup)||void 0===a?void 0:a.length)&&s.searchParams.set("sidebarGroup",e.sidebarGroup.join(","))}else s.searchParams.set("path",r.path);return s.toString()}(yield r.getAppAuthBaseUrl(),e,t,window.location.origin)})()}openAppAuth(e,t,r){var n=this;return s(function*(){const i=yield n.buildAppAuthUrl(e,t);return"_self"===(null==r?void 0:r.target)&&"undefined"!=typeof window?(window.location.assign(i),i):(yield n.openURL(i,null==r?void 0:r.target,null==r?void 0:r.features),i)})()}parseAppAuthCallback(e){return function(e){var t,r,n,i;const o=e instanceof URLSearchParams?e:e instanceof URL?e.searchParams:"string"==typeof e?new URL(e,null!==(t=null===(r=globalThis.location)||void 0===r?void 0:r.origin)&&void 0!==t?t:"http://localhost").searchParams:new URLSearchParams(null!==(n=null===(i=globalThis.location)||void 0===i?void 0:i.search)&&void 0!==n?n:""),s=o.get("method"),l=s&&Object.prototype.hasOwnProperty.call(Ce,s)?s:void 0,a=o.get("path");let u;if(a)try{const e=JSON.parse(a);Array.isArray(e)&&e.every(e=>"string"==typeof e)&&(u=e)}catch(p){u=void 0}return{status:o.get("status")||void 0,error:o.get("error")||void 0,method:l,appName:o.get("appName")||void 0,state:o.get("state")||void 0,path:u}}(e)}setTitle(e){var t=this;return s(function*(){if(yield t.initPromise,n.log("Setting title:",e),document.title=e,t.isWeb)return t.getWebMethods().setTitle(e)})()}setExitPageTips(e){var t=this;return s(function*(){return yield t.initPromise,t.isWeb?t.getWebMethods().setExitPageTips(e):t.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})()}openFile(e){var t=this;return s(function*(){return yield t.initPromise,n.log("Opening file:",e),t.isWeb?t.getWebMethods().openFile(e):t.callAppMethod("openFile",e)})()}openFileManager(e){var t=this;return s(function*(){if(yield t.initPromise,n.log("Opening file manager:",e),t.isWeb){const r=t.getWebMethods();return(r.openFileManager||r.openFileManagerApp)(e)}return t.assertMobileAppApi("openFileManager"),t.callAppMethod("openFileManager",e)})()}showFileDetails(e,t){var r=this;return s(function*(){return yield r.initPromise,r.isWeb?r.getWebMethods().showFileDetails(e,t):(r.assertMobileAppApi("showFileDetails"),r.callAppMethod("showFileDetails",JSON.stringify({paths:e,options:t})))})()}authorizeUserFile(e){var t=this;return s(function*(){var r;return yield t.initPromise,t.isWeb?t.getWebMethods().authorizeUserFile(e):(t.assertMobileAppApi("authorizeUserFile"),null!==(r=yield t.callAppMethod("authorizeUserFile",JSON.stringify({path:e})))&&void 0!==r?r:void 0)})()}authorizeSharedFile(e){var t=this;return s(function*(){var r;return yield t.initPromise,t.isWeb?t.getWebMethods().authorizeSharedFile(e):(t.assertMobileAppApi("authorizeSharedFile"),null!==(r=yield t.callAppMethod("authorizeSharedFile",JSON.stringify({path:e})))&&void 0!==r?r:void 0)})()}openAppSetting(){var e=this;return s(function*(){return yield e.initPromise,n.log("Opening app setting"),e.isWeb?e.getWebMethods().openAppSetting():(e.assertMobileAppApi("openAppSetting"),e.callAppMethod("openAppSetting"))})()}openApp(e){var t=this;return s(function*(){return yield t.initPromise,n.log("Opening app:",e),t.isWeb?t.getWebMethods().openApp(e):!!i()&&t.callAppMethod("openAppPage",e)})()}openCustomApp(e,t){var r=this;return s(function*(){if(yield r.initPromise,n.log("Opening custom app:",e,t),r.isWeb)return r.getWebMethods().openCustomApp(e,t);throw new Error("openCustomApp is not supported on mobile platform")})()}openURL(e,t,r){var i=this;return s(function*(){if(yield i.initPromise,n.log("Opening URL:",e,t,r),!i.isWeb)return i.callAppMethod("openSystemBrowser",e);if("_self"===t)return void window.location.assign(e);if(!r)return void window.open(e,t,r);const o=window.open("",t,r);o&&(o.location.href=e)})()}close(){var e=this;return s(function*(){return yield e.initPromise,e.isWeb?e.getWebMethods().close():e.callAppMethod("exitPage")})()}query(e,t){var r=this;return s(function*(){if(yield r.initPromise,r.isWeb){if(null==t?void 0:t.observable)return r.getWebMethods().createObservableQuery(e,t);const n=yield r.getWebMethods().query(e,t);if(!n)throw new Error("Failed to query");return n}if(r.assertMobileAppApi("query"),null==t?void 0:t.observable){if(!r.flutterInAppWebView)throw new Error("Failed to start observable query");return function(e,t,r){return v(),new f(n=>{let i,o=!1;return c(e,"wsQuery",null==t?void 0:t.req,JSON.stringify(t),void 0===r?void 0:JSON.stringify(r)).then(e=>{(null==e?void 0:e.reqId)?(i=e.reqId,o||h.set(i,n)):n.error(/* @__PURE__ */new Error("Failed to start observable query"))},e=>{n.error(e)}),()=>{o=!0,i&&h.delete(i)}})}(r.flutterInAppWebView,e,t)}const n=yield r.callAppMethod("wsQuery",null==e?void 0:e.req,JSON.stringify(e),void 0===t?void 0:JSON.stringify(t));if(!n)throw new Error("Failed to query");if("succ"!==n.result)throw n;return n})()}refreshToken(){var e=this;return s(function*(){if(yield e.initPromise,!e.isWeb)throw new Error("refreshToken is not supported on mobile platform");return e.getWebMethods().refreshToken()})()}$on(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$on is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$on(e,t)})()}$off(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$off is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$off(e,t)})()}$once(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$once is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$once(e,t)})()}pickFile(e){var t=this;return s(function*(){var r,n;return yield t.initPromise,t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.pickFile(e):t.isAtLeastVersion(t.appApiVersion,"v1.0")?null!==(n=yield t.callAppMethod("pickFile",JSON.stringify(e)))&&void 0!==n?n:void 0:t.flutterInAppWebView?function(e,t){return y.apply(this,arguments)}(t.flutterInAppWebView,e):void 0})()}pickUserFile(){var e=arguments,t=this;return s(function*(){var r;let n=e.length>0&&void 0!==e[0]?e[0]:{};return yield t.initPromise,t.isWeb?t.getWebMethods().pickUserFile(n):(t.assertMobileAppApi("pickUserFile"),null!==(r=yield t.callAppMethod("pickUserFile",JSON.stringify(n)))&&void 0!==r?r:void 0)})()}pickSharedFile(){var e=arguments,t=this;return s(function*(){var r;let n=e.length>0&&void 0!==e[0]?e[0]:{};return yield t.initPromise,t.isWeb?t.getWebMethods().pickSharedFile(n):(t.assertMobileAppApi("pickSharedFile"),null!==(r=yield t.callAppMethod("pickSharedFile",JSON.stringify(n)))&&void 0!==r?r:void 0)})()}};export{Ve as TrimApp,Ve as default};
1
+ function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,r||"default");if("object"!=e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==e(r)?r:r+""}function r(e,r,n){return(r=t(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}var n=new class{constructor(){r(this,"debug",!1)}setDebug(e){this.debug=e}isDebug(){return this.debug}log(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.log("[Trim App]",...t)}}warn(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.warn("[Trim App]",...t)}}error(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.error("[Trim App]",...t)}}info(){if(this.debug){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.info("[Trim App]",...t)}}};var i=()=>function(e){const t=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,r={};let n;for(;null!==(n=t.exec(e));)n[1]&&(r.fnOSVersion=n[1]),n[2]&&(r.fnAppType=n[2]),n[3]&&(r.fnAppVersion=n[3]);return r}(navigator.userAgent).fnAppVersion;function o(e,t,r,n,i,o,s){try{var l=e[o](s),a=l.value}catch(e){return void r(e)}l.done?t(a):Promise.resolve(a).then(n,i)}function s(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var s=e.apply(t,r);function l(e){o(s,n,i,l,a,"next",e)}function a(e){o(s,n,i,l,a,"throw",e)}l(void 0)})}}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var u=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{u=!0});var c=/(iPad|iPhone|iPod|Macintosh|Mac OS X)/i.test(navigator.userAgent),p=/* @__PURE__ */function(){var e=s(function*(e,t){for(var r=arguments.length,i=new Array(r>2?r-2:0),o=2;o<r;o++)i[o-2]=arguments[o];n.log(`callHandler: ${t}, params: ${i.map(e=>String(e)).join(", ")}`);const s=yield e.callHandler(t,...i);if(s)try{const e=JSON.parse(s);n.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return n.log(`appMessage: ${JSON.stringify(t)}`),t}catch(l){return n.error(`error: ${l}`),null}return null});return function(t,r){return e.apply(this,arguments)}}(),d=/* @__PURE__ */new Map,f=class{constructor(e){r(this,"subscribeFn",void 0),this.subscribeFn=e}subscribe(e,t,r){var n;const i="function"==typeof e?{next:e,error:t,complete:r}:null!=e?e:{};let o=!1;const s=null!==(n=this.subscribeFn({next:e=>{var t;o||(null===(t=i.next)||void 0===t||t.call(i,e))},error:e=>{var t;o||(o=!0,null===(t=i.error)||void 0===t||t.call(i,e))},complete:()=>{var e;o||(o=!0,null===(e=i.complete)||void 0===e||e.call(i))}}))&&void 0!==n?n:()=>{};return{unsubscribe:()=>{o||(o=!0,s())}}}},h=/* @__PURE__ */new Map;function v(){window._flutter_onAppObservableQueryResult=e=>{n.log("_flutter_onAppObservableQueryResult",e);const t=function(e){var t,r;const n="string"==typeof e?JSON.parse(e):e,i=null!==(t=n.reqid)&&void 0!==t?t:n.reqId;return a(a({},n),{},{reqId:null!==(r=n.reqId)&&void 0!==r?r:i,reqid:i})}(e),r=h.get(t.reqId);if(r)if(t.result&&"doing"!==t.result){if("succ"===t.result)return r.next(t),r.complete(),void h.delete(t.reqId);r.error(t),h.delete(t.reqId)}else r.next(t);else n.log("_flutter_onAppObservableQueryResult observer not found",t)}}function y(){return(y=s(function*(e,t){return new Promise((r,i)=>{null==e||e.callHandler("openFolder",JSON.stringify(t)).then(e=>{if(n.log("pickFilePromise callback registered",{reqId:e,params:t}),e){function o(e){r(e.result)}d.set(e,o)}else i(/* @__PURE__ */new Error("openFolder failed"))})})})).apply(this,arguments)}i()&&(window.fnAppMessage=e=>{n.log("app-message",e);const t=JSON.parse(e),r=d.get(t.reqId);r&&(r(t),d.delete(t.reqId))}),i()&&v();var g=/* @__PURE__ */function(e){return e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e}({}),b=/* @__PURE__ */function(e){return e.Fulfilled="fulfilled",e.Rejected="rejected",e}({}),m=/* @__PURE__ */function(e){return e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e}({}),w=/* @__PURE__ */function(e){return e.DataCloneError="DataCloneError",e}({}),A=/* @__PURE__ */function(e){return e.Message="message",e}({}),S=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),O=(e,t,r)=>{let{localName:n,local:i,remote:o,originForSending:s,originForReceiving:l}=e,a=!1,u=e=>{if(e.source!==o||e.data.penpal!==g.Call)return;if("*"!==l&&e.origin!==l)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${l}`);let{methodName:i,args:u,id:c}=e.data;r(`${n}: Received ${i}() call`);let p=e=>t=>{if(r(`${n}: Sending ${i}() reply`),a)return void r(`${n}: Unable to send ${i}() reply due to destroyed connection`);let l={penpal:g.Reply,id:c,resolution:e,returnValue:t};e===b.Rejected&&t instanceof Error&&(l.returnValue=S(t),l.returnValueIsError=!0);try{o.postMessage(l,s)}catch(e){let r=e instanceof Error?e:Error(String(e));if(r.name===w.DataCloneError){let e={penpal:g.Reply,id:c,resolution:b.Rejected,returnValue:S(r),returnValueIsError:!0};o.postMessage(e,s)}throw e}};new Promise(e=>e(t[i].apply(t,u))).then(p(b.Fulfilled),p(b.Rejected))};return i.addEventListener(A.Message,u),()=>{a=!0,i.removeEventListener(A.Message,u)}},P=0,E=()=>++P,M=e=>e?e.split("."):[],F=(e,t,r)=>{let n=M(t);return n.reduce((e,t,i)=>(void 0===e[t]&&(e[t]={}),i===n.length-1&&(e[t]=r),e[t]),e),e},$=(e,t)=>{let r={};return Object.keys(e).forEach(n=>{let i=e[n],o=((e,t)=>{let r=M(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof i&&Object.assign(r,$(i,o)),"function"==typeof i&&(r[o]=i)}),r},_=(e,t,r,n,i)=>{let{localName:o,local:s,remote:l,originForSending:a,originForReceiving:u}=t,c=!1,p=/* @__PURE__ */new Set;i(`${o}: Connecting call sender`);let d=e=>(...r)=>{let d;i(`${o}: Sending ${e}() call`);try{l.closed&&(d=!0)}catch(g){d=!0}if(d&&n(),c){let t=/* @__PURE__ */Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=m.ConnectionDestroyed,t}return new Promise((n,c)=>{var d;let f,h=E(),v=()=>{s.removeEventListener(A.Message,m),void 0!==f&&clearTimeout(f),p.delete(y)},y=()=>{v(),c(/* @__PURE__ */Error("Connection closed"))},m=t=>{var r;if(t.source!==l||(null==(r=t.data)?void 0:r.penpal)!==g.Reply||t.data.id!==h)return;if("*"!==u&&t.origin!==u)return void i(`${o} received message from origin ${t.origin} which did not match expected origin ${u}`);let s=t.data;i(`${o}: Received ${e}() reply`),v();let a=s.returnValue;s.returnValueIsError&&(a=(e=>{let t=/* @__PURE__ */Error();return Object.assign(t,e),t})(a)),(s.resolution===b.Fulfilled?n:c)(a)};s.addEventListener(A.Message,m),p.add(y);let w=null==(d=t.callTimeouts)?void 0:d[e];void 0!==w&&(f=setTimeout(y,w));let S={penpal:g.Call,id:h,methodName:e,args:r};try{l.postMessage(S,a)}catch(g){v(),c(g)}})},f=r.reduce((e,t)=>(e[t]=d(t),e),{});return Object.assign(e,(e=>{let t={};for(let r in e)F(t,r,e[r]);return t})(f)),()=>{c=!0;for(let e of p)e()}},k=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout(()=>{let r=/* @__PURE__ */Error(`Connection timed out after ${e}ms`);r.code=m.ConnectionTimeout,t(r)},e)),()=>{clearTimeout(r)}};function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function j(e){var t=function(e,t){if("object"!=T(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=T(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==T(t)?t:t+""}function N(e,t,r){return(t=j(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function W(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function C(e){for(var t=1;t<arguments.length;t++){var r=null==arguments[t]?{}:arguments[t];t%2?W(Object(r),!0).forEach(function(t){N(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):W(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var q=(e,t,r,n,i,o)=>{let{destroy:s,onDestroy:l}=n;return n=>{if(!(e instanceof RegExp?e.test(n.origin):"*"===e||e===n.origin))return void i(`Child: Handshake - Received SYN-ACK from origin ${n.origin} which did not match expected origin ${e}`);i("Child: Handshake - Received SYN-ACK, responding with ACK");let a="null"===n.origin?"*":n.origin,u={penpal:g.Ack,methodNames:Object.keys(t),config:r};window.parent.postMessage(u,a);let c={callTimeouts:o,localName:"Child",local:window,remote:window.parent,originForSending:a,originForReceiving:n.origin},p=O(c,t,i);l(p);let d={},f=_(d,c,n.data.methodNames,s,i);return l(f),d}};function x(e,t){var r;null==(r=console)||r.warn(`[fnApp warn]: ${e}`,t)}function I(e,t){var r;null==(r=console)||r.error(`[fnApp error]: ${e}`,t)}var U="_fn_all_event",V="事件订阅数量为空";function R(e){return R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},R(e)}function D(e){var t=function(e,t){if("object"!=R(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=R(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==R(t)?t:t+""}function z(e,t,r){return(t=D(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var L=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:/* @__PURE__ */new Map,J=class{constructor(e,t){z(this,"id",void 0),z(this,"appName",void 0),z(this,"eventObj",void 0),z(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),L.get(this.id)||L.set(this.id,{}),this.eventObj=L.get(this.id)}$on(e,t){let r=this.eventObj[e];return r?(r.includes(t)||r.push(t),this):(this.eventObj[e]=[t],this)}$onAll(e){return this.$on(U,e)}$once(e,t){t.$__once=!0,this.$on(e,t)}$off(e,t){let r=this.eventObj[e];if(!e||!r||!r.length)return x(`${e} ${V}`),this;let n,i=r.length;for(;i--;)if(n=r[i],n===t){r.splice(i,1);break}return this}$offAll(e){return this.$off(U,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let r=0;return L.forEach(n=>{if(n[e])for(let i=n[e].length-1;i>=0;i--){r++;let o=n[e][i];o.$__once&&n[e].splice(i,1);try{o(...t)}catch(e){I(e)}}if(n._fn_all_event)for(let i=n[U].length-1;i>=0;i--){r++;let o=n[U][i];o.$__once&&n[U].splice(i,1);try{o(...t)}catch(e){I(e)}}}),(!e||0===r)&&x(`${e} ${V}`),this}$clear(){var e;let t=null==(e=L.get(this.id))?{}:e;return Object.keys(t).forEach(e=>delete t[e]),this}},H=function(e,t){return H=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},H(e,t)};function Q(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}H(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function B(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Y(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}function G(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)(n||!(i in t))&&(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}function K(e){return"function"==typeof e}var X=function(e){var t=e(function(e){Error.call(e),e.stack=/* @__PURE__ */Error().stack});return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}(function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map(function(e,t){return t+1+") "+e.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}});function Z(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var ee=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var e,t,r,n,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var s=B(o),l=s.next();!l.done;l=s.next())l.value.remove(this)}catch(t){e={error:t}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else o.remove(this);var a=this.initialTeardown;if(K(a))try{a()}catch(e){i=e instanceof X?e.errors:[e]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var c=B(u),p=c.next();!p.done;p=c.next()){var d=p.value;try{re(d)}catch(e){i=null==i?[]:i,e instanceof X?i=G(G([],Y(i)),Y(e.errors)):i.push(e)}}}catch(e){r={error:e}}finally{try{p&&!p.done&&(n=c.return)&&n.call(c)}finally{if(r)throw r.error}}}if(i)throw new X(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)re(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null==(r=this._finalizers)?[]:r).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&Z(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&Z(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();function te(e){return e instanceof ee||e&&"closed"in e&&K(e.remove)&&K(e.add)&&K(e.unsubscribe)}function re(e){K(e)?e():e.unsubscribe()}ee.EMPTY;var ne=null,ie=null,oe=void 0,se=!1,le=!1,ae={setTimeout:function(e,t){var r=[...arguments].slice(2),n=ae.delegate;return null!=n&&n.setTimeout?n.setTimeout.apply(n,G([e,t],Y(r))):setTimeout.apply(void 0,G([e,t],Y(r)))},clearTimeout:function(e){var t=ae.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function ue(){}var ce=pe("C",void 0,void 0);function pe(e,t,r){return{kind:e,value:t,error:r}}var de=null;var fe=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,te(t)&&t.add(r)):r.destination=we,r}return Q(t,e),t.create=function(e,t,r){return new ge(e,t,r)},t.prototype.next=function(e){this.isStopped?me(function(e){return pe("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?me(function(e){return pe("E",void 0,e)}(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?me(ce,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(ee),he=Function.prototype.bind;function ve(e,t){return he.call(e,t)}var ye=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){be(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){be(e)}else be(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){be(e)}},e}(),ge=function(e){function t(t,r,n){var i,o,s=e.call(this)||this;K(t)||!t?i={next:null==t?void 0:t,error:null==r?void 0:r,complete:null==n?void 0:n}:s&&le?((o=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&ve(t.next,o),error:t.error&&ve(t.error,o),complete:t.complete&&ve(t.complete,o)}):i=t;return s.destination=new ye(i),s}return Q(t,e),t}(fe);function be(e){se?function(e){se&&de&&(de.errorThrown=!0,de.error=e)}(e):function(e){ae.setTimeout(function(){if(!ne)throw e;ne(e)})}(e)}function me(e,t){var r=ie;r&&ae.setTimeout(function(){return r(e,t)})}var we={closed:!0,next:ue,error:function(e){throw e},complete:ue},Ae="function"==typeof Symbol&&Symbol.observable||"@@observable";function Se(e){return e}var Oe=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(e,t,r){var n=this,i=function(e){return e&&e instanceof fe||function(e){return e&&K(e.next)&&K(e.error)&&K(e.complete)}(e)&&te(e)}(e)?e:new ge(e,t,r);return function(e){if(se){var t=!de;if(t&&(de={errorThrown:!1,error:null}),e(),t){var r=de,n=r.errorThrown,i=r.error;if(de=null,n)throw i}}else e()}(function(){var e=n,t=e.operator,r=e.source;i.add(t?t.call(i,r):r?n._subscribe(i):n._trySubscribe(i))}),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(b){e.error(b)}},e.prototype.forEach=function(e,t){var r=this;return new(t=Pe(t))(function(t,n){var i=new ge({next:function(t){try{e(t)}catch(e){n(e),i.unsubscribe()}},error:n,complete:t});r.subscribe(i)})},e.prototype._subscribe=function(e){var t;return null==(t=this.source)?void 0:t.subscribe(e)},e.prototype[Ae]=function(){return this},e.prototype.pipe=function(){return function(e){return 0===e.length?Se:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)}}([...arguments])(this)},e.prototype.toPromise=function(e){var t=this;return new(e=Pe(e))(function(e,r){var n;t.subscribe(function(e){return n=e},function(e){return r(e)},function(){return e(n)})})},e.create=function(t){return new e(t)},e}();function Pe(e){var t;return null==(t=null==e?oe:e)?Promise:t}function Ee(e,t,r,n,i,o,s){try{var l=e[o](s),a=l.value}catch(e){return void r(e)}l.done?t(a):Promise.resolve(a).then(n,i)}function Me(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var o=e.apply(t,r);function s(e){Ee(o,n,i,s,l,"next",e)}function l(e){Ee(o,n,i,s,l,"throw",e)}s(void 0)})}}var Fe=(e={})=>{let{parentOrigin:t="*",timeout:r,debug:n=!1,config:i={}}=e,o=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(n),s=((e,t)=>{let r=[],n=!1;return{destroy(i){n||(n=!0,t(`${e}: Destroying connection`),r.forEach(e=>{e(i)}))},onDestroy(e){n?e():r.push(e)}}})("App",o),{destroy:l,onDestroy:a}=s;return{promise:new Promise((n,u)=>{let c=k(r,l),p=r=>{if((()=>{try{clearTimeout(void 0)}catch(g){return!1}return!0})()&&r.source===parent&&r.data&&r.data.penpal===g.SynAck){let l=r.data,a=new J(l.id,l.appName),u=new J(l.id+"/api",l.appName),d=l.id,f={},h=e=>"api/"+e,v={$emit:(e,...t)=>{a.getEventCallBackLength(e)>0?a.$pureEmit(e,...t):null==f||f.$off(e,()=>{},!0)},onQueryResult:e=>{u.$pureEmit(h(e.reqid),e)},onOsNotify:e=>{}},y=e=>function(t){let r=h(e);u.$on(r,function e(n){t.next(n),n.reqid&&"succ"===n.result&&(t.complete(),u.$off(r,e))})},g=$(v),b=q(t,g,C(C({},i),{},{postmateVersion:"0.1.5"}),s,o,e.callTimeouts)(r),m={},w=b.bus;if(w){let e=(e,t,r)=>{r?(t.$__once=!0,a.$once(e,t)):a.$on(e,t),m[e]?m[e].push(t):(m[e]=[t],w.$on(e,d))};Object.assign(f,w,{$on:e,$off:(e,t,r)=>{var n;if(m[e]){let r=m[e].indexOf(t);r>-1&&(m[e].splice(r,1),a.$off(e,t))}r&&delete m[e],null!=(n=m[e])&&n.length||(w.$off(e,d),delete m[e])},$once:(t,r)=>{e(t,r,!0)}})}let S=C(C({},b),{},{bus:f,query:function(){var e=Me(function*(e,t){let r=(null==e?void 0:e.reqid)||(yield b.genReqId());return new Promise((n,i)=>{b.query(C(C({},e),{},{reqid:r}),t).then(e=>{"succ"===(null==e?void 0:e.result)?n(e):i(e)})})});return function(t,r){return e.apply(this,arguments)}}(),createObservableQuery:function(){var e=Me(function*(e,t={}){let r=(null==e?void 0:e.reqid)||(yield b.genReqId()),n=new Oe(y(r));return b.query(C(C({},e),{},{reqid:r}),C(C({},t),{},{observable:!0})),n});return function(t){return e.apply(this,arguments)}}()});b&&(window.removeEventListener(A.Message,p),c(),n({methods:S,config:r.data.config}))}};window.addEventListener(A.Message,p),(()=>{o("Child: Handshake - Sending SYN");let e={penpal:g.Syn},r=t instanceof RegExp?"*":t;window.parent.postMessage(e,r)})(),a(e=>{window.removeEventListener(A.Message,p),e&&u(e)})}),destroy(){l()}}},$e="trimjs-extension-host";function _e(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`web-ext-${Date.now()}-${Math.random().toString(16).slice(2)}`}function ke(e){if(!e||"object"!=typeof e)return!1;const t=e;return t.source===$e&&1===t.version&&"string"==typeof t.requestId&&("request"===t.kind||"response"===t.kind||"event"===t.kind)}function Te(e){const t=/* @__PURE__ */new Error(`NotSupportedInExtensionHost: ${e}`);throw t.code="NotSupportedInExtensionHost",t}function je(e){var t;const r=null!==(t=null==e?void 0:e.timeoutMs)&&void 0!==t?t:1500,n=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set,o=e=>{if(ke(t=e.data)&&"response"===t.kind){const t=n.get(e.data.requestId);if(!t)return;return n.delete(e.data.requestId),clearTimeout(t.timeoutId),void t.resolve(e.data)}var t;(function(e){return ke(e)&&"event"===e.kind})(e.data)&&i.forEach(t=>{t(e.data)})};return window.addEventListener("message",o),{request:(e,t,i)=>s(function*(){const o=function(e,t){return{source:$e,version:1,kind:"request",requestId:_e(),payload:{method:e,params:t}}}(e,t),s=yield new Promise((t,s)=>{let l;const a=i&&"timeoutMs"in i?i.timeoutMs:r;"number"==typeof a&&a>=0&&(l=setTimeout(()=>{n.delete(o.requestId),s(/* @__PURE__ */new Error(`Extension host timeout while calling ${e}`))},a)),n.set(o.requestId,{resolve:t,reject:s,timeoutId:l}),window.postMessage(o,"*")});var l,a;if(!s.payload.ok)throw new Error(null!==(l=null===(a=s.payload.error)||void 0===a?void 0:a.message)&&void 0!==l?l:`Extension host request failed: ${e}`);return s.payload.result})(),onEvent:e=>(i.add(e),()=>{i.delete(e)}),destroy(){window.removeEventListener("message",o),n.forEach(e=>{clearTimeout(e.timeoutId),e.reject(/* @__PURE__ */new Error("Extension bridge destroyed"))}),n.clear(),i.clear()}}}function Ne(){return(Ne=s(function*(e){const t=je();try{var r;const i=yield t.request("handshake",{debug:null!==(r=null==e?void 0:e.debug)&&void 0!==r&&r},{timeoutMs:5e3});return n.log("Extension host probe response:",i),!0===i.available}catch(i){return n.log("Extension host probe failed:",i),!1}finally{t.destroy()}})).apply(this,arguments)}function We(){return We=s(function*(){const e=je(),t=/* @__PURE__ */new Map;e.onEvent(e=>{const r=t.get(e.payload.event);null==r||r.forEach(t=>{t(e.payload.data)})}),yield e.request("handshake",{},{timeoutMs:5e3});const r=yield e.request("getPlatformConfig",{}),n={bus:{$on(r,n){var i;const o=null!==(i=t.get(r))&&void 0!==i?i:/* @__PURE__ */new Set,s=0===o.size;o.add(n),t.set(r,o),s&&e.request("subscribe",{event:r})},$off(r,n){const i=t.get(r);i&&(i.delete(n),0===i.size&&(t.delete(r),e.request("unsubscribe",{event:r})))},$once(e,t){const r=function(){n.bus.$off(e,r),t(...arguments)};n.bus.$on(e,r)},$emit(){Te("bus.$emit")}},genReqId:()=>_e(),query:(t,r)=>e.request("query",{params:t,config:r}),createObservableQuery:(o=s(function*(){return Te("createObservableQuery")}),function(){return o.apply(this,arguments)}),openApp:()=>Te("openApp"),openAppSetting:()=>Te("openAppSetting"),openCustomApp:()=>Te("openCustomApp"),setTitle:()=>Te("setTitle"),pickFile:t=>e.request("pickFile",t,{timeoutMs:null}),pickUserFile:()=>Te("pickUserFile"),pickSharedFile:()=>Te("pickSharedFile"),showFileDetails:(e,t)=>Te("showFileDetails"),authorizeUserFile:e=>Te("authorizeUserFile"),authorizeSharedFile:e=>Te("authorizeSharedFile"),close:(i=s(function*(){e.destroy()}),function(){return i.apply(this,arguments)}),refreshToken:()=>e.request("refreshToken",{}),setExitPageTips:()=>Te("setExitPageTips"),openFileManagerApp:()=>Te("openFileManagerApp"),openFileManager:()=>Te("openFileManager"),openFile:()=>Te("openFile"),getPlatformConfig:()=>Promise.resolve(r),getHostSnapshot:()=>e.request("getHostSnapshot",{})};var i,o,l;return{methods:n,config:(l=r,{appName:"extension-host",os:{version:l.systemVersion,theme:l.theme,language:l.language,format:{date:{date:l.format.date,time:l.format.time}}}})}}),We.apply(this,arguments)}var Ce=null;function qe(){return(qe=s(function*(e){const t=Fe({callTimeouts:{getSessionCredentials:5e3},debug:null==e?void 0:e.debug,timeout:1500});try{const e=yield t.promise;return e}catch(r){return t.destroy(),n.log("Native OS connection probe failed:",r),null}})).apply(this,arguments)}var xe=e=>Ce||(Ce=s(function*(){if("undefined"!=typeof window&&window.parent!==window){const t=yield function(e){return qe.apply(this,arguments)}(e);if(t)return t}return(yield function(e){return Ne.apply(this,arguments)}(e))?function(){return We.apply(this,arguments)}():Fe({callTimeouts:{getSessionCredentials:5e3},debug:null==e?void 0:e.debug}).promise})()),Ie={pickFile:"pick-file",pickUserFile:"pick-user-file",pickSharedFile:"pick-shared-file",authorizeUserFile:"authorize-user-file",authorizeSharedFile:"authorize-shared-file"};var Ue=class{constructor(){r(this,"options",void 0),r(this,"flutterInAppWebView",null),r(this,"osConnector",null),r(this,"initPromise",void 0),r(this,"appApiVersion",void 0),r(this,"isWeb",!0),r(this,"isStandaloneWeb",!1);let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,e.debug&&(n.setDebug(!0),n.log("Trim App initialized with debug mode")),n.log("Options:",e),this.initPromise=this.init()}init(){var e=this;return s(function*(){return n.log("Starting initialization..."),new Promise(t=>{if(i())e.isWeb=!1,n.log("Initializing mobile platform..."),new Promise(e=>{var t;(c?window.flutter_inappwebview:u||(null===(t=window.flutter_inappwebview)||void 0===t?void 0:t._platformReady))?(n.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{n.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)})}).then((r=s(function*(r){yield e.initMobileAppApi(r),n.log("Mobile platform initialized"),t()}),function(e){return r.apply(this,arguments)}));else{if(e.isWeb=!0,e.isStandaloneWeb="undefined"!=typeof window&&window.parent===window,e.isStandaloneWeb)return n.log("Standalone web platform detected; host bridge initialization skipped"),void t();n.log("Initializing web platform..."),xe().then(r=>{e.osConnector=r,n.log("Web platform initialized"),t()})}var r})})()}getWebMethods(){var e;const t=null===(e=this.osConnector)||void 0===e?void 0:e.methods;if(!t)throw new Error("Host bridge is not available outside iframe or app runtime");return t}loadAppMessage(){var e=this;return s(function*(){return e.callAppMethod("getAppMessage")})()}initMobileAppApi(e){var t=this;return s(function*(){t.flutterInAppWebView=e;try{const e=yield t.loadAppMessage();t.appApiVersion=null==e?void 0:e.appApi}catch(r){n.log("Failed to load mobile appApi version:",r),t.appApiVersion=void 0}})()}assertMobileAppApi(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"v1.0";if(!this.isAtLeastVersion(this.appApiVersion,t))throw new Error(`${e} requires appApi >= ${t}`)}isAtLeastVersion(e,t){if(!e)return!1;const r=this.parseVersion(e),n=this.parseVersion(t),i=Math.max(r.length,n.length);for(let l=0;l<i;l+=1){var o,s;const e=null!==(o=r[l])&&void 0!==o?o:0,t=null!==(s=n[l])&&void 0!==s?s:0;if(e>t)return!0;if(e<t)return!1}return!0}parseVersion(e){return e.replace(/^v/i,"").split(".").map(e=>Number.parseInt(e,10)||0)}callAppMethod(e){var t=arguments,r=this;return s(function*(){if(!r.flutterInAppWebView)return null;for(var n=t.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=t[o];return p(r.flutterInAppWebView,e,...i)})()}ready(){var e=this;return s(function*(){return e.initPromise})()}getHostCapabilities(){var e=this;return s(function*(){var t;let r;try{yield Promise.race([e.initPromise,new Promise((e,t)=>{r=setTimeout(()=>t(/* @__PURE__ */new Error("Host connection unavailable")),5e3)})])}finally{void 0!==r&&clearTimeout(r)}if(!e.isWeb)return{runtime:"mobile"};const n=null===(t=e.osConnector)||void 0===t||null===(t=t.config)||void 0===t?void 0:t.host;return"desktop"===(null==n?void 0:n.runtime)?a({runtime:"desktop"},1===n.sessionCredentials?{sessionCredentials:1}:{}):{runtime:"web"===(null==n?void 0:n.runtime)?"web":"unknown"}})()}getSessionCredentials(){var e=this;return s(function*(){const t=e=>({code:1,msg:e,error:e,data:null});try{var r,n;const i=yield e.getHostCapabilities(),o=null===(r=e.osConnector)||void 0===r?void 0:r.methods.getSessionCredentials;if("desktop"!==i.runtime||1!==i.sessionCredentials||!o)return t("NOT_SUPPORTED");const s=yield o();return 0===(null==s?void 0:s.code)&&"string"==typeof(null===(n=s.data)||void 0===n?void 0:n.secret)&&s.data.secret?{code:0,msg:"",data:a({secret:s.data.secret},"string"==typeof s.data.token&&s.data.token?{token:s.data.token}:{})}:1===(null==s?void 0:s.code)&&["NOT_SUPPORTED","FORBIDDEN","SESSION_UNAVAILABLE","CONNECTION_CLOSED"].includes(s.error)?t(s.error):t("SESSION_UNAVAILABLE")}catch(i){return t("CONNECTION_CLOSED")}})()}getOptions(){return this.options}setOptions(e){this.options=a(a({},this.options),e),void 0!==e.debug&&n.setDebug(e.debug),n.log("Options updated:",this.options)}getPlatformConfig(){var e=this;return s(function*(){if(yield e.initPromise,e.isWeb){const t=yield e.getWebMethods().getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}if(e.appApiVersion){const t=yield e.callAppMethod("getPlatformConfig");if(!t)throw new Error("Failed to get platform config");return t}const t=yield e.loadAppMessage();if(!t)throw new Error("Failed to get platform config");return e.appApiVersion=t.appApi,{theme:t.nightMode,language:t.language,appVersion:t.appVersion,systemVersion:t.systemVersion,format:{date:t.dateFormat,time:t.timeFormat}}})()}getHostSnapshot(){var e=this;return s(function*(){if(yield e.initPromise,!e.isWeb)throw new Error("getHostSnapshot is not supported on mobile platform");const t=yield e.getWebMethods().getHostSnapshot();if(!t)throw new Error("Failed to get host snapshot");return t})()}getAppAuthBaseUrl(){var e=this;return s(function*(){if("undefined"!=typeof window&&window.parent!==window){const e=document.referrer;if(e)try{return new URL(e).origin}catch(t){n.log("Failed to derive app auth base url from document.referrer:",t)}}if("undefined"!=typeof window)return window.location.origin;if(yield e.initPromise,e.isWeb)try{const t=yield e.getHostSnapshot();if(t.host)return t.host}catch(t){n.log("Failed to derive app auth host snapshot:",t)}throw new Error("Failed to derive app auth base url")})()}buildAppAuthUrl(e,t){var r=this;return s(function*(){return function(e,t,r,n){var i,o;const s=new URL(e,null!==(i=null!=n?n:null===(o=globalThis.location)||void 0===o?void 0:o.origin)&&void 0!==i?i:"http://localhost"),l=Ie[t];if(s.pathname=function(e){return`/app-auth/${e}`}(l),s.searchParams.set("appName",r.appName),r.redirectUri&&s.searchParams.set("redirectUri",r.redirectUri),r.state&&s.searchParams.set("state",r.state),"pickFile"===t||"pickUserFile"===t||"pickSharedFile"===t){var a;const e=r;"pickSharedFile"!==t&&e.directory&&s.searchParams.set("directory","true");const n="pickSharedFile"!==t?e.accept:void 0;(null==n?void 0:n.length)&&s.searchParams.set("accept",n.join(",")),(null===(a=e.sidebarGroup)||void 0===a?void 0:a.length)&&s.searchParams.set("sidebarGroup",e.sidebarGroup.join(","))}else s.searchParams.set("path",r.path);return s.toString()}(yield r.getAppAuthBaseUrl(),e,t,window.location.origin)})()}openAppAuth(e,t,r){var n=this;return s(function*(){if(yield n.initPromise,!n.isWeb)throw new Error("openAppAuth is not supported on mobile platform");const i=yield n.buildAppAuthUrl(e,t);return"_self"===(null==r?void 0:r.target)&&"undefined"!=typeof window?(window.location.assign(i),i):(yield n.openURL(i,null==r?void 0:r.target,null==r?void 0:r.features),i)})()}parseAppAuthCallback(e){return function(e){var t,r,n,i;const o=e instanceof URLSearchParams?e:e instanceof URL?e.searchParams:"string"==typeof e?new URL(e,null!==(t=null===(r=globalThis.location)||void 0===r?void 0:r.origin)&&void 0!==t?t:"http://localhost").searchParams:new URLSearchParams(null!==(n=null===(i=globalThis.location)||void 0===i?void 0:i.search)&&void 0!==n?n:""),s=o.get("method"),l=s&&Object.prototype.hasOwnProperty.call(Ie,s)?s:void 0,a=o.get("path");let u;if(a)try{const e=JSON.parse(a);Array.isArray(e)&&e.every(e=>"string"==typeof e)&&(u=e)}catch(c){u=void 0}return{status:o.get("status")||void 0,error:o.get("error")||void 0,method:l,appName:o.get("appName")||void 0,state:o.get("state")||void 0,path:u}}(e)}setTitle(e){var t=this;return s(function*(){if(yield t.initPromise,n.log("Setting title:",e),document.title=e,t.isWeb)return t.getWebMethods().setTitle(e)})()}setExitPageTips(e){var t=this;return s(function*(){return yield t.initPromise,t.isWeb?t.getWebMethods().setExitPageTips(e):t.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})()}openFile(e){var t=this;return s(function*(){return yield t.initPromise,n.log("Opening file:",e),t.isWeb?t.getWebMethods().openFile(e):t.callAppMethod("openFile",e)})()}openFileManager(e){var t=this;return s(function*(){if(yield t.initPromise,n.log("Opening file manager:",e),t.isWeb){const r=t.getWebMethods();return(r.openFileManager||r.openFileManagerApp)(e)}return t.assertMobileAppApi("openFileManager"),t.callAppMethod("openFileManager",e)})()}showFileDetails(e,t){var r=this;return s(function*(){return yield r.initPromise,r.isWeb?r.getWebMethods().showFileDetails(e,t):(r.assertMobileAppApi("showFileDetails"),r.callAppMethod("showFileDetails",JSON.stringify({paths:e,options:t})))})()}authorizeUserFile(e){var t=this;return s(function*(){var r;return yield t.initPromise,t.isWeb?t.getWebMethods().authorizeUserFile(e):(t.assertMobileAppApi("authorizeUserFile"),null!==(r=yield t.callAppMethod("authorizeUserFile",JSON.stringify({path:e})))&&void 0!==r?r:void 0)})()}authorizeSharedFile(e){var t=this;return s(function*(){var r;return yield t.initPromise,t.isWeb?t.getWebMethods().authorizeSharedFile(e):(t.assertMobileAppApi("authorizeSharedFile"),null!==(r=yield t.callAppMethod("authorizeSharedFile",JSON.stringify({path:e})))&&void 0!==r?r:void 0)})()}openAppSetting(){var e=this;return s(function*(){return yield e.initPromise,n.log("Opening app setting"),e.isWeb?e.getWebMethods().openAppSetting():(e.assertMobileAppApi("openAppSetting"),e.callAppMethod("openAppSetting"))})()}openApp(e){var t=this;return s(function*(){return yield t.initPromise,n.log("Opening app:",e),t.isWeb?t.getWebMethods().openApp(e):!!i()&&t.callAppMethod("openAppPage",e)})()}openCustomApp(e,t){var r=this;return s(function*(){if(yield r.initPromise,n.log("Opening custom app:",e,t),r.isWeb)return r.getWebMethods().openCustomApp(e,t);throw new Error("openCustomApp is not supported on mobile platform")})()}openURL(e,t,r){var i=this;return s(function*(){if(yield i.initPromise,n.log("Opening URL:",e,t,r),!i.isWeb)return i.callAppMethod("openSystemBrowser",e);if("_self"===t)return void window.location.assign(e);if(!r)return void window.open(e,t,r);const o=window.open("",t,r);o&&(o.location.href=e)})()}close(){var e=this;return s(function*(){return yield e.initPromise,e.isWeb?e.getWebMethods().close():e.callAppMethod("exitPage")})()}query(e,t){var r=this;return s(function*(){if(yield r.initPromise,r.isWeb){if(null==t?void 0:t.observable)return r.getWebMethods().createObservableQuery(e,t);const n=yield r.getWebMethods().query(e,t);if(!n)throw new Error("Failed to query");return n}if(r.assertMobileAppApi("query"),null==t?void 0:t.observable){if(!r.flutterInAppWebView)throw new Error("Failed to start observable query");return function(e,t,r){return v(),new f(n=>{let i,o=!1;return p(e,"wsQuery",null==t?void 0:t.req,JSON.stringify(t),void 0===r?void 0:JSON.stringify(r)).then(e=>{(null==e?void 0:e.reqId)?(i=e.reqId,o||h.set(i,n)):n.error(/* @__PURE__ */new Error("Failed to start observable query"))},e=>{n.error(e)}),()=>{o=!0,i&&h.delete(i)}})}(r.flutterInAppWebView,e,t)}const n=yield r.callAppMethod("wsQuery",null==e?void 0:e.req,JSON.stringify(e),void 0===t?void 0:JSON.stringify(t));if(!n)throw new Error("Failed to query");if("succ"!==n.result)throw n;return n})()}refreshToken(){var e=this;return s(function*(){if(yield e.initPromise,!e.isWeb)throw new Error("refreshToken is not supported on mobile platform");return e.getWebMethods().refreshToken()})()}$on(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$on is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$on(e,t)})()}$off(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$off is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$off(e,t)})()}$once(e,t){var r=this;return s(function*(){if(yield r.initPromise,!r.isWeb)throw new Error("$once is not supported on mobile platform");const n=r.getWebMethods().bus;if(!n)throw new Error("bus is not available");n.$once(e,t)})()}pickFile(e){var t=this;return s(function*(){var r,n;return yield t.initPromise,t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.pickFile(e):t.isAtLeastVersion(t.appApiVersion,"v1.0")?null!==(n=yield t.callAppMethod("pickFile",JSON.stringify(e)))&&void 0!==n?n:void 0:t.flutterInAppWebView?function(e,t){return y.apply(this,arguments)}(t.flutterInAppWebView,e):void 0})()}pickUserFile(){var e=arguments,t=this;return s(function*(){var r;let n=e.length>0&&void 0!==e[0]?e[0]:{};return yield t.initPromise,t.isWeb?t.getWebMethods().pickUserFile(n):(t.assertMobileAppApi("pickUserFile"),null!==(r=yield t.callAppMethod("pickUserFile",JSON.stringify(n)))&&void 0!==r?r:void 0)})()}pickSharedFile(){var e=arguments,t=this;return s(function*(){var r;let n=e.length>0&&void 0!==e[0]?e[0]:{};return yield t.initPromise,t.isWeb?t.getWebMethods().pickSharedFile(n):(t.assertMobileAppApi("pickSharedFile"),null!==(r=yield t.callAppMethod("pickSharedFile",JSON.stringify(n)))&&void 0!==r?r:void 0)})()}};export{Ue as TrimApp,Ue as default};
package/dist/types.d.ts CHANGED
@@ -30,6 +30,24 @@ export interface HostSnapshot {
30
30
  }>;
31
31
  errorMessage?: string;
32
32
  }
33
+ /** Protocol support only; the host authorizes each request independently. */
34
+ export interface HostCapabilities {
35
+ runtime: 'desktop' | 'web' | 'mobile' | 'unknown';
36
+ sessionCredentials?: 1;
37
+ }
38
+ export type SessionCredentialsResult = {
39
+ code: 0;
40
+ msg: string;
41
+ data: {
42
+ secret: string;
43
+ token?: string;
44
+ };
45
+ } | {
46
+ code: 1;
47
+ msg: string;
48
+ error: 'NOT_SUPPORTED' | 'FORBIDDEN' | 'SESSION_UNAVAILABLE' | 'CONNECTION_CLOSED';
49
+ data: null;
50
+ };
33
51
  export interface FileDetailsOptions {
34
52
  admin?: boolean;
35
53
  }
@@ -1,6 +1,7 @@
1
1
  import { OSConfig, OSMethods, ConnectionResult, FilePickerParams } from '@fn/micro-app-postmate';
2
- import { AppBridgeResponse, AuthorizeFileResult, FileDetailsOptions, HostSnapshot, PlatformConfig, TrimAppOptions } from '../types';
2
+ import { AppBridgeResponse, AuthorizeFileResult, FileDetailsOptions, HostSnapshot, PlatformConfig, TrimAppOptions, SessionCredentialsResult } from '../types';
3
3
  type HostMethods = OSMethods & {
4
+ getSessionCredentials?: () => Promise<SessionCredentialsResult>;
4
5
  setExitPageTips: (params?: {
5
6
  title?: string;
6
7
  content?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trimjs/web-app",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "web app sdk for nas",
5
5
  "files": [
6
6
  "dist"
@@ -19,24 +19,24 @@
19
19
  "publishConfig": {
20
20
  "access": "public"
21
21
  },
22
+ "devDependencies": {
23
+ "@babel/preset-env": "^7.21.4",
24
+ "@rollup/plugin-babel": "^6.1.0",
25
+ "@typescript/typescript6": "^6.0.2",
26
+ "terser": "^5.46.0",
27
+ "typescript": "7.0.2",
28
+ "vite": "^8.1.5",
29
+ "vite-plugin-dts": "^5.0.3",
30
+ "vite-plus": "^0.2.5",
31
+ "vitest": "latest",
32
+ "@fn/micro-app-event": "0.0.1",
33
+ "@fn/micro-app-postmate": "0.1.5"
34
+ },
22
35
  "scripts": {
23
36
  "dev": "vp dev",
24
37
  "build": "vp build",
25
38
  "lint": "vp lint .",
26
39
  "test": "vp test",
27
40
  "typecheck": "tsc --noEmit"
28
- },
29
- "devDependencies": {
30
- "@babel/preset-env": "^7.21.4",
31
- "@fn/micro-app-event": "workspace:*",
32
- "@fn/micro-app-postmate": "workspace:*",
33
- "@rollup/plugin-babel": "^6.1.0",
34
- "@typescript/typescript6": "catalog:",
35
- "terser": "^5.46.0",
36
- "typescript": "catalog:",
37
- "vite": "catalog:",
38
- "vite-plugin-dts": "catalog:",
39
- "vite-plus": "catalog:",
40
- "vitest": "catalog:"
41
41
  }
42
- }
42
+ }