@tarojs/taro-h5 3.5.6-alpha.2 → 3.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/api/ad/index.d.ts +2 -6
  2. package/dist/api/ai/facial.d.ts +3 -9
  3. package/dist/api/ai/visual.d.ts +2 -6
  4. package/dist/api/alipay/index.d.ts +1 -3
  5. package/dist/api/base/crypto.d.ts +1 -3
  6. package/dist/api/base/debug.d.ts +3 -9
  7. package/dist/api/base/index.d.ts +1 -3
  8. package/dist/api/base/performance.d.ts +2 -6
  9. package/dist/api/base/system.d.ts +2 -8
  10. package/dist/api/base/system.js +1 -1
  11. package/dist/api/base/update.d.ts +2 -6
  12. package/dist/api/base/weapp/app-event.d.ts +12 -36
  13. package/dist/api/canvas/CanvasContext.js +1 -1
  14. package/dist/api/canvas/index.d.ts +1 -3
  15. package/dist/api/cloud/index.d.ts +9 -27
  16. package/dist/api/data-analysis/index.d.ts +4 -12
  17. package/dist/api/device/accessibility.d.ts +1 -3
  18. package/dist/api/device/battery.d.ts +1 -3
  19. package/dist/api/device/bluetooth-ble.d.ts +16 -48
  20. package/dist/api/device/bluetooth-peripheral.d.ts +3 -9
  21. package/dist/api/device/bluetooth.d.ts +13 -39
  22. package/dist/api/device/calendar.d.ts +2 -6
  23. package/dist/api/device/contact.d.ts +2 -6
  24. package/dist/api/device/crypto.d.ts +1 -3
  25. package/dist/api/device/gyroscope.d.ts +4 -12
  26. package/dist/api/device/iBeacon.d.ts +7 -21
  27. package/dist/api/device/keyboard.d.ts +4 -12
  28. package/dist/api/device/memory.d.ts +2 -6
  29. package/dist/api/device/network.d.ts +3 -9
  30. package/dist/api/device/nfc.d.ts +7 -21
  31. package/dist/api/device/screen.d.ts +6 -18
  32. package/dist/api/device/wifi.d.ts +11 -33
  33. package/dist/api/ext/index.d.ts +2 -6
  34. package/dist/api/files/index.d.ts +8 -24
  35. package/dist/api/location/index.d.ts +9 -27
  36. package/dist/api/media/EditorContext.d.ts +13 -39
  37. package/dist/api/media/audio/index.d.ts +8 -24
  38. package/dist/api/media/background-audio/BackgroundAudioManager.d.ts +4 -12
  39. package/dist/api/media/background-audio/index.d.ts +8 -24
  40. package/dist/api/media/camera.d.ts +1 -3
  41. package/dist/api/media/image/index.d.ts +4 -12
  42. package/dist/api/media/live.d.ts +2 -6
  43. package/dist/api/media/map.d.ts +1 -3
  44. package/dist/api/media/media-recorder.d.ts +1 -3
  45. package/dist/api/media/recorder.d.ts +3 -9
  46. package/dist/api/media/video/index.d.ts +5 -15
  47. package/dist/api/media/video-decoder.d.ts +1 -3
  48. package/dist/api/media/video-processing.d.ts +1 -3
  49. package/dist/api/media/voip.d.ts +14 -42
  50. package/dist/api/navigate/index.d.ts +5 -15
  51. package/dist/api/network/download.js +4 -3
  52. package/dist/api/network/mdns.d.ts +10 -30
  53. package/dist/api/network/request/index.js +5 -4
  54. package/dist/api/network/tcp.d.ts +1 -3
  55. package/dist/api/network/udp.d.ts +1 -3
  56. package/dist/api/network/upload.js +4 -3
  57. package/dist/api/open-api/account.d.ts +1 -3
  58. package/dist/api/open-api/address.d.ts +1 -3
  59. package/dist/api/open-api/authorize.d.ts +2 -6
  60. package/dist/api/open-api/card.d.ts +2 -6
  61. package/dist/api/open-api/channels-live.d.ts +6 -18
  62. package/dist/api/open-api/customer-service.d.ts +1 -3
  63. package/dist/api/open-api/facial.d.ts +4 -12
  64. package/dist/api/open-api/favorites.d.ts +2 -6
  65. package/dist/api/open-api/group.d.ts +1 -3
  66. package/dist/api/open-api/invoice.d.ts +2 -6
  67. package/dist/api/open-api/license-plate.d.ts +1 -3
  68. package/dist/api/open-api/login.d.ts +3 -9
  69. package/dist/api/open-api/red-package.d.ts +1 -3
  70. package/dist/api/open-api/settings.d.ts +2 -6
  71. package/dist/api/open-api/soter.d.ts +3 -9
  72. package/dist/api/open-api/subscribe-message.d.ts +1 -3
  73. package/dist/api/open-api/user-info.d.ts +2 -6
  74. package/dist/api/open-api/werun.d.ts +2 -6
  75. package/dist/api/payment/index.d.ts +2 -6
  76. package/dist/api/share/index.d.ts +10 -30
  77. package/dist/api/storage/background-fetch.d.ts +4 -12
  78. package/dist/api/storage/index.d.ts +2 -6
  79. package/dist/api/swan/index.d.ts +21 -63
  80. package/dist/api/taro.d.ts +1 -3
  81. package/dist/api/ui/background.d.ts +2 -6
  82. package/dist/api/ui/interaction/index.d.ts +2 -6
  83. package/dist/api/ui/menu.d.ts +1 -3
  84. package/dist/api/ui/navigation-bar/index.d.ts +3 -9
  85. package/dist/api/ui/sticky.d.ts +1 -3
  86. package/dist/api/ui/window.d.ts +1 -3
  87. package/dist/api/worker/index.d.ts +1 -3
  88. package/dist/api/wxml/index.d.ts +1 -3
  89. package/dist/index.cjs.d.ts +306 -918
  90. package/dist/index.cjs.js +142 -129
  91. package/dist/index.cjs.js.map +1 -1
  92. package/dist/index.esm.d.ts +306 -918
  93. package/dist/index.esm.js +142 -129
  94. package/dist/index.esm.js.map +1 -1
  95. package/dist/taroApis.d.ts +305 -915
  96. package/dist/utils/index.d.ts +4 -9
  97. package/dist/utils/index.js +48 -36
  98. package/package.json +4 -4
package/dist/index.cjs.js CHANGED
@@ -16,6 +16,87 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
16
16
  var Taro__default = /*#__PURE__*/_interopDefaultLegacy(Taro);
17
17
  var jsonpRetry__default = /*#__PURE__*/_interopDefaultLegacy(jsonpRetry);
18
18
 
19
+ class MethodHandler {
20
+ constructor({ name, success, fail, complete }) {
21
+ this.methodName = name;
22
+ this.__success = success;
23
+ this.__fail = fail;
24
+ this.__complete = complete;
25
+ }
26
+ success(res = {}, resolve = Promise.resolve.bind(Promise)) {
27
+ if (!res.errMsg) {
28
+ res.errMsg = `${this.methodName}:ok`;
29
+ }
30
+ typeof this.__success === 'function' && this.__success(res);
31
+ typeof this.__complete === 'function' && this.__complete(res);
32
+ return resolve(res);
33
+ }
34
+ fail(res = {}, reject = Promise.reject.bind(Promise)) {
35
+ if (!res.errMsg) {
36
+ res.errMsg = `${this.methodName}:fail`;
37
+ }
38
+ else {
39
+ res.errMsg = `${this.methodName}:fail ${res.errMsg}`;
40
+ }
41
+ console.error(res.errMsg);
42
+ typeof this.__fail === 'function' && this.__fail(res);
43
+ typeof this.__complete === 'function' && this.__complete(res);
44
+ return reject(res);
45
+ }
46
+ }
47
+ class CallbackManager {
48
+ constructor() {
49
+ this.callbacks = [];
50
+ /**
51
+ * 添加回调
52
+ * @param {{ callback: function, ctx: any } | function} opt
53
+ */
54
+ this.add = (opt) => {
55
+ if (opt)
56
+ this.callbacks.push(opt);
57
+ };
58
+ /**
59
+ * 移除回调
60
+ * @param {{ callback: function, ctx: any } | function} opt
61
+ */
62
+ this.remove = (opt) => {
63
+ if (opt) {
64
+ let pos = -1;
65
+ this.callbacks.forEach((callback, k) => {
66
+ if (callback === opt) {
67
+ pos = k;
68
+ }
69
+ });
70
+ if (pos > -1) {
71
+ this.callbacks.splice(pos, 1);
72
+ }
73
+ }
74
+ };
75
+ /**
76
+ * 获取回调函数数量
77
+ * @return {number}
78
+ */
79
+ this.count = () => {
80
+ return this.callbacks.length;
81
+ };
82
+ /**
83
+ * 触发回调
84
+ * @param {...any} args 回调的调用参数
85
+ */
86
+ this.trigger = (...args) => {
87
+ this.callbacks.forEach(opt => {
88
+ if (typeof opt === 'function') {
89
+ opt(...args);
90
+ }
91
+ else {
92
+ const { callback, ctx } = opt;
93
+ typeof callback === 'function' && callback.call(ctx, ...args);
94
+ }
95
+ });
96
+ };
97
+ }
98
+ }
99
+
19
100
  /**
20
101
  * ease-in-out的函数
21
102
  * @param t 0-1的数字
@@ -70,6 +151,7 @@ const isValidColor = (color) => {
70
151
  };
71
152
 
72
153
  /* eslint-disable prefer-promise-reject-errors */
154
+ const isProd = process.env.NODE_ENV === 'production';
73
155
  function shouldBeObject(target) {
74
156
  if (target && typeof target === 'object')
75
157
  return { flag: true };
@@ -137,54 +219,63 @@ function serializeParams(params) {
137
219
  : encodeURIComponent(params[key])}`))
138
220
  .join('&');
139
221
  }
140
- function temporarilyNotSupport(apiName) {
141
- return () => {
142
- const errMsg = `暂时不支持 API ${apiName}`;
143
- if (process.env.NODE_ENV !== 'production') {
144
- console.error(errMsg);
145
- return Promise.reject({
146
- errMsg
147
- });
222
+ function temporarilyNotSupport(name = '') {
223
+ return (option = {}, ...args) => {
224
+ const { success, fail, complete } = option;
225
+ const handle = new MethodHandler({ name, success, fail, complete });
226
+ const errMsg = '暂时不支持 API';
227
+ Taro__default["default"].eventCenter.trigger('__taroNotSupport', {
228
+ name,
229
+ args: [option, ...args],
230
+ type: 'method',
231
+ category: 'temporarily',
232
+ });
233
+ if (isProd) {
234
+ console.warn(errMsg);
235
+ return handle.success({ errMsg });
148
236
  }
149
237
  else {
150
- console.warn(errMsg);
151
- return Promise.resolve({
152
- errMsg
153
- });
238
+ return handle.fail({ errMsg });
154
239
  }
155
240
  };
156
241
  }
157
- function weixinCorpSupport(apiName) {
158
- return () => {
159
- const errMsg = `h5端当前仅在微信公众号JS-SDK环境下支持此 API ${apiName}`;
160
- if (process.env.NODE_ENV !== 'production') {
161
- console.error(errMsg);
162
- return Promise.reject({
163
- errMsg
164
- });
242
+ function weixinCorpSupport(name) {
243
+ return (option = {}, ...args) => {
244
+ const { success, fail, complete } = option;
245
+ const handle = new MethodHandler({ name, success, fail, complete });
246
+ const errMsg = 'h5 端当前仅在微信公众号 JS-SDK 环境下支持此 API';
247
+ Taro__default["default"].eventCenter.trigger('__taroNotSupport', {
248
+ name,
249
+ args: [option, ...args],
250
+ type: 'method',
251
+ category: 'weixin_corp',
252
+ });
253
+ if (isProd) {
254
+ console.warn(errMsg);
255
+ return handle.success({ errMsg });
165
256
  }
166
257
  else {
167
- console.warn(errMsg);
168
- return Promise.resolve({
169
- errMsg
170
- });
258
+ return handle.fail({ errMsg });
171
259
  }
172
260
  };
173
261
  }
174
- function permanentlyNotSupport(apiName) {
175
- return () => {
176
- const errMsg = `不支持 API ${apiName}`;
177
- if (process.env.NODE_ENV !== 'production') {
178
- console.error(errMsg);
179
- return Promise.reject({
180
- errMsg
181
- });
262
+ function permanentlyNotSupport(name = '') {
263
+ return (option = {}, ...args) => {
264
+ const { success, fail, complete } = option;
265
+ const handle = new MethodHandler({ name, success, fail, complete });
266
+ const errMsg = '不支持 API';
267
+ Taro__default["default"].eventCenter.trigger('__taroNotSupport', {
268
+ name,
269
+ args: [option, ...args],
270
+ type: 'method',
271
+ category: 'permanently',
272
+ });
273
+ if (isProd) {
274
+ console.warn(errMsg);
275
+ return handle.success({ errMsg });
182
276
  }
183
277
  else {
184
- console.warn(errMsg);
185
- return Promise.resolve({
186
- errMsg
187
- });
278
+ return handle.fail({ errMsg });
188
279
  }
189
280
  };
190
281
  }
@@ -468,87 +559,6 @@ function __classPrivateFieldSet(receiver, privateMap, value) {
468
559
  return value;
469
560
  }
470
561
 
471
- class MethodHandler {
472
- constructor({ name, success, fail, complete }) {
473
- this.methodName = name;
474
- this.__success = success;
475
- this.__fail = fail;
476
- this.__complete = complete;
477
- }
478
- success(res = {}, resolve = Promise.resolve.bind(Promise)) {
479
- if (!res.errMsg) {
480
- res.errMsg = `${this.methodName}:ok`;
481
- }
482
- typeof this.__success === 'function' && this.__success(res);
483
- typeof this.__complete === 'function' && this.__complete(res);
484
- return resolve(res);
485
- }
486
- fail(res = {}, reject = Promise.reject.bind(Promise)) {
487
- if (!res.errMsg) {
488
- res.errMsg = `${this.methodName}:fail`;
489
- }
490
- else {
491
- res.errMsg = `${this.methodName}:fail ${res.errMsg}`;
492
- }
493
- console.error(res.errMsg);
494
- typeof this.__fail === 'function' && this.__fail(res);
495
- typeof this.__complete === 'function' && this.__complete(res);
496
- return reject(res);
497
- }
498
- }
499
- class CallbackManager {
500
- constructor() {
501
- this.callbacks = [];
502
- /**
503
- * 添加回调
504
- * @param {{ callback: function, ctx: any } | function} opt
505
- */
506
- this.add = (opt) => {
507
- if (opt)
508
- this.callbacks.push(opt);
509
- };
510
- /**
511
- * 移除回调
512
- * @param {{ callback: function, ctx: any } | function} opt
513
- */
514
- this.remove = (opt) => {
515
- if (opt) {
516
- let pos = -1;
517
- this.callbacks.forEach((callback, k) => {
518
- if (callback === opt) {
519
- pos = k;
520
- }
521
- });
522
- if (pos > -1) {
523
- this.callbacks.splice(pos, 1);
524
- }
525
- }
526
- };
527
- /**
528
- * 获取回调函数数量
529
- * @return {number}
530
- */
531
- this.count = () => {
532
- return this.callbacks.length;
533
- };
534
- /**
535
- * 触发回调
536
- * @param {...any} args 回调的调用参数
537
- */
538
- this.trigger = (...args) => {
539
- this.callbacks.forEach(opt => {
540
- if (typeof opt === 'function') {
541
- opt(...args);
542
- }
543
- else {
544
- const { callback, ctx } = opt;
545
- typeof callback === 'function' && callback.call(ctx, ...args);
546
- }
547
- });
548
- };
549
- }
550
- }
551
-
552
562
  /** 跳转系统蓝牙设置页 */
553
563
  const openSystemBluetoothSetting = temporarilyNotSupport('openSystemBluetoothSetting');
554
564
  /** 跳转系统微信授权管理页 */
@@ -625,7 +635,7 @@ const getAppBaseInfo = () => {
625
635
  /** 客户端基础库版本 */
626
636
  SDKVersion: '',
627
637
  /** 是否已打开调试。可通过右上角菜单或 [Taro.setEnableDebug](/docs/apis/base/debug/setEnableDebug) 打开调试。 */
628
- enableDebug: process.env.NODE_ENV === 'development',
638
+ enableDebug: process.env.NODE_ENV !== 'production',
629
639
  /** 当前小程序运行的宿主环境 */
630
640
  // host: { appId: '' },
631
641
  /** 微信设置的语言 */
@@ -1013,7 +1023,7 @@ class CanvasContext {
1013
1023
  return radialGradient;
1014
1024
  }
1015
1025
  createLinearGradient(x0, y0, x1, y1) {
1016
- return this.createLinearGradient(x0, y0, x1, y1);
1026
+ return this.ctx.createLinearGradient(x0, y0, x1, y1);
1017
1027
  }
1018
1028
  }
1019
1029
 
@@ -2650,7 +2660,7 @@ const convertObjectUrlToBlob = url => {
2650
2660
  });
2651
2661
  };
2652
2662
 
2653
- const createDownloadTask = ({ url, header, success, error }) => {
2663
+ const createDownloadTask = ({ url, header, withCredentials = true, success, error }) => {
2654
2664
  let timeout;
2655
2665
  const apiName = 'downloadFile';
2656
2666
  const xhr = new XMLHttpRequest();
@@ -2659,7 +2669,7 @@ const createDownloadTask = ({ url, header, success, error }) => {
2659
2669
  progressUpdate: new CallbackManager()
2660
2670
  };
2661
2671
  xhr.open('GET', url, true);
2662
- xhr.withCredentials = true;
2672
+ xhr.withCredentials = !!withCredentials;
2663
2673
  xhr.responseType = 'blob';
2664
2674
  setHeader(xhr, header);
2665
2675
  xhr.onprogress = e => {
@@ -2750,12 +2760,13 @@ const createDownloadTask = ({ url, header, success, error }) => {
2750
2760
  * 下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径。使用前请注意阅读相关说明。
2751
2761
  * 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
2752
2762
  */
2753
- const downloadFile = ({ url, header, success, fail, complete }) => {
2763
+ const downloadFile = ({ url, header, withCredentials, success, fail, complete }) => {
2754
2764
  let task;
2755
2765
  const result = new Promise((resolve, reject) => {
2756
2766
  task = createDownloadTask({
2757
2767
  url,
2758
2768
  header,
2769
+ withCredentials,
2759
2770
  success: res => {
2760
2771
  success && success(res);
2761
2772
  complete && complete(res);
@@ -2877,15 +2888,14 @@ function _request(options) {
2877
2888
  for (const key of response.headers.keys()) {
2878
2889
  res.header[key] = response.headers.get(key);
2879
2890
  }
2880
- if (!response.ok) {
2881
- throw response;
2882
- }
2883
2891
  if (options.responseType === 'arraybuffer') {
2884
2892
  return response.arrayBuffer();
2885
2893
  }
2886
2894
  if (res.statusCode !== 204) {
2887
2895
  if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
2888
- return response.json();
2896
+ return response.json().catch(() => {
2897
+ return null;
2898
+ });
2889
2899
  }
2890
2900
  }
2891
2901
  if (options.responseType === 'text' || options.dataType === 'text') {
@@ -2902,6 +2912,8 @@ function _request(options) {
2902
2912
  .catch(err => {
2903
2913
  typeof fail === 'function' && fail(err);
2904
2914
  typeof complete === 'function' && complete(res);
2915
+ err.statusCode = res.statusCode;
2916
+ err.errMsg = err.message;
2905
2917
  return Promise.reject(err);
2906
2918
  });
2907
2919
  }
@@ -2918,7 +2930,7 @@ const createTCPSocket = temporarilyNotSupport('createTCPSocket');
2918
2930
  // UDP 通信
2919
2931
  const createUDPSocket = temporarilyNotSupport('createUDPSocket');
2920
2932
 
2921
- const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, success, error }) => {
2933
+ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, withCredentials = true, success, error }) => {
2922
2934
  let timeoutInter;
2923
2935
  let formKey;
2924
2936
  const apiName = 'uploadFile';
@@ -2929,7 +2941,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
2929
2941
  progressUpdate: new CallbackManager()
2930
2942
  };
2931
2943
  xhr.open('POST', url);
2932
- xhr.withCredentials = true;
2944
+ xhr.withCredentials = !!withCredentials;
2933
2945
  setHeader(xhr, header);
2934
2946
  for (formKey in formData) {
2935
2947
  form.append(formKey, formData[formKey]);
@@ -3035,7 +3047,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
3035
3047
  /**
3036
3048
  * 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。
3037
3049
  */
3038
- const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, success, fail, complete }) => {
3050
+ const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, withCredentials, success, fail, complete }) => {
3039
3051
  let task;
3040
3052
  const result = new Promise((resolve, reject) => {
3041
3053
  task = createUploadTask({
@@ -3046,6 +3058,7 @@ const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName,
3046
3058
  formData,
3047
3059
  timeout,
3048
3060
  fileName,
3061
+ withCredentials,
3049
3062
  success: res => {
3050
3063
  success && success(res);
3051
3064
  complete && complete(res);