@trimjs/web-app 0.2.6 → 0.2.8

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
@@ -470,7 +470,7 @@ const response2 = await app.query(
470
470
  {
471
471
  timer: false,
472
472
  autoFailTips: true,
473
- }
473
+ },
474
474
  );
475
475
  ```
476
476
 
@@ -629,17 +629,17 @@ app.$once("os/app.activated", () => {
629
629
 
630
630
  以下是基座平台提供的系统事件:
631
631
 
632
- | 事件名 | 说明 |
633
- |---|---|
634
- | `os/theme` | 主题色变更(dark / light) |
635
- | `os/language` | 系统语言变更 |
636
- | `os/format.date` | 日期格式变更 |
637
- | `os/app.appMeta` | 应用元数据变更 |
638
- | `os/app.visibilitychange` | 应用最小化状态变更 |
639
- | `os/app.activated` | 应用激活态变更 |
640
- | `os/net.set` | 网络设置变更 |
641
- | `os/net.ovs` | 网络 OVS 开关变更 |
642
- | `os/storage.change` | 存储变更 |
632
+ | 事件名 | 说明 |
633
+ | ------------------------- | -------------------------- |
634
+ | `os/theme` | 主题色变更(dark / light) |
635
+ | `os/language` | 系统语言变更 |
636
+ | `os/format.date` | 日期格式变更 |
637
+ | `os/app.appMeta` | 应用元数据变更 |
638
+ | `os/app.visibilitychange` | 应用最小化状态变更 |
639
+ | `os/app.activated` | 应用激活态变更 |
640
+ | `os/net.set` | 网络设置变更 |
641
+ | `os/net.ovs` | 网络 OVS 开关变更 |
642
+ | `os/storage.change` | 存储变更 |
643
643
 
644
644
  ---
645
645
 
@@ -672,7 +672,7 @@ async callAppMethod<T>(fn: string, params?: string): Promise<T | null>
672
672
  // 调用自定义方法
673
673
  const result = await app.callAppMethod<{ success: boolean }>(
674
674
  "customMethod",
675
- JSON.stringify({ key: "value" })
675
+ JSON.stringify({ key: "value" }),
676
676
  );
677
677
  ```
678
678
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=Object.defineProperty,t=Object.defineProperties,n=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,n,r)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[n]=r,l=(e,t)=>{for(var n in t||(t={}))o.call(t,n)&&s(e,n,t[n]);if(r)for(var n of r(t))i.call(t,n)&&s(e,n,t[n]);return e},a=(e,r)=>t(e,n(r)),c=(e,t,n)=>s(e,"symbol"!=typeof t?t+"":t,n),u=(e,t,n)=>new Promise((r,o)=>{var i=e=>{try{l(n.next(e))}catch(t){o(t)}},s=e=>{try{l(n.throw(e))}catch(t){o(t)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(i,s);l((n=n.apply(e,t)).next())});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=new class{constructor(){c(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),n=0;n<e;n++)t[n]=arguments[n];console.log("[Trim App]",...t)}}warn(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.warn("[Trim App]",...t)}}error(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.error("[Trim App]",...t)}}info(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.info("[Trim App]",...t)}}};const d=()=>function(e){const t=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,n={};let r;for(;null!==(r=t.exec(e));)r[1]&&(n.fnOSVersion=r[1]),r[2]&&(n.fnAppType=r[2]),r[3]&&(n.fnAppVersion=r[3]);return n}(navigator.userAgent).fnAppVersion;let h=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{h=!0});const f=new Map;d()&&(window.fnAppMessage=e=>{p.log("app-message",e);const t=JSON.parse(e),n=f.get(t.reqId);n&&(n(t),f.delete(t.reqId))});var g=(e=>(e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e))(g||{}),y=(e=>(e.Fulfilled="fulfilled",e.Rejected="rejected",e))(y||{}),m=(e=>(e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e))(m||{}),v=(e=>(e.DataCloneError="DataCloneError",e))(v||{}),b=(e=>(e.Message="message",e))(b||{});const w=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});let $=0;const _=e=>e?e.split("."):[],A=(e,t,n)=>{const r=_(t);return r.reduce((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===r.length-1&&(e[t]=n),e[t]),e),e},E=(e,t)=>{const n={};return Object.keys(e).forEach(r=>{const o=e[r],i=((e,t)=>{const n=_(t||"");return n.push(e),(e=>e.join("."))(n)})(r,t);"object"==typeof o&&Object.assign(n,E(o,i)),"function"==typeof o&&(n[i]=o)}),n},O=(e,t,n,r,o)=>{const{localName:i,local:s,remote:l,originForSending:a,originForReceiving:c}=t;let u=!1;o(`${i}: Connecting call sender`);const p=e=>(...t)=>{let n;o(`${i}: Sending ${e}() call`);try{l.closed&&(n=!0)}catch(p){n=!0}if(n&&r(),u){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=m.ConnectionDestroyed,t}return new Promise((n,r)=>{const u=++$,p=t=>{if(t.source!==l||t.data.penpal!==g.Reply||t.data.id!==u)return;if("*"!==c&&t.origin!==c)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${c}`);const a=t.data;o(`${i}: Received ${e}() reply`),s.removeEventListener(b.Message,p);let d=a.returnValue;a.returnValueIsError&&(d=(e=>{const t=new Error;return Object.keys(e).forEach(n=>t[n]=e[n]),t})(d)),(a.resolution===y.Fulfilled?n:r)(d)};s.addEventListener(b.Message,p);const d={penpal:g.Call,id:u,methodName:e,args:t};l.postMessage(d,a)})},d=n.reduce((e,t)=>(e[t]=p(t),e),{});return Object.assign(e,(e=>{const t={};for(const n in e)A(t,n,e[n]);return t})(d)),()=>{u=!0}},P="0.1.2",S=(e,t,n,r,o)=>{const{destroy:i,onDestroy:s}=r;return r=>{if(!(e instanceof RegExp?e.test(r.origin):"*"===e||e===r.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${r.origin} which did not match expected origin ${e}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const l="null"===r.origin?"*":r.origin,a={penpal:g.Ack,methodNames:Object.keys(t),config:n};window.parent.postMessage(a,l);const c={localName:"Child",local:window,remote:window.parent,originForSending:l,originForReceiving:r.origin},u=((e,t,n)=>{const{localName:r,local:o,remote:i,originForSending:s,originForReceiving:l}=e;let a=!1;const c=e=>{if(e.source!==i||e.data.penpal!==g.Call)return;if("*"!==l&&e.origin!==l)return void n(`${r} received message from origin ${e.origin} which did not match expected origin ${l}`);const o=e.data,{methodName:c,args:u,id:p}=o;n(`${r}: Received ${c}() call`);const d=e=>t=>{if(n(`${r}: Sending ${c}() reply`),a)return void n(`${r}: Unable to send ${c}() reply due to destroyed connection`);const o={penpal:g.Reply,id:p,resolution:e,returnValue:t};e===y.Rejected&&t instanceof Error&&(o.returnValue=w(t),o.returnValueIsError=!0);try{i.postMessage(o,s)}catch(l){if(l.name===v.DataCloneError){const e={penpal:g.Reply,id:p,resolution:y.Rejected,returnValue:w(l),returnValueIsError:!0};i.postMessage(e,s)}throw l}};new Promise(e=>e(t[c].apply(t,u))).then(d(y.Fulfilled),d(y.Rejected))};return o.addEventListener(b.Message,c),()=>{a=!0,o.removeEventListener(b.Message,c)}})(c,t,o);s(u);const p={},d=O(p,c,r.data.methodNames,i,o);return s(d),p}};function C(e,t){null==console||console.warn(`[fnApp warn]: ${e}`,t)}function M(e,t){null==console||console.error(`[fnApp error]: ${e}`,t)}const x="_fn_all_event",j="事件订阅数量为空",N=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map;class F{constructor(e,t){c(this,"id"),c(this,"appName"),c(this,"eventObj"),c(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),N.get(this.id)||N.set(this.id,{}),this.eventObj=N.get(this.id)}$on(e,t){const n=this.eventObj[e];return n?(n.includes(t)||n.push(t),this):(this.eventObj[e]=[t],this)}$onAll(e){return this.$on(x,e)}$once(e,t){t.$__once=!0,this.$on(e,t)}$off(e,t){const n=this.eventObj[e];if(!e||!n||!n.length)return C(`${e} ${j}`),this;let r,o=n.length;for(;o--;)if(r=n[o],r===t){n.splice(o,1);break}return this}$offAll(e){return this.$off(x,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let n=0;return N.forEach(r=>{if(r[e])for(let i=r[e].length-1;i>=0;i--){n++;const s=r[e][i];s.$__once&&r[e].splice(i,1);try{s(...t)}catch(o){M(o)}}if(r[x])for(let e=r[x].length-1;e>=0;e--){n++;const i=r[x][e];i.$__once&&r[x].splice(e,1);try{i(...t)}catch(o){M(o)}}}),e&&0!==n||C(`${e} ${j}`),this}$clear(){const e=N.get(this.id)||{};return Object.keys(e).forEach(t=>delete e[t]),this}}var T=function(e,t){return(T=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function R(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}T(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function W(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function k(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(l){o={error:l}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function V(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function I(e){return"function"==typeof e}"function"==typeof SuppressedError&&SuppressedError;var q,D=((q=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(e){Error.call(e),e.stack=(new Error).stack})).prototype=Object.create(Error.prototype),q.prototype.constructor=q,q);function L(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var z=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=W(i),l=s.next();!l.done;l=s.next()){l.value.remove(this)}}catch(h){e={error:h}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var a=this.initialTeardown;if(I(a))try{a()}catch(f){o=f instanceof D?f.errors:[f]}var c=this._finalizers;if(c){this._finalizers=null;try{for(var u=W(c),p=u.next();!p.done;p=u.next()){var d=p.value;try{Y(d)}catch(g){o=null!=o?o:[],g instanceof D?o=V(V([],k(o)),k(g.errors)):o.push(g)}}}catch(y){n={error:y}}finally{try{p&&!p.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}if(o)throw new D(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)Y(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).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)&&L(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&L(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}();function J(e){return e instanceof z||e&&"closed"in e&&I(e.remove)&&I(e.add)&&I(e.unsubscribe)}function Y(e){I(e)?e():e.unsubscribe()}z.EMPTY;var H=void 0,U=function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,V([e,t],k(n)))};function B(){}var K=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,J(t)&&t.add(n)):n.destination=Z,n}return R(t,e),t.create=function(e,t,n){return new G(e,t,n)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(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}(z),Q=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(n){X(n)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){X(n)}else X(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){X(t)}},e}(),G=function(e){function t(t,n,r){var o,i=e.call(this)||this;return o=I(t)||!t?{next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:t,i.destination=new Q(o),i}return R(t,e),t}(K);function X(e){var t;t=e,U(function(){throw t})}var Z={closed:!0,next:B,error:function(e){throw e},complete:B},ee="function"==typeof Symbol&&Symbol.observable||"@@observable";function te(e){return e}var ne=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof K||function(e){return e&&I(e.next)&&I(e.error)&&I(e.complete)}(r)&&J(r)?e:new G(e,t,n);return function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))}(),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=re(t))(function(t,r){var o=new G({next:function(t){try{e(t)}catch(n){r(n),o.unsubscribe()}},error:r,complete:t});n.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[ee]=function(){return this},e.prototype.pipe=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return(0===(e=t).length?te:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)})(this)},e.prototype.toPromise=function(e){var t=this;return new(e=re(e))(function(e,n){var r;t.subscribe(function(e){return r=e},function(e){return n(e)},function(){return e(r)})})},e.create=function(t){return new e(t)},e}();function re(e){var t;return null!==(t=null!=e?e:H)&&void 0!==t?t:Promise}const oe=(e={})=>{const{parentOrigin:t="*",timeout:n,debug:r=!1,config:o={}}=e,i=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(r),s=((e,t)=>{const n=[];let r=!1;return{destroy(o){r||(r=!0,t(`${e}: Destroying connection`),n.forEach(e=>{e(o)}))},onDestroy(e){r?e():n.push(e)}}})("App",i),{destroy:c,onDestroy:p}=s,d=new Promise((e,r)=>{const d=((e,t)=>{let n;return void 0!==e&&(n=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=m.ConnectionTimeout,t(n)},e)),()=>{clearTimeout(n)}})(n,c),h=n=>{if((()=>{try{clearTimeout(void 0)}catch(e){return!1}return!0})()&&n.source===parent&&n.data&&n.data.penpal===g.SynAck){const r=n.data,c=new F(r.id,r.appName),p=new F(r.id+"/api",r.appName),f=r.id,g={},y=e=>"api/"+e,m=e=>function(t){const n=y(e);p.$on(n,function e(r){t.next(r),r.reqid&&"succ"===r.result&&(t.complete(),p.$off(n,e))})},v=E({$emit:(e,...t)=>{c.getEventCallBackLength(e)>0?c.$pureEmit(e,...t):null==g||g.$off(e,()=>{},!0)},onQueryResult:e=>{p.$pureEmit(y(e.reqid),e)},onOsNotify:e=>{}}),w=S(t,v,a(l({},o),{postmateVersion:P}),s,i)(n),$={},_=w.bus;if(_){const e=(e,t,n)=>{n?(t.$__once=!0,c.$once(e,t)):c.$on(e,t),$[e]?$[e].push(t):($[e]=[t],_.$on(e,f))};Object.assign(g,_,{$on:e,$off:(e,t,n)=>{var r;if($[e]){const n=$[e].indexOf(t);n>-1&&($[e].splice(n,1),c.$off(e,t))}n&&delete $[e],(null==(r=$[e])?void 0:r.length)||(_.$off(e,f),delete $[e])},$once:(t,n)=>{e(t,n,!0)}})}const A=a(l({},w),{bus:g,query:(e,t)=>u(null,null,function*(){const n=(null==e?void 0:e.reqid)||(yield w.genReqId());return new Promise((r,o)=>{w.query(a(l({},e),{reqid:n}),t).then(e=>{"succ"===(null==e?void 0:e.result)?r(e):o(e)})})}),createObservableQuery:(e,...t)=>u(null,[e,...t],function*(e,t={}){const n=(null==e?void 0:e.reqid)||(yield w.genReqId()),r=new ne(m(n));return w.query(a(l({},e),{reqid:n}),a(l({},t),{observable:!0})),r})});w&&(window.removeEventListener(b.Message,h),d(),e({methods:A,config:n.data.config}))}};window.addEventListener(b.Message,h),(()=>{i("Child: Handshake - Sending SYN");const e={penpal:g.Syn},n=t instanceof RegExp?"*":t;window.parent.postMessage(e,n)})(),p(e=>{window.removeEventListener(b.Message,h),e&&r(e)})});return{promise:d,destroy(){c()}}};let ie=null;class se{constructor(){c(this,"options"),c(this,"flutterInAppWebView",null),c(this,"osConnector",null),c(this,"initPromise"),c(this,"isWeb",!0);let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,e.debug&&(p.setDebug(!0),p.log("Trim App initialized with debug mode")),p.log("Options:",e),this.initPromise=this.init()}init(){return u(this,null,function*(){return p.log("Starting initialization..."),new Promise(e=>{var t;d()?(this.isWeb=!1,p.log("Initializing mobile platform..."),new Promise(e=>{var t;h||(null==(t=window.flutter_inappwebview)?void 0:t._platformReady)?(p.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{p.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)})}).then(t=>{this.flutterInAppWebView=t,p.log("Mobile platform initialized"),e()})):(this.isWeb=!0,p.log("Initializing web platform..."),(ie||(ie=oe({debug:null==t?void 0:t.debug})),ie.promise).then(t=>{this.osConnector=t,p.log("Web platform initialized"),e()}))})})}callAppMethod(e,t){return u(this,null,function*(){return this.flutterInAppWebView?((e,t,n)=>u(null,null,function*(){p.log(`callHandler: ${t}, params: ${n}`);const r=yield e.callHandler(t,n);if(r)try{const e=JSON.parse(r);p.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return p.log(`appMessage: ${JSON.stringify(t)}`),t}catch(o){return p.error(`error: ${o}`),null}return null}))(this.flutterInAppWebView,e,t):null})}ready(){return u(this,null,function*(){return this.initPromise})}getOptions(){return this.options}setOptions(e){this.options=l(l({},this.options),e),void 0!==e.debug&&p.setDebug(e.debug),p.log("Options updated:",this.options)}getPlatformConfig(){return u(this,null,function*(){var e;if(yield this.initPromise,this.isWeb){const t=yield null==(e=this.osConnector)?void 0:e.methods.getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}{const e=yield this.callAppMethod("getAppMessage");if(!e)throw new Error("Failed to get platform config");return{theme:e.nightMode,language:e.language,appVersion:e.appVersion,systemVersion:e.systemVersion,format:{date:e.dateFormat,time:e.timeFormat}}}})}setTitle(e){return u(this,null,function*(){var t;return yield this.initPromise,p.log("Setting title:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)})}setExitPageTips(e){return u(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})}openFile(e){return u(this,null,function*(){var t;return yield this.initPromise,p.log("Opening file:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)})}openFileManager(e){return u(this,null,function*(){var t;return yield this.initPromise,p.log("Opening file manager:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)})}openApp(e){return u(this,null,function*(){var t;if(yield this.initPromise,p.log("Opening app:",e),this.isWeb)return null==(t=this.osConnector)?void 0:t.methods.openApp(e);throw new Error("openApp is not supported on mobile platform")})}openCustomApp(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,p.log("Opening custom app:",e,t),this.isWeb)return null==(n=this.osConnector)?void 0:n.methods.openCustomApp(e,t);throw new Error("openCustomApp is not supported on mobile platform")})}openURL(e,t,n){return u(this,null,function*(){if(yield this.initPromise,p.log("Opening URL:",e,t,n),!this.isWeb)return this.callAppMethod("openSystemBrowser",e);if(!n)return void window.open(e,t,n);const r=window.open("",t,n);r&&(r.location.href=e)})}close(){return u(this,null,function*(){var e;return yield this.initPromise,this.isWeb?null==(e=this.osConnector)?void 0:e.methods.close():this.callAppMethod("exitPage")})}query(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,this.isWeb){const r=yield null==(n=this.osConnector)?void 0:n.methods.query(e,t);if(!r)throw new Error("Failed to query");return r}throw new Error("query is not supported on mobile platform")})}$on(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$on is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$on(e,t)})}$off(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$off is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$off(e,t)})}$once(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$once is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$once(e,t)})}pickFile(e){return u(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))})}}exports.TrimApp=se,exports.default=se;
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 o=n.call(t,r||"default");if("object"!=e(o))return o;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 o=()=>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 i(e,t,r,n,o,i,l){try{var s=e[i](l),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,o)}function l(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var l=e.apply(t,r);function s(e){i(l,n,o,s,u,"next",e)}function u(e){i(l,n,o,s,u,"throw",e)}s(void 0)})}}var s=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{s=!0});var u,a=/(iPad|iPhone|iPod|Macintosh|Mac OS X)/i.test(navigator.userAgent),c=(u=l(function*(e,t,r){n.log(`callHandler: ${t}, params: ${r}`);const o=yield e.callHandler(t,r);if(o)try{const e=JSON.parse(o);n.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return n.log(`appMessage: ${JSON.stringify(t)}`),t}catch(i){return n.error(`error: ${i}`),null}return null}),function(e,t,r){return u.apply(this,arguments)}),p=new Map;function f(){return(f=l(function*(e,t){return new Promise((r,o)=>{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 o(new Error("openFolder failed"))})})})).apply(this,arguments)}o()&&(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}({}),h=function(e){return e.Fulfilled="fulfilled",e.Rejected="rejected",e}({}),v=function(e){return e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e}({}),y=function(e){return e.DataCloneError="DataCloneError",e}({}),m=function(e){return e.Message="message",e}({}),b=(e,t)=>{let r=[],n=!1;return{destroy(o){n||(n=!0,t(`${e}: Destroying connection`),r.forEach(e=>{e(o)}))},onDestroy(e){n?e():r.push(e)}}},g=e=>(...t)=>{e&&console.log("[Penpal]",...t)},w=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),O=(e,t,r)=>{let{localName:n,local:o,remote:i,originForSending:l,originForReceiving:s}=e,u=!1,a=e=>{if(e.source!==i||e.data.penpal!==d.Call)return;if("*"!==s&&e.origin!==s)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${s}`);let{methodName:o,args:a,id:c}=e.data;r(`${n}: Received ${o}() call`);let p=e=>t=>{if(r(`${n}: Sending ${o}() reply`),u)return void r(`${n}: Unable to send ${o}() reply due to destroyed connection`);let s={penpal:d.Reply,id:c,resolution:e,returnValue:t};e===h.Rejected&&t instanceof Error&&(s.returnValue=w(t),s.returnValueIsError=!0);try{i.postMessage(s,l)}catch(e){if(e.name===y.DataCloneError){let r={penpal:d.Reply,id:c,resolution:h.Rejected,returnValue:w(e),returnValueIsError:!0};i.postMessage(r,l)}throw e}};new Promise(e=>e(t[o].apply(t,a))).then(p(h.Fulfilled),p(h.Rejected))};return o.addEventListener(m.Message,a),()=>{u=!0,o.removeEventListener(m.Message,a)}},P=0,$=()=>++P,S=e=>e?e.split("."):[],_=(e,t,r)=>{let n=S(t);return n.reduce((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===n.length-1&&(e[t]=r),e[t]),e),e},A=(e,t)=>{let r={};return Object.keys(e).forEach(n=>{let o=e[n],i=((e,t)=>{let r=S(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof o&&Object.assign(r,A(o,i)),"function"==typeof o&&(r[i]=o)}),r},E=(e,t,r,n,o)=>{let{localName:i,local:l,remote:s,originForSending:u,originForReceiving:a}=t,c=!1;o(`${i}: Connecting call sender`);let p=e=>(...t)=>{let r;o(`${i}: Sending ${e}() call`);try{s.closed&&(r=!0)}catch(d){r=!0}if(r&&n(),c){let t=Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=v.ConnectionDestroyed,t}return new Promise((r,n)=>{let c=$(),p=t=>{if(t.source!==s||t.data.penpal!==d.Reply||t.data.id!==c)return;if("*"!==a&&t.origin!==a)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${a}`);let u=t.data;o(`${i}: Received ${e}() reply`),l.removeEventListener(m.Message,p);let f=u.returnValue;u.returnValueIsError&&(f=(e=>{let t=Error();return Object.keys(e).forEach(r=>t[r]=e[r]),t})(f)),(u.resolution===h.Fulfilled?r:n)(f)};l.addEventListener(m.Message,p);let f={penpal:d.Call,id:c,methodName:e,args:t};s.postMessage(f,u)})},f=r.reduce((e,t)=>(e[t]=p(t),e),{});return Object.assign(e,(e=>{let t={};for(let r in e)_(t,r,e[r]);return t})(f)),()=>{c=!0}},j=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout(()=>{let r=Error(`Connection timed out after ${e}ms`);r.code=v.ConnectionTimeout,t(r)},e)),()=>{clearTimeout(r)}},C="0.1.2";function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function x(e){var t=function(e,t){if("object"!=T(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=T(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==T(t)?t:t+""}function M(e,t,r){return(t=x(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function N(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 F(e){for(var t=1;t<arguments.length;t++){var r=null==arguments[t]?{}:arguments[t];t%2?N(Object(r),!0).forEach(function(t){M(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):N(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var k=(e,t,r,n,o)=>{let{destroy:i,onDestroy:l}=n;return n=>{if(!(e instanceof RegExp?e.test(n.origin):"*"===e||e===n.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${n.origin} which did not match expected origin ${e}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");let s="null"===n.origin?"*":n.origin,u={penpal:d.Ack,methodNames:Object.keys(t),config:r};window.parent.postMessage(u,s);let a={localName:"Child",local:window,remote:window.parent,originForSending:s,originForReceiving:n.origin};l(O(a,t,o));let c={};return l(E(c,a,n.data.methodNames,i,o)),c}};function W(e,t){var r;null==(r=console)||r.warn(`[fnApp warn]: ${e}`,t)}function R(e,t){var r;null==(r=console)||r.error(`[fnApp error]: ${e}`,t)}var D="_fn_all_event",V="事件订阅数量为空";function I(e){return I="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},I(e)}function q(e){var t=function(e,t){if("object"!=I(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=I(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==I(t)?t:t+""}function L(e,t,r){return(t=q(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var z=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map,J=class{constructor(e,t){L(this,"id",void 0),L(this,"appName",void 0),L(this,"eventObj",void 0),L(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),z.get(this.id)||z.set(this.id,{}),this.eventObj=z.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(D,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 W(`${e} ${V}`),this;let n,o=r.length;for(;o--;)if(n=r[o],n===t){r.splice(o,1);break}return this}$offAll(e){return this.$off(D,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let r=0;return z.forEach(n=>{if(n[e])for(let o=n[e].length-1;o>=0;o--){r++;let i=n[e][o];i.$__once&&n[e].splice(o,1);try{i(...t)}catch(e){R(e)}}if(n._fn_all_event)for(let o=n[D].length-1;o>=0;o--){r++;let i=n[D][o];i.$__once&&n[D].splice(o,1);try{i(...t)}catch(e){R(e)}}}),(!e||0===r)&&W(`${e} ${V}`),this}$clear(){let e=z.get(this.id)||{};return Object.keys(e).forEach(t=>delete e[t]),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 Y(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 U(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 B(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),l=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)l.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return l}function K(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)(n||!(o in t))&&(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}function Q(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 G(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var Z=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,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var l=U(i),s=l.next();!s.done;s=l.next())s.value.remove(this)}catch(t){e={error:t}}finally{try{s&&!s.done&&(t=l.return)&&t.call(l)}finally{if(e)throw e.error}}else i.remove(this);var u=this.initialTeardown;if(Q(u))try{u()}catch(e){o=e instanceof X?e.errors:[e]}var a=this._finalizers;if(a){this._finalizers=null;try{for(var c=U(a),p=c.next();!p.done;p=c.next()){var f=p.value;try{te(f)}catch(e){o=null==o?[]:o,e instanceof X?o=K(K([],B(o)),B(e.errors)):o.push(e)}}}catch(e){r={error:e}}finally{try{p&&!p.done&&(n=c.return)&&n.call(c)}finally{if(r)throw r.error}}}if(o)throw new X(o)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)te(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)&&G(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&G(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();function ee(e){return e instanceof Z||e&&"closed"in e&&Q(e.remove)&&Q(e.add)&&Q(e.unsubscribe)}function te(e){Q(e)?e():e.unsubscribe()}Z.EMPTY;var re=null,ne=null,oe=void 0,ie=!1,le=!1,se={setTimeout:function(e,t){var r=[...arguments].slice(2),n=se.delegate;return null!=n&&n.setTimeout?n.setTimeout.apply(n,K([e,t],B(r))):setTimeout.apply(void 0,K([e,t],B(r)))},clearTimeout:function(e){var t=se.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function ue(){}var ae=ce("C",void 0,void 0);function ce(e,t,r){return{kind:e,value:t,error:r}}var pe=null;var fe=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,ee(t)&&t.add(r)):r.destination=ge,r}return Y(t,e),t.create=function(e,t,r){return new ye(e,t,r)},t.prototype.next=function(e){this.isStopped?be(function(e){return ce("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?be(function(e){return ce("E",void 0,e)}(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?be(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}(Z),de=Function.prototype.bind;function he(e,t){return de.call(e,t)}var ve=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){me(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){me(e)}else me(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){me(e)}},e}(),ye=function(e){function t(t,r,n){var o,i,l=e.call(this)||this;Q(t)||!t?o={next:null==t?void 0:t,error:null==r?void 0:r,complete:null==n?void 0:n}:l&&le?((i=Object.create(t)).unsubscribe=function(){return l.unsubscribe()},o={next:t.next&&he(t.next,i),error:t.error&&he(t.error,i),complete:t.complete&&he(t.complete,i)}):o=t;return l.destination=new ve(o),l}return Y(t,e),t}(fe);function me(e){ie?function(e){ie&&pe&&(pe.errorThrown=!0,pe.error=e)}(e):function(e){se.setTimeout(function(){if(!re)throw e;re(e)})}(e)}function be(e,t){var r=ne;r&&se.setTimeout(function(){return r(e,t)})}var ge={closed:!0,next:ue,error:function(e){throw e},complete:ue},we="function"==typeof Symbol&&Symbol.observable||"@@observable";function Oe(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,o=function(e){return e&&e instanceof fe||function(e){return e&&Q(e.next)&&Q(e.error)&&Q(e.complete)}(e)&&ee(e)}(e)?e:new ye(e,t,r);return function(e){if(ie){var t=!pe;if(t&&(pe={errorThrown:!1,error:null}),e(),t){var r=pe,n=r.errorThrown,o=r.error;if(pe=null,n)throw o}}else e()}(function(){var e=n,t=e.operator,r=e.source;o.add(t?t.call(o,r):r?n._subscribe(o):n._trySubscribe(o))}),o},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(h){e.error(h)}},e.prototype.forEach=function(e,t){var r=this;return new(t=$e(t))(function(t,n){var o=new ye({next:function(t){try{e(t)}catch(e){n(e),o.unsubscribe()}},error:n,complete:t});r.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null==(t=this.source)?void 0:t.subscribe(e)},e.prototype[we]=function(){return this},e.prototype.pipe=function(){return function(e){return 0===e.length?Oe: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=$e(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 $e(e){var t;return null==(t=null==e?oe:e)?Promise:t}function Se(e,t,r,n,o,i,l){try{var s=e[i](l),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,o)}function _e(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function l(e){Se(i,n,o,l,s,"next",e)}function s(e){Se(i,n,o,l,s,"throw",e)}l(void 0)})}}var Ae=(e={})=>{let{parentOrigin:t="*",timeout:r,debug:n=!1,config:o={}}=e,i=g(n),l=b("App",i),{destroy:s,onDestroy:u}=l;return{promise:new Promise((e,n)=>{let a=j(r,s),c=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,s=new J(n.id,n.appName),u=new J(n.id+"/api",n.appName),p=n.id,f={},d=e=>"api/"+e,h={$emit:(e,...t)=>{s.getEventCallBackLength(e)>0?s.$pureEmit(e,...t):null==f||f.$off(e,()=>{},!0)},onQueryResult:e=>{u.$pureEmit(d(e.reqid),e)},onOsNotify:e=>{}},v=e=>function(t){let r=d(e);u.$on(r,function e(n){t.next(n),n.reqid&&"succ"===n.result&&(t.complete(),u.$off(r,e))})},y=k(t,A(h),F(F({},o),{},{postmateVersion:C}),l,i)(r),b={},g=y.bus;if(g){let e=(e,t,r)=>{r?(t.$__once=!0,s.$once(e,t)):s.$on(e,t),b[e]?b[e].push(t):(b[e]=[t],g.$on(e,p))};Object.assign(f,g,{$on:e,$off:(e,t,r)=>{var n;if(b[e]){let r=b[e].indexOf(t);r>-1&&(b[e].splice(r,1),s.$off(e,t))}r&&delete b[e],null!=(n=b[e])&&n.length||(g.$off(e,p),delete b[e])},$once:(t,r)=>{e(t,r,!0)}})}let w=F(F({},y),{},{bus:f,query:function(){var e=_e(function*(e,t){let r=(null==e?void 0:e.reqid)||(yield y.genReqId());return new Promise((n,o)=>{y.query(F(F({},e),{},{reqid:r}),t).then(e=>{"succ"===(null==e?void 0:e.result)?n(e):o(e)})})});return function(t,r){return e.apply(this,arguments)}}(),createObservableQuery:function(){var e=_e(function*(e,t={}){let r=(null==e?void 0:e.reqid)||(yield y.genReqId()),n=new Pe(v(r));return y.query(F(F({},e),{},{reqid:r}),F(F({},t),{},{observable:!0})),n});return function(t){return e.apply(this,arguments)}}()});y&&(window.removeEventListener(m.Message,c),a(),e({methods:w,config:r.data.config}))}};window.addEventListener(m.Message,c),(()=>{i("Child: Handshake - Sending SYN");let e={penpal:d.Syn},r=t instanceof RegExp?"*":t;window.parent.postMessage(e,r)})(),u(e=>{window.removeEventListener(m.Message,c),e&&n(e)})}),destroy(){s()}}},Ee=null;function je(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?je(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):je(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var Te=class{constructor(){r(this,"options",void 0),r(this,"flutterInAppWebView",null),r(this,"osConnector",null),r(this,"initPromise",void 0),r(this,"isWeb",!0);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 l(function*(){return n.log("Starting initialization..."),new Promise(t=>{var r;o()?(e.isWeb=!1,n.log("Initializing mobile platform..."),new Promise(e=>{var t;(a?window.flutter_inappwebview:s||(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=>{e.flutterInAppWebView=r,n.log("Mobile platform initialized"),t()})):(e.isWeb=!0,n.log("Initializing web platform..."),(Ee?Ee.promise:(Ee=Ae({debug:null==r?void 0:r.debug})).promise).then(r=>{e.osConnector=r,n.log("Web platform initialized"),t()}))})})()}callAppMethod(e,t){var r=this;return l(function*(){return r.flutterInAppWebView?c(r.flutterInAppWebView,e,t):null})()}ready(){var e=this;return l(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 l(function*(){if(yield e.initPromise,e.isWeb){var t;const r=yield null===(t=e.osConnector)||void 0===t?void 0:t.methods.getPlatformConfig();if(!r)throw new Error("Failed to get platform config");return r}{const t=yield e.callAppMethod("getAppMessage");if(!t)throw new Error("Failed to get platform config");return{theme:t.nightMode,language:t.language,appVersion:t.appVersion,systemVersion:t.systemVersion,format:{date:t.dateFormat,time:t.timeFormat}}}})()}setTitle(e){var t=this;return l(function*(){var r;return yield t.initPromise,n.log("Setting title:",e),t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.setTitle(e):t.callAppMethod("updateTitle",e)})()}setExitPageTips(e){var t=this;return l(function*(){var r;return yield t.initPromise,t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.setExitPageTips(e):t.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})()}openFile(e){var t=this;return l(function*(){var r;return yield t.initPromise,n.log("Opening file:",e),t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.openFile(e):t.callAppMethod("openFile",e)})()}openFileManager(e){var t=this;return l(function*(){var r;return yield t.initPromise,n.log("Opening file manager:",e),t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.openFileManagerApp(e):t.callAppMethod("openFileManager",e)})()}openApp(e){var t=this;return l(function*(){var r;if(yield t.initPromise,n.log("Opening app:",e),t.isWeb)return null===(r=t.osConnector)||void 0===r?void 0:r.methods.openApp(e);throw new Error("openApp is not supported on mobile platform")})()}openCustomApp(e,t){var r=this;return l(function*(){var o;if(yield r.initPromise,n.log("Opening custom app:",e,t),r.isWeb)return null===(o=r.osConnector)||void 0===o?void 0:o.methods.openCustomApp(e,t);throw new Error("openCustomApp is not supported on mobile platform")})()}openURL(e,t,r){var o=this;return l(function*(){if(yield o.initPromise,n.log("Opening URL:",e,t,r),!o.isWeb)return o.callAppMethod("openSystemBrowser",e);if(!r)return void window.open(e,t,r);const i=window.open("",t,r);i&&(i.location.href=e)})()}close(){var e=this;return l(function*(){var t;return yield e.initPromise,e.isWeb?null===(t=e.osConnector)||void 0===t?void 0:t.methods.close():e.callAppMethod("exitPage")})()}query(e,t){var r=this;return l(function*(){if(yield r.initPromise,r.isWeb){var n;const o=yield null===(n=r.osConnector)||void 0===n?void 0:n.methods.query(e,t);if(!o)throw new Error("Failed to query");return o}throw new Error("query is not supported on mobile platform")})()}$on(e,t){var r=this;return l(function*(){var n;if(yield r.initPromise,!r.isWeb)throw new Error("$on is not supported on mobile platform");(null===(n=r.osConnector)||void 0===n?void 0:n.methods.bus).$on(e,t)})()}$off(e,t){var r=this;return l(function*(){var n;if(yield r.initPromise,!r.isWeb)throw new Error("$off is not supported on mobile platform");(null===(n=r.osConnector)||void 0===n?void 0:n.methods.bus).$off(e,t)})()}$once(e,t){var r=this;return l(function*(){var n;if(yield r.initPromise,!r.isWeb)throw new Error("$once is not supported on mobile platform");(null===(n=r.osConnector)||void 0===n?void 0:n.methods.bus).$once(e,t)})()}pickFile(e){var t=this;return l(function*(){var r;return yield t.initPromise,t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.pickFile(e):t.flutterInAppWebView?function(e,t){return f.apply(this,arguments)}(t.flutterInAppWebView,e):void 0})()}};exports.TrimApp=Te,exports.default=Te;
package/dist/index.d.ts CHANGED
@@ -1,28 +1,28 @@
1
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; // 应用类型
2
+ name: string;
3
+ icon: string;
4
+ headerIconVisible?: boolean;
5
+ appName: string;
6
+ serviceName?: string;
7
+ alias?: string;
8
+ type: AppType;
9
9
  componentUrl?: string;
10
- iframe?: boolean; // 是否是iframe
11
- microApp?: boolean; // 与飞牛基座适配的微应用
12
- url?: string; // 应用的url(非内置应用的类型)
13
- description?: string; // 应用描述
14
- multiple?: boolean; // 是否支持多开
15
- hiddenDesktopIcon?: boolean; // 是否隐藏桌面图标
16
- enableSettings?: boolean; // 是否开启设置,默认为false
17
- enableMaximize?: boolean; // 是否允许最大化
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
18
  width?: number;
19
19
  style?: any;
20
20
  }
21
21
 
22
22
  declare enum AppType {
23
- INBUILT = "inbuilt", // 内置应用
24
- THIRD_PARTY = "third-party", // 第三方
25
- TEMPORARY = "temporary", // 临时的应用,非常规应用,不会出现在应用列表中,关闭后会被销毁
23
+ INBUILT = "inbuilt",// 内置应用
24
+ THIRD_PARTY = "third-party",// 第三方
25
+ TEMPORARY = "temporary"
26
26
  }
27
27
 
28
28
  declare interface FilePickerParams {
@@ -54,17 +54,7 @@ declare interface FilePickerParams {
54
54
  * @default
55
55
  * ['myFiles']
56
56
  */
57
- sidebarGroup?: (
58
- | "myFiles"
59
- | "otherShare"
60
- | "external"
61
- | "remote"
62
- | "favorites"
63
- | "storage"
64
- | "torrent"
65
- | "team"
66
- | string
67
- )[];
57
+ sidebarGroup?: ("myFiles" | "otherShare" | "external" | "remote" | "favorites" | "storage" | "torrent" | "team" | string)[];
68
58
  /**
69
59
  * 不可选的路径列表, 如果是路径也不可被展开
70
60
  * @example
@@ -118,8 +108,10 @@ declare interface OpenAppParams {
118
108
  custom?: {
119
109
  name?: string;
120
110
  };
121
- app?: App; // 自定义的应用
122
- params?: { [key: string]: any }; // 打开应用时带入的data参数,
111
+ app?: App;
112
+ params?: {
113
+ [key: string]: any;
114
+ };
123
115
  }
124
116
 
125
117
  declare interface PlatformConfig {
@@ -134,9 +126,8 @@ declare interface PlatformConfig {
134
126
  }
135
127
 
136
128
  declare interface QueryConfig {
137
- timer?: boolean; // 是否是 timer 请求
138
- observable?: boolean; // 是否需要 observable 对象
139
-
129
+ timer?: boolean;
130
+ observable?: boolean;
140
131
  encrypt?: boolean;
141
132
  timeout?: number;
142
133
  skipPreflight?: boolean;
@@ -157,10 +148,10 @@ declare interface ResponseDataBase {
157
148
  }
158
149
 
159
150
  declare enum ResponseStatus {
160
- SUCCESS = 'succ', // 成功
161
- FAIL = 'fail', // 失败
162
- CANCEL = 'cancel', // 用户取消
163
- DOING = 'doing', // 任务进行中
151
+ SUCCESS = "succ",// 成功
152
+ FAIL = "fail",// 失败
153
+ CANCEL = "cancel",// 用户取消
154
+ DOING = "doing"
164
155
  }
165
156
 
166
157
  /**
@@ -252,7 +243,7 @@ declare class TrimApp {
252
243
  /**
253
244
  * 选择文件
254
245
  */
255
- pickFile(params: FilePickerParams): Promise<unknown>;
246
+ pickFile(params: FilePickerParams): Promise<string[] | undefined>;
256
247
  }
257
248
  export { TrimApp }
258
249
  export default TrimApp;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var e=Object.defineProperty,t=Object.defineProperties,n=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,n,r)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[n]=r,l=(e,t)=>{for(var n in t||(t={}))o.call(t,n)&&s(e,n,t[n]);if(r)for(var n of r(t))i.call(t,n)&&s(e,n,t[n]);return e},a=(e,r)=>t(e,n(r)),c=(e,t,n)=>s(e,"symbol"!=typeof t?t+"":t,n),u=(e,t,n)=>new Promise((r,o)=>{var i=e=>{try{l(n.next(e))}catch(t){o(t)}},s=e=>{try{l(n.throw(e))}catch(t){o(t)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(i,s);l((n=n.apply(e,t)).next())});const p=new class{constructor(){c(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),n=0;n<e;n++)t[n]=arguments[n];console.log("[Trim App]",...t)}}warn(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.warn("[Trim App]",...t)}}error(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.error("[Trim App]",...t)}}info(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.info("[Trim App]",...t)}}};const d=()=>function(e){const t=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,n={};let r;for(;null!==(r=t.exec(e));)r[1]&&(n.fnOSVersion=r[1]),r[2]&&(n.fnAppType=r[2]),r[3]&&(n.fnAppVersion=r[3]);return n}(navigator.userAgent).fnAppVersion;let h=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{h=!0});const f=/* @__PURE__ */new Map;d()&&(window.fnAppMessage=e=>{p.log("app-message",e);const t=JSON.parse(e),n=f.get(t.reqId);n&&(n(t),f.delete(t.reqId))});var g=/* @__PURE__ */(e=>(e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e))(g||{}),y=/* @__PURE__ */(e=>(e.Fulfilled="fulfilled",e.Rejected="rejected",e))(y||{}),m=/* @__PURE__ */(e=>(e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e))(m||{}),v=/* @__PURE__ */(e=>(e.DataCloneError="DataCloneError",e))(v||{}),b=/* @__PURE__ */(e=>(e.Message="message",e))(b||{});const w=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});let $=0;const A=e=>e?e.split("."):[],_=(e,t,n)=>{const r=A(t);return r.reduce((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===r.length-1&&(e[t]=n),e[t]),e),e},E=(e,t)=>{const n={};return Object.keys(e).forEach(r=>{const o=e[r],i=((e,t)=>{const n=A(t||"");return n.push(e),(e=>e.join("."))(n)})(r,t);"object"==typeof o&&Object.assign(n,E(o,i)),"function"==typeof o&&(n[i]=o)}),n},O=(e,t,n,r,o)=>{const{localName:i,local:s,remote:l,originForSending:a,originForReceiving:c}=t;let u=!1;o(`${i}: Connecting call sender`);const p=e=>(...t)=>{let n;o(`${i}: Sending ${e}() call`);try{l.closed&&(n=!0)}catch(p){n=!0}if(n&&r(),u){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=m.ConnectionDestroyed,t}return new Promise((n,r)=>{const u=++$,p=t=>{if(t.source!==l||t.data.penpal!==g.Reply||t.data.id!==u)return;if("*"!==c&&t.origin!==c)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${c}`);const a=t.data;o(`${i}: Received ${e}() reply`),s.removeEventListener(b.Message,p);let d=a.returnValue;a.returnValueIsError&&(d=(e=>{const t=new Error;return Object.keys(e).forEach(n=>t[n]=e[n]),t})(d)),(a.resolution===y.Fulfilled?n:r)(d)};s.addEventListener(b.Message,p);const d={penpal:g.Call,id:u,methodName:e,args:t};l.postMessage(d,a)})},d=n.reduce((e,t)=>(e[t]=p(t),e),{});return Object.assign(e,(e=>{const t={};for(const n in e)_(t,n,e[n]);return t})(d)),()=>{u=!0}},P="0.1.2",S=(e,t,n,r,o)=>{const{destroy:i,onDestroy:s}=r;return r=>{if(!(e instanceof RegExp?e.test(r.origin):"*"===e||e===r.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${r.origin} which did not match expected origin ${e}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const l="null"===r.origin?"*":r.origin,a={penpal:g.Ack,methodNames:Object.keys(t),config:n};window.parent.postMessage(a,l);const c={localName:"Child",local:window,remote:window.parent,originForSending:l,originForReceiving:r.origin},u=((e,t,n)=>{const{localName:r,local:o,remote:i,originForSending:s,originForReceiving:l}=e;let a=!1;const c=e=>{if(e.source!==i||e.data.penpal!==g.Call)return;if("*"!==l&&e.origin!==l)return void n(`${r} received message from origin ${e.origin} which did not match expected origin ${l}`);const o=e.data,{methodName:c,args:u,id:p}=o;n(`${r}: Received ${c}() call`);const d=e=>t=>{if(n(`${r}: Sending ${c}() reply`),a)return void n(`${r}: Unable to send ${c}() reply due to destroyed connection`);const o={penpal:g.Reply,id:p,resolution:e,returnValue:t};e===y.Rejected&&t instanceof Error&&(o.returnValue=w(t),o.returnValueIsError=!0);try{i.postMessage(o,s)}catch(l){if(l.name===v.DataCloneError){const e={penpal:g.Reply,id:p,resolution:y.Rejected,returnValue:w(l),returnValueIsError:!0};i.postMessage(e,s)}throw l}};new Promise(e=>e(t[c].apply(t,u))).then(d(y.Fulfilled),d(y.Rejected))};return o.addEventListener(b.Message,c),()=>{a=!0,o.removeEventListener(b.Message,c)}})(c,t,o);s(u);const p={},d=O(p,c,r.data.methodNames,i,o);return s(d),p}};function C(e,t){null==console||console.warn(`[fnApp warn]: ${e}`,t)}function M(e,t){null==console||console.error(`[fnApp error]: ${e}`,t)}const j="_fn_all_event",x="事件订阅数量为空",N=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:/* @__PURE__ */new Map;class F{constructor(e,t){c(this,"id"),c(this,"appName"),c(this,"eventObj"),c(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),N.get(this.id)||N.set(this.id,{}),this.eventObj=N.get(this.id)}$on(e,t){const n=this.eventObj[e];return n?(n.includes(t)||n.push(t),this):(this.eventObj[e]=[t],this)}$onAll(e){return this.$on(j,e)}$once(e,t){t.$__once=!0,this.$on(e,t)}$off(e,t){const n=this.eventObj[e];if(!e||!n||!n.length)return C(`${e} ${x}`),this;let r,o=n.length;for(;o--;)if(r=n[o],r===t){n.splice(o,1);break}return this}$offAll(e){return this.$off(j,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let n=0;return N.forEach(r=>{if(r[e])for(let i=r[e].length-1;i>=0;i--){n++;const s=r[e][i];s.$__once&&r[e].splice(i,1);try{s(...t)}catch(o){M(o)}}if(r[j])for(let e=r[j].length-1;e>=0;e--){n++;const i=r[j][e];i.$__once&&r[j].splice(e,1);try{i(...t)}catch(o){M(o)}}}),e&&0!==n||C(`${e} ${x}`),this}$clear(){const e=N.get(this.id)||{};return Object.keys(e).forEach(t=>delete e[t]),this}}var R=function(e,t){return(R=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function T(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}R(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function W(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function k(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(l){o={error:l}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function V(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function I(e){return"function"==typeof e}"function"==typeof SuppressedError&&SuppressedError;var q,D=((q=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(e){Error.call(e),e.stack=(new Error).stack})).prototype=Object.create(Error.prototype),q.prototype.constructor=q,q);function L(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var z=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=W(i),l=s.next();!l.done;l=s.next()){l.value.remove(this)}}catch(h){e={error:h}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var a=this.initialTeardown;if(I(a))try{a()}catch(f){o=f instanceof D?f.errors:[f]}var c=this._finalizers;if(c){this._finalizers=null;try{for(var u=W(c),p=u.next();!p.done;p=u.next()){var d=p.value;try{Y(d)}catch(g){o=null!=o?o:[],g instanceof D?o=V(V([],k(o)),k(g.errors)):o.push(g)}}}catch(y){n={error:y}}finally{try{p&&!p.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}if(o)throw new D(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)Y(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).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)&&L(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&L(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}();function J(e){return e instanceof z||e&&"closed"in e&&I(e.remove)&&I(e.add)&&I(e.unsubscribe)}function Y(e){I(e)?e():e.unsubscribe()}z.EMPTY;var H=void 0,U=function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,V([e,t],k(n)))};function B(){}var K=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,J(t)&&t.add(n)):n.destination=Z,n}return T(t,e),t.create=function(e,t,n){return new G(e,t,n)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(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}(z),Q=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(n){X(n)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){X(n)}else X(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){X(t)}},e}(),G=function(e){function t(t,n,r){var o,i=e.call(this)||this;return o=I(t)||!t?{next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:t,i.destination=new Q(o),i}return T(t,e),t}(K);function X(e){var t;t=e,U(function(){throw t})}var Z={closed:!0,next:B,error:function(e){throw e},complete:B},ee="function"==typeof Symbol&&Symbol.observable||"@@observable";function te(e){return e}var ne=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof K||function(e){return e&&I(e.next)&&I(e.error)&&I(e.complete)}(r)&&J(r)?e:new G(e,t,n);return function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))}(),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=re(t))(function(t,r){var o=new G({next:function(t){try{e(t)}catch(n){r(n),o.unsubscribe()}},error:r,complete:t});n.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[ee]=function(){return this},e.prototype.pipe=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return(0===(e=t).length?te:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)})(this)},e.prototype.toPromise=function(e){var t=this;return new(e=re(e))(function(e,n){var r;t.subscribe(function(e){return r=e},function(e){return n(e)},function(){return e(r)})})},e.create=function(t){return new e(t)},e}();function re(e){var t;return null!==(t=null!=e?e:H)&&void 0!==t?t:Promise}const oe=(e={})=>{const{parentOrigin:t="*",timeout:n,debug:r=!1,config:o={}}=e,i=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(r),s=((e,t)=>{const n=[];let r=!1;return{destroy(o){r||(r=!0,t(`${e}: Destroying connection`),n.forEach(e=>{e(o)}))},onDestroy(e){r?e():n.push(e)}}})("App",i),{destroy:c,onDestroy:p}=s,d=new Promise((e,r)=>{const d=((e,t)=>{let n;return void 0!==e&&(n=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=m.ConnectionTimeout,t(n)},e)),()=>{clearTimeout(n)}})(n,c),h=n=>{if((()=>{try{clearTimeout(void 0)}catch(e){return!1}return!0})()&&n.source===parent&&n.data&&n.data.penpal===g.SynAck){const r=n.data,c=new F(r.id,r.appName),p=new F(r.id+"/api",r.appName),f=r.id,g={},y=e=>"api/"+e,m=e=>function(t){const n=y(e);p.$on(n,function e(r){t.next(r),r.reqid&&"succ"===r.result&&(t.complete(),p.$off(n,e))})},v=E({$emit:(e,...t)=>{c.getEventCallBackLength(e)>0?c.$pureEmit(e,...t):null==g||g.$off(e,()=>{},!0)},onQueryResult:e=>{p.$pureEmit(y(e.reqid),e)},onOsNotify:e=>{}}),w=S(t,v,a(l({},o),{postmateVersion:P}),s,i)(n),$={},A=w.bus;if(A){const e=(e,t,n)=>{n?(t.$__once=!0,c.$once(e,t)):c.$on(e,t),$[e]?$[e].push(t):($[e]=[t],A.$on(e,f))};Object.assign(g,A,{$on:e,$off:(e,t,n)=>{var r;if($[e]){const n=$[e].indexOf(t);n>-1&&($[e].splice(n,1),c.$off(e,t))}n&&delete $[e],(null==(r=$[e])?void 0:r.length)||(A.$off(e,f),delete $[e])},$once:(t,n)=>{e(t,n,!0)}})}const _=a(l({},w),{bus:g,query:(e,t)=>u(null,null,function*(){const n=(null==e?void 0:e.reqid)||(yield w.genReqId());return new Promise((r,o)=>{w.query(a(l({},e),{reqid:n}),t).then(e=>{"succ"===(null==e?void 0:e.result)?r(e):o(e)})})}),createObservableQuery:(e,...t)=>u(null,[e,...t],function*(e,t={}){const n=(null==e?void 0:e.reqid)||(yield w.genReqId()),r=new ne(m(n));return w.query(a(l({},e),{reqid:n}),a(l({},t),{observable:!0})),r})});w&&(window.removeEventListener(b.Message,h),d(),e({methods:_,config:n.data.config}))}};window.addEventListener(b.Message,h),(()=>{i("Child: Handshake - Sending SYN");const e={penpal:g.Syn},n=t instanceof RegExp?"*":t;window.parent.postMessage(e,n)})(),p(e=>{window.removeEventListener(b.Message,h),e&&r(e)})});return{promise:d,destroy(){c()}}};let ie=null;class se{constructor(){c(this,"options"),c(this,"flutterInAppWebView",null),c(this,"osConnector",null),c(this,"initPromise"),c(this,"isWeb",!0);let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,e.debug&&(p.setDebug(!0),p.log("Trim App initialized with debug mode")),p.log("Options:",e),this.initPromise=this.init()}init(){return u(this,null,function*(){return p.log("Starting initialization..."),new Promise(e=>{var t;d()?(this.isWeb=!1,p.log("Initializing mobile platform..."),new Promise(e=>{var t;h||(null==(t=window.flutter_inappwebview)?void 0:t._platformReady)?(p.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{p.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)})}).then(t=>{this.flutterInAppWebView=t,p.log("Mobile platform initialized"),e()})):(this.isWeb=!0,p.log("Initializing web platform..."),(ie||(ie=oe({debug:null==t?void 0:t.debug})),ie.promise).then(t=>{this.osConnector=t,p.log("Web platform initialized"),e()}))})})}callAppMethod(e,t){return u(this,null,function*(){return this.flutterInAppWebView?((e,t,n)=>u(null,null,function*(){p.log(`callHandler: ${t}, params: ${n}`);const r=yield e.callHandler(t,n);if(r)try{const e=JSON.parse(r);p.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return p.log(`appMessage: ${JSON.stringify(t)}`),t}catch(o){return p.error(`error: ${o}`),null}return null}))(this.flutterInAppWebView,e,t):null})}ready(){return u(this,null,function*(){return this.initPromise})}getOptions(){return this.options}setOptions(e){this.options=l(l({},this.options),e),void 0!==e.debug&&p.setDebug(e.debug),p.log("Options updated:",this.options)}getPlatformConfig(){return u(this,null,function*(){var e;if(yield this.initPromise,this.isWeb){const t=yield null==(e=this.osConnector)?void 0:e.methods.getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}{const e=yield this.callAppMethod("getAppMessage");if(!e)throw new Error("Failed to get platform config");return{theme:e.nightMode,language:e.language,appVersion:e.appVersion,systemVersion:e.systemVersion,format:{date:e.dateFormat,time:e.timeFormat}}}})}setTitle(e){return u(this,null,function*(){var t;return yield this.initPromise,p.log("Setting title:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)})}setExitPageTips(e){return u(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})}openFile(e){return u(this,null,function*(){var t;return yield this.initPromise,p.log("Opening file:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)})}openFileManager(e){return u(this,null,function*(){var t;return yield this.initPromise,p.log("Opening file manager:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)})}openApp(e){return u(this,null,function*(){var t;if(yield this.initPromise,p.log("Opening app:",e),this.isWeb)return null==(t=this.osConnector)?void 0:t.methods.openApp(e);throw new Error("openApp is not supported on mobile platform")})}openCustomApp(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,p.log("Opening custom app:",e,t),this.isWeb)return null==(n=this.osConnector)?void 0:n.methods.openCustomApp(e,t);throw new Error("openCustomApp is not supported on mobile platform")})}openURL(e,t,n){return u(this,null,function*(){if(yield this.initPromise,p.log("Opening URL:",e,t,n),!this.isWeb)return this.callAppMethod("openSystemBrowser",e);if(!n)return void window.open(e,t,n);const r=window.open("",t,n);r&&(r.location.href=e)})}close(){return u(this,null,function*(){var e;return yield this.initPromise,this.isWeb?null==(e=this.osConnector)?void 0:e.methods.close():this.callAppMethod("exitPage")})}query(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,this.isWeb){const r=yield null==(n=this.osConnector)?void 0:n.methods.query(e,t);if(!r)throw new Error("Failed to query");return r}throw new Error("query is not supported on mobile platform")})}$on(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$on is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$on(e,t)})}$off(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$off is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$off(e,t)})}$once(e,t){return u(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$once is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$once(e,t)})}pickFile(e){return u(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))})}}export{se as TrimApp,se 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 o=n.call(t,r||"default");if("object"!=e(o))return o;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 o=()=>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 i(e,t,r,n,o,i,l){try{var s=e[i](l),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,o)}function l(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var l=e.apply(t,r);function s(e){i(l,n,o,s,u,"next",e)}function u(e){i(l,n,o,s,u,"throw",e)}s(void 0)})}}var s=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{s=!0});var u,a=/(iPad|iPhone|iPod|Macintosh|Mac OS X)/i.test(navigator.userAgent),c=(u=l(function*(e,t,r){n.log(`callHandler: ${t}, params: ${r}`);const o=yield e.callHandler(t,r);if(o)try{const e=JSON.parse(o);n.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return n.log(`appMessage: ${JSON.stringify(t)}`),t}catch(i){return n.error(`error: ${i}`),null}return null}),function(e,t,r){return u.apply(this,arguments)}),p=/* @__PURE__ */new Map;function f(){return(f=l(function*(e,t){return new Promise((r,o)=>{null==e||e.callHandler("openFolder",JSON.stringify(t)).then(e=>{if(n.log("pickFilePromise callback registered",{reqId:e,params:t}),e){function i(e){r(e.result)}p.set(e,i)}else o(/* @__PURE__ */new Error("openFolder failed"))})})})).apply(this,arguments)}o()&&(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}({}),h=/* @__PURE__ */function(e){return e.Fulfilled="fulfilled",e.Rejected="rejected",e}({}),v=/* @__PURE__ */function(e){return e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e}({}),y=/* @__PURE__ */function(e){return e.DataCloneError="DataCloneError",e}({}),m=/* @__PURE__ */function(e){return e.Message="message",e}({}),b=(e,t)=>{let r=[],n=!1;return{destroy(o){n||(n=!0,t(`${e}: Destroying connection`),r.forEach(e=>{e(o)}))},onDestroy(e){n?e():r.push(e)}}},g=e=>(...t)=>{e&&console.log("[Penpal]",...t)},w=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),O=(e,t,r)=>{let{localName:n,local:o,remote:i,originForSending:l,originForReceiving:s}=e,u=!1,a=e=>{if(e.source!==i||e.data.penpal!==d.Call)return;if("*"!==s&&e.origin!==s)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${s}`);let{methodName:o,args:a,id:c}=e.data;r(`${n}: Received ${o}() call`);let p=e=>t=>{if(r(`${n}: Sending ${o}() reply`),u)return void r(`${n}: Unable to send ${o}() reply due to destroyed connection`);let s={penpal:d.Reply,id:c,resolution:e,returnValue:t};e===h.Rejected&&t instanceof Error&&(s.returnValue=w(t),s.returnValueIsError=!0);try{i.postMessage(s,l)}catch(e){if(e.name===y.DataCloneError){let r={penpal:d.Reply,id:c,resolution:h.Rejected,returnValue:w(e),returnValueIsError:!0};i.postMessage(r,l)}throw e}};new Promise(e=>e(t[o].apply(t,a))).then(p(h.Fulfilled),p(h.Rejected))};return o.addEventListener(m.Message,a),()=>{u=!0,o.removeEventListener(m.Message,a)}},P=0,$=()=>++P,S=e=>e?e.split("."):[],_=(e,t,r)=>{let n=S(t);return n.reduce((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===n.length-1&&(e[t]=r),e[t]),e),e},A=(e,t)=>{let r={};return Object.keys(e).forEach(n=>{let o=e[n],i=((e,t)=>{let r=S(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof o&&Object.assign(r,A(o,i)),"function"==typeof o&&(r[i]=o)}),r},E=(e,t,r,n,o)=>{let{localName:i,local:l,remote:s,originForSending:u,originForReceiving:a}=t,c=!1;o(`${i}: Connecting call sender`);let p=e=>(...t)=>{let r;o(`${i}: Sending ${e}() call`);try{s.closed&&(r=!0)}catch(d){r=!0}if(r&&n(),c){let t=/* @__PURE__ */Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=v.ConnectionDestroyed,t}return new Promise((r,n)=>{let c=$(),p=t=>{if(t.source!==s||t.data.penpal!==d.Reply||t.data.id!==c)return;if("*"!==a&&t.origin!==a)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${a}`);let u=t.data;o(`${i}: Received ${e}() reply`),l.removeEventListener(m.Message,p);let f=u.returnValue;u.returnValueIsError&&(f=(e=>{let t=/* @__PURE__ */Error();return Object.keys(e).forEach(r=>t[r]=e[r]),t})(f)),(u.resolution===h.Fulfilled?r:n)(f)};l.addEventListener(m.Message,p);let f={penpal:d.Call,id:c,methodName:e,args:t};s.postMessage(f,u)})},f=r.reduce((e,t)=>(e[t]=p(t),e),{});return Object.assign(e,(e=>{let t={};for(let r in e)_(t,r,e[r]);return t})(f)),()=>{c=!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=v.ConnectionTimeout,t(r)},e)),()=>{clearTimeout(r)}},C="0.1.2";function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function x(e){var t=function(e,t){if("object"!=T(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=T(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==T(t)?t:t+""}function M(e,t,r){return(t=x(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function N(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 F(e){for(var t=1;t<arguments.length;t++){var r=null==arguments[t]?{}:arguments[t];t%2?N(Object(r),!0).forEach(function(t){M(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):N(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var k=(e,t,r,n,o)=>{let{destroy:i,onDestroy:l}=n;return n=>{if(!(e instanceof RegExp?e.test(n.origin):"*"===e||e===n.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${n.origin} which did not match expected origin ${e}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");let s="null"===n.origin?"*":n.origin,u={penpal:d.Ack,methodNames:Object.keys(t),config:r};window.parent.postMessage(u,s);let a={localName:"Child",local:window,remote:window.parent,originForSending:s,originForReceiving:n.origin};l(O(a,t,o));let c={};return l(E(c,a,n.data.methodNames,i,o)),c}};function W(e,t){var r;null==(r=console)||r.warn(`[fnApp warn]: ${e}`,t)}function R(e,t){var r;null==(r=console)||r.error(`[fnApp error]: ${e}`,t)}var D="_fn_all_event",V="事件订阅数量为空";function I(e){return I="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},I(e)}function q(e){var t=function(e,t){if("object"!=I(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=I(n))return n;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==I(t)?t:t+""}function L(e,t,r){return(t=q(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var z=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:/* @__PURE__ */new Map,J=class{constructor(e,t){L(this,"id",void 0),L(this,"appName",void 0),L(this,"eventObj",void 0),L(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),z.get(this.id)||z.set(this.id,{}),this.eventObj=z.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(D,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 W(`${e} ${V}`),this;let n,o=r.length;for(;o--;)if(n=r[o],n===t){r.splice(o,1);break}return this}$offAll(e){return this.$off(D,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let r=0;return z.forEach(n=>{if(n[e])for(let o=n[e].length-1;o>=0;o--){r++;let i=n[e][o];i.$__once&&n[e].splice(o,1);try{i(...t)}catch(e){R(e)}}if(n._fn_all_event)for(let o=n[D].length-1;o>=0;o--){r++;let i=n[D][o];i.$__once&&n[D].splice(o,1);try{i(...t)}catch(e){R(e)}}}),(!e||0===r)&&W(`${e} ${V}`),this}$clear(){let e=z.get(this.id)||{};return Object.keys(e).forEach(t=>delete e[t]),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 Y(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 U(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 B(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),l=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)l.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return l}function K(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)(n||!(o in t))&&(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}function Q(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 G(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var Z=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,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var l=U(i),s=l.next();!s.done;s=l.next())s.value.remove(this)}catch(t){e={error:t}}finally{try{s&&!s.done&&(t=l.return)&&t.call(l)}finally{if(e)throw e.error}}else i.remove(this);var u=this.initialTeardown;if(Q(u))try{u()}catch(e){o=e instanceof X?e.errors:[e]}var a=this._finalizers;if(a){this._finalizers=null;try{for(var c=U(a),p=c.next();!p.done;p=c.next()){var f=p.value;try{te(f)}catch(e){o=null==o?[]:o,e instanceof X?o=K(K([],B(o)),B(e.errors)):o.push(e)}}}catch(e){r={error:e}}finally{try{p&&!p.done&&(n=c.return)&&n.call(c)}finally{if(r)throw r.error}}}if(o)throw new X(o)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)te(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)&&G(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&G(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();function ee(e){return e instanceof Z||e&&"closed"in e&&Q(e.remove)&&Q(e.add)&&Q(e.unsubscribe)}function te(e){Q(e)?e():e.unsubscribe()}Z.EMPTY;var re=null,ne=null,oe=void 0,ie=!1,le=!1,se={setTimeout:function(e,t){var r=[...arguments].slice(2),n=se.delegate;return null!=n&&n.setTimeout?n.setTimeout.apply(n,K([e,t],B(r))):setTimeout.apply(void 0,K([e,t],B(r)))},clearTimeout:function(e){var t=se.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function ue(){}var ae=ce("C",void 0,void 0);function ce(e,t,r){return{kind:e,value:t,error:r}}var pe=null;var fe=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,ee(t)&&t.add(r)):r.destination=ge,r}return Y(t,e),t.create=function(e,t,r){return new ye(e,t,r)},t.prototype.next=function(e){this.isStopped?be(function(e){return ce("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?be(function(e){return ce("E",void 0,e)}(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?be(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}(Z),de=Function.prototype.bind;function he(e,t){return de.call(e,t)}var ve=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){me(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){me(e)}else me(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){me(e)}},e}(),ye=function(e){function t(t,r,n){var o,i,l=e.call(this)||this;Q(t)||!t?o={next:null==t?void 0:t,error:null==r?void 0:r,complete:null==n?void 0:n}:l&&le?((i=Object.create(t)).unsubscribe=function(){return l.unsubscribe()},o={next:t.next&&he(t.next,i),error:t.error&&he(t.error,i),complete:t.complete&&he(t.complete,i)}):o=t;return l.destination=new ve(o),l}return Y(t,e),t}(fe);function me(e){ie?function(e){ie&&pe&&(pe.errorThrown=!0,pe.error=e)}(e):function(e){se.setTimeout(function(){if(!re)throw e;re(e)})}(e)}function be(e,t){var r=ne;r&&se.setTimeout(function(){return r(e,t)})}var ge={closed:!0,next:ue,error:function(e){throw e},complete:ue},we="function"==typeof Symbol&&Symbol.observable||"@@observable";function Oe(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,o=function(e){return e&&e instanceof fe||function(e){return e&&Q(e.next)&&Q(e.error)&&Q(e.complete)}(e)&&ee(e)}(e)?e:new ye(e,t,r);return function(e){if(ie){var t=!pe;if(t&&(pe={errorThrown:!1,error:null}),e(),t){var r=pe,n=r.errorThrown,o=r.error;if(pe=null,n)throw o}}else e()}(function(){var e=n,t=e.operator,r=e.source;o.add(t?t.call(o,r):r?n._subscribe(o):n._trySubscribe(o))}),o},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(h){e.error(h)}},e.prototype.forEach=function(e,t){var r=this;return new(t=$e(t))(function(t,n){var o=new ye({next:function(t){try{e(t)}catch(e){n(e),o.unsubscribe()}},error:n,complete:t});r.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null==(t=this.source)?void 0:t.subscribe(e)},e.prototype[we]=function(){return this},e.prototype.pipe=function(){return function(e){return 0===e.length?Oe: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=$e(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 $e(e){var t;return null==(t=null==e?oe:e)?Promise:t}function Se(e,t,r,n,o,i,l){try{var s=e[i](l),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,o)}function _e(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function l(e){Se(i,n,o,l,s,"next",e)}function s(e){Se(i,n,o,l,s,"throw",e)}l(void 0)})}}var Ae=(e={})=>{let{parentOrigin:t="*",timeout:r,debug:n=!1,config:o={}}=e,i=g(n),l=b("App",i),{destroy:s,onDestroy:u}=l;return{promise:new Promise((e,n)=>{let a=j(r,s),c=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,s=new J(n.id,n.appName),u=new J(n.id+"/api",n.appName),p=n.id,f={},d=e=>"api/"+e,h={$emit:(e,...t)=>{s.getEventCallBackLength(e)>0?s.$pureEmit(e,...t):null==f||f.$off(e,()=>{},!0)},onQueryResult:e=>{u.$pureEmit(d(e.reqid),e)},onOsNotify:e=>{}},v=e=>function(t){let r=d(e);u.$on(r,function e(n){t.next(n),n.reqid&&"succ"===n.result&&(t.complete(),u.$off(r,e))})},y=k(t,A(h),F(F({},o),{},{postmateVersion:C}),l,i)(r),b={},g=y.bus;if(g){let e=(e,t,r)=>{r?(t.$__once=!0,s.$once(e,t)):s.$on(e,t),b[e]?b[e].push(t):(b[e]=[t],g.$on(e,p))};Object.assign(f,g,{$on:e,$off:(e,t,r)=>{var n;if(b[e]){let r=b[e].indexOf(t);r>-1&&(b[e].splice(r,1),s.$off(e,t))}r&&delete b[e],null!=(n=b[e])&&n.length||(g.$off(e,p),delete b[e])},$once:(t,r)=>{e(t,r,!0)}})}let w=F(F({},y),{},{bus:f,query:function(){var e=_e(function*(e,t){let r=(null==e?void 0:e.reqid)||(yield y.genReqId());return new Promise((n,o)=>{y.query(F(F({},e),{},{reqid:r}),t).then(e=>{"succ"===(null==e?void 0:e.result)?n(e):o(e)})})});return function(t,r){return e.apply(this,arguments)}}(),createObservableQuery:function(){var e=_e(function*(e,t={}){let r=(null==e?void 0:e.reqid)||(yield y.genReqId()),n=new Pe(v(r));return y.query(F(F({},e),{},{reqid:r}),F(F({},t),{},{observable:!0})),n});return function(t){return e.apply(this,arguments)}}()});y&&(window.removeEventListener(m.Message,c),a(),e({methods:w,config:r.data.config}))}};window.addEventListener(m.Message,c),(()=>{i("Child: Handshake - Sending SYN");let e={penpal:d.Syn},r=t instanceof RegExp?"*":t;window.parent.postMessage(e,r)})(),u(e=>{window.removeEventListener(m.Message,c),e&&n(e)})}),destroy(){s()}}},Ee=null;function je(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?je(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):je(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var Te=class{constructor(){r(this,"options",void 0),r(this,"flutterInAppWebView",null),r(this,"osConnector",null),r(this,"initPromise",void 0),r(this,"isWeb",!0);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 l(function*(){return n.log("Starting initialization..."),new Promise(t=>{var r;o()?(e.isWeb=!1,n.log("Initializing mobile platform..."),new Promise(e=>{var t;(a?window.flutter_inappwebview:s||(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=>{e.flutterInAppWebView=r,n.log("Mobile platform initialized"),t()})):(e.isWeb=!0,n.log("Initializing web platform..."),(Ee?Ee.promise:(Ee=Ae({debug:null==r?void 0:r.debug})).promise).then(r=>{e.osConnector=r,n.log("Web platform initialized"),t()}))})})()}callAppMethod(e,t){var r=this;return l(function*(){return r.flutterInAppWebView?c(r.flutterInAppWebView,e,t):null})()}ready(){var e=this;return l(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 l(function*(){if(yield e.initPromise,e.isWeb){var t;const r=yield null===(t=e.osConnector)||void 0===t?void 0:t.methods.getPlatformConfig();if(!r)throw new Error("Failed to get platform config");return r}{const t=yield e.callAppMethod("getAppMessage");if(!t)throw new Error("Failed to get platform config");return{theme:t.nightMode,language:t.language,appVersion:t.appVersion,systemVersion:t.systemVersion,format:{date:t.dateFormat,time:t.timeFormat}}}})()}setTitle(e){var t=this;return l(function*(){var r;return yield t.initPromise,n.log("Setting title:",e),t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.setTitle(e):t.callAppMethod("updateTitle",e)})()}setExitPageTips(e){var t=this;return l(function*(){var r;return yield t.initPromise,t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.setExitPageTips(e):t.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})()}openFile(e){var t=this;return l(function*(){var r;return yield t.initPromise,n.log("Opening file:",e),t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.openFile(e):t.callAppMethod("openFile",e)})()}openFileManager(e){var t=this;return l(function*(){var r;return yield t.initPromise,n.log("Opening file manager:",e),t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.openFileManagerApp(e):t.callAppMethod("openFileManager",e)})()}openApp(e){var t=this;return l(function*(){var r;if(yield t.initPromise,n.log("Opening app:",e),t.isWeb)return null===(r=t.osConnector)||void 0===r?void 0:r.methods.openApp(e);throw new Error("openApp is not supported on mobile platform")})()}openCustomApp(e,t){var r=this;return l(function*(){var o;if(yield r.initPromise,n.log("Opening custom app:",e,t),r.isWeb)return null===(o=r.osConnector)||void 0===o?void 0:o.methods.openCustomApp(e,t);throw new Error("openCustomApp is not supported on mobile platform")})()}openURL(e,t,r){var o=this;return l(function*(){if(yield o.initPromise,n.log("Opening URL:",e,t,r),!o.isWeb)return o.callAppMethod("openSystemBrowser",e);if(!r)return void window.open(e,t,r);const i=window.open("",t,r);i&&(i.location.href=e)})()}close(){var e=this;return l(function*(){var t;return yield e.initPromise,e.isWeb?null===(t=e.osConnector)||void 0===t?void 0:t.methods.close():e.callAppMethod("exitPage")})()}query(e,t){var r=this;return l(function*(){if(yield r.initPromise,r.isWeb){var n;const o=yield null===(n=r.osConnector)||void 0===n?void 0:n.methods.query(e,t);if(!o)throw new Error("Failed to query");return o}throw new Error("query is not supported on mobile platform")})()}$on(e,t){var r=this;return l(function*(){var n;if(yield r.initPromise,!r.isWeb)throw new Error("$on is not supported on mobile platform");(null===(n=r.osConnector)||void 0===n?void 0:n.methods.bus).$on(e,t)})()}$off(e,t){var r=this;return l(function*(){var n;if(yield r.initPromise,!r.isWeb)throw new Error("$off is not supported on mobile platform");(null===(n=r.osConnector)||void 0===n?void 0:n.methods.bus).$off(e,t)})()}$once(e,t){var r=this;return l(function*(){var n;if(yield r.initPromise,!r.isWeb)throw new Error("$once is not supported on mobile platform");(null===(n=r.osConnector)||void 0===n?void 0:n.methods.bus).$once(e,t)})()}pickFile(e){var t=this;return l(function*(){var r;return yield t.initPromise,t.isWeb?null===(r=t.osConnector)||void 0===r?void 0:r.methods.pickFile(e):t.flutterInAppWebView?function(e,t){return f.apply(this,arguments)}(t.flutterInAppWebView,e):void 0})()}};export{Te as TrimApp,Te as default};
package/package.json CHANGED
@@ -1,36 +1,40 @@
1
1
  {
2
2
  "name": "@trimjs/web-app",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "web app sdk for nas",
5
- "type": "module",
6
- "main": "dist/index.cjs",
7
- "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
9
- "scripts": {
10
- "dev": "vite",
11
- "build": "vite build",
12
- "lint": "eslint .",
13
- "typecheck": "tsc --noEmit"
14
- },
15
5
  "files": [
16
6
  "dist"
17
7
  ],
8
+ "type": "module",
9
+ "main": "./dist/index.cjs",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs"
17
+ }
18
+ },
18
19
  "publishConfig": {
19
20
  "access": "public"
20
21
  },
22
+ "scripts": {
23
+ "dev": "vp dev",
24
+ "build": "vp build",
25
+ "lint": "vp lint .",
26
+ "test": "bun test",
27
+ "typecheck": "tsc --noEmit"
28
+ },
21
29
  "devDependencies": {
22
30
  "@babel/preset-env": "^7.21.4",
23
- "@eslint/js": "^9.13.0",
24
31
  "@fn/micro-app-event": "workspace:*",
25
32
  "@fn/micro-app-postmate": "workspace:*",
26
- "@microsoft/api-extractor": "^7.52.8",
27
33
  "@rollup/plugin-babel": "^6.1.0",
28
- "eslint": "^9.13.0",
29
- "globals": "^15.11.0",
30
34
  "terser": "^5.46.0",
31
35
  "typescript": "~5.6.2",
32
- "typescript-eslint": "^8.11.0",
33
- "vite": "^7.3.1",
34
- "vite-plugin-dts": "^4.5.4"
36
+ "vite": "catalog:",
37
+ "vite-plugin-dts": "^4.5.4",
38
+ "vite-plus": "catalog:"
35
39
  }
36
40
  }
@@ -1 +0,0 @@
1
- var TrimApp=function(e){"use strict";var t=Object.defineProperty,n=Object.defineProperties,r=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,l=(e,n,r)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r,a=(e,t)=>{for(var n in t||(t={}))i.call(t,n)&&l(e,n,t[n]);if(o)for(var n of o(t))s.call(t,n)&&l(e,n,t[n]);return e},c=(e,t)=>n(e,r(t)),u=(e,t,n)=>l(e,"symbol"!=typeof t?t+"":t,n),p=(e,t,n)=>new Promise((r,o)=>{var i=e=>{try{l(n.next(e))}catch(t){o(t)}},s=e=>{try{l(n.throw(e))}catch(t){o(t)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(i,s);l((n=n.apply(e,t)).next())});const d=new class{constructor(){u(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),n=0;n<e;n++)t[n]=arguments[n];console.log("[Trim App]",...t)}}warn(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.warn("[Trim App]",...t)}}error(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.error("[Trim App]",...t)}}info(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.info("[Trim App]",...t)}}};const h=()=>function(e){const t=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,n={};let r;for(;null!==(r=t.exec(e));)r[1]&&(n.fnOSVersion=r[1]),r[2]&&(n.fnAppType=r[2]),r[3]&&(n.fnAppVersion=r[3]);return n}(navigator.userAgent).fnAppVersion;let f=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{f=!0});const g=new Map;h()&&(window.fnAppMessage=e=>{d.log("app-message",e);const t=JSON.parse(e),n=g.get(t.reqId);n&&(n(t),g.delete(t.reqId))});var y=(e=>(e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e))(y||{}),m=(e=>(e.Fulfilled="fulfilled",e.Rejected="rejected",e))(m||{}),v=(e=>(e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e))(v||{}),b=(e=>(e.DataCloneError="DataCloneError",e))(b||{}),w=(e=>(e.Message="message",e))(w||{});const $=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});let A=0;const _=e=>e?e.split("."):[],E=(e,t,n)=>{const r=_(t);return r.reduce((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===r.length-1&&(e[t]=n),e[t]),e),e},O=(e,t)=>{const n={};return Object.keys(e).forEach(r=>{const o=e[r],i=((e,t)=>{const n=_(t||"");return n.push(e),(e=>e.join("."))(n)})(r,t);"object"==typeof o&&Object.assign(n,O(o,i)),"function"==typeof o&&(n[i]=o)}),n},P=(e,t,n,r,o)=>{const{localName:i,local:s,remote:l,originForSending:a,originForReceiving:c}=t;let u=!1;o(`${i}: Connecting call sender`);const p=e=>(...t)=>{let n;o(`${i}: Sending ${e}() call`);try{l.closed&&(n=!0)}catch(p){n=!0}if(n&&r(),u){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=v.ConnectionDestroyed,t}return new Promise((n,r)=>{const u=++A,p=t=>{if(t.source!==l||t.data.penpal!==y.Reply||t.data.id!==u)return;if("*"!==c&&t.origin!==c)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${c}`);const a=t.data;o(`${i}: Received ${e}() reply`),s.removeEventListener(w.Message,p);let d=a.returnValue;a.returnValueIsError&&(d=(e=>{const t=new Error;return Object.keys(e).forEach(n=>t[n]=e[n]),t})(d)),(a.resolution===m.Fulfilled?n:r)(d)};s.addEventListener(w.Message,p);const d={penpal:y.Call,id:u,methodName:e,args:t};l.postMessage(d,a)})},d=n.reduce((e,t)=>(e[t]=p(t),e),{});return Object.assign(e,(e=>{const t={};for(const n in e)E(t,n,e[n]);return t})(d)),()=>{u=!0}},S="0.1.2",C=(e,t,n,r,o)=>{const{destroy:i,onDestroy:s}=r;return r=>{if(!(e instanceof RegExp?e.test(r.origin):"*"===e||e===r.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${r.origin} which did not match expected origin ${e}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const l="null"===r.origin?"*":r.origin,a={penpal:y.Ack,methodNames:Object.keys(t),config:n};window.parent.postMessage(a,l);const c={localName:"Child",local:window,remote:window.parent,originForSending:l,originForReceiving:r.origin},u=((e,t,n)=>{const{localName:r,local:o,remote:i,originForSending:s,originForReceiving:l}=e;let a=!1;const c=e=>{if(e.source!==i||e.data.penpal!==y.Call)return;if("*"!==l&&e.origin!==l)return void n(`${r} received message from origin ${e.origin} which did not match expected origin ${l}`);const o=e.data,{methodName:c,args:u,id:p}=o;n(`${r}: Received ${c}() call`);const d=e=>t=>{if(n(`${r}: Sending ${c}() reply`),a)return void n(`${r}: Unable to send ${c}() reply due to destroyed connection`);const o={penpal:y.Reply,id:p,resolution:e,returnValue:t};e===m.Rejected&&t instanceof Error&&(o.returnValue=$(t),o.returnValueIsError=!0);try{i.postMessage(o,s)}catch(l){if(l.name===b.DataCloneError){const e={penpal:y.Reply,id:p,resolution:m.Rejected,returnValue:$(l),returnValueIsError:!0};i.postMessage(e,s)}throw l}};new Promise(e=>e(t[c].apply(t,u))).then(d(m.Fulfilled),d(m.Rejected))};return o.addEventListener(w.Message,c),()=>{a=!0,o.removeEventListener(w.Message,c)}})(c,t,o);s(u);const p={},d=P(p,c,r.data.methodNames,i,o);return s(d),p}};function M(e,t){null==console||console.warn(`[fnApp warn]: ${e}`,t)}function j(e,t){null==console||console.error(`[fnApp error]: ${e}`,t)}const x="_fn_all_event",N="事件订阅数量为空",T=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map;class F{constructor(e,t){u(this,"id"),u(this,"appName"),u(this,"eventObj"),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(),T.get(this.id)||T.set(this.id,{}),this.eventObj=T.get(this.id)}$on(e,t){const n=this.eventObj[e];return n?(n.includes(t)||n.push(t),this):(this.eventObj[e]=[t],this)}$onAll(e){return this.$on(x,e)}$once(e,t){t.$__once=!0,this.$on(e,t)}$off(e,t){const n=this.eventObj[e];if(!e||!n||!n.length)return M(`${e} ${N}`),this;let r,o=n.length;for(;o--;)if(r=n[o],r===t){n.splice(o,1);break}return this}$offAll(e){return this.$off(x,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let n=0;return T.forEach(r=>{if(r[e])for(let i=r[e].length-1;i>=0;i--){n++;const s=r[e][i];s.$__once&&r[e].splice(i,1);try{s(...t)}catch(o){j(o)}}if(r[x])for(let e=r[x].length-1;e>=0;e--){n++;const i=r[x][e];i.$__once&&r[x].splice(e,1);try{i(...t)}catch(o){j(o)}}}),e&&0!==n||M(`${e} ${N}`),this}$clear(){const e=T.get(this.id)||{};return Object.keys(e).forEach(t=>delete e[t]),this}}var R=function(e,t){return(R=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function W(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}R(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function k(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function V(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(l){o={error:l}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function I(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function q(e){return"function"==typeof e}"function"==typeof SuppressedError&&SuppressedError;var D,L=((D=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(e){Error.call(e),e.stack=(new Error).stack})).prototype=Object.create(Error.prototype),D.prototype.constructor=D,D);function z(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var J=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=k(i),l=s.next();!l.done;l=s.next()){l.value.remove(this)}}catch(h){e={error:h}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var a=this.initialTeardown;if(q(a))try{a()}catch(f){o=f instanceof L?f.errors:[f]}var c=this._finalizers;if(c){this._finalizers=null;try{for(var u=k(c),p=u.next();!p.done;p=u.next()){var d=p.value;try{H(d)}catch(g){o=null!=o?o:[],g instanceof L?o=I(I([],V(o)),V(g.errors)):o.push(g)}}}catch(y){n={error:y}}finally{try{p&&!p.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}if(o)throw new L(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)H(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).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 n=this._finalizers;n&&z(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}();function Y(e){return e instanceof J||e&&"closed"in e&&q(e.remove)&&q(e.add)&&q(e.unsubscribe)}function H(e){q(e)?e():e.unsubscribe()}J.EMPTY;var U=void 0,B=function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,I([e,t],V(n)))};function K(){}var Q=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,Y(t)&&t.add(n)):n.destination=ee,n}return W(t,e),t.create=function(e,t,n){return new X(e,t,n)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(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}(J),G=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(n){Z(n)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){Z(n)}else Z(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){Z(t)}},e}(),X=function(e){function t(t,n,r){var o,i=e.call(this)||this;return o=q(t)||!t?{next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:t,i.destination=new G(o),i}return W(t,e),t}(Q);function Z(e){var t;t=e,B(function(){throw t})}var ee={closed:!0,next:K,error:function(e){throw e},complete:K},te="function"==typeof Symbol&&Symbol.observable||"@@observable";function ne(e){return e}var re=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof Q||function(e){return e&&q(e.next)&&q(e.error)&&q(e.complete)}(r)&&Y(r)?e:new X(e,t,n);return function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))}(),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=oe(t))(function(t,r){var o=new X({next:function(t){try{e(t)}catch(n){r(n),o.unsubscribe()}},error:r,complete:t});n.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[te]=function(){return this},e.prototype.pipe=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return(0===(e=t).length?ne:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)})(this)},e.prototype.toPromise=function(e){var t=this;return new(e=oe(e))(function(e,n){var r;t.subscribe(function(e){return r=e},function(e){return n(e)},function(){return e(r)})})},e.create=function(t){return new e(t)},e}();function oe(e){var t;return null!==(t=null!=e?e:U)&&void 0!==t?t:Promise}const ie=(e={})=>{const{parentOrigin:t="*",timeout:n,debug:r=!1,config:o={}}=e,i=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(r),s=((e,t)=>{const n=[];let r=!1;return{destroy(o){r||(r=!0,t(`${e}: Destroying connection`),n.forEach(e=>{e(o)}))},onDestroy(e){r?e():n.push(e)}}})("App",i),{destroy:l,onDestroy:u}=s,d=new Promise((e,r)=>{const d=((e,t)=>{let n;return void 0!==e&&(n=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=v.ConnectionTimeout,t(n)},e)),()=>{clearTimeout(n)}})(n,l),h=n=>{if((()=>{try{clearTimeout(void 0)}catch(e){return!1}return!0})()&&n.source===parent&&n.data&&n.data.penpal===y.SynAck){const r=n.data,l=new F(r.id,r.appName),u=new F(r.id+"/api",r.appName),f=r.id,g={},y=e=>"api/"+e,m=e=>function(t){const n=y(e);u.$on(n,function e(r){t.next(r),r.reqid&&"succ"===r.result&&(t.complete(),u.$off(n,e))})},v=O({$emit:(e,...t)=>{l.getEventCallBackLength(e)>0?l.$pureEmit(e,...t):null==g||g.$off(e,()=>{},!0)},onQueryResult:e=>{u.$pureEmit(y(e.reqid),e)},onOsNotify:e=>{}}),b=C(t,v,c(a({},o),{postmateVersion:S}),s,i)(n),$={},A=b.bus;if(A){const e=(e,t,n)=>{n?(t.$__once=!0,l.$once(e,t)):l.$on(e,t),$[e]?$[e].push(t):($[e]=[t],A.$on(e,f))};Object.assign(g,A,{$on:e,$off:(e,t,n)=>{var r;if($[e]){const n=$[e].indexOf(t);n>-1&&($[e].splice(n,1),l.$off(e,t))}n&&delete $[e],(null==(r=$[e])?void 0:r.length)||(A.$off(e,f),delete $[e])},$once:(t,n)=>{e(t,n,!0)}})}const _=c(a({},b),{bus:g,query:(e,t)=>p(null,null,function*(){const n=(null==e?void 0:e.reqid)||(yield b.genReqId());return new Promise((r,o)=>{b.query(c(a({},e),{reqid:n}),t).then(e=>{"succ"===(null==e?void 0:e.result)?r(e):o(e)})})}),createObservableQuery:(e,...t)=>p(null,[e,...t],function*(e,t={}){const n=(null==e?void 0:e.reqid)||(yield b.genReqId()),r=new re(m(n));return b.query(c(a({},e),{reqid:n}),c(a({},t),{observable:!0})),r})});b&&(window.removeEventListener(w.Message,h),d(),e({methods:_,config:n.data.config}))}};window.addEventListener(w.Message,h),(()=>{i("Child: Handshake - Sending SYN");const e={penpal:y.Syn},n=t instanceof RegExp?"*":t;window.parent.postMessage(e,n)})(),u(e=>{window.removeEventListener(w.Message,h),e&&r(e)})});return{promise:d,destroy(){l()}}};let se=null;class le{constructor(){u(this,"options"),u(this,"flutterInAppWebView",null),u(this,"osConnector",null),u(this,"initPromise"),u(this,"isWeb",!0);let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,e.debug&&(d.setDebug(!0),d.log("Trim App initialized with debug mode")),d.log("Options:",e),this.initPromise=this.init()}init(){return p(this,null,function*(){return d.log("Starting initialization..."),new Promise(e=>{var t;h()?(this.isWeb=!1,d.log("Initializing mobile platform..."),new Promise(e=>{var t;f||(null==(t=window.flutter_inappwebview)?void 0:t._platformReady)?(d.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{d.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)})}).then(t=>{this.flutterInAppWebView=t,d.log("Mobile platform initialized"),e()})):(this.isWeb=!0,d.log("Initializing web platform..."),(se||(se=ie({debug:null==t?void 0:t.debug})),se.promise).then(t=>{this.osConnector=t,d.log("Web platform initialized"),e()}))})})}callAppMethod(e,t){return p(this,null,function*(){return this.flutterInAppWebView?((e,t,n)=>p(null,null,function*(){d.log(`callHandler: ${t}, params: ${n}`);const r=yield e.callHandler(t,n);if(r)try{const e=JSON.parse(r);d.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return d.log(`appMessage: ${JSON.stringify(t)}`),t}catch(o){return d.error(`error: ${o}`),null}return null}))(this.flutterInAppWebView,e,t):null})}ready(){return p(this,null,function*(){return this.initPromise})}getOptions(){return this.options}setOptions(e){this.options=a(a({},this.options),e),void 0!==e.debug&&d.setDebug(e.debug),d.log("Options updated:",this.options)}getPlatformConfig(){return p(this,null,function*(){var e;if(yield this.initPromise,this.isWeb){const t=yield null==(e=this.osConnector)?void 0:e.methods.getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}{const e=yield this.callAppMethod("getAppMessage");if(!e)throw new Error("Failed to get platform config");return{theme:e.nightMode,language:e.language,appVersion:e.appVersion,systemVersion:e.systemVersion,format:{date:e.dateFormat,time:e.timeFormat}}}})}setTitle(e){return p(this,null,function*(){var t;return yield this.initPromise,d.log("Setting title:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)})}setExitPageTips(e){return p(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})}openFile(e){return p(this,null,function*(){var t;return yield this.initPromise,d.log("Opening file:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)})}openFileManager(e){return p(this,null,function*(){var t;return yield this.initPromise,d.log("Opening file manager:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)})}openApp(e){return p(this,null,function*(){var t;if(yield this.initPromise,d.log("Opening app:",e),this.isWeb)return null==(t=this.osConnector)?void 0:t.methods.openApp(e);throw new Error("openApp is not supported on mobile platform")})}openCustomApp(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,d.log("Opening custom app:",e,t),this.isWeb)return null==(n=this.osConnector)?void 0:n.methods.openCustomApp(e,t);throw new Error("openCustomApp is not supported on mobile platform")})}openURL(e,t,n){return p(this,null,function*(){if(yield this.initPromise,d.log("Opening URL:",e,t,n),!this.isWeb)return this.callAppMethod("openSystemBrowser",e);if(!n)return void window.open(e,t,n);const r=window.open("",t,n);r&&(r.location.href=e)})}close(){return p(this,null,function*(){var e;return yield this.initPromise,this.isWeb?null==(e=this.osConnector)?void 0:e.methods.close():this.callAppMethod("exitPage")})}query(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,this.isWeb){const r=yield null==(n=this.osConnector)?void 0:n.methods.query(e,t);if(!r)throw new Error("Failed to query");return r}throw new Error("query is not supported on mobile platform")})}$on(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$on is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$on(e,t)})}$off(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$off is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$off(e,t)})}$once(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$once is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$once(e,t)})}pickFile(e){return p(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))})}}return e.TrimApp=le,e.default=le,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),e}({});
@@ -1 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TrimApp={})}(this,function(e){"use strict";var t=Object.defineProperty,n=Object.defineProperties,r=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,l=(e,n,r)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r,a=(e,t)=>{for(var n in t||(t={}))i.call(t,n)&&l(e,n,t[n]);if(o)for(var n of o(t))s.call(t,n)&&l(e,n,t[n]);return e},u=(e,t)=>n(e,r(t)),c=(e,t,n)=>l(e,"symbol"!=typeof t?t+"":t,n),p=(e,t,n)=>new Promise((r,o)=>{var i=e=>{try{l(n.next(e))}catch(t){o(t)}},s=e=>{try{l(n.throw(e))}catch(t){o(t)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(i,s);l((n=n.apply(e,t)).next())});const d=new class{constructor(){c(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),n=0;n<e;n++)t[n]=arguments[n];console.log("[Trim App]",...t)}}warn(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.warn("[Trim App]",...t)}}error(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.error("[Trim App]",...t)}}info(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.info("[Trim App]",...t)}}};const f=()=>function(e){const t=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,n={};let r;for(;null!==(r=t.exec(e));)r[1]&&(n.fnOSVersion=r[1]),r[2]&&(n.fnAppType=r[2]),r[3]&&(n.fnAppVersion=r[3]);return n}(navigator.userAgent).fnAppVersion;let h=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{h=!0});const g=new Map;f()&&(window.fnAppMessage=e=>{d.log("app-message",e);const t=JSON.parse(e),n=g.get(t.reqId);n&&(n(t),g.delete(t.reqId))});var y=(e=>(e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e))(y||{}),m=(e=>(e.Fulfilled="fulfilled",e.Rejected="rejected",e))(m||{}),v=(e=>(e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e))(v||{}),b=(e=>(e.DataCloneError="DataCloneError",e))(b||{}),w=(e=>(e.Message="message",e))(w||{});const $=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});let A=0;const _=e=>e?e.split("."):[],E=(e,t,n)=>{const r=_(t);return r.reduce((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===r.length-1&&(e[t]=n),e[t]),e),e},O=(e,t)=>{const n={};return Object.keys(e).forEach(r=>{const o=e[r],i=((e,t)=>{const n=_(t||"");return n.push(e),(e=>e.join("."))(n)})(r,t);"object"==typeof o&&Object.assign(n,O(o,i)),"function"==typeof o&&(n[i]=o)}),n},P=(e,t,n,r,o)=>{const{localName:i,local:s,remote:l,originForSending:a,originForReceiving:u}=t;let c=!1;o(`${i}: Connecting call sender`);const p=e=>(...t)=>{let n;o(`${i}: Sending ${e}() call`);try{l.closed&&(n=!0)}catch(p){n=!0}if(n&&r(),c){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=v.ConnectionDestroyed,t}return new Promise((n,r)=>{const c=++A,p=t=>{if(t.source!==l||t.data.penpal!==y.Reply||t.data.id!==c)return;if("*"!==u&&t.origin!==u)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${u}`);const a=t.data;o(`${i}: Received ${e}() reply`),s.removeEventListener(w.Message,p);let d=a.returnValue;a.returnValueIsError&&(d=(e=>{const t=new Error;return Object.keys(e).forEach(n=>t[n]=e[n]),t})(d)),(a.resolution===m.Fulfilled?n:r)(d)};s.addEventListener(w.Message,p);const d={penpal:y.Call,id:c,methodName:e,args:t};l.postMessage(d,a)})},d=n.reduce((e,t)=>(e[t]=p(t),e),{});return Object.assign(e,(e=>{const t={};for(const n in e)E(t,n,e[n]);return t})(d)),()=>{c=!0}},S="0.1.2",C=(e,t,n,r,o)=>{const{destroy:i,onDestroy:s}=r;return r=>{if(!(e instanceof RegExp?e.test(r.origin):"*"===e||e===r.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${r.origin} which did not match expected origin ${e}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const l="null"===r.origin?"*":r.origin,a={penpal:y.Ack,methodNames:Object.keys(t),config:n};window.parent.postMessage(a,l);const u={localName:"Child",local:window,remote:window.parent,originForSending:l,originForReceiving:r.origin},c=((e,t,n)=>{const{localName:r,local:o,remote:i,originForSending:s,originForReceiving:l}=e;let a=!1;const u=e=>{if(e.source!==i||e.data.penpal!==y.Call)return;if("*"!==l&&e.origin!==l)return void n(`${r} received message from origin ${e.origin} which did not match expected origin ${l}`);const o=e.data,{methodName:u,args:c,id:p}=o;n(`${r}: Received ${u}() call`);const d=e=>t=>{if(n(`${r}: Sending ${u}() reply`),a)return void n(`${r}: Unable to send ${u}() reply due to destroyed connection`);const o={penpal:y.Reply,id:p,resolution:e,returnValue:t};e===m.Rejected&&t instanceof Error&&(o.returnValue=$(t),o.returnValueIsError=!0);try{i.postMessage(o,s)}catch(l){if(l.name===b.DataCloneError){const e={penpal:y.Reply,id:p,resolution:m.Rejected,returnValue:$(l),returnValueIsError:!0};i.postMessage(e,s)}throw l}};new Promise(e=>e(t[u].apply(t,c))).then(d(m.Fulfilled),d(m.Rejected))};return o.addEventListener(w.Message,u),()=>{a=!0,o.removeEventListener(w.Message,u)}})(u,t,o);s(c);const p={},d=P(p,u,r.data.methodNames,i,o);return s(d),p}};function M(e,t){null==console||console.warn(`[fnApp warn]: ${e}`,t)}function j(e,t){null==console||console.error(`[fnApp error]: ${e}`,t)}const x="_fn_all_event",T="事件订阅数量为空",N=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map;class F{constructor(e,t){c(this,"id"),c(this,"appName"),c(this,"eventObj"),c(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),N.get(this.id)||N.set(this.id,{}),this.eventObj=N.get(this.id)}$on(e,t){const n=this.eventObj[e];return n?(n.includes(t)||n.push(t),this):(this.eventObj[e]=[t],this)}$onAll(e){return this.$on(x,e)}$once(e,t){t.$__once=!0,this.$on(e,t)}$off(e,t){const n=this.eventObj[e];if(!e||!n||!n.length)return M(`${e} ${T}`),this;let r,o=n.length;for(;o--;)if(r=n[o],r===t){n.splice(o,1);break}return this}$offAll(e){return this.$off(x,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let n=0;return N.forEach(r=>{if(r[e])for(let i=r[e].length-1;i>=0;i--){n++;const s=r[e][i];s.$__once&&r[e].splice(i,1);try{s(...t)}catch(o){j(o)}}if(r[x])for(let e=r[x].length-1;e>=0;e--){n++;const i=r[x][e];i.$__once&&r[x].splice(e,1);try{i(...t)}catch(o){j(o)}}}),e&&0!==n||M(`${e} ${T}`),this}$clear(){const e=N.get(this.id)||{};return Object.keys(e).forEach(t=>delete e[t]),this}}var R=function(e,t){return(R=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function W(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}R(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function k(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function V(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(l){o={error:l}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function I(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function q(e){return"function"==typeof e}"function"==typeof SuppressedError&&SuppressedError;var D,L=((D=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(e){Error.call(e),e.stack=(new Error).stack})).prototype=Object.create(Error.prototype),D.prototype.constructor=D,D);function z(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var J=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=k(i),l=s.next();!l.done;l=s.next()){l.value.remove(this)}}catch(f){e={error:f}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var a=this.initialTeardown;if(q(a))try{a()}catch(h){o=h instanceof L?h.errors:[h]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var c=k(u),p=c.next();!p.done;p=c.next()){var d=p.value;try{H(d)}catch(g){o=null!=o?o:[],g instanceof L?o=I(I([],V(o)),V(g.errors)):o.push(g)}}}catch(y){n={error:y}}finally{try{p&&!p.done&&(r=c.return)&&r.call(c)}finally{if(n)throw n.error}}}if(o)throw new L(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)H(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).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 n=this._finalizers;n&&z(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}();function Y(e){return e instanceof J||e&&"closed"in e&&q(e.remove)&&q(e.add)&&q(e.unsubscribe)}function H(e){q(e)?e():e.unsubscribe()}J.EMPTY;var U=void 0,B=function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,I([e,t],V(n)))};function K(){}var Q=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,Y(t)&&t.add(n)):n.destination=ee,n}return W(t,e),t.create=function(e,t,n){return new X(e,t,n)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(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}(J),G=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(n){Z(n)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){Z(n)}else Z(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){Z(t)}},e}(),X=function(e){function t(t,n,r){var o,i=e.call(this)||this;return o=q(t)||!t?{next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:t,i.destination=new G(o),i}return W(t,e),t}(Q);function Z(e){var t;t=e,B(function(){throw t})}var ee={closed:!0,next:K,error:function(e){throw e},complete:K},te="function"==typeof Symbol&&Symbol.observable||"@@observable";function ne(e){return e}var re=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof Q||function(e){return e&&q(e.next)&&q(e.error)&&q(e.complete)}(r)&&Y(r)?e:new X(e,t,n);return function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))}(),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=oe(t))(function(t,r){var o=new X({next:function(t){try{e(t)}catch(n){r(n),o.unsubscribe()}},error:r,complete:t});n.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[te]=function(){return this},e.prototype.pipe=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return(0===(e=t).length?ne:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)})(this)},e.prototype.toPromise=function(e){var t=this;return new(e=oe(e))(function(e,n){var r;t.subscribe(function(e){return r=e},function(e){return n(e)},function(){return e(r)})})},e.create=function(t){return new e(t)},e}();function oe(e){var t;return null!==(t=null!=e?e:U)&&void 0!==t?t:Promise}const ie=(e={})=>{const{parentOrigin:t="*",timeout:n,debug:r=!1,config:o={}}=e,i=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(r),s=((e,t)=>{const n=[];let r=!1;return{destroy(o){r||(r=!0,t(`${e}: Destroying connection`),n.forEach(e=>{e(o)}))},onDestroy(e){r?e():n.push(e)}}})("App",i),{destroy:l,onDestroy:c}=s,d=new Promise((e,r)=>{const d=((e,t)=>{let n;return void 0!==e&&(n=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=v.ConnectionTimeout,t(n)},e)),()=>{clearTimeout(n)}})(n,l),f=n=>{if((()=>{try{clearTimeout(void 0)}catch(e){return!1}return!0})()&&n.source===parent&&n.data&&n.data.penpal===y.SynAck){const r=n.data,l=new F(r.id,r.appName),c=new F(r.id+"/api",r.appName),h=r.id,g={},y=e=>"api/"+e,m=e=>function(t){const n=y(e);c.$on(n,function e(r){t.next(r),r.reqid&&"succ"===r.result&&(t.complete(),c.$off(n,e))})},v=O({$emit:(e,...t)=>{l.getEventCallBackLength(e)>0?l.$pureEmit(e,...t):null==g||g.$off(e,()=>{},!0)},onQueryResult:e=>{c.$pureEmit(y(e.reqid),e)},onOsNotify:e=>{}}),b=C(t,v,u(a({},o),{postmateVersion:S}),s,i)(n),$={},A=b.bus;if(A){const e=(e,t,n)=>{n?(t.$__once=!0,l.$once(e,t)):l.$on(e,t),$[e]?$[e].push(t):($[e]=[t],A.$on(e,h))};Object.assign(g,A,{$on:e,$off:(e,t,n)=>{var r;if($[e]){const n=$[e].indexOf(t);n>-1&&($[e].splice(n,1),l.$off(e,t))}n&&delete $[e],(null==(r=$[e])?void 0:r.length)||(A.$off(e,h),delete $[e])},$once:(t,n)=>{e(t,n,!0)}})}const _=u(a({},b),{bus:g,query:(e,t)=>p(null,null,function*(){const n=(null==e?void 0:e.reqid)||(yield b.genReqId());return new Promise((r,o)=>{b.query(u(a({},e),{reqid:n}),t).then(e=>{"succ"===(null==e?void 0:e.result)?r(e):o(e)})})}),createObservableQuery:(e,...t)=>p(null,[e,...t],function*(e,t={}){const n=(null==e?void 0:e.reqid)||(yield b.genReqId()),r=new re(m(n));return b.query(u(a({},e),{reqid:n}),u(a({},t),{observable:!0})),r})});b&&(window.removeEventListener(w.Message,f),d(),e({methods:_,config:n.data.config}))}};window.addEventListener(w.Message,f),(()=>{i("Child: Handshake - Sending SYN");const e={penpal:y.Syn},n=t instanceof RegExp?"*":t;window.parent.postMessage(e,n)})(),c(e=>{window.removeEventListener(w.Message,f),e&&r(e)})});return{promise:d,destroy(){l()}}};let se=null;class le{constructor(){c(this,"options"),c(this,"flutterInAppWebView",null),c(this,"osConnector",null),c(this,"initPromise"),c(this,"isWeb",!0);let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,e.debug&&(d.setDebug(!0),d.log("Trim App initialized with debug mode")),d.log("Options:",e),this.initPromise=this.init()}init(){return p(this,null,function*(){return d.log("Starting initialization..."),new Promise(e=>{var t;f()?(this.isWeb=!1,d.log("Initializing mobile platform..."),new Promise(e=>{var t;h||(null==(t=window.flutter_inappwebview)?void 0:t._platformReady)?(d.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{d.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)})}).then(t=>{this.flutterInAppWebView=t,d.log("Mobile platform initialized"),e()})):(this.isWeb=!0,d.log("Initializing web platform..."),(se||(se=ie({debug:null==t?void 0:t.debug})),se.promise).then(t=>{this.osConnector=t,d.log("Web platform initialized"),e()}))})})}callAppMethod(e,t){return p(this,null,function*(){return this.flutterInAppWebView?((e,t,n)=>p(null,null,function*(){d.log(`callHandler: ${t}, params: ${n}`);const r=yield e.callHandler(t,n);if(r)try{const e=JSON.parse(r);d.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return d.log(`appMessage: ${JSON.stringify(t)}`),t}catch(o){return d.error(`error: ${o}`),null}return null}))(this.flutterInAppWebView,e,t):null})}ready(){return p(this,null,function*(){return this.initPromise})}getOptions(){return this.options}setOptions(e){this.options=a(a({},this.options),e),void 0!==e.debug&&d.setDebug(e.debug),d.log("Options updated:",this.options)}getPlatformConfig(){return p(this,null,function*(){var e;if(yield this.initPromise,this.isWeb){const t=yield null==(e=this.osConnector)?void 0:e.methods.getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}{const e=yield this.callAppMethod("getAppMessage");if(!e)throw new Error("Failed to get platform config");return{theme:e.nightMode,language:e.language,appVersion:e.appVersion,systemVersion:e.systemVersion,format:{date:e.dateFormat,time:e.timeFormat}}}})}setTitle(e){return p(this,null,function*(){var t;return yield this.initPromise,d.log("Setting title:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)})}setExitPageTips(e){return p(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})}openFile(e){return p(this,null,function*(){var t;return yield this.initPromise,d.log("Opening file:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)})}openFileManager(e){return p(this,null,function*(){var t;return yield this.initPromise,d.log("Opening file manager:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)})}openApp(e){return p(this,null,function*(){var t;if(yield this.initPromise,d.log("Opening app:",e),this.isWeb)return null==(t=this.osConnector)?void 0:t.methods.openApp(e);throw new Error("openApp is not supported on mobile platform")})}openCustomApp(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,d.log("Opening custom app:",e,t),this.isWeb)return null==(n=this.osConnector)?void 0:n.methods.openCustomApp(e,t);throw new Error("openCustomApp is not supported on mobile platform")})}openURL(e,t,n){return p(this,null,function*(){if(yield this.initPromise,d.log("Opening URL:",e,t,n),!this.isWeb)return this.callAppMethod("openSystemBrowser",e);if(!n)return void window.open(e,t,n);const r=window.open("",t,n);r&&(r.location.href=e)})}close(){return p(this,null,function*(){var e;return yield this.initPromise,this.isWeb?null==(e=this.osConnector)?void 0:e.methods.close():this.callAppMethod("exitPage")})}query(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,this.isWeb){const r=yield null==(n=this.osConnector)?void 0:n.methods.query(e,t);if(!r)throw new Error("Failed to query");return r}throw new Error("query is not supported on mobile platform")})}$on(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$on is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$on(e,t)})}$off(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$off is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$off(e,t)})}$once(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,!this.isWeb)throw new Error("$once is not supported on mobile platform");(null==(n=this.osConnector)?void 0:n.methods.bus).$once(e,t)})}pickFile(e){return p(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))})}}e.TrimApp=le,e.default=le,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});