@kbapp/js-bridge 1.0.8-alpha.0 → 1.0.10-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
@@ -1,73 +1,74 @@
1
- import { filterUndefinedAndNullProperties as r } from "../utils/filter-undefined-properties.js";
1
+ import { filterUndefinedAndNullProperties as b } from "../utils/filter-undefined-properties.js";
2
2
  import { BridgeCode as d } from "../lib/bridge-code.js";
3
- import b from "./lib/flutter-ds-bridge.js";
3
+ import k from "./lib/flutter-ds-bridge.js";
4
4
  var g;
5
- const f = ((e) => /(kb)/i.test(e) ? b() : {
5
+ const r = ((e) => /(kb)/i.test(e) ? k() : {
6
6
  registerHandler(u, n) {
7
7
  throw d.UNSUPPORTED_BRIDGE_ENV;
8
8
  },
9
9
  callHandler(u, n, i) {
10
10
  throw d.UNSUPPORTED_BRIDGE_ENV;
11
11
  }
12
- })((g = window == null ? void 0 : window.navigator) == null ? void 0 : g.userAgent), w = (e) => new Promise((u, n) => {
13
- var i, o, c;
12
+ })((g = window == null ? void 0 : window.navigator) == null ? void 0 : g.userAgent), B = (e) => new Promise((u, n) => {
13
+ var i, c, o;
14
14
  try {
15
- f.registerHandler(e.name, e.handler), (i = e.success) == null || i.call(e), u();
15
+ r.registerHandler(e.name, e.handler), (i = e.success) == null || i.call(e), u();
16
16
  } catch (t) {
17
- (o = e.fail) == null || o.call(e, t), n(t);
17
+ (c = e.fail) == null || c.call(e, t), n(t);
18
18
  } finally {
19
- (c = e.complete) == null || c.call(e);
19
+ (o = e.complete) == null || o.call(e);
20
20
  }
21
21
  });
22
- function B(e) {
22
+ function N(e) {
23
23
  const u = (n) => {
24
24
  let i;
25
- const o = (t) => {
25
+ const c = (t) => {
26
26
  var l;
27
27
  (!i || i === "success") && (i = "success", (l = n.success) == null || l.call(n, t));
28
- }, c = (t) => {
28
+ }, o = (t) => {
29
29
  var l;
30
30
  i || (i = "error", (l = n.fail) == null || l.call(n, t));
31
31
  };
32
32
  n.timeout && setTimeout(() => {
33
- c(d.TIMEOUT);
33
+ o(d.TIMEOUT);
34
34
  }, n.timeout);
35
35
  try {
36
- f.callHandler(n.name, n.params, (t) => {
36
+ r.callHandler(n.name, n.params, (t) => {
37
37
  let l;
38
38
  try {
39
- typeof t == "string" && /^\s*(\{|\[).*(\}|\])\s*$/.test(t) ? l = JSON.parse(t.replace(/\n/g, "\\n").replace(/\r/g, "\\r")) : l = t;
40
- } catch {
39
+ typeof t == "string" && /^\s*(\{|\[).*(\}|\])\s*$/.test(t) ? l = JSON.parse(t.trim().replace(/[\u0000-\u001F\u007F-\u009F]/g, (f) => f === `
40
+ ` ? "\\n" : f === "\r" ? "\\r" : f === " " ? "\\t" : "")) : l = t;
41
+ } catch (f) {
41
42
  l = t;
42
43
  }
43
- o(l);
44
+ c(l);
44
45
  });
45
46
  } catch (t) {
46
- c(t);
47
+ o(t);
47
48
  }
48
49
  };
49
50
  return new Promise((n, i) => {
50
51
  u({
51
52
  name: e.name,
52
- params: r(e.params),
53
+ params: b(e.params),
53
54
  timeout: e.timeout,
54
- success: (o) => {
55
- var c, t;
56
- (c = e.success) == null || c.call(e, o), (t = e.complete) == null || t.call(e), n(o);
55
+ success: (c) => {
56
+ var o, t;
57
+ (o = e.success) == null || o.call(e, c), (t = e.complete) == null || t.call(e), n(c);
57
58
  },
58
- fail: (o) => {
59
- var c, t;
60
- (c = e.fail) == null || c.call(e, o), (t = e.complete) == null || t.call(e), i(o);
59
+ fail: (c) => {
60
+ var o, t;
61
+ (o = e.fail) == null || o.call(e, c), (t = e.complete) == null || t.call(e), i(c);
61
62
  }
62
63
  });
63
64
  });
64
65
  }
65
- function N(e) {
66
- f.callHandler(e.name, e.params, (u) => {
66
+ function U(e) {
67
+ r.callHandler(e.name, e.params, (u) => {
67
68
  });
68
69
  }
69
70
  export {
70
- w as defineBridgeCallback,
71
- N as runBridgeApi,
72
- B as runBridgeApiResponse
71
+ B as defineBridgeCallback,
72
+ U as runBridgeApi,
73
+ N as runBridgeApiResponse
73
74
  };
@@ -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,56 +1,74 @@
1
- import { runBridgeApiResponse as p, runBridgeApi as g } from "../core/index.js";
2
- import { wrapAsync as i } from "../utils/wrap-async.js";
3
- class l {
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 u = i(async () => (await p({
6
- name: "OpenActRequest",
7
- timeout: 5e3,
8
- params: { type: 31, data: { requireLogin: !1 } }
9
- })).data || null), a = /* @__PURE__ */ (() => {
10
- const e = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ (() => {
11
- let t;
12
- const r = (o) => {
13
- t = setTimeout(async () => {
14
- const s = await u();
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 r(++o);
17
- e.forEach((c) => c(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 && r(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 && n.stop();
53
+ removeTask(e) {
54
+ t.delete(e), t.size === 0 && o.stop();
37
55
  },
38
56
  /** 触发定时检测是否登录成功任务 */
39
57
  triggerCheckTask() {
40
- n.start();
58
+ o.start();
41
59
  }
42
60
  };
43
- })(), m = i(async () => {
44
- a.triggerCheckTask(), await g({
61
+ })(), y = k(() => c(void 0, null, function* () {
62
+ p.triggerCheckTask(), yield d({
45
63
  name: "OpenActRequest",
46
64
  params: { type: 31, data: { requireLogin: !0 } }
47
65
  });
48
- }), f = (e) => (a.addTask(e), a.triggerCheckTask(), () => {
49
- a.removeTask(e);
66
+ })), L = (t) => (p.addTask(t), p.triggerCheckTask(), () => {
67
+ p.removeTask(t);
50
68
  });
51
69
  export {
52
- l as AppLoginInfo,
53
- u as getAppLoginInfo,
54
- f as onLoopCheckAppLogin,
55
- m as triggerAppLogin
70
+ A as AppLoginInfo,
71
+ l as getAppLoginInfo,
72
+ L as onLoopCheckAppLogin,
73
+ y as triggerAppLogin
56
74
  };
@@ -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
  };
package/dist/umd/index.js CHANGED
@@ -1 +1,2 @@
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 i={};return Object.keys(e).forEach(t=>{const o=e[t];o!=null&&(i[t]=Object.prototype.toString.call(o)==="[object Object]"?A(o):o)}),i}const p=class p{constructor(i){this.errorCode=i.errorCode,this.errorMsg=i.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,a,n)=>{var c="";typeof a=="function"&&(n=a,a={});var u={data:a===void 0?null:a};if(typeof n=="function"){var g="dscb"+window.dscb++;window[g]=n,u._dscbstub=g}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错误")}},i=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,t=(()=>{const s=[],a=setInterval(()=>{i()&&(clearInterval(a),s.forEach(n=>{e.apply(window,n)}),s.length=0)},500);return(...n)=>{s.push(n)}})();var o={default:void 0,callHandler:function(s,a,n){return i()?e(s,a,n):t(s,a,n)},register:function(s,a,n){var c=n?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){o.callHandler("_dsb.dsinit")},0)),typeof a=="object"?c._obs[s]=a:c[s]=a},registerHandler:function(s,a){this.register(s,a,!0)}};return function(){if(!window._dsf){var s={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:o,_handleMessageFromNative:function(n){var c=JSON.parse(n.data),u={id:n.callbackId,complete:!0},g=this._dsf[n.method],E=this._dsaf[n.method],U=function(T,b){u.data=T.apply(b,c),o.callHandler("_dsb.returnValue",u)},B=function(T,b){c.push(function(ge,he){u.data=ge,u.complete=he!==!1,o.callHandler("_dsb.returnValue",u)}),T.apply(b,c)};if(g)U(g,this._dsf);else if(E)B(E,this._dsaf);else{var O=n.method.split(".");if(O.length<2)return;var C=O.pop(),D=O.join("."),P=this._dsf._obs,y=P[D]||{},w=y[C];if(w&&typeof w=="function"){U(w,y);return}if(P=this._dsaf._obs,y=P[D]||{},w=y[C],w&&typeof w=="function"){B(w,y);return}}}};for(var a in s)window[a]=s[a]}}(),o},S=(e=>/(kb)/i.test(e)?L():{registerHandler(i,t){throw f.UNSUPPORTED_BRIDGE_ENV},callHandler(i,t,o){throw f.UNSUPPORTED_BRIDGE_ENV}})((V=window==null?void 0:window.navigator)==null?void 0:V.userAgent),R=e=>new Promise((i,t)=>{var o,s,a;try{S.registerHandler(e.name,e.handler),(o=e.success)==null||o.call(e),i()}catch(n){(s=e.fail)==null||s.call(e,n),t(n)}finally{(a=e.complete)==null||a.call(e)}});function h(e){const i=t=>{let o;const s=n=>{var c;(!o||o==="success")&&(o="success",(c=t.success)==null||c.call(t,n))},a=n=>{var c;o||(o="error",(c=t.fail)==null||c.call(t,n))};t.timeout&&setTimeout(()=>{a(f.TIMEOUT)},t.timeout);try{S.callHandler(t.name,t.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){a(n)}};return new Promise((t,o)=>{i({name:e.name,params:A(e.params),timeout:e.timeout,success:s=>{var a,n;(a=e.success)==null||a.call(e,s),(n=e.complete)==null||n.call(e),t(s)},fail:s=>{var a,n;(a=e.fail)==null||a.call(e,s),(n=e.complete)==null||n.call(e),o(s)}})})}function l(e){S.callHandler(e.name,e.params,i=>{})}function d(e){return async function(...t){const o=t[0]||{},{success:s,fail:a,complete:n,...c}=o;try{const u=await Promise.resolve(e(c));return s==null||s(u),u}catch(u){const g=u!=null&&u.errorCode?u:new f({errorCode:f.UNKNOWN.errorCode,errorMsg:String(u)});throw a==null||a(g),g}finally{n==null||n()}}}function H(e){const i=new Map;return function(...t){const o=JSON.stringify(t);if(i.has(o))return i.get(o);const s=e(...t);return i.set(o,s),Promise.resolve(s).catch(()=>{i.delete(o)}),s}}class j{}const m=d(H(()=>h({name:"OpenActRequest",timeout:5e3,params:{type:35,data:{}}}))),k=d(async e=>(await m()).vcode>=e.minVersion);function F(e,i){return(...t)=>k({minVersion:e.minVersion}).then(o=>o?i(...t):Promise.reject(new f({errorCode:f.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}const J=d(()=>{l({name:"OpenActRequest",params:{type:56,data:null}})}),W=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(i,t){t(I[i.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:i,...t}=e,{data:o}=await h({name:"OpenActRequest",timeout:5e3,params:{type:51,data:t}});return o});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 i=new M;return e&&Object.keys(e).forEach(t=>{i[t]=e[t]}),{hint:e==null?void 0:e.placeholder,initialText:e==null?void 0:e.initialText,audio:i.audioRqr!==2,image:i.imageMax!==0,video:i.videoRqr!==2,address:i.streetRqr!==2,asset_video:i.mediaRqr!==2,audio_must:i.audioRqr===3,image_must:i.imageMin>0,asset_video_must:i.mediaRqr===3,max_image_count:i.imageMax,min_image_count:i.imageMin,video_must:i.videoRqr===3,text_must:i.textMin>0,content_max_length:i.textMax,content_min_length:i.textMin}}const z=d(async e=>h({name:"OpenActRequest",params:{type:13,data:(e==null?void 0:e.postRule)??{}}}).then(({data:i})=>{const{pic:t,...o}=i;return{images:t,...o}})),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(()=>h({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}})}),v="SHARE_EVENT_NAME";class re{}const oe=d(e=>R({name:"CommonShare",handler(i,t){window.dispatchEvent(new Event(v)),"onShareApp"in e&&e.onShareApp?t({type:12,data:e.onShareApp()}):t({type:12,data:e})}})),se=d(async e=>{window.dispatchEvent(new Event(v)),l({name:"OpenActRequest",params:{type:58,data:e}})});function ae(e){return window.addEventListener(v,e),()=>{window.removeEventListener(v,e)}}const ce=d(e=>{l({name:"OpenActRequest",params:{type:68,data:{show:e.showMenu,showActionMode:e.panelStyle||0}}})}),de=d(()=>h({name:"OpenActRequest",params:{type:72}})),ue=d(async()=>{l({name:"OpenActRequest",params:{type:73}})});class le{}const q=d(async()=>(await h({name:"OpenActRequest",timeout:5e3,params:{type:31,data:{requireLogin:!1}}})).data||null),_=(()=>{const e=new Set,i=(()=>{let t;const o=s=>{t=setTimeout(async()=>{const n=await q();if(!n)return o(++s);e.forEach(c=>c(n)),e.clear()},(n=>n===0?0:n<50?600:n<80?1e3:5e3)(s))};return{start(){t&&clearTimeout(t),e.size>0&&o(0)},stop(){t&&clearTimeout(t)}}})();return{addTask(t){e.add(t)},removeTask(t){e.delete(t),e.size===0&&i.stop()},triggerCheckTask(){i.start()}}})(),fe=d(async()=>{_.triggerCheckTask(),await l({name:"OpenActRequest",params:{type:31,data:{requireLogin:!0}}})}),pe=e=>(_.addTask(e),_.triggerCheckTask(),()=>{_.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=J,r.closeWebView=W,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=h,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{p(c.next(d))}catch(E){_(E)}},y=d=>{try{p(c.throw(d))}catch(E){_(E)}},p=d=>d.done?h(d.value):Promise.resolve(d.value).then(R,y);p((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 f={data:s===void 0?null:s};if(typeof i=="function"){var g="dscb"+window.dscb++;window[g]=i,f._dscbstub=g}if(f=JSON.stringify(f),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(u=window.flutter_inappwebview.callHandler(""+o,f)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(u=prompt("_flutterDsbridge="+o,f)),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),f={id:i.callbackId,complete:!0},g=this._dsf[i.method],S=this._dsaf[i.method],H=function(N,M){f.data=N.apply(M,u),a.callHandler("_dsb.returnValue",f)},j=function(N,M){u.push(function(Se,Re){f.data=Se,f.complete=Re!==!1,a.callHandler("_dsb.returnValue",f)}),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.trim().replace(/[\u0000-\u001F\u007F-\u009F]/g,f=>f===`
2
+ `?"\\n":f==="\r"?"\\r":f===" "?"\\t":"")):u=i}catch(f){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 p(e){_.callHandler(e.name,e.params,r=>{})}function d(e){return function(...n){return A(this,null,function*(){const f=n[0]||{},{success:o,fail:s,complete:i}=f,u=m(f,["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(()=>{p({name:"OpenActRequest",params:{type:56,data:null}})}),Y=d(()=>{p({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=>{p({name:"OpenActRequest",params:{type:69,data:{eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType}}})}),re=d(e=>{p({name:"OpenActRequest",params:{type:1001,data:e}})}),oe=d(e=>{p({name:"OpenActRequest",params:{type:62,data:e}})}),se=d(e=>{p({name:"OpenActRequest",params:{type:63,data:e}})}),ae=d(()=>y({name:"OpenActRequest",params:{type:26,data:{}}})),ce=d(e=>{p({name:"OpenActRequest",params:{type:71,data:e}})}),de=d(e=>{p({name:"OpenActRequest",params:{type:64,data:e}})}),ue=d(e=>{p({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)),p({name:"OpenActRequest",params:{type:58,data:e}})}));function ge(e){return window.addEventListener(P,e),()=>{window.removeEventListener(P,e)}}const he=d(e=>{p({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*(){p({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 p({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=p,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.8-alpha.0",
6
+ "version": "1.0.10-alpha.0",
7
7
  "description": "开吧客户端桥接",
8
8
  "author": "along",
9
9
  "main": "./dist/umd/index.js",
@@ -24,6 +24,12 @@
24
24
  "publish": "npm run build && npm publish",
25
25
  "test": "vitest"
26
26
  },
27
+ "files": [
28
+ "dist",
29
+ "package.json",
30
+ "README.md",
31
+ "examples"
32
+ ],
27
33
  "devDependencies": {
28
34
  "@vitest/ui": "^4.1.2",
29
35
  "jsdom": "^29.0.1",
@@ -1,6 +0,0 @@
1
- {
2
- "enabledMcpjsonServers": [
3
- "wechat"
4
- ],
5
- "enableAllProjectMcpServers": true
6
- }
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
- }
package/vitest.config.ts DELETED
@@ -1,18 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
- import { resolve } from 'path'
3
-
4
- export default defineConfig({
5
- test: {
6
- globals: true,
7
- environment: 'jsdom', // 因为代码依赖 window 对象
8
- setupFiles: ['./test/setup.ts'], // 设置文件用于模拟环境
9
- coverage: {
10
- reporter: ['text', 'json', 'html'],
11
- },
12
- },
13
- resolve: {
14
- alias: {
15
- '@': resolve(__dirname, './src'),
16
- },
17
- },
18
- })