@trimjs/web-app 0.1.2 → 0.1.4
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/dist/index.cjs +3 -3
- package/dist/index.iife.js +2 -2
- package/dist/index.js +401 -388
- package/dist/index.umd.cjs +2 -2
- package/package.json +5 -5
- package/dist/index.d.ts +0 -72
- package/dist/logger.d.ts +0 -38
- package/dist/mobile/index.d.ts +0 -23
- package/dist/mobile/types.d.ts +0 -9
- package/dist/types.d.ts +0 -17
- package/dist/utils/platform.d.ts +0 -2
- package/dist/web/index.d.ts +0 -14
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var Pe=Object.defineProperty,Me=Object.defineProperties;var
|
|
2
|
-
`+t.map(function(
|
|
3
|
-
`):"",this.name="UnsubscriptionError",this.errors=t}});function ae(n,e){if(n){var t=n.indexOf(e);0<=t&&n.splice(t,1)}}var Z=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,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=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){o=l instanceof J?l.errors:[l]}var S=this._finalizers;if(S){this._finalizers=null;try{for(var g=ce(S),p=g.next();!p.done;p=g.next()){var b=p.value;try{le(b)}catch(l){o=o!=null?o:[],l instanceof J?o=Q(Q([],K(o)),K(l.errors)):o.push(l)}}}catch(l){r={error:l}}finally{try{p&&!p.done&&(i=g.return)&&i.call(g)}finally{if(r)throw r.error}}}if(o)throw new J(o)}},n.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)le(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)&&ae(t,e)},n.prototype.remove=function(e){var t=this._finalizers;t&&ae(t,e),e instanceof n&&e._removeParent(this)},n.EMPTY=function(){var e=new n;return e.closed=!0,e}(),n}();Z.EMPTY;function we(n){return n instanceof Z||n&&"closed"in n&&R(n.remove)&&R(n.add)&&R(n.unsubscribe)}function le(n){R(n)?n():n.unsubscribe()}var ve={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ot={setTimeout:function(n,e){for(var t=[],r=2;r<arguments.length;r++)t[r-2]=arguments[r];return setTimeout.apply(void 0,Q([n,e],K(t)))},clearTimeout:function(n){return clearTimeout(n)},delegate:void 0};function st(n){ot.setTimeout(function(){throw n})}function ue(){}function ct(n){n()}var Ee=function(n){me(e,n);function e(t){var r=n.call(this)||this;return r.isStopped=!1,t?(r.destination=t,we(t)&&t.add(r)):r.destination=ft,r}return e.create=function(t,r,i){return new G(t,r,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,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}(Z),at=Function.prototype.bind;function Y(n,e){return at.call(n,e)}var lt=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){U(r)}},n.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(r){U(r)}else U(e)},n.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){U(t)}},n}(),G=function(n){me(e,n);function e(t,r,i){var o=n.call(this)||this,s;if(R(t)||!t)s={next:t!=null?t:void 0,error:r!=null?r:void 0,complete:i!=null?i:void 0};else{var c;o&&ve.useDeprecatedNextContext?(c=Object.create(t),c.unsubscribe=function(){return o.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 o.destination=new lt(s),o}return e}(Ee);function U(n){st(n)}function ut(n){throw n}var ft={closed:!0,next:ue,error:ut,complete:ue},pt=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function dt(n){return n}function ht(n){return n.length===0?dt:n.length===1?n[0]:function(t){return n.reduce(function(r,i){return i(r)},t)}}var gt=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 i=this,o=bt(e)?e:new G(e,t,r);return ct(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},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=fe(t),new t(function(i,o){var s=new G({next:function(c){try{e(c)}catch(a){o(a),s.unsubscribe()}},error:o,complete:i});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[pt]=function(){return this},n.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return ht(e)(this)},n.prototype.toPromise=function(e){var t=this;return e=fe(e),new e(function(r,i){var o;t.subscribe(function(s){return o=s},function(s){return i(s)},function(){return r(o)})})},n.create=function(e){return new n(e)},n}();function fe(n){var e;return(e=n!=null?n:ve.Promise)!==null&&e!==void 0?e:Promise}function yt(n){return n&&R(n.next)&&R(n.error)&&R(n.complete)}function bt(n){return n&&n instanceof Ee||yt(n)&&we(n)}const mt=()=>{try{clearTimeout(void 0)}catch(n){return!1}return!0},wt=(n={})=>{const{parentOrigin:e="*",timeout:t,debug:r=!1,config:i={}}=n,o=je(r),s=Ie("App",o),{destroy:c,onDestroy:a}=s,h=()=>{o("Child: Handshake - Sending SYN");const S={penpal:O.Syn},g=e instanceof RegExp?"*":e;window.parent.postMessage(S,g)};return{promise:new Promise((S,g)=>{const p=Je(t,c),b=l=>{if(mt()&&!(l.source!==parent||!l.data)&&l.data.penpal===O.SynAck){const y=l.data,A=new se(y.id,y.appName),P=new se(y.id+"/api",y.appName),M=y.id,_={},C=u=>"api/"+u,q={$emit:(u,...f)=>{A.getEventCallBackLength(u)>0?A.$pureEmit(u,...f):_==null||_.$off(u,()=>{},!0)},onQueryResult:u=>{P.$pureEmit(C(u.reqid),u)},onOsNotify:u=>{}},L=u=>function(m){const x=C(u);P.$on(x,function F(E){m.next(E),E.reqid&&E.result==="succ"&&(m.complete(),P.$off(x,F))})},Ae=be(q),j=rt(e,Ae,k(D({},i),{postmateVersion:nt.version}),s,o)(l),T={},H=j.bus;if(H){const u=(f,m,x)=>{x?(m.$__once=!0,A.$once(f,m)):A.$on(f,m),T[f]?T[f].push(m):(T[f]=[m],H.$on(f,M))};Object.assign(_,H,{$on:u,$off:(f,m,x)=>{var F;if(T[f]){const E=T[f].indexOf(m);E>-1&&(T[f].splice(E,1),A.$off(f,m))}x&&delete T[f],(F=T[f])!=null&&F.length||(H.$off(f,M),delete T[f])},$once:(f,m)=>{u(f,m,!0)}})}const $e=k(D({},j),{bus:_,query:(u,f)=>w(exports,null,function*(){const m=(u==null?void 0:u.reqid)||(yield j.genReqId());return new Promise((x,F)=>{j.query(k(D({},u),{reqid:m}),f).then(E=>{(E==null?void 0:E.result)==="succ"?x(E):F(E)})})}),createObservableQuery:(m,...x)=>w(exports,[m,...x],function*(u,f={}){const F=(u==null?void 0:u.reqid)||(yield j.genReqId()),E=new gt(L(F));return j.query(k(D({},u),{reqid:F}),k(D({},f),{observable:!0})),E})});j&&(window.removeEventListener(I.Message,b),p(),S({methods:$e,config:l.data.config}))}};window.addEventListener(I.Message,b),h(),a(l=>{window.removeEventListener(I.Message,b),l&&g(l)})}),destroy(){c()}}},vt=n=>wt({debug:n==null?void 0:n.debug}).promise;class Se{constructor(e={}){$(this,"options");$(this,"flutterInAppWebView",null);$(this,"osConnector",null);$(this,"initPromise");$(this,"isWeb",!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 r;if(yield this.initPromise,this.isWeb){const i=yield(r=this.osConnector)==null?void 0:r.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=Se;exports.default=Se;
|
|
1
|
+
"use strict";var Pe=Object.defineProperty,Me=Object.defineProperties;var Ce=Object.getOwnPropertyDescriptors;var ee=Object.getOwnPropertySymbols;var Te=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var B=(r,e,t)=>e in r?Pe(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,D=(r,e)=>{for(var t in e||(e={}))Te.call(e,t)&&B(r,t,e[t]);if(ee)for(var t of ee(e))_e.call(e,t)&&B(r,t,e[t]);return r},V=(r,e)=>Me(r,Ce(e));var $=(r,e,t)=>B(r,typeof e!="symbol"?e+"":e,t);var w=(r,e,t)=>new Promise((n,o)=>{var i=a=>{try{c(t.next(a))}catch(h){o(h)}},s=a=>{try{c(t.throw(a))}catch(h){o(h)}},c=a=>a.done?n(a.value):Promise.resolve(a.value).then(i,s);c((t=t.apply(r,e)).next())});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class Fe{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 Fe;function Oe(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 pe=()=>Oe(navigator.userAgent).fnAppVersion;let de=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{de=!0});const Re=()=>new Promise(r=>{var e;de||(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)})}),xe=(r,e,t)=>w(exports,null,function*(){d.log(`callHandler: ${e}, params: ${t}`);const n=yield r.callHandler(e,t);if(n)try{const o=JSON.parse(n);d.log(`messageData: ${JSON.stringify(o)}`);const i=JSON.parse(o.result);return d.log(`appMessage: ${JSON.stringify(i)}`),i}catch(o){return d.error(`error: ${o}`),null}return null}),te=new Map;function De(){window.fnAppMessage=r=>{d.log("app-message",r);const e=JSON.parse(r),t=te.get(e.reqId);t&&(t(e),te.delete(e.reqId))}}pe()&&De();var O=(r=>(r.Call="call",r.Reply="reply",r.Syn="syn",r.SynAck="synAck",r.Ack="ack",r))(O||{}),q=(r=>(r.Fulfilled="fulfilled",r.Rejected="rejected",r))(q||{}),X=(r=>(r.ConnectionDestroyed="ConnectionDestroyed",r.ConnectionTimeout="ConnectionTimeout",r.NoIframeSrc="NoIframeSrc",r))(X||{}),he=(r=>(r.DataCloneError="DataCloneError",r))(he||{}),I=(r=>(r.Message="message",r))(I||{});const Ie=(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)}}},je=r=>(...e)=>{r&&console.log("[Penpal]",...e)},re=({name:r,message:e,stack:t})=>({name:r,message:e,stack:t}),Ve=r=>{const e=new Error;return Object.keys(r).forEach(t=>e[t]=r[t]),e},We=(r,e,t)=>{const{localName:n,local:o,remote:i,originForSending:s,originForReceiving:c}=r;let a=!1;const h=v=>{if(v.source!==i||v.data.penpal!==O.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:O.Reply,id:m,resolution:y,returnValue:S};y===q.Rejected&&S instanceof Error&&(P.returnValue=re(S),P.returnValueIsError=!0);try{i.postMessage(P,s)}catch(M){if(M.name===he.DataCloneError){const C={penpal:O.Reply,id:m,resolution:q.Rejected,returnValue:re(M),returnValueIsError:!0};i.postMessage(C,s)}throw M}};new Promise(y=>y(e[g].apply(e,p))).then(l(q.Fulfilled),l(q.Rejected))};return o.addEventListener(I.Message,h),()=>{a=!0,o.removeEventListener(I.Message,h)}};let qe=0;const Ne=()=>++qe,ge=".",ye=r=>r?r.split(ge):[],Le=r=>r.join(ge),He=(r,e)=>{const t=ye(e||"");return t.push(r),Le(t)},ke=(r,e,t)=>{const n=ye(e);return n.reduce((o,i,s)=>(typeof o[i]=="undefined"&&(o[i]={}),s===n.length-1&&(o[i]=t),o[i]),r),r},me=(r,e)=>{const t={};return Object.keys(r).forEach(n=>{const o=r[n],i=He(n,e);typeof o=="object"&&Object.assign(t,me(o,i)),typeof o=="function"&&(t[i]=o)}),t},Ue=r=>{const e={};for(const t in r)ke(e,t,r[t]);return e},Be=(r,e,t,n,o)=>{const{localName:i,local:s,remote:c,originForSending:a,originForReceiving:h}=e;let v=!1;o(`${i}: Connecting call sender`);const A=p=>(...m)=>{o(`${i}: 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=X.ConnectionDestroyed,y}return new Promise((y,S)=>{const P=Ne(),M=T=>{if(T.source!==c||T.data.penpal!==O.Reply||T.data.id!==P)return;if(h!=="*"&&T.origin!==h){o(`${i} received message from origin ${T.origin} which did not match expected origin ${h}`);return}const N=T.data;o(`${i}: Received ${p}() reply`),s.removeEventListener(I.Message,M);let L=N.returnValue;N.returnValueIsError&&(L=Ve(L)),(N.resolution===q.Fulfilled?y:S)(L)};s.addEventListener(I.Message,M);const C={penpal:O.Call,id:P,methodName:p,args:m};c.postMessage(C,a)})},g=t.reduce((p,m)=>(p[m]=A(m),p),{});return Object.assign(r,Ue(g)),()=>{v=!0}},Je=(r,e)=>{let t;return r!==void 0&&(t=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${r}ms`);n.code=X.ConnectionTimeout,e(n)},r)),()=>{clearTimeout(t)}},Ye="@fn/micro-app-postmate",ze="0.1.2",Ke="module",Qe="src/index.ts",Ge={dev:"vite",build:"tsc -b && vite build",lint:"eslint ."},Xe=["src","dist"],Ze={"@fn/micro-app-event":"^0.0.1",rxjs:"^7.8.0"},et={"@eslint/js":"^9.13.0","@fn/micro-app-event":"workspace:*",eslint:"^9.13.0",globals:"^15.11.0",typescript:"~5.6.2","typescript-eslint":"^8.11.0",rxjs:"^7.8.0",vite:"^5.4.10"},tt={registry:"http://verdaccio.teiron-inc.cn:4873"},rt={name:Ye,version:ze,type:Ke,main:Qe,scripts:Ge,files:Xe,peerDependencies:Ze,devDependencies:et,publishConfig:tt},nt=(r,e,t,n,o)=>{const{destroy:i,onDestroy:s}=n;return c=>{if(!(r instanceof RegExp?r.test(c.origin):r==="*"||r===c.origin)){o(`Child: Handshake - Received SYN-ACK from origin ${c.origin} which did not match expected origin ${r}`);return}o("Child: Handshake - Received SYN-ACK, responding with ACK");const h=c.origin==="null"?"*":c.origin,v={penpal:O.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=We(A,e,o);s(g);const p={},m=Be(p,A,c.data.methodNames,i,o);return s(m),p}};function ne(r,e){console==null||console.warn(`[fnApp warn]: ${r}`,e)}function ie(r,e){console==null||console.error(`[fnApp error]: ${r}`,e)}const W="_fn_all_event",oe="事件订阅数量为空",H=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map;class se{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(W,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 ne(`${e} ${oe}`),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(W,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let n=0,o=0;return H.forEach(i=>{if(i[e])for(let s=i[e].length-1;s>=0;s--){n++;const c=i[e][s];c.$__once&&i[e].splice(s,1);try{c(...t)}catch(a){ie(a)}}if(i[W])for(let s=i[W].length-1;s>=0;s--){n++;const c=i[W][s];c.$__once&&i[W].splice(s,1);try{c(...t)}catch(a){ie(a)}}}),(!e||n===0&&o===0)&&ne(`${e} ${oe}`),this}$clear(){const e=H.get(this.id)||{};return Object.keys(e).forEach(n=>delete e[n]),this}}var z=function(r,e){return z=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])},z(r,e)};function be(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");z(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function ce(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 K(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(c){s={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return i}function Q(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))}function R(r){return typeof r=="function"}function it(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=it(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 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;
|
package/dist/index.iife.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var TrimApp=function(g){"use strict";var at=Object.defineProperty,lt=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var
|
|
1
|
+
var TrimApp=function(g){"use strict";var at=Object.defineProperty,lt=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var Te=Object.getOwnPropertySymbols;var ft=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable;var ae=(g,d,a)=>d in g?at(g,d,{enumerable:!0,configurable:!0,writable:!0,value:a}):g[d]=a,W=(g,d)=>{for(var a in d||(d={}))ft.call(d,a)&&ae(g,a,d[a]);if(Te)for(var a of Te(d))pt.call(d,a)&&ae(g,a,d[a]);return g},H=(g,d)=>lt(g,ut(d));var M=(g,d,a)=>ae(g,typeof d!="symbol"?d+"":d,a);var v=(g,d,a)=>new Promise((X,k)=>{var K=C=>{try{U(a.next(C))}catch(B){k(B)}},Z=C=>{try{U(a.throw(C))}catch(B){k(B)}},U=C=>C.done?X(C.value):Promise.resolve(C.value).then(K,Z);U((a=a.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),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)}}}const a=new d;function X(n){const e=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,t={};let r;for(;(r=e.exec(n))!==null;)r[1]&&(t.fnOSVersion=r[1]),r[2]&&(t.fnAppType=r[2]),r[3]&&(t.fnAppVersion=r[3]);return t}const k=()=>X(navigator.userAgent).fnAppVersion;let K=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{K=!0});const Z=()=>new Promise(n=>{var e;K||(e=window.flutter_inappwebview)!=null&&e._platformReady?(a.log("flutter_inappwebview is ready"),n(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{a.log("flutter_inappwebview is ready"),n(window.flutter_inappwebview)})}),U=(n,e,t)=>v(this,null,function*(){a.log(`callHandler: ${e}, params: ${t}`);const r=yield n.callHandler(e,t);if(r)try{const o=JSON.parse(r);a.log(`messageData: ${JSON.stringify(o)}`);const i=JSON.parse(o.result);return a.log(`appMessage: ${JSON.stringify(i)}`),i}catch(o){return a.error(`error: ${o}`),null}return null}),C=new Map;function B(){window.fnAppMessage=n=>{a.log("app-message",n);const e=JSON.parse(n),t=C.get(e.reqId);t&&(t(e),C.delete(e.reqId))}}k()&&B();var _=(n=>(n.Call="call",n.Reply="reply",n.Syn="syn",n.SynAck="synAck",n.Ack="ack",n))(_||{}),N=(n=>(n.Fulfilled="fulfilled",n.Rejected="rejected",n))(N||{}),ee=(n=>(n.ConnectionDestroyed="ConnectionDestroyed",n.ConnectionTimeout="ConnectionTimeout",n.NoIframeSrc="NoIframeSrc",n))(ee||{}),le=(n=>(n.DataCloneError="DataCloneError",n))(le||{}),j=(n=>(n.Message="message",n))(j||{});const _e=(n,e)=>{const t=[];let r=!1;return{destroy(o){r||(r=!0,e(`${n}: Destroying connection`),t.forEach(i=>{i(o)}))},onDestroy(o){r?o():t.push(o)}}},Fe=n=>(...e)=>{n&&console.log("[Penpal]",...e)},ue=({name:n,message:e,stack:t})=>({name:n,message:e,stack:t}),Oe=n=>{const e=new Error;return Object.keys(n).forEach(t=>e[t]=n[t]),e},Re=(n,e,t)=>{const{localName:r,local:o,remote:i,originForSending:s,originForReceiving:c}=n;let p=!1;const S=E=>{if(E.source!==i||E.data.penpal!==_.Call)return;if(c!=="*"&&E.origin!==c){t(`${r} received message from origin ${E.origin} which did not match expected origin ${c}`);return}const $=E.data,{methodName:y,args:h,id:b}=$;t(`${r}: Received ${y}() call`);const l=m=>P=>{if(t(`${r}: Sending ${y}() reply`),p){t(`${r}: Unable to send ${y}() reply due to destroyed connection`);return}const T={penpal:_.Reply,id:b,resolution:m,returnValue:P};m===N.Rejected&&P instanceof Error&&(T.returnValue=ue(P),T.returnValueIsError=!0);try{i.postMessage(T,s)}catch(O){if(O.name===le.DataCloneError){const R={penpal:_.Reply,id:b,resolution:N.Rejected,returnValue:ue(O),returnValueIsError:!0};i.postMessage(R,s)}throw O}};new Promise(m=>m(e[y].apply(e,h))).then(l(N.Fulfilled),l(N.Rejected))};return o.addEventListener(j.Message,S),()=>{p=!0,o.removeEventListener(j.Message,S)}};let De=0;const xe=()=>++De,fe=".",pe=n=>n?n.split(fe):[],Ie=n=>n.join(fe),je=(n,e)=>{const t=pe(e||"");return t.push(n),Ie(t)},Ve=(n,e,t)=>{const r=pe(e);return r.reduce((o,i,s)=>(typeof o[i]=="undefined"&&(o[i]={}),s===r.length-1&&(o[i]=t),o[i]),n),n},de=(n,e)=>{const t={};return Object.keys(n).forEach(r=>{const o=n[r],i=je(r,e);typeof o=="object"&&Object.assign(t,de(o,i)),typeof o=="function"&&(t[i]=o)}),t},We=n=>{const e={};for(const t in n)Ve(e,t,n[t]);return e},qe=(n,e,t,r,o)=>{const{localName:i,local:s,remote:c,originForSending:p,originForReceiving:S}=e;let E=!1;o(`${i}: Connecting call sender`);const $=h=>(...b)=>{o(`${i}: Sending ${h}() call`);let l;try{c.closed&&(l=!0)}catch(m){l=!0}if(l&&r(),E){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 T=xe(),O=D=>{if(D.source!==c||D.data.penpal!==_.Reply||D.data.id!==T)return;if(S!=="*"&&D.origin!==S){o(`${i} received message from origin ${D.origin} which did not match expected origin ${S}`);return}const Y=D.data;o(`${i}: Received ${h}() reply`),s.removeEventListener(j.Message,O);let z=Y.returnValue;Y.returnValueIsError&&(z=Oe(z)),(Y.resolution===N.Fulfilled?m:P)(z)};s.addEventListener(j.Message,O);const R={penpal:_.Call,id:T,methodName:h,args:b};c.postMessage(R,p)})},y=t.reduce((h,b)=>(h[b]=$(b),h),{});return Object.assign(n,We(y)),()=>{E=!0}},Ne=(n,e)=>{let t;return n!==void 0&&(t=window.setTimeout(()=>{const r=new Error(`Connection timed out after ${n}ms`);r.code=ee.ConnectionTimeout,e(r)},n)),()=>{clearTimeout(t)}},Le={name:"@fn/micro-app-postmate",version:"0.1.2",type:"module",main:"src/index.ts",scripts:{dev:"vite",build:"tsc -b && vite build",lint:"eslint ."},files:["src","dist"],peerDependencies:{"@fn/micro-app-event":"^0.0.1",rxjs:"^7.8.0"},devDependencies:{"@eslint/js":"^9.13.0","@fn/micro-app-event":"workspace:*",eslint:"^9.13.0",globals:"^15.11.0",typescript:"~5.6.2","typescript-eslint":"^8.11.0",rxjs:"^7.8.0",vite:"^5.4.10"},publishConfig:{registry:"http://verdaccio.teiron-inc.cn:4873"}},He=(n,e,t,r,o)=>{const{destroy:i,onDestroy:s}=r;return c=>{if(!(n instanceof RegExp?n.test(c.origin):n==="*"||n===c.origin)){o(`Child: Handshake - Received SYN-ACK from origin ${c.origin} which did not match expected origin ${n}`);return}o("Child: Handshake - Received SYN-ACK, responding with ACK");const S=c.origin==="null"?"*":c.origin,E={penpal:_.Ack,methodNames:Object.keys(e),config:t};window.parent.postMessage(E,S);const $={localName:"Child",local:window,remote:window.parent,originForSending:S,originForReceiving:c.origin},y=Re($,e,o);s(y);const h={},b=qe(h,$,c.data.methodNames,i,o);return s(b),h}};function he(n,e){console==null||console.warn(`[fnApp warn]: ${n}`,e)}function ge(n,e){console==null||console.error(`[fnApp error]: ${n}`,e)}const L="_fn_all_event",ye="事件订阅数量为空",J=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map;class me{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 r=this.eventObj[e];return r?(r.includes(t)||r.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 r=this.eventObj[e];if(!e||!r||!r.length)return he(`${e} ${ye}`),this;let o,i=r.length;for(;i--;)if(o=r[i],o===t){r.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 r=0,o=0;return J.forEach(i=>{if(i[e])for(let s=i[e].length-1;s>=0;s--){r++;const c=i[e][s];c.$__once&&i[e].splice(s,1);try{c(...t)}catch(p){ge(p)}}if(i[L])for(let s=i[L].length-1;s>=0;s--){r++;const c=i[L][s];c.$__once&&i[L].splice(s,1);try{c(...t)}catch(p){ge(p)}}}),(!e||r===0&&o===0)&&he(`${e} ${ye}`),this}$clear(){const e=J.get(this.id)||{};return Object.keys(e).forEach(r=>delete e[r]),this}}var te=function(n,e){return te=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])},te(n,e)};function be(n,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");te(n,e);function t(){this.constructor=n}n.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function we(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],r=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function ne(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var r=t.call(n),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=r.next()).done;)i.push(o.value)}catch(c){s={error:c}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(s)throw s.error}}return i}function re(n,e,t){if(t||arguments.length===2)for(var r=0,o=e.length,i;r<o;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return n.concat(i||Array.prototype.slice.call(e))}typeof SuppressedError=="function"&&SuppressedError;function F(n){return typeof n=="function"}function ke(n){var e=function(r){Error.call(r),r.stack=new Error().stack},t=n(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var ie=ke(function(n){return function(t){n(this),this.message=t?t.length+` errors occurred during unsubscription:
|
|
2
2
|
`+t.map(function(r,o){return o+1+") "+r.toString()}).join(`
|
|
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 A=p.value;A.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{Se(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)Se(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 Se(n){F(n)?n():n.unsubscribe()}var Ae={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&&Ae.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:Ae.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=Te("App",i),{destroy:c,onDestroy:p}=s,A=()=>{i("Child: Handshake - Sending SYN");const $={penpal:T.Syn},y=e instanceof RegExp?"*":e;window.parent.postMessage($,y)};return{promise:new Promise(($,y)=>{const h=qe(t,c),b=l=>{if(rt()&&!(l.source!==parent||!l.data)&&l.data.penpal===T.SynAck){const m=l.data,P=new me(m.id,m.appName),C=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=>{C.$pureEmit(D(u.reqid),u)},onOsNotify:u=>{}},z=u=>function(w){const k=D(u);C.$on(k,function I(S){w.next(S),S.reqid&&S.result==="succ"&&(w.complete(),C.$off(k,I))})},st=de(Y),W=Ne(e,st,N(V({},o),{postmateVersion:Le.version}),s,i)(l),x={},G=W.bus;if(G){const u=(f,w,k)=>{k?(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,k)=>{var I;if(x[f]){const S=x[f].indexOf(w);S>-1&&(x[f].splice(S,1),P.$off(f,w))}k&&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=N(V({},W),{bus:R,query:(u,f)=>v(this,null,function*(){const w=(u==null?void 0:u.reqid)||(yield W.genReqId());return new Promise((k,I)=>{W.query(N(V({},u),{reqid:w}),f).then(S=>{(S==null?void 0:S.result)==="succ"?k(S):I(S)})})}),createObservableQuery:(w,...k)=>v(this,[w,...k],function*(u,f={}){const I=(u==null?void 0:u.reqid)||(yield W.genReqId()),S=new et(z(I));return W.query(N(V({},u),{reqid:I}),N(V({},f),{observable:!0})),S})});W&&(window.removeEventListener(j.Message,b),h(),$({methods:ct,config:l.data.config}))}};window.addEventListener(j.Message,b),A(),p(l=>{window.removeEventListener(j.Message,b),l&&y(l)})}),destroy(){c()}}},ot=n=>it({debug:n==null?void 0:n.debug}).promise;class _e{constructor(e={}){M(this,"options");M(this,"flutterInAppWebView",null);M(this,"osConnector",null);M(this,"initPromise");M(this,"isWeb",!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=>{H()?(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=V(V({},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=_e,g.default=_e,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),g}({});
|
|
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}({});
|