@trimjs/web-app 0.1.1 → 0.1.3
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 +545 -589
- package/dist/index.umd.cjs +2 -2
- package/package.json +1 -4
package/dist/index.umd.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(w,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(w=typeof globalThis<"u"?globalThis:w||self,v(w.TrimApp={}))})(this,function(w){"use strict";var rt=Object.defineProperty;var it=(w,v,l)=>v in w?rt(w,v,{enumerable:!0,configurable:!0,writable:!0,value:l}):w[v]=l;var P=(w,v,l)=>it(w,typeof v!="symbol"?v+"":v,l);class v{constructor(){P(this,"debug",!1)}setDebug(e){this.debug=e}isDebug(){return this.debug}log(...e){this.debug&&console.log("[Trim App]",...e)}warn(...e){this.debug&&console.warn("[Trim App]",...e)}error(...e){this.debug&&console.error("[Trim App]",...e)}info(...e){this.debug&&console.info("[Trim App]",...e)}}const l=new v;function ve(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 X=()=>ve(navigator.userAgent).fnAppVersion;let Z=!1;window.addEventListener("flutterInAppWebViewPlatformReady",()=>{Z=!0});const Ee=()=>new Promise(n=>{var e;Z||(e=window.flutter_inappwebview)!=null&&e._platformReady?(l.log("flutter_inappwebview is ready"),n(window.flutter_inappwebview)):window.addEventListener("flutterInAppWebViewPlatformReady",()=>{l.log("flutter_inappwebview is ready"),n(window.flutter_inappwebview)})}),Se=async(n,e,t)=>{l.log(`callHandler: ${e}, params: ${t}`);const r=await n.callHandler(e,t);if(r)try{const o=JSON.parse(r);l.log(`messageData: ${JSON.stringify(o)}`);const i=JSON.parse(o.result);return l.log(`appMessage: ${JSON.stringify(i)}`),i}catch(o){return l.error(`error: ${o}`),null}return null},ee=new Map;function Ae(){window.fnAppMessage=n=>{l.log("app-message",n);const e=JSON.parse(n),t=ee.get(e.reqId);t&&(t(e),ee.delete(e.reqId))}}X()&&Ae();var C=(n=>(n.Call="call",n.Reply="reply",n.Syn="syn",n.SynAck="synAck",n.Ack="ack",n))(C||{}),j=(n=>(n.Fulfilled="fulfilled",n.Rejected="rejected",n))(j||{}),U=(n=>(n.ConnectionDestroyed="ConnectionDestroyed",n.ConnectionTimeout="ConnectionTimeout",n.NoIframeSrc="NoIframeSrc",n))(U||{}),te=(n=>(n.DataCloneError="DataCloneError",n))(te||{}),D=(n=>(n.Message="message",n))(D||{});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)}}},Pe=n=>(...e)=>{n&&console.log("[Penpal]",...e)},ne=({name:n,message:e,stack:t})=>({name:n,message:e,stack:t}),Me=n=>{const e=new Error;return Object.keys(n).forEach(t=>e[t]=n[t]),e},_e=(n,e,t)=>{const{localName:r,local:o,remote:i,originForSending:s,originForReceiving:c}=n;let p=!1;const E=b=>{if(b.source!==i||b.data.penpal!==C.Call)return;if(c!=="*"&&b.origin!==c){t(`${r} received message from origin ${b.origin} which did not match expected origin ${c}`);return}const S=b.data,{methodName:g,args:d,id:m}=S;t(`${r}: Received ${g}() call`);const a=y=>$=>{if(t(`${r}: Sending ${g}() reply`),p){t(`${r}: Unable to send ${g}() reply due to destroyed connection`);return}const M={penpal:C.Reply,id:m,resolution:y,returnValue:$};y===j.Rejected&&$ instanceof Error&&(M.returnValue=ne($),M.returnValueIsError=!0);try{i.postMessage(M,s)}catch(F){if(F.name===te.DataCloneError){const O={penpal:C.Reply,id:m,resolution:j.Rejected,returnValue:ne(F),returnValueIsError:!0};i.postMessage(O,s)}throw F}};new Promise(y=>y(e[g].apply(e,d))).then(a(j.Fulfilled),a(j.Rejected))};return o.addEventListener(D.Message,E),()=>{p=!0,o.removeEventListener(D.Message,E)}};let Ce=0;const Te=()=>++Ce,re=".",ie=n=>n?n.split(re):[],Fe=n=>n.join(re),Oe=(n,e)=>{const t=ie(e||"");return t.push(n),Fe(t)},Re=(n,e,t)=>{const r=ie(e);return r.reduce((o,i,s)=>(typeof o[i]>"u"&&(o[i]={}),s===r.length-1&&(o[i]=t),o[i]),n),n},oe=(n,e)=>{const t={};return Object.keys(n).forEach(r=>{const o=n[r],i=Oe(r,e);typeof o=="object"&&Object.assign(t,oe(o,i)),typeof o=="function"&&(t[i]=o)}),t},xe=n=>{const e={};for(const t in n)Re(e,t,n[t]);return e},De=(n,e,t,r,o)=>{const{localName:i,local:s,remote:c,originForSending:p,originForReceiving:E}=e;let b=!1;o(`${i}: Connecting call sender`);const S=d=>(...m)=>{o(`${i}: Sending ${d}() call`);let a;try{c.closed&&(a=!0)}catch{a=!0}if(a&&r(),b){const y=new Error(`Unable to send ${d}() call due to destroyed connection`);throw y.code=U.ConnectionDestroyed,y}return new Promise((y,$)=>{const M=Te(),F=R=>{if(R.source!==c||R.data.penpal!==C.Reply||R.data.id!==M)return;if(E!=="*"&&R.origin!==E){o(`${i} received message from origin ${R.origin} which did not match expected origin ${E}`);return}const q=R.data;o(`${i}: Received ${d}() reply`),s.removeEventListener(D.Message,F);let N=q.returnValue;q.returnValueIsError&&(N=Me(N)),(q.resolution===j.Fulfilled?y:$)(N)};s.addEventListener(D.Message,F);const O={penpal:C.Call,id:M,methodName:d,args:m};c.postMessage(O,p)})},g=t.reduce((d,m)=>(d[m]=S(m),d),{});return Object.assign(n,xe(g)),()=>{b=!0}},Ie=(n,e)=>{let t;return n!==void 0&&(t=window.setTimeout(()=>{const r=new Error(`Connection timed out after ${n}ms`);r.code=U.ConnectionTimeout,e(r)},n)),()=>{clearTimeout(t)}},je={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"}},ke=(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 E=c.origin==="null"?"*":c.origin,b={penpal:C.Ack,methodNames:Object.keys(e),config:t};window.parent.postMessage(b,E);const S={localName:"Child",local:window,remote:window.parent,originForSending:E,originForReceiving:c.origin},g=_e(S,e,o);s(g);const d={},m=De(d,S,c.data.methodNames,i,o);return s(m),d}};function se(n,e){console==null||console.warn(`[fnApp warn]: ${n}`,e)}function ce(n,e){console==null||console.error(`[fnApp error]: ${n}`,e)}const k="_fn_all_event",ae="事件订阅数量为空",W=window.__POWERED_BY_FNAPP__?window.__FNAPP.inject.appEventObjMap:new Map;class le{constructor(e,t){P(this,"id");P(this,"appName");P(this,"eventObj");P(this,"getEventCallBackLength",e=>{var t;return((t=this.eventObj[e])==null?void 0:t.length)||0});this.id=e,this.appName=t,this.$clear(),W.get(this.id)||W.set(this.id,{}),this.eventObj=W.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(k,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 se(`${e} ${ae}`),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(k,e)}$emit(e,...t){return e=`${this.appName}/${e}`,this.$pureEmit(e,...t)}$pureEmit(e,...t){let r=0,o=0;return W.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){ce(p)}}if(i[k])for(let s=i[k].length-1;s>=0;s--){r++;const c=i[k][s];c.$__once&&i[k].splice(s,1);try{c(...t)}catch(p){ce(p)}}}),(!e||r===0&&o===0)&&se(`${e} ${ae}`),this}$clear(){const e=W.get(this.id)||{};return Object.keys(e).forEach(r=>delete e[r]),this}}var B=function(n,e){return B=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])},B(n,e)};function ue(n,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");B(n,e);function t(){this.constructor=n}n.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function fe(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 J(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 Y(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 T(n){return typeof n=="function"}function Ve(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 z=Ve(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),d=c.next();!d.done;d=c.next()){var A=d.value;A.remove(this)}}catch(l){e={error:l}}finally{try{d&&!d.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($),g=y.next();!g.done;g=y.next()){var b=g.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{g&&!g.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,d=s.source;i.add(c?c.call(i,d):d?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(d){i(d),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:d}=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 g=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={},x=f=>"api/"+f,Y={$emit:(f,...p)=>{P.getEventCallBackLength(f)>0?P.$pureEmit(f,...p):R==null||R.$off(f,()=>{},!0)},onQueryResult:f=>{C.$pureEmit(x(f.reqid),f)},onOsNotify:f=>{}},z=f=>function(w){const k=x(f);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),D={},G=W.bus;if(G){const f=(p,w,k)=>{k?(w.$__once=!0,P.$once(p,w)):P.$on(p,w),D[p]?D[p].push(w):(D[p]=[w],G.$on(p,O))};Object.assign(R,G,{$on:f,$off:(p,w,k)=>{var I;if(D[p]){const S=D[p].indexOf(w);S>-1&&(D[p].splice(S,1),P.$off(p,w))}k&&delete D[p],(I=D[p])!=null&&I.length||(G.$off(p,O),delete D[p])},$once:(p,w)=>{f(p,w,!0)}})}const ct=N(V({},W),{bus:R,query:(f,p)=>v(this,null,function*(){const w=(f==null?void 0:f.reqid)||(yield W.genReqId());return new Promise((k,I)=>{W.query(N(V({},f),{reqid:w}),p).then(S=>{(S==null?void 0:S.result)==="succ"?k(S):I(S)})})}),createObservableQuery:(w,...k)=>v(this,[w,...k],function*(f,p={}){const I=(f==null?void 0:f.reqid)||(yield W.genReqId()),S=new et(z(I));return W.query(N(V({},f),{reqid:I}),N(V({},p),{observable:!0})),S})});W&&(window.removeEventListener(j.Message,b),g(),$({methods:ct,config:l.data.config}))}};window.addEventListener(j.Message,b),A(),d(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))})}}h.TrimApp=_e,h.default=_e,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=t}});function pe(n,e){if(n){var t=n.indexOf(e);0<=t&&n.splice(t,1)}}var K=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=fe(s),p=c.next();!p.done;p=c.next()){var E=p.value;E.remove(this)}}catch(a){e={error:a}}finally{try{p&&!p.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else s.remove(this);var b=this.initialTeardown;if(T(b))try{b()}catch(a){i=a instanceof z?a.errors:[a]}var S=this._finalizers;if(S){this._finalizers=null;try{for(var g=fe(S),d=g.next();!d.done;d=g.next()){var m=d.value;try{he(m)}catch(a){i=i??[],a instanceof z?i=Y(Y([],J(i)),J(a.errors)):i.push(a)}}}catch(a){r={error:a}}finally{try{d&&!d.done&&(o=g.return)&&o.call(g)}finally{if(r)throw r.error}}}if(i)throw new z(i)}},n.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)he(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)&&pe(t,e)},n.prototype.remove=function(e){var t=this._finalizers;t&&pe(t,e),e instanceof n&&e._removeParent(this)},n.EMPTY=function(){var e=new n;return e.closed=!0,e}(),n}();K.EMPTY;function de(n){return n instanceof K||n&&"closed"in n&&T(n.remove)&&T(n.add)&&T(n.unsubscribe)}function he(n){T(n)?n():n.unsubscribe()}var ge={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},We={setTimeout:function(n,e){for(var t=[],r=2;r<arguments.length;r++)t[r-2]=arguments[r];return setTimeout.apply(void 0,Y([n,e],J(t)))},clearTimeout:function(n){return clearTimeout(n)},delegate:void 0};function qe(n){We.setTimeout(function(){throw n})}function ye(){}function Ne(n){n()}var me=function(n){ue(e,n);function e(t){var r=n.call(this)||this;return r.isStopped=!1,t?(r.destination=t,de(t)&&t.add(r)):r.destination=Be,r}return e.create=function(t,r,o){return new G(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}(K),Le=Function.prototype.bind;function Q(n,e){return Le.call(n,e)}var He=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){L(r)}},n.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(r){L(r)}else L(e)},n.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){L(t)}},n}(),G=function(n){ue(e,n);function e(t,r,o){var i=n.call(this)||this,s;if(T(t)||!t)s={next:t??void 0,error:r??void 0,complete:o??void 0};else{var c;i&&ge.useDeprecatedNextContext?(c=Object.create(t),c.unsubscribe=function(){return i.unsubscribe()},s={next:t.next&&Q(t.next,c),error:t.error&&Q(t.error,c),complete:t.complete&&Q(t.complete,c)}):s=t}return i.destination=new He(s),i}return e}(me);function L(n){qe(n)}function Ue(n){throw n}var Be={closed:!0,next:ye,error:Ue,complete:ye},Je=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Ye(n){return n}function ze(n){return n.length===0?Ye:n.length===1?n[0]:function(t){return n.reduce(function(r,o){return o(r)},t)}}var Ke=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=Ge(e)?e:new G(e,t,r);return Ne(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=be(t),new t(function(o,i){var s=new G({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[Je]=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=be(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 be(n){var e;return(e=n??ge.Promise)!==null&&e!==void 0?e:Promise}function Qe(n){return n&&T(n.next)&&T(n.error)&&T(n.complete)}function Ge(n){return n&&n instanceof me||Qe(n)&&de(n)}const Xe=()=>{try{clearTimeout(void 0)}catch{return!1}return!0},Ze=(n={})=>{const{parentOrigin:e="*",timeout:t,debug:r=!1,config:o={}}=n,i=Pe(r),s=$e("App",i),{destroy:c,onDestroy:p}=s,E=()=>{i("Child: Handshake - Sending SYN");const S={penpal:C.Syn},g=e instanceof RegExp?"*":e;window.parent.postMessage(S,g)};return{promise:new Promise((S,g)=>{const d=Ie(t,c),m=a=>{if(Xe()&&!(a.source!==parent||!a.data)&&a.data.penpal===C.SynAck){const y=a.data,$=new le(y.id,y.appName),M=new le(y.id+"/api",y.appName),F=y.id,O={},R=u=>"api/"+u,q={$emit:(u,...f)=>{$.getEventCallBackLength(u)>0?$.$pureEmit(u,...f):O==null||O.$off(u,()=>{},!0)},onQueryResult:u=>{M.$pureEmit(R(u.reqid),u)},onOsNotify:u=>{}},N=u=>function(h){const _=R(u);M.$on(_,function V(A){h.next(A),A.reqid&&A.result==="succ"&&(h.complete(),M.$off(_,V))})},tt=oe(q),I=ke(e,tt,{...o,postmateVersion:je.version},s,i)(a),x={},H=I.bus;if(H){const u=(f,h,_)=>{_?(h.$__once=!0,$.$once(f,h)):$.$on(f,h),x[f]?x[f].push(h):(x[f]=[h],H.$on(f,F))};Object.assign(O,H,{$on:u,$off:(f,h,_)=>{var V;if(x[f]){const A=x[f].indexOf(h);A>-1&&(x[f].splice(A,1),$.$off(f,h))}_&&delete x[f],(V=x[f])!=null&&V.length||(H.$off(f,F),delete x[f])},$once:(f,h)=>{u(f,h,!0)}})}const nt={...I,bus:O,query:async(u,f)=>{const h=(u==null?void 0:u.reqid)||await I.genReqId();return new Promise((_,V)=>{I.query({...u,reqid:h},f).then(A=>{(A==null?void 0:A.result)==="succ"?_(A):V(A)})})},createObservableQuery:async(u,f={})=>{const h=(u==null?void 0:u.reqid)||await I.genReqId(),_=new Ke(N(h));return I.query({...u,reqid:h},{...f,observable:!0}),_}};I&&(window.removeEventListener(D.Message,m),d(),S({methods:nt,config:a.data.config}))}};window.addEventListener(D.Message,m),E(),p(a=>{window.removeEventListener(D.Message,m),a&&g(a)})}),destroy(){c()}}},et=n=>Ze({debug:n==null?void 0:n.debug}).promise;class we{constructor(e={}){P(this,"options");P(this,"flutterInAppWebView",null);P(this,"osConnector",null);P(this,"initPromise");P(this,"isWeb",!0);this.options=e,e.debug&&(l.setDebug(!0),l.log("Trim App initialized with debug mode")),l.log("Options:",e),this.initPromise=this.init()}async init(){return l.log("Starting initialization..."),new Promise(e=>{X()?(this.isWeb=!1,l.log("Initializing mobile platform..."),Ee().then(t=>{this.flutterInAppWebView=t,l.log("Mobile platform initialized"),e()})):(this.isWeb=!0,l.log("Initializing web platform..."),et().then(t=>{this.osConnector=t,l.log("Web platform initialized"),e()}))})}async callAppMethod(e,t){return this.flutterInAppWebView?Se(this.flutterInAppWebView,e,t):null}async ready(){return this.initPromise}getOptions(){return this.options}setOptions(e){this.options={...this.options,...e},e.debug!==void 0&&l.setDebug(e.debug),l.log("Options updated:",this.options)}async getPlatformConfig(){var e;if(await this.initPromise,this.isWeb){const t=await((e=this.osConnector)==null?void 0:e.methods.getPlatformConfig());if(!t)throw new Error("Failed to get platform config");return t}else{const t=await 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}}}}async setTitle(e){var t;return await this.initPromise,l.log("Setting title:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.setTitle(e):this.callAppMethod("updateTitle",e)}async setExitPageTips(e){var t;return await this.initPromise,this.isWeb?(t=this.osConnector)==null?void 0:t.methods.setExitPageTips(e):this.callAppMethod("setExitPageTips",e?JSON.stringify(e):"")}async openFile(e){var t;return await this.initPromise,l.log("Opening file:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.openFile(e):this.callAppMethod("openFile",e)}async openFileManager(e){var t;return await this.initPromise,l.log("Opening file manager:",e),this.isWeb?(t=this.osConnector)==null?void 0:t.methods.openFileManagerApp(e):this.callAppMethod("openFileManager",e)}async close(){var e;return await this.initPromise,this.isWeb?(e=this.osConnector)==null?void 0:e.methods.close():this.callAppMethod("exitPage")}async query(e,t){var r;if(await this.initPromise,this.isWeb){const o=await((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")}async pickFile(e){var t;return await this.initPromise,this.isWeb?(t=this.osConnector)==null?void 0:t.methods.pickFile(e):this.callAppMethod("openFolder",JSON.stringify(e))}}w.TrimApp=we,w.default=we,Object.defineProperties(w,{__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.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "web app sdk for nas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -16,9 +16,6 @@
|
|
|
16
16
|
"src",
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
-
"publishConfig": {
|
|
20
|
-
"access": "public"
|
|
21
|
-
},
|
|
22
19
|
"devDependencies": {
|
|
23
20
|
"@fn/micro-app-postmate": "workspace:*",
|
|
24
21
|
"@fn/micro-app-event": "workspace:*",
|