@kbapp/js-bridge 1.0.7-alpha.0 → 1.0.9-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.
package/README.md CHANGED
@@ -15,13 +15,13 @@ npm i @kbapp/js-bridge
15
15
  使用 unpkg CDN:
16
16
 
17
17
  ```html
18
- <script src="https://unpkg.com/@kbapp/js-bridge@latest/dist/index.umd.js"></script>
18
+ <script src="https://unpkg.com/@kbapp/js-bridge@latest/dist/umd/index.js"></script>
19
19
  ```
20
20
 
21
21
  使用 jsdelivr CDN:
22
22
 
23
23
  ```html
24
- <script src="https://cdn.jsdelivr.net/npm/@kbapp/js-bridge@latest/dist/index.umd.js"></script>
24
+ <script src="https://cdn.jsdelivr.net/npm/@kbapp/js-bridge@latest/dist/umd/index.js"></script>
25
25
  ```
26
26
 
27
27
  > 通过 script 标签引入后,SDK 将作为全局变量 `kbBridge` 挂载在 window 对象上
@@ -47,9 +47,11 @@ function saveImageHandle() {
47
47
 
48
48
  ### 通过 script 标签引入的使用示例
49
49
 
50
- ```js
51
- // 通过全局变量kbBridge访问SDK功能
50
+ ```html
51
+ <script src="https://unpkg.com/@kbapp/js-bridge@latest/dist/umd/index.js"></script>
52
+ <script>
52
53
  async function saveImageHandle() {
54
+ // 通过全局变量kbBridge访问SDK功能
53
55
  kbBridge.saveImageToLocal({
54
56
  imageUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png',
55
57
  success() {
@@ -60,6 +62,7 @@ async function saveImageHandle() {
60
62
  },
61
63
  })
62
64
  }
65
+ </script>
63
66
  ```
64
67
 
65
68
  ## API
@@ -37,7 +37,7 @@ function B(e) {
37
37
  let l;
38
38
  try {
39
39
  typeof t == "string" && /^\s*(\{|\[).*(\}|\])\s*$/.test(t) ? l = JSON.parse(t.replace(/\n/g, "\\n").replace(/\r/g, "\\r")) : l = t;
40
- } catch {
40
+ } catch (k) {
41
41
  l = t;
42
42
  }
43
43
  o(l);
@@ -11,7 +11,7 @@ const S = () => {
11
11
  return n;
12
12
  try {
13
13
  return JSON.parse(n || "{}").data;
14
- } catch {
14
+ } catch (f) {
15
15
  console.error("callHandle异常,JSON.parse错误");
16
16
  }
17
17
  }, _ = () => window.navigator.userAgent.includes("Android") ? window.flutter_inappwebview && window.flutter_inappwebview._platformReady : !0, y = (() => {
@@ -1,18 +1,36 @@
1
- import { wrapAsync as t } from "../utils/wrap-async.js";
2
- import { getAppBaseInfo as p } from "./get-app-base-info.js";
3
- import { BridgeCode as e } from "./bridge-code.js";
4
- const s = t(async (r) => (await p()).vcode >= r.minVersion);
5
- function a(r, o) {
6
- return (...n) => s({
7
- minVersion: r.minVersion
8
- }).then((i) => i ? o(...n) : Promise.reject(
9
- new e({
10
- errorCode: e.UNSUPPORTED_VERSION.errorCode,
11
- errorMsg: `最低版本要求${r.minVersion}`
1
+ var m = (e, n, o) => new Promise((i, s) => {
2
+ var V = (r) => {
3
+ try {
4
+ t(o.next(r));
5
+ } catch (p) {
6
+ s(p);
7
+ }
8
+ }, a = (r) => {
9
+ try {
10
+ t(o.throw(r));
11
+ } catch (p) {
12
+ s(p);
13
+ }
14
+ }, t = (r) => r.done ? i(r.value) : Promise.resolve(r.value).then(V, a);
15
+ t((o = o.apply(e, n)).next());
16
+ });
17
+ import { wrapAsync as c } from "../utils/wrap-async.js";
18
+ import { getAppBaseInfo as d } from "./get-app-base-info.js";
19
+ import { BridgeCode as u } from "./bridge-code.js";
20
+ const f = c((e) => m(void 0, null, function* () {
21
+ return (yield d()).vcode >= e.minVersion;
22
+ }));
23
+ function P(e, n) {
24
+ return (...o) => f({
25
+ minVersion: e.minVersion
26
+ }).then((i) => i ? n(...o) : Promise.reject(
27
+ new u({
28
+ errorCode: u.UNSUPPORTED_VERSION.errorCode,
29
+ errorMsg: `最低版本要求${e.minVersion}`
12
30
  })
13
31
  ));
14
32
  }
15
33
  export {
16
- a as decorateAppVersionSupport,
17
- s as isAppVersionSupport
34
+ P as decorateAppVersionSupport,
35
+ f as isAppVersionSupport
18
36
  };
@@ -1,16 +1,43 @@
1
- import { wrapAsync as n } from "../utils/wrap-async.js";
2
- import { runBridgeApiResponse as r } from "../core/index.js";
3
- const m = n(async (t) => {
4
- const { kbKey: o, ...e } = t, { data: a } = await r({
1
+ var m = Object.getOwnPropertySymbols;
2
+ var d = Object.prototype.hasOwnProperty, g = Object.prototype.propertyIsEnumerable;
3
+ var i = (e, r) => {
4
+ var a = {};
5
+ for (var t in e)
6
+ d.call(e, t) && r.indexOf(t) < 0 && (a[t] = e[t]);
7
+ if (e != null && m)
8
+ for (var t of m(e))
9
+ r.indexOf(t) < 0 && g.call(e, t) && (a[t] = e[t]);
10
+ return a;
11
+ };
12
+ var c = (e, r, a) => new Promise((t, o) => {
13
+ var u = (n) => {
14
+ try {
15
+ p(a.next(n));
16
+ } catch (s) {
17
+ o(s);
18
+ }
19
+ }, y = (n) => {
20
+ try {
21
+ p(a.throw(n));
22
+ } catch (s) {
23
+ o(s);
24
+ }
25
+ }, p = (n) => n.done ? t(n.value) : Promise.resolve(n.value).then(u, y);
26
+ p((a = a.apply(e, r)).next());
27
+ });
28
+ import { wrapAsync as A } from "../utils/wrap-async.js";
29
+ import { runBridgeApiResponse as f } from "../core/index.js";
30
+ const R = A((e) => c(void 0, null, function* () {
31
+ const o = e, { kbKey: r } = o, a = i(o, ["kbKey"]), { data: t } = yield f({
5
32
  name: "OpenActRequest",
6
33
  timeout: 5e3,
7
34
  params: {
8
35
  type: 51,
9
- data: e
36
+ data: a
10
37
  }
11
38
  });
12
- return a;
13
- });
39
+ return t;
40
+ }));
14
41
  export {
15
- m as generateKBSign
42
+ R as generateKBSign
16
43
  };
@@ -1,13 +1,49 @@
1
- import { runBridgeApiResponse as n } from "../core/index.js";
2
- import { wrapAsync as s } from "../utils/wrap-async.js";
3
- var d = /* @__PURE__ */ ((t) => (t[t.FREE = 1] = "FREE", t[t.FORBID = 2] = "FORBID", t[t.REQUIRED = 3] = "REQUIRED", t))(d || {});
4
- class r {
1
+ var E = Object.defineProperty;
2
+ var r = Object.getOwnPropertySymbols;
3
+ var h = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
4
+ var c = (t, e, i) => e in t ? E(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i, a = (t, e) => {
5
+ for (var i in e || (e = {}))
6
+ h.call(e, i) && c(t, i, e[i]);
7
+ if (r)
8
+ for (var i of r(e))
9
+ x.call(e, i) && c(t, i, e[i]);
10
+ return t;
11
+ };
12
+ var g = (t, e) => {
13
+ var i = {};
14
+ for (var o in t)
15
+ h.call(t, o) && e.indexOf(o) < 0 && (i[o] = t[o]);
16
+ if (t != null && r)
17
+ for (var o of r(t))
18
+ e.indexOf(o) < 0 && x.call(t, o) && (i[o] = t[o]);
19
+ return i;
20
+ };
21
+ var _ = (t, e, i) => new Promise((o, s) => {
22
+ var d = (n) => {
23
+ try {
24
+ R(i.next(n));
25
+ } catch (u) {
26
+ s(u);
27
+ }
28
+ }, l = (n) => {
29
+ try {
30
+ R(i.throw(n));
31
+ } catch (u) {
32
+ s(u);
33
+ }
34
+ }, R = (n) => n.done ? o(n.value) : Promise.resolve(n.value).then(d, l);
35
+ R((i = i.apply(t, e)).next());
36
+ });
37
+ import { runBridgeApiResponse as M } from "../core/index.js";
38
+ import { wrapAsync as m } from "../utils/wrap-async.js";
39
+ var v = /* @__PURE__ */ ((t) => (t[t.FREE = 1] = "FREE", t[t.FORBID = 2] = "FORBID", t[t.REQUIRED = 3] = "REQUIRED", t))(v || {});
40
+ class q {
5
41
  constructor() {
6
42
  this.textMin = 0, this.textMax = 1e3, this.imageMax = 9, this.imageMin = 0, this.audioRqr = 1, this.videoRqr = 1, this.mediaRqr = 2, this.streetRqr = 1;
7
43
  }
8
44
  }
9
- function c(t) {
10
- const e = new r();
45
+ function B(t) {
46
+ const e = new q();
11
47
  return t && Object.keys(t).forEach((i) => {
12
48
  e[i] = t[i];
13
49
  }), {
@@ -29,18 +65,21 @@ function c(t) {
29
65
  content_min_length: e.textMin
30
66
  };
31
67
  }
32
- const h = s(
33
- async (t) => n({
34
- name: "OpenActRequest",
35
- params: { type: 13, data: (t == null ? void 0 : t.postRule) ?? {} }
36
- }).then(({ data: e }) => {
37
- const { pic: i, ...o } = e;
38
- return { images: i, ...o };
68
+ const D = m(
69
+ (t) => _(void 0, null, function* () {
70
+ var e;
71
+ return M({
72
+ name: "OpenActRequest",
73
+ params: { type: 13, data: (e = t == null ? void 0 : t.postRule) != null ? e : {} }
74
+ }).then(({ data: i }) => {
75
+ const d = i, { pic: o } = d, s = g(d, ["pic"]);
76
+ return a({ images: o }, s);
77
+ });
39
78
  })
40
79
  );
41
80
  export {
42
- d as KbRequirement,
43
- r as NoteThreadPostRule,
44
- c as generatePostEditorParamsByThreadPostRule,
45
- h as openPostEditor
81
+ v as KbRequirement,
82
+ q as NoteThreadPostRule,
83
+ B as generatePostEditorParamsByThreadPostRule,
84
+ D as openPostEditor
46
85
  };
@@ -1,30 +1,46 @@
1
- import { defineBridgeCallback as a, runBridgeApi as p } from "../core/index.js";
2
- import { wrapAsync as t } from "../utils/wrap-async.js";
3
- const n = "SHARE_EVENT_NAME";
4
- class A {
1
+ var A = (e, d, n) => new Promise((s, i) => {
2
+ var w = (t) => {
3
+ try {
4
+ p(n.next(t));
5
+ } catch (a) {
6
+ i(a);
7
+ }
8
+ }, E = (t) => {
9
+ try {
10
+ p(n.throw(t));
11
+ } catch (a) {
12
+ i(a);
13
+ }
14
+ }, p = (t) => t.done ? s(t.value) : Promise.resolve(t.value).then(w, E);
15
+ p((n = n.apply(e, d)).next());
16
+ });
17
+ import { defineBridgeCallback as S, runBridgeApi as h } from "../core/index.js";
18
+ import { wrapAsync as r } from "../utils/wrap-async.js";
19
+ const o = "SHARE_EVENT_NAME";
20
+ class f {
5
21
  }
6
- const h = t((e) => a({
22
+ const u = r((e) => S({
7
23
  name: "CommonShare",
8
- handler(r, o) {
9
- window.dispatchEvent(new Event(n)), "onShareApp" in e && e.onShareApp ? o({ type: 12, data: e.onShareApp() }) : o({ type: 12, data: e });
24
+ handler(d, n) {
25
+ window.dispatchEvent(new Event(o)), "onShareApp" in e && e.onShareApp ? n({ type: 12, data: e.onShareApp() }) : n({ type: 12, data: e });
10
26
  }
11
- })), s = t(async (e) => {
12
- window.dispatchEvent(new Event(n)), p({
27
+ })), v = r((e) => A(void 0, null, function* () {
28
+ window.dispatchEvent(new Event(o)), h({
13
29
  name: "OpenActRequest",
14
30
  params: {
15
31
  type: 58,
16
32
  data: e
17
33
  }
18
34
  });
19
- });
20
- function w(e) {
21
- return window.addEventListener(n, e), () => {
22
- window.removeEventListener(n, e);
35
+ }));
36
+ function y(e) {
37
+ return window.addEventListener(o, e), () => {
38
+ window.removeEventListener(o, e);
23
39
  };
24
40
  }
25
- const E = t(
41
+ const M = r(
26
42
  (e) => {
27
- p({
43
+ h({
28
44
  name: "OpenActRequest",
29
45
  params: {
30
46
  type: 68,
@@ -37,9 +53,9 @@ const E = t(
37
53
  }
38
54
  );
39
55
  export {
40
- A as AppShareModel,
41
- h as defineAppShareModel,
42
- E as defineAppSharePanelState,
43
- w as onAppSharePanelShow,
44
- s as openAppSharePanel
56
+ f as AppShareModel,
57
+ u as defineAppShareModel,
58
+ M as defineAppSharePanelState,
59
+ y as onAppSharePanelShow,
60
+ v as openAppSharePanel
45
61
  };
@@ -1,19 +1,35 @@
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({
1
+ var s = (o, a, t) => new Promise((c, n) => {
2
+ var m = (e) => {
3
+ try {
4
+ p(t.next(e));
5
+ } catch (r) {
6
+ n(r);
7
+ }
8
+ }, u = (e) => {
9
+ try {
10
+ p(t.throw(e));
11
+ } catch (r) {
12
+ n(r);
13
+ }
14
+ }, p = (e) => e.done ? c(e.value) : Promise.resolve(e.value).then(m, u);
15
+ p((t = t.apply(o, a)).next());
16
+ });
17
+ import { runBridgeApiResponse as A, runBridgeApi as y } from "../core/index.js";
18
+ import { wrapAsync as i } from "../utils/wrap-async.js";
19
+ const S = i(() => A({
4
20
  name: "OpenActRequest",
5
21
  params: {
6
22
  type: 72
7
23
  }
8
- })), i = e(async () => {
9
- p({
24
+ })), R = i(() => s(void 0, null, function* () {
25
+ y({
10
26
  name: "OpenActRequest",
11
27
  params: {
12
28
  type: 73
13
29
  }
14
30
  });
15
- });
31
+ }));
16
32
  export {
17
- s as getAppSubscribeNotifyStatus,
18
- i as openAppSubscribeNotifySettings
33
+ S as getAppSubscribeNotifyStatus,
34
+ R as openAppSubscribeNotifySettings
19
35
  };
@@ -1,60 +1,74 @@
1
- import { runBridgeApiResponse as i } from "../core/index.js";
2
- import { wrapAsync as c } from "../utils/wrap-async.js";
3
- class d {
1
+ var c = (t, o, e) => new Promise((i, n) => {
2
+ var u = (a) => {
3
+ try {
4
+ r(e.next(a));
5
+ } catch (g) {
6
+ n(g);
7
+ }
8
+ }, s = (a) => {
9
+ try {
10
+ r(e.throw(a));
11
+ } catch (g) {
12
+ n(g);
13
+ }
14
+ }, r = (a) => a.done ? i(a.value) : Promise.resolve(a.value).then(u, s);
15
+ r((e = e.apply(t, o)).next());
16
+ });
17
+ import { runBridgeApiResponse as T, runBridgeApi as d } from "../core/index.js";
18
+ import { wrapAsync as k } from "../utils/wrap-async.js";
19
+ class A {
4
20
  }
5
- const g = c(async () => (await i({
6
- name: "OpenActRequest",
7
- timeout: 5e3,
8
- params: { type: 31, data: { requireLogin: !1 } }
9
- })).data || null), r = /* @__PURE__ */ (() => {
10
- const e = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ (() => {
11
- let t;
12
- const n = (o) => {
13
- t = setTimeout(async () => {
14
- const s = await g();
21
+ const l = k(() => c(void 0, null, function* () {
22
+ return (yield T({
23
+ name: "OpenActRequest",
24
+ timeout: 5e3,
25
+ params: { type: 31, data: { requireLogin: !1 } }
26
+ })).data || null;
27
+ })), p = /* @__PURE__ */ (() => {
28
+ const t = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ (() => {
29
+ let e;
30
+ const i = (n) => {
31
+ e = setTimeout(() => c(void 0, null, function* () {
32
+ const s = yield l();
15
33
  if (!s)
16
- return n(++o);
17
- e.forEach((p) => p(s)), e.clear();
18
- }, ((s) => s === 0 ? 0 : s < 50 ? 600 : s < 80 ? 1e3 : 5e3)(o));
34
+ return i(++n);
35
+ t.forEach((r) => r(s)), t.clear();
36
+ }), ((s) => s === 0 ? 0 : s < 50 ? 600 : s < 80 ? 1e3 : 5e3)(n));
19
37
  };
20
38
  return {
21
39
  start() {
22
- t && clearTimeout(t), e.size > 0 && n(0);
40
+ e && clearTimeout(e), t.size > 0 && i(0);
23
41
  },
24
42
  stop() {
25
- t && clearTimeout(t);
43
+ e && clearTimeout(e);
26
44
  }
27
45
  };
28
46
  })();
29
47
  return {
30
48
  /** 注册监听事件(需要通过triggerCheckTask触发检测任务) */
31
- addTask(t) {
32
- e.add(t);
49
+ addTask(e) {
50
+ t.add(e);
33
51
  },
34
52
  /** 移除监听 */
35
- removeTask(t) {
36
- e.delete(t), e.size === 0 && a.stop();
53
+ removeTask(e) {
54
+ t.delete(e), t.size === 0 && o.stop();
37
55
  },
38
56
  /** 触发定时检测是否登录成功任务 */
39
57
  triggerCheckTask() {
40
- a.start();
58
+ o.start();
41
59
  }
42
60
  };
43
- })(), l = c(async () => {
44
- r.triggerCheckTask(), i({
61
+ })(), y = k(() => c(void 0, null, function* () {
62
+ p.triggerCheckTask(), yield d({
45
63
  name: "OpenActRequest",
46
- params: { type: 31, data: { requireLogin: !0 } },
47
- success(e) {
48
- var a;
49
- (a = e.data) != null && a.userId && r.triggerCheckTask();
50
- }
64
+ params: { type: 31, data: { requireLogin: !0 } }
51
65
  });
52
- }), m = (e) => (r.addTask(e), r.triggerCheckTask(), () => {
53
- r.removeTask(e);
66
+ })), L = (t) => (p.addTask(t), p.triggerCheckTask(), () => {
67
+ p.removeTask(t);
54
68
  });
55
69
  export {
56
- d as AppLoginInfo,
57
- g as getAppLoginInfo,
58
- m as onLoopCheckAppLogin,
59
- l as triggerAppLogin
70
+ A as AppLoginInfo,
71
+ l as getAppLoginInfo,
72
+ L as onLoopCheckAppLogin,
73
+ y as triggerAppLogin
60
74
  };
@@ -1,11 +1,15 @@
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);
1
+ function s(r) {
2
+ const e = /* @__PURE__ */ new Map();
3
+ return function(...c) {
4
+ const t = JSON.stringify(c);
5
+ if (e.has(t))
6
+ return e.get(t);
7
+ const n = r(...c);
8
+ return e.set(t, n), Promise.resolve(n).catch(() => {
9
+ e.delete(t);
10
+ }), n;
7
11
  };
8
12
  }
9
13
  export {
10
- n as decorateCacheAsyncResult
14
+ s as decorateCacheAsyncResult
11
15
  };
@@ -1,21 +1,50 @@
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;
1
+ var u = Object.getOwnPropertySymbols;
2
+ var C = Object.prototype.hasOwnProperty, f = Object.prototype.propertyIsEnumerable;
3
+ var w = (t, a) => {
4
+ var e = {};
5
+ for (var r in t)
6
+ C.call(t, r) && a.indexOf(r) < 0 && (e[r] = t[r]);
7
+ if (t != null && u)
8
+ for (var r of u(t))
9
+ a.indexOf(r) < 0 && f.call(t, r) && (e[r] = t[r]);
10
+ return e;
11
+ };
12
+ var m = (t, a, e) => new Promise((r, s) => {
13
+ var c = (n) => {
14
+ try {
15
+ d(e.next(n));
16
+ } catch (o) {
17
+ s(o);
18
+ }
19
+ }, i = (n) => {
5
20
  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();
21
+ d(e.throw(n));
22
+ } catch (o) {
23
+ s(o);
16
24
  }
25
+ }, d = (n) => n.done ? r(n.value) : Promise.resolve(n.value).then(c, i);
26
+ d((e = e.apply(t, a)).next());
27
+ });
28
+ import { BridgeCode as y } from "../lib/bridge-code.js";
29
+ function N(t) {
30
+ return function(...e) {
31
+ return m(this, null, function* () {
32
+ const n = e[0] || {}, { success: s, fail: c, complete: i } = n, d = w(n, ["success", "fail", "complete"]);
33
+ try {
34
+ const o = yield Promise.resolve(t(d));
35
+ return s == null || s(o), o;
36
+ } catch (o) {
37
+ const p = o != null && o.errorCode ? o : new y({
38
+ errorCode: y.UNKNOWN.errorCode,
39
+ errorMsg: String(o)
40
+ });
41
+ throw c == null || c(p), p;
42
+ } finally {
43
+ i == null || i();
44
+ }
45
+ });
17
46
  };
18
47
  }
19
48
  export {
20
- w as wrapAsync
49
+ N as wrapAsync
21
50
  };
@@ -36,6 +36,6 @@ const onTapLogin = decorateAppVersionSupport({ minVersion: 80711 }, () => {
36
36
  })
37
37
  ```
38
38
  */
39
- export declare function decorateAppVersionSupport<Callback extends (...params: any[]) => any>(config: {
39
+ export declare function decorateAppVersionSupport<T extends (...args: any[]) => any>(config: {
40
40
  minVersion: number;
41
- }, callback: Callback): (...params: Parameters<Callback>) => Promise<any>;
41
+ }, callback: T): (...params: Parameters<T>) => Promise<Awaited<ReturnType<T>>>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- *
3
- * @description 缓存promise结果
2
+ * @description 缓存 Promise 结果(支持参数感知)
3
+ * 只有当参数完全一致时才返回缓存,参数变动则重新发起调用
4
4
  */
5
5
  export declare function decorateCacheAsyncResult<CB extends (...params: any[]) => any>(cb: CB): (...params: Parameters<CB>) => ReturnType<CB>;
package/dist/umd/index.js CHANGED
@@ -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 a=e[i];a!=null&&(t[i]=Object.prototype.toString.call(a)==="[object Object]"?A(a):a)}),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=(s,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(""+s,u)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(c=prompt("_flutterDsbridge="+s,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 s=[],o=setInterval(()=>{t()&&(clearInterval(o),s.forEach(n=>{e.apply(window,n)}),s.length=0)},500);return(...n)=>{s.push(n)}})();var a={default:void 0,callHandler:function(s,o,n){return t()?e(s,o,n):i(s,o,n)},register:function(s,o,n){var c=n?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){a.callHandler("_dsb.dsinit")},0)),typeof o=="object"?c._obs[s]=o:c[s]=o},registerHandler:function(s,o){this.register(s,o,!0)}};return function(){if(!window._dsf){var s={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:a,_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),a.callHandler("_dsb.returnValue",u)},U=function(P,b){c.push(function(ge,he){u.data=ge,u.complete=he!==!1,a.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 s)window[o]=s[o]}}(),a},S=(e=>/(kb)/i.test(e)?L():{registerHandler(t,i){throw f.UNSUPPORTED_BRIDGE_ENV},callHandler(t,i,a){throw f.UNSUPPORTED_BRIDGE_ENV}})((V=window==null?void 0:window.navigator)==null?void 0:V.userAgent),R=e=>new Promise((t,i)=>{var a,s,o;try{S.registerHandler(e.name,e.handler),(a=e.success)==null||a.call(e),t()}catch(n){(s=e.fail)==null||s.call(e,n),i(n)}finally{(o=e.complete)==null||o.call(e)}});function g(e){const t=i=>{let a;const s=n=>{var c;(!a||a==="success")&&(a="success",(c=i.success)==null||c.call(i,n))},o=n=>{var c;a||(a="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}s(c)})}catch(n){o(n)}};return new Promise((i,a)=>{t({name:e.name,params:A(e.params),timeout:e.timeout,success:s=>{var o,n;(o=e.success)==null||o.call(e,s),(n=e.complete)==null||n.call(e),i(s)},fail:s=>{var o,n;(o=e.fail)==null||o.call(e,s),(n=e.complete)==null||n.call(e),a(s)}})})}function l(e){S.callHandler(e.name,e.params,t=>{})}function d(e){return async function(...i){const a=i[0]||{},{success:s,fail:o,complete:n,...c}=a;try{const u=await Promise.resolve(e(c));return s==null||s(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 m=d(H(()=>g({name:"OpenActRequest",timeout:5e3,params:{type:35,data:{}}}))),k=d(async e=>(await m()).vcode>=e.minVersion);function F(e,t){return(...i)=>k({minVersion:e.minVersion}).then(a=>a?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:a}=await g({name:"OpenActRequest",timeout:5e3,params:{type:51,data:i}});return a});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,...a}=t;return{images:i,...a}})),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",timeout:5e3,params:{type:31,data:{requireLogin:!1}}})).data||null),y=(()=>{const e=new Set,t=(()=>{let i;const a=s=>{i=setTimeout(async()=>{const n=await q();if(!n)return a(++s);e.forEach(c=>c(n)),e.clear()},(n=>n===0?0:n<50?600:n<80?1e3:5e3)(s))};return{start(){i&&clearTimeout(i),e.size>0&&a(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=m,r.getAppLoginInfo=q,r.getAppSubscribeNotifyStatus=de,r.isAppVersionSupport=k,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(t,l){typeof exports=="object"&&typeof module!="undefined"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(t=typeof globalThis!="undefined"?globalThis:t||self,l(t.kbBridge={}))})(this,function(t){"use strict";var Ee=Object.defineProperty;var b=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var W=(t,l,c)=>l in t?Ee(t,l,{enumerable:!0,configurable:!0,writable:!0,value:c}):t[l]=c,K=(t,l)=>{for(var c in l||(l={}))Q.call(l,c)&&W(t,c,l[c]);if(b)for(var c of b(l))G.call(l,c)&&W(t,c,l[c]);return t};var m=(t,l)=>{var c={};for(var h in t)Q.call(t,h)&&l.indexOf(h)<0&&(c[h]=t[h]);if(t!=null&&b)for(var h of b(t))l.indexOf(h)<0&&G.call(t,h)&&(c[h]=t[h]);return c};var A=(t,l,c)=>new Promise((h,_)=>{var R=d=>{try{f(c.next(d))}catch(E){_(E)}},y=d=>{try{f(c.throw(d))}catch(E){_(E)}},f=d=>d.done?h(d.value):Promise.resolve(d.value).then(R,y);f((c=c.apply(t,l)).next())});var L;function l(e){if(Object.prototype.toString.call(e)!=="[object Object]")return e;const r={};return Object.keys(e).forEach(n=>{const a=e[n];a!=null&&(r[n]=Object.prototype.toString.call(a)==="[object Object]"?l(a):a)}),r}const w=class w{constructor(r){this.errorCode=r.errorCode,this.errorMsg=r.errorMsg}};w.UNKNOWN=new w({errorCode:1e3,errorMsg:"未知错误"}),w.UNSUPPORTED_VERSION=new w({errorCode:1001,errorMsg:"当前开吧版本不支持"}),w.TIMEOUT=new w({errorCode:1002,errorMsg:"执行超时"}),w.UNSUPPORTED_BRIDGE_ENV=new w({errorCode:1003,errorMsg:"请在开吧app内执行"});let c=w;const h=()=>{const e=(o,s,i)=>{var u="";typeof s=="function"&&(i=s,s={});var p={data:s===void 0?null:s};if(typeof i=="function"){var g="dscb"+window.dscb++;window[g]=i,p._dscbstub=g}if(p=JSON.stringify(p),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(u=window.flutter_inappwebview.callHandler(""+o,p)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(u=prompt("_flutterDsbridge="+o,p)),u instanceof Promise)return u;try{return JSON.parse(u||"{}").data}catch(S){console.error("callHandle异常,JSON.parse错误")}},r=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,n=(()=>{const o=[],s=setInterval(()=>{r()&&(clearInterval(s),o.forEach(i=>{e.apply(window,i)}),o.length=0)},500);return(...i)=>{o.push(i)}})();var a={default:void 0,callHandler:function(o,s,i){return r()?e(o,s,i):n(o,s,i)},register:function(o,s,i){var u=i?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){a.callHandler("_dsb.dsinit")},0)),typeof s=="object"?u._obs[o]=s:u[o]=s},registerHandler:function(o,s){this.register(o,s,!0)}};return function(){if(!window._dsf){var o={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:a,_handleMessageFromNative:function(i){var u=JSON.parse(i.data),p={id:i.callbackId,complete:!0},g=this._dsf[i.method],S=this._dsaf[i.method],H=function(N,M){p.data=N.apply(M,u),a.callHandler("_dsb.returnValue",p)},j=function(N,M){u.push(function(Se,Re){p.data=Se,p.complete=Re!==!1,a.callHandler("_dsb.returnValue",p)}),N.apply(M,u)};if(g)H(g,this._dsf);else if(S)j(S,this._dsaf);else{var k=i.method.split(".");if(k.length<2)return;var F=k.pop(),J=k.join("."),I=this._dsf._obs,O=I[J]||{},v=O[F];if(v&&typeof v=="function"){H(v,O);return}if(I=this._dsaf._obs,O=I[J]||{},v=O[F],v&&typeof v=="function"){j(v,O);return}}}};for(var s in o)window[s]=o[s]}}(),a},_=(e=>/(kb)/i.test(e)?h():{registerHandler(r,n){throw c.UNSUPPORTED_BRIDGE_ENV},callHandler(r,n,a){throw c.UNSUPPORTED_BRIDGE_ENV}})((L=window==null?void 0:window.navigator)==null?void 0:L.userAgent),R=e=>new Promise((r,n)=>{var a,o,s;try{_.registerHandler(e.name,e.handler),(a=e.success)==null||a.call(e),r()}catch(i){(o=e.fail)==null||o.call(e,i),n(i)}finally{(s=e.complete)==null||s.call(e)}});function y(e){const r=n=>{let a;const o=i=>{var u;(!a||a==="success")&&(a="success",(u=n.success)==null||u.call(n,i))},s=i=>{var u;a||(a="error",(u=n.fail)==null||u.call(n,i))};n.timeout&&setTimeout(()=>{s(c.TIMEOUT)},n.timeout);try{_.callHandler(n.name,n.params,i=>{let u;try{typeof i=="string"&&/^\s*(\{|\[).*(\}|\])\s*$/.test(i)?u=JSON.parse(i.replace(/\n/g,"\\n").replace(/\r/g,"\\r")):u=i}catch(p){u=i}o(u)})}catch(i){s(i)}};return new Promise((n,a)=>{r({name:e.name,params:l(e.params),timeout:e.timeout,success:o=>{var s,i;(s=e.success)==null||s.call(e,o),(i=e.complete)==null||i.call(e),n(o)},fail:o=>{var s,i;(s=e.fail)==null||s.call(e,o),(i=e.complete)==null||i.call(e),a(o)}})})}function f(e){_.callHandler(e.name,e.params,r=>{})}function d(e){return function(...n){return A(this,null,function*(){const p=n[0]||{},{success:o,fail:s,complete:i}=p,u=m(p,["success","fail","complete"]);try{const g=yield Promise.resolve(e(u));return o==null||o(g),g}catch(g){const S=g!=null&&g.errorCode?g:new c({errorCode:c.UNKNOWN.errorCode,errorMsg:String(g)});throw s==null||s(S),S}finally{i==null||i()}})}}function E(e){const r=new Map;return function(...n){const a=JSON.stringify(n);if(r.has(a))return r.get(a);const o=e(...n);return r.set(a,o),Promise.resolve(o).catch(()=>{r.delete(a)}),o}}class ${}const q=d(E(()=>y({name:"OpenActRequest",timeout:5e3,params:{type:35,data:{}}}))),V=d(e=>A(this,null,function*(){return(yield q()).vcode>=e.minVersion}));function z(e,r){return(...n)=>V({minVersion:e.minVersion}).then(a=>a?r(...n):Promise.reject(new c({errorCode:c.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}const X=d(()=>{f({name:"OpenActRequest",params:{type:56,data:null}})}),Y=d(()=>{f({name:"OpenActRequest",params:{type:-1,data:{}}})}),U={microphone:{description:"用于发帖上传音频"},location:{description:"获取你选择的位置信息,用于线下导航服务"},camera:{description:"收集你选中的照片或视频信息 ,用于 发表评论、分享视频"}},Z=d(e=>(Object.assign(U,e),R({name:"getPermissionUsage",handler(r,n){n(U[r.permission])}}))),x=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent),ee=d(e=>A(this,null,function*(){const o=e,{kbKey:r}=o,n=m(o,["kbKey"]),{data:a}=yield y({name:"OpenActRequest",timeout:5e3,params:{type:51,data:n}});return a}));var B=(e=>(e[e.FREE=1]="FREE",e[e.FORBID=2]="FORBID",e[e.REQUIRED=3]="REQUIRED",e))(B||{});class C{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 te(e){const r=new C;return e&&Object.keys(e).forEach(n=>{r[n]=e[n]}),{hint:e==null?void 0:e.placeholder,initialText:e==null?void 0:e.initialText,audio:r.audioRqr!==2,image:r.imageMax!==0,video:r.videoRqr!==2,address:r.streetRqr!==2,asset_video:r.mediaRqr!==2,audio_must:r.audioRqr===3,image_must:r.imageMin>0,asset_video_must:r.mediaRqr===3,max_image_count:r.imageMax,min_image_count:r.imageMin,video_must:r.videoRqr===3,text_must:r.textMin>0,content_max_length:r.textMax,content_min_length:r.textMin}}const ne=d(e=>A(this,null,function*(){var r;return y({name:"OpenActRequest",params:{type:13,data:(r=e==null?void 0:e.postRule)!=null?r:{}}}).then(({data:n})=>{const s=n,{pic:a}=s,o=m(s,["pic"]);return K({images:a},o)})})),ie=d(e=>{f({name:"OpenActRequest",params:{type:69,data:{eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType}}})}),re=d(e=>{f({name:"OpenActRequest",params:{type:1001,data:e}})}),oe=d(e=>{f({name:"OpenActRequest",params:{type:62,data:e}})}),se=d(e=>{f({name:"OpenActRequest",params:{type:63,data:e}})}),ae=d(()=>y({name:"OpenActRequest",params:{type:26,data:{}}})),ce=d(e=>{f({name:"OpenActRequest",params:{type:71,data:e}})}),de=d(e=>{f({name:"OpenActRequest",params:{type:64,data:e}})}),ue=d(e=>{f({name:"OpenActRequest",params:{type:58,data:e}})}),P="SHARE_EVENT_NAME";class le{}const fe=d(e=>R({name:"CommonShare",handler(r,n){window.dispatchEvent(new Event(P)),"onShareApp"in e&&e.onShareApp?n({type:12,data:e.onShareApp()}):n({type:12,data:e})}})),pe=d(e=>A(this,null,function*(){window.dispatchEvent(new Event(P)),f({name:"OpenActRequest",params:{type:58,data:e}})}));function ge(e){return window.addEventListener(P,e),()=>{window.removeEventListener(P,e)}}const he=d(e=>{f({name:"OpenActRequest",params:{type:68,data:{show:e.showMenu,showActionMode:e.panelStyle||0}}})}),we=d(()=>y({name:"OpenActRequest",params:{type:72}})),Ae=d(()=>A(this,null,function*(){f({name:"OpenActRequest",params:{type:73}})}));class ye{}const D=d(()=>A(this,null,function*(){return(yield y({name:"OpenActRequest",timeout:5e3,params:{type:31,data:{requireLogin:!1}}})).data||null})),T=(()=>{const e=new Set,r=(()=>{let n;const a=o=>{n=setTimeout(()=>A(this,null,function*(){const i=yield D();if(!i)return a(++o);e.forEach(u=>u(i)),e.clear()}),(i=>i===0?0:i<50?600:i<80?1e3:5e3)(o))};return{start(){n&&clearTimeout(n),e.size>0&&a(0)},stop(){n&&clearTimeout(n)}}})();return{addTask(n){e.add(n)},removeTask(n){e.delete(n),e.size===0&&r.stop()},triggerCheckTask(){r.start()}}})(),ve=d(()=>A(this,null,function*(){T.triggerCheckTask(),yield f({name:"OpenActRequest",params:{type:31,data:{requireLogin:!0}}})})),_e=e=>(T.addTask(e),T.triggerCheckTask(),()=>{T.removeTask(e)});t.AppBaseInfo=$,t.AppLoginInfo=ye,t.AppShareModel=le,t.BridgeCode=c,t.IS_KB_APP_ENV=x,t.KbRequirement=B,t.NoteThreadPostRule=C,t.checkForNewVersion=X,t.closeWebView=Y,t.decorateAppVersionSupport=z,t.defineAppShareModel=fe,t.defineAppSharePanelState=he,t.defineBridgeCallback=R,t.definePermissionUsage=Z,t.generateKBSign=ee,t.generatePostEditorParamsByThreadPostRule=te,t.getAppBaseInfo=q,t.getAppLoginInfo=D,t.getAppSubscribeNotifyStatus=we,t.isAppVersionSupport=V,t.onAppSharePanelShow=ge,t.onLoopCheckAppLogin=_e,t.openAppSharePanel=pe,t.openAppSubscribeNotifySettings=Ae,t.openPostEditor=ne,t.reportDAEvent=ie,t.runAction=re,t.runBridgeApi=f,t.runBridgeApiResponse=y,t.saveImageToLocal=oe,t.saveVideoToLocal=se,t.scanQRCode=ae,t.setScreenOrientation=ce,t.setWebViewTitle=de,t.shareImage=ue,t.triggerAppLogin=ve,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.7-alpha.0",
6
+ "version": "1.0.9-alpha.0",
7
7
  "description": "开吧客户端桥接",
8
8
  "author": "along",
9
9
  "main": "./dist/umd/index.js",
@@ -21,11 +21,21 @@
21
21
  "scripts": {
22
22
  "build": "rm -rf ./dist && vite build",
23
23
  "dev": "npm run build && vite",
24
- "publish": "npm run build && npm publish"
24
+ "publish": "npm run build && npm publish",
25
+ "test": "vitest"
25
26
  },
27
+ "files": [
28
+ "dist",
29
+ "package.json",
30
+ "README.md",
31
+ "examples"
32
+ ],
26
33
  "devDependencies": {
34
+ "@vitest/ui": "^4.1.2",
35
+ "jsdom": "^29.0.1",
27
36
  "typescript": "^5.0.0",
28
37
  "vite": "^5.0.0",
29
- "vite-plugin-dts": "^3.0.0"
38
+ "vite-plugin-dts": "^3.0.0",
39
+ "vitest": "^4.1.2"
30
40
  }
31
- }
41
+ }
package/LOGIN.MD DELETED
@@ -1,79 +0,0 @@
1
-
2
- ### 登录设计
3
-
4
- 核心提供
5
-
6
- 1. 静默登录方法, 如果用户未注册, 不引导注册
7
- 2. 强制登录, 如果用户未注册, 引导注册
8
-
9
- 页面打开的时候, 默认执行静默登录, 获取用户信息
10
-
11
- 1. 某些点击事件需要登录才能执行, 提供 decorateTryLogin
12
-
13
- ```js
14
- const onTapSomeButton = decorateTryLogin(() => {
15
- // Todo someting
16
- })
17
- ```
18
-
19
- 该装饰器执行逻辑为如果未登录, 则执行登录操作(比如跳转到登录页面), 并直接抛出异常, 不做 _监听登录成功后执行回调函数_ 操作
20
-
21
- > 那岂不是用户登陆完成后回到当页面还需与再点一下
22
-
23
- 没错, 的确要这么设计, 原因是为了解 如果点击了 2 个通过装饰器包装的按钮, 登陆成功后, 2 个按钮的回调事件将会全部执行(其实也有办法解决, 只是多点代码) 这种情况, 测试较真的话, 真是个问题
24
- 担心一个动作触发累计多个回调事件, 导致逻辑混乱
25
-
26
- ---
27
-
28
- A 页面 业务逻辑简单, 监听登录成功后, 自身处理重新触发登录请求
29
- B 页面 业务复杂, 需要登录成功后原地刷新
30
- C 页面 需要登录成功后才能看
31
-
32
- ---
33
-
34
- 1. uniapp 网页 适配 开吧 app 方案 (不采用中间件)
35
-
36
- A,B,C 均需要考虑停留一点时间后, 页面登录成功了
37
-
38
- A 页面 通过 onLoginReady 替代 onMounted
39
-
40
- ```js
41
- onLoginReady(() => {
42
- <!-- todo 业务代码 -->
43
- })
44
- ```
45
-
46
- B 页面需要
47
-
48
- 监听页面登录成功后执行刷新页面
49
-
50
- ```js
51
- onLoginIfNotLoggedIn(() => {
52
- <!-- 当页面登录后, 执行刷新页面 -->
53
- window.reload()
54
- })
55
- ```
56
-
57
- C 页面
58
-
59
- 当页面没有登录的时候, redirectTo 登录页面, 登录页面有个按钮, 点击唤起开吧登录, 页面加载的时候也立刻唤起开吧登录, 登录成功后 redirectTo 回来
60
-
61
- ---
62
-
63
- 2. 纯小程序架构
64
-
65
- A,B,C 均需要考虑页面加载一段时间后, app 登录完成了或者登录失败, 页面主动点击触发登录
66
-
67
- A 页面
68
- 监听登录成功执行操作
69
-
70
- B 页面
71
- 监听登录成功后, 刷新页面
72
-
73
- C 页面
74
- 页面打开的时候,如果未登录
75
- redirectTo 登录授权页面, 登录成功后 redirectTo 返回当前页面
76
-
77
- 我建议 B 和 C 的分享链接改为 有个公共的前缀页面, 该页面静默登录或者强制登录成功后再进入 B/C, 这样子可以避免页面刷一下的体验
78
-
79
- 执行登录是前往一个登录页面
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES5",
4
- "module": "CommonJS",
5
- "allowJs": true,
6
- "strict": true,
7
- "outDir": "./dist",
8
- "baseUrl": ".",
9
- "declaration": true,
10
- "lib": [
11
- "esnext",
12
- "dom"
13
- ],
14
- "sourceMap": false,
15
- "moduleResolution": "Node"
16
- },
17
- "include": [
18
- "src"
19
- ]
20
- }