@kbapp/js-bridge 0.4.8-alpha.0 → 1.0.0-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 (60) hide show
  1. package/LOGIN.MD +79 -0
  2. package/README.MD +1045 -182
  3. package/dist/core/index.d.ts +68 -16
  4. package/dist/index.d.ts +8 -5
  5. package/dist/index.es.js +516 -0
  6. package/dist/index.umd.js +1 -0
  7. package/dist/lib/app-version-support.d.ts +41 -0
  8. package/dist/lib/bridge-code.d.ts +14 -0
  9. package/dist/lib/check-for-new-version.d.ts +7 -5
  10. package/dist/lib/close-webview.d.ts +6 -2
  11. package/dist/lib/define-permission-usage.d.ts +8 -2
  12. package/dist/lib/generate-kb-sign.d.ts +13 -2
  13. package/dist/lib/{get-device-info.d.ts → get-app-base-info.d.ts} +14 -7
  14. package/dist/lib/open-post-editor.d.ts +47 -4
  15. package/dist/lib/report-da-event.d.ts +33 -0
  16. package/dist/lib/run-action.d.ts +9 -5
  17. package/dist/lib/save-image-to-local.d.ts +8 -4
  18. package/dist/lib/save-video-to-local.d.ts +7 -3
  19. package/dist/lib/scan-qr-code.d.ts +23 -0
  20. package/dist/lib/screen-orientation.d.ts +13 -0
  21. package/dist/lib/set-webview-title.d.ts +7 -3
  22. package/dist/lib/share-image.d.ts +21 -0
  23. package/dist/lib/share-model.d.ts +170 -45
  24. package/dist/lib/subscribe-notify.d.ts +25 -0
  25. package/dist/lib/trigger-login.d.ts +18 -10
  26. package/dist/utils/filter-undefined-properties.d.ts +6 -0
  27. package/dist/utils/promise-cache.d.ts +5 -0
  28. package/dist/utils/wrap-async.d.ts +17 -0
  29. package/examples/index.html +236 -0
  30. package/package.json +17 -4
  31. package/vite.config.ts +32 -0
  32. package/dist/core/index.js +0 -84
  33. package/dist/core/lib/ds-bridge.d.ts +0 -7
  34. package/dist/core/lib/ds-bridge.js +0 -126
  35. package/dist/core/lib/flutter-ds-bridge.js +0 -172
  36. package/dist/core/lib/js-bridge.d.ts +0 -22
  37. package/dist/core/lib/js-bridge.js +0 -188
  38. package/dist/index.js +0 -33
  39. package/dist/lib/can-i-use.d.ts +0 -13
  40. package/dist/lib/can-i-use.js +0 -102
  41. package/dist/lib/check-for-new-version.js +0 -26
  42. package/dist/lib/close-webview.js +0 -24
  43. package/dist/lib/define-permission-usage.js +0 -40
  44. package/dist/lib/generate-kb-sign.js +0 -75
  45. package/dist/lib/get-device-info.js +0 -36
  46. package/dist/lib/js-bridge-code.d.ts +0 -10
  47. package/dist/lib/js-bridge-code.js +0 -14
  48. package/dist/lib/open-post-editor.js +0 -116
  49. package/dist/lib/report-getui.d.ts +0 -14
  50. package/dist/lib/report-getui.js +0 -17
  51. package/dist/lib/run-action.js +0 -29
  52. package/dist/lib/save-image-to-local.js +0 -28
  53. package/dist/lib/save-video-to-local.js +0 -28
  54. package/dist/lib/set-webview-title.js +0 -27
  55. package/dist/lib/share-model.js +0 -80
  56. package/dist/lib/share-poster.d.ts +0 -16
  57. package/dist/lib/share-poster.js +0 -26
  58. package/dist/lib/trigger-login.js +0 -195
  59. package/dist/util/promise-cache.d.ts +0 -5
  60. package/dist/util/promise-cache.js +0 -24
@@ -1,17 +1,67 @@
1
+ import { BridgeCode } from '../lib/bridge-code';
2
+
1
3
  /**
2
4
  *
3
- * @description 注册事件 提供给native端调用
5
+ * @description 注册 提供给native端调用
6
+ *
7
+ * **示例代码**
8
+ ```js
9
+ import { defineBridgeCallback } from '@kbapp/market-partner-sdk';
10
+
11
+ defineBridgeCallback({
12
+ name: 'CommonShare',
13
+ handler() {
14
+ },
15
+ })
16
+ ```
4
17
  */
5
- export declare const registerHandler: <Data = unknown>(
6
- /** 任务名称 */
7
- name: string,
8
- /** 回调函数 */
9
- cb: (data: Data, cb: (data: Record<string, any>) => void) => void) => void;
18
+ export declare const defineBridgeCallback: (params: {
19
+ /** 任务名称 */
20
+ name: string;
21
+ /** 回调函数 */
22
+ handler: (...params: any[]) => any;
23
+ /** 注册函数成功 */
24
+ success?: () => void;
25
+ /** 注册函数失败 */
26
+ fail?: (error: BridgeCode) => void;
27
+ complete?: () => void;
28
+ }) => Promise<void>;
10
29
  /**
11
30
  *
12
- * @description 主动触发 触发native端任务
31
+ * @description 执行app桥接方法(等待响应)
32
+ *
33
+ * **示例代码**
34
+ ```js
35
+ import { runBridgeApi } from '@kbapp/market-partner-sdk';
36
+
37
+ runBridgeApi({
38
+ name: 'OpenActRequest',
39
+ params: {
40
+ type: 60001,
41
+ data: {},
42
+ },
43
+ success(result: Result) {
44
+ console.log(result)
45
+ },
46
+ fail(error: BridgeCode) {
47
+ console.error(error)
48
+ }
49
+ })
50
+
51
+ runBridgeApi({
52
+ name: 'OpenActRequest',
53
+ params: {
54
+ type: 60001,
55
+ data: {},
56
+ },
57
+ }).then((result: Result) => {
58
+ console.log(result)
59
+ }).catch((error: BridgeCode) => {
60
+ console.error(error)
61
+ })
62
+ ```
13
63
  */
14
- export declare const callHandler: <Result = void>(data: {
64
+ export declare function runBridgeApiResponse<Result = void>(params: {
15
65
  /** 任务名称 */
16
66
  name: string;
17
67
  /** 任务参数 */
@@ -19,18 +69,20 @@ export declare const callHandler: <Result = void>(data: {
19
69
  type: number;
20
70
  data?: any;
21
71
  };
22
- /** 表示 任务执行成功.有且当该任务有回调时触发, */
72
+ /** 设置超时时间 */
73
+ timeout?: number;
74
+ /** 执行成功 */
23
75
  success?: (result: Result) => void;
24
- /** 任务执行失败.有且当该任务有回调时触发 */
25
- fail?: (result: any) => void;
26
- /** 成功或失败均触发.有且当该任务有回调时触发 */
76
+ /** 执行失败 */
77
+ fail?: (error: BridgeCode) => void;
78
+ /** 同时触发 */
27
79
  complete?: () => void;
28
- }) => void;
80
+ }): Promise<Result>;
29
81
  /**
30
82
  *
31
- * @description promise版本 callHandle
83
+ * @description 执行app桥接方法(无响应)
32
84
  */
33
- export declare function callHandlerPromise<Result>(data: {
85
+ export declare function runBridgeApi(params: {
34
86
  /** 任务名称 */
35
87
  name: string;
36
88
  /** 任务参数 */
@@ -38,4 +90,4 @@ export declare function callHandlerPromise<Result>(data: {
38
90
  type: number;
39
91
  data?: any;
40
92
  };
41
- }): Promise<Result>;
93
+ }): void;
package/dist/index.d.ts CHANGED
@@ -1,17 +1,20 @@
1
1
  export * from './core';
2
- export * from './lib/can-i-use';
2
+ export * from './lib/app-version-support';
3
+ export * from './lib/bridge-code';
3
4
  export * from './lib/check-for-new-version';
4
5
  export * from './lib/close-webview';
5
6
  export * from './lib/define-permission-usage';
6
7
  export * from './lib/generate-kb-sign';
7
- export * from './lib/get-device-info';
8
- export * from './lib/js-bridge-code';
8
+ export * from './lib/get-app-base-info';
9
9
  export * from './lib/open-post-editor';
10
- export * from './lib/report-getui';
10
+ export * from './lib/report-da-event';
11
11
  export * from './lib/run-action';
12
12
  export * from './lib/save-image-to-local';
13
13
  export * from './lib/save-video-to-local';
14
+ export * from './lib/scan-qr-code';
15
+ export * from './lib/screen-orientation';
14
16
  export * from './lib/set-webview-title';
17
+ export * from './lib/share-image';
15
18
  export * from './lib/share-model';
16
- export * from './lib/share-poster';
19
+ export * from './lib/subscribe-notify';
17
20
  export * from './lib/trigger-login';
@@ -0,0 +1,516 @@
1
+ function q(e) {
2
+ if (Object.prototype.toString.call(e) !== "[object Object]")
3
+ return e;
4
+ const t = {};
5
+ return Object.keys(e).forEach((r) => {
6
+ const i = e[r];
7
+ i != null && (t[r] = Object.prototype.toString.call(i) === "[object Object]" ? q(i) : i);
8
+ }), t;
9
+ }
10
+ const l = class l {
11
+ constructor(t) {
12
+ this.errorCode = t.errorCode, this.errorMsg = t.errorMsg;
13
+ }
14
+ };
15
+ l.UNKNOWN = new l({
16
+ errorCode: 1e3,
17
+ errorMsg: "未知错误"
18
+ }), l.UNSUPPORTED_VERSION = new l({
19
+ errorCode: 1001,
20
+ errorMsg: "当前开吧版本不支持"
21
+ }), l.TIMEOUT = new l({
22
+ errorCode: 1002,
23
+ errorMsg: "执行超时"
24
+ }), l.UNSUPPORTED_BRIDGE_ENV = new l({
25
+ errorCode: 1003,
26
+ errorMsg: "请在开吧app内执行"
27
+ });
28
+ let p = l;
29
+ const C = () => {
30
+ const e = (o, s, n) => {
31
+ var a = "";
32
+ typeof s == "function" && (n = s, s = {});
33
+ var d = { data: s === void 0 ? null : s };
34
+ if (typeof n == "function") {
35
+ var f = "dscb" + window.dscb++;
36
+ window[f] = n, d._dscbstub = f;
37
+ }
38
+ if (d = JSON.stringify(d), window.flutter_inappwebview ? window.flutter_inappwebview.callHandler && (a = window.flutter_inappwebview.callHandler("" + o, d)) : (window._dswk || navigator.userAgent.indexOf("_dsbridge") != -1) && (a = prompt("_flutterDsbridge=" + o, d)), a instanceof Promise)
39
+ return a;
40
+ try {
41
+ return JSON.parse(a || "{}").data;
42
+ } catch {
43
+ console.error("callHandle异常,JSON.parse错误");
44
+ }
45
+ }, t = () => window.navigator.userAgent.includes("Android") ? window.flutter_inappwebview && window.flutter_inappwebview._platformReady : !0, r = (() => {
46
+ const o = [], s = setInterval(() => {
47
+ t() && (clearInterval(s), o.forEach((n) => {
48
+ e.apply(window, n);
49
+ }), o.length = 0);
50
+ }, 500);
51
+ return (...n) => {
52
+ o.push(n);
53
+ };
54
+ })();
55
+ var i = {
56
+ default: void 0,
57
+ // for typescript
58
+ callHandler: function(o, s, n) {
59
+ return t() ? e(o, s, n) : r(o, s, n);
60
+ },
61
+ register: function(o, s, n) {
62
+ var a = n ? window._dsaf : window._dsf;
63
+ window._dsInit || (window._dsInit = !0, setTimeout(function() {
64
+ i.callHandler("_dsb.dsinit");
65
+ }, 0)), typeof s == "object" ? a._obs[o] = s : a[o] = s;
66
+ },
67
+ registerHandler: function(o, s) {
68
+ this.register(o, s, !0);
69
+ }
70
+ };
71
+ return function() {
72
+ if (!window._dsf) {
73
+ var o = {
74
+ //保存JS同步方法
75
+ _dsf: {
76
+ _obs: {}
77
+ },
78
+ //保存JS异步方法
79
+ _dsaf: {
80
+ _obs: {}
81
+ },
82
+ dscb: 0,
83
+ jsBridge: i,
84
+ _handleMessageFromNative: function(n) {
85
+ var a = JSON.parse(n.data), d = {
86
+ id: n.callbackId,
87
+ complete: !0
88
+ }, f = this._dsf[n.method], v = this._dsaf[n.method], T = function(O, S) {
89
+ d.data = O.apply(S, a), i.callHandler("_dsb.returnValue", d);
90
+ }, E = function(O, S) {
91
+ a.push(function(U, V) {
92
+ d.data = U, d.complete = V !== !1, i.callHandler("_dsb.returnValue", d);
93
+ }), O.apply(S, a);
94
+ };
95
+ if (f)
96
+ T(f, this._dsf);
97
+ else if (v)
98
+ E(v, this._dsaf);
99
+ else {
100
+ var m = n.method.split(".");
101
+ if (m.length < 2) return;
102
+ var b = m.pop(), P = m.join("."), _ = this._dsf._obs, g = _[P] || {}, h = g[b];
103
+ if (h && typeof h == "function") {
104
+ T(h, g);
105
+ return;
106
+ }
107
+ if (_ = this._dsaf._obs, g = _[P] || {}, h = g[b], h && typeof h == "function") {
108
+ E(h, g);
109
+ return;
110
+ }
111
+ }
112
+ }
113
+ };
114
+ for (var s in o)
115
+ window[s] = o[s];
116
+ }
117
+ }(), i;
118
+ };
119
+ var k;
120
+ const R = ((e) => /(kb)/i.test(e) ? C() : {
121
+ registerHandler(t, r) {
122
+ throw p.UNSUPPORTED_BRIDGE_ENV;
123
+ },
124
+ callHandler(t, r, i) {
125
+ throw p.UNSUPPORTED_BRIDGE_ENV;
126
+ }
127
+ })((k = window == null ? void 0 : window.navigator) == null ? void 0 : k.userAgent), N = (e) => new Promise((t, r) => {
128
+ var i, o, s;
129
+ try {
130
+ R.registerHandler(e.name, e.handler), (i = e.success) == null || i.call(e), t();
131
+ } catch (n) {
132
+ (o = e.fail) == null || o.call(e, n), r(n);
133
+ } finally {
134
+ (s = e.complete) == null || s.call(e);
135
+ }
136
+ });
137
+ function w(e) {
138
+ const t = (r) => {
139
+ let i;
140
+ const o = (n) => {
141
+ var a;
142
+ (!i || i === "success") && (i = "success", (a = r.success) == null || a.call(r, n));
143
+ }, s = (n) => {
144
+ var a;
145
+ (!i || i === "error") && (i = "error", (a = r.fail) == null || a.call(r, n));
146
+ };
147
+ r.timeout && setTimeout(() => {
148
+ s(p.TIMEOUT);
149
+ }, r.timeout);
150
+ try {
151
+ R.callHandler(r.name, r.params, (n) => {
152
+ let a;
153
+ try {
154
+ typeof n == "string" && /^\s*(\{|\[).*(\}|\])\s*$/.test(n) ? a = JSON.parse(n.replace(/\n/g, "\\n").replace(/\r/g, "\\r")) : a = n;
155
+ } catch {
156
+ a = n;
157
+ }
158
+ o(a);
159
+ });
160
+ } catch (n) {
161
+ s(n);
162
+ }
163
+ };
164
+ return new Promise((r, i) => {
165
+ t({
166
+ name: e.name,
167
+ params: q(e.params),
168
+ timeout: e.timeout,
169
+ success: (o) => {
170
+ var s, n;
171
+ (s = e.success) == null || s.call(e, o), (n = e.complete) == null || n.call(e), r(o);
172
+ },
173
+ fail: (o) => {
174
+ var s, n;
175
+ (s = e.fail) == null || s.call(e, o), (n = e.complete) == null || n.call(e), i(o);
176
+ }
177
+ });
178
+ });
179
+ }
180
+ function u(e) {
181
+ R.callHandler(e.name, e.params, (t) => {
182
+ });
183
+ }
184
+ function c(e) {
185
+ return async function(...r) {
186
+ const i = r[0] || {}, { success: o, fail: s, complete: n, ...a } = i;
187
+ try {
188
+ const d = await Promise.resolve(e(a));
189
+ return o == null || o(d), d;
190
+ } catch (d) {
191
+ const f = d != null && d.errorCode ? d : new p({
192
+ errorCode: p.UNKNOWN.errorCode,
193
+ errorMsg: String(d)
194
+ });
195
+ throw s == null || s(f), f;
196
+ } finally {
197
+ n == null || n();
198
+ }
199
+ };
200
+ }
201
+ function M(e) {
202
+ let t;
203
+ return function(...r) {
204
+ return t || (t = e(...r), Promise.resolve(t).catch(() => {
205
+ t = void 0;
206
+ }), t);
207
+ };
208
+ }
209
+ class j {
210
+ }
211
+ const H = M(
212
+ c(() => w({
213
+ name: "OpenActRequest",
214
+ params: {
215
+ type: 35,
216
+ data: {}
217
+ }
218
+ }))
219
+ ), D = c(async (e) => (await H()).vcode >= e.minVersion);
220
+ function B(e, t) {
221
+ return (...r) => D({
222
+ minVersion: e.minVersion
223
+ }).then((i) => i ? t(...r) : Promise.reject(
224
+ new p({
225
+ errorCode: p.UNSUPPORTED_VERSION.errorCode,
226
+ errorMsg: `最低版本要求${e.minVersion}`
227
+ })
228
+ ));
229
+ }
230
+ const J = c(() => {
231
+ u({
232
+ name: "OpenActRequest",
233
+ params: {
234
+ type: 56,
235
+ data: null
236
+ }
237
+ });
238
+ }), F = c(() => {
239
+ u({
240
+ name: "OpenActRequest",
241
+ params: {
242
+ type: -1,
243
+ data: {}
244
+ }
245
+ });
246
+ }), I = {
247
+ microphone: { description: "用于发帖上传音频" },
248
+ location: { description: "获取你选择的位置信息,用于线下导航服务" },
249
+ camera: { description: "收集你选中的照片或视频信息 ,用于 发表评论、分享视频" }
250
+ }, K = c((e) => (Object.assign(I, e), N({
251
+ name: "getPermissionUsage",
252
+ handler(t, r) {
253
+ r(I[t.permission]);
254
+ }
255
+ }))), W = c(async (e) => {
256
+ const { kbKey: t, ...r } = e, { data: i } = await w({
257
+ name: "OpenActRequest",
258
+ params: {
259
+ type: 51,
260
+ data: r
261
+ }
262
+ });
263
+ return i;
264
+ });
265
+ class L {
266
+ constructor() {
267
+ this.enableImageUpload = !0, this.enableAudioUpload = !0, this.enableVideoUpload = !0, this.enableAddress = !0, this.enableMediaVideoUpload = !1, this.minTextLength = 0, this.maxTextLength = 1e3, this.minImageCount = 0, this.maxImageCount = 9, this.isAudioRequired = !1, this.isVideoRequired = !1, this.isMediaVideoRequired = !1;
268
+ }
269
+ }
270
+ function G(e) {
271
+ const t = new L();
272
+ return e && Object.keys(e).forEach((i) => {
273
+ t[i] = e[i];
274
+ }), {
275
+ hint: t.placeholder,
276
+ initialText: t.initialText,
277
+ audio: t.enableAudioUpload,
278
+ image: t.enableImageUpload,
279
+ video: t.enableVideoUpload,
280
+ address: t.enableAddress,
281
+ asset_video: t.enableMediaVideoUpload,
282
+ text_must: t.minTextLength > 0,
283
+ content_min_length: t.minTextLength,
284
+ content_max_length: t.maxTextLength,
285
+ image_must: t.minImageCount > 0,
286
+ min_image_count: t.minImageCount,
287
+ max_image_count: t.maxImageCount,
288
+ audio_must: t.isAudioRequired,
289
+ video_must: t.isVideoRequired,
290
+ asset_video_must: t.isMediaVideoRequired
291
+ };
292
+ }
293
+ const $ = c(
294
+ async (e = {}) => w({
295
+ name: "OpenActRequest",
296
+ params: { type: 13, data: e }
297
+ }).then(({ data: t }) => {
298
+ const { pic: r, ...i } = t;
299
+ return { images: r, ...i };
300
+ })
301
+ ), z = c(
302
+ (e) => {
303
+ u({
304
+ name: "OpenActRequest",
305
+ params: {
306
+ type: 69,
307
+ data: {
308
+ /** 事件名 */
309
+ eventId: e.eventName,
310
+ /** 上报值 */
311
+ trackParams: e.eventParams,
312
+ /** 开始结束类型传递 */
313
+ ExtEventType: e.eventType
314
+ }
315
+ }
316
+ });
317
+ }
318
+ ), Q = c((e) => {
319
+ u({
320
+ name: "OpenActRequest",
321
+ params: {
322
+ type: 1001,
323
+ data: e
324
+ }
325
+ });
326
+ }), X = c(
327
+ (e) => {
328
+ u({
329
+ name: "OpenActRequest",
330
+ params: {
331
+ type: 62,
332
+ data: e
333
+ }
334
+ });
335
+ }
336
+ ), Y = c(
337
+ (e) => {
338
+ u({
339
+ name: "OpenActRequest",
340
+ params: {
341
+ type: 63,
342
+ data: e
343
+ }
344
+ });
345
+ }
346
+ ), Z = c(() => w({
347
+ name: "OpenActRequest",
348
+ params: {
349
+ type: 26,
350
+ data: {}
351
+ }
352
+ })), ee = c(
353
+ (e) => {
354
+ u({
355
+ name: "OpenActRequest",
356
+ params: {
357
+ type: 71,
358
+ data: e
359
+ }
360
+ });
361
+ }
362
+ ), te = c(
363
+ (e) => {
364
+ u({
365
+ name: "OpenActRequest",
366
+ params: {
367
+ type: 64,
368
+ data: e
369
+ }
370
+ });
371
+ }
372
+ ), ne = c(
373
+ (e) => {
374
+ u({
375
+ name: "OpenActRequest",
376
+ params: {
377
+ type: 58,
378
+ data: e
379
+ }
380
+ });
381
+ }
382
+ ), A = "SHARE_EVENT_NAME";
383
+ class re {
384
+ }
385
+ const ie = c((e) => N({
386
+ name: "CommonShare",
387
+ handler(t, r) {
388
+ window.dispatchEvent(new Event(A)), "onShareApp" in e && e.onShareApp ? r({ type: 12, data: e.onShareApp() }) : r({ type: 12, data: e });
389
+ }
390
+ })), se = c(async (e) => {
391
+ window.dispatchEvent(new Event(A)), u({
392
+ name: "OpenActRequest",
393
+ params: {
394
+ type: 58,
395
+ data: e
396
+ }
397
+ });
398
+ });
399
+ function oe(e) {
400
+ return window.addEventListener(A, e), () => {
401
+ window.removeEventListener(A, e);
402
+ };
403
+ }
404
+ const ae = c(
405
+ (e) => {
406
+ u({
407
+ name: "OpenActRequest",
408
+ params: {
409
+ type: 68,
410
+ data: {
411
+ show: e.showMenu,
412
+ showActionMode: e.panelStyle || 0
413
+ }
414
+ }
415
+ });
416
+ }
417
+ ), ce = c(() => w({
418
+ name: "OpenActRequest",
419
+ params: {
420
+ type: 72
421
+ }
422
+ })), de = c(async () => {
423
+ u({
424
+ name: "OpenActRequest",
425
+ params: {
426
+ type: 73
427
+ }
428
+ });
429
+ });
430
+ class ue {
431
+ }
432
+ const x = c(async () => (await w({
433
+ name: "OpenActRequest",
434
+ params: { type: 31, data: { requireLogin: !1 } }
435
+ })).data || null), y = /* @__PURE__ */ (() => {
436
+ const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ (() => {
437
+ let r;
438
+ const i = (o) => {
439
+ r = setTimeout(async () => {
440
+ const n = await x();
441
+ if (!n)
442
+ return i(++o);
443
+ e.forEach((a) => a(n)), e.clear();
444
+ }, ((n) => n === 0 ? 0 : n < 50 ? 600 : n < 80 ? 1e3 : 5e3)(o));
445
+ };
446
+ return {
447
+ start() {
448
+ r && clearTimeout(r), e.size > 0 && i(0);
449
+ },
450
+ stop() {
451
+ r && clearTimeout(r);
452
+ }
453
+ };
454
+ })();
455
+ return {
456
+ /** 注册监听事件(需要通过triggerCheckTask触发检测任务) */
457
+ addTask(r) {
458
+ e.add(r);
459
+ },
460
+ /** 移除监听 */
461
+ removeTask(r) {
462
+ e.delete(r), e.size === 0 && t.stop();
463
+ },
464
+ /** 触发定时检测是否登录成功任务 */
465
+ triggerCheckTask() {
466
+ t.start();
467
+ }
468
+ };
469
+ })(), le = c(async () => {
470
+ y.triggerCheckTask(), w({
471
+ name: "OpenActRequest",
472
+ params: { type: 31, data: { requireLogin: !0 } },
473
+ success(e) {
474
+ var t;
475
+ (t = e.data) != null && t.userId && y.triggerCheckTask();
476
+ }
477
+ });
478
+ }), pe = (e) => (y.addTask(e), y.triggerCheckTask(), () => {
479
+ y.removeTask(e);
480
+ });
481
+ export {
482
+ j as AppBaseInfo,
483
+ ue as AppBridgedUserInfo,
484
+ re as AppShareModel,
485
+ p as BridgeCode,
486
+ L as PostEditorParams,
487
+ J as checkForNewVersion,
488
+ F as closeWebView,
489
+ G as createPostEditorParams,
490
+ B as decorateAppVersionSupport,
491
+ ie as defineAppShareModel,
492
+ ae as defineAppSharePanelState,
493
+ N as defineBridgeCallback,
494
+ K as definePermissionUsage,
495
+ W as generateKBSign,
496
+ H as getAppBaseInfo,
497
+ x as getAppLoginInfo,
498
+ ce as getAppSubscribeNotifyStatus,
499
+ D as isAppVersionSupport,
500
+ pe as onAppLoginSuccess,
501
+ oe as onAppSharePanelShow,
502
+ se as openAppSharePanel,
503
+ de as openAppSubscribeNotifySettings,
504
+ $ as openPostEditor,
505
+ z as reportDAEvent,
506
+ Q as runAction,
507
+ u as runBridgeApi,
508
+ w as runBridgeApiResponse,
509
+ X as saveImageToLocal,
510
+ Y as saveVideoToLocal,
511
+ Z as scanQRCode,
512
+ ee as setScreenOrientation,
513
+ te as setWebViewTitle,
514
+ ne as shareImage,
515
+ le as triggerAppLogin
516
+ };
@@ -0,0 +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 U;function A(e){if(Object.prototype.toString.call(e)!=="[object Object]")return e;const t={};return Object.keys(e).forEach(i=>{const o=e[i];o!=null&&(t[i]=Object.prototype.toString.call(o)==="[object Object]"?A(o):o)}),t}const f=class f{constructor(t){this.errorCode=t.errorCode,this.errorMsg=t.errorMsg}};f.UNKNOWN=new f({errorCode:1e3,errorMsg:"未知错误"}),f.UNSUPPORTED_VERSION=new f({errorCode:1001,errorMsg:"当前开吧版本不支持"}),f.TIMEOUT=new f({errorCode:1002,errorMsg:"执行超时"}),f.UNSUPPORTED_BRIDGE_ENV=new f({errorCode:1003,errorMsg:"请在开吧app内执行"});let p=f;const H=()=>{const e=(a,s,n)=>{var c="";typeof s=="function"&&(n=s,s={});var u={data:s===void 0?null:s};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=[],s=setInterval(()=>{t()&&(clearInterval(s),a.forEach(n=>{e.apply(window,n)}),a.length=0)},500);return(...n)=>{a.push(n)}})();var o={default:void 0,callHandler:function(a,s,n){return t()?e(a,s,n):i(a,s,n)},register:function(a,s,n){var c=n?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){o.callHandler("_dsb.dsinit")},0)),typeof s=="object"?c._obs[a]=s:c[a]=s},registerHandler:function(a,s){this.register(a,s,!0)}};return function(){if(!window._dsf){var a={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:o,_handleMessageFromNative:function(n){var c=JSON.parse(n.data),u={id:n.callbackId,complete:!0},h=this._dsf[n.method],b=this._dsaf[n.method],q=function(R,E){u.data=R.apply(E,c),o.callHandler("_dsb.returnValue",u)},C=function(R,E){c.push(function(pe,fe){u.data=pe,u.complete=fe!==!1,o.callHandler("_dsb.returnValue",u)}),R.apply(E,c)};if(h)q(h,this._dsf);else if(b)C(b,this._dsaf);else{var T=n.method.split(".");if(T.length<2)return;var M=T.pop(),L=T.join("."),O=this._dsf._obs,m=O[L]||{},w=m[M];if(w&&typeof w=="function"){q(w,m);return}if(O=this._dsaf._obs,m=O[L]||{},w=m[M],w&&typeof w=="function"){C(w,m);return}}}};for(var s in a)window[s]=a[s]}}(),o},S=(e=>/(kb)/i.test(e)?H():{registerHandler(t,i){throw p.UNSUPPORTED_BRIDGE_ENV},callHandler(t,i,o){throw p.UNSUPPORTED_BRIDGE_ENV}})((U=window==null?void 0:window.navigator)==null?void 0:U.userAgent),_=e=>new Promise((t,i)=>{var o,a,s;try{S.registerHandler(e.name,e.handler),(o=e.success)==null||o.call(e),t()}catch(n){(a=e.fail)==null||a.call(e,n),i(n)}finally{(s=e.complete)==null||s.call(e)}});function g(e){const t=i=>{let o;const a=n=>{var c;(!o||o==="success")&&(o="success",(c=i.success)==null||c.call(i,n))},s=n=>{var c;(!o||o==="error")&&(o="error",(c=i.fail)==null||c.call(i,n))};i.timeout&&setTimeout(()=>{s(p.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){s(n)}};return new Promise((i,o)=>{t({name:e.name,params:A(e.params),timeout:e.timeout,success:a=>{var s,n;(s=e.success)==null||s.call(e,a),(n=e.complete)==null||n.call(e),i(a)},fail:a=>{var s,n;(s=e.fail)==null||s.call(e,a),(n=e.complete)==null||n.call(e),o(a)}})})}function l(e){S.callHandler(e.name,e.params,t=>{})}function d(e){return async function(...i){const o=i[0]||{},{success:a,fail:s,complete:n,...c}=o;try{const u=await Promise.resolve(e(c));return a==null||a(u),u}catch(u){const h=u!=null&&u.errorCode?u:new p({errorCode:p.UNKNOWN.errorCode,errorMsg:String(u)});throw s==null||s(h),h}finally{n==null||n()}}}function B(e){let t;return function(...i){return t||(t=e(...i),Promise.resolve(t).catch(()=>{t=void 0}),t)}}class D{}const P=B(d(()=>g({name:"OpenActRequest",params:{type:35,data:{}}}))),I=d(async e=>(await P()).vcode>=e.minVersion);function j(e,t){return(...i)=>I({minVersion:e.minVersion}).then(o=>o?t(...i):Promise.reject(new p({errorCode:p.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}const W=d(()=>{l({name:"OpenActRequest",params:{type:56,data:null}})}),F=d(()=>{l({name:"OpenActRequest",params:{type:-1,data:{}}})}),k={microphone:{description:"用于发帖上传音频"},location:{description:"获取你选择的位置信息,用于线下导航服务"},camera:{description:"收集你选中的照片或视频信息 ,用于 发表评论、分享视频"}},J=d(e=>(Object.assign(k,e),_({name:"getPermissionUsage",handler(t,i){i(k[t.permission])}}))),K=d(async e=>{const{kbKey:t,...i}=e,{data:o}=await g({name:"OpenActRequest",params:{type:51,data:i}});return o});class V{constructor(){this.enableImageUpload=!0,this.enableAudioUpload=!0,this.enableVideoUpload=!0,this.enableAddress=!0,this.enableMediaVideoUpload=!1,this.minTextLength=0,this.maxTextLength=1e3,this.minImageCount=0,this.maxImageCount=9,this.isAudioRequired=!1,this.isVideoRequired=!1,this.isMediaVideoRequired=!1}}function G(e){const t=new V;return e&&Object.keys(e).forEach(o=>{t[o]=e[o]}),{hint:t.placeholder,initialText:t.initialText,audio:t.enableAudioUpload,image:t.enableImageUpload,video:t.enableVideoUpload,address:t.enableAddress,asset_video:t.enableMediaVideoUpload,text_must:t.minTextLength>0,content_min_length:t.minTextLength,content_max_length:t.maxTextLength,image_must:t.minImageCount>0,min_image_count:t.minImageCount,max_image_count:t.maxImageCount,audio_must:t.isAudioRequired,video_must:t.isVideoRequired,asset_video_must:t.isMediaVideoRequired}}const $=d(async(e={})=>g({name:"OpenActRequest",params:{type:13,data:e}}).then(({data:t})=>{const{pic:i,...o}=t;return{images:i,...o}})),z=d(e=>{l({name:"OpenActRequest",params:{type:69,data:{eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType}}})}),Q=d(e=>{l({name:"OpenActRequest",params:{type:1001,data:e}})}),X=d(e=>{l({name:"OpenActRequest",params:{type:62,data:e}})}),Y=d(e=>{l({name:"OpenActRequest",params:{type:63,data:e}})}),Z=d(()=>g({name:"OpenActRequest",params:{type:26,data:{}}})),x=d(e=>{l({name:"OpenActRequest",params:{type:71,data:e}})}),ee=d(e=>{l({name:"OpenActRequest",params:{type:64,data:e}})}),te=d(e=>{l({name:"OpenActRequest",params:{type:58,data:e}})}),v="SHARE_EVENT_NAME";class ne{}const ie=d(e=>_({name:"CommonShare",handler(t,i){window.dispatchEvent(new Event(v)),"onShareApp"in e&&e.onShareApp?i({type:12,data:e.onShareApp()}):i({type:12,data:e})}})),re=d(async e=>{window.dispatchEvent(new Event(v)),l({name:"OpenActRequest",params:{type:58,data:e}})});function oe(e){return window.addEventListener(v,e),()=>{window.removeEventListener(v,e)}}const se=d(e=>{l({name:"OpenActRequest",params:{type:68,data:{show:e.showMenu,showActionMode:e.panelStyle||0}}})}),ae=d(()=>g({name:"OpenActRequest",params:{type:72}})),ce=d(async()=>{l({name:"OpenActRequest",params:{type:73}})});class de{}const N=d(async()=>(await g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!1}}})).data||null),y=(()=>{const e=new Set,t=(()=>{let i;const o=a=>{i=setTimeout(async()=>{const n=await N();if(!n)return o(++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&&o(0)},stop(){i&&clearTimeout(i)}}})();return{addTask(i){e.add(i)},removeTask(i){e.delete(i),e.size===0&&t.stop()},triggerCheckTask(){t.start()}}})(),ue=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()}})}),le=e=>(y.addTask(e),y.triggerCheckTask(),()=>{y.removeTask(e)});r.AppBaseInfo=D,r.AppBridgedUserInfo=de,r.AppShareModel=ne,r.BridgeCode=p,r.PostEditorParams=V,r.checkForNewVersion=W,r.closeWebView=F,r.createPostEditorParams=G,r.decorateAppVersionSupport=j,r.defineAppShareModel=ie,r.defineAppSharePanelState=se,r.defineBridgeCallback=_,r.definePermissionUsage=J,r.generateKBSign=K,r.getAppBaseInfo=P,r.getAppLoginInfo=N,r.getAppSubscribeNotifyStatus=ae,r.isAppVersionSupport=I,r.onAppLoginSuccess=le,r.onAppSharePanelShow=oe,r.openAppSharePanel=re,r.openAppSubscribeNotifySettings=ce,r.openPostEditor=$,r.reportDAEvent=z,r.runAction=Q,r.runBridgeApi=l,r.runBridgeApiResponse=g,r.saveImageToLocal=X,r.saveVideoToLocal=Y,r.scanQRCode=Z,r.setScreenOrientation=x,r.setWebViewTitle=ee,r.shareImage=te,r.triggerAppLogin=ue,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});