qsh-webview-sdk 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,116 +1,117 @@
1
- /**
2
- * UniApp WebView SDK 类型定义
3
- */
4
-
5
- declare namespace UniWebView {
6
- /**
7
- * 导航选项
8
- */
9
- interface NavigateOptions {
10
- /** 目标页面路径 */
11
- url: string;
12
- }
13
-
14
- /**
15
- * 返回选项
16
- */
17
- interface NavigateBackOptions {
18
- /** 返回的页面数,默认1 */
19
- delta?: number;
20
- }
21
-
22
- /**
23
- * 消息选项
24
- */
25
- interface PostMessageOptions {
26
- /** 要发送的数据 */
27
- data?: any;
28
- }
29
-
30
- /**
31
- * 环境信息
32
- */
33
- interface EnvironmentInfo {
34
- /** 是否微信小程序环境 */
35
- miniprogram?: boolean;
36
- /** 是否微信环境 */
37
- weixin?: boolean;
38
- /** 是否 APP 环境 */
39
- app?: boolean;
40
- /** 是否 Plus 环境 */
41
- plus?: boolean;
42
- /** 是否 NVUE 环境 */
43
- nvue?: boolean;
44
- /** 是否 UVUE 环境 */
45
- uvue?: boolean;
46
- /** 是否 H5 环境 */
47
- h5?: boolean;
48
- }
49
-
50
- /**
51
- * 环境对象
52
- */
53
- interface Environment {
54
- /** 是否微信小程序环境 */
55
- isWeixinMiniProgram: boolean;
56
- /** 是否 APP Plus 环境 */
57
- isAppPlus: boolean;
58
- /** 是否 NVUE 环境 */
59
- isNvue: boolean;
60
- /** 是否 UVUE 环境 */
61
- isUvue: boolean;
62
- /** 是否 UniApp 环境 */
63
- isUniApp: boolean;
64
- /** 是否 Html5Plus 环境 */
65
- isHtml5Plus: boolean;
66
- /** 环境类型 */
67
- type: 'weixin' | 'plus' | 'nvue' | 'uvue' | 'h5';
68
- }
69
-
70
- /**
71
- * WebView 对象接口
72
- */
73
- interface WebView {
74
- navigateTo(options: NavigateOptions): void;
75
- navigateBack(options?: NavigateBackOptions): void;
76
- switchTab(options: NavigateOptions): void;
77
- reLaunch(options: NavigateOptions): void;
78
- redirectTo(options: NavigateOptions): void;
79
- postMessage(options?: PostMessageOptions): void;
80
- getEnv(callback: (info: EnvironmentInfo) => void): void;
81
- }
82
-
83
- /**
84
- * Uni 对象接口
85
- */
86
- interface Uni extends WebView {
87
- /** 环境信息 */
88
- environment: Environment;
89
- /** 等待桥接准备就绪 */
90
- ready(): Promise<void>;
91
- /** WebView 对象(兼容旧版本) */
92
- webView: WebView | null;
93
- }
94
- }
95
-
96
- /**
97
- * 全局 uni 对象
98
- */
99
- declare const uni: UniWebView.Uni;
100
-
101
- /**
102
- * 模块导出
103
- */
104
- export default uni;
105
-
106
- /**
107
- * 全局声明
108
- */
109
- declare global {
110
- interface Window {
111
- uni: UniWebView.Uni;
112
- UniAppJSBridge?: boolean;
113
- }
114
- }
115
-
116
- export as namespace uni;
1
+ /**
2
+ * UniApp WebView SDK 类型定义
3
+ */
4
+
5
+ declare namespace UniWebView {
6
+ /**
7
+ * 导航选项
8
+ */
9
+ interface NavigateOptions {
10
+ /** 目标页面路径 */
11
+ url: string;
12
+ }
13
+
14
+ /**
15
+ * 返回选项
16
+ */
17
+ interface NavigateBackOptions {
18
+ /** 返回的页面数,默认1 */
19
+ delta?: number;
20
+ }
21
+
22
+ /**
23
+ * 消息选项
24
+ */
25
+ interface PostMessageOptions {
26
+ /** 要发送的数据 */
27
+ data?: any;
28
+ }
29
+
30
+ /**
31
+ * 环境信息
32
+ */
33
+ interface EnvironmentInfo {
34
+ /** 是否微信小程序环境 */
35
+ miniprogram?: boolean;
36
+ /** 是否微信环境 */
37
+ weixin?: boolean;
38
+ /** 是否 APP 环境 */
39
+ app?: boolean;
40
+ /** 是否 Plus 环境 */
41
+ plus?: boolean;
42
+ /** 是否 NVUE 环境 */
43
+ nvue?: boolean;
44
+ /** 是否 UVUE 环境 */
45
+ uvue?: boolean;
46
+ /** 是否 H5 环境 */
47
+ h5?: boolean;
48
+ }
49
+
50
+ /**
51
+ * 环境对象
52
+ */
53
+ interface Environment {
54
+ /** 是否微信小程序环境 */
55
+ isWeixinMiniProgram: boolean;
56
+ /** 是否 APP Plus 环境 */
57
+ isAppPlus: boolean;
58
+ /** 是否 NVUE 环境 */
59
+ isNvue: boolean;
60
+ /** 是否 UVUE 环境 */
61
+ isUvue: boolean;
62
+ /** 是否 UniApp 环境 */
63
+ isUniApp: boolean;
64
+ /** 是否 Html5Plus 环境 */
65
+ isHtml5Plus: boolean;
66
+ /** 环境类型 */
67
+ type: 'weixin' | 'plus' | 'nvue' | 'uvue' | 'h5';
68
+ }
69
+
70
+ /**
71
+ * WebView 对象接口
72
+ */
73
+ interface WebView {
74
+ navigateTo(options: NavigateOptions): void;
75
+ navigateBack(options?: NavigateBackOptions): void;
76
+ switchTab(options: NavigateOptions): void;
77
+ reLaunch(options: NavigateOptions): void;
78
+ redirectTo(options: NavigateOptions): void;
79
+ postMessage(options?: PostMessageOptions): void;
80
+ getEnv(callback: (info: EnvironmentInfo) => void): void;
81
+ }
82
+
83
+ /**
84
+ * Uni 对象接口
85
+ */
86
+ interface Uni extends WebView {
87
+ /** 环境信息 */
88
+ environment: Environment;
89
+ /** 等待桥接准备就绪 */
90
+ ready(): Promise<void>;
91
+ /** WebView 对象(兼容旧版本) */
92
+ webView: WebView | null;
93
+ }
94
+ }
95
+
96
+ /**
97
+ * 全局 qsh/uni 对象(默认导出为模块默认值)
98
+ */
99
+ declare const qsh: UniWebView.Uni;
100
+ declare const uni: UniWebView.Uni;
101
+
102
+ /**
103
+ * 模块导出
104
+ */
105
+ export default qsh;
106
+
107
+ /**
108
+ * 全局声明
109
+ */
110
+ declare global {
111
+ interface Window {
112
+ qsh: UniWebView.Uni;
113
+ UniAppJSBridge?: boolean;
114
+ }
115
+ }
116
+
117
+ export as namespace qsh;
@@ -1,5 +1,5 @@
1
- function u() {
2
- return window.wx && window.wx.miniProgram && /micromessenger/i.test(navigator.userAgent) && /miniProgram/i.test(navigator.userAgent);
1
+ function w() {
2
+ return !!(typeof window != "undefined" && window.__wxjs_environment === "miniprogram" || typeof window != "undefined" && window.wx && window.wx.miniProgram || /micromessenger/i.test(navigator.userAgent) && /miniProgram/i.test(navigator.userAgent));
3
3
  }
4
4
  function d() {
5
5
  return typeof window.plus != "undefined";
@@ -10,58 +10,61 @@ function c() {
10
10
  function p() {
11
11
  return window.__uniapp_x_postMessage || window.__uniapp_x_;
12
12
  }
13
- function f() {
13
+ function l() {
14
14
  return /uni-app/i.test(navigator.userAgent);
15
15
  }
16
- function _() {
16
+ function m() {
17
17
  return /Html5Plus/i.test(navigator.userAgent);
18
18
  }
19
- function S() {
20
- return p() ? "uvue" : c() ? "nvue" : u() ? "weixin" : d() ? "plus" : "h5";
19
+ function U() {
20
+ return p() ? "uvue" : c() ? "nvue" : w() ? "weixin" : d() ? "plus" : "h5";
21
21
  }
22
- const l = {
23
- isWeixinMiniProgram: u(),
22
+ const v = {
23
+ isWeixinMiniProgram: w(),
24
24
  isAppPlus: d(),
25
25
  isNvue: c(),
26
26
  isUvue: p(),
27
- isUniApp: f(),
28
- isHtml5Plus: _(),
29
- type: S()
30
- }, y = /complete|loaded|interactive/;
31
- function A() {
27
+ isUniApp: l(),
28
+ isHtml5Plus: m(),
29
+ type: U()
30
+ }, x = /complete|loaded|interactive/;
31
+ function W() {
32
32
  window.UniAppJSBridge = !0, document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady", {
33
33
  bubbles: !0,
34
34
  cancelable: !0
35
35
  }));
36
36
  }
37
- function U(e) {
38
- return f() || _() ? (window.__uniapp_x_postMessage || window.__uniapp_x_ || window.__dcloud_weex_postMessage || window.__dcloud_weex_ ? document.addEventListener("DOMContentLoaded", e) : window.plus && y.test(document.readyState) ? setTimeout(e, 0) : document.addEventListener("plusready", e), !0) : !1;
37
+ function L(e) {
38
+ return l() || m() ? (window.__uniapp_x_postMessage || window.__uniapp_x_ || window.__dcloud_weex_postMessage || window.__dcloud_weex_ ? document.addEventListener("DOMContentLoaded", e) : window.plus && x.test(document.readyState) ? setTimeout(e, 0) : document.addEventListener("plusready", e), !0) : !1;
39
39
  }
40
- function W(e) {
40
+ function R(e) {
41
41
  return window.wx && window.wx.miniProgram ? (window.WeixinJSBridge && window.WeixinJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener("WeixinJSBridgeReady", e), !0) : !1;
42
42
  }
43
- function R(e) {
44
- return U(e) || W(e) || document.addEventListener("DOMContentLoaded", e), !0;
43
+ function O(e) {
44
+ return L(e) || R(e) || (x.test(document.readyState) ? setTimeout(e, 0) : document.addEventListener("DOMContentLoaded", e)), !0;
45
45
  }
46
- function L() {
46
+ function N() {
47
47
  return new Promise((e) => {
48
48
  window.UniAppJSBridge ? e() : document.addEventListener("UniAppJSBridgeReady", e, { once: !0 });
49
49
  });
50
50
  }
51
- R(A);
51
+ let g = !1;
52
+ function f() {
53
+ g || (g = !0, O(W));
54
+ }
52
55
  let s = [];
53
- function O() {
56
+ function $() {
54
57
  if (s.length === 0 && window.plus) {
55
58
  const e = plus.webview.currentWebview();
56
59
  if (!e)
57
60
  throw new Error("plus.webview.currentWebview() is undefined");
58
- const n = e.parent(), t = n ? n.id : e.id;
59
- s.push(t);
61
+ const n = e.parent(), i = n ? n.id : e.id;
62
+ s.push(i);
60
63
  }
61
64
  return s;
62
65
  }
63
- function N(e, n) {
64
- const t = {
66
+ function J(e, n) {
67
+ const i = {
65
68
  options: {
66
69
  timestamp: +/* @__PURE__ */ new Date()
67
70
  },
@@ -75,14 +78,14 @@ function N(e, n) {
75
78
  const o = {
76
79
  type: "WEB_INVOKE_APPSERVICE",
77
80
  args: {
78
- data: t,
81
+ data: i,
79
82
  webviewIds: s
80
83
  }
81
84
  };
82
85
  window.__uniapp_x_postMessage ? window.__uniapp_x_postMessageToService(o) : window.__uniapp_x_.postMessageToService(JSON.stringify(o));
83
86
  }
84
- function $(e, n) {
85
- const t = {
87
+ function V(e, n) {
88
+ const i = {
86
89
  options: {
87
90
  timestamp: +/* @__PURE__ */ new Date()
88
91
  },
@@ -96,37 +99,37 @@ function $(e, n) {
96
99
  const o = {
97
100
  type: "WEB_INVOKE_APPSERVICE",
98
101
  args: {
99
- data: t,
102
+ data: i,
100
103
  webviewIds: s
101
104
  }
102
105
  };
103
106
  window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessageToService(o) : window.__dcloud_weex_.postMessageToService(JSON.stringify(o));
104
107
  }
105
- function J(e, n) {
106
- const t = {
108
+ function C(e, n) {
109
+ const i = {
107
110
  options: {
108
111
  timestamp: +/* @__PURE__ */ new Date()
109
112
  },
110
113
  name: e,
111
114
  arg: n
112
- }, o = O();
115
+ }, o = $();
113
116
  if (plus.webview.getWebviewById("__uniapp__service"))
114
117
  plus.webview.postMessageToUniNView({
115
118
  type: "WEB_INVOKE_APPSERVICE",
116
119
  args: {
117
- data: t,
120
+ data: i,
118
121
  webviewIds: o
119
122
  }
120
123
  }, "__uniapp__service");
121
124
  else {
122
- const r = JSON.stringify(t), B = JSON.stringify(o);
125
+ const r = JSON.stringify(i), A = JSON.stringify(o);
123
126
  plus.webview.getLaunchWebview().evalJS(
124
- `UniPlusBridge.subscribeHandler("WEB_INVOKE_APPSERVICE",${r},${B});`
127
+ `UniPlusBridge.subscribeHandler("WEB_INVOKE_APPSERVICE",${r},${A});`
125
128
  );
126
129
  }
127
130
  }
128
- function V(e, n) {
129
- const t = {
131
+ function D(e, n) {
132
+ const i = {
130
133
  options: {
131
134
  timestamp: +/* @__PURE__ */ new Date()
132
135
  },
@@ -135,72 +138,72 @@ function V(e, n) {
135
138
  };
136
139
  window.parent.postMessage({
137
140
  type: "WEB_INVOKE_APPSERVICE",
138
- data: t,
141
+ data: i,
139
142
  pageId: ""
140
143
  }, "*");
141
144
  }
142
- function i(e, n) {
143
- p() ? N(e, n) : c() ? $(e, n) : d() ? J(e, n) : V(e, n);
145
+ function t(e, n) {
146
+ p() ? J(e, n) : c() ? V(e, n) : d() ? C(e, n) : D(e, n);
144
147
  }
145
- function C(e = {}) {
148
+ function j(e = {}) {
146
149
  const { url: n } = e;
147
150
  if (window.wx && window.wx.miniProgram)
148
151
  return window.wx.miniProgram.navigateTo({
149
152
  url: n
150
153
  });
151
- i("navigateTo", {
154
+ t("navigateTo", {
152
155
  url: encodeURI(n)
153
156
  });
154
157
  }
155
- function D(e = {}) {
158
+ function z(e = {}) {
156
159
  const { delta: n = 1 } = e;
157
160
  if (window.wx && window.wx.miniProgram)
158
161
  return window.wx.miniProgram.navigateBack({
159
162
  delta: parseInt(n)
160
163
  });
161
- i("navigateBack", {
164
+ t("navigateBack", {
162
165
  delta: parseInt(n)
163
166
  });
164
167
  }
165
- function j(e = {}) {
168
+ function K(e = {}) {
166
169
  const { url: n } = e;
167
170
  if (window.wx && window.wx.miniProgram)
168
171
  return window.wx.miniProgram.switchTab({
169
172
  url: n
170
173
  });
171
- i("switchTab", {
174
+ t("switchTab", {
172
175
  url: encodeURI(n)
173
176
  });
174
177
  }
175
- function z(e = {}) {
178
+ function H(e = {}) {
176
179
  const { url: n } = e;
177
180
  if (window.wx && window.wx.miniProgram)
178
181
  return window.wx.miniProgram.reLaunch({
179
182
  url: n
180
183
  });
181
- i("reLaunch", {
184
+ t("reLaunch", {
182
185
  url: encodeURI(n)
183
186
  });
184
187
  }
185
- function K(e = {}) {
188
+ function k(e = {}) {
186
189
  const { url: n } = e;
187
190
  if (window.wx && window.wx.miniProgram)
188
191
  return window.wx.miniProgram.redirectTo({
189
192
  url: n
190
193
  });
191
- i("redirectTo", {
194
+ t("redirectTo", {
192
195
  url: encodeURI(n)
193
196
  });
194
197
  }
195
- function H(e = {}) {
198
+ function X(e = {}) {
196
199
  const { data: n = {} } = e;
197
200
  if (window.wx && window.wx.miniProgram)
198
201
  return window.wx.miniProgram.postMessage({
199
202
  data: n
200
203
  });
201
- i("postMessage", n);
204
+ t("postMessage", n);
202
205
  }
203
- function k(e) {
206
+ function q(e) {
204
207
  if (window.wx && window.wx.miniProgram && window.wx.miniProgram.getEnv)
205
208
  return window.wx.miniProgram.getEnv(e);
206
209
  e({
@@ -208,122 +211,128 @@ function k(e) {
208
211
  weixin: !0
209
212
  });
210
213
  }
211
- var m = /* @__PURE__ */ Object.freeze({
214
+ var P = /* @__PURE__ */ Object.freeze({
212
215
  __proto__: null,
213
- getEnv: k,
214
- navigateBack: D,
215
- navigateTo: C,
216
- postMessage: H,
217
- reLaunch: z,
218
- redirectTo: K,
219
- switchTab: j
216
+ getEnv: q,
217
+ navigateBack: z,
218
+ navigateTo: j,
219
+ postMessage: X,
220
+ reLaunch: H,
221
+ redirectTo: k,
222
+ switchTab: K
220
223
  });
221
- function X(e = {}) {
224
+ function F(e = {}) {
222
225
  const { url: n } = e;
223
- i("navigateTo", {
226
+ t("navigateTo", {
224
227
  url: encodeURI(n)
225
228
  });
226
229
  }
227
- function F(e = {}) {
230
+ function G(e = {}) {
228
231
  const { delta: n = 1 } = e;
229
- i("navigateBack", {
232
+ t("navigateBack", {
230
233
  delta: parseInt(n)
231
234
  });
232
235
  }
233
- function G(e = {}) {
236
+ function Y(e = {}) {
234
237
  const { url: n } = e;
235
- i("switchTab", {
238
+ t("switchTab", {
236
239
  url: encodeURI(n)
237
240
  });
238
241
  }
239
- function Y(e = {}) {
242
+ function Q(e = {}) {
240
243
  const { url: n } = e;
241
- i("reLaunch", {
244
+ t("reLaunch", {
242
245
  url: encodeURI(n)
243
246
  });
244
247
  }
245
- function q(e = {}) {
248
+ function Z(e = {}) {
246
249
  const { url: n } = e;
247
- i("redirectTo", {
250
+ t("redirectTo", {
248
251
  url: encodeURI(n)
249
252
  });
250
253
  }
251
- function Q(e = {}) {
254
+ function ee(e = {}) {
252
255
  const { data: n = {} } = e;
253
- i("postMessage", n);
256
+ t("postMessage", n);
254
257
  }
255
- function Z(e) {
258
+ function ne(e) {
256
259
  const n = {};
257
- p() ? n.uvue = !0 : c() ? n.nvue = !0 : d() && (n.plus = !0), n.app = !0, e(n);
260
+ let i = !1;
261
+ p() ? (n.uvue = !0, i = !0) : c() ? (n.nvue = !0, i = !0) : d() && (n.plus = !0, i = !0), i ? n.app = !0 : n.h5 = !0, e(n);
258
262
  }
259
- var v = /* @__PURE__ */ Object.freeze({
263
+ var E = /* @__PURE__ */ Object.freeze({
260
264
  __proto__: null,
261
- getEnv: Z,
262
- navigateBack: F,
263
- navigateTo: X,
264
- postMessage: Q,
265
- reLaunch: Y,
266
- redirectTo: q,
267
- switchTab: G
265
+ getEnv: ne,
266
+ navigateBack: G,
267
+ navigateTo: F,
268
+ postMessage: ee,
269
+ reLaunch: Q,
270
+ redirectTo: Z,
271
+ switchTab: Y
268
272
  });
269
- function w() {
270
- return u() ? m : v;
273
+ function u() {
274
+ return w() ? P : E;
271
275
  }
272
- function x(e) {
273
- return w().navigateTo(e);
276
+ function T(e) {
277
+ return u().navigateTo(e);
274
278
  }
275
- function P(e) {
276
- return w().navigateBack(e);
279
+ function M(e) {
280
+ return u().navigateBack(e);
277
281
  }
278
- function E(e) {
279
- return w().switchTab(e);
282
+ function I(e) {
283
+ return u().switchTab(e);
280
284
  }
281
- function T(e) {
282
- return w().reLaunch(e);
285
+ function b(e) {
286
+ return u().reLaunch(e);
283
287
  }
284
- function M(e) {
285
- return w().redirectTo(e);
288
+ function S(e) {
289
+ return u().redirectTo(e);
286
290
  }
287
- function I() {
288
- return u() ? m : v;
291
+ function h() {
292
+ return w() ? P : E;
289
293
  }
290
- function b(e = {}) {
291
- return I().postMessage(e);
294
+ function y(e = {}) {
295
+ return h().postMessage(e);
292
296
  }
293
- function h(e) {
294
- return I().getEnv(e);
297
+ function B(e) {
298
+ return h().getEnv(e);
295
299
  }
300
+ typeof window != "undefined" && (document.readyState === "complete" || document.readyState === "interactive" ? setTimeout(() => f(), 0) : document.addEventListener("DOMContentLoaded", () => {
301
+ f();
302
+ }));
296
303
  const a = {
297
304
  // 导航 API
298
- navigateTo: x,
299
- navigateBack: P,
300
- switchTab: E,
301
- reLaunch: T,
302
- redirectTo: M,
305
+ navigateTo: T,
306
+ navigateBack: M,
307
+ switchTab: I,
308
+ reLaunch: b,
309
+ redirectTo: S,
303
310
  // 消息 API
304
- postMessage: b,
305
- getEnv: h,
311
+ postMessage: y,
312
+ getEnv: B,
306
313
  // 环境信息
307
- environment: l,
314
+ environment: v,
308
315
  // 等待桥接准备就绪
309
- ready: L,
316
+ ready: N,
317
+ // 添加手动初始化方法(供需要手动控制的场景使用)
318
+ init: f,
310
319
  // WebView 对象(兼容旧版本)
311
320
  webView: null
312
321
  };
313
- l.isWeixinMiniProgram ? a.webView = window.wx && window.wx.miniProgram : a.webView = {
314
- navigateTo: x,
315
- navigateBack: P,
316
- switchTab: E,
317
- reLaunch: T,
318
- redirectTo: M,
319
- postMessage: b,
320
- getEnv: h
322
+ v.isWeixinMiniProgram ? a.webView = window.wx && window.wx.miniProgram : a.webView = {
323
+ navigateTo: T,
324
+ navigateBack: M,
325
+ switchTab: I,
326
+ reLaunch: b,
327
+ redirectTo: S,
328
+ postMessage: y,
329
+ getEnv: B
321
330
  };
322
- const g = typeof window.uni != "undefined" ? window.uni : {};
323
- Object.keys(g).forEach((e) => {
324
- a.hasOwnProperty(e) || (a[e] = g[e]);
331
+ const _ = typeof window.uni != "undefined" ? window.uni : {};
332
+ Object.keys(_).forEach((e) => {
333
+ a.hasOwnProperty(e) || (a[e] = _[e]);
325
334
  });
326
- typeof window != "undefined" && (window.uni = a);
335
+ typeof window != "undefined" && (window.qsh = a);
327
336
  export {
328
337
  a as default
329
338
  };