@trimjs/web-app 0.1.4 → 0.1.6
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 +2 -12
- package/dist/index.cjs +3 -3
- package/dist/index.iife.js +3 -3
- package/dist/index.js +289 -338
- package/dist/index.umd.cjs +3 -3
- package/package.json +2 -5
- package/src/index.ts +0 -257
- package/src/logger.ts +0 -65
- package/src/mobile/index.ts +0 -112
- package/src/mobile/types.ts +0 -9
- package/src/types.ts +0 -18
- package/src/utils/platform.ts +0 -17
- package/src/web/index.ts +0 -27
package/README.md
CHANGED
|
@@ -288,26 +288,16 @@ const dateFormatter = new Intl.DateTimeFormat(config.language, {
|
|
|
288
288
|
async close(): Promise<void>
|
|
289
289
|
```
|
|
290
290
|
|
|
291
|
-
|
|
291
|
+
关闭应用。
|
|
292
292
|
|
|
293
293
|
**返回值:**
|
|
294
294
|
|
|
295
295
|
- `Promise<void>`
|
|
296
296
|
|
|
297
|
-
**注意:**
|
|
298
|
-
|
|
299
|
-
- 此方法仅在 Web 平台(iframe)中可用
|
|
300
|
-
- 在移动端调用会抛出错误
|
|
301
|
-
|
|
302
297
|
**示例:**
|
|
303
298
|
|
|
304
299
|
```typescript
|
|
305
|
-
|
|
306
|
-
if (app.isWeb) {
|
|
307
|
-
await app.query();
|
|
308
|
-
} else {
|
|
309
|
-
console.log("query 方法仅在 Web 平台可用");
|
|
310
|
-
}
|
|
300
|
+
app.close();
|
|
311
301
|
```
|
|
312
302
|
|
|
313
303
|
---
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`+t.map(function(n,
|
|
3
|
-
`):"",this.name="UnsubscriptionError",this.errors=t}});function ae(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var Z=function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var c=ce(s),a=c.next();!a.done;a=c.next()){var h=a.value;h.remove(this)}}catch(l){e={error:l}}finally{try{a&&!a.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else s.remove(this);var v=this.initialTeardown;if(R(v))try{v()}catch(l){i=l instanceof J?l.errors:[l]}var A=this._finalizers;if(A){this._finalizers=null;try{for(var g=ce(A),p=g.next();!p.done;p=g.next()){var m=p.value;try{le(m)}catch(l){i=i!=null?i:[],l instanceof J?i=Q(Q([],K(i)),K(l.errors)):i.push(l)}}}catch(l){n={error:l}}finally{try{p&&!p.done&&(o=g.return)&&o.call(g)}finally{if(n)throw n.error}}}if(i)throw new J(i)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)le(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&ae(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&ae(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=function(){var e=new r;return e.closed=!0,e}(),r}();Z.EMPTY;function we(r){return r instanceof Z||r&&"closed"in r&&R(r.remove)&&R(r.add)&&R(r.unsubscribe)}function le(r){R(r)?r():r.unsubscribe()}var ve={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ot={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setTimeout.apply(void 0,Q([r,e],K(t)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function st(r){ot.setTimeout(function(){throw r})}function ue(){}function ct(r){r()}var Ee=function(r){be(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,we(t)&&t.add(n)):n.destination=ft,n}return e.create=function(t,n,o){return new G(t,n,o)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(Z),at=Function.prototype.bind;function Y(r,e){return at.call(r,e)}var lt=function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){U(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){U(n)}else U(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){U(t)}},r}(),G=function(r){be(e,r);function e(t,n,o){var i=r.call(this)||this,s;if(R(t)||!t)s={next:t!=null?t:void 0,error:n!=null?n:void 0,complete:o!=null?o:void 0};else{var c;i&&ve.useDeprecatedNextContext?(c=Object.create(t),c.unsubscribe=function(){return i.unsubscribe()},s={next:t.next&&Y(t.next,c),error:t.error&&Y(t.error,c),complete:t.complete&&Y(t.complete,c)}):s=t}return i.destination=new lt(s),i}return e}(Ee);function U(r){st(r)}function ut(r){throw r}var ft={closed:!0,next:ue,error:ut,complete:ue},pt=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function dt(r){return r}function ht(r){return r.length===0?dt:r.length===1?r[0]:function(t){return r.reduce(function(n,o){return o(n)},t)}}var gt=function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,n){var o=this,i=mt(e)?e:new G(e,t,n);return ct(function(){var s=o,c=s.operator,a=s.source;i.add(c?c.call(i,a):a?o._subscribe(i):o._trySubscribe(i))}),i},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var n=this;return t=fe(t),new t(function(o,i){var s=new G({next:function(c){try{e(c)}catch(a){i(a),s.unsubscribe()}},error:i,complete:o});n.subscribe(s)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[pt]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return ht(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=fe(e),new e(function(n,o){var i;t.subscribe(function(s){return i=s},function(s){return o(s)},function(){return n(i)})})},r.create=function(e){return new r(e)},r}();function fe(r){var e;return(e=r!=null?r:ve.Promise)!==null&&e!==void 0?e:Promise}function yt(r){return r&&R(r.next)&&R(r.error)&&R(r.complete)}function mt(r){return r&&r instanceof Ee||yt(r)&&we(r)}const bt=()=>{try{clearTimeout(void 0)}catch(r){return!1}return!0},wt=(r={})=>{const{parentOrigin:e="*",timeout:t,debug:n=!1,config:o={}}=r,i=je(n),s=Ie("App",i),{destroy:c,onDestroy:a}=s,h=()=>{i("Child: Handshake - Sending SYN");const A={penpal:O.Syn},g=e instanceof RegExp?"*":e;window.parent.postMessage(A,g)};return{promise:new Promise((A,g)=>{const p=Je(t,c),m=l=>{if(bt()&&!(l.source!==parent||!l.data)&&l.data.penpal===O.SynAck){const y=l.data,S=new se(y.id,y.appName),P=new se(y.id+"/api",y.appName),M=y.id,C={},T=u=>"api/"+u,N={$emit:(u,...f)=>{S.getEventCallBackLength(u)>0?S.$pureEmit(u,...f):C==null||C.$off(u,()=>{},!0)},onQueryResult:u=>{P.$pureEmit(T(u.reqid),u)},onOsNotify:u=>{}},L=u=>function(b){const x=T(u);P.$on(x,function F(E){b.next(E),E.reqid&&E.result==="succ"&&(b.complete(),P.$off(x,F))})},Se=me(N),j=nt(e,Se,V(D({},o),{postmateVersion:rt.version}),s,i)(l),_={},k=j.bus;if(k){const u=(f,b,x)=>{x?(b.$__once=!0,S.$once(f,b)):S.$on(f,b),_[f]?_[f].push(b):(_[f]=[b],k.$on(f,M))};Object.assign(C,k,{$on:u,$off:(f,b,x)=>{var F;if(_[f]){const E=_[f].indexOf(b);E>-1&&(_[f].splice(E,1),S.$off(f,b))}x&&delete _[f],(F=_[f])!=null&&F.length||(k.$off(f,M),delete _[f])},$once:(f,b)=>{u(f,b,!0)}})}const $e=V(D({},j),{bus:C,query:(u,f)=>w(exports,null,function*(){const b=(u==null?void 0:u.reqid)||(yield j.genReqId());return new Promise((x,F)=>{j.query(V(D({},u),{reqid:b}),f).then(E=>{(E==null?void 0:E.result)==="succ"?x(E):F(E)})})}),createObservableQuery:(b,...x)=>w(exports,[b,...x],function*(u,f={}){const F=(u==null?void 0:u.reqid)||(yield j.genReqId()),E=new gt(L(F));return j.query(V(D({},u),{reqid:F}),V(D({},f),{observable:!0})),E})});j&&(window.removeEventListener(I.Message,m),p(),A({methods:$e,config:l.data.config}))}};window.addEventListener(I.Message,m),h(),a(l=>{window.removeEventListener(I.Message,m),l&&g(l)})}),destroy(){c()}}},vt=r=>wt({debug:r==null?void 0:r.debug}).promise;class Ae{constructor(){$(this,"options");$(this,"flutterInAppWebView",null);$(this,"osConnector",null);$(this,"initPromise");$(this,"isWeb",!0);let e=arguments.length>0&&arguments[0]!==void 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 w(this,null,function*(){return d.log("Starting initialization..."),new Promise(e=>{pe()?(this.isWeb=!1,d.log("Initializing mobile platform..."),Re().then(t=>{this.flutterInAppWebView=t,d.log("Mobile platform initialized"),e()})):(this.isWeb=!0,d.log("Initializing web platform..."),vt().then(t=>{this.osConnector=t,d.log("Web platform initialized"),e()}))})})}callAppMethod(e,t){return w(this,null,function*(){return this.flutterInAppWebView?xe(this.flutterInAppWebView,e,t):null})}ready(){return w(this,null,function*(){return this.initPromise})}getOptions(){return this.options}setOptions(e){this.options=D(D({},this.options),e),e.debug!==void 0&&d.setDebug(e.debug),d.log("Options updated:",this.options)}getPlatformConfig(){return w(this,null,function*(){var e;if(yield this.initPromise,this.isWeb){const t=yield(e=this.osConnector)==null?void 0:e.methods.getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}else{const t=yield this.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){return w(this,null,function*(){var t;return yield this.initPromise,d.log("Setting title:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)})}setExitPageTips(e){return w(this,null,function*(){var t;return yield this.initPromise,this.isWeb?(t=this.osConnector)==null?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})}openFile(e){return w(this,null,function*(){var t;return yield this.initPromise,d.log("Opening file:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)})}openFileManager(e){return w(this,null,function*(){var t;return yield this.initPromise,d.log("Opening file manager:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)})}close(){return w(this,null,function*(){var e;return yield this.initPromise,this.isWeb?(e=this.osConnector)==null?void 0:e.methods.close():this.callAppMethod("exitPage")})}query(e,t){return w(this,null,function*(){var n;if(yield this.initPromise,this.isWeb){const o=yield(n=this.osConnector)==null?void 0:n.methods.query(e,t);if(!o)throw new Error("Failed to query");return o}else throw new Error("query is not supported on mobile platform")})}pickFile(e){return w(this,null,function*(){var t;return yield this.initPromise,this.isWeb?(t=this.osConnector)==null?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))})}}exports.TrimApp=Ae;exports.default=Ae;
|
|
1
|
+
"use strict";var Se=Object.defineProperty,$e=Object.defineProperties;var Pe=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var Me=Object.prototype.hasOwnProperty,Oe=Object.prototype.propertyIsEnumerable;var B=(r,e,t)=>e in r?Se(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,I=(r,e)=>{for(var t in e||(e={}))Me.call(e,t)&&B(r,t,e[t]);if(Z)for(var t of Z(e))Oe.call(e,t)&&B(r,t,e[t]);return r},W=(r,e)=>$e(r,Pe(e));var $=(r,e,t)=>B(r,typeof e!="symbol"?e+"":e,t);var w=(r,e,t)=>new Promise((n,i)=>{var o=a=>{try{c(t.next(a))}catch(h){i(h)}},s=a=>{try{c(t.throw(a))}catch(h){i(h)}},c=a=>a.done?n(a.value):Promise.resolve(a.value).then(o,s);c((t=t.apply(r,e)).next())});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class _e{constructor(){$(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=new _e;function Ce(r){const e=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,t={};let n;for(;(n=e.exec(r))!==null;)n[1]&&(t.fnOSVersion=n[1]),n[2]&&(t.fnAppType=n[2]),n[3]&&(t.fnAppVersion=n[3]);return t}const fe=()=>Ce(navigator.userAgent).fnAppVersion;let pe=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{pe=!0});const Te=()=>new Promise(r=>{var e;pe||(e=window.flutter_inappwebview)!=null&&e._platformReady?(d.log("flutter_inappwebview is ready"),r(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{d.log("flutter_inappwebview is ready"),r(window.flutter_inappwebview)})}),Fe=(r,e,t)=>w(null,null,function*(){d.log(`callHandler: ${e}, params: ${t}`);const n=yield r.callHandler(e,t);if(n)try{const i=JSON.parse(n);d.log(`messageData: ${JSON.stringify(i)}`);const o=JSON.parse(i.result);return d.log(`appMessage: ${JSON.stringify(o)}`),o}catch(i){return d.error(`error: ${i}`),null}return null}),ee=new Map;function Re(){window.fnAppMessage=r=>{d.log("app-message",r);const e=JSON.parse(r),t=ee.get(e.reqId);t&&(t(e),ee.delete(e.reqId))}}fe()&&Re();var F=(r=>(r.Call="call",r.Reply="reply",r.Syn="syn",r.SynAck="synAck",r.Ack="ack",r))(F||{}),D=(r=>(r.Fulfilled="fulfilled",r.Rejected="rejected",r))(D||{}),G=(r=>(r.ConnectionDestroyed="ConnectionDestroyed",r.ConnectionTimeout="ConnectionTimeout",r.NoIframeSrc="NoIframeSrc",r))(G||{}),de=(r=>(r.DataCloneError="DataCloneError",r))(de||{}),N=(r=>(r.Message="message",r))(N||{});const xe=(r,e)=>{const t=[];let n=!1;return{destroy(i){n||(n=!0,e(`${r}: Destroying connection`),t.forEach(o=>{o(i)}))},onDestroy(i){n?i():t.push(i)}}},Ie=r=>(...e)=>{r&&console.log("[Penpal]",...e)},te=({name:r,message:e,stack:t})=>({name:r,message:e,stack:t}),Ne=r=>{const e=new Error;return Object.keys(r).forEach(t=>e[t]=r[t]),e},Ve=(r,e,t)=>{const{localName:n,local:i,remote:o,originForSending:s,originForReceiving:c}=r;let a=!1;const h=v=>{if(v.source!==o||v.data.penpal!==F.Call)return;if(c!=="*"&&v.origin!==c){t(`${n} received message from origin ${v.origin} which did not match expected origin ${c}`);return}const A=v.data,{methodName:g,args:p,id:m}=A;t(`${n}: Received ${g}() call`);const l=y=>S=>{if(t(`${n}: Sending ${g}() reply`),a){t(`${n}: Unable to send ${g}() reply due to destroyed connection`);return}const P={penpal:F.Reply,id:m,resolution:y,returnValue:S};y===D.Rejected&&S instanceof Error&&(P.returnValue=te(S),P.returnValueIsError=!0);try{o.postMessage(P,s)}catch(M){if(M.name===de.DataCloneError){const O={penpal:F.Reply,id:m,resolution:D.Rejected,returnValue:te(M),returnValueIsError:!0};o.postMessage(O,s)}throw M}};new Promise(y=>y(e[g].apply(e,p))).then(l(D.Fulfilled),l(D.Rejected))};return i.addEventListener(N.Message,h),()=>{a=!0,i.removeEventListener(N.Message,h)}};let We=0;const qe=()=>++We,he=".",ge=r=>r?r.split(he):[],De=r=>r.join(he),je=(r,e)=>{const t=ge(e||"");return t.push(r),De(t)},Le=(r,e,t)=>{const n=ge(e);return n.reduce((i,o,s)=>(typeof i[o]=="undefined"&&(i[o]={}),s===n.length-1&&(i[o]=t),i[o]),r),r},ye=(r,e)=>{const t={};return Object.keys(r).forEach(n=>{const i=r[n],o=je(n,e);typeof i=="object"&&Object.assign(t,ye(i,o)),typeof i=="function"&&(t[o]=i)}),t},He=r=>{const e={};for(const t in r)Le(e,t,r[t]);return e},ke=(r,e,t,n,i)=>{const{localName:o,local:s,remote:c,originForSending:a,originForReceiving:h}=e;let v=!1;i(`${o}: Connecting call sender`);const A=p=>(...m)=>{i(`${o}: Sending ${p}() call`);let l;try{c.closed&&(l=!0)}catch(y){l=!0}if(l&&n(),v){const y=new Error(`Unable to send ${p}() call due to destroyed connection`);throw y.code=G.ConnectionDestroyed,y}return new Promise((y,S)=>{const P=qe(),M=_=>{if(_.source!==c||_.data.penpal!==F.Reply||_.data.id!==P)return;if(h!=="*"&&_.origin!==h){i(`${o} received message from origin ${_.origin} which did not match expected origin ${h}`);return}const j=_.data;i(`${o}: Received ${p}() reply`),s.removeEventListener(N.Message,M);let L=j.returnValue;j.returnValueIsError&&(L=Ne(L)),(j.resolution===D.Fulfilled?y:S)(L)};s.addEventListener(N.Message,M);const O={penpal:F.Call,id:P,methodName:p,args:m};c.postMessage(O,a)})},g=t.reduce((p,m)=>(p[m]=A(m),p),{});return Object.assign(r,He(g)),()=>{v=!0}},Ue=(r,e)=>{let t;return r!==void 0&&(t=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${r}ms`);n.code=G.ConnectionTimeout,e(n)},r)),()=>{clearTimeout(t)}},Be="0.1.2",Je={version:Be},Ye=(r,e,t,n,i)=>{const{destroy:o,onDestroy:s}=n;return c=>{if(!(r instanceof RegExp?r.test(c.origin):r==="*"||r===c.origin)){i(`Child: Handshake - Received SYN-ACK from origin ${c.origin} which did not match expected origin ${r}`);return}i("Child: Handshake - Received SYN-ACK, responding with ACK");const h=c.origin==="null"?"*":c.origin,v={penpal:F.Ack,methodNames:Object.keys(e),config:t};window.parent.postMessage(v,h);const A={localName:"Child",local:window,remote:window.parent,originForSending:h,originForReceiving:c.origin},g=Ve(A,e,i);s(g);const p={},m=ke(p,A,c.data.methodNames,o,i);return s(m),p}};function re(r,e){console==null||console.warn(`[fnApp warn]: ${r}`,e)}function ne(r,e){console==null||console.error(`[fnApp error]: ${r}`,e)}const q="_fn_all_event",ie="事件订阅数量为空",H=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map;class oe{constructor(e,t){$(this,"id");$(this,"appName");$(this,"eventObj");$(this,"getEventCallBackLength",e=>{var t;return((t=this.eventObj[e])==null?void 0:t.length)||0});this.id=e,this.appName=t,this.$clear(),H.get(this.id)||H.set(this.id,{}),this.eventObj=H.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(q,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 re(`${e} ${ie}`),this;let i,o=n.length;for(;o--;)if(i=n[o],i===t){n.splice(o,1);break}return this}$offAll(e){return this.$off(q,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let n=0,i=0;return H.forEach(o=>{if(o[e])for(let s=o[e].length-1;s>=0;s--){n++;const c=o[e][s];c.$__once&&o[e].splice(s,1);try{c(...t)}catch(a){ne(a)}}if(o[q])for(let s=o[q].length-1;s>=0;s--){n++;const c=o[q][s];c.$__once&&o[q].splice(s,1);try{c(...t)}catch(a){ne(a)}}}),(!e||n===0&&i===0)&&re(`${e} ${ie}`),this}$clear(){const e=H.get(this.id)||{};return Object.keys(e).forEach(n=>delete e[n]),this}}var Y=function(r,e){return Y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])},Y(r,e)};function me(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Y(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function se(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function z(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,o=[],s;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(c){s={error:c}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return o}function K(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,o;n<i;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))}function R(r){return typeof r=="function"}function ze(r){var e=function(n){Error.call(n),n.stack=new Error().stack},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var J=ze(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
|
|
2
|
+
`+t.map(function(n,i){return i+1+") "+n.toString()}).join(`
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=t}});function ce(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var X=(function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,i,o;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var c=se(s),a=c.next();!a.done;a=c.next()){var h=a.value;h.remove(this)}}catch(l){e={error:l}}finally{try{a&&!a.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else s.remove(this);var v=this.initialTeardown;if(R(v))try{v()}catch(l){o=l instanceof J?l.errors:[l]}var A=this._finalizers;if(A){this._finalizers=null;try{for(var g=se(A),p=g.next();!p.done;p=g.next()){var m=p.value;try{ae(m)}catch(l){o=o!=null?o:[],l instanceof J?o=K(K([],z(o)),z(l.errors)):o.push(l)}}}catch(l){n={error:l}}finally{try{p&&!p.done&&(i=g.return)&&i.call(g)}finally{if(n)throw n.error}}}if(o)throw new J(o)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)ae(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&ce(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&ce(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=(function(){var e=new r;return e.closed=!0,e})(),r})();X.EMPTY;function be(r){return r instanceof X||r&&"closed"in r&&R(r.remove)&&R(r.add)&&R(r.unsubscribe)}function ae(r){R(r)?r():r.unsubscribe()}var Ke={Promise:void 0},Qe={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setTimeout.apply(void 0,K([r,e],z(t)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function Ge(r){Qe.setTimeout(function(){throw r})}function le(){}function Xe(r){r()}var we=(function(r){me(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,be(t)&&t.add(n)):n.destination=tt,n}return e.create=function(t,n,i){return new Q(t,n,i)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e})(X),Ze=(function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){U(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){U(n)}else U(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){U(t)}},r})(),Q=(function(r){me(e,r);function e(t,n,i){var o=r.call(this)||this,s;return R(t)||!t?s={next:t!=null?t:void 0,error:n!=null?n:void 0,complete:i!=null?i:void 0}:s=t,o.destination=new Ze(s),o}return e})(we);function U(r){Ge(r)}function et(r){throw r}var tt={closed:!0,next:le,error:et,complete:le},rt=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function nt(r){return r}function it(r){return r.length===0?nt:r.length===1?r[0]:function(t){return r.reduce(function(n,i){return i(n)},t)}}var ot=(function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,n){var i=this,o=ct(e)?e:new Q(e,t,n);return Xe(function(){var s=i,c=s.operator,a=s.source;o.add(c?c.call(o,a):a?i._subscribe(o):i._trySubscribe(o))}),o},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var n=this;return t=ue(t),new t(function(i,o){var s=new Q({next:function(c){try{e(c)}catch(a){o(a),s.unsubscribe()}},error:o,complete:i});n.subscribe(s)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[rt]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return it(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=ue(e),new e(function(n,i){var o;t.subscribe(function(s){return o=s},function(s){return i(s)},function(){return n(o)})})},r.create=function(e){return new r(e)},r})();function ue(r){var e;return(e=r!=null?r:Ke.Promise)!==null&&e!==void 0?e:Promise}function st(r){return r&&R(r.next)&&R(r.error)&&R(r.complete)}function ct(r){return r&&r instanceof we||st(r)&&be(r)}const at=()=>{try{clearTimeout(void 0)}catch(r){return!1}return!0},lt=(r={})=>{const{parentOrigin:e="*",timeout:t,debug:n=!1,config:i={}}=r,o=Ie(n),s=xe("App",o),{destroy:c,onDestroy:a}=s,h=()=>{o("Child: Handshake - Sending SYN");const A={penpal:F.Syn},g=e instanceof RegExp?"*":e;window.parent.postMessage(A,g)};return{promise:new Promise((A,g)=>{const p=Ue(t,c),m=l=>{if(at()&&!(l.source!==parent||!l.data)&&l.data.penpal===F.SynAck){const y=l.data,S=new oe(y.id,y.appName),P=new oe(y.id+"/api",y.appName),M=y.id,O={},_=u=>"api/"+u,j={$emit:(u,...f)=>{S.getEventCallBackLength(u)>0?S.$pureEmit(u,...f):O==null||O.$off(u,()=>{},!0)},onQueryResult:u=>{P.$pureEmit(_(u.reqid),u)},onOsNotify:u=>{}},L=u=>function(b){const x=_(u);P.$on(x,function T(E){b.next(E),E.reqid&&E.result==="succ"&&(b.complete(),P.$off(x,T))})},Ee=ye(j),V=Ye(e,Ee,W(I({},i),{postmateVersion:Je.version}),s,o)(l),C={},k=V.bus;if(k){const u=(f,b,x)=>{x?(b.$__once=!0,S.$once(f,b)):S.$on(f,b),C[f]?C[f].push(b):(C[f]=[b],k.$on(f,M))};Object.assign(O,k,{$on:u,$off:(f,b,x)=>{var T;if(C[f]){const E=C[f].indexOf(b);E>-1&&(C[f].splice(E,1),S.$off(f,b))}x&&delete C[f],(T=C[f])!=null&&T.length||(k.$off(f,M),delete C[f])},$once:(f,b)=>{u(f,b,!0)}})}const Ae=W(I({},V),{bus:O,query:(u,f)=>w(null,null,function*(){const b=(u==null?void 0:u.reqid)||(yield V.genReqId());return new Promise((x,T)=>{V.query(W(I({},u),{reqid:b}),f).then(E=>{(E==null?void 0:E.result)==="succ"?x(E):T(E)})})}),createObservableQuery:(b,...x)=>w(null,[b,...x],function*(u,f={}){const T=(u==null?void 0:u.reqid)||(yield V.genReqId()),E=new ot(L(T));return V.query(W(I({},u),{reqid:T}),W(I({},f),{observable:!0})),E})});V&&(window.removeEventListener(N.Message,m),p(),A({methods:Ae,config:l.data.config}))}};window.addEventListener(N.Message,m),h(),a(l=>{window.removeEventListener(N.Message,m),l&&g(l)})}),destroy(){c()}}},ut=r=>lt({debug:r==null?void 0:r.debug}).promise;class ve{constructor(){$(this,"options");$(this,"flutterInAppWebView",null);$(this,"osConnector",null);$(this,"initPromise");$(this,"isWeb",!0);let e=arguments.length>0&&arguments[0]!==void 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 w(this,null,function*(){return d.log("Starting initialization..."),new Promise(e=>{fe()?(this.isWeb=!1,d.log("Initializing mobile platform..."),Te().then(t=>{this.flutterInAppWebView=t,d.log("Mobile platform initialized"),e()})):(this.isWeb=!0,d.log("Initializing web platform..."),ut().then(t=>{this.osConnector=t,d.log("Web platform initialized"),e()}))})})}callAppMethod(e,t){return w(this,null,function*(){return this.flutterInAppWebView?Fe(this.flutterInAppWebView,e,t):null})}ready(){return w(this,null,function*(){return this.initPromise})}getOptions(){return this.options}setOptions(e){this.options=I(I({},this.options),e),e.debug!==void 0&&d.setDebug(e.debug),d.log("Options updated:",this.options)}getPlatformConfig(){return w(this,null,function*(){var e;if(yield this.initPromise,this.isWeb){const t=yield(e=this.osConnector)==null?void 0:e.methods.getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}else{const t=yield this.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){return w(this,null,function*(){var t;return yield this.initPromise,d.log("Setting title:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)})}setExitPageTips(e){return w(this,null,function*(){var t;return yield this.initPromise,this.isWeb?(t=this.osConnector)==null?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})}openFile(e){return w(this,null,function*(){var t;return yield this.initPromise,d.log("Opening file:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)})}openFileManager(e){return w(this,null,function*(){var t;return yield this.initPromise,d.log("Opening file manager:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)})}close(){return w(this,null,function*(){var e;return yield this.initPromise,this.isWeb?(e=this.osConnector)==null?void 0:e.methods.close():this.callAppMethod("exitPage")})}query(e,t){return w(this,null,function*(){var n;if(yield this.initPromise,this.isWeb){const i=yield(n=this.osConnector)==null?void 0:n.methods.query(e,t);if(!i)throw new Error("Failed to query");return i}else throw new Error("query is not supported on mobile platform")})}pickFile(e){return w(this,null,function*(){var t;return yield this.initPromise,this.isWeb?(t=this.osConnector)==null?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))})}}exports.TrimApp=ve;exports.default=ve;
|
package/dist/index.iife.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var TrimApp=function(g){"use strict";var
|
|
2
|
-
`+t.map(function(
|
|
3
|
-
`):"",this.name="UnsubscriptionError",this.errors=t}});function ve(n,e){if(n){var t=n.indexOf(e);0<=t&&n.splice(t,1)}}var oe=function(){function n(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var e,t,r,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var c=we(s),p=c.next();!p.done;p=c.next()){var S=p.value;S.remove(this)}}catch(l){e={error:l}}finally{try{p&&!p.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else s.remove(this);var E=this.initialTeardown;if(F(E))try{E()}catch(l){i=l instanceof ie?l.errors:[l]}var $=this._finalizers;if($){this._finalizers=null;try{for(var y=we($),h=y.next();!h.done;h=y.next()){var b=h.value;try{Ae(b)}catch(l){i=i!=null?i:[],l instanceof ie?i=re(re([],ne(i)),ne(l.errors)):i.push(l)}}}catch(l){r={error:l}}finally{try{h&&!h.done&&(o=y.return)&&o.call(y)}finally{if(r)throw r.error}}}if(i)throw new ie(i)}},n.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)Ae(e);else{if(e instanceof n){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},n.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},n.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},n.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&ve(t,e)},n.prototype.remove=function(e){var t=this._finalizers;t&&ve(t,e),e instanceof n&&e._removeParent(this)},n.EMPTY=function(){var e=new n;return e.closed=!0,e}(),n}();oe.EMPTY;function Ee(n){return n instanceof oe||n&&"closed"in n&&F(n.remove)&&F(n.add)&&F(n.unsubscribe)}function Ae(n){F(n)?n():n.unsubscribe()}var Se={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},Ue={setTimeout:function(n,e){for(var t=[],r=2;r<arguments.length;r++)t[r-2]=arguments[r];return setTimeout.apply(void 0,re([n,e],ne(t)))},clearTimeout:function(n){return clearTimeout(n)},delegate:void 0};function Be(n){Ue.setTimeout(function(){throw n})}function $e(){}function Je(n){n()}var Pe=function(n){be(e,n);function e(t){var r=n.call(this)||this;return r.isStopped=!1,t?(r.destination=t,Ee(t)&&t.add(r)):r.destination=Qe,r}return e.create=function(t,r,o){return new ce(t,r,o)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(oe),Ye=Function.prototype.bind;function se(n,e){return Ye.call(n,e)}var ze=function(){function n(e){this.partialObserver=e}return n.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(r){Q(r)}},n.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(r){Q(r)}else Q(e)},n.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){Q(t)}},n}(),ce=function(n){be(e,n);function e(t,r,o){var i=n.call(this)||this,s;if(F(t)||!t)s={next:t!=null?t:void 0,error:r!=null?r:void 0,complete:o!=null?o:void 0};else{var c;i&&Se.useDeprecatedNextContext?(c=Object.create(t),c.unsubscribe=function(){return i.unsubscribe()},s={next:t.next&&se(t.next,c),error:t.error&&se(t.error,c),complete:t.complete&&se(t.complete,c)}):s=t}return i.destination=new ze(s),i}return e}(Pe);function Q(n){Be(n)}function Ke(n){throw n}var Qe={closed:!0,next:$e,error:Ke,complete:$e},Ge=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Xe(n){return n}function Ze(n){return n.length===0?Xe:n.length===1?n[0]:function(t){return n.reduce(function(r,o){return o(r)},t)}}var et=function(){function n(e){e&&(this._subscribe=e)}return n.prototype.lift=function(e){var t=new n;return t.source=this,t.operator=e,t},n.prototype.subscribe=function(e,t,r){var o=this,i=nt(e)?e:new ce(e,t,r);return Je(function(){var s=o,c=s.operator,p=s.source;i.add(c?c.call(i,p):p?o._subscribe(i):o._trySubscribe(i))}),i},n.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},n.prototype.forEach=function(e,t){var r=this;return t=Me(t),new t(function(o,i){var s=new ce({next:function(c){try{e(c)}catch(p){i(p),s.unsubscribe()}},error:i,complete:o});r.subscribe(s)})},n.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},n.prototype[Ge]=function(){return this},n.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ze(e)(this)},n.prototype.toPromise=function(e){var t=this;return e=Me(e),new e(function(r,o){var i;t.subscribe(function(s){return i=s},function(s){return o(s)},function(){return r(i)})})},n.create=function(e){return new n(e)},n}();function Me(n){var e;return(e=n!=null?n:Se.Promise)!==null&&e!==void 0?e:Promise}function tt(n){return n&&F(n.next)&&F(n.error)&&F(n.complete)}function nt(n){return n&&n instanceof Pe||tt(n)&&Ee(n)}const rt=()=>{try{clearTimeout(void 0)}catch(n){return!1}return!0},it=(n={})=>{const{parentOrigin:e="*",timeout:t,debug:r=!1,config:o={}}=n,i=Fe(r),s=_e("App",i),{destroy:c,onDestroy:p}=s,S=()=>{i("Child: Handshake - Sending SYN");const $={penpal:_.Syn},y=e instanceof RegExp?"*":e;window.parent.postMessage($,y)};return{promise:new Promise(($,y)=>{const h=Ne(t,c),b=l=>{if(rt()&&!(l.source!==parent||!l.data)&&l.data.penpal===_.SynAck){const m=l.data,P=new me(m.id,m.appName),T=new me(m.id+"/api",m.appName),O=m.id,R={},D=u=>"api/"+u,Y={$emit:(u,...f)=>{P.getEventCallBackLength(u)>0?P.$pureEmit(u,...f):R==null||R.$off(u,()=>{},!0)},onQueryResult:u=>{T.$pureEmit(D(u.reqid),u)},onOsNotify:u=>{}},z=u=>function(w){const V=D(u);T.$on(V,function I(A){w.next(A),A.reqid&&A.result==="succ"&&(w.complete(),T.$off(V,I))})},st=de(Y),q=He(e,st,H(W({},o),{postmateVersion:Le.version}),s,i)(l),x={},G=q.bus;if(G){const u=(f,w,V)=>{V?(w.$__once=!0,P.$once(f,w)):P.$on(f,w),x[f]?x[f].push(w):(x[f]=[w],G.$on(f,O))};Object.assign(R,G,{$on:u,$off:(f,w,V)=>{var I;if(x[f]){const A=x[f].indexOf(w);A>-1&&(x[f].splice(A,1),P.$off(f,w))}V&&delete x[f],(I=x[f])!=null&&I.length||(G.$off(f,O),delete x[f])},$once:(f,w)=>{u(f,w,!0)}})}const ct=H(W({},q),{bus:R,query:(u,f)=>v(this,null,function*(){const w=(u==null?void 0:u.reqid)||(yield q.genReqId());return new Promise((V,I)=>{q.query(H(W({},u),{reqid:w}),f).then(A=>{(A==null?void 0:A.result)==="succ"?V(A):I(A)})})}),createObservableQuery:(w,...V)=>v(this,[w,...V],function*(u,f={}){const I=(u==null?void 0:u.reqid)||(yield q.genReqId()),A=new et(z(I));return q.query(H(W({},u),{reqid:I}),H(W({},f),{observable:!0})),A})});q&&(window.removeEventListener(j.Message,b),h(),$({methods:ct,config:l.data.config}))}};window.addEventListener(j.Message,b),S(),p(l=>{window.removeEventListener(j.Message,b),l&&y(l)})}),destroy(){c()}}},ot=n=>it({debug:n==null?void 0:n.debug}).promise;class Ce{constructor(){M(this,"options");M(this,"flutterInAppWebView",null);M(this,"osConnector",null);M(this,"initPromise");M(this,"isWeb",!0);let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.options=e,e.debug&&(a.setDebug(!0),a.log("Trim App initialized with debug mode")),a.log("Options:",e),this.initPromise=this.init()}init(){return v(this,null,function*(){return a.log("Starting initialization..."),new Promise(e=>{k()?(this.isWeb=!1,a.log("Initializing mobile platform..."),Z().then(t=>{this.flutterInAppWebView=t,a.log("Mobile platform initialized"),e()})):(this.isWeb=!0,a.log("Initializing web platform..."),ot().then(t=>{this.osConnector=t,a.log("Web platform initialized"),e()}))})})}callAppMethod(e,t){return v(this,null,function*(){return this.flutterInAppWebView?U(this.flutterInAppWebView,e,t):null})}ready(){return v(this,null,function*(){return this.initPromise})}getOptions(){return this.options}setOptions(e){this.options=W(W({},this.options),e),e.debug!==void 0&&a.setDebug(e.debug),a.log("Options updated:",this.options)}getPlatformConfig(){return v(this,null,function*(){var e;if(yield this.initPromise,this.isWeb){const t=yield(e=this.osConnector)==null?void 0:e.methods.getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}else{const t=yield this.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){return v(this,null,function*(){var t;return yield this.initPromise,a.log("Setting title:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)})}setExitPageTips(e){return v(this,null,function*(){var t;return yield this.initPromise,this.isWeb?(t=this.osConnector)==null?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})}openFile(e){return v(this,null,function*(){var t;return yield this.initPromise,a.log("Opening file:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)})}openFileManager(e){return v(this,null,function*(){var t;return yield this.initPromise,a.log("Opening file manager:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)})}close(){return v(this,null,function*(){var e;return yield this.initPromise,this.isWeb?(e=this.osConnector)==null?void 0:e.methods.close():this.callAppMethod("exitPage")})}query(e,t){return v(this,null,function*(){var r;if(yield this.initPromise,this.isWeb){const o=yield(r=this.osConnector)==null?void 0:r.methods.query(e,t);if(!o)throw new Error("Failed to query");return o}else throw new Error("query is not supported on mobile platform")})}pickFile(e){return v(this,null,function*(){var t;return yield this.initPromise,this.isWeb?(t=this.osConnector)==null?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))})}}return g.TrimApp=Ce,g.default=Ce,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),g}({});
|
|
1
|
+
var TrimApp=(function(g){"use strict";var st=Object.defineProperty,ct=Object.defineProperties;var at=Object.getOwnPropertyDescriptors;var Me=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable;var ce=(g,d,c)=>d in g?st(g,d,{enumerable:!0,configurable:!0,writable:!0,value:c}):g[d]=c,q=(g,d)=>{for(var c in d||(d={}))lt.call(d,c)&&ce(g,c,d[c]);if(Me)for(var c of Me(d))ut.call(d,c)&&ce(g,c,d[c]);return g},H=(g,d)=>ct(g,at(d));var M=(g,d,c)=>ce(g,typeof d!="symbol"?d+"":d,c);var v=(g,d,c)=>new Promise((X,k)=>{var K=O=>{try{U(c.next(O))}catch(B){k(B)}},Z=O=>{try{U(c.throw(O))}catch(B){k(B)}},U=O=>O.done?X(O.value):Promise.resolve(O.value).then(K,Z);U((c=c.apply(g,d)).next())});class d{constructor(){M(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 c=new d;function X(r){const e=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,t={};let n;for(;(n=e.exec(r))!==null;)n[1]&&(t.fnOSVersion=n[1]),n[2]&&(t.fnAppType=n[2]),n[3]&&(t.fnAppVersion=n[3]);return t}const k=()=>X(navigator.userAgent).fnAppVersion;let K=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{K=!0});const Z=()=>new Promise(r=>{var e;K||(e=window.flutter_inappwebview)!=null&&e._platformReady?(c.log("flutter_inappwebview is ready"),r(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{c.log("flutter_inappwebview is ready"),r(window.flutter_inappwebview)})}),U=(r,e,t)=>v(null,null,function*(){c.log(`callHandler: ${e}, params: ${t}`);const n=yield r.callHandler(e,t);if(n)try{const o=JSON.parse(n);c.log(`messageData: ${JSON.stringify(o)}`);const i=JSON.parse(o.result);return c.log(`appMessage: ${JSON.stringify(i)}`),i}catch(o){return c.error(`error: ${o}`),null}return null}),O=new Map;function B(){window.fnAppMessage=r=>{c.log("app-message",r);const e=JSON.parse(r),t=O.get(e.reqId);t&&(t(e),O.delete(e.reqId))}}k()&&B();var C=(r=>(r.Call="call",r.Reply="reply",r.Syn="syn",r.SynAck="synAck",r.Ack="ack",r))(C||{}),j=(r=>(r.Fulfilled="fulfilled",r.Rejected="rejected",r))(j||{}),ee=(r=>(r.ConnectionDestroyed="ConnectionDestroyed",r.ConnectionTimeout="ConnectionTimeout",r.NoIframeSrc="NoIframeSrc",r))(ee||{}),ae=(r=>(r.DataCloneError="DataCloneError",r))(ae||{}),V=(r=>(r.Message="message",r))(V||{});const Oe=(r,e)=>{const t=[];let n=!1;return{destroy(o){n||(n=!0,e(`${r}: Destroying connection`),t.forEach(i=>{i(o)}))},onDestroy(o){n?o():t.push(o)}}},_e=r=>(...e)=>{r&&console.log("[Penpal]",...e)},le=({name:r,message:e,stack:t})=>({name:r,message:e,stack:t}),Ce=r=>{const e=new Error;return Object.keys(r).forEach(t=>e[t]=r[t]),e},Te=(r,e,t)=>{const{localName:n,local:o,remote:i,originForSending:s,originForReceiving:a}=r;let p=!1;const S=A=>{if(A.source!==i||A.data.penpal!==C.Call)return;if(a!=="*"&&A.origin!==a){t(`${n} received message from origin ${A.origin} which did not match expected origin ${a}`);return}const $=A.data,{methodName:y,args:h,id:b}=$;t(`${n}: Received ${y}() call`);const l=m=>P=>{if(t(`${n}: Sending ${y}() reply`),p){t(`${n}: Unable to send ${y}() reply due to destroyed connection`);return}const _={penpal:C.Reply,id:b,resolution:m,returnValue:P};m===j.Rejected&&P instanceof Error&&(_.returnValue=le(P),_.returnValueIsError=!0);try{i.postMessage(_,s)}catch(F){if(F.name===ae.DataCloneError){const R={penpal:C.Reply,id:b,resolution:j.Rejected,returnValue:le(F),returnValueIsError:!0};i.postMessage(R,s)}throw F}};new Promise(m=>m(e[y].apply(e,h))).then(l(j.Fulfilled),l(j.Rejected))};return o.addEventListener(V.Message,S),()=>{p=!0,o.removeEventListener(V.Message,S)}};let Fe=0;const Re=()=>++Fe,ue=".",fe=r=>r?r.split(ue):[],xe=r=>r.join(ue),Ie=(r,e)=>{const t=fe(e||"");return t.push(r),xe(t)},Ne=(r,e,t)=>{const n=fe(e);return n.reduce((o,i,s)=>(typeof o[i]=="undefined"&&(o[i]={}),s===n.length-1&&(o[i]=t),o[i]),r),r},pe=(r,e)=>{const t={};return Object.keys(r).forEach(n=>{const o=r[n],i=Ie(n,e);typeof o=="object"&&Object.assign(t,pe(o,i)),typeof o=="function"&&(t[i]=o)}),t},Ve=r=>{const e={};for(const t in r)Ne(e,t,r[t]);return e},We=(r,e,t,n,o)=>{const{localName:i,local:s,remote:a,originForSending:p,originForReceiving:S}=e;let A=!1;o(`${i}: Connecting call sender`);const $=h=>(...b)=>{o(`${i}: Sending ${h}() call`);let l;try{a.closed&&(l=!0)}catch(m){l=!0}if(l&&n(),A){const m=new Error(`Unable to send ${h}() call due to destroyed connection`);throw m.code=ee.ConnectionDestroyed,m}return new Promise((m,P)=>{const _=Re(),F=x=>{if(x.source!==a||x.data.penpal!==C.Reply||x.data.id!==_)return;if(S!=="*"&&x.origin!==S){o(`${i} received message from origin ${x.origin} which did not match expected origin ${S}`);return}const Y=x.data;o(`${i}: Received ${h}() reply`),s.removeEventListener(V.Message,F);let z=Y.returnValue;Y.returnValueIsError&&(z=Ce(z)),(Y.resolution===j.Fulfilled?m:P)(z)};s.addEventListener(V.Message,F);const R={penpal:C.Call,id:_,methodName:h,args:b};a.postMessage(R,p)})},y=t.reduce((h,b)=>(h[b]=$(b),h),{});return Object.assign(r,Ve(y)),()=>{A=!0}},qe=(r,e)=>{let t;return r!==void 0&&(t=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${r}ms`);n.code=ee.ConnectionTimeout,e(n)},r)),()=>{clearTimeout(t)}},De={version:"0.1.2"},je=(r,e,t,n,o)=>{const{destroy:i,onDestroy:s}=n;return a=>{if(!(r instanceof RegExp?r.test(a.origin):r==="*"||r===a.origin)){o(`Child: Handshake - Received SYN-ACK from origin ${a.origin} which did not match expected origin ${r}`);return}o("Child: Handshake - Received SYN-ACK, responding with ACK");const S=a.origin==="null"?"*":a.origin,A={penpal:C.Ack,methodNames:Object.keys(e),config:t};window.parent.postMessage(A,S);const $={localName:"Child",local:window,remote:window.parent,originForSending:S,originForReceiving:a.origin},y=Te($,e,o);s(y);const h={},b=We(h,$,a.data.methodNames,i,o);return s(b),h}};function de(r,e){console==null||console.warn(`[fnApp warn]: ${r}`,e)}function he(r,e){console==null||console.error(`[fnApp error]: ${r}`,e)}const L="_fn_all_event",ge="事件订阅数量为空",J=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map;class ye{constructor(e,t){M(this,"id");M(this,"appName");M(this,"eventObj");M(this,"getEventCallBackLength",e=>{var t;return((t=this.eventObj[e])==null?void 0:t.length)||0});this.id=e,this.appName=t,this.$clear(),J.get(this.id)||J.set(this.id,{}),this.eventObj=J.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(L,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 de(`${e} ${ge}`),this;let o,i=n.length;for(;i--;)if(o=n[i],o===t){n.splice(i,1);break}return this}$offAll(e){return this.$off(L,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let n=0,o=0;return J.forEach(i=>{if(i[e])for(let s=i[e].length-1;s>=0;s--){n++;const a=i[e][s];a.$__once&&i[e].splice(s,1);try{a(...t)}catch(p){he(p)}}if(i[L])for(let s=i[L].length-1;s>=0;s--){n++;const a=i[L][s];a.$__once&&i[L].splice(s,1);try{a(...t)}catch(p){he(p)}}}),(!e||n===0&&o===0)&&de(`${e} ${ge}`),this}$clear(){const e=J.get(this.id)||{};return Object.keys(e).forEach(n=>delete e[n]),this}}var te=function(r,e){return te=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])},te(r,e)};function me(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");te(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function be(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function re(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(a){s={error:a}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return i}function ne(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))}typeof SuppressedError=="function"&&SuppressedError;function T(r){return typeof r=="function"}function Le(r){var e=function(n){Error.call(n),n.stack=new Error().stack},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var ie=Le(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
|
|
2
|
+
`+t.map(function(n,o){return o+1+") "+n.toString()}).join(`
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=t}});function we(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var oe=(function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=be(s),p=a.next();!p.done;p=a.next()){var S=p.value;S.remove(this)}}catch(l){e={error:l}}finally{try{p&&!p.done&&(t=a.return)&&t.call(a)}finally{if(e)throw e.error}}else s.remove(this);var A=this.initialTeardown;if(T(A))try{A()}catch(l){i=l instanceof ie?l.errors:[l]}var $=this._finalizers;if($){this._finalizers=null;try{for(var y=be($),h=y.next();!h.done;h=y.next()){var b=h.value;try{Ae(b)}catch(l){i=i!=null?i:[],l instanceof ie?i=ne(ne([],re(i)),re(l.errors)):i.push(l)}}}catch(l){n={error:l}}finally{try{h&&!h.done&&(o=y.return)&&o.call(y)}finally{if(n)throw n.error}}}if(i)throw new ie(i)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)Ae(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&we(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&we(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=(function(){var e=new r;return e.closed=!0,e})(),r})();oe.EMPTY;function ve(r){return r instanceof oe||r&&"closed"in r&&T(r.remove)&&T(r.add)&&T(r.unsubscribe)}function Ae(r){T(r)?r():r.unsubscribe()}var He={Promise:void 0},ke={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setTimeout.apply(void 0,ne([r,e],re(t)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function Ue(r){ke.setTimeout(function(){throw r})}function Ee(){}function Be(r){r()}var Se=(function(r){me(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,ve(t)&&t.add(n)):n.destination=ze,n}return e.create=function(t,n,o){return new se(t,n,o)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e})(oe),Je=(function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){Q(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){Q(n)}else Q(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){Q(t)}},r})(),se=(function(r){me(e,r);function e(t,n,o){var i=r.call(this)||this,s;return T(t)||!t?s={next:t!=null?t:void 0,error:n!=null?n:void 0,complete:o!=null?o:void 0}:s=t,i.destination=new Je(s),i}return e})(Se);function Q(r){Ue(r)}function Ye(r){throw r}var ze={closed:!0,next:Ee,error:Ye,complete:Ee},Ke=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Qe(r){return r}function Ge(r){return r.length===0?Qe:r.length===1?r[0]:function(t){return r.reduce(function(n,o){return o(n)},t)}}var Xe=(function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,n){var o=this,i=et(e)?e:new se(e,t,n);return Be(function(){var s=o,a=s.operator,p=s.source;i.add(a?a.call(i,p):p?o._subscribe(i):o._trySubscribe(i))}),i},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var n=this;return t=$e(t),new t(function(o,i){var s=new se({next:function(a){try{e(a)}catch(p){i(p),s.unsubscribe()}},error:i,complete:o});n.subscribe(s)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[Ke]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ge(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=$e(e),new e(function(n,o){var i;t.subscribe(function(s){return i=s},function(s){return o(s)},function(){return n(i)})})},r.create=function(e){return new r(e)},r})();function $e(r){var e;return(e=r!=null?r:He.Promise)!==null&&e!==void 0?e:Promise}function Ze(r){return r&&T(r.next)&&T(r.error)&&T(r.complete)}function et(r){return r&&r instanceof Se||Ze(r)&&ve(r)}const tt=()=>{try{clearTimeout(void 0)}catch(r){return!1}return!0},rt=(r={})=>{const{parentOrigin:e="*",timeout:t,debug:n=!1,config:o={}}=r,i=_e(n),s=Oe("App",i),{destroy:a,onDestroy:p}=s,S=()=>{i("Child: Handshake - Sending SYN");const $={penpal:C.Syn},y=e instanceof RegExp?"*":e;window.parent.postMessage($,y)};return{promise:new Promise(($,y)=>{const h=qe(t,a),b=l=>{if(tt()&&!(l.source!==parent||!l.data)&&l.data.penpal===C.SynAck){const m=l.data,P=new ye(m.id,m.appName),_=new ye(m.id+"/api",m.appName),F=m.id,R={},x=u=>"api/"+u,Y={$emit:(u,...f)=>{P.getEventCallBackLength(u)>0?P.$pureEmit(u,...f):R==null||R.$off(u,()=>{},!0)},onQueryResult:u=>{_.$pureEmit(x(u.reqid),u)},onOsNotify:u=>{}},z=u=>function(w){const W=x(u);_.$on(W,function N(E){w.next(E),E.reqid&&E.result==="succ"&&(w.complete(),_.$off(W,N))})},it=pe(Y),D=je(e,it,H(q({},o),{postmateVersion:De.version}),s,i)(l),I={},G=D.bus;if(G){const u=(f,w,W)=>{W?(w.$__once=!0,P.$once(f,w)):P.$on(f,w),I[f]?I[f].push(w):(I[f]=[w],G.$on(f,F))};Object.assign(R,G,{$on:u,$off:(f,w,W)=>{var N;if(I[f]){const E=I[f].indexOf(w);E>-1&&(I[f].splice(E,1),P.$off(f,w))}W&&delete I[f],(N=I[f])!=null&&N.length||(G.$off(f,F),delete I[f])},$once:(f,w)=>{u(f,w,!0)}})}const ot=H(q({},D),{bus:R,query:(u,f)=>v(null,null,function*(){const w=(u==null?void 0:u.reqid)||(yield D.genReqId());return new Promise((W,N)=>{D.query(H(q({},u),{reqid:w}),f).then(E=>{(E==null?void 0:E.result)==="succ"?W(E):N(E)})})}),createObservableQuery:(w,...W)=>v(null,[w,...W],function*(u,f={}){const N=(u==null?void 0:u.reqid)||(yield D.genReqId()),E=new Xe(z(N));return D.query(H(q({},u),{reqid:N}),H(q({},f),{observable:!0})),E})});D&&(window.removeEventListener(V.Message,b),h(),$({methods:ot,config:l.data.config}))}};window.addEventListener(V.Message,b),S(),p(l=>{window.removeEventListener(V.Message,b),l&&y(l)})}),destroy(){a()}}},nt=r=>rt({debug:r==null?void 0:r.debug}).promise;class Pe{constructor(){M(this,"options");M(this,"flutterInAppWebView",null);M(this,"osConnector",null);M(this,"initPromise");M(this,"isWeb",!0);let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.options=e,e.debug&&(c.setDebug(!0),c.log("Trim App initialized with debug mode")),c.log("Options:",e),this.initPromise=this.init()}init(){return v(this,null,function*(){return c.log("Starting initialization..."),new Promise(e=>{k()?(this.isWeb=!1,c.log("Initializing mobile platform..."),Z().then(t=>{this.flutterInAppWebView=t,c.log("Mobile platform initialized"),e()})):(this.isWeb=!0,c.log("Initializing web platform..."),nt().then(t=>{this.osConnector=t,c.log("Web platform initialized"),e()}))})})}callAppMethod(e,t){return v(this,null,function*(){return this.flutterInAppWebView?U(this.flutterInAppWebView,e,t):null})}ready(){return v(this,null,function*(){return this.initPromise})}getOptions(){return this.options}setOptions(e){this.options=q(q({},this.options),e),e.debug!==void 0&&c.setDebug(e.debug),c.log("Options updated:",this.options)}getPlatformConfig(){return v(this,null,function*(){var e;if(yield this.initPromise,this.isWeb){const t=yield(e=this.osConnector)==null?void 0:e.methods.getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}else{const t=yield this.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){return v(this,null,function*(){var t;return yield this.initPromise,c.log("Setting title:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)})}setExitPageTips(e){return v(this,null,function*(){var t;return yield this.initPromise,this.isWeb?(t=this.osConnector)==null?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})}openFile(e){return v(this,null,function*(){var t;return yield this.initPromise,c.log("Opening file:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)})}openFileManager(e){return v(this,null,function*(){var t;return yield this.initPromise,c.log("Opening file manager:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)})}close(){return v(this,null,function*(){var e;return yield this.initPromise,this.isWeb?(e=this.osConnector)==null?void 0:e.methods.close():this.callAppMethod("exitPage")})}query(e,t){return v(this,null,function*(){var n;if(yield this.initPromise,this.isWeb){const o=yield(n=this.osConnector)==null?void 0:n.methods.query(e,t);if(!o)throw new Error("Failed to query");return o}else throw new Error("query is not supported on mobile platform")})}pickFile(e){return v(this,null,function*(){var t;return yield this.initPromise,this.isWeb?(t=this.osConnector)==null?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))})}}return g.TrimApp=Pe,g.default=Pe,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),g})({});
|