@trimjs/web-app 0.3.2 → 0.4.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
@@ -239,7 +239,8 @@ Opens the host file picker.
239
239
  ```ts
240
240
  const files = await app.pickFile({
241
241
  multiple: true,
242
- accept: ['.pdf', 'image/*'],
242
+ accept: ['.pdf', '.jpg', '.jpeg', '.png', '.gif', '.webp'],
243
+ sidebarGroup: ['myFiles', 'external'],
243
244
  title: 'Select files',
244
245
  });
245
246
  ```
@@ -250,7 +251,8 @@ Common `FilePickerParams` fields:
250
251
  | --------------- | ---------- | --------------------------------------------------- |
251
252
  | `multiple` | `boolean` | Allows selecting multiple files. |
252
253
  | `directory` | `boolean` | Allows selecting folders instead of files. |
253
- | `accept` | `string[]` | Accepted file extensions or MIME types. |
254
+ | `accept` | `string[]` | Accepted file extensions, each prefixed with `.`. |
255
+ | `sidebarGroup` | `string[]` | Sidebar groups to show, in display order. |
254
256
  | `title` | `string` | Picker title. |
255
257
  | `okText` | `string` | Confirm button text. |
256
258
  | `creatable` | `boolean` | Allows creating folders when supported by the host. |
@@ -269,6 +271,7 @@ Opens the shared file picker and authorizes the selected shared paths for the cu
269
271
  ```ts
270
272
  const result = await app.pickSharedFile({
271
273
  title: 'Select shared folder',
274
+ sidebarGroup: ['myFiles', 'otherShare'],
272
275
  });
273
276
 
274
277
  console.log(result?.data);
@@ -302,7 +305,8 @@ App Auth routes are useful when an app needs to start a file authorization or fi
302
305
 
303
306
  ```ts
304
307
  openAppAuth(
305
- request: AppAuthRequest,
308
+ method: AppAuthMethod,
309
+ params: AppAuthParams,
306
310
  options?: { target?: string; features?: string },
307
311
  ): Promise<string>
308
312
  ```
@@ -310,9 +314,7 @@ openAppAuth(
310
314
  Starts an App Auth route flow. The returned string is the URL that was opened.
311
315
 
312
316
  ```ts
313
- await app.openAppAuth({
314
- routeMethod: 'pick-file',
315
- method: 'pickFile',
317
+ await app.openAppAuth('pickFile', {
316
318
  appName: 'trim.demo',
317
319
  directory: true,
318
320
  redirectUri: '/callback',
@@ -320,14 +322,14 @@ await app.openAppAuth({
320
322
  });
321
323
  ```
322
324
 
323
- Supported `routeMethod` values:
325
+ Supported method names and their internal routes:
324
326
 
325
- | routeMethod | method |
326
- | ----------------------- | --------------------- |
327
- | `pick-file` | `pickFile` |
328
- | `pick-shared-file` | `pickSharedFile` |
329
- | `authorize-user-file` | `authorizeUserFile` |
330
- | `authorize-shared-file` | `authorizeSharedFile` |
327
+ | method | route |
328
+ | --------------------- | --------------------------------- |
329
+ | `pickFile` | `/app-auth/pick-file` |
330
+ | `pickSharedFile` | `/app-auth/pick-shared-file` |
331
+ | `authorizeUserFile` | `/app-auth/authorize-user-file` |
332
+ | `authorizeSharedFile` | `/app-auth/authorize-shared-file` |
331
333
 
332
334
  ### parseAppAuthCallback
333
335
 
@@ -348,15 +350,13 @@ console.log(result.state);
348
350
  ### buildAppAuthUrl
349
351
 
350
352
  ```ts
351
- buildAppAuthUrl(request: AppAuthRequest): Promise<string>
353
+ buildAppAuthUrl(method: AppAuthMethod, params: AppAuthParams): Promise<string>
352
354
  ```
353
355
 
354
356
  Builds an App Auth route URL without opening it. Most apps should use `openAppAuth()` directly. Use this helper only when you need to control navigation yourself.
355
357
 
356
358
  ```ts
357
- const url = await app.buildAppAuthUrl({
358
- routeMethod: 'authorize-user-file',
359
- method: 'authorizeUserFile',
359
+ const url = await app.buildAppAuthUrl('authorizeUserFile', {
360
360
  appName: 'trim.demo',
361
361
  path: '/vol1/1000/photos',
362
362
  redirectUri: '/callback',
@@ -385,15 +385,16 @@ Indicates whether the current runtime is a standalone browser page without an if
385
385
 
386
386
  ```ts
387
387
  import type {
388
- AppAuthAuthorizeRequest,
389
- AppAuthBaseRequest,
388
+ AppAuthAuthorizeParams,
389
+ AppAuthBaseParams,
390
390
  AppAuthCallbackError,
391
391
  AppAuthCallbackStatus,
392
392
  AppAuthMethod,
393
- AppAuthPickRequest,
394
- AppAuthRequest,
393
+ AppAuthMethodParamsMap,
394
+ AppAuthParams,
395
+ AppAuthPickFileParams,
396
+ AppAuthPickSharedFileParams,
395
397
  AppAuthResult,
396
- AppAuthRouteMethod,
397
398
  AppBridgeResponse,
398
399
  AuthorizeFileResult,
399
400
  FileDetailsOptions,
@@ -0,0 +1,52 @@
1
+ import { FilePickerParams } from '@fn/micro-app-postmate';
2
+ export declare const appAuthMethodRouteMap: {
3
+ readonly pickFile: "pick-file";
4
+ readonly pickSharedFile: "pick-shared-file";
5
+ readonly authorizeUserFile: "authorize-user-file";
6
+ readonly authorizeSharedFile: "authorize-shared-file";
7
+ };
8
+ export type AppAuthMethod = keyof typeof appAuthMethodRouteMap;
9
+ export type AppAuthRouteMethod = (typeof appAuthMethodRouteMap)[AppAuthMethod];
10
+ export type AppAuthPickRouteMethod = Extract<AppAuthRouteMethod, 'pick-file' | 'pick-shared-file'>;
11
+ export type AppAuthAuthorizeRouteMethod = Extract<AppAuthRouteMethod, 'authorize-user-file' | 'authorize-shared-file'>;
12
+ export type AppAuthCallbackStatus = 'success' | 'cancel' | 'error';
13
+ export type AppAuthCallbackError = 'access_denied';
14
+ export interface AppAuthBaseParams {
15
+ appName: string;
16
+ redirectUri?: string;
17
+ state?: string;
18
+ }
19
+ export interface AppAuthPickFileParams extends AppAuthBaseParams {
20
+ directory?: boolean;
21
+ accept?: string[];
22
+ sidebarGroup?: FilePickerParams['sidebarGroup'];
23
+ }
24
+ export interface AppAuthPickSharedFileParams extends AppAuthBaseParams {
25
+ sidebarGroup?: FilePickerParams['sidebarGroup'];
26
+ }
27
+ export interface AppAuthAuthorizeParams extends AppAuthBaseParams {
28
+ path: string;
29
+ }
30
+ export interface AppAuthMethodParamsMap {
31
+ pickFile: AppAuthPickFileParams;
32
+ pickSharedFile: AppAuthPickSharedFileParams;
33
+ authorizeUserFile: AppAuthAuthorizeParams;
34
+ authorizeSharedFile: AppAuthAuthorizeParams;
35
+ }
36
+ export type AppAuthParams<TMethod extends AppAuthMethod = AppAuthMethod> = AppAuthMethodParamsMap[TMethod];
37
+ export interface AppAuthResult {
38
+ status?: AppAuthCallbackStatus;
39
+ error?: AppAuthCallbackError;
40
+ method?: AppAuthMethod;
41
+ appName?: string;
42
+ state?: string;
43
+ }
44
+ export declare function createAppAuthPath(routeMethod: AppAuthRouteMethod): string;
45
+ export declare function buildAppAuthUrl<TMethod extends AppAuthMethod>(baseUrl: string, method: TMethod, params: AppAuthParams<NoInfer<TMethod>>, locationOrigin?: string): string;
46
+ export declare function parseAppAuthCallback(input?: string | URL | URLSearchParams): {
47
+ status: AppAuthResult["status"];
48
+ error: AppAuthResult["error"];
49
+ method: "pickFile" | "pickSharedFile" | "authorizeUserFile" | "authorizeSharedFile" | undefined;
50
+ appName: string | undefined;
51
+ state: string | undefined;
52
+ };
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 a=e[o](s),l=a.value}catch(e){return void r(e)}a.done?t(l):Promise.resolve(l).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 a(e){o(s,n,i,a,l,"next",e)}function l(e){o(s,n,i,a,l,"throw",e)}a(void 0)})}}var a=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{a=!0});var l=/(iPad|iPhone|iPod|Macintosh|Mac OS X)/i.test(navigator.userAgent),u=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(a){return n.error(`error: ${a}`),null}return null});return function(t,r){return e.apply(this,arguments)}}(),p=new Map;function c(){return(c=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){p.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=p.get(t.reqId);r&&(r(t),p.delete(t.reqId))});var d=function(e){return e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e}({}),f=function(e){return e.Fulfilled="fulfilled",e.Rejected="rejected",e}({}),h=function(e){return e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e}({}),v=function(e){return e.DataCloneError="DataCloneError",e}({}),g=function(e){return e.Message="message",e}({}),y=(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)}}},b=e=>(...t)=>{e&&console.log("[Penpal]",...t)},m=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),w=(e,t,r)=>{let{localName:n,local:i,remote:o,originForSending:s,originForReceiving:a}=e,l=!1,u=e=>{if(e.source!==o||e.data.penpal!==d.Call)return;if("*"!==a&&e.origin!==a)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${a}`);let{methodName:i,args:u,id:p}=e.data;r(`${n}: Received ${i}() call`);let c=e=>t=>{if(r(`${n}: Sending ${i}() reply`),l)return void r(`${n}: Unable to send ${i}() reply due to destroyed connection`);let a={penpal:d.Reply,id:p,resolution:e,returnValue:t};e===f.Rejected&&t instanceof Error&&(a.returnValue=m(t),a.returnValueIsError=!0);try{o.postMessage(a,s)}catch(e){if(e.name===v.DataCloneError){let r={penpal:d.Reply,id:p,resolution:f.Rejected,returnValue:m(e),returnValueIsError:!0};o.postMessage(r,s)}throw e}};new Promise(e=>e(t[i].apply(t,u))).then(c(f.Fulfilled),c(f.Rejected))};return i.addEventListener(g.Message,u),()=>{l=!0,i.removeEventListener(g.Message,u)}},A=0,S=()=>++A,P=e=>e?e.split("."):[],M=(e,t,r)=>{let n=P(t);return n.reduce((e,t,i)=>(void 0===e[t]&&(e[t]={}),i===n.length-1&&(e[t]=r),e[t]),e),e},O=(e,t)=>{let r={};return Object.keys(e).forEach(n=>{let i=e[n],o=((e,t)=>{let r=P(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof i&&Object.assign(r,O(i,o)),"function"==typeof i&&(r[o]=i)}),r},E=(e,t,r,n,i)=>{let{localName:o,local:s,remote:a,originForSending:l,originForReceiving:u}=t,p=!1;i(`${o}: Connecting call sender`);let c=e=>(...t)=>{let r;i(`${o}: Sending ${e}() call`);try{a.closed&&(r=!0)}catch(d){r=!0}if(r&&n(),p){let t=Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=h.ConnectionDestroyed,t}return new Promise((r,n)=>{let p=S(),c=t=>{if(t.source!==a||t.data.penpal!==d.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 l=t.data;i(`${o}: Received ${e}() reply`),s.removeEventListener(g.Message,c);let h=l.returnValue;l.returnValueIsError&&(h=(e=>{let t=Error();return Object.assign(t,e),t})(h)),(l.resolution===f.Fulfilled?r:n)(h)};s.addEventListener(g.Message,c);let h={penpal:d.Call,id:p,methodName:e,args:t};a.postMessage(h,l)})},v=r.reduce((e,t)=>(e[t]=c(t),e),{});return Object.assign(e,(e=>{let t={};for(let r in e)M(t,r,e[r]);return t})(v)),()=>{p=!0}},$=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout(()=>{let r=Error(`Connection timed out after ${e}ms`);r.code=h.ConnectionTimeout,t(r)},e)),()=>{clearTimeout(r)}};function F(e){return F="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},F(e)}function _(e){var t=function(e,t){if("object"!=F(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=F(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==F(t)?t:t+""}function j(e,t,r){return(t=_(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function k(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 W(e){for(var t=1;t<arguments.length;t++){var r=null==arguments[t]?{}:arguments[t];t%2?k(Object(r),!0).forEach(function(t){j(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):k(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 a="null"===n.origin?"*":n.origin,l={penpal:d.Ack,methodNames:Object.keys(t),config:r};window.parent.postMessage(l,a);let u={localName:"Child",local:window,remote:window.parent,originForSending:a,originForReceiving:n.origin};s(w(u,t,i));let p={};return s(E(p,u,n.data.methodNames,o,i)),p}};function x(e,t){var r;null==(r=console)||r.warn(`[fnApp warn]: ${e}`,t)}function N(e,t){var r;null==(r=console)||r.error(`[fnApp error]: ${e}`,t)}var q="_fn_all_event",C="事件订阅数量为空";function V(e){return V="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},V(e)}function I(e){var t=function(e,t){if("object"!=V(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=V(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==V(t)?t:t+""}function R(e,t,r){return(t=I(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var D=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map,z=class{constructor(e,t){R(this,"id",void 0),R(this,"appName",void 0),R(this,"eventObj",void 0),R(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),D.get(this.id)||D.set(this.id,{}),this.eventObj=D.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(q,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} ${C}`),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(q,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let r=0;return D.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){N(e)}}if(n._fn_all_event)for(let i=n[q].length-1;i>=0;i--){r++;let o=n[q][i];o.$__once&&n[q].splice(i,1);try{o(...t)}catch(e){N(e)}}}),(!e||0===r)&&x(`${e} ${C}`),this}$clear(){var e;let t=null==(e=D.get(this.id))?{}:e;return Object.keys(t).forEach(e=>delete t[e]),this}},U=function(e,t){return U=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])},U(e,t)};function L(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}U(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function H(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 J(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 B(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 Y(e){return"function"==typeof e}var Q=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 K(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var X=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=H(o),a=s.next();!a.done;a=s.next())a.value.remove(this)}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else o.remove(this);var l=this.initialTeardown;if(Y(l))try{l()}catch(e){i=e instanceof Q?e.errors:[e]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var p=H(u),c=p.next();!c.done;c=p.next()){var d=c.value;try{Z(d)}catch(e){i=null==i?[]:i,e instanceof Q?i=B(B([],J(i)),J(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 Q(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)Z(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)&&K(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&K(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();function G(e){return e instanceof X||e&&"closed"in e&&Y(e.remove)&&Y(e.add)&&Y(e.unsubscribe)}function Z(e){Y(e)?e():e.unsubscribe()}X.EMPTY;var ee=null,te=null,re=void 0,ne=!1,ie=!1,oe={setTimeout:function(e,t){var r=[...arguments].slice(2),n=oe.delegate;return null!=n&&n.setTimeout?n.setTimeout.apply(n,B([e,t],J(r))):setTimeout.apply(void 0,B([e,t],J(r)))},clearTimeout:function(e){var t=oe.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function se(){}var ae=le("C",void 0,void 0);function le(e,t,r){return{kind:e,value:t,error:r}}var ue=null;var pe=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,G(t)&&t.add(r)):r.destination=ye,r}return L(t,e),t.create=function(e,t,r){return new he(e,t,r)},t.prototype.next=function(e){this.isStopped?ge(function(e){return le("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?ge(function(e){return le("E",void 0,e)}(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?ge(ae,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}(X),ce=Function.prototype.bind;function de(e,t){return ce.call(e,t)}var fe=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){ve(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){ve(e)}else ve(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){ve(e)}},e}(),he=function(e){function t(t,r,n){var i,o,s=e.call(this)||this;Y(t)||!t?i={next:null==t?void 0:t,error:null==r?void 0:r,complete:null==n?void 0:n}:s&&ie?((o=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&de(t.next,o),error:t.error&&de(t.error,o),complete:t.complete&&de(t.complete,o)}):i=t;return s.destination=new fe(i),s}return L(t,e),t}(pe);function ve(e){ne?function(e){ne&&ue&&(ue.errorThrown=!0,ue.error=e)}(e):function(e){oe.setTimeout(function(){if(!ee)throw e;ee(e)})}(e)}function ge(e,t){var r=te;r&&oe.setTimeout(function(){return r(e,t)})}var ye={closed:!0,next:se,error:function(e){throw e},complete:se},be="function"==typeof Symbol&&Symbol.observable||"@@observable";function me(e){return e}var we=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 pe||function(e){return e&&Y(e.next)&&Y(e.error)&&Y(e.complete)}(e)&&G(e)}(e)?e:new he(e,t,r);return function(e){if(ne){var t=!ue;if(t&&(ue={errorThrown:!1,error:null}),e(),t){var r=ue,n=r.errorThrown,i=r.error;if(ue=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(f){e.error(f)}},e.prototype.forEach=function(e,t){var r=this;return new(t=Ae(t))(function(t,n){var i=new he({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[be]=function(){return this},e.prototype.pipe=function(){return function(e){return 0===e.length?me: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=Ae(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 Ae(e){var t;return null==(t=null==e?re:e)?Promise:t}function Se(e,t,r,n,i,o,s){try{var a=e[o](s),l=a.value}catch(e){return void r(e)}a.done?t(l):Promise.resolve(l).then(n,i)}function Pe(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var o=e.apply(t,r);function s(e){Se(o,n,i,s,a,"next",e)}function a(e){Se(o,n,i,s,a,"throw",e)}s(void 0)})}}var Me=(e={})=>{let{parentOrigin:t="*",timeout:r,debug:n=!1,config:i={}}=e,o=b(n),s=y("App",o),{destroy:a,onDestroy:l}=s;return{promise:new Promise((e,n)=>{let u=$(r,a),p=r=>{if((()=>{try{clearTimeout(void 0)}catch(d){return!1}return!0})()&&r.source===parent&&r.data&&r.data.penpal===d.SynAck){let n=r.data,a=new z(n.id,n.appName),l=new z(n.id+"/api",n.appName),c=n.id,d={},f=e=>"api/"+e,h={$emit:(e,...t)=>{a.getEventCallBackLength(e)>0?a.$pureEmit(e,...t):null==d||d.$off(e,()=>{},!0)},onQueryResult:e=>{l.$pureEmit(f(e.reqid),e)},onOsNotify:e=>{}},v=e=>function(t){let r=f(e);l.$on(r,function e(n){t.next(n),n.reqid&&"succ"===n.result&&(t.complete(),l.$off(r,e))})},y=T(t,O(h),W(W({},i),{},{postmateVersion:"0.1.3"}),s,o)(r),b={},m=y.bus;if(m){let e=(e,t,r)=>{r?(t.$__once=!0,a.$once(e,t)):a.$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),a.$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=W(W({},y),{},{bus:d,query:function(){var e=Pe(function*(e,t){let r=(null==e?void 0:e.reqid)||(yield y.genReqId());return new Promise((n,i)=>{y.query(W(W({},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=Pe(function*(e,t={}){let r=(null==e?void 0:e.reqid)||(yield y.genReqId()),n=new we(v(r));return y.query(W(W({},e),{},{reqid:r}),W(W({},t),{},{observable:!0})),n});return function(t){return e.apply(this,arguments)}}()});y&&(window.removeEventListener(g.Message,p),u(),e({methods:w,config:r.data.config}))}};window.addEventListener(g.Message,p),(()=>{o("Child: Handshake - Sending SYN");let e={penpal:d.Syn},r=t instanceof RegExp?"*":t;window.parent.postMessage(e,r)})(),l(e=>{window.removeEventListener(g.Message,p),e&&n(e)})}),destroy(){a()}}},Oe="trimjs-extension-host";function Ee(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`web-ext-${Date.now()}-${Math.random().toString(16).slice(2)}`}function $e(e){if(!e||"object"!=typeof e)return!1;const t=e;return t.source===Oe&&1===t.version&&"string"==typeof t.requestId&&("request"===t.kind||"response"===t.kind||"event"===t.kind)}function Fe(e){const t=new Error(`NotSupportedInExtensionHost: ${e}`);throw t.code="NotSupportedInExtensionHost",t}function _e(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($e(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 $e(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:Oe,version:1,kind:"request",requestId:Ee(),payload:{method:e,params:t}}}(e,t),s=yield new Promise((t,s)=>{let a;const l=i&&"timeoutMs"in i?i.timeoutMs:r;"number"==typeof l&&l>=0&&(a=setTimeout(()=>{n.delete(o.requestId),s(new Error(`Extension host timeout while calling ${e}`))},l)),n.set(o.requestId,{resolve:t,reject:s,timeoutId:a}),window.postMessage(o,"*")});var a,l;if(!s.payload.ok)throw new Error(null!==(a=null===(l=s.payload.error)||void 0===l?void 0:l.message)&&void 0!==a?a:`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 je(){return(je=s(function*(e){const t=_e();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 ke(){return ke=s(function*(){const e=_e(),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(){Fe("bus.$emit")}},genReqId:()=>Ee(),query:(t,r)=>e.request("query",{params:t,config:r}),createObservableQuery:(o=s(function*(){return Fe("createObservableQuery")}),function(){return o.apply(this,arguments)}),openApp:()=>Fe("openApp"),openAppSetting:()=>Fe("openAppSetting"),openCustomApp:()=>Fe("openCustomApp"),setTitle:()=>Fe("setTitle"),pickFile:t=>e.request("pickFile",t,{timeoutMs:null}),pickSharedFile:()=>Fe("pickSharedFile"),showFileDetails:(e,t)=>Fe("showFileDetails"),authorizeUserFile:e=>Fe("authorizeUserFile"),authorizeSharedFile:e=>Fe("authorizeSharedFile"),close:(i=s(function*(){e.destroy()}),function(){return i.apply(this,arguments)}),refreshToken:()=>e.request("refreshToken",{}),setExitPageTips:()=>Fe("setExitPageTips"),openFileManagerApp:()=>Fe("openFileManagerApp"),openFileManager:()=>Fe("openFileManager"),openFile:()=>Fe("openFile"),getPlatformConfig:()=>Promise.resolve(r),getHostSnapshot:()=>e.request("getHostSnapshot",{})};var i,o,a;return{methods:n,config:(a=r,{appName:"extension-host",os:{version:a.systemVersion,theme:a.theme,language:a.language,format:{date:{date:a.format.date,time:a.format.time}}}})}}),ke.apply(this,arguments)}var We=null;function Te(){return(Te=s(function*(e){const t=Me({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=>We||(We=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 je.apply(this,arguments)}(e))?function(){return ke.apply(this,arguments)}():Me({debug:null==e?void 0:e.debug}).promise})()),Ne={"pick-file":"pickFile","pick-shared-file":"pickSharedFile","authorize-user-file":"authorizeUserFile","authorize-shared-file":"authorizeSharedFile"};function qe(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 Ce(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?qe(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):qe(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}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;(l?window.flutter_inappwebview:a||(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 a=0;a<i;a+=1){var o,s;const e=null!==(o=r[a])&&void 0!==o?o:0,t=null!==(s=n[a])&&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 u(r.flutterInAppWebView,e,...i)})()}ready(){var e=this;return s(function*(){return e.initPromise})()}getOptions(){return this.options}setOptions(e){this.options=Ce(Ce({},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){var t=this;return s(function*(){return function(e,t,r){var n,i;const o=new URL(e,null!==(n=null!=r?r:null===(i=globalThis.location)||void 0===i?void 0:i.origin)&&void 0!==n?n:"http://localhost");var s;return o.pathname=`/app-auth/${t.routeMethod}`,o.searchParams.set("appName",t.appName),t.redirectUri&&o.searchParams.set("redirectUri",t.redirectUri),t.state&&o.searchParams.set("state",t.state),function(e){return"pick-file"===e.routeMethod||"pick-shared-file"===e.routeMethod}(t)?("pick-file"===t.routeMethod&&t.directory&&o.searchParams.set("directory","true"),"pick-file"===t.routeMethod&&(null===(s=t.accept)||void 0===s?void 0:s.length)&&o.searchParams.set("accept",t.accept.join(","))):o.searchParams.set("path",t.path),o.toString()}(yield t.getAppAuthBaseUrl(),e,window.location.origin)})()}openAppAuth(e,t){var r=this;return s(function*(){const n=yield r.buildAppAuthUrl(e);return"_self"===(null==t?void 0:t.target)&&"undefined"!=typeof window?(window.location.assign(n),n):(yield r.openURL(n,null==t?void 0:t.target,null==t?void 0:t.features),n)})()}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");let a;for(const l in Ne)if(Ne[l]===s){a=l;break}return{status:o.get("status")||void 0,error:o.get("error")||void 0,method:a?Ne[a]:void 0,appName:o.get("appName")||void 0,state:o.get("state")||void 0}}(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){const n=yield r.getWebMethods().query(e,t);if(!n)throw new Error("Failed to query");return n}r.assertMobileAppApi("query");const n=yield r.callAppMethod("wsQuery",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 c.apply(this,arguments)}(t.flutterInAppWebView,e):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 g(){return(g=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 y=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!==y.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:y.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:y.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("."):[],$=(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},F=(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,F(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(y){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!==y.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:y.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)$(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 W(e){return W="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},W(e)}function k(e){var t=function(e,t){if("object"!=W(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=W(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==W(t)?t:t+""}function x(e,t,r){return(t=k(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:y.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",R="事件订阅数量为空";function D(e){return D="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},D(e)}function z(e){var t=function(e,t){if("object"!=D(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=D(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==D(t)?t:t+""}function U(e,t,r){return(t=z(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){U(this,"id",void 0),U(this,"appName",void 0),U(this,"eventObj",void 0),U(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} ${R}`),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} ${R}`),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 ye(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 ge=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}(),ye=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 ge(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 ye(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 ye({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 $e=(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(y){return!1}return!0})()&&r.source===parent&&r.data&&r.data.penpal===y.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))})},g=F(h),y=N(t,g,T(T({},i),{},{postmateVersion:"0.1.3"}),s,o)(r),b={},m=y.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({},y),{},{bus:d,query:function(){var e=Ee(function*(e,t){let r=(null==e?void 0:e.reqid)||(yield y.genReqId());return new Promise((n,i)=>{y.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 y.genReqId()),n=new Pe(v(r));return y.query(T(T({},e),{},{reqid:r}),T(T({},t),{},{observable:!0})),n});return function(t){return e.apply(this,arguments)}}()});y&&(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:y.Syn},r=t instanceof RegExp?"*":t;window.parent.postMessage(e,r)})(),a(e=>{window.removeEventListener(A.Message,p),e&&n(e)})}),destroy(){l()}}},Fe="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===Fe&&1===t.version&&"string"==typeof t.requestId&&("request"===t.kind||"response"===t.kind||"event"===t.kind)}function We(e){const t=new Error(`NotSupportedInExtensionHost: ${e}`);throw t.code="NotSupportedInExtensionHost",t}function ke(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:Fe,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=ke();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=ke(),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(){We("bus.$emit")}},genReqId:()=>_e(),query:(t,r)=>e.request("query",{params:t,config:r}),createObservableQuery:(o=s(function*(){return We("createObservableQuery")}),function(){return o.apply(this,arguments)}),openApp:()=>We("openApp"),openAppSetting:()=>We("openAppSetting"),openCustomApp:()=>We("openCustomApp"),setTitle:()=>We("setTitle"),pickFile:t=>e.request("pickFile",t,{timeoutMs:null}),pickSharedFile:()=>We("pickSharedFile"),showFileDetails:(e,t)=>We("showFileDetails"),authorizeUserFile:e=>We("authorizeUserFile"),authorizeSharedFile:e=>We("authorizeSharedFile"),close:(i=s(function*(){e.destroy()}),function(){return i.apply(this,arguments)}),refreshToken:()=>e.request("refreshToken",{}),setExitPageTips:()=>We("setExitPageTips"),openFileManagerApp:()=>We("openFileManagerApp"),openFileManager:()=>We("openFileManager"),openFile:()=>We("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=$e({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)}():$e({debug:null==e?void 0:e.debug}).promise})()),Ce={pickFile:"pick-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||"pickSharedFile"===t){var a;const e=r;"pickFile"===t&&e.directory&&s.searchParams.set("directory","true");const n="pickFile"===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;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}}(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 g.apply(this,arguments)}(t.flutterInAppWebView,e):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;
package/dist/index.d.ts CHANGED
@@ -1,382 +1,141 @@
1
- declare interface App {
2
- name: string;
3
- icon: string;
4
- headerIconVisible?: boolean;
5
- appName: string;
6
- serviceName?: string;
7
- alias?: string;
8
- type: AppType;
9
- componentUrl?: string;
10
- iframe?: boolean;
11
- microApp?: boolean;
12
- url?: string;
13
- description?: string;
14
- multiple?: boolean;
15
- hiddenDesktopIcon?: boolean;
16
- enableSettings?: boolean;
17
- enableMaximize?: boolean;
18
- width?: number;
19
- style?: any;
20
- }
21
-
22
- export declare interface AppAuthAuthorizeRequest extends AppAuthBaseRequest {
23
- routeMethod: AppAuthAuthorizeRouteMethod;
24
- method: Extract<AppAuthMethod, 'authorizeUserFile' | 'authorizeSharedFile'>;
25
- path: string;
26
- }
27
-
28
- declare type AppAuthAuthorizeRouteMethod = Extract<AppAuthRouteMethod, 'authorize-user-file' | 'authorize-shared-file'>;
29
-
30
- export declare interface AppAuthBaseRequest {
31
- appName: string;
32
- redirectUri?: string;
33
- state?: string;
34
- }
35
-
36
- export declare type AppAuthCallbackError = 'access_denied';
37
-
38
- export declare type AppAuthCallbackStatus = 'success' | 'cancel' | 'error';
39
-
40
- export declare type AppAuthMethod = (typeof appAuthMethodRouteMap)[AppAuthRouteMethod];
41
-
42
- declare const appAuthMethodRouteMap: {
43
- readonly 'pick-file': "pickFile";
44
- readonly 'pick-shared-file': "pickSharedFile";
45
- readonly 'authorize-user-file': "authorizeUserFile";
46
- readonly 'authorize-shared-file': "authorizeSharedFile";
47
- };
48
-
49
- declare interface AppAuthPickFileRequest extends AppAuthBaseRequest {
50
- routeMethod: 'pick-file';
51
- method: 'pickFile';
52
- directory?: boolean;
53
- accept?: string[];
54
- }
55
-
56
- export declare type AppAuthPickRequest = AppAuthPickFileRequest | AppAuthPickSharedFileRequest;
57
-
58
- declare interface AppAuthPickSharedFileRequest extends AppAuthBaseRequest {
59
- routeMethod: 'pick-shared-file';
60
- method: 'pickSharedFile';
61
- }
62
-
63
- export declare type AppAuthRequest = AppAuthPickRequest | AppAuthAuthorizeRequest;
64
-
65
- export declare interface AppAuthResult {
66
- status?: AppAuthCallbackStatus;
67
- error?: AppAuthCallbackError;
68
- method?: AppAuthMethod;
69
- appName?: string;
70
- state?: string;
71
- }
72
-
73
- export declare type AppAuthRouteMethod = keyof typeof appAuthMethodRouteMap;
74
-
75
- export declare type AppBridgeResponse<T> = {
76
- code: number;
77
- msg: string;
78
- data: T;
79
- };
80
-
81
- declare type AppBridgeResponse_2<T> = {
82
- code: number;
83
- msg: string;
84
- data: T;
85
- };
86
-
87
- declare enum AppType {
88
- INBUILT = "inbuilt",// 内置应用
89
- THIRD_PARTY = "third-party",// 第三方
90
- TEMPORARY = "temporary"
91
- }
92
-
93
- export declare type AuthorizeFileResult = boolean;
94
-
95
- export declare interface FileDetailsOptions {
96
- admin?: boolean;
97
- }
98
-
99
- export declare interface FilePickerParams {
100
- /**
101
- * 是否多选
102
- *
103
- * @default false
104
- */
105
- multiple?: boolean;
106
- /**
107
- * 是否选择文件夹
108
- *
109
- * @default false
110
- */
111
- directory?: boolean;
112
- /**
113
- * 接受的文件类型
114
- *
115
- * @example
116
- * accept: ['.txt', '.jpg', '.png'];
117
- */
118
- accept?: string[];
119
- /**
120
- * 可选的范围 传入顺序决定侧边栏的顺序 myFiles. 我的文件 otherShare. 他人共享 external. 外接存储 favorites. 我的收藏 storage.
121
- * 存储空间(管理员)
122
- *
123
- * @default
124
- * ['myFiles']
125
- */
126
- sidebarGroup?: ('myFiles' | 'otherShare' | 'external' | 'remote' | 'favorites' | 'storage' | 'torrent' | 'team' | string)[];
127
- /**
128
- * 不可选的路径列表, 如果是路径也不可被展开
129
- *
130
- * @example
131
- * disabledPaths: ['/vol1/1000/xxx', '/vol2/1000/yyy'];
132
- */
133
- disabledPaths?: string[];
134
- /**
135
- * 可选择的正则表达式(预留)
136
- *
137
- * @example
138
- * selectablePatterns: [['\\.(torrent|bt)$', 'i']];
139
- */
140
- selectablePatterns?: [string, string][];
141
- /**
142
- * 扩充搜索 文件类型
143
- *
144
- * @example
145
- * expandFiles: [
146
- * {
147
- * title: '我的种子',
148
- * extension: '.torrent',
149
- * },
150
- * ];
151
- */
152
- expandFiles?: {
153
- /**
154
- * 侧边栏标题
155
- */
156
- title: string;
157
- /**
158
- * 文件扩展名
159
- */
160
- extension: string;
161
- }[];
162
- /**
163
- * 是否允许创建文件夹
164
- *
165
- * @default true
166
- */
167
- creatable?: boolean;
168
- /**
169
- * 标题
170
- *
171
- * @default '选择文件' | '选择文件夹'
172
- */
173
- title?: string;
174
- /**
175
- * 确认按钮文本
176
- *
177
- * @default '确定'
178
- */
179
- okText?: string;
180
- }
181
-
182
- export declare interface HostSnapshot {
183
- status: string;
184
- host?: string;
185
- username?: string;
186
- currentSessionId?: string;
187
- sessions: Array<{
188
- id: string;
189
- label: string;
190
- host?: string;
191
- username?: string;
192
- }>;
193
- errorMessage?: string;
194
- }
195
-
196
- declare interface OpenAppParams {
197
- custom?: {
198
- name?: string;
199
- };
200
- app?: App;
201
- params?: {
202
- [key: string]: any;
203
- };
204
- }
205
-
206
- export declare interface PlatformConfig {
207
- theme: 'dark' | 'light';
208
- language: string;
209
- appVersion?: string;
210
- systemVersion: string;
211
- format: {
212
- date?: string;
213
- time?: string;
214
- };
215
- }
216
-
217
- export declare interface QueryConfig {
218
- timer?: boolean;
219
- observable?: boolean;
220
- encrypt?: boolean;
221
- timeout?: number;
222
- skipPreflight?: boolean;
223
- autoFailTips?: boolean;
224
- failTipsPrefix?: string;
225
- }
226
-
227
- export declare type ResponseData<T> = T extends undefined ? ResponseDataBase : ResponseDataBase & T;
228
-
229
- declare interface ResponseDataBase {
230
- reqid: string;
231
- result: ResponseStatus;
232
- taskId?: string;
233
- type?: string;
234
- errmsg?: string;
235
- errno?: number;
236
- extra?: string;
237
- }
238
-
239
- declare enum ResponseStatus {
240
- SUCCESS = "succ",// 成功
241
- FAIL = "fail",// 失败
242
- CANCEL = "cancel",// 用户取消
243
- DOING = "doing"
244
- }
245
-
246
- /**
247
- * Trim App 实例类
248
- */
249
- declare class TrimApp {
250
- private options;
251
- private flutterInAppWebView;
252
- private osConnector;
253
- private initPromise;
254
- private appApiVersion?;
255
- isWeb: boolean;
256
- isStandaloneWeb: boolean;
257
- constructor(options?: TrimAppOptions);
258
- private init;
259
- private getWebMethods;
260
- private loadAppMessage;
261
- private initMobileAppApi;
262
- private assertMobileAppApi;
263
- private isAtLeastVersion;
264
- private parseVersion;
265
- callAppMethod<T>(fn: string, ...params: Array<string | undefined>): Promise<T | null>;
266
- /**
267
- * 等待初始化完成
268
- *
269
- * @returns Promise
270
- */
271
- ready(): Promise<void>;
272
- /**
273
- * 获取配置
274
- */
275
- getOptions(): TrimAppOptions;
276
- /**
277
- * 更新配置
278
- */
279
- setOptions(options: Partial<TrimAppOptions>): void;
280
- /**
281
- * 获取平台配置
282
- */
283
- getPlatformConfig(): Promise<PlatformConfig>;
284
- getHostSnapshot(): Promise<HostSnapshot>;
285
- getAppAuthBaseUrl(): Promise<string>;
286
- buildAppAuthUrl(request: AppAuthRequest): Promise<string>;
287
- openAppAuth(request: AppAuthRequest, options?: {
288
- target?: string;
289
- features?: string;
290
- }): Promise<string>;
291
- parseAppAuthCallback(input?: string | URL | URLSearchParams): AppAuthResult;
292
- /**
293
- * setTitle - 设置标题
294
- *
295
- * @param title 标题文本
296
- */
297
- setTitle(title: string): Promise<void>;
298
- /**
299
- * setExitPageTips - 设置退出页面提示
300
- *
301
- * @param params 提示参数
302
- */
303
- setExitPageTips(params?: {
304
- title?: string;
305
- content?: string;
306
- }): Promise<unknown>;
307
- /**
308
- * 通过应用打开某个文件
309
- */
310
- openFile(path: string): Promise<unknown>;
311
- /**
312
- * 打开文件管理器
313
- */
314
- openFileManager(path: string): Promise<unknown>;
315
- showFileDetails(paths: string[], options?: FileDetailsOptions): Promise<unknown>;
316
- authorizeUserFile(path: string): Promise<AppBridgeResponse_2<AuthorizeFileResult> | undefined>;
317
- authorizeSharedFile(path: string): Promise<AppBridgeResponse_2<AuthorizeFileResult> | undefined>;
318
- /**
319
- * 打开当前应用在系统中的应用设置页
320
- */
321
- openAppSetting(): Promise<unknown>;
322
- /**
323
- * 打开应用
324
- *
325
- * @param anchor 锚点
326
- */
327
- openApp(anchor: string): Promise<unknown>;
328
- /**
329
- * 打开自定义应用
330
- *
331
- * @param appName 自定义应用标识
332
- * @param options 自定义应用配置和打开参数
333
- */
334
- openCustomApp(appName: string, options: OpenAppParams): Promise<void>;
335
- /**
336
- * 打开外部链接 App 端通过系统浏览器打开,Web 端沿用 window.open 行为
337
- */
338
- openURL(url: string, target?: string, features?: string): Promise<unknown>;
339
- /**
340
- * 关闭应用
341
- */
342
- close(): Promise<unknown>;
343
- /**
344
- * 请求接口
345
- */
346
- query<T>(params: any, config?: QueryConfig): Promise<ResponseData<T>>;
347
- refreshToken(): Promise<void>;
348
- /**
349
- * 监听事件(仅 Web 平台)
350
- */
351
- $on(event: string, cb: (...args: any[]) => void): Promise<void>;
352
- /**
353
- * 取消监听事件(仅 Web 平台)
354
- */
355
- $off(event: string, cb: (...args: any[]) => void): Promise<void>;
356
- /**
357
- * 监听一次事件(仅 Web 平台)
358
- */
359
- $once(event: string, cb: (...args: any[]) => void): Promise<void>;
360
- /**
361
- * 选择文件
362
- */
363
- pickFile(params: FilePickerParams): Promise<string[] | undefined>;
364
- /**
365
- * 选择共享文件并授权给当前应用
366
- */
367
- pickSharedFile(params?: Omit<FilePickerParams, 'directory'>): Promise<AppBridgeResponse_2<string[]> | undefined>;
368
- }
369
- export { TrimApp }
370
- export default TrimApp;
371
-
372
- /**
373
- * SDK 配置选项
374
- */
375
- export declare interface TrimAppOptions {
376
- /**
377
- * 是否开启 debug 模式,开启后会输出日志
378
- */
379
- debug?: boolean;
380
- }
381
-
382
- export { }
1
+ import { AuthorizeFileResult, FileDetailsOptions, HostSnapshot, PlatformConfig, TrimAppOptions } from './types';
2
+ import { AppAuthMethod, AppAuthParams, AppAuthResult } from './app-auth';
3
+ import { ObservableLike } from './mobile/index';
4
+ import { AppBridgeResponse, OpenAppParams, ResponseData, FilePickerParams, QueryConfig } from '@fn/micro-app-postmate';
5
+ export type { FilePickerParams, QueryConfig, ResponseData } from '@fn/micro-app-postmate';
6
+ /**
7
+ * nas 应用 SDK
8
+ *
9
+ * @trim/app - NAS 应用 SDK
10
+ */
11
+ export type { PlatformConfig, TrimAppOptions } from './types';
12
+ export type { HostSnapshot } from './types';
13
+ export type { AppBridgeResponse, AuthorizeFileResult, FileDetailsOptions } from './types';
14
+ export type { AppAuthAuthorizeParams, AppAuthBaseParams, AppAuthCallbackError, AppAuthCallbackStatus, AppAuthMethod, AppAuthMethodParamsMap, AppAuthParams, AppAuthPickFileParams, AppAuthPickSharedFileParams, AppAuthResult, } from './types';
15
+ /**
16
+ * Trim App 实例类
17
+ */
18
+ export declare class TrimApp {
19
+ private options;
20
+ private flutterInAppWebView;
21
+ private osConnector;
22
+ private initPromise;
23
+ private appApiVersion?;
24
+ isWeb: boolean;
25
+ isStandaloneWeb: boolean;
26
+ constructor(options?: TrimAppOptions);
27
+ private init;
28
+ private getWebMethods;
29
+ private loadAppMessage;
30
+ private initMobileAppApi;
31
+ private assertMobileAppApi;
32
+ private isAtLeastVersion;
33
+ private parseVersion;
34
+ callAppMethod<T>(fn: string, ...params: Array<string | undefined>): Promise<T | null>;
35
+ /**
36
+ * 等待初始化完成
37
+ *
38
+ * @returns Promise
39
+ */
40
+ ready(): Promise<void>;
41
+ /**
42
+ * 获取配置
43
+ */
44
+ getOptions(): TrimAppOptions;
45
+ /**
46
+ * 更新配置
47
+ */
48
+ setOptions(options: Partial<TrimAppOptions>): void;
49
+ /**
50
+ * 获取平台配置
51
+ */
52
+ getPlatformConfig(): Promise<PlatformConfig>;
53
+ getHostSnapshot(): Promise<HostSnapshot>;
54
+ getAppAuthBaseUrl(): Promise<string>;
55
+ buildAppAuthUrl<TMethod extends AppAuthMethod>(method: TMethod, params: AppAuthParams<NoInfer<TMethod>>): Promise<string>;
56
+ openAppAuth<TMethod extends AppAuthMethod>(method: TMethod, params: AppAuthParams<NoInfer<TMethod>>, options?: {
57
+ target?: string;
58
+ features?: string;
59
+ }): Promise<string>;
60
+ parseAppAuthCallback(input?: string | URL | URLSearchParams): AppAuthResult;
61
+ /**
62
+ * setTitle - 设置标题
63
+ *
64
+ * @param title 标题文本
65
+ */
66
+ setTitle(title: string): Promise<void>;
67
+ /**
68
+ * setExitPageTips - 设置退出页面提示
69
+ *
70
+ * @param params 提示参数
71
+ */
72
+ setExitPageTips(params?: {
73
+ title?: string;
74
+ content?: string;
75
+ }): Promise<unknown>;
76
+ /**
77
+ * 通过应用打开某个文件
78
+ */
79
+ openFile(path: string): Promise<unknown>;
80
+ /**
81
+ * 打开文件管理器
82
+ */
83
+ openFileManager(path: string): Promise<unknown>;
84
+ showFileDetails(paths: string[], options?: FileDetailsOptions): Promise<unknown>;
85
+ authorizeUserFile(path: string): Promise<AppBridgeResponse<AuthorizeFileResult> | undefined>;
86
+ authorizeSharedFile(path: string): Promise<AppBridgeResponse<AuthorizeFileResult> | undefined>;
87
+ /**
88
+ * 打开当前应用在系统中的应用设置页
89
+ */
90
+ openAppSetting(): Promise<unknown>;
91
+ /**
92
+ * 打开应用
93
+ *
94
+ * @param anchor 锚点
95
+ */
96
+ openApp(anchor: string): Promise<unknown>;
97
+ /**
98
+ * 打开自定义应用
99
+ *
100
+ * @param appName 自定义应用标识
101
+ * @param options 自定义应用配置和打开参数
102
+ */
103
+ openCustomApp(appName: string, options: OpenAppParams): Promise<void>;
104
+ /**
105
+ * 打开外部链接 App 端通过系统浏览器打开,Web 端沿用 window.open 行为
106
+ */
107
+ openURL(url: string, target?: string, features?: string): Promise<unknown>;
108
+ /**
109
+ * 关闭应用
110
+ */
111
+ close(): Promise<unknown>;
112
+ /**
113
+ * 请求接口
114
+ */
115
+ query<T>(params: any, config: QueryConfig & {
116
+ observable: true;
117
+ }): Promise<ObservableLike<ResponseData<T>>>;
118
+ query<T>(params: any, config?: QueryConfig): Promise<ResponseData<T>>;
119
+ refreshToken(): Promise<void>;
120
+ /**
121
+ * 监听事件(仅 Web 平台)
122
+ */
123
+ $on(event: string, cb: (...args: any[]) => void): Promise<void>;
124
+ /**
125
+ * 取消监听事件(仅 Web 平台)
126
+ */
127
+ $off(event: string, cb: (...args: any[]) => void): Promise<void>;
128
+ /**
129
+ * 监听一次事件(仅 Web 平台)
130
+ */
131
+ $once(event: string, cb: (...args: any[]) => void): Promise<void>;
132
+ /**
133
+ * 选择文件
134
+ */
135
+ pickFile(params: FilePickerParams): Promise<string[] | undefined>;
136
+ /**
137
+ * 选择共享文件并授权给当前应用
138
+ */
139
+ pickSharedFile(params?: Omit<FilePickerParams, 'directory'>): Promise<AppBridgeResponse<string[]> | undefined>;
140
+ }
141
+ export default TrimApp;
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 a=e[o](s),l=a.value}catch(e){return void r(e)}a.done?t(l):Promise.resolve(l).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 a(e){o(s,n,i,a,l,"next",e)}function l(e){o(s,n,i,a,l,"throw",e)}a(void 0)})}}var a=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{a=!0});var l=/(iPad|iPhone|iPod|Macintosh|Mac OS X)/i.test(navigator.userAgent),u=/* @__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(a){return n.error(`error: ${a}`),null}return null});return function(t,r){return e.apply(this,arguments)}}(),p=/* @__PURE__ */new Map;function c(){return(c=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)}p.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=p.get(t.reqId);r&&(r(t),p.delete(t.reqId))});var d=/* @__PURE__ */function(e){return e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e}({}),f=/* @__PURE__ */function(e){return e.Fulfilled="fulfilled",e.Rejected="rejected",e}({}),h=/* @__PURE__ */function(e){return e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e}({}),v=/* @__PURE__ */function(e){return e.DataCloneError="DataCloneError",e}({}),g=/* @__PURE__ */function(e){return e.Message="message",e}({}),y=(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)}}},b=e=>(...t)=>{e&&console.log("[Penpal]",...t)},m=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),w=(e,t,r)=>{let{localName:n,local:i,remote:o,originForSending:s,originForReceiving:a}=e,l=!1,u=e=>{if(e.source!==o||e.data.penpal!==d.Call)return;if("*"!==a&&e.origin!==a)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${a}`);let{methodName:i,args:u,id:p}=e.data;r(`${n}: Received ${i}() call`);let c=e=>t=>{if(r(`${n}: Sending ${i}() reply`),l)return void r(`${n}: Unable to send ${i}() reply due to destroyed connection`);let a={penpal:d.Reply,id:p,resolution:e,returnValue:t};e===f.Rejected&&t instanceof Error&&(a.returnValue=m(t),a.returnValueIsError=!0);try{o.postMessage(a,s)}catch(e){if(e.name===v.DataCloneError){let r={penpal:d.Reply,id:p,resolution:f.Rejected,returnValue:m(e),returnValueIsError:!0};o.postMessage(r,s)}throw e}};new Promise(e=>e(t[i].apply(t,u))).then(c(f.Fulfilled),c(f.Rejected))};return i.addEventListener(g.Message,u),()=>{l=!0,i.removeEventListener(g.Message,u)}},A=0,S=()=>++A,P=e=>e?e.split("."):[],M=(e,t,r)=>{let n=P(t);return n.reduce((e,t,i)=>(void 0===e[t]&&(e[t]={}),i===n.length-1&&(e[t]=r),e[t]),e),e},O=(e,t)=>{let r={};return Object.keys(e).forEach(n=>{let i=e[n],o=((e,t)=>{let r=P(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof i&&Object.assign(r,O(i,o)),"function"==typeof i&&(r[o]=i)}),r},E=(e,t,r,n,i)=>{let{localName:o,local:s,remote:a,originForSending:l,originForReceiving:u}=t,p=!1;i(`${o}: Connecting call sender`);let c=e=>(...t)=>{let r;i(`${o}: Sending ${e}() call`);try{a.closed&&(r=!0)}catch(d){r=!0}if(r&&n(),p){let t=/* @__PURE__ */Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=h.ConnectionDestroyed,t}return new Promise((r,n)=>{let p=S(),c=t=>{if(t.source!==a||t.data.penpal!==d.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 l=t.data;i(`${o}: Received ${e}() reply`),s.removeEventListener(g.Message,c);let h=l.returnValue;l.returnValueIsError&&(h=(e=>{let t=/* @__PURE__ */Error();return Object.assign(t,e),t})(h)),(l.resolution===f.Fulfilled?r:n)(h)};s.addEventListener(g.Message,c);let h={penpal:d.Call,id:p,methodName:e,args:t};a.postMessage(h,l)})},v=r.reduce((e,t)=>(e[t]=c(t),e),{});return Object.assign(e,(e=>{let t={};for(let r in e)M(t,r,e[r]);return t})(v)),()=>{p=!0}},$=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout(()=>{let r=/* @__PURE__ */Error(`Connection timed out after ${e}ms`);r.code=h.ConnectionTimeout,t(r)},e)),()=>{clearTimeout(r)}};function F(e){return F="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},F(e)}function _(e){var t=function(e,t){if("object"!=F(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=F(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==F(t)?t:t+""}function j(e,t,r){return(t=_(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function k(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 W(e){for(var t=1;t<arguments.length;t++){var r=null==arguments[t]?{}:arguments[t];t%2?k(Object(r),!0).forEach(function(t){j(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):k(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 a="null"===n.origin?"*":n.origin,l={penpal:d.Ack,methodNames:Object.keys(t),config:r};window.parent.postMessage(l,a);let u={localName:"Child",local:window,remote:window.parent,originForSending:a,originForReceiving:n.origin};s(w(u,t,i));let p={};return s(E(p,u,n.data.methodNames,o,i)),p}};function x(e,t){var r;null==(r=console)||r.warn(`[fnApp warn]: ${e}`,t)}function N(e,t){var r;null==(r=console)||r.error(`[fnApp error]: ${e}`,t)}var q="_fn_all_event",C="事件订阅数量为空";function V(e){return V="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},V(e)}function I(e){var t=function(e,t){if("object"!=V(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=V(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==V(t)?t:t+""}function R(e,t,r){return(t=I(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var D=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:/* @__PURE__ */new Map,z=class{constructor(e,t){R(this,"id",void 0),R(this,"appName",void 0),R(this,"eventObj",void 0),R(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),D.get(this.id)||D.set(this.id,{}),this.eventObj=D.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(q,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} ${C}`),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(q,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let r=0;return D.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){N(e)}}if(n._fn_all_event)for(let i=n[q].length-1;i>=0;i--){r++;let o=n[q][i];o.$__once&&n[q].splice(i,1);try{o(...t)}catch(e){N(e)}}}),(!e||0===r)&&x(`${e} ${C}`),this}$clear(){var e;let t=null==(e=D.get(this.id))?{}:e;return Object.keys(t).forEach(e=>delete t[e]),this}},U=function(e,t){return U=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])},U(e,t)};function L(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}U(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function H(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 J(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 B(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 Y(e){return"function"==typeof e}var Q=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 K(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var X=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=H(o),a=s.next();!a.done;a=s.next())a.value.remove(this)}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else o.remove(this);var l=this.initialTeardown;if(Y(l))try{l()}catch(e){i=e instanceof Q?e.errors:[e]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var p=H(u),c=p.next();!c.done;c=p.next()){var d=c.value;try{Z(d)}catch(e){i=null==i?[]:i,e instanceof Q?i=B(B([],J(i)),J(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 Q(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)Z(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)&&K(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&K(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();function G(e){return e instanceof X||e&&"closed"in e&&Y(e.remove)&&Y(e.add)&&Y(e.unsubscribe)}function Z(e){Y(e)?e():e.unsubscribe()}X.EMPTY;var ee=null,te=null,re=void 0,ne=!1,ie=!1,oe={setTimeout:function(e,t){var r=[...arguments].slice(2),n=oe.delegate;return null!=n&&n.setTimeout?n.setTimeout.apply(n,B([e,t],J(r))):setTimeout.apply(void 0,B([e,t],J(r)))},clearTimeout:function(e){var t=oe.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function se(){}var ae=le("C",void 0,void 0);function le(e,t,r){return{kind:e,value:t,error:r}}var ue=null;var pe=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,G(t)&&t.add(r)):r.destination=ye,r}return L(t,e),t.create=function(e,t,r){return new he(e,t,r)},t.prototype.next=function(e){this.isStopped?ge(function(e){return le("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?ge(function(e){return le("E",void 0,e)}(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?ge(ae,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}(X),ce=Function.prototype.bind;function de(e,t){return ce.call(e,t)}var fe=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){ve(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){ve(e)}else ve(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){ve(e)}},e}(),he=function(e){function t(t,r,n){var i,o,s=e.call(this)||this;Y(t)||!t?i={next:null==t?void 0:t,error:null==r?void 0:r,complete:null==n?void 0:n}:s&&ie?((o=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&de(t.next,o),error:t.error&&de(t.error,o),complete:t.complete&&de(t.complete,o)}):i=t;return s.destination=new fe(i),s}return L(t,e),t}(pe);function ve(e){ne?function(e){ne&&ue&&(ue.errorThrown=!0,ue.error=e)}(e):function(e){oe.setTimeout(function(){if(!ee)throw e;ee(e)})}(e)}function ge(e,t){var r=te;r&&oe.setTimeout(function(){return r(e,t)})}var ye={closed:!0,next:se,error:function(e){throw e},complete:se},be="function"==typeof Symbol&&Symbol.observable||"@@observable";function me(e){return e}var we=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 pe||function(e){return e&&Y(e.next)&&Y(e.error)&&Y(e.complete)}(e)&&G(e)}(e)?e:new he(e,t,r);return function(e){if(ne){var t=!ue;if(t&&(ue={errorThrown:!1,error:null}),e(),t){var r=ue,n=r.errorThrown,i=r.error;if(ue=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(f){e.error(f)}},e.prototype.forEach=function(e,t){var r=this;return new(t=Ae(t))(function(t,n){var i=new he({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[be]=function(){return this},e.prototype.pipe=function(){return function(e){return 0===e.length?me: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=Ae(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 Ae(e){var t;return null==(t=null==e?re:e)?Promise:t}function Se(e,t,r,n,i,o,s){try{var a=e[o](s),l=a.value}catch(e){return void r(e)}a.done?t(l):Promise.resolve(l).then(n,i)}function Pe(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var o=e.apply(t,r);function s(e){Se(o,n,i,s,a,"next",e)}function a(e){Se(o,n,i,s,a,"throw",e)}s(void 0)})}}var Me=(e={})=>{let{parentOrigin:t="*",timeout:r,debug:n=!1,config:i={}}=e,o=b(n),s=y("App",o),{destroy:a,onDestroy:l}=s;return{promise:new Promise((e,n)=>{let u=$(r,a),p=r=>{if((()=>{try{clearTimeout(void 0)}catch(d){return!1}return!0})()&&r.source===parent&&r.data&&r.data.penpal===d.SynAck){let n=r.data,a=new z(n.id,n.appName),l=new z(n.id+"/api",n.appName),c=n.id,d={},f=e=>"api/"+e,h={$emit:(e,...t)=>{a.getEventCallBackLength(e)>0?a.$pureEmit(e,...t):null==d||d.$off(e,()=>{},!0)},onQueryResult:e=>{l.$pureEmit(f(e.reqid),e)},onOsNotify:e=>{}},v=e=>function(t){let r=f(e);l.$on(r,function e(n){t.next(n),n.reqid&&"succ"===n.result&&(t.complete(),l.$off(r,e))})},y=T(t,O(h),W(W({},i),{},{postmateVersion:"0.1.3"}),s,o)(r),b={},m=y.bus;if(m){let e=(e,t,r)=>{r?(t.$__once=!0,a.$once(e,t)):a.$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),a.$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=W(W({},y),{},{bus:d,query:function(){var e=Pe(function*(e,t){let r=(null==e?void 0:e.reqid)||(yield y.genReqId());return new Promise((n,i)=>{y.query(W(W({},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=Pe(function*(e,t={}){let r=(null==e?void 0:e.reqid)||(yield y.genReqId()),n=new we(v(r));return y.query(W(W({},e),{},{reqid:r}),W(W({},t),{},{observable:!0})),n});return function(t){return e.apply(this,arguments)}}()});y&&(window.removeEventListener(g.Message,p),u(),e({methods:w,config:r.data.config}))}};window.addEventListener(g.Message,p),(()=>{o("Child: Handshake - Sending SYN");let e={penpal:d.Syn},r=t instanceof RegExp?"*":t;window.parent.postMessage(e,r)})(),l(e=>{window.removeEventListener(g.Message,p),e&&n(e)})}),destroy(){a()}}},Oe="trimjs-extension-host";function Ee(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`web-ext-${Date.now()}-${Math.random().toString(16).slice(2)}`}function $e(e){if(!e||"object"!=typeof e)return!1;const t=e;return t.source===Oe&&1===t.version&&"string"==typeof t.requestId&&("request"===t.kind||"response"===t.kind||"event"===t.kind)}function Fe(e){const t=/* @__PURE__ */new Error(`NotSupportedInExtensionHost: ${e}`);throw t.code="NotSupportedInExtensionHost",t}function _e(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($e(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 $e(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:Oe,version:1,kind:"request",requestId:Ee(),payload:{method:e,params:t}}}(e,t),s=yield new Promise((t,s)=>{let a;const l=i&&"timeoutMs"in i?i.timeoutMs:r;"number"==typeof l&&l>=0&&(a=setTimeout(()=>{n.delete(o.requestId),s(/* @__PURE__ */new Error(`Extension host timeout while calling ${e}`))},l)),n.set(o.requestId,{resolve:t,reject:s,timeoutId:a}),window.postMessage(o,"*")});var a,l;if(!s.payload.ok)throw new Error(null!==(a=null===(l=s.payload.error)||void 0===l?void 0:l.message)&&void 0!==a?a:`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 je(){return(je=s(function*(e){const t=_e();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 ke(){return ke=s(function*(){const e=_e(),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(){Fe("bus.$emit")}},genReqId:()=>Ee(),query:(t,r)=>e.request("query",{params:t,config:r}),createObservableQuery:(o=s(function*(){return Fe("createObservableQuery")}),function(){return o.apply(this,arguments)}),openApp:()=>Fe("openApp"),openAppSetting:()=>Fe("openAppSetting"),openCustomApp:()=>Fe("openCustomApp"),setTitle:()=>Fe("setTitle"),pickFile:t=>e.request("pickFile",t,{timeoutMs:null}),pickSharedFile:()=>Fe("pickSharedFile"),showFileDetails:(e,t)=>Fe("showFileDetails"),authorizeUserFile:e=>Fe("authorizeUserFile"),authorizeSharedFile:e=>Fe("authorizeSharedFile"),close:(i=s(function*(){e.destroy()}),function(){return i.apply(this,arguments)}),refreshToken:()=>e.request("refreshToken",{}),setExitPageTips:()=>Fe("setExitPageTips"),openFileManagerApp:()=>Fe("openFileManagerApp"),openFileManager:()=>Fe("openFileManager"),openFile:()=>Fe("openFile"),getPlatformConfig:()=>Promise.resolve(r),getHostSnapshot:()=>e.request("getHostSnapshot",{})};var i,o,a;return{methods:n,config:(a=r,{appName:"extension-host",os:{version:a.systemVersion,theme:a.theme,language:a.language,format:{date:{date:a.format.date,time:a.format.time}}}})}}),ke.apply(this,arguments)}var We=null;function Te(){return(Te=s(function*(e){const t=Me({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=>We||(We=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 je.apply(this,arguments)}(e))?function(){return ke.apply(this,arguments)}():Me({debug:null==e?void 0:e.debug}).promise})()),Ne={"pick-file":"pickFile","pick-shared-file":"pickSharedFile","authorize-user-file":"authorizeUserFile","authorize-shared-file":"authorizeSharedFile"};function qe(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 Ce(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?qe(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):qe(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}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;(l?window.flutter_inappwebview:a||(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 a=0;a<i;a+=1){var o,s;const e=null!==(o=r[a])&&void 0!==o?o:0,t=null!==(s=n[a])&&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 u(r.flutterInAppWebView,e,...i)})()}ready(){var e=this;return s(function*(){return e.initPromise})()}getOptions(){return this.options}setOptions(e){this.options=Ce(Ce({},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){var t=this;return s(function*(){return function(e,t,r){var n,i;const o=new URL(e,null!==(n=null!=r?r:null===(i=globalThis.location)||void 0===i?void 0:i.origin)&&void 0!==n?n:"http://localhost");var s;return o.pathname=`/app-auth/${t.routeMethod}`,o.searchParams.set("appName",t.appName),t.redirectUri&&o.searchParams.set("redirectUri",t.redirectUri),t.state&&o.searchParams.set("state",t.state),function(e){return"pick-file"===e.routeMethod||"pick-shared-file"===e.routeMethod}(t)?("pick-file"===t.routeMethod&&t.directory&&o.searchParams.set("directory","true"),"pick-file"===t.routeMethod&&(null===(s=t.accept)||void 0===s?void 0:s.length)&&o.searchParams.set("accept",t.accept.join(","))):o.searchParams.set("path",t.path),o.toString()}(yield t.getAppAuthBaseUrl(),e,window.location.origin)})()}openAppAuth(e,t){var r=this;return s(function*(){const n=yield r.buildAppAuthUrl(e);return"_self"===(null==t?void 0:t.target)&&"undefined"!=typeof window?(window.location.assign(n),n):(yield r.openURL(n,null==t?void 0:t.target,null==t?void 0:t.features),n)})()}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");let a;for(const l in Ne)if(Ne[l]===s){a=l;break}return{status:o.get("status")||void 0,error:o.get("error")||void 0,method:a?Ne[a]:void 0,appName:o.get("appName")||void 0,state:o.get("state")||void 0}}(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){const n=yield r.getWebMethods().query(e,t);if(!n)throw new Error("Failed to query");return n}r.assertMobileAppApi("query");const n=yield r.callAppMethod("wsQuery",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 c.apply(this,arguments)}(t.flutterInAppWebView,e):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 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,E=()=>++O,M=e=>e?e.split("."):[],$=(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},F=(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,F(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=E(),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)$(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 W(e){return W="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},W(e)}function k(e){var t=function(e,t){if("object"!=W(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=W(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==W(t)?t:t+""}function q(e,t,r){return(t=k(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 T(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 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",R="事件订阅数量为空";function D(e){return D="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},D(e)}function z(e){var t=function(e,t){if("object"!=D(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=D(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==D(t)?t:t+""}function U(e,t,r){return(t=z(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){U(this,"id",void 0),U(this,"appName",void 0),U(this,"eventObj",void 0),U(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} ${R}`),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} ${R}`),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 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 $e=(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=F(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=Me(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=Me(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()}}},Fe="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===Fe&&1===t.version&&"string"==typeof t.requestId&&("request"===t.kind||"response"===t.kind||"event"===t.kind)}function We(e){const t=/* @__PURE__ */new Error(`NotSupportedInExtensionHost: ${e}`);throw t.code="NotSupportedInExtensionHost",t}function ke(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:Fe,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=ke();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=ke(),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(){We("bus.$emit")}},genReqId:()=>_e(),query:(t,r)=>e.request("query",{params:t,config:r}),createObservableQuery:(o=s(function*(){return We("createObservableQuery")}),function(){return o.apply(this,arguments)}),openApp:()=>We("openApp"),openAppSetting:()=>We("openAppSetting"),openCustomApp:()=>We("openCustomApp"),setTitle:()=>We("setTitle"),pickFile:t=>e.request("pickFile",t,{timeoutMs:null}),pickSharedFile:()=>We("pickSharedFile"),showFileDetails:(e,t)=>We("showFileDetails"),authorizeUserFile:e=>We("authorizeUserFile"),authorizeSharedFile:e=>We("authorizeSharedFile"),close:(i=s(function*(){e.destroy()}),function(){return i.apply(this,arguments)}),refreshToken:()=>e.request("refreshToken",{}),setExitPageTips:()=>We("setExitPageTips"),openFileManagerApp:()=>We("openFileManagerApp"),openFileManager:()=>We("openFileManager"),openFile:()=>We("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 Te=null;function Ne(){return(Ne=s(function*(e){const t=$e({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 qe.apply(this,arguments)}(e))?function(){return xe.apply(this,arguments)}():$e({debug:null==e?void 0:e.debug}).promise})()),Ce={pickFile:"pick-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||"pickSharedFile"===t){var a;const e=r;"pickFile"===t&&e.directory&&s.searchParams.set("directory","true");const n="pickFile"===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;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}}(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})()}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};
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Logger 工具类 只有在 debug 模式下才会输出日志
3
+ */
4
+ declare class Logger {
5
+ private debug;
6
+ /**
7
+ * 设置 debug 模式
8
+ *
9
+ * @param enabled 是否启用 debug
10
+ */
11
+ setDebug(enabled: boolean): void;
12
+ /**
13
+ * 获取当前 debug 状态
14
+ */
15
+ isDebug(): boolean;
16
+ /**
17
+ * 输出日志(只在 debug 模式下)
18
+ *
19
+ * @param args 日志参数
20
+ */
21
+ log(...args: any[]): void;
22
+ /**
23
+ * 输出警告日志(只在 debug 模式下)
24
+ *
25
+ * @param args 日志参数
26
+ */
27
+ warn(...args: any[]): void;
28
+ /**
29
+ * 输出错误日志(只在 debug 模式下)
30
+ *
31
+ * @param args 日志参数
32
+ */
33
+ error(...args: any[]): void;
34
+ /**
35
+ * 输出信息日志(只在 debug 模式下)
36
+ *
37
+ * @param args 日志参数
38
+ */
39
+ info(...args: any[]): void;
40
+ }
41
+ export declare const logger: Logger;
42
+ export {};
@@ -0,0 +1,53 @@
1
+ import { FilePickerParams, QueryConfig, ResponseData } from '@fn/micro-app-postmate';
2
+ export interface FlutterInAppWebView {
3
+ callHandler: (fn: string, ...params: Array<string | undefined>) => Promise<string>;
4
+ _platformReady?: boolean;
5
+ }
6
+ declare global {
7
+ interface Window {
8
+ flutter_inappwebview: FlutterInAppWebView;
9
+ fnAppMessage?: (message: string) => void;
10
+ _flutter_onAppObservableQueryResult?: (message: string | MobileObservableQueryResult<any>) => void;
11
+ onAppHeaderGoBack?: () => boolean | number | string;
12
+ }
13
+ }
14
+ export declare const initMobile: () => Promise<FlutterInAppWebView>;
15
+ export interface FnAppMessage<T> {
16
+ reqId: string;
17
+ method: string;
18
+ result: T;
19
+ }
20
+ export declare const callHandler: <T>(flutterInAppWebView: FlutterInAppWebView, fn: string, ...params: Array<string | undefined>) => Promise<T | null>;
21
+ type ObservableObserver<T> = {
22
+ next?: (value: T) => void;
23
+ error?: (error: unknown) => void;
24
+ complete?: () => void;
25
+ };
26
+ export type ObservableSubscription = {
27
+ unsubscribe: () => void;
28
+ };
29
+ export type ObservableLike<T> = {
30
+ subscribe: (observerOrNext?: ObservableObserver<T> | ((value: T) => void), error?: (error: unknown) => void, complete?: () => void) => ObservableSubscription;
31
+ };
32
+ type InternalObservableObserver<T> = {
33
+ next: (value: T) => void;
34
+ error: (error: unknown) => void;
35
+ complete: () => void;
36
+ };
37
+ declare class SimpleObservable<T> implements ObservableLike<T> {
38
+ private readonly subscribeFn;
39
+ constructor(subscribeFn: (observer: InternalObservableObserver<T>) => void | (() => void));
40
+ subscribe(observerOrNext?: ObservableObserver<T> | ((value: T) => void), error?: (error: unknown) => void, complete?: () => void): {
41
+ unsubscribe: () => void;
42
+ };
43
+ }
44
+ type MobileObservableQueryResult<T> = ResponseData<T> & {
45
+ reqId: string;
46
+ result?: string;
47
+ };
48
+ export declare function createMobileObservableQuery<T>(flutterInAppWebView: FlutterInAppWebView, params: any, config?: QueryConfig): SimpleObservable<ResponseData<T>>;
49
+ /**
50
+ * App 端当前仅支持 title、multiple、directory 这 3 个参数。
51
+ */
52
+ export declare function pickFilePromise(flutterInAppWebView: FlutterInAppWebView, params: FilePickerParams): Promise<string[] | undefined>;
53
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface AppMessage {
2
+ nightMode: string;
3
+ language: string;
4
+ platform: string;
5
+ appVersion?: string;
6
+ appApi?: string;
7
+ systemVersion: string;
8
+ dateFormat: string;
9
+ timeFormat: string;
10
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * SDK 配置选项
3
+ */
4
+ export interface TrimAppOptions {
5
+ /**
6
+ * 是否开启 debug 模式,开启后会输出日志
7
+ */
8
+ debug?: boolean;
9
+ }
10
+ export interface PlatformConfig {
11
+ theme: 'dark' | 'light';
12
+ language: string;
13
+ appVersion?: string;
14
+ systemVersion: string;
15
+ format: {
16
+ date?: string;
17
+ time?: string;
18
+ };
19
+ }
20
+ export interface HostSnapshot {
21
+ status: string;
22
+ host?: string;
23
+ username?: string;
24
+ currentSessionId?: string;
25
+ sessions: Array<{
26
+ id: string;
27
+ label: string;
28
+ host?: string;
29
+ username?: string;
30
+ }>;
31
+ errorMessage?: string;
32
+ }
33
+ export interface FileDetailsOptions {
34
+ admin?: boolean;
35
+ }
36
+ export type AppBridgeResponse<T> = {
37
+ code: number;
38
+ msg: string;
39
+ data: T;
40
+ };
41
+ export type AuthorizeFileResult = boolean;
42
+ export type { AppAuthAuthorizeParams, AppAuthBaseParams, AppAuthCallbackError, AppAuthCallbackStatus, AppAuthMethod, AppAuthMethodParamsMap, AppAuthParams, AppAuthPickFileParams, AppAuthPickSharedFileParams, AppAuthResult, } from './app-auth';
@@ -0,0 +1,3 @@
1
+ export declare function fnAppUAMatch(ua: string): any;
2
+ export declare const isFnApp: () => any;
3
+ export declare const isApplePlatform: () => boolean;
@@ -0,0 +1,4 @@
1
+ import { TrimAppOptions } from '../types';
2
+ import { OSConnection } from './index';
3
+ export declare function probeExtensionHost(options?: TrimAppOptions): Promise<boolean>;
4
+ export declare function connectToExtensionHost(): Promise<OSConnection>;
@@ -0,0 +1,23 @@
1
+ import { OSConfig, OSMethods, ConnectionResult, FilePickerParams } from '@fn/micro-app-postmate';
2
+ import { AppBridgeResponse, AuthorizeFileResult, FileDetailsOptions, HostSnapshot, PlatformConfig, TrimAppOptions } from '../types';
3
+ type HostMethods = OSMethods & {
4
+ setExitPageTips: (params?: {
5
+ title?: string;
6
+ content?: string;
7
+ }) => void;
8
+ openFileManager: (path: string) => void;
9
+ openFileManagerApp?: (path: string) => void;
10
+ openFile: (path: string) => void;
11
+ openAppSetting: () => void;
12
+ pickSharedFile: (params?: Omit<FilePickerParams, 'directory'>) => Promise<AppBridgeResponse<string[]>>;
13
+ showFileDetails: (paths: string[], options?: FileDetailsOptions) => void;
14
+ authorizeUserFile: (path: string) => Promise<AppBridgeResponse<AuthorizeFileResult>>;
15
+ authorizeSharedFile: (path: string) => Promise<AppBridgeResponse<AuthorizeFileResult>>;
16
+ refreshToken: () => Promise<void>;
17
+ getPlatformConfig: () => Promise<PlatformConfig>;
18
+ getHostSnapshot: () => Promise<HostSnapshot>;
19
+ close: () => void;
20
+ };
21
+ export type OSConnection = ConnectionResult<HostMethods, OSConfig>;
22
+ export declare const initWeb: (options?: TrimAppOptions) => Promise<OSConnection>;
23
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trimjs/web-app",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "web app sdk for nas",
5
5
  "files": [
6
6
  "dist"
@@ -31,10 +31,11 @@
31
31
  "@fn/micro-app-event": "workspace:*",
32
32
  "@fn/micro-app-postmate": "workspace:*",
33
33
  "@rollup/plugin-babel": "^6.1.0",
34
+ "@typescript/typescript6": "catalog:",
34
35
  "terser": "^5.46.0",
35
- "typescript": "~5.6.2",
36
+ "typescript": "catalog:",
36
37
  "vite": "catalog:",
37
- "vite-plugin-dts": "^4.5.4",
38
+ "vite-plugin-dts": "catalog:",
38
39
  "vite-plus": "catalog:",
39
40
  "vitest": "catalog:"
40
41
  }