@kbapp/js-bridge 1.0.4-alpha.0 → 1.0.6-alpha.0

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.
Files changed (58) hide show
  1. package/{README.MD → README.md} +24 -24
  2. package/dist/es/core/index.js +73 -0
  3. package/dist/es/core/lib/flutter-ds-bridge.js +93 -0
  4. package/dist/es/index.js +59 -0
  5. package/dist/es/lib/app-version-support.js +18 -0
  6. package/dist/es/lib/bridge-code.js +22 -0
  7. package/dist/es/lib/check-for-new-version.js +14 -0
  8. package/dist/es/lib/close-webview.js +14 -0
  9. package/dist/es/lib/define-permission-usage.js +15 -0
  10. package/dist/es/lib/env.js +4 -0
  11. package/dist/es/lib/generate-kb-sign.js +15 -0
  12. package/dist/es/lib/get-app-base-info.js +18 -0
  13. package/dist/es/lib/open-post-editor.js +46 -0
  14. package/dist/es/lib/report-da-event.js +23 -0
  15. package/dist/es/lib/run-action.js +14 -0
  16. package/dist/es/lib/save-image-to-local.js +16 -0
  17. package/dist/es/lib/save-video-to-local.js +16 -0
  18. package/dist/es/lib/scan-qr-code.js +12 -0
  19. package/dist/es/lib/screen-orientation.js +16 -0
  20. package/dist/es/lib/set-webview-title.js +16 -0
  21. package/dist/es/lib/share-image.js +16 -0
  22. package/dist/es/lib/share-model.js +45 -0
  23. package/dist/es/lib/subscribe-notify.js +19 -0
  24. package/dist/es/lib/trigger-login.js +59 -0
  25. package/dist/es/utils/filter-undefined-properties.js +12 -0
  26. package/dist/es/utils/promise-cache.js +11 -0
  27. package/dist/es/utils/wrap-async.js +21 -0
  28. package/dist/{lib → types/lib}/open-post-editor.d.ts +1 -1
  29. package/dist/{index.umd.js → umd/index.js} +1 -1
  30. package/examples/index.html +2 -2
  31. package/package.json +13 -5
  32. package/dist/core/lib/flutter-ds-bridge.d.ts +0 -7
  33. package/dist/index.es.js +0 -519
  34. package/vite.config.ts +0 -32
  35. /package/dist/{core → types/core}/index.d.ts +0 -0
  36. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  37. /package/dist/{lib → types/lib}/app-version-support.d.ts +0 -0
  38. /package/dist/{lib → types/lib}/bridge-code.d.ts +0 -0
  39. /package/dist/{lib → types/lib}/check-for-new-version.d.ts +0 -0
  40. /package/dist/{lib → types/lib}/close-webview.d.ts +0 -0
  41. /package/dist/{lib → types/lib}/define-permission-usage.d.ts +0 -0
  42. /package/dist/{lib → types/lib}/env.d.ts +0 -0
  43. /package/dist/{lib → types/lib}/generate-kb-sign.d.ts +0 -0
  44. /package/dist/{lib → types/lib}/get-app-base-info.d.ts +0 -0
  45. /package/dist/{lib → types/lib}/report-da-event.d.ts +0 -0
  46. /package/dist/{lib → types/lib}/run-action.d.ts +0 -0
  47. /package/dist/{lib → types/lib}/save-image-to-local.d.ts +0 -0
  48. /package/dist/{lib → types/lib}/save-video-to-local.d.ts +0 -0
  49. /package/dist/{lib → types/lib}/scan-qr-code.d.ts +0 -0
  50. /package/dist/{lib → types/lib}/screen-orientation.d.ts +0 -0
  51. /package/dist/{lib → types/lib}/set-webview-title.d.ts +0 -0
  52. /package/dist/{lib → types/lib}/share-image.d.ts +0 -0
  53. /package/dist/{lib → types/lib}/share-model.d.ts +0 -0
  54. /package/dist/{lib → types/lib}/subscribe-notify.d.ts +0 -0
  55. /package/dist/{lib → types/lib}/trigger-login.d.ts +0 -0
  56. /package/dist/{utils → types/utils}/filter-undefined-properties.d.ts +0 -0
  57. /package/dist/{utils → types/utils}/promise-cache.d.ts +0 -0
  58. /package/dist/{utils → types/utils}/wrap-async.d.ts +0 -0
@@ -0,0 +1,19 @@
1
+ import { runBridgeApiResponse as t, runBridgeApi as p } from "../core/index.js";
2
+ import { wrapAsync as e } from "../utils/wrap-async.js";
3
+ const s = e(() => t({
4
+ name: "OpenActRequest",
5
+ params: {
6
+ type: 72
7
+ }
8
+ })), i = e(async () => {
9
+ p({
10
+ name: "OpenActRequest",
11
+ params: {
12
+ type: 73
13
+ }
14
+ });
15
+ });
16
+ export {
17
+ s as getAppSubscribeNotifyStatus,
18
+ i as openAppSubscribeNotifySettings
19
+ };
@@ -0,0 +1,59 @@
1
+ import { runBridgeApiResponse as c } from "../core/index.js";
2
+ import { wrapAsync as i } from "../utils/wrap-async.js";
3
+ class d {
4
+ }
5
+ const g = i(async () => (await c({
6
+ name: "OpenActRequest",
7
+ params: { type: 31, data: { requireLogin: !1 } }
8
+ })).data || null), r = /* @__PURE__ */ (() => {
9
+ const e = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ (() => {
10
+ let t;
11
+ const n = (o) => {
12
+ t = setTimeout(async () => {
13
+ const s = await g();
14
+ if (!s)
15
+ return n(++o);
16
+ e.forEach((p) => p(s)), e.clear();
17
+ }, ((s) => s === 0 ? 0 : s < 50 ? 600 : s < 80 ? 1e3 : 5e3)(o));
18
+ };
19
+ return {
20
+ start() {
21
+ t && clearTimeout(t), e.size > 0 && n(0);
22
+ },
23
+ stop() {
24
+ t && clearTimeout(t);
25
+ }
26
+ };
27
+ })();
28
+ return {
29
+ /** 注册监听事件(需要通过triggerCheckTask触发检测任务) */
30
+ addTask(t) {
31
+ e.add(t);
32
+ },
33
+ /** 移除监听 */
34
+ removeTask(t) {
35
+ e.delete(t), e.size === 0 && a.stop();
36
+ },
37
+ /** 触发定时检测是否登录成功任务 */
38
+ triggerCheckTask() {
39
+ a.start();
40
+ }
41
+ };
42
+ })(), l = i(async () => {
43
+ r.triggerCheckTask(), c({
44
+ name: "OpenActRequest",
45
+ params: { type: 31, data: { requireLogin: !0 } },
46
+ success(e) {
47
+ var a;
48
+ (a = e.data) != null && a.userId && r.triggerCheckTask();
49
+ }
50
+ });
51
+ }), m = (e) => (r.addTask(e), r.triggerCheckTask(), () => {
52
+ r.removeTask(e);
53
+ });
54
+ export {
55
+ d as AppLoginInfo,
56
+ g as getAppLoginInfo,
57
+ m as onLoopCheckAppLogin,
58
+ l as triggerAppLogin
59
+ };
@@ -0,0 +1,12 @@
1
+ function n(e) {
2
+ if (Object.prototype.toString.call(e) !== "[object Object]")
3
+ return e;
4
+ const r = {};
5
+ return Object.keys(e).forEach((c) => {
6
+ const t = e[c];
7
+ t != null && (r[c] = Object.prototype.toString.call(t) === "[object Object]" ? n(t) : t);
8
+ }), r;
9
+ }
10
+ export {
11
+ n as filterUndefinedAndNullProperties
12
+ };
@@ -0,0 +1,11 @@
1
+ function n(r) {
2
+ let e;
3
+ return function(...t) {
4
+ return e || (e = r(...t), Promise.resolve(e).catch(() => {
5
+ e = void 0;
6
+ }), e);
7
+ };
8
+ }
9
+ export {
10
+ n as decorateCacheAsyncResult
11
+ };
@@ -0,0 +1,21 @@
1
+ import { BridgeCode as s } from "../lib/bridge-code.js";
2
+ function w(a) {
3
+ return async function(...c) {
4
+ const i = c[0] || {}, { success: o, fail: t, complete: e, ...d } = i;
5
+ try {
6
+ const r = await Promise.resolve(a(d));
7
+ return o == null || o(r), r;
8
+ } catch (r) {
9
+ const n = r != null && r.errorCode ? r : new s({
10
+ errorCode: s.UNKNOWN.errorCode,
11
+ errorMsg: String(r)
12
+ });
13
+ throw t == null || t(n), n;
14
+ } finally {
15
+ e == null || e();
16
+ }
17
+ };
18
+ }
19
+ export {
20
+ w as wrapAsync
21
+ };
@@ -28,7 +28,7 @@ export declare class NoteThreadPostRule {
28
28
  *
29
29
  * @description 构造富文本编辑器参数
30
30
  */
31
- export declare function createPostEditorParamsByThreadPostRule(params?: Partial<NoteThreadPostRule> & {
31
+ export declare function generatePostEditorParamsByThreadPostRule(params?: Partial<NoteThreadPostRule> & {
32
32
  /** 文本输入框 低下显示的提示文案 */
33
33
  placeholder?: string;
34
34
  /** 初始化文本内容 */
@@ -1 +1 @@
1
- (function(r,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(r=typeof globalThis<"u"?globalThis:r||self,A(r.kbBridge={}))})(this,function(r){"use strict";var V;function A(e){if(Object.prototype.toString.call(e)!=="[object Object]")return e;const t={};return Object.keys(e).forEach(i=>{const s=e[i];s!=null&&(t[i]=Object.prototype.toString.call(s)==="[object Object]"?A(s):s)}),t}const p=class p{constructor(t){this.errorCode=t.errorCode,this.errorMsg=t.errorMsg}};p.UNKNOWN=new p({errorCode:1e3,errorMsg:"未知错误"}),p.UNSUPPORTED_VERSION=new p({errorCode:1001,errorMsg:"当前开吧版本不支持"}),p.TIMEOUT=new p({errorCode:1002,errorMsg:"执行超时"}),p.UNSUPPORTED_BRIDGE_ENV=new p({errorCode:1003,errorMsg:"请在开吧app内执行"});let f=p;const L=()=>{const e=(a,o,n)=>{var c="";typeof o=="function"&&(n=o,o={});var u={data:o===void 0?null:o};if(typeof n=="function"){var h="dscb"+window.dscb++;window[h]=n,u._dscbstub=h}if(u=JSON.stringify(u),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(c=window.flutter_inappwebview.callHandler(""+a,u)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(c=prompt("_flutterDsbridge="+a,u)),c instanceof Promise)return c;try{return JSON.parse(c||"{}").data}catch{console.error("callHandle异常,JSON.parse错误")}},t=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,i=(()=>{const a=[],o=setInterval(()=>{t()&&(clearInterval(o),a.forEach(n=>{e.apply(window,n)}),a.length=0)},500);return(...n)=>{a.push(n)}})();var s={default:void 0,callHandler:function(a,o,n){return t()?e(a,o,n):i(a,o,n)},register:function(a,o,n){var c=n?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){s.callHandler("_dsb.dsinit")},0)),typeof o=="object"?c._obs[a]=o:c[a]=o},registerHandler:function(a,o){this.register(a,o,!0)}};return function(){if(!window._dsf){var a={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:s,_handleMessageFromNative:function(n){var c=JSON.parse(n.data),u={id:n.callbackId,complete:!0},h=this._dsf[n.method],E=this._dsaf[n.method],C=function(P,b){u.data=P.apply(b,c),s.callHandler("_dsb.returnValue",u)},U=function(P,b){c.push(function(ge,he){u.data=ge,u.complete=he!==!1,s.callHandler("_dsb.returnValue",u)}),P.apply(b,c)};if(h)C(h,this._dsf);else if(E)U(E,this._dsaf);else{var O=n.method.split(".");if(O.length<2)return;var B=O.pop(),D=O.join("."),T=this._dsf._obs,v=T[D]||{},w=v[B];if(w&&typeof w=="function"){C(w,v);return}if(T=this._dsaf._obs,v=T[D]||{},w=v[B],w&&typeof w=="function"){U(w,v);return}}}};for(var o in a)window[o]=a[o]}}(),s},S=(e=>/(kb)/i.test(e)?L():{registerHandler(t,i){throw f.UNSUPPORTED_BRIDGE_ENV},callHandler(t,i,s){throw f.UNSUPPORTED_BRIDGE_ENV}})((V=window==null?void 0:window.navigator)==null?void 0:V.userAgent),R=e=>new Promise((t,i)=>{var s,a,o;try{S.registerHandler(e.name,e.handler),(s=e.success)==null||s.call(e),t()}catch(n){(a=e.fail)==null||a.call(e,n),i(n)}finally{(o=e.complete)==null||o.call(e)}});function g(e){const t=i=>{let s;const a=n=>{var c;(!s||s==="success")&&(s="success",(c=i.success)==null||c.call(i,n))},o=n=>{var c;(!s||s==="error")&&(s="error",(c=i.fail)==null||c.call(i,n))};i.timeout&&setTimeout(()=>{o(f.TIMEOUT)},i.timeout);try{S.callHandler(i.name,i.params,n=>{let c;try{typeof n=="string"&&/^\s*(\{|\[).*(\}|\])\s*$/.test(n)?c=JSON.parse(n.replace(/\n/g,"\\n").replace(/\r/g,"\\r")):c=n}catch{c=n}a(c)})}catch(n){o(n)}};return new Promise((i,s)=>{t({name:e.name,params:A(e.params),timeout:e.timeout,success:a=>{var o,n;(o=e.success)==null||o.call(e,a),(n=e.complete)==null||n.call(e),i(a)},fail:a=>{var o,n;(o=e.fail)==null||o.call(e,a),(n=e.complete)==null||n.call(e),s(a)}})})}function l(e){S.callHandler(e.name,e.params,t=>{})}function d(e){return async function(...i){const s=i[0]||{},{success:a,fail:o,complete:n,...c}=s;try{const u=await Promise.resolve(e(c));return a==null||a(u),u}catch(u){const h=u!=null&&u.errorCode?u:new f({errorCode:f.UNKNOWN.errorCode,errorMsg:String(u)});throw o==null||o(h),h}finally{n==null||n()}}}function H(e){let t;return function(...i){return t||(t=e(...i),Promise.resolve(t).catch(()=>{t=void 0}),t)}}class j{}const k=d(H(()=>g({name:"OpenActRequest",params:{type:35,data:{}}}))),m=d(async e=>(await k()).vcode>=e.minVersion);function F(e,t){return(...i)=>m({minVersion:e.minVersion}).then(s=>s?t(...i):Promise.reject(new f({errorCode:f.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}const W=d(()=>{l({name:"OpenActRequest",params:{type:56,data:null}})}),J=d(()=>{l({name:"OpenActRequest",params:{type:-1,data:{}}})}),I={microphone:{description:"用于发帖上传音频"},location:{description:"获取你选择的位置信息,用于线下导航服务"},camera:{description:"收集你选中的照片或视频信息 ,用于 发表评论、分享视频"}},Q=d(e=>(Object.assign(I,e),R({name:"getPermissionUsage",handler(t,i){i(I[t.permission])}}))),G=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent),K=d(async e=>{const{kbKey:t,...i}=e,{data:s}=await g({name:"OpenActRequest",params:{type:51,data:i}});return s});var N=(e=>(e[e.FREE=1]="FREE",e[e.FORBID=2]="FORBID",e[e.REQUIRED=3]="REQUIRED",e))(N||{});class M{constructor(){this.textMin=0,this.textMax=1e3,this.imageMax=9,this.imageMin=0,this.audioRqr=1,this.videoRqr=1,this.mediaRqr=2,this.streetRqr=1}}function $(e){const t=new M;return e&&Object.keys(e).forEach(i=>{t[i]=e[i]}),{hint:e==null?void 0:e.placeholder,initialText:e==null?void 0:e.initialText,audio:t.audioRqr!==2,image:t.imageMax!==0,video:t.videoRqr!==2,address:t.streetRqr!==2,asset_video:t.mediaRqr!==2,audio_must:t.audioRqr===3,image_must:t.imageMin>0,asset_video_must:t.mediaRqr===3,max_image_count:t.imageMax,min_image_count:t.imageMin,video_must:t.videoRqr===3,text_must:t.textMin>0,content_max_length:t.textMax,content_min_length:t.textMin}}const z=d(async e=>g({name:"OpenActRequest",params:{type:13,data:(e==null?void 0:e.postRule)??{}}}).then(({data:t})=>{const{pic:i,...s}=t;return{images:i,...s}})),X=d(e=>{l({name:"OpenActRequest",params:{type:69,data:{eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType}}})}),Y=d(e=>{l({name:"OpenActRequest",params:{type:1001,data:e}})}),Z=d(e=>{l({name:"OpenActRequest",params:{type:62,data:e}})}),x=d(e=>{l({name:"OpenActRequest",params:{type:63,data:e}})}),ee=d(()=>g({name:"OpenActRequest",params:{type:26,data:{}}})),te=d(e=>{l({name:"OpenActRequest",params:{type:71,data:e}})}),ne=d(e=>{l({name:"OpenActRequest",params:{type:64,data:e}})}),ie=d(e=>{l({name:"OpenActRequest",params:{type:58,data:e}})}),_="SHARE_EVENT_NAME";class re{}const oe=d(e=>R({name:"CommonShare",handler(t,i){window.dispatchEvent(new Event(_)),"onShareApp"in e&&e.onShareApp?i({type:12,data:e.onShareApp()}):i({type:12,data:e})}})),se=d(async e=>{window.dispatchEvent(new Event(_)),l({name:"OpenActRequest",params:{type:58,data:e}})});function ae(e){return window.addEventListener(_,e),()=>{window.removeEventListener(_,e)}}const ce=d(e=>{l({name:"OpenActRequest",params:{type:68,data:{show:e.showMenu,showActionMode:e.panelStyle||0}}})}),de=d(()=>g({name:"OpenActRequest",params:{type:72}})),ue=d(async()=>{l({name:"OpenActRequest",params:{type:73}})});class le{}const q=d(async()=>(await g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!1}}})).data||null),y=(()=>{const e=new Set,t=(()=>{let i;const s=a=>{i=setTimeout(async()=>{const n=await q();if(!n)return s(++a);e.forEach(c=>c(n)),e.clear()},(n=>n===0?0:n<50?600:n<80?1e3:5e3)(a))};return{start(){i&&clearTimeout(i),e.size>0&&s(0)},stop(){i&&clearTimeout(i)}}})();return{addTask(i){e.add(i)},removeTask(i){e.delete(i),e.size===0&&t.stop()},triggerCheckTask(){t.start()}}})(),fe=d(async()=>{y.triggerCheckTask(),g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!0}},success(e){var t;(t=e.data)!=null&&t.userId&&y.triggerCheckTask()}})}),pe=e=>(y.addTask(e),y.triggerCheckTask(),()=>{y.removeTask(e)});r.AppBaseInfo=j,r.AppLoginInfo=le,r.AppShareModel=re,r.BridgeCode=f,r.IS_KB_APP_ENV=G,r.KbRequirement=N,r.NoteThreadPostRule=M,r.checkForNewVersion=W,r.closeWebView=J,r.createPostEditorParamsByThreadPostRule=$,r.decorateAppVersionSupport=F,r.defineAppShareModel=oe,r.defineAppSharePanelState=ce,r.defineBridgeCallback=R,r.definePermissionUsage=Q,r.generateKBSign=K,r.getAppBaseInfo=k,r.getAppLoginInfo=q,r.getAppSubscribeNotifyStatus=de,r.isAppVersionSupport=m,r.onAppSharePanelShow=ae,r.onLoopCheckAppLogin=pe,r.openAppSharePanel=se,r.openAppSubscribeNotifySettings=ue,r.openPostEditor=z,r.reportDAEvent=X,r.runAction=Y,r.runBridgeApi=l,r.runBridgeApiResponse=g,r.saveImageToLocal=Z,r.saveVideoToLocal=x,r.scanQRCode=ee,r.setScreenOrientation=te,r.setWebViewTitle=ne,r.shareImage=ie,r.triggerAppLogin=fe,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
1
+ (function(r,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(r=typeof globalThis<"u"?globalThis:r||self,A(r.kbBridge={}))})(this,function(r){"use strict";var V;function A(e){if(Object.prototype.toString.call(e)!=="[object Object]")return e;const t={};return Object.keys(e).forEach(i=>{const s=e[i];s!=null&&(t[i]=Object.prototype.toString.call(s)==="[object Object]"?A(s):s)}),t}const p=class p{constructor(t){this.errorCode=t.errorCode,this.errorMsg=t.errorMsg}};p.UNKNOWN=new p({errorCode:1e3,errorMsg:"未知错误"}),p.UNSUPPORTED_VERSION=new p({errorCode:1001,errorMsg:"当前开吧版本不支持"}),p.TIMEOUT=new p({errorCode:1002,errorMsg:"执行超时"}),p.UNSUPPORTED_BRIDGE_ENV=new p({errorCode:1003,errorMsg:"请在开吧app内执行"});let f=p;const L=()=>{const e=(a,o,n)=>{var c="";typeof o=="function"&&(n=o,o={});var u={data:o===void 0?null:o};if(typeof n=="function"){var h="dscb"+window.dscb++;window[h]=n,u._dscbstub=h}if(u=JSON.stringify(u),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(c=window.flutter_inappwebview.callHandler(""+a,u)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(c=prompt("_flutterDsbridge="+a,u)),c instanceof Promise)return c;try{return JSON.parse(c||"{}").data}catch{console.error("callHandle异常,JSON.parse错误")}},t=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,i=(()=>{const a=[],o=setInterval(()=>{t()&&(clearInterval(o),a.forEach(n=>{e.apply(window,n)}),a.length=0)},500);return(...n)=>{a.push(n)}})();var s={default:void 0,callHandler:function(a,o,n){return t()?e(a,o,n):i(a,o,n)},register:function(a,o,n){var c=n?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){s.callHandler("_dsb.dsinit")},0)),typeof o=="object"?c._obs[a]=o:c[a]=o},registerHandler:function(a,o){this.register(a,o,!0)}};return function(){if(!window._dsf){var a={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:s,_handleMessageFromNative:function(n){var c=JSON.parse(n.data),u={id:n.callbackId,complete:!0},h=this._dsf[n.method],E=this._dsaf[n.method],C=function(P,b){u.data=P.apply(b,c),s.callHandler("_dsb.returnValue",u)},U=function(P,b){c.push(function(ge,he){u.data=ge,u.complete=he!==!1,s.callHandler("_dsb.returnValue",u)}),P.apply(b,c)};if(h)C(h,this._dsf);else if(E)U(E,this._dsaf);else{var O=n.method.split(".");if(O.length<2)return;var B=O.pop(),D=O.join("."),T=this._dsf._obs,v=T[D]||{},w=v[B];if(w&&typeof w=="function"){C(w,v);return}if(T=this._dsaf._obs,v=T[D]||{},w=v[B],w&&typeof w=="function"){U(w,v);return}}}};for(var o in a)window[o]=a[o]}}(),s},S=(e=>/(kb)/i.test(e)?L():{registerHandler(t,i){throw f.UNSUPPORTED_BRIDGE_ENV},callHandler(t,i,s){throw f.UNSUPPORTED_BRIDGE_ENV}})((V=window==null?void 0:window.navigator)==null?void 0:V.userAgent),R=e=>new Promise((t,i)=>{var s,a,o;try{S.registerHandler(e.name,e.handler),(s=e.success)==null||s.call(e),t()}catch(n){(a=e.fail)==null||a.call(e,n),i(n)}finally{(o=e.complete)==null||o.call(e)}});function g(e){const t=i=>{let s;const a=n=>{var c;(!s||s==="success")&&(s="success",(c=i.success)==null||c.call(i,n))},o=n=>{var c;(!s||s==="error")&&(s="error",(c=i.fail)==null||c.call(i,n))};i.timeout&&setTimeout(()=>{o(f.TIMEOUT)},i.timeout);try{S.callHandler(i.name,i.params,n=>{let c;try{typeof n=="string"&&/^\s*(\{|\[).*(\}|\])\s*$/.test(n)?c=JSON.parse(n.replace(/\n/g,"\\n").replace(/\r/g,"\\r")):c=n}catch{c=n}a(c)})}catch(n){o(n)}};return new Promise((i,s)=>{t({name:e.name,params:A(e.params),timeout:e.timeout,success:a=>{var o,n;(o=e.success)==null||o.call(e,a),(n=e.complete)==null||n.call(e),i(a)},fail:a=>{var o,n;(o=e.fail)==null||o.call(e,a),(n=e.complete)==null||n.call(e),s(a)}})})}function l(e){S.callHandler(e.name,e.params,t=>{})}function d(e){return async function(...i){const s=i[0]||{},{success:a,fail:o,complete:n,...c}=s;try{const u=await Promise.resolve(e(c));return a==null||a(u),u}catch(u){const h=u!=null&&u.errorCode?u:new f({errorCode:f.UNKNOWN.errorCode,errorMsg:String(u)});throw o==null||o(h),h}finally{n==null||n()}}}function H(e){let t;return function(...i){return t||(t=e(...i),Promise.resolve(t).catch(()=>{t=void 0}),t)}}class j{}const k=d(H(()=>g({name:"OpenActRequest",params:{type:35,data:{}}}))),m=d(async e=>(await k()).vcode>=e.minVersion);function F(e,t){return(...i)=>m({minVersion:e.minVersion}).then(s=>s?t(...i):Promise.reject(new f({errorCode:f.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}const W=d(()=>{l({name:"OpenActRequest",params:{type:56,data:null}})}),J=d(()=>{l({name:"OpenActRequest",params:{type:-1,data:{}}})}),I={microphone:{description:"用于发帖上传音频"},location:{description:"获取你选择的位置信息,用于线下导航服务"},camera:{description:"收集你选中的照片或视频信息 ,用于 发表评论、分享视频"}},Q=d(e=>(Object.assign(I,e),R({name:"getPermissionUsage",handler(t,i){i(I[t.permission])}}))),G=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent),K=d(async e=>{const{kbKey:t,...i}=e,{data:s}=await g({name:"OpenActRequest",params:{type:51,data:i}});return s});var N=(e=>(e[e.FREE=1]="FREE",e[e.FORBID=2]="FORBID",e[e.REQUIRED=3]="REQUIRED",e))(N||{});class M{constructor(){this.textMin=0,this.textMax=1e3,this.imageMax=9,this.imageMin=0,this.audioRqr=1,this.videoRqr=1,this.mediaRqr=2,this.streetRqr=1}}function $(e){const t=new M;return e&&Object.keys(e).forEach(i=>{t[i]=e[i]}),{hint:e==null?void 0:e.placeholder,initialText:e==null?void 0:e.initialText,audio:t.audioRqr!==2,image:t.imageMax!==0,video:t.videoRqr!==2,address:t.streetRqr!==2,asset_video:t.mediaRqr!==2,audio_must:t.audioRqr===3,image_must:t.imageMin>0,asset_video_must:t.mediaRqr===3,max_image_count:t.imageMax,min_image_count:t.imageMin,video_must:t.videoRqr===3,text_must:t.textMin>0,content_max_length:t.textMax,content_min_length:t.textMin}}const z=d(async e=>g({name:"OpenActRequest",params:{type:13,data:(e==null?void 0:e.postRule)??{}}}).then(({data:t})=>{const{pic:i,...s}=t;return{images:i,...s}})),X=d(e=>{l({name:"OpenActRequest",params:{type:69,data:{eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType}}})}),Y=d(e=>{l({name:"OpenActRequest",params:{type:1001,data:e}})}),Z=d(e=>{l({name:"OpenActRequest",params:{type:62,data:e}})}),x=d(e=>{l({name:"OpenActRequest",params:{type:63,data:e}})}),ee=d(()=>g({name:"OpenActRequest",params:{type:26,data:{}}})),te=d(e=>{l({name:"OpenActRequest",params:{type:71,data:e}})}),ne=d(e=>{l({name:"OpenActRequest",params:{type:64,data:e}})}),ie=d(e=>{l({name:"OpenActRequest",params:{type:58,data:e}})}),_="SHARE_EVENT_NAME";class re{}const oe=d(e=>R({name:"CommonShare",handler(t,i){window.dispatchEvent(new Event(_)),"onShareApp"in e&&e.onShareApp?i({type:12,data:e.onShareApp()}):i({type:12,data:e})}})),se=d(async e=>{window.dispatchEvent(new Event(_)),l({name:"OpenActRequest",params:{type:58,data:e}})});function ae(e){return window.addEventListener(_,e),()=>{window.removeEventListener(_,e)}}const ce=d(e=>{l({name:"OpenActRequest",params:{type:68,data:{show:e.showMenu,showActionMode:e.panelStyle||0}}})}),de=d(()=>g({name:"OpenActRequest",params:{type:72}})),ue=d(async()=>{l({name:"OpenActRequest",params:{type:73}})});class le{}const q=d(async()=>(await g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!1}}})).data||null),y=(()=>{const e=new Set,t=(()=>{let i;const s=a=>{i=setTimeout(async()=>{const n=await q();if(!n)return s(++a);e.forEach(c=>c(n)),e.clear()},(n=>n===0?0:n<50?600:n<80?1e3:5e3)(a))};return{start(){i&&clearTimeout(i),e.size>0&&s(0)},stop(){i&&clearTimeout(i)}}})();return{addTask(i){e.add(i)},removeTask(i){e.delete(i),e.size===0&&t.stop()},triggerCheckTask(){t.start()}}})(),fe=d(async()=>{y.triggerCheckTask(),g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!0}},success(e){var t;(t=e.data)!=null&&t.userId&&y.triggerCheckTask()}})}),pe=e=>(y.addTask(e),y.triggerCheckTask(),()=>{y.removeTask(e)});r.AppBaseInfo=j,r.AppLoginInfo=le,r.AppShareModel=re,r.BridgeCode=f,r.IS_KB_APP_ENV=G,r.KbRequirement=N,r.NoteThreadPostRule=M,r.checkForNewVersion=W,r.closeWebView=J,r.decorateAppVersionSupport=F,r.defineAppShareModel=oe,r.defineAppSharePanelState=ce,r.defineBridgeCallback=R,r.definePermissionUsage=Q,r.generateKBSign=K,r.generatePostEditorParamsByThreadPostRule=$,r.getAppBaseInfo=k,r.getAppLoginInfo=q,r.getAppSubscribeNotifyStatus=de,r.isAppVersionSupport=m,r.onAppSharePanelShow=ae,r.onLoopCheckAppLogin=pe,r.openAppSharePanel=se,r.openAppSubscribeNotifySettings=ue,r.openPostEditor=z,r.reportDAEvent=X,r.runAction=Y,r.runBridgeApi=l,r.runBridgeApiResponse=g,r.saveImageToLocal=Z,r.saveVideoToLocal=x,r.scanQRCode=ee,r.setScreenOrientation=te,r.setWebViewTitle=ne,r.shareImage=ie,r.triggerAppLogin=fe,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
@@ -81,9 +81,9 @@
81
81
  </body>
82
82
  <script type="module">
83
83
  import { createApp, ref, reactive } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
84
- import { runAction, defineAppShareModel, openAppSharePanel, reportDAEvent, getAppBaseInfo, shareImage, scanQRCode } from '../dist/index.es.js'
84
+ import { runAction, defineAppShareModel, openAppSharePanel, reportDAEvent, getAppBaseInfo, shareImage, scanQRCode } from '../dist/es/index.js'
85
85
 
86
- // import '../dist/index.umd.js'
86
+ // import '../dist/umd/index.js'
87
87
  // const { runAction, defineAppShareModel, openAppSharePanel, reportDAEvent, getAppBaseInfo, shareImage, scanQRCode } = window.kbBridge
88
88
 
89
89
  /**
package/package.json CHANGED
@@ -3,13 +3,21 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.4-alpha.0",
6
+ "version": "1.0.6-alpha.0",
7
7
  "description": "开吧客户端桥接",
8
8
  "author": "along",
9
- "type": "module",
10
- "main": "./dist/index.umd.js",
11
- "module": "./dist/index.es.js",
12
- "types": "./dist/index.d.ts",
9
+ "main": "./dist/umd/index.js",
10
+ "module": "./dist/es/index.js",
11
+ "types": "./dist/types/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/types/index.d.ts",
15
+ "import": "./dist/es/index.js",
16
+ "require": "./dist/umd/index.js"
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
20
+ "sideEffects": true,
13
21
  "scripts": {
14
22
  "build": "rm -rf ./dist && vite build",
15
23
  "dev": "npm run build && vite",
@@ -1,7 +0,0 @@
1
- declare function _default(): {
2
- default: undefined;
3
- callHandler: (method: any, args: any, cb: any) => any;
4
- register: (name: any, fun: any, asyn: any) => void;
5
- registerHandler: (name: any, fun: any) => void;
6
- };
7
- export default _default;