@trimjs/web-app 0.2.0 → 0.2.1
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 +1 -3
- package/dist/index.iife.js +1 -3
- package/dist/index.js +1 -1051
- package/dist/index.umd.cjs +1 -3
- package/package.json +5 -4
package/dist/index.umd.cjs
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
(function(h,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(h=typeof globalThis!="undefined"?globalThis:h||self,u(h.TrimApp={}))})(this,(function(h){"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=(h,u,c)=>u in h?st(h,u,{enumerable:!0,configurable:!0,writable:!0,value:c}):h[u]=c,j=(h,u)=>{for(var c in u||(u={}))lt.call(u,c)&&ce(h,c,u[c]);if(Me)for(var c of Me(u))ut.call(u,c)&&ce(h,c,u[c]);return h},H=(h,u)=>ct(h,at(u));var M=(h,u,c)=>ce(h,typeof u!="symbol"?u+"":u,c);var v=(h,u,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(h,u)).next())});class u{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 u;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 _=(r=>(r.Call="call",r.Reply="reply",r.Syn="syn",r.SynAck="synAck",r.Ack="ack",r))(_||{}),D=(r=>(r.Fulfilled="fulfilled",r.Rejected="rejected",r))(D||{}),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)}}},Te=r=>(...e)=>{r&&console.log("[Penpal]",...e)},le=({name:r,message:e,stack:t})=>({name:r,message:e,stack:t}),_e=r=>{const e=new Error;return Object.keys(r).forEach(t=>e[t]=r[t]),e},Ce=(r,e,t)=>{const{localName:n,local:o,remote:i,originForSending:s,originForReceiving:a}=r;let d=!1;const S=A=>{if(A.source!==i||A.data.penpal!==_.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:g,id:b}=$;t(`${n}: Received ${y}() call`);const l=m=>P=>{if(t(`${n}: Sending ${y}() reply`),d){t(`${n}: Unable to send ${y}() reply due to destroyed connection`);return}const T={penpal:_.Reply,id:b,resolution:m,returnValue:P};m===D.Rejected&&P instanceof Error&&(T.returnValue=le(P),T.returnValueIsError=!0);try{i.postMessage(T,s)}catch(F){if(F.name===ae.DataCloneError){const R={penpal:_.Reply,id:b,resolution:D.Rejected,returnValue:le(F),returnValueIsError:!0};i.postMessage(R,s)}throw F}};new Promise(m=>m(e[y].apply(e,g))).then(l(D.Fulfilled),l(D.Rejected))};return o.addEventListener(V.Message,S),()=>{d=!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:d,originForReceiving:S}=e;let A=!1;o(`${i}: Connecting call sender`);const $=g=>(...b)=>{o(`${i}: Sending ${g}() call`);let l;try{a.closed&&(l=!0)}catch(m){l=!0}if(l&&n(),A){const m=new Error(`Unable to send ${g}() call due to destroyed connection`);throw m.code=ee.ConnectionDestroyed,m}return new Promise((m,P)=>{const T=Re(),F=x=>{if(x.source!==a||x.data.penpal!==_.Reply||x.data.id!==T)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 ${g}() reply`),s.removeEventListener(V.Message,F);let z=Y.returnValue;Y.returnValueIsError&&(z=_e(z)),(Y.resolution===D.Fulfilled?m:P)(z)};s.addEventListener(V.Message,F);const R={penpal:_.Call,id:T,methodName:g,args:b};a.postMessage(R,d)})},y=t.reduce((g,b)=>(g[b]=$(b),g),{});return Object.assign(r,Ve(y)),()=>{A=!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=ee.ConnectionTimeout,e(n)},r)),()=>{clearTimeout(t)}},qe={version:"0.1.2"},De=(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:_.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=Ce($,e,o);s(y);const g={},b=We(g,$,a.data.methodNames,i,o);return s(b),g}};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(d){he(d)}}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(d){he(d)}}}),(!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 C(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),d=a.next();!d.done;d=a.next()){var S=d.value;S.remove(this)}}catch(l){e={error:l}}finally{try{d&&!d.done&&(t=a.return)&&t.call(a)}finally{if(e)throw e.error}}else s.remove(this);var A=this.initialTeardown;if(C(A))try{A()}catch(l){i=l instanceof ie?l.errors:[l]}var $=this._finalizers;if($){this._finalizers=null;try{for(var y=be($),g=y.next();!g.done;g=y.next()){var b=g.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{g&&!g.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&&C(r.remove)&&C(r.add)&&C(r.unsubscribe)}function Ae(r){C(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 C(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,d=s.source;i.add(a?a.call(i,d):d?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(d){i(d),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&&C(r.next)&&C(r.error)&&C(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=Te(n),s=Oe("App",i),{destroy:a,onDestroy:d}=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 g=je(t,a),b=l=>{if(tt()&&!(l.source!==parent||!l.data)&&l.data.penpal===_.SynAck){const m=l.data,P=new ye(m.id,m.appName),T=new ye(m.id+"/api",m.appName),F=m.id,R={},x=f=>"api/"+f,Y={$emit:(f,...p)=>{P.getEventCallBackLength(f)>0?P.$pureEmit(f,...p):R==null||R.$off(f,()=>{},!0)},onQueryResult:f=>{T.$pureEmit(x(f.reqid),f)},onOsNotify:f=>{}},z=f=>function(w){const W=x(f);T.$on(W,function N(E){w.next(E),E.reqid&&E.result==="succ"&&(w.complete(),T.$off(W,N))})},it=pe(Y),q=De(e,it,H(j({},o),{postmateVersion:qe.version}),s,i)(l),I={},G=q.bus;if(G){const f=(p,w,W)=>{W?(w.$__once=!0,P.$once(p,w)):P.$on(p,w),I[p]?I[p].push(w):(I[p]=[w],G.$on(p,F))};Object.assign(R,G,{$on:f,$off:(p,w,W)=>{var N;if(I[p]){const E=I[p].indexOf(w);E>-1&&(I[p].splice(E,1),P.$off(p,w))}W&&delete I[p],(N=I[p])!=null&&N.length||(G.$off(p,F),delete I[p])},$once:(p,w)=>{f(p,w,!0)}})}const ot=H(j({},q),{bus:R,query:(f,p)=>v(null,null,function*(){const w=(f==null?void 0:f.reqid)||(yield q.genReqId());return new Promise((W,N)=>{q.query(H(j({},f),{reqid:w}),p).then(E=>{(E==null?void 0:E.result)==="succ"?W(E):N(E)})})}),createObservableQuery:(w,...W)=>v(null,[w,...W],function*(f,p={}){const N=(f==null?void 0:f.reqid)||(yield q.genReqId()),E=new Xe(z(N));return q.query(H(j({},f),{reqid:N}),H(j({},p),{observable:!0})),E})});q&&(window.removeEventListener(V.Message,b),g(),$({methods:ot,config:l.data.config}))}};window.addEventListener(V.Message,b),S(),d(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=j(j({},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))})}}h.TrimApp=Pe,h.default=Pe,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TrimApp={})}(this,function(e){"use strict";var t=Object.defineProperty,n=Object.defineProperties,r=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,l=(e,n,r)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r,a=(e,t)=>{for(var n in t||(t={}))i.call(t,n)&&l(e,n,t[n]);if(o)for(var n of o(t))s.call(t,n)&&l(e,n,t[n]);return e},c=(e,t)=>n(e,r(t)),u=(e,t,n)=>l(e,"symbol"!=typeof t?t+"":t,n),p=(e,t,n)=>new Promise((r,o)=>{var i=e=>{try{l(n.next(e))}catch(t){o(t)}},s=e=>{try{l(n.throw(e))}catch(t){o(t)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(i,s);l((n=n.apply(e,t)).next())});const d=new class{constructor(){u(this,"debug",!1)}setDebug(e){this.debug=e}isDebug(){return this.debug}log(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.log("[Trim App]",...t)}}warn(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.warn("[Trim App]",...t)}}error(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.error("[Trim App]",...t)}}info(){if(this.debug){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];console.info("[Trim App]",...t)}}};const f=()=>function(e){const t=/FNOS\/([\d.]+)|FNAppType\/(\w+)|FNAppVer\/([\d.]+)/g,n={};let r;for(;null!==(r=t.exec(e));)r[1]&&(n.fnOSVersion=r[1]),r[2]&&(n.fnAppType=r[2]),r[3]&&(n.fnAppVersion=r[3]);return n}(navigator.userAgent).fnAppVersion;let h=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{h=!0});const g=new Map;f()&&(window.fnAppMessage=e=>{d.log("app-message",e);const t=JSON.parse(e),n=g.get(t.reqId);n&&(n(t),g.delete(t.reqId))});var y=(e=>(e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack",e))(y||{}),v=(e=>(e.Fulfilled="fulfilled",e.Rejected="rejected",e))(v||{}),m=(e=>(e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NoIframeSrc="NoIframeSrc",e))(m||{}),b=(e=>(e.DataCloneError="DataCloneError",e))(b||{}),w=(e=>(e.Message="message",e))(w||{});const _=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});let $=0;const A=e=>e?e.split("."):[],O=(e,t,n)=>{const r=A(t);return r.reduce((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===r.length-1&&(e[t]=n),e[t]),e),e},E=(e,t)=>{const n={};return Object.keys(e).forEach(r=>{const o=e[r],i=((e,t)=>{const n=A(t||"");return n.push(e),(e=>e.join("."))(n)})(r,t);"object"==typeof o&&Object.assign(n,E(o,i)),"function"==typeof o&&(n[i]=o)}),n},P=(e,t,n,r,o)=>{const{localName:i,local:s,remote:l,originForSending:a,originForReceiving:c}=t;let u=!1;o(`${i}: Connecting call sender`);const p=e=>(...t)=>{let n;o(`${i}: Sending ${e}() call`);try{l.closed&&(n=!0)}catch(p){n=!0}if(n&&r(),u){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=m.ConnectionDestroyed,t}return new Promise((n,r)=>{const u=++$,p=t=>{if(t.source!==l||t.data.penpal!==y.Reply||t.data.id!==u)return;if("*"!==c&&t.origin!==c)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${c}`);const a=t.data;o(`${i}: Received ${e}() reply`),s.removeEventListener(w.Message,p);let d=a.returnValue;a.returnValueIsError&&(d=(e=>{const t=new Error;return Object.keys(e).forEach(n=>t[n]=e[n]),t})(d)),(a.resolution===v.Fulfilled?n:r)(d)};s.addEventListener(w.Message,p);const d={penpal:y.Call,id:u,methodName:e,args:t};l.postMessage(d,a)})},d=n.reduce((e,t)=>(e[t]=p(t),e),{});return Object.assign(e,(e=>{const t={};for(const n in e)O(t,n,e[n]);return t})(d)),()=>{u=!0}},S="0.1.2",j=(e,t,n,r,o)=>{const{destroy:i,onDestroy:s}=r;return r=>{if(!(e instanceof RegExp?e.test(r.origin):"*"===e||e===r.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${r.origin} which did not match expected origin ${e}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const l="null"===r.origin?"*":r.origin,a={penpal:y.Ack,methodNames:Object.keys(t),config:n};window.parent.postMessage(a,l);const c={localName:"Child",local:window,remote:window.parent,originForSending:l,originForReceiving:r.origin},u=((e,t,n)=>{const{localName:r,local:o,remote:i,originForSending:s,originForReceiving:l}=e;let a=!1;const c=e=>{if(e.source!==i||e.data.penpal!==y.Call)return;if("*"!==l&&e.origin!==l)return void n(`${r} received message from origin ${e.origin} which did not match expected origin ${l}`);const o=e.data,{methodName:c,args:u,id:p}=o;n(`${r}: Received ${c}() call`);const d=e=>t=>{if(n(`${r}: Sending ${c}() reply`),a)return void n(`${r}: Unable to send ${c}() reply due to destroyed connection`);const o={penpal:y.Reply,id:p,resolution:e,returnValue:t};e===v.Rejected&&t instanceof Error&&(o.returnValue=_(t),o.returnValueIsError=!0);try{i.postMessage(o,s)}catch(l){if(l.name===b.DataCloneError){const e={penpal:y.Reply,id:p,resolution:v.Rejected,returnValue:_(l),returnValueIsError:!0};i.postMessage(e,s)}throw l}};new Promise(e=>e(t[c].apply(t,u))).then(d(v.Fulfilled),d(v.Rejected))};return o.addEventListener(w.Message,c),()=>{a=!0,o.removeEventListener(w.Message,c)}})(c,t,o);s(u);const p={},d=P(p,c,r.data.methodNames,i,o);return s(d),p}};function x(e,t){null==console||console.warn(`[fnApp warn]: ${e}`,t)}function C(e,t){null==console||console.error(`[fnApp error]: ${e}`,t)}const M="_fn_all_event",T="事件订阅数量为空",N=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map;class F{constructor(e,t){u(this,"id"),u(this,"appName"),u(this,"eventObj"),u(this,"getEventCallBackLength",e=>{var t;return(null==(t=this.eventObj[e])?void 0:t.length)||0}),this.id=e,this.appName=t,this.$clear(),N.get(this.id)||N.set(this.id,{}),this.eventObj=N.get(this.id)}$on(e,t){const n=this.eventObj[e];return n?(n.includes(t)||n.push(t),this):(this.eventObj[e]=[t],this)}$onAll(e){return this.$on(M,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 x(`${e} ${T}`),this;let r,o=n.length;for(;o--;)if(r=n[o],r===t){n.splice(o,1);break}return this}$offAll(e){return this.$off(M,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let n=0;return N.forEach(r=>{if(r[e])for(let i=r[e].length-1;i>=0;i--){n++;const s=r[e][i];s.$__once&&r[e].splice(i,1);try{s(...t)}catch(o){C(o)}}if(r[M])for(let e=r[M].length-1;e>=0;e--){n++;const i=r[M][e];i.$__once&&r[M].splice(e,1);try{i(...t)}catch(o){C(o)}}}),e&&0!==n||x(`${e} ${T}`),this}$clear(){const e=N.get(this.id)||{};return Object.keys(e).forEach(t=>delete e[t]),this}}var R=function(e,t){return(R=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function k(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}R(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function V(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function W(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(l){o={error:l}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function I(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function q(e){return"function"==typeof e}"function"==typeof SuppressedError&&SuppressedError;var D,z=((D=function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map(function(e,t){return t+1+") "+e.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}}(function(e){Error.call(e),e.stack=(new Error).stack})).prototype=Object.create(Error.prototype),D.prototype.constructor=D,D);function L(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var J=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=V(i),l=s.next();!l.done;l=s.next()){l.value.remove(this)}}catch(f){e={error:f}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var a=this.initialTeardown;if(q(a))try{a()}catch(h){o=h instanceof z?h.errors:[h]}var c=this._finalizers;if(c){this._finalizers=null;try{for(var u=V(c),p=u.next();!p.done;p=u.next()){var d=p.value;try{H(d)}catch(g){o=null!=o?o:[],g instanceof z?o=I(I([],W(o)),W(g.errors)):o.push(g)}}}catch(y){n={error:y}}finally{try{p&&!p.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}if(o)throw new z(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)H(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&L(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&L(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}();function Y(e){return e instanceof J||e&&"closed"in e&&q(e.remove)&&q(e.add)&&q(e.unsubscribe)}function H(e){q(e)?e():e.unsubscribe()}J.EMPTY;var B=void 0,K=function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,I([e,t],W(n)))};function U(){}var Q=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,Y(t)&&t.add(n)):n.destination=ee,n}return k(t,e),t.create=function(e,t,n){return new X(e,t,n)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(J),G=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){Z(n)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){Z(n)}else Z(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){Z(t)}},e}(),X=function(e){function t(t,n,r){var o,i=e.call(this)||this;return o=q(t)||!t?{next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:t,i.destination=new G(o),i}return k(t,e),t}(Q);function Z(e){var t;t=e,K(function(){throw t})}var ee={closed:!0,next:U,error:function(e){throw e},complete:U},te="function"==typeof Symbol&&Symbol.observable||"@@observable";function ne(e){return e}var re=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof Q||function(e){return e&&q(e.next)&&q(e.error)&&q(e.complete)}(r)&&Y(r)?e:new X(e,t,n);return function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))}(),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=oe(t))(function(t,r){var o=new X({next:function(t){try{e(t)}catch(n){r(n),o.unsubscribe()}},error:r,complete:t});n.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[te]=function(){return this},e.prototype.pipe=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return(0===(e=t).length?ne:1===e.length?e[0]:function(t){return e.reduce(function(e,t){return t(e)},t)})(this)},e.prototype.toPromise=function(e){var t=this;return new(e=oe(e))(function(e,n){var r;t.subscribe(function(e){return r=e},function(e){return n(e)},function(){return e(r)})})},e.create=function(t){return new e(t)},e}();function oe(e){var t;return null!==(t=null!=e?e:B)&&void 0!==t?t:Promise}const ie=(e={})=>{const{parentOrigin:t="*",timeout:n,debug:r=!1,config:o={}}=e,i=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(r),s=((e,t)=>{const n=[];let r=!1;return{destroy(o){r||(r=!0,t(`${e}: Destroying connection`),n.forEach(e=>{e(o)}))},onDestroy(e){r?e():n.push(e)}}})("App",i),{destroy:l,onDestroy:u}=s,d=new Promise((e,r)=>{const d=((e,t)=>{let n;return void 0!==e&&(n=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=m.ConnectionTimeout,t(n)},e)),()=>{clearTimeout(n)}})(n,l),f=n=>{if((()=>{try{clearTimeout(void 0)}catch(e){return!1}return!0})()&&n.source===parent&&n.data&&n.data.penpal===y.SynAck){const r=n.data,l=new F(r.id,r.appName),u=new F(r.id+"/api",r.appName),h=r.id,g={},y=e=>"api/"+e,v=e=>function(t){const n=y(e);u.$on(n,function e(r){t.next(r),r.reqid&&"succ"===r.result&&(t.complete(),u.$off(n,e))})},m=E({$emit:(e,...t)=>{l.getEventCallBackLength(e)>0?l.$pureEmit(e,...t):null==g||g.$off(e,()=>{},!0)},onQueryResult:e=>{u.$pureEmit(y(e.reqid),e)},onOsNotify:e=>{}}),b=j(t,m,c(a({},o),{postmateVersion:S}),s,i)(n),_={},$=b.bus;if($){const e=(e,t,n)=>{n?(t.$__once=!0,l.$once(e,t)):l.$on(e,t),_[e]?_[e].push(t):(_[e]=[t],$.$on(e,h))};Object.assign(g,$,{$on:e,$off:(e,t,n)=>{var r;if(_[e]){const n=_[e].indexOf(t);n>-1&&(_[e].splice(n,1),l.$off(e,t))}n&&delete _[e],(null==(r=_[e])?void 0:r.length)||($.$off(e,h),delete _[e])},$once:(t,n)=>{e(t,n,!0)}})}const A=c(a({},b),{bus:g,query:(e,t)=>p(null,null,function*(){const n=(null==e?void 0:e.reqid)||(yield b.genReqId());return new Promise((r,o)=>{b.query(c(a({},e),{reqid:n}),t).then(e=>{"succ"===(null==e?void 0:e.result)?r(e):o(e)})})}),createObservableQuery:(e,...t)=>p(null,[e,...t],function*(e,t={}){const n=(null==e?void 0:e.reqid)||(yield b.genReqId()),r=new re(v(n));return b.query(c(a({},e),{reqid:n}),c(a({},t),{observable:!0})),r})});b&&(window.removeEventListener(w.Message,f),d(),e({methods:A,config:n.data.config}))}};window.addEventListener(w.Message,f),(()=>{i("Child: Handshake - Sending SYN");const e={penpal:y.Syn},n=t instanceof RegExp?"*":t;window.parent.postMessage(e,n)})(),u(e=>{window.removeEventListener(w.Message,f),e&&r(e)})});return{promise:d,destroy(){l()}}};class se{constructor(){u(this,"options"),u(this,"flutterInAppWebView",null),u(this,"osConnector",null),u(this,"initPromise"),u(this,"isWeb",!0);let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,e.debug&&(d.setDebug(!0),d.log("Trim App initialized with debug mode")),d.log("Options:",e),this.initPromise=this.init()}init(){return p(this,null,function*(){return d.log("Starting initialization..."),new Promise(e=>{var t;f()?(this.isWeb=!1,d.log("Initializing mobile platform..."),new Promise(e=>{var t;h||(null==(t=window.flutter_inappwebview)?void 0:t._platformReady)?(d.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{d.log("flutter_inappwebview is ready"),e(window.flutter_inappwebview)})}).then(t=>{this.flutterInAppWebView=t,d.log("Mobile platform initialized"),e()})):(this.isWeb=!0,d.log("Initializing web platform..."),ie({debug:null==t?void 0:t.debug}).promise.then(t=>{this.osConnector=t,d.log("Web platform initialized"),e()}))})})}callAppMethod(e,t){return p(this,null,function*(){return this.flutterInAppWebView?((e,t,n)=>p(null,null,function*(){d.log(`callHandler: ${t}, params: ${n}`);const r=yield e.callHandler(t,n);if(r)try{const e=JSON.parse(r);d.log(`messageData: ${JSON.stringify(e)}`);const t=JSON.parse(e.result);return d.log(`appMessage: ${JSON.stringify(t)}`),t}catch(o){return d.error(`error: ${o}`),null}return null}))(this.flutterInAppWebView,e,t):null})}ready(){return p(this,null,function*(){return this.initPromise})}getOptions(){return this.options}setOptions(e){this.options=a(a({},this.options),e),void 0!==e.debug&&d.setDebug(e.debug),d.log("Options updated:",this.options)}getPlatformConfig(){return p(this,null,function*(){var e;if(yield this.initPromise,this.isWeb){const t=yield null==(e=this.osConnector)?void 0:e.methods.getPlatformConfig();if(!t)throw new Error("Failed to get platform config");return t}{const e=yield this.callAppMethod("getAppMessage");if(!e)throw new Error("Failed to get platform config");return{theme:e.nightMode,language:e.language,appVersion:e.appVersion,systemVersion:e.systemVersion,format:{date:e.dateFormat,time:e.timeFormat}}}})}setTitle(e){return p(this,null,function*(){var t;return yield this.initPromise,d.log("Setting title:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)})}setExitPageTips(e){return p(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")})}openFile(e){return p(this,null,function*(){var t;return yield this.initPromise,d.log("Opening file:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)})}openFileManager(e){return p(this,null,function*(){var t;return yield this.initPromise,d.log("Opening file manager:",e),this.isWeb?null==(t=this.osConnector)?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)})}close(){return p(this,null,function*(){var e;return yield this.initPromise,this.isWeb?null==(e=this.osConnector)?void 0:e.methods.close():this.callAppMethod("exitPage")})}query(e,t){return p(this,null,function*(){var n;if(yield this.initPromise,this.isWeb){const r=yield null==(n=this.osConnector)?void 0:n.methods.query(e,t);if(!r)throw new Error("Failed to query");return r}throw new Error("query is not supported on mobile platform")})}pickFile(e){return p(this,null,function*(){var t;return yield this.initPromise,this.isWeb?null==(t=this.osConnector)?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))})}}e.TrimApp=se,e.default=se,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trimjs/web-app",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "web app sdk for nas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -17,16 +17,17 @@
|
|
|
17
17
|
],
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@babel/preset-env": "^7.21.4",
|
|
20
|
-
"@microsoft/api-extractor": "^7.52.8",
|
|
21
|
-
"vite-plugin-dts": "^4.5.4",
|
|
22
20
|
"@eslint/js": "^9.13.0",
|
|
23
21
|
"@fn/micro-app-event": "workspace:*",
|
|
24
22
|
"@fn/micro-app-postmate": "workspace:*",
|
|
23
|
+
"@microsoft/api-extractor": "^7.52.8",
|
|
25
24
|
"@rollup/plugin-babel": "^6.1.0",
|
|
26
25
|
"eslint": "^9.13.0",
|
|
27
26
|
"globals": "^15.11.0",
|
|
27
|
+
"terser": "^5.46.0",
|
|
28
28
|
"typescript": "~5.6.2",
|
|
29
29
|
"typescript-eslint": "^8.11.0",
|
|
30
|
-
"vite": "^7.3.1"
|
|
30
|
+
"vite": "^7.3.1",
|
|
31
|
+
"vite-plugin-dts": "^4.5.4"
|
|
31
32
|
}
|
|
32
33
|
}
|