@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.umd.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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 at=Object.defineProperty,lt=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var Ce=Object.getOwnPropertySymbols;var ft=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable;var ae=(h,u,a)=>u in h?at(h,u,{enumerable:!0,configurable:!0,writable:!0,value:a}):h[u]=a,V=(h,u)=>{for(var a in u||(u={}))ft.call(u,a)&&ae(h,a,u[a]);if(Ce)for(var a of Ce(u))pt.call(u,a)&&ae(h,a,u[a]);return h},N=(h,u)=>lt(h,ut(u));var M=(h,u,a)=>ae(h,typeof u!="symbol"?u+"":u,a);var v=(h,u,a)=>new Promise((X,H)=>{var K=_=>{try{U(a.next(_))}catch(B){H(B)}},Z=_=>{try{U(a.throw(_))}catch(B){H(B)}},U=_=>_.done?X(_.value):Promise.resolve(_.value).then(K,Z);U((a=a.apply(h,u)).next())});class u{constructor(){M(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 a=new u;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 H=()=>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}),_=new Map;function B(){window.fnAppMessage=n=>{a.log("app-message",n);const e=JSON.parse(n),t=_.get(e.reqId);t&&(t(e),_.delete(e.reqId))}}H()&&B();var T=(n=>(n.Call="call",n.Reply="reply",n.Syn="syn",n.SynAck="synAck",n.Ack="ack",n))(T||{}),q=(n=>(n.Fulfilled="fulfilled",n.Rejected="rejected",n))(q||{}),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 Te=(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 d=!1;const A=E=>{if(E.source!==i||E.data.penpal!==T.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:g,id:b}=$;t(`${r}: Received ${y}() call`);const l=m=>P=>{if(t(`${r}: Sending ${y}() reply`),d){t(`${r}: Unable to send ${y}() reply due to destroyed connection`);return}const C={penpal:T.Reply,id:b,resolution:m,returnValue:P};m===q.Rejected&&P instanceof Error&&(C.returnValue=ue(P),C.returnValueIsError=!0);try{i.postMessage(C,s)}catch(O){if(O.name===le.DataCloneError){const R={penpal:T.Reply,id:b,resolution:q.Rejected,returnValue:ue(O),returnValueIsError:!0};i.postMessage(R,s)}throw O}};new Promise(m=>m(e[y].apply(e,g))).then(l(q.Fulfilled),l(q.Rejected))};return o.addEventListener(j.Message,A),()=>{d=!0,o.removeEventListener(j.Message,A)}};let xe=0;const De=()=>++xe,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)},ke=(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},Ve=n=>{const e={};for(const t in n)ke(e,t,n[t]);return e},We=(n,e,t,r,o)=>{const{localName:i,local:s,remote:c,originForSending:d,originForReceiving:A}=e;let E=!1;o(`${i}: Connecting call sender`);const $=g=>(...b)=>{o(`${i}: Sending ${g}() call`);let l;try{c.closed&&(l=!0)}catch(m){l=!0}if(l&&r(),E){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 C=De(),O=x=>{if(x.source!==c||x.data.penpal!==T.Reply||x.data.id!==C)return;if(A!=="*"&&x.origin!==A){o(`${i} received message from origin ${x.origin} which did not match expected origin ${A}`);return}const Y=x.data;o(`${i}: Received ${g}() reply`),s.removeEventListener(j.Message,O);let z=Y.returnValue;Y.returnValueIsError&&(z=Oe(z)),(Y.resolution===q.Fulfilled?m:P)(z)};s.addEventListener(j.Message,O);const R={penpal:T.Call,id:C,methodName:g,args:b};c.postMessage(R,d)})},y=t.reduce((g,b)=>(g[b]=$(b),g),{});return Object.assign(n,Ve(y)),()=>{E=!0}},qe=(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"}},Ne=(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 A=c.origin==="null"?"*":c.origin,E={penpal:T.Ack,methodNames:Object.keys(e),config:t};window.parent.postMessage(E,A);const $={localName:"Child",local:window,remote:window.parent,originForSending:A,originForReceiving:c.origin},y=Re($,e,o);s(y);const g={},b=We(g,$,c.data.methodNames,i,o);return s(b),g}};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});console.log("id",e,t),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(d){ge(d)}}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(d){ge(d)}}}),(!e||r===0&&o===0)&&he(`${e} ${ye}`),this}$clear(){var r;const e=(r=J.get(this.id))!=null?r:{};return Object.keys(e).forEach(o=>delete e[o]),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 He(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=He(function(n){return function(t){n(this),this.message=t?t.length+` errors occurred during unsubscription:
|
|
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 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=(h,u,a)=>u in h?at(h,u,{enumerable:!0,configurable:!0,writable:!0,value:a}):h[u]=a,W=(h,u)=>{for(var a in u||(u={}))ft.call(u,a)&&ae(h,a,u[a]);if(Te)for(var a of Te(u))pt.call(u,a)&&ae(h,a,u[a]);return h},H=(h,u)=>lt(h,ut(u));var M=(h,u,a)=>ae(h,typeof u!="symbol"?u+"":u,a);var v=(h,u,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(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),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 u;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 d=!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:g,id:b}=$;t(`${r}: Received ${y}() call`);const l=m=>P=>{if(t(`${r}: Sending ${y}() reply`),d){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,g))).then(l(N.Fulfilled),l(N.Rejected))};return o.addEventListener(j.Message,S),()=>{d=!0,o.removeEventListener(j.Message,S)}};let xe=0;const De=()=>++xe,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:d,originForReceiving:S}=e;let E=!1;o(`${i}: Connecting call sender`);const $=g=>(...b)=>{o(`${i}: Sending ${g}() call`);let l;try{c.closed&&(l=!0)}catch(m){l=!0}if(l&&r(),E){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=De(),O=x=>{if(x.source!==c||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(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:g,args:b};c.postMessage(R,d)})},y=t.reduce((g,b)=>(g[b]=$(b),g),{});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 g={},b=qe(g,$,c.data.methodNames,i,o);return s(b),g}};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(d){ge(d)}}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(d){ge(d)}}}),(!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),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 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 S=d.value;S.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{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{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)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,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: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: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=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={},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 V=x(f);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),D={},G=q.bus;if(G){const f=(p,w,V)=>{V?(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,V)=>{var I;if(D[p]){const A=D[p].indexOf(w);A>-1&&(D[p].splice(A,1),P.$off(p,w))}V&&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=H(W({},q),{bus:R,query:(f,p)=>v(this,null,function*(){const w=(f==null?void 0:f.reqid)||(yield q.genReqId());return new Promise((V,I)=>{q.query(H(W({},f),{reqid:w}),p).then(A=>{(A==null?void 0:A.result)==="succ"?V(A):I(A)})})}),createObservableQuery:(w,...V)=>v(this,[w,...V],function*(f,p={}){const I=(f==null?void 0:f.reqid)||(yield q.genReqId()),A=new et(z(I));return q.query(H(W({},f),{reqid:I}),H(W({},p),{observable:!0})),A})});q&&(window.removeEventListener(j.Message,b),g(),$({methods:ct,config:l.data.config}))}};window.addEventListener(j.Message,b),S(),d(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))})}}h.TrimApp=Ce,h.default=Ce,Object.defineProperties(h,{__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.4",
|
|
4
4
|
"description": "web app sdk for nas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "vite",
|
|
11
|
-
"build": "
|
|
11
|
+
"build": "tsc -b && vite build",
|
|
12
12
|
"lint": "eslint .",
|
|
13
13
|
"typecheck": "tsc --noEmit"
|
|
14
14
|
},
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
"src",
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
-
"publishConfig": {
|
|
20
|
-
"access": "public"
|
|
21
|
-
},
|
|
22
19
|
"devDependencies": {
|
|
20
|
+
"@babel/preset-env": "^7.21.4",
|
|
23
21
|
"@eslint/js": "^9.13.0",
|
|
24
22
|
"@fn/micro-app-event": "workspace:*",
|
|
25
23
|
"@fn/micro-app-postmate": "workspace:*",
|
|
24
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
26
25
|
"eslint": "^9.13.0",
|
|
27
26
|
"globals": "^15.11.0",
|
|
27
|
+
"rollup": "^4.24.0",
|
|
28
28
|
"typescript": "~5.6.2",
|
|
29
29
|
"typescript-eslint": "^8.11.0",
|
|
30
30
|
"vite": "^5.4.10"
|
package/dist/index.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { PlatformConfig, TrimAppOptions } from "./types";
|
|
2
|
-
import { type ResponseData } from "@fn/micro-app-postmate/src/child/os-type";
|
|
3
|
-
import { type FilePickerParams, type QueryConfig } from "@fn/micro-app-postmate/src/child/type";
|
|
4
|
-
/**
|
|
5
|
-
* @trim/app - NAS 应用 SDK
|
|
6
|
-
* @description nas 应用 SDK
|
|
7
|
-
*/
|
|
8
|
-
export type { TrimAppOptions } from "./types";
|
|
9
|
-
/**
|
|
10
|
-
* Trim App 实例类
|
|
11
|
-
*/
|
|
12
|
-
export declare class TrimApp {
|
|
13
|
-
private options;
|
|
14
|
-
private flutterInAppWebView;
|
|
15
|
-
private osConnector;
|
|
16
|
-
private initPromise;
|
|
17
|
-
isWeb: boolean;
|
|
18
|
-
constructor(options?: TrimAppOptions);
|
|
19
|
-
private init;
|
|
20
|
-
callAppMethod<T>(fn: string, params?: string): Promise<T | null>;
|
|
21
|
-
/**
|
|
22
|
-
* 等待初始化完成
|
|
23
|
-
* @returns Promise
|
|
24
|
-
*/
|
|
25
|
-
ready(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* 获取配置
|
|
28
|
-
*/
|
|
29
|
-
getOptions(): TrimAppOptions;
|
|
30
|
-
/**
|
|
31
|
-
* 更新配置
|
|
32
|
-
*/
|
|
33
|
-
setOptions(options: Partial<TrimAppOptions>): void;
|
|
34
|
-
/**
|
|
35
|
-
* 获取平台配置
|
|
36
|
-
*/
|
|
37
|
-
getPlatformConfig(): Promise<PlatformConfig>;
|
|
38
|
-
/**
|
|
39
|
-
* setTitle - 设置标题
|
|
40
|
-
* @param title 标题文本
|
|
41
|
-
*/
|
|
42
|
-
setTitle(title: string): Promise<unknown>;
|
|
43
|
-
/**
|
|
44
|
-
* setExitPageTips - 设置退出页面提示
|
|
45
|
-
* @param params 提示参数
|
|
46
|
-
*/
|
|
47
|
-
setExitPageTips(params?: {
|
|
48
|
-
title?: string;
|
|
49
|
-
content?: string;
|
|
50
|
-
}): Promise<unknown>;
|
|
51
|
-
/**
|
|
52
|
-
* 通过应用打开某个文件
|
|
53
|
-
*/
|
|
54
|
-
openFile(path: string): Promise<unknown>;
|
|
55
|
-
/**
|
|
56
|
-
* 打开文件管理器
|
|
57
|
-
*/
|
|
58
|
-
openFileManager(path: string): Promise<unknown>;
|
|
59
|
-
/**
|
|
60
|
-
* 关闭应用
|
|
61
|
-
*/
|
|
62
|
-
close(): Promise<unknown>;
|
|
63
|
-
/**
|
|
64
|
-
* 请求接口
|
|
65
|
-
*/
|
|
66
|
-
query<T>(params: any, config?: QueryConfig): Promise<ResponseData<T>>;
|
|
67
|
-
/**
|
|
68
|
-
* 选择文件
|
|
69
|
-
*/
|
|
70
|
-
pickFile(params: FilePickerParams): Promise<unknown>;
|
|
71
|
-
}
|
|
72
|
-
export default TrimApp;
|
package/dist/logger.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logger 工具类
|
|
3
|
-
* 只有在 debug 模式下才会输出日志
|
|
4
|
-
*/
|
|
5
|
-
declare class Logger {
|
|
6
|
-
private debug;
|
|
7
|
-
/**
|
|
8
|
-
* 设置 debug 模式
|
|
9
|
-
* @param enabled 是否启用 debug
|
|
10
|
-
*/
|
|
11
|
-
setDebug(enabled: boolean): void;
|
|
12
|
-
/**
|
|
13
|
-
* 获取当前 debug 状态
|
|
14
|
-
*/
|
|
15
|
-
isDebug(): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* 输出日志(只在 debug 模式下)
|
|
18
|
-
* @param args 日志参数
|
|
19
|
-
*/
|
|
20
|
-
log(...args: any[]): void;
|
|
21
|
-
/**
|
|
22
|
-
* 输出警告日志(只在 debug 模式下)
|
|
23
|
-
* @param args 日志参数
|
|
24
|
-
*/
|
|
25
|
-
warn(...args: any[]): void;
|
|
26
|
-
/**
|
|
27
|
-
* 输出错误日志(只在 debug 模式下)
|
|
28
|
-
* @param args 日志参数
|
|
29
|
-
*/
|
|
30
|
-
error(...args: any[]): void;
|
|
31
|
-
/**
|
|
32
|
-
* 输出信息日志(只在 debug 模式下)
|
|
33
|
-
* @param args 日志参数
|
|
34
|
-
*/
|
|
35
|
-
info(...args: any[]): void;
|
|
36
|
-
}
|
|
37
|
-
export declare const logger: Logger;
|
|
38
|
-
export {};
|
package/dist/mobile/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface FlutterInAppWebView {
|
|
2
|
-
callHandler: (fn: string, params?: string) => Promise<string>;
|
|
3
|
-
_platformReady?: boolean;
|
|
4
|
-
}
|
|
5
|
-
declare global {
|
|
6
|
-
interface Window {
|
|
7
|
-
flutter_inappwebview: FlutterInAppWebView;
|
|
8
|
-
fnAppMessage?: (message: string) => void;
|
|
9
|
-
onAppHeaderGoBack?: () => boolean | number | string;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export declare const initMobile: () => Promise<FlutterInAppWebView>;
|
|
13
|
-
export interface FnAppMessage<T> {
|
|
14
|
-
reqId: string;
|
|
15
|
-
method: string;
|
|
16
|
-
result: T;
|
|
17
|
-
}
|
|
18
|
-
export declare const callHandler: <T>(flutterInAppWebView: FlutterInAppWebView, fn: string, params?: string) => Promise<T | null>;
|
|
19
|
-
export declare function pickFilePromise(flutterInAppWebView: FlutterInAppWebView, params: {
|
|
20
|
-
title: string;
|
|
21
|
-
multiple: boolean;
|
|
22
|
-
directory: boolean;
|
|
23
|
-
}): Promise<string[] | undefined>;
|
package/dist/mobile/types.d.ts
DELETED
package/dist/types.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK 配置选项
|
|
3
|
-
*/
|
|
4
|
-
export interface TrimAppOptions {
|
|
5
|
-
/** 是否开启 debug 模式,开启后会输出日志 */
|
|
6
|
-
debug?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface PlatformConfig {
|
|
9
|
-
theme: "dark" | "light";
|
|
10
|
-
language: string;
|
|
11
|
-
appVersion?: string;
|
|
12
|
-
systemVersion: string;
|
|
13
|
-
format: {
|
|
14
|
-
date?: string;
|
|
15
|
-
time?: string;
|
|
16
|
-
};
|
|
17
|
-
}
|
package/dist/utils/platform.d.ts
DELETED
package/dist/web/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type OSConfig } from "@fn/micro-app-postmate/src/parent/type";
|
|
2
|
-
import { type OSMethods, type ConnectionResult, type AsyncMethodReturns } from "@fn/micro-app-postmate/src/types";
|
|
3
|
-
import type { PlatformConfig, TrimAppOptions } from "../types";
|
|
4
|
-
export type OSConnection = AsyncMethodReturns<ConnectionResult<OSMethods & {
|
|
5
|
-
setExitPageTips: (params?: {
|
|
6
|
-
title?: string;
|
|
7
|
-
content?: string;
|
|
8
|
-
}) => void;
|
|
9
|
-
openFileManagerApp: (path: string) => void;
|
|
10
|
-
openFile: (path: string) => void;
|
|
11
|
-
getPlatformConfig: () => Promise<PlatformConfig>;
|
|
12
|
-
close: () => void;
|
|
13
|
-
}, OSConfig>>;
|
|
14
|
-
export declare const initWeb: (options?: TrimAppOptions) => Promise<AsyncMethodReturns<ConnectionResult<OSMethods>>>;
|