@tarojs/taro-h5 3.6.7-alpha.0 → 3.6.7-alpha.1

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 (214) hide show
  1. package/dist/api/ad/index.js +2 -2
  2. package/dist/api/ad/index.js.map +1 -1
  3. package/dist/api/ai/facial.js +3 -3
  4. package/dist/api/ai/facial.js.map +1 -1
  5. package/dist/api/ai/visual.js +2 -2
  6. package/dist/api/ai/visual.js.map +1 -1
  7. package/dist/api/alipay/index.js +1 -1
  8. package/dist/api/alipay/index.js.map +1 -1
  9. package/dist/api/base/crypto.js +1 -1
  10. package/dist/api/base/crypto.js.map +1 -1
  11. package/dist/api/base/debug.js +3 -3
  12. package/dist/api/base/debug.js.map +1 -1
  13. package/dist/api/base/performance.js +2 -2
  14. package/dist/api/base/performance.js.map +1 -1
  15. package/dist/api/base/system.js +2 -2
  16. package/dist/api/base/system.js.map +1 -1
  17. package/dist/api/base/update.js +2 -2
  18. package/dist/api/base/update.js.map +1 -1
  19. package/dist/api/base/weapp/app-event.js +5 -5
  20. package/dist/api/base/weapp/app-event.js.map +1 -1
  21. package/dist/api/canvas/index.js +1 -1
  22. package/dist/api/canvas/index.js.map +1 -1
  23. package/dist/api/data-analysis/index.js +4 -4
  24. package/dist/api/data-analysis/index.js.map +1 -1
  25. package/dist/api/device/accelerometer.js +1 -1
  26. package/dist/api/device/accelerometer.js.map +1 -1
  27. package/dist/api/device/accessibility.js +1 -1
  28. package/dist/api/device/accessibility.js.map +1 -1
  29. package/dist/api/device/battery.js +1 -1
  30. package/dist/api/device/battery.js.map +1 -1
  31. package/dist/api/device/bluetooth-ble.js +16 -16
  32. package/dist/api/device/bluetooth-ble.js.map +1 -1
  33. package/dist/api/device/bluetooth-peripheral.js +3 -3
  34. package/dist/api/device/bluetooth-peripheral.js.map +1 -1
  35. package/dist/api/device/bluetooth.js +13 -13
  36. package/dist/api/device/bluetooth.js.map +1 -1
  37. package/dist/api/device/calendar.d.ts +3 -2
  38. package/dist/api/device/calendar.js +142 -3
  39. package/dist/api/device/calendar.js.map +1 -1
  40. package/dist/api/device/compass.js +1 -1
  41. package/dist/api/device/compass.js.map +1 -1
  42. package/dist/api/device/contact.js +2 -2
  43. package/dist/api/device/contact.js.map +1 -1
  44. package/dist/api/device/crypto.js +1 -1
  45. package/dist/api/device/crypto.js.map +1 -1
  46. package/dist/api/device/gyroscope.js +4 -4
  47. package/dist/api/device/gyroscope.js.map +1 -1
  48. package/dist/api/device/iBeacon.js +7 -7
  49. package/dist/api/device/iBeacon.js.map +1 -1
  50. package/dist/api/device/keyboard.js +4 -4
  51. package/dist/api/device/keyboard.js.map +1 -1
  52. package/dist/api/device/memory.js +2 -2
  53. package/dist/api/device/memory.js.map +1 -1
  54. package/dist/api/device/motion.js +1 -1
  55. package/dist/api/device/motion.js.map +1 -1
  56. package/dist/api/device/network.js +3 -3
  57. package/dist/api/device/network.js.map +1 -1
  58. package/dist/api/device/nfc.js +7 -7
  59. package/dist/api/device/nfc.js.map +1 -1
  60. package/dist/api/device/scan.js +1 -1
  61. package/dist/api/device/scan.js.map +1 -1
  62. package/dist/api/device/screen.js +6 -6
  63. package/dist/api/device/screen.js.map +1 -1
  64. package/dist/api/device/wifi.js +12 -12
  65. package/dist/api/device/wifi.js.map +1 -1
  66. package/dist/api/ext/index.js +2 -2
  67. package/dist/api/ext/index.js.map +1 -1
  68. package/dist/api/files/index.js +8 -8
  69. package/dist/api/files/index.js.map +1 -1
  70. package/dist/api/index.js +7 -2
  71. package/dist/api/index.js.map +1 -1
  72. package/dist/api/location/getLocation.js +1 -1
  73. package/dist/api/location/getLocation.js.map +1 -1
  74. package/dist/api/location/index.js +10 -10
  75. package/dist/api/location/index.js.map +1 -1
  76. package/dist/api/media/audio/index.js +8 -8
  77. package/dist/api/media/audio/index.js.map +1 -1
  78. package/dist/api/media/background-audio/index.js +8 -8
  79. package/dist/api/media/background-audio/index.js.map +1 -1
  80. package/dist/api/media/camera.js +1 -1
  81. package/dist/api/media/camera.js.map +1 -1
  82. package/dist/api/media/image/chooseImage.d.ts +1 -0
  83. package/dist/api/media/image/chooseImage.js +28 -71
  84. package/dist/api/media/image/chooseImage.js.map +1 -1
  85. package/dist/api/media/image/index.d.ts +4 -3
  86. package/dist/api/media/image/index.js +8 -9
  87. package/dist/api/media/image/index.js.map +1 -1
  88. package/dist/api/media/image/saveImageToPhotosAlbum.d.ts +3 -0
  89. package/dist/api/media/image/saveImageToPhotosAlbum.js +30 -0
  90. package/dist/api/media/image/saveImageToPhotosAlbum.js.map +1 -0
  91. package/dist/api/media/index.js +2 -2
  92. package/dist/api/media/live.js +2 -2
  93. package/dist/api/media/live.js.map +1 -1
  94. package/dist/api/media/map.js +1 -1
  95. package/dist/api/media/map.js.map +1 -1
  96. package/dist/api/media/media-recorder.js +1 -1
  97. package/dist/api/media/media-recorder.js.map +1 -1
  98. package/dist/api/media/recorder.js +3 -3
  99. package/dist/api/media/recorder.js.map +1 -1
  100. package/dist/api/media/video/chooseMedia.d.ts +6 -0
  101. package/dist/api/media/video/chooseMedia.js +208 -0
  102. package/dist/api/media/video/chooseMedia.js.map +1 -0
  103. package/dist/api/media/video/chooseVideo.d.ts +7 -0
  104. package/dist/api/media/video/chooseVideo.js +44 -0
  105. package/dist/api/media/video/chooseVideo.js.map +1 -0
  106. package/dist/api/media/video/getVideoInfo.d.ts +3 -0
  107. package/dist/api/media/video/getVideoInfo.js +63 -0
  108. package/dist/api/media/video/getVideoInfo.js.map +1 -0
  109. package/dist/api/media/video/index.d.ts +5 -8
  110. package/dist/api/media/video/index.js +8 -67
  111. package/dist/api/media/video/index.js.map +1 -1
  112. package/dist/api/media/video/saveVideoToPhotosAlbum.d.ts +3 -0
  113. package/dist/api/media/video/saveVideoToPhotosAlbum.js +30 -0
  114. package/dist/api/media/video/saveVideoToPhotosAlbum.js.map +1 -0
  115. package/dist/api/media/video-decoder.js +1 -1
  116. package/dist/api/media/video-decoder.js.map +1 -1
  117. package/dist/api/media/video-processing.js +1 -1
  118. package/dist/api/media/video-processing.js.map +1 -1
  119. package/dist/api/media/voip.js +14 -14
  120. package/dist/api/media/voip.js.map +1 -1
  121. package/dist/api/navigate/index.js +5 -5
  122. package/dist/api/navigate/index.js.map +1 -1
  123. package/dist/api/network/mdns.js +10 -10
  124. package/dist/api/network/mdns.js.map +1 -1
  125. package/dist/api/network/tcp.js +1 -1
  126. package/dist/api/network/tcp.js.map +1 -1
  127. package/dist/api/network/udp.js +1 -1
  128. package/dist/api/network/udp.js.map +1 -1
  129. package/dist/api/open-api/account.js +1 -1
  130. package/dist/api/open-api/account.js.map +1 -1
  131. package/dist/api/open-api/address.js +1 -1
  132. package/dist/api/open-api/address.js.map +1 -1
  133. package/dist/api/open-api/authorize.js +2 -2
  134. package/dist/api/open-api/authorize.js.map +1 -1
  135. package/dist/api/open-api/card.js +2 -2
  136. package/dist/api/open-api/card.js.map +1 -1
  137. package/dist/api/open-api/channels-live.js +6 -6
  138. package/dist/api/open-api/channels-live.js.map +1 -1
  139. package/dist/api/open-api/customer-service.js +1 -1
  140. package/dist/api/open-api/customer-service.js.map +1 -1
  141. package/dist/api/open-api/facial.js +4 -4
  142. package/dist/api/open-api/facial.js.map +1 -1
  143. package/dist/api/open-api/favorites.js +3 -3
  144. package/dist/api/open-api/favorites.js.map +1 -1
  145. package/dist/api/open-api/group.js +1 -1
  146. package/dist/api/open-api/group.js.map +1 -1
  147. package/dist/api/open-api/invoice.js +2 -2
  148. package/dist/api/open-api/invoice.js.map +1 -1
  149. package/dist/api/open-api/license-plate.js +1 -1
  150. package/dist/api/open-api/license-plate.js.map +1 -1
  151. package/dist/api/open-api/login.js +3 -3
  152. package/dist/api/open-api/login.js.map +1 -1
  153. package/dist/api/open-api/red-package.js +1 -1
  154. package/dist/api/open-api/red-package.js.map +1 -1
  155. package/dist/api/open-api/settings.js +2 -2
  156. package/dist/api/open-api/settings.js.map +1 -1
  157. package/dist/api/open-api/soter.js +3 -3
  158. package/dist/api/open-api/soter.js.map +1 -1
  159. package/dist/api/open-api/subscribe-message.js +2 -2
  160. package/dist/api/open-api/subscribe-message.js.map +1 -1
  161. package/dist/api/open-api/user-info.js +2 -2
  162. package/dist/api/open-api/user-info.js.map +1 -1
  163. package/dist/api/open-api/werun.js +2 -2
  164. package/dist/api/open-api/werun.js.map +1 -1
  165. package/dist/api/payment/index.js +2 -2
  166. package/dist/api/payment/index.js.map +1 -1
  167. package/dist/api/qq/index.js +1 -1
  168. package/dist/api/qq/index.js.map +1 -1
  169. package/dist/api/share/index.d.ts +10 -0
  170. package/dist/api/share/index.js +21 -11
  171. package/dist/api/share/index.js.map +1 -1
  172. package/dist/api/storage/background-fetch.js +4 -4
  173. package/dist/api/storage/background-fetch.js.map +1 -1
  174. package/dist/api/storage/index.js +2 -2
  175. package/dist/api/storage/index.js.map +1 -1
  176. package/dist/api/swan/index.js +21 -21
  177. package/dist/api/swan/index.js.map +1 -1
  178. package/dist/api/taro.js +1 -1
  179. package/dist/api/taro.js.map +1 -1
  180. package/dist/api/ui/background.js +2 -2
  181. package/dist/api/ui/background.js.map +1 -1
  182. package/dist/api/ui/interaction/index.d.ts +1 -1
  183. package/dist/api/ui/interaction/index.js +4 -4
  184. package/dist/api/ui/interaction/index.js.map +1 -1
  185. package/dist/api/ui/menu.js +1 -1
  186. package/dist/api/ui/menu.js.map +1 -1
  187. package/dist/api/ui/navigation-bar/index.js +3 -3
  188. package/dist/api/ui/navigation-bar/index.js.map +1 -1
  189. package/dist/api/ui/sticky.js +1 -1
  190. package/dist/api/ui/sticky.js.map +1 -1
  191. package/dist/api/ui/window.js +2 -2
  192. package/dist/api/ui/window.js.map +1 -1
  193. package/dist/api/worker/index.js +1 -1
  194. package/dist/api/worker/index.js.map +1 -1
  195. package/dist/api/wxml/IntersectionObserver.d.ts +1 -1
  196. package/dist/api/wxml/IntersectionObserver.js +0 -1
  197. package/dist/api/wxml/IntersectionObserver.js.map +1 -1
  198. package/dist/api/wxml/MediaQueryObserver.d.ts +1 -1
  199. package/dist/api/wxml/MediaQueryObserver.js.map +1 -1
  200. package/dist/index.cjs.d.ts +24 -11
  201. package/dist/index.cjs.js +2262 -1853
  202. package/dist/index.cjs.js.map +1 -1
  203. package/dist/index.esm.d.ts +24 -11
  204. package/dist/index.esm.js +2241 -1851
  205. package/dist/index.esm.js.map +1 -1
  206. package/dist/index.js +7 -2
  207. package/dist/index.js.map +1 -1
  208. package/dist/utils/helper.d.ts +2 -0
  209. package/dist/utils/helper.js +11 -0
  210. package/dist/utils/helper.js.map +1 -0
  211. package/dist/utils/index.d.ts +1 -0
  212. package/dist/utils/index.js +1 -0
  213. package/dist/utils/index.js.map +1 -1
  214. package/package.json +7 -6
package/dist/index.cjs.js CHANGED
@@ -9,13 +9,34 @@ var utils = require('@tarojs/router/dist/utils');
9
9
  var runtime = require('@tarojs/runtime');
10
10
  var base64Js = require('base64-js');
11
11
  var navigate = require('@tarojs/router/dist/utils/navigate');
12
- var lodashEs = require('lodash-es');
12
+ var isNil = require('lodash-es/isNil');
13
13
  var queryString = require('query-string');
14
+ var throttle = require('lodash-es/throttle');
15
+ var ics = require('ics');
14
16
  var components = require('@tarojs/components/dist/components');
15
17
  require('whatwg-fetch');
16
18
  require('abortcontroller-polyfill/dist/abortcontroller-polyfill-only');
17
19
  var jsonpRetry = require('jsonp-retry');
18
20
 
21
+ function _interopNamespaceDefault(e) {
22
+ var n = Object.create(null);
23
+ if (e) {
24
+ Object.keys(e).forEach(function (k) {
25
+ if (k !== 'default') {
26
+ var d = Object.getOwnPropertyDescriptor(e, k);
27
+ Object.defineProperty(n, k, d.get ? d : {
28
+ enumerable: true,
29
+ get: function () { return e[k]; }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ n.default = e;
35
+ return Object.freeze(n);
36
+ }
37
+
38
+ var ics__namespace = /*#__PURE__*/_interopNamespaceDefault(ics);
39
+
19
40
  class MethodHandler {
20
41
  constructor({ name, success, fail, complete }) {
21
42
  this.isHandlerError = false;
@@ -105,6 +126,15 @@ const getTimingFunc = (easeFunc, frameCnt) => {
105
126
  };
106
127
  };
107
128
 
129
+ function createDownload(url = '', download = '') {
130
+ const link = document.createElement('a');
131
+ link.style.display = 'none';
132
+ link.href = url;
133
+ link.download = download;
134
+ // Note: 需要注意,该方案不能监听用户取消或禁止下载等操作,亦不能获取下载成功或失败状态
135
+ link.click();
136
+ }
137
+
108
138
  const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/;
109
139
  const isValidColor = (color) => {
110
140
  return VALID_COLOR_REG.test(color);
@@ -282,32 +312,32 @@ function getCurrentPath() {
282
312
  }
283
313
 
284
314
  // 广告
285
- const createRewardedVideoAd = temporarilyNotSupport('createRewardedVideoAd');
286
- const createInterstitialAd = temporarilyNotSupport('createInterstitialAd');
315
+ const createRewardedVideoAd = /* @__PURE__ */ temporarilyNotSupport('createRewardedVideoAd');
316
+ const createInterstitialAd = /* @__PURE__ */ temporarilyNotSupport('createInterstitialAd');
287
317
 
288
318
  // 人脸识别
289
- const stopFaceDetect = temporarilyNotSupport('stopFaceDetect');
290
- const initFaceDetect = temporarilyNotSupport('initFaceDetect');
291
- const faceDetect = temporarilyNotSupport('faceDetect');
319
+ const stopFaceDetect = /* @__PURE__ */ temporarilyNotSupport('stopFaceDetect');
320
+ const initFaceDetect = /* @__PURE__ */ temporarilyNotSupport('initFaceDetect');
321
+ const faceDetect = /* @__PURE__ */ temporarilyNotSupport('faceDetect');
292
322
 
293
323
  // 判断支持版本
294
- const isVKSupport = temporarilyNotSupport('isVKSupport');
324
+ const isVKSupport = /* @__PURE__ */ temporarilyNotSupport('isVKSupport');
295
325
  // 视觉算法
296
- const createVKSession = temporarilyNotSupport('createVKSession');
326
+ const createVKSession = /* @__PURE__ */ temporarilyNotSupport('createVKSession');
297
327
 
298
328
  // AliPay
299
- const getOpenUserInfo = temporarilyNotSupport('getOpenUserInfo');
329
+ const getOpenUserInfo = /* @__PURE__ */ temporarilyNotSupport('getOpenUserInfo');
300
330
 
301
331
  // 加密
302
- const getUserCryptoManager = temporarilyNotSupport('getUserCryptoManager');
332
+ const getUserCryptoManager = /* @__PURE__ */ temporarilyNotSupport('getUserCryptoManager');
303
333
 
304
- const setEnableDebug = temporarilyNotSupport('setEnableDebug');
305
- const getRealtimeLogManager = temporarilyNotSupport('getRealtimeLogManager');
306
- const getLogManager = temporarilyNotSupport('getLogManager');
334
+ const setEnableDebug = /* @__PURE__ */ temporarilyNotSupport('setEnableDebug');
335
+ const getRealtimeLogManager = /* @__PURE__ */ temporarilyNotSupport('getRealtimeLogManager');
336
+ const getLogManager = /* @__PURE__ */ temporarilyNotSupport('getLogManager');
307
337
 
308
338
  // 性能
309
- const reportPerformance = temporarilyNotSupport('reportPerformance');
310
- const getPerformance = temporarilyNotSupport('getPerformance');
339
+ const reportPerformance = /* @__PURE__ */ temporarilyNotSupport('reportPerformance');
340
+ const getPerformance = /* @__PURE__ */ temporarilyNotSupport('getPerformance');
311
341
 
312
342
  /******************************************************************************
313
343
  Copyright (c) Microsoft Corporation.
@@ -604,9 +634,9 @@ function __classPrivateFieldIn(state, receiver) {
604
634
  }
605
635
 
606
636
  /** 跳转系统蓝牙设置页 */
607
- const openSystemBluetoothSetting = temporarilyNotSupport('openSystemBluetoothSetting');
637
+ const openSystemBluetoothSetting = /* @__PURE__ */ temporarilyNotSupport('openSystemBluetoothSetting');
608
638
  /** 跳转系统微信授权管理页 */
609
- const openAppAuthorizeSetting = temporarilyNotSupport('openAppAuthorizeSetting');
639
+ const openAppAuthorizeSetting = /* @__PURE__ */ temporarilyNotSupport('openAppAuthorizeSetting');
610
640
  /** 获取窗口信息 */
611
641
  const getWindowInfo = () => {
612
642
  const info = {
@@ -788,8 +818,8 @@ const getSystemInfo = (options = {}) => __awaiter(void 0, void 0, void 0, functi
788
818
  });
789
819
 
790
820
  // 更新
791
- const updateWeChatApp = temporarilyNotSupport('updateWeChatApp');
792
- const getUpdateManager = temporarilyNotSupport('getUpdateManager');
821
+ const updateWeChatApp = /* @__PURE__ */ temporarilyNotSupport('updateWeChatApp');
822
+ const getUpdateManager = /* @__PURE__ */ temporarilyNotSupport('getUpdateManager');
793
823
 
794
824
  const unhandledRejectionCallbackManager = new CallbackManager();
795
825
  const themeChangeCallbackManager = new CallbackManager();
@@ -849,7 +879,7 @@ const onUnhandledRejection = callback => {
849
879
  const onThemeChange = callback => {
850
880
  themeChangeCallbackManager.add(callback);
851
881
  if (themeChangeCallbackManager.count() === 1) {
852
- if (lodashEs.isNil(themeMatchMedia)) {
882
+ if (isNil(themeMatchMedia)) {
853
883
  themeMatchMedia = window.matchMedia('(prefers-color-scheme: light)');
854
884
  }
855
885
  themeMatchMedia.addEventListener('change', themeChangeListener);
@@ -867,8 +897,8 @@ const onError = callback => {
867
897
  window.addEventListener('error', errorListener);
868
898
  }
869
899
  };
870
- const onAudioInterruptionEnd = temporarilyNotSupport('onAudioInterruptionEnd');
871
- const onAudioInterruptionBegin = temporarilyNotSupport('onAudioInterruptionBegin');
900
+ const onAudioInterruptionEnd = /* @__PURE__ */ temporarilyNotSupport('onAudioInterruptionEnd');
901
+ const onAudioInterruptionBegin = /* @__PURE__ */ temporarilyNotSupport('onAudioInterruptionBegin');
872
902
  const onAppShow = callback => {
873
903
  appShowCallbackManager.add(callback);
874
904
  if (appShowCallbackManager.count() === 1) {
@@ -890,7 +920,7 @@ const offUnhandledRejection = callback => {
890
920
  const offThemeChange = callback => {
891
921
  themeChangeCallbackManager.remove(callback);
892
922
  if (themeChangeCallbackManager.count() === 0) {
893
- if (lodashEs.isNil(themeMatchMedia)) {
923
+ if (isNil(themeMatchMedia)) {
894
924
  themeMatchMedia = window.matchMedia('(prefers-color-scheme: light)');
895
925
  }
896
926
  themeMatchMedia.removeEventListener('change', themeChangeListener);
@@ -909,8 +939,8 @@ const offError = callback => {
909
939
  window.removeEventListener('error', errorListener);
910
940
  }
911
941
  };
912
- const offAudioInterruptionEnd = temporarilyNotSupport('offAudioInterruptionEnd');
913
- const offAudioInterruptionBegin = temporarilyNotSupport('offAudioInterruptionBegin');
942
+ const offAudioInterruptionEnd = /* @__PURE__ */ temporarilyNotSupport('offAudioInterruptionEnd');
943
+ const offAudioInterruptionBegin = /* @__PURE__ */ temporarilyNotSupport('offAudioInterruptionBegin');
914
944
  const offAppShow = callback => {
915
945
  appShowCallbackManager.remove(callback);
916
946
  if (appShowCallbackManager.count() === 0) {
@@ -1231,7 +1261,7 @@ const canvasGetImageData = ({ canvasId, success, fail, complete, x, y, width, he
1231
1261
 
1232
1262
  // 画布
1233
1263
  /** 创建离屏 canvas 实例 */
1234
- const createOffscreenCanvas = temporarilyNotSupport('createOffscreenCanvas');
1264
+ const createOffscreenCanvas = /* @__PURE__ */ temporarilyNotSupport('createOffscreenCanvas');
1235
1265
 
1236
1266
  class cloud {
1237
1267
  constructor() {
@@ -1254,10 +1284,10 @@ class cloud {
1254
1284
  }
1255
1285
  }
1256
1286
 
1257
- const reportMonitor = temporarilyNotSupport('reportMonitor');
1258
- const reportAnalytics = temporarilyNotSupport('reportAnalytics');
1259
- const reportEvent = temporarilyNotSupport('reportEvent');
1260
- const getExptInfoSync = temporarilyNotSupport('getExptInfoSync');
1287
+ const reportMonitor = /* @__PURE__ */ temporarilyNotSupport('reportMonitor');
1288
+ const reportAnalytics = /* @__PURE__ */ temporarilyNotSupport('reportAnalytics');
1289
+ const reportEvent = /* @__PURE__ */ temporarilyNotSupport('reportEvent');
1290
+ const getExptInfoSync = /* @__PURE__ */ temporarilyNotSupport('getExptInfoSync');
1261
1291
 
1262
1292
  const callbackManager$3 = new CallbackManager();
1263
1293
  let devicemotionListener;
@@ -1301,7 +1331,7 @@ const startAccelerometer = ({ interval = 'normal', success, fail, complete } = {
1301
1331
  if (devicemotionListener) {
1302
1332
  stopAccelerometer();
1303
1333
  }
1304
- devicemotionListener = lodashEs.throttle((evt) => {
1334
+ devicemotionListener = throttle((evt) => {
1305
1335
  var _a, _b, _c;
1306
1336
  callbackManager$3.trigger({
1307
1337
  x: ((_a = evt.acceleration) === null || _a === void 0 ? void 0 : _a.x) || 0,
@@ -1334,11 +1364,11 @@ const offAccelerometerChange = callback => {
1334
1364
  };
1335
1365
 
1336
1366
  // 无障碍
1337
- const checkIsOpenAccessibility = temporarilyNotSupport('checkIsOpenAccessibility');
1367
+ const checkIsOpenAccessibility = /* @__PURE__ */ temporarilyNotSupport('checkIsOpenAccessibility');
1338
1368
 
1339
1369
  // 电量
1340
1370
  // Note: 浏览器标准下不支持,其他实现方案不准确,不建议开发者使用
1341
- const getBatteryInfoSync = permanentlyNotSupport('getBatteryInfoSync');
1371
+ const getBatteryInfoSync = /* @__PURE__ */ permanentlyNotSupport('getBatteryInfoSync');
1342
1372
  const getBatteryInfo = ({ success, fail, complete } = {}) => __awaiter(void 0, void 0, void 0, function* () {
1343
1373
  var _a;
1344
1374
  const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete });
@@ -1358,52 +1388,188 @@ const getBatteryInfo = ({ success, fail, complete } = {}) => __awaiter(void 0, v
1358
1388
  });
1359
1389
 
1360
1390
  // 蓝牙-通用
1361
- const stopBluetoothDevicesDiscovery = temporarilyNotSupport('stopBluetoothDevicesDiscovery');
1362
- const startBluetoothDevicesDiscovery = temporarilyNotSupport('startBluetoothDevicesDiscovery');
1363
- const openBluetoothAdapter = temporarilyNotSupport('openBluetoothAdapter');
1364
- const onBluetoothDeviceFound = temporarilyNotSupport('onBluetoothDeviceFound');
1365
- const onBluetoothAdapterStateChange = temporarilyNotSupport('onBluetoothAdapterStateChange');
1366
- const offBluetoothDeviceFound = temporarilyNotSupport('offBluetoothDeviceFound');
1367
- const offBluetoothAdapterStateChange = temporarilyNotSupport('offBluetoothAdapterStateChange');
1368
- const makeBluetoothPair = temporarilyNotSupport('makeBluetoothPair');
1369
- const isBluetoothDevicePaired = temporarilyNotSupport('isBluetoothDevicePaired');
1370
- const getConnectedBluetoothDevices = temporarilyNotSupport('getConnectedBluetoothDevices');
1371
- const getBluetoothDevices = temporarilyNotSupport('getBluetoothDevices');
1372
- const getBluetoothAdapterState = temporarilyNotSupport('getBluetoothAdapterState');
1373
- const closeBluetoothAdapter = temporarilyNotSupport('closeBluetoothAdapter');
1391
+ const stopBluetoothDevicesDiscovery = /* @__PURE__ */ temporarilyNotSupport('stopBluetoothDevicesDiscovery');
1392
+ const startBluetoothDevicesDiscovery = /* @__PURE__ */ temporarilyNotSupport('startBluetoothDevicesDiscovery');
1393
+ const openBluetoothAdapter = /* @__PURE__ */ temporarilyNotSupport('openBluetoothAdapter');
1394
+ const onBluetoothDeviceFound = /* @__PURE__ */ temporarilyNotSupport('onBluetoothDeviceFound');
1395
+ const onBluetoothAdapterStateChange = /* @__PURE__ */ temporarilyNotSupport('onBluetoothAdapterStateChange');
1396
+ const offBluetoothDeviceFound = /* @__PURE__ */ temporarilyNotSupport('offBluetoothDeviceFound');
1397
+ const offBluetoothAdapterStateChange = /* @__PURE__ */ temporarilyNotSupport('offBluetoothAdapterStateChange');
1398
+ const makeBluetoothPair = /* @__PURE__ */ temporarilyNotSupport('makeBluetoothPair');
1399
+ const isBluetoothDevicePaired = /* @__PURE__ */ temporarilyNotSupport('isBluetoothDevicePaired');
1400
+ const getConnectedBluetoothDevices = /* @__PURE__ */ temporarilyNotSupport('getConnectedBluetoothDevices');
1401
+ const getBluetoothDevices = /* @__PURE__ */ temporarilyNotSupport('getBluetoothDevices');
1402
+ const getBluetoothAdapterState = /* @__PURE__ */ temporarilyNotSupport('getBluetoothAdapterState');
1403
+ const closeBluetoothAdapter = /* @__PURE__ */ temporarilyNotSupport('closeBluetoothAdapter');
1374
1404
 
1375
1405
  // 蓝牙-低功耗中心设备
1376
- const writeBLECharacteristicValue = temporarilyNotSupport('writeBLECharacteristicValue');
1377
- const setBLEMTU = temporarilyNotSupport('setBLEMTU');
1378
- const readBLECharacteristicValue = temporarilyNotSupport('readBLECharacteristicValue');
1379
- const onBLEMTUChange = temporarilyNotSupport('onBLEMTUChange');
1380
- const onBLEConnectionStateChange = temporarilyNotSupport('onBLEConnectionStateChange');
1381
- const onBLECharacteristicValueChange = temporarilyNotSupport('onBLECharacteristicValueChange');
1382
- const offBLEMTUChange = temporarilyNotSupport('offBLEMTUChange');
1383
- const offBLEConnectionStateChange = temporarilyNotSupport('offBLEConnectionStateChange');
1384
- const offBLECharacteristicValueChange = temporarilyNotSupport('offBLECharacteristicValueChange');
1385
- const notifyBLECharacteristicValueChange = temporarilyNotSupport('notifyBLECharacteristicValueChange');
1386
- const getBLEMTU = temporarilyNotSupport('getBLEMTU');
1387
- const getBLEDeviceServices = temporarilyNotSupport('getBLEDeviceServices');
1388
- const getBLEDeviceRSSI = temporarilyNotSupport('getBLEDeviceRSSI');
1389
- const getBLEDeviceCharacteristics = temporarilyNotSupport('getBLEDeviceCharacteristics');
1390
- const createBLEConnection = temporarilyNotSupport('createBLEConnection');
1391
- const closeBLEConnection = temporarilyNotSupport('closeBLEConnection');
1406
+ const writeBLECharacteristicValue = /* @__PURE__ */ temporarilyNotSupport('writeBLECharacteristicValue');
1407
+ const setBLEMTU = /* @__PURE__ */ temporarilyNotSupport('setBLEMTU');
1408
+ const readBLECharacteristicValue = /* @__PURE__ */ temporarilyNotSupport('readBLECharacteristicValue');
1409
+ const onBLEMTUChange = /* @__PURE__ */ temporarilyNotSupport('onBLEMTUChange');
1410
+ const onBLEConnectionStateChange = /* @__PURE__ */ temporarilyNotSupport('onBLEConnectionStateChange');
1411
+ const onBLECharacteristicValueChange = /* @__PURE__ */ temporarilyNotSupport('onBLECharacteristicValueChange');
1412
+ const offBLEMTUChange = /* @__PURE__ */ temporarilyNotSupport('offBLEMTUChange');
1413
+ const offBLEConnectionStateChange = /* @__PURE__ */ temporarilyNotSupport('offBLEConnectionStateChange');
1414
+ const offBLECharacteristicValueChange = /* @__PURE__ */ temporarilyNotSupport('offBLECharacteristicValueChange');
1415
+ const notifyBLECharacteristicValueChange = /* @__PURE__ */ temporarilyNotSupport('notifyBLECharacteristicValueChange');
1416
+ const getBLEMTU = /* @__PURE__ */ temporarilyNotSupport('getBLEMTU');
1417
+ const getBLEDeviceServices = /* @__PURE__ */ temporarilyNotSupport('getBLEDeviceServices');
1418
+ const getBLEDeviceRSSI = /* @__PURE__ */ temporarilyNotSupport('getBLEDeviceRSSI');
1419
+ const getBLEDeviceCharacteristics = /* @__PURE__ */ temporarilyNotSupport('getBLEDeviceCharacteristics');
1420
+ const createBLEConnection = /* @__PURE__ */ temporarilyNotSupport('createBLEConnection');
1421
+ const closeBLEConnection = /* @__PURE__ */ temporarilyNotSupport('closeBLEConnection');
1392
1422
 
1393
1423
  // 蓝牙-低功耗外围设备
1394
- const onBLEPeripheralConnectionStateChanged = temporarilyNotSupport('onBLEPeripheralConnectionStateChanged');
1395
- const offBLEPeripheralConnectionStateChanged = temporarilyNotSupport('offBLEPeripheralConnectionStateChanged');
1396
- const createBLEPeripheralServer = temporarilyNotSupport('createBLEPeripheralServer');
1424
+ const onBLEPeripheralConnectionStateChanged = /* @__PURE__ */ temporarilyNotSupport('onBLEPeripheralConnectionStateChanged');
1425
+ const offBLEPeripheralConnectionStateChanged = /* @__PURE__ */ temporarilyNotSupport('offBLEPeripheralConnectionStateChanged');
1426
+ const createBLEPeripheralServer = /* @__PURE__ */ temporarilyNotSupport('createBLEPeripheralServer');
1397
1427
 
1398
1428
  // 日历
1399
- const addPhoneRepeatCalendar = temporarilyNotSupport('addPhoneRepeatCalendar');
1400
- const addPhoneCalendar = temporarilyNotSupport('addPhoneCalendar');
1429
+ const addPhoneRepeatCalendar = (options) => {
1430
+ const methodName = 'addPhoneRepeatCalendar';
1431
+ // options must be an Object
1432
+ const isObject = shouldBeObject(options);
1433
+ if (!isObject.flag) {
1434
+ const res = { errMsg: `${methodName}:fail ${isObject.msg}` };
1435
+ console.error(res.errMsg);
1436
+ return Promise.reject(res);
1437
+ }
1438
+ const { title, startTime = new Date().getTime(), allDay = false, description = '', location = '', endTime, alarm = true, alarmOffset = 0, repeatInterval = 'month', repeatEndTime, success, fail, complete, } = options;
1439
+ const handle = new MethodHandler({ name: methodName, success, fail, complete });
1440
+ if (typeof title !== 'string') {
1441
+ return handle.fail({
1442
+ errMsg: getParameterError({
1443
+ para: 'title',
1444
+ correct: 'String',
1445
+ wrong: title
1446
+ })
1447
+ });
1448
+ }
1449
+ const start = new Date(startTime);
1450
+ const end = new Date(endTime || startTime);
1451
+ if (!endTime && allDay) {
1452
+ end.setDate(end.getDate() + 1);
1453
+ }
1454
+ const interval = 1000 * 60 * 60 * 24;
1455
+ let days = 1;
1456
+ let repeat = 1;
1457
+ if (repeatEndTime) {
1458
+ const repeatEnd = new Date(repeatEndTime);
1459
+ if (repeatEnd < start) {
1460
+ return handle.fail({
1461
+ errMsg: 'repeatEndTime must be greater than startTime'
1462
+ });
1463
+ }
1464
+ switch (repeatInterval) {
1465
+ case 'week':
1466
+ days = 7;
1467
+ break;
1468
+ case 'month':
1469
+ days = 30;
1470
+ break;
1471
+ case 'year':
1472
+ days = 365;
1473
+ break;
1474
+ default:
1475
+ }
1476
+ repeat = Math.ceil((repeatEnd.getTime() - start.getTime()) / (interval * days));
1477
+ }
1478
+ const { error, value } = ics__namespace.createEvent({
1479
+ title,
1480
+ start: parseTime2Array(start, allDay),
1481
+ description,
1482
+ location,
1483
+ end: parseTime2Array(end, allDay),
1484
+ alarms: alarm ? [{
1485
+ action: 'display',
1486
+ description,
1487
+ trigger: {
1488
+ before: true,
1489
+ seconds: alarmOffset,
1490
+ },
1491
+ duration: {
1492
+ days,
1493
+ },
1494
+ repeat,
1495
+ }] : [],
1496
+ });
1497
+ if (error || !value) {
1498
+ return handle.fail({
1499
+ errMsg: error === null || error === void 0 ? void 0 : error.message
1500
+ });
1501
+ }
1502
+ const url = URL.createObjectURL(new Blob([value]));
1503
+ createDownload(url, `${title}.ics`);
1504
+ return handle.success();
1505
+ };
1506
+ const addPhoneCalendar = (options) => {
1507
+ const methodName = 'addPhoneCalendar';
1508
+ // options must be an Object
1509
+ const isObject = shouldBeObject(options);
1510
+ if (!isObject.flag) {
1511
+ const res = { errMsg: `${methodName}:fail ${isObject.msg}` };
1512
+ console.error(res.errMsg);
1513
+ return Promise.reject(res);
1514
+ }
1515
+ const { title, startTime = new Date().getTime(), allDay = false, description = '', location = '', endTime, alarm = true, alarmOffset = 0, success, fail, complete, } = options;
1516
+ const handle = new MethodHandler({ name: methodName, success, fail, complete });
1517
+ if (typeof title !== 'string') {
1518
+ return handle.fail({
1519
+ errMsg: getParameterError({
1520
+ para: 'title',
1521
+ correct: 'String',
1522
+ wrong: title
1523
+ })
1524
+ });
1525
+ }
1526
+ const start = new Date(startTime);
1527
+ const end = new Date(endTime || startTime);
1528
+ if (!endTime && allDay) {
1529
+ end.setDate(end.getDate() + 1);
1530
+ }
1531
+ const { error, value } = ics__namespace.createEvent({
1532
+ title,
1533
+ start: parseTime2Array(start, allDay),
1534
+ description,
1535
+ location,
1536
+ end: parseTime2Array(end, allDay),
1537
+ alarms: alarm ? [{
1538
+ action: 'display',
1539
+ description,
1540
+ trigger: {
1541
+ before: true,
1542
+ seconds: alarmOffset,
1543
+ },
1544
+ }] : [],
1545
+ });
1546
+ if (error || !value) {
1547
+ return handle.fail({
1548
+ errMsg: error === null || error === void 0 ? void 0 : error.message
1549
+ });
1550
+ }
1551
+ const url = URL.createObjectURL(new Blob([value]));
1552
+ createDownload(url, `${title}.ics`);
1553
+ return handle.success();
1554
+ };
1555
+ function parseTime2Array(time, allDay = false) {
1556
+ const t = new Date(time);
1557
+ const timeArr = [
1558
+ t.getFullYear(),
1559
+ t.getMonth() + 1,
1560
+ t.getDate(),
1561
+ ];
1562
+ if (!allDay) {
1563
+ timeArr.push(t.getHours(), t.getMinutes());
1564
+ }
1565
+ return timeArr;
1566
+ }
1401
1567
 
1402
1568
  // 周期性更新
1403
- const setBackgroundFetchToken = temporarilyNotSupport('setBackgroundFetchToken');
1404
- const onBackgroundFetchData = temporarilyNotSupport('onBackgroundFetchData');
1405
- const getBackgroundFetchToken = temporarilyNotSupport('getBackgroundFetchToken');
1406
- const getBackgroundFetchData = temporarilyNotSupport('getBackgroundFetchData');
1569
+ const setBackgroundFetchToken = /* @__PURE__ */ temporarilyNotSupport('setBackgroundFetchToken');
1570
+ const onBackgroundFetchData = /* @__PURE__ */ temporarilyNotSupport('onBackgroundFetchData');
1571
+ const getBackgroundFetchToken = /* @__PURE__ */ temporarilyNotSupport('getBackgroundFetchToken');
1572
+ const getBackgroundFetchData = /* @__PURE__ */ temporarilyNotSupport('getBackgroundFetchData');
1407
1573
 
1408
1574
  function getItem(key) {
1409
1575
  let item;
@@ -1461,7 +1627,7 @@ const setStorage = (options) => {
1461
1627
  setStorageSync(key, data);
1462
1628
  return handle.success();
1463
1629
  };
1464
- const revokeBufferURL = temporarilyNotSupport('revokeBufferURL');
1630
+ const revokeBufferURL = /* @__PURE__ */ temporarilyNotSupport('revokeBufferURL');
1465
1631
  const removeStorageSync = (key) => {
1466
1632
  if (typeof key !== 'string') {
1467
1633
  console.error(getParameterError({
@@ -1550,7 +1716,7 @@ const getStorage = (options) => {
1550
1716
  });
1551
1717
  }
1552
1718
  };
1553
- const createBufferURL = temporarilyNotSupport('createBufferURL');
1719
+ const createBufferURL = /* @__PURE__ */ temporarilyNotSupport('createBufferURL');
1554
1720
  const clearStorageSync = () => {
1555
1721
  localStorage.clear();
1556
1722
  };
@@ -1658,7 +1824,7 @@ const startCompass = ({ success, fail, complete } = {}) => {
1658
1824
  if (compassListener) {
1659
1825
  stopCompass();
1660
1826
  }
1661
- compassListener = lodashEs.throttle((evt) => {
1827
+ compassListener = throttle((evt) => {
1662
1828
  const isAndroid = getDeviceInfo().system === 'AndroidOS';
1663
1829
  if (isAndroid && !evt.absolute && !CompassChangeTrigger) {
1664
1830
  CompassChangeTrigger = true;
@@ -1701,36 +1867,36 @@ const offCompassChange = callback => {
1701
1867
  };
1702
1868
 
1703
1869
  // 联系人
1704
- const chooseContact = temporarilyNotSupport('chooseContact');
1705
- const addPhoneContact = temporarilyNotSupport('addPhoneContact');
1870
+ const chooseContact = /* @__PURE__ */ temporarilyNotSupport('chooseContact');
1871
+ const addPhoneContact = /* @__PURE__ */ temporarilyNotSupport('addPhoneContact');
1706
1872
 
1707
1873
  // 加密
1708
- const getRandomValues = temporarilyNotSupport('getRandomValues');
1874
+ const getRandomValues = /* @__PURE__ */ temporarilyNotSupport('getRandomValues');
1709
1875
 
1710
1876
  // 陀螺仪
1711
- const stopGyroscope = temporarilyNotSupport('stopGyroscope');
1712
- const startGyroscope = temporarilyNotSupport('startGyroscope');
1713
- const onGyroscopeChange = temporarilyNotSupport('onGyroscopeChange');
1714
- const offGyroscopeChange = temporarilyNotSupport('offGyroscopeChange');
1877
+ const stopGyroscope = /* @__PURE__ */ temporarilyNotSupport('stopGyroscope');
1878
+ const startGyroscope = /* @__PURE__ */ temporarilyNotSupport('startGyroscope');
1879
+ const onGyroscopeChange = /* @__PURE__ */ temporarilyNotSupport('onGyroscopeChange');
1880
+ const offGyroscopeChange = /* @__PURE__ */ temporarilyNotSupport('offGyroscopeChange');
1715
1881
 
1716
1882
  // 蓝牙-信标(Beacon)
1717
- const stopBeaconDiscovery = temporarilyNotSupport('stopBeaconDiscovery');
1718
- const startBeaconDiscovery = temporarilyNotSupport('startBeaconDiscovery');
1719
- const onBeaconUpdate = temporarilyNotSupport('onBeaconUpdate');
1720
- const onBeaconServiceChange = temporarilyNotSupport('onBeaconServiceChange');
1721
- const offBeaconUpdate = temporarilyNotSupport('offBeaconUpdate');
1722
- const offBeaconServiceChange = temporarilyNotSupport('offBeaconServiceChange');
1723
- const getBeacons = temporarilyNotSupport('getBeacons');
1883
+ const stopBeaconDiscovery = /* @__PURE__ */ temporarilyNotSupport('stopBeaconDiscovery');
1884
+ const startBeaconDiscovery = /* @__PURE__ */ temporarilyNotSupport('startBeaconDiscovery');
1885
+ const onBeaconUpdate = /* @__PURE__ */ temporarilyNotSupport('onBeaconUpdate');
1886
+ const onBeaconServiceChange = /* @__PURE__ */ temporarilyNotSupport('onBeaconServiceChange');
1887
+ const offBeaconUpdate = /* @__PURE__ */ temporarilyNotSupport('offBeaconUpdate');
1888
+ const offBeaconServiceChange = /* @__PURE__ */ temporarilyNotSupport('offBeaconServiceChange');
1889
+ const getBeacons = /* @__PURE__ */ temporarilyNotSupport('getBeacons');
1724
1890
 
1725
1891
  // 键盘
1726
- const onKeyboardHeightChange = temporarilyNotSupport('onKeyboardHeightChange');
1727
- const offKeyboardHeightChange = temporarilyNotSupport('offKeyboardHeightChange');
1728
- const hideKeyboard = temporarilyNotSupport('hideKeyboard');
1729
- const getSelectedTextRange = temporarilyNotSupport('getSelectedTextRange');
1892
+ const onKeyboardHeightChange = /* @__PURE__ */ temporarilyNotSupport('onKeyboardHeightChange');
1893
+ const offKeyboardHeightChange = /* @__PURE__ */ temporarilyNotSupport('offKeyboardHeightChange');
1894
+ const hideKeyboard = /* @__PURE__ */ temporarilyNotSupport('hideKeyboard');
1895
+ const getSelectedTextRange = /* @__PURE__ */ temporarilyNotSupport('getSelectedTextRange');
1730
1896
 
1731
1897
  // 内存
1732
- const onMemoryWarning = temporarilyNotSupport('onMemoryWarning');
1733
- const offMemoryWarning = temporarilyNotSupport('offMemoryWarning');
1898
+ const onMemoryWarning = /* @__PURE__ */ temporarilyNotSupport('onMemoryWarning');
1899
+ const offMemoryWarning = /* @__PURE__ */ temporarilyNotSupport('offMemoryWarning');
1734
1900
 
1735
1901
  const callbackManager$1 = new CallbackManager();
1736
1902
  let deviceMotionListener;
@@ -1772,7 +1938,7 @@ const startDeviceMotionListening = ({ interval = 'normal', success, fail, comple
1772
1938
  if (deviceMotionListener) {
1773
1939
  stopDeviceMotionListening();
1774
1940
  }
1775
- deviceMotionListener = lodashEs.throttle((evt) => {
1941
+ deviceMotionListener = throttle((evt) => {
1776
1942
  callbackManager$1.trigger({
1777
1943
  alpha: evt.alpha,
1778
1944
  beta: evt.beta,
@@ -1862,7 +2028,7 @@ const networkStatusListener = () => __awaiter(void 0, void 0, void 0, function*
1862
2028
  * - 出现三次以上的丢包
1863
2029
  * > 弱网事件通知规则是: 弱网状态变化时立即通知, 状态不变时 30s 内最多通知一次。
1864
2030
  */
1865
- const onNetworkWeakChange = temporarilyNotSupport('onNetworkWeakChange');
2031
+ const onNetworkWeakChange = /* @__PURE__ */ temporarilyNotSupport('onNetworkWeakChange');
1866
2032
  const onNetworkStatusChange = callback => {
1867
2033
  networkStatusManager.add(callback);
1868
2034
  const connection = getConnection();
@@ -1870,7 +2036,7 @@ const onNetworkStatusChange = callback => {
1870
2036
  connection.addEventListener('change', networkStatusListener);
1871
2037
  }
1872
2038
  };
1873
- const offNetworkWeakChange = temporarilyNotSupport('offNetworkWeakChange');
2039
+ const offNetworkWeakChange = /* @__PURE__ */ temporarilyNotSupport('offNetworkWeakChange');
1874
2040
  const offNetworkStatusChange = callback => {
1875
2041
  networkStatusManager.remove(callback);
1876
2042
  const connection = getConnection();
@@ -1878,16 +2044,16 @@ const offNetworkStatusChange = callback => {
1878
2044
  connection.removeEventListener('change', networkStatusListener);
1879
2045
  }
1880
2046
  };
1881
- const getLocalIPAddress = temporarilyNotSupport('getLocalIPAddress');
2047
+ const getLocalIPAddress = /* @__PURE__ */ temporarilyNotSupport('getLocalIPAddress');
1882
2048
 
1883
2049
  // NFC
1884
- const stopHCE = temporarilyNotSupport('stopHCE');
1885
- const startHCE = temporarilyNotSupport('startHCE');
1886
- const sendHCEMessage = temporarilyNotSupport('sendHCEMessage');
1887
- const onHCEMessage = temporarilyNotSupport('onHCEMessage');
1888
- const offHCEMessage = temporarilyNotSupport('offHCEMessage');
1889
- const getNFCAdapter = temporarilyNotSupport('getNFCAdapter');
1890
- const getHCEState = temporarilyNotSupport('getHCEState');
2050
+ const stopHCE = /* @__PURE__ */ temporarilyNotSupport('stopHCE');
2051
+ const startHCE = /* @__PURE__ */ temporarilyNotSupport('startHCE');
2052
+ const sendHCEMessage = /* @__PURE__ */ temporarilyNotSupport('sendHCEMessage');
2053
+ const onHCEMessage = /* @__PURE__ */ temporarilyNotSupport('onHCEMessage');
2054
+ const offHCEMessage = /* @__PURE__ */ temporarilyNotSupport('offHCEMessage');
2055
+ const getNFCAdapter = /* @__PURE__ */ temporarilyNotSupport('getNFCAdapter');
2056
+ const getHCEState = /* @__PURE__ */ temporarilyNotSupport('getHCEState');
1891
2057
 
1892
2058
  const makePhoneCall = (options) => {
1893
2059
  // options must be an Object
@@ -1913,7 +2079,7 @@ const makePhoneCall = (options) => {
1913
2079
  };
1914
2080
 
1915
2081
  // 扫码
1916
- const scanCode = processOpenApi({
2082
+ const scanCode = /* @__PURE__ */ processOpenApi({
1917
2083
  name: 'scanQRCode',
1918
2084
  defaultOptions: { needResult: 1 },
1919
2085
  formatResult: res => ({
@@ -1923,12 +2089,12 @@ const scanCode = processOpenApi({
1923
2089
  });
1924
2090
 
1925
2091
  // 屏幕
1926
- const setVisualEffectOnCapture = temporarilyNotSupport('setVisualEffectOnCapture');
1927
- const setScreenBrightness = temporarilyNotSupport('setScreenBrightness');
1928
- const setKeepScreenOn = temporarilyNotSupport('setKeepScreenOn');
1929
- const onUserCaptureScreen = temporarilyNotSupport('onUserCaptureScreen');
1930
- const offUserCaptureScreen = temporarilyNotSupport('offUserCaptureScreen');
1931
- const getScreenBrightness = temporarilyNotSupport('getScreenBrightness');
2092
+ const setVisualEffectOnCapture = /* @__PURE__ */ temporarilyNotSupport('setVisualEffectOnCapture');
2093
+ const setScreenBrightness = /* @__PURE__ */ temporarilyNotSupport('setScreenBrightness');
2094
+ const setKeepScreenOn = /* @__PURE__ */ temporarilyNotSupport('setKeepScreenOn');
2095
+ const onUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('onUserCaptureScreen');
2096
+ const offUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('offUserCaptureScreen');
2097
+ const getScreenBrightness = /* @__PURE__ */ temporarilyNotSupport('getScreenBrightness');
1932
2098
 
1933
2099
  const vibrator = function vibrator(mm) {
1934
2100
  try {
@@ -1964,32 +2130,32 @@ const vibrateLong = ({ success, fail, complete } = {}) => {
1964
2130
  };
1965
2131
 
1966
2132
  // Wi-Fi
1967
- const stopWifi = temporarilyNotSupport('stopWifi');
1968
- const startWifi = temporarilyNotSupport('startWifi');
1969
- const setWifiList = temporarilyNotSupport('setWifiList');
1970
- const onWifiConnectedWithPartialInfo = temporarilyNotSupport('onWifiConnectedWithPartialInfo');
1971
- const onWifiConnected = temporarilyNotSupport('onWifiConnected');
1972
- const onGetWifiList = temporarilyNotSupport('onGetWifiList');
1973
- const offWifiConnectedWithPartialInfo = temporarilyNotSupport('offWifiConnectedWithPartialInfo');
1974
- const offWifiConnected = temporarilyNotSupport('offWifiConnected');
1975
- const offGetWifiList = temporarilyNotSupport('offGetWifiList');
1976
- const getWifiList = temporarilyNotSupport('getWifiList');
1977
- const getConnectedWifi = temporarilyNotSupport('getConnectedWifi');
1978
- const connectWifi = temporarilyNotSupport('connectWifi');
2133
+ const stopWifi = /* @__PURE__ */ temporarilyNotSupport('stopWifi');
2134
+ const startWifi = /* @__PURE__ */ temporarilyNotSupport('startWifi');
2135
+ const setWifiList = /* @__PURE__ */ temporarilyNotSupport('setWifiList');
2136
+ const onWifiConnectedWithPartialInfo = /* @__PURE__ */ temporarilyNotSupport('onWifiConnectedWithPartialInfo');
2137
+ const onWifiConnected = /* @__PURE__ */ temporarilyNotSupport('onWifiConnected');
2138
+ const onGetWifiList = /* @__PURE__ */ temporarilyNotSupport('onGetWifiList');
2139
+ const offWifiConnectedWithPartialInfo = /* @__PURE__ */ temporarilyNotSupport('offWifiConnectedWithPartialInfo');
2140
+ const offWifiConnected = /* @__PURE__ */ temporarilyNotSupport('offWifiConnected');
2141
+ const offGetWifiList = /* @__PURE__ */ temporarilyNotSupport('offGetWifiList');
2142
+ const getWifiList = /* @__PURE__ */ temporarilyNotSupport('getWifiList');
2143
+ const getConnectedWifi = /* @__PURE__ */ temporarilyNotSupport('getConnectedWifi');
2144
+ const connectWifi = /* @__PURE__ */ temporarilyNotSupport('connectWifi');
1979
2145
 
1980
2146
  // 第三方平台
1981
- const getExtConfigSync = temporarilyNotSupport('getExtConfigSync');
1982
- const getExtConfig = temporarilyNotSupport('getExtConfig');
2147
+ const getExtConfigSync = /* @__PURE__ */ temporarilyNotSupport('getExtConfigSync');
2148
+ const getExtConfig = /* @__PURE__ */ temporarilyNotSupport('getExtConfig');
1983
2149
 
1984
2150
  // 文件
1985
- const saveFileToDisk = temporarilyNotSupport('saveFileToDisk');
1986
- const saveFile = temporarilyNotSupport('saveFile');
1987
- const removeSavedFile = temporarilyNotSupport('removeSavedFile');
1988
- const openDocument = temporarilyNotSupport('openDocument');
1989
- const getSavedFileList = temporarilyNotSupport('getSavedFileList');
1990
- const getSavedFileInfo = temporarilyNotSupport('getSavedFileInfo');
1991
- const getFileSystemManager = temporarilyNotSupport('getFileSystemManager');
1992
- const getFileInfo = temporarilyNotSupport('getFileInfo');
2151
+ const saveFileToDisk = /* @__PURE__ */ temporarilyNotSupport('saveFileToDisk');
2152
+ const saveFile = /* @__PURE__ */ temporarilyNotSupport('saveFile');
2153
+ const removeSavedFile = /* @__PURE__ */ temporarilyNotSupport('removeSavedFile');
2154
+ const openDocument = /* @__PURE__ */ temporarilyNotSupport('openDocument');
2155
+ const getSavedFileList = /* @__PURE__ */ temporarilyNotSupport('getSavedFileList');
2156
+ const getSavedFileInfo = /* @__PURE__ */ temporarilyNotSupport('getSavedFileInfo');
2157
+ const getFileSystemManager = /* @__PURE__ */ temporarilyNotSupport('getFileSystemManager');
2158
+ const getFileInfo = /* @__PURE__ */ temporarilyNotSupport('getFileInfo');
1993
2159
 
1994
2160
  const getApp = function () {
1995
2161
  return Taro.getCurrentInstance().app;
@@ -2055,7 +2221,7 @@ const getLocationByW3CApi = (options) => {
2055
2221
  }, positionOptions);
2056
2222
  });
2057
2223
  };
2058
- const getLocation = processOpenApi({
2224
+ const getLocation = /* @__PURE__ */ processOpenApi({
2059
2225
  name: 'getLocation',
2060
2226
  standardMethod: getLocationByW3CApi
2061
2227
  });
@@ -2190,19 +2356,19 @@ const chooseLocation = ({ success, fail, complete, mapOpts } = {}) => {
2190
2356
  };
2191
2357
 
2192
2358
  // 位置
2193
- const stopLocationUpdate = temporarilyNotSupport('stopLocationUpdate');
2194
- const startLocationUpdateBackground = temporarilyNotSupport('startLocationUpdateBackground');
2195
- const startLocationUpdate = temporarilyNotSupport('startLocationUpdate');
2196
- const openLocation = processOpenApi({
2359
+ const stopLocationUpdate = /* @__PURE__ */ temporarilyNotSupport('stopLocationUpdate');
2360
+ const startLocationUpdateBackground = /* @__PURE__ */ temporarilyNotSupport('startLocationUpdateBackground');
2361
+ const startLocationUpdate = /* @__PURE__ */ temporarilyNotSupport('startLocationUpdate');
2362
+ const openLocation = /* @__PURE__ */ processOpenApi({
2197
2363
  name: 'openLocation',
2198
2364
  defaultOptions: { scale: 18 }
2199
2365
  });
2200
- const onLocationChangeError = temporarilyNotSupport('onLocationChangeError');
2201
- const onLocationChange = temporarilyNotSupport('onLocationChange');
2202
- const offLocationChangeError = temporarilyNotSupport('offLocationChangeError');
2203
- const offLocationChange = temporarilyNotSupport('offLocationChange');
2204
- const choosePoi = temporarilyNotSupport('choosePoi');
2205
- const getFuzzyLocation = temporarilyNotSupport('getFuzzyLocation');
2366
+ const onLocationChangeError = /* @__PURE__ */ temporarilyNotSupport('onLocationChangeError');
2367
+ const onLocationChange = /* @__PURE__ */ temporarilyNotSupport('onLocationChange');
2368
+ const offLocationChangeError = /* @__PURE__ */ temporarilyNotSupport('offLocationChangeError');
2369
+ const offLocationChange = /* @__PURE__ */ temporarilyNotSupport('offLocationChange');
2370
+ const choosePoi = /* @__PURE__ */ temporarilyNotSupport('choosePoi');
2371
+ const getFuzzyLocation = /* @__PURE__ */ temporarilyNotSupport('getFuzzyLocation');
2206
2372
 
2207
2373
  class InnerAudioContext {
2208
2374
  constructor() {
@@ -2290,18 +2456,18 @@ class InnerAudioContext {
2290
2456
  }
2291
2457
 
2292
2458
  // 音频
2293
- const stopVoice = temporarilyNotSupport('stopVoice');
2294
- const setInnerAudioOption = temporarilyNotSupport('setInnerAudioOption');
2295
- const playVoice = temporarilyNotSupport('playVoice');
2296
- const pauseVoice = temporarilyNotSupport('pauseVoice');
2297
- const getAvailableAudioSources = temporarilyNotSupport('getAvailableAudioSources');
2298
- const createWebAudioContext = temporarilyNotSupport('createWebAudioContext');
2299
- const createMediaAudioPlayer = temporarilyNotSupport('createMediaAudioPlayer');
2459
+ const stopVoice = /* @__PURE__ */ temporarilyNotSupport('stopVoice');
2460
+ const setInnerAudioOption = /* @__PURE__ */ temporarilyNotSupport('setInnerAudioOption');
2461
+ const playVoice = /* @__PURE__ */ temporarilyNotSupport('playVoice');
2462
+ const pauseVoice = /* @__PURE__ */ temporarilyNotSupport('pauseVoice');
2463
+ const getAvailableAudioSources = /* @__PURE__ */ temporarilyNotSupport('getAvailableAudioSources');
2464
+ const createWebAudioContext = /* @__PURE__ */ temporarilyNotSupport('createWebAudioContext');
2465
+ const createMediaAudioPlayer = /* @__PURE__ */ temporarilyNotSupport('createMediaAudioPlayer');
2300
2466
  /**
2301
2467
  * 创建内部 audio 上下文 InnerAudioContext 对象。
2302
2468
  */
2303
2469
  const createInnerAudioContext = () => new InnerAudioContext();
2304
- const createAudioContext = temporarilyNotSupport('createAudioContext');
2470
+ const createAudioContext = /* @__PURE__ */ temporarilyNotSupport('createAudioContext');
2305
2471
 
2306
2472
  class BackgroundAudioManager {
2307
2473
  constructor() {
@@ -2389,21 +2555,45 @@ class BackgroundAudioManager {
2389
2555
  }
2390
2556
 
2391
2557
  // 背景音频
2392
- const stopBackgroundAudio = temporarilyNotSupport('stopBackgroundAudio');
2393
- const seekBackgroundAudio = temporarilyNotSupport('seekBackgroundAudio');
2394
- const playBackgroundAudio = temporarilyNotSupport('playBackgroundAudio');
2395
- const pauseBackgroundAudio = temporarilyNotSupport('pauseBackgroundAudio');
2396
- const onBackgroundAudioStop = temporarilyNotSupport('onBackgroundAudioStop');
2397
- const onBackgroundAudioPlay = temporarilyNotSupport('onBackgroundAudioPlay');
2398
- const onBackgroundAudioPause = temporarilyNotSupport('onBackgroundAudioPause');
2399
- const getBackgroundAudioPlayerState = temporarilyNotSupport('getBackgroundAudioPlayerState');
2558
+ const stopBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('stopBackgroundAudio');
2559
+ const seekBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('seekBackgroundAudio');
2560
+ const playBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('playBackgroundAudio');
2561
+ const pauseBackgroundAudio = /* @__PURE__ */ temporarilyNotSupport('pauseBackgroundAudio');
2562
+ const onBackgroundAudioStop = /* @__PURE__ */ temporarilyNotSupport('onBackgroundAudioStop');
2563
+ const onBackgroundAudioPlay = /* @__PURE__ */ temporarilyNotSupport('onBackgroundAudioPlay');
2564
+ const onBackgroundAudioPause = /* @__PURE__ */ temporarilyNotSupport('onBackgroundAudioPause');
2565
+ const getBackgroundAudioPlayerState = /* @__PURE__ */ temporarilyNotSupport('getBackgroundAudioPlayerState');
2400
2566
  /**
2401
2567
  * 获取全局唯一的背景音频管理器
2402
2568
  */
2403
2569
  const getBackgroundAudioManager = () => new BackgroundAudioManager();
2404
2570
 
2405
2571
  // 相机
2406
- const createCameraContext = temporarilyNotSupport('createCameraContext');
2572
+ const createCameraContext = /* @__PURE__ */ temporarilyNotSupport('createCameraContext');
2573
+
2574
+ const saveImageToPhotosAlbum = (options) => {
2575
+ const methodName = 'saveImageToPhotosAlbum';
2576
+ // options must be an Object
2577
+ const isObject = shouldBeObject(options);
2578
+ if (!isObject.flag) {
2579
+ const res = { errMsg: `${methodName}:fail ${isObject.msg}` };
2580
+ console.error(res.errMsg);
2581
+ return Promise.reject(res);
2582
+ }
2583
+ const { filePath, success, fail, complete, } = options;
2584
+ const handle = new MethodHandler({ name: methodName, success, fail, complete });
2585
+ if (typeof filePath !== 'string') {
2586
+ return handle.fail({
2587
+ errMsg: getParameterError({
2588
+ para: 'filePath',
2589
+ correct: 'String',
2590
+ wrong: filePath
2591
+ })
2592
+ });
2593
+ }
2594
+ createDownload(filePath);
2595
+ return handle.success();
2596
+ };
2407
2597
 
2408
2598
  /**
2409
2599
  * 获取图片信息。网络图片需先配置download域名才能生效。
@@ -2523,1123 +2713,142 @@ const previewImage = (options) => __awaiter(void 0, void 0, void 0, function* ()
2523
2713
  });
2524
2714
 
2525
2715
  /**
2526
- * 从本地相册选择图片或使用相机拍照。
2716
+ * H5 下的 styleSheet 操作
2717
+ * @author leeenx
2527
2718
  */
2528
- const chooseImage = function (options) {
2529
- // options must be an Object
2530
- const isObject = shouldBeObject(options);
2531
- if (!isObject.flag) {
2532
- const res = { errMsg: `chooseImage:fail ${isObject.msg}` };
2533
- console.error(res.errMsg);
2534
- return Promise.reject(res);
2719
+ class StyleSheet {
2720
+ constructor() {
2721
+ this.$style = null;
2722
+ this.sheet = null;
2723
+ this.appendStyleSheet = () => {
2724
+ if (this.$style) {
2725
+ const head = document.getElementsByTagName('head')[0];
2726
+ this.$style.setAttribute('type', 'text/css');
2727
+ this.$style.setAttribute('data-type', 'Taro');
2728
+ head.appendChild(this.$style);
2729
+ this.sheet = this.$style.sheet;
2730
+ }
2731
+ if (this.sheet && !('insertRule' in this.sheet)) {
2732
+ console.warn('当前浏览器不支持 stylesheet.insertRule 接口');
2733
+ }
2734
+ };
2735
+ // 添加样式命令
2736
+ this.add = (cssText, index = 0) => {
2737
+ var _a;
2738
+ if (this.sheet === null) {
2739
+ // $style 未插入到 DOM
2740
+ this.appendStyleSheet();
2741
+ }
2742
+ (_a = this.sheet) === null || _a === void 0 ? void 0 : _a.insertRule(cssText, index);
2743
+ };
2744
+ this.$style = document.createElement('style');
2535
2745
  }
2536
- const { count = 1, success, fail, complete, imageId = 'taroChooseImage', sourceType = ['album', 'camera'] } = options;
2537
- const handle = new MethodHandler({ name: 'chooseImage', success, fail, complete });
2538
- const res = {
2539
- tempFilePaths: [],
2540
- tempFiles: []
2541
- };
2542
- const sourceTypeString = sourceType && sourceType.toString();
2543
- const acceptableSourceType = ['user', 'environment', 'camera'];
2544
- if (count && typeof count !== 'number') {
2545
- res.errMsg = getParameterError({
2546
- para: 'count',
2547
- correct: 'Number',
2548
- wrong: count
2746
+ }
2747
+ const styleSheet = new StyleSheet();
2748
+ // 监听事件
2749
+ let TRANSITION_END = 'transitionend';
2750
+ let TRANSFORM = 'transform';
2751
+ const $detect = document.createElement('div');
2752
+ $detect.style.cssText = '-webkit-animation-name:webkit;-moz-animation-name:moz;-ms-animation-name:ms;animation-name:standard;';
2753
+ if ($detect.style['animation-name'] === 'standard') {
2754
+ // 支持标准写法
2755
+ TRANSITION_END = 'transitionend';
2756
+ TRANSFORM = 'transform';
2757
+ }
2758
+ else if ($detect.style['-webkit-animation-name'] === 'webkit') {
2759
+ // webkit 前缀
2760
+ TRANSITION_END = 'webkitTransitionEnd';
2761
+ TRANSFORM = '-webkit-transform';
2762
+ }
2763
+ else if ($detect.style['-moz-animation-name'] === 'moz') {
2764
+ // moz 前缀
2765
+ TRANSITION_END = 'mozTransitionEnd';
2766
+ TRANSFORM = '-moz-transform';
2767
+ }
2768
+ else if ($detect.style['-ms-animation-name'] === 'ms') {
2769
+ // ms 前缀
2770
+ TRANSITION_END = 'msTransitionEnd';
2771
+ TRANSFORM = '-ms-transform';
2772
+ }
2773
+ let animId = 0;
2774
+ class Animation {
2775
+ constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
2776
+ // 属性组合
2777
+ this.rules = [];
2778
+ // transform 对象
2779
+ this.transform = [`${TRANSFORM}:`];
2780
+ // 组合动画
2781
+ this.steps = [];
2782
+ // 动画 map ----- 永久保留
2783
+ this.animationMap = {};
2784
+ // animationMap 的长度
2785
+ this.animationMapCount = 0;
2786
+ // 默认值
2787
+ this.setDefault(duration, delay, timingFunction, transformOrigin);
2788
+ this.unit = unit;
2789
+ // atom 环境下,animation 属性不会显示,所以要改成 data-animation
2790
+ let animAttr = 'animation';
2791
+ // 动画 id
2792
+ this.id = ++animId;
2793
+ // 监听事件
2794
+ document.body.addEventListener(TRANSITION_END, (e) => {
2795
+ const target = e.target;
2796
+ if (target.getAttribute(animAttr) === null) {
2797
+ animAttr = 'data-animation';
2798
+ }
2799
+ const animData = target.getAttribute(animAttr);
2800
+ // 没有动画存在
2801
+ if (animData === null)
2802
+ return;
2803
+ const [animName, animPath] = animData.split('__');
2804
+ if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
2805
+ const [animIndex, __stepIndex = 0] = animPath.split('--');
2806
+ const stepIndex = Number(__stepIndex);
2807
+ // 动画总的关键帧
2808
+ const animStepsCount = this.animationMap[`${animName}__${animIndex}`];
2809
+ const animStepsMaxIndex = animStepsCount - 1;
2810
+ if (stepIndex < animStepsMaxIndex) {
2811
+ // 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
2812
+ target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`);
2813
+ if (animAttr === 'animation') {
2814
+ // Nerv 环境,animation & data-animation 双重保险
2815
+ target.setAttribute('data-animation', `${animName}__${animIndex}--${stepIndex + 1}`);
2816
+ }
2817
+ }
2818
+ }
2549
2819
  });
2550
- return handle.fail(res);
2551
2820
  }
2552
- let el = document.getElementById(imageId);
2553
- if (!el) {
2554
- const obj = document.createElement('input');
2555
- obj.setAttribute('type', 'file');
2556
- obj.setAttribute('id', imageId);
2557
- if (count > 1) {
2558
- obj.setAttribute('multiple', 'multiple');
2559
- }
2560
- if (acceptableSourceType.indexOf(sourceTypeString) > -1) {
2561
- obj.setAttribute('capture', sourceTypeString);
2562
- }
2563
- obj.setAttribute('accept', 'image/*');
2564
- obj.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;');
2565
- document.body.appendChild(obj);
2566
- el = document.getElementById(imageId);
2821
+ transformUnit(...args) {
2822
+ const ret = [];
2823
+ args.forEach(each => {
2824
+ ret.push(isNaN(each) ? each : `${each}${this.unit}`);
2825
+ });
2826
+ return ret;
2567
2827
  }
2568
- else {
2569
- if (count > 1) {
2570
- el.setAttribute('multiple', 'multiple');
2571
- }
2572
- else {
2573
- el.removeAttribute('multiple');
2574
- }
2575
- if (acceptableSourceType.indexOf(sourceTypeString) > -1) {
2576
- el.setAttribute('capture', sourceTypeString);
2828
+ // 设置默认值
2829
+ setDefault(duration, delay, timingFunction, transformOrigin) {
2830
+ this.DEFAULT = { duration, delay, timingFunction, transformOrigin };
2831
+ }
2832
+ matrix(a, b, c, d, tx, ty) {
2833
+ this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`);
2834
+ return this;
2835
+ }
2836
+ matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
2837
+ this.transform.push(`matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`);
2838
+ return this;
2839
+ }
2840
+ rotate(angle) {
2841
+ this.transform.push(`rotate(${angle}deg)`);
2842
+ return this;
2843
+ }
2844
+ rotate3d(x, y, z, angle) {
2845
+ if (typeof y !== 'number') {
2846
+ this.transform.push(`rotate3d(${x})`);
2577
2847
  }
2578
2848
  else {
2579
- el.removeAttribute('capture');
2849
+ this.transform.push(`rotate3d(${x}, ${y || 0}, ${z || 0}, ${angle || 0}deg)`);
2580
2850
  }
2581
- }
2582
- return new Promise((resolve, reject) => {
2583
- const TaroMouseEvents = document.createEvent('MouseEvents');
2584
- TaroMouseEvents.initEvent('click', true, true);
2585
- if (el) {
2586
- el.dispatchEvent(TaroMouseEvents);
2587
- el.onchange = function (e) {
2588
- const target = e.target;
2589
- if (target) {
2590
- const files = target.files || [];
2591
- const arr = [...files];
2592
- arr && arr.forEach(item => {
2593
- var _a, _b;
2594
- const blob = new Blob([item], {
2595
- type: item.type
2596
- });
2597
- const url = URL.createObjectURL(blob);
2598
- (_a = res.tempFilePaths) === null || _a === void 0 ? void 0 : _a.push(url);
2599
- (_b = res.tempFiles) === null || _b === void 0 ? void 0 : _b.push({ path: url, size: item.size, type: item.type, originalFileObj: item });
2600
- });
2601
- handle.success(res, { resolve, reject });
2602
- target.value = '';
2603
- }
2604
- };
2605
- }
2606
- });
2607
- };
2608
-
2609
- // 图片
2610
- const saveImageToPhotosAlbum = temporarilyNotSupport('saveImageToPhotosAlbum');
2611
- const previewMedia = temporarilyNotSupport('previewMedia');
2612
- const compressImage = temporarilyNotSupport('compressImage');
2613
- const chooseMessageFile = temporarilyNotSupport('chooseMessageFile');
2614
- const editImage = temporarilyNotSupport('editImage');
2615
- const cropImage = temporarilyNotSupport('cropImage');
2616
-
2617
- // 实时音视频
2618
- const createLivePusherContext = temporarilyNotSupport('createLivePusherContext');
2619
- const createLivePlayerContext = temporarilyNotSupport('createLivePlayerContext');
2620
-
2621
- // 地图
2622
- const createMapContext = temporarilyNotSupport('createMapContext');
2623
-
2624
- // 画面录制器
2625
- const createMediaRecorder = temporarilyNotSupport('createMediaRecorder');
2626
-
2627
- // 录音
2628
- const stopRecord = temporarilyNotSupport('stopRecord');
2629
- const startRecord = temporarilyNotSupport('startRecord');
2630
- const getRecorderManager = temporarilyNotSupport('getRecorderManager');
2631
-
2632
- // 视频
2633
- const saveVideoToPhotosAlbum = temporarilyNotSupport('saveVideoToPhotosAlbum');
2634
- const openVideoEditor = temporarilyNotSupport('openVideoEditor');
2635
- const getVideoInfo = temporarilyNotSupport('getVideoInfo');
2636
- /**
2637
- * 创建 video 上下文 VideoContext 对象。
2638
- */
2639
- const createVideoContext = (id, inst) => {
2640
- const el = findDOM(inst);
2641
- // TODO HTMLVideoElement to VideoContext
2642
- return el === null || el === void 0 ? void 0 : el.querySelector(`taro-video-core[id=${id}]`);
2643
- };
2644
- const compressVideo = temporarilyNotSupport('compressVideo');
2645
- /**
2646
- * 拍摄视频或从手机相册中选视频。
2647
- */
2648
- const chooseVideo = (options) => {
2649
- // options must be an Object
2650
- const isObject = shouldBeObject(options);
2651
- if (!isObject.flag) {
2652
- const res = { errMsg: `chooseVideo:fail ${isObject.msg}` };
2653
- console.error(res.errMsg);
2654
- return Promise.reject(res);
2655
- }
2656
- const { success, fail, complete } = options;
2657
- const handle = new MethodHandler({ name: 'chooseVideo', success, fail, complete });
2658
- const res = {
2659
- tempFilePath: '',
2660
- duration: 0,
2661
- size: 0,
2662
- height: 0,
2663
- width: 0
2664
- };
2665
- const inputEl = document.createElement('input');
2666
- inputEl.setAttribute('type', 'file');
2667
- inputEl.setAttribute('multiple', 'multiple');
2668
- inputEl.setAttribute('accept', 'video/*');
2669
- inputEl.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;');
2670
- document.body.appendChild(inputEl);
2671
- return new Promise((resolve, reject) => {
2672
- const TaroMouseEvents = document.createEvent('MouseEvents');
2673
- TaroMouseEvents.initEvent('click', true, true);
2674
- inputEl.dispatchEvent(TaroMouseEvents);
2675
- inputEl.onchange = function (e) {
2676
- var _a;
2677
- const target = e.target;
2678
- const file = (_a = target.files) === null || _a === void 0 ? void 0 : _a[0];
2679
- const reader = new FileReader();
2680
- reader.onload = function (event) {
2681
- var _a;
2682
- const videoEl = document.createElement('video');
2683
- const url = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
2684
- videoEl.preload = 'metadata';
2685
- videoEl.src = url;
2686
- videoEl.onloadedmetadata = () => {
2687
- res.tempFilePath = url;
2688
- res.duration = videoEl.duration;
2689
- res.size = event.total;
2690
- res.height = videoEl.videoHeight;
2691
- res.width = videoEl.videoHeight;
2692
- return handle.success(res, { resolve, reject });
2693
- };
2694
- };
2695
- if (file) {
2696
- reader.readAsDataURL(file);
2697
- }
2698
- };
2699
- }).finally(() => {
2700
- document.body.removeChild(inputEl);
2701
- });
2702
- };
2703
- const chooseMedia = temporarilyNotSupport('chooseMedia');
2704
-
2705
- // 视频解码器
2706
- const createVideoDecoder = temporarilyNotSupport('createVideoDecoder');
2707
-
2708
- // 音视频合成
2709
- const createMediaContainer = temporarilyNotSupport('createMediaContainer');
2710
-
2711
- // 实时语音
2712
- const updateVoIPChatMuteConfig = temporarilyNotSupport('updateVoIPChatMuteConfig');
2713
- const subscribeVoIPVideoMembers = temporarilyNotSupport('subscribeVoIPVideoMembers');
2714
- const setEnable1v1Chat = temporarilyNotSupport('setEnable1v1Chat');
2715
- const onVoIPVideoMembersChanged = temporarilyNotSupport('onVoIPVideoMembersChanged');
2716
- const onVoIPChatStateChanged = temporarilyNotSupport('onVoIPChatStateChanged');
2717
- const onVoIPChatSpeakersChanged = temporarilyNotSupport('onVoIPChatSpeakersChanged');
2718
- const onVoIPChatMembersChanged = temporarilyNotSupport('onVoIPChatMembersChanged');
2719
- const onVoIPChatInterrupted = temporarilyNotSupport('onVoIPChatInterrupted');
2720
- const offVoIPVideoMembersChanged = temporarilyNotSupport('offVoIPVideoMembersChanged');
2721
- const offVoIPChatStateChanged = temporarilyNotSupport('offVoIPChatStateChanged');
2722
- const offVoIPChatMembersChanged = temporarilyNotSupport('offVoIPChatMembersChanged');
2723
- const offVoIPChatInterrupted = temporarilyNotSupport('offVoIPChatInterrupted');
2724
- const joinVoIPChat = temporarilyNotSupport('joinVoIPChat');
2725
- const exitVoIPChat = temporarilyNotSupport('exitVoIPChat');
2726
-
2727
- // 跳转
2728
- const openEmbeddedMiniProgram = temporarilyNotSupport('openEmbeddedMiniProgram');
2729
- const navigateToMiniProgram = temporarilyNotSupport('navigateToMiniProgram');
2730
- const navigateBackMiniProgram = temporarilyNotSupport('navigateBackMiniProgram');
2731
- const exitMiniProgram = temporarilyNotSupport('exitMiniProgram');
2732
- const openBusinessView = temporarilyNotSupport('openBusinessView');
2733
-
2734
- /**
2735
- * HTTP Response Header 事件回调函数的参数
2736
- * @typedef {Object} HeadersReceivedParam
2737
- * @property {Object} header 开发者服务器返回的 HTTP Response Header
2738
- */
2739
- /**
2740
- * HTTP Response Header 事件的回调函数
2741
- * @callback HeadersReceivedCallback
2742
- * @param {HeadersReceivedParam} res 参数
2743
- */
2744
- /**
2745
- * 进度变化回调函数的参数
2746
- * @typedef {Object} ProgressUpdateParam
2747
- * @property {number} progress 进度百分比
2748
- * @property {number} [totalBytesWritten] 已经下载的数据长度,单位 Bytes
2749
- * @property {number} [totalBytesSent] 已经上传的数据长度,单位 Bytes
2750
- * @property {number} [totalBytesExpectedToWrite] 预期需要下载的数据总长度,单位 Bytes
2751
- * @property {number} [totalBytesExpectedToSend] 预期需要上传的数据总长度,单位 Bytes
2752
- */
2753
- /**
2754
- * 进度变化事件的回调函数
2755
- * @callback ProgressUpdateCallback
2756
- * @param {ProgressUpdateParam} res 参数
2757
- */
2758
- const NETWORK_TIMEOUT = 60000;
2759
- const XHR_STATS = {
2760
- UNSENT: 0,
2761
- OPENED: 1,
2762
- HEADERS_RECEIVED: 2,
2763
- LOADING: 3,
2764
- DONE: 4 // The operation is complete.
2765
- };
2766
- /**
2767
- * 设置xhr的header
2768
- * @param {XMLHttpRequest} xhr
2769
- * @param {Object} header
2770
- */
2771
- const setHeader = (xhr, header) => {
2772
- let headerKey;
2773
- for (headerKey in header) {
2774
- xhr.setRequestHeader(headerKey, header[headerKey]);
2775
- }
2776
- };
2777
- /**
2778
- * 将 blob url 转化为文件
2779
- * @param {string} url 要转换的 blob url
2780
- * @returns {Promise<File>}
2781
- */
2782
- const convertObjectUrlToBlob = url => {
2783
- return new Promise((resolve, reject) => {
2784
- const xhr = new XMLHttpRequest();
2785
- xhr.open('GET', url, true);
2786
- xhr.responseType = 'blob';
2787
- xhr.withCredentials = true;
2788
- xhr.onload = function () {
2789
- if (this.status === 200) {
2790
- resolve(this.response);
2791
- }
2792
- else {
2793
- /* eslint-disable prefer-promise-reject-errors */
2794
- reject({ status: this.status });
2795
- }
2796
- };
2797
- xhr.send();
2798
- });
2799
- };
2800
-
2801
- const createDownloadTask = ({ url, header, withCredentials = true, timeout, success, error }) => {
2802
- let timeoutInter;
2803
- const apiName = 'downloadFile';
2804
- const xhr = new XMLHttpRequest();
2805
- const callbackManager = {
2806
- headersReceived: new CallbackManager(),
2807
- progressUpdate: new CallbackManager()
2808
- };
2809
- xhr.open('GET', url, true);
2810
- xhr.withCredentials = !!withCredentials;
2811
- xhr.responseType = 'blob';
2812
- setHeader(xhr, header);
2813
- xhr.onprogress = e => {
2814
- const { loaded, total } = e;
2815
- callbackManager.progressUpdate.trigger({
2816
- progress: Math.round(loaded / total * 100),
2817
- totalBytesWritten: loaded,
2818
- totalBytesExpectedToWrite: total
2819
- });
2820
- };
2821
- xhr.onreadystatechange = () => {
2822
- if (xhr.readyState !== XHR_STATS.HEADERS_RECEIVED)
2823
- return;
2824
- callbackManager.headersReceived.trigger({
2825
- header: xhr.getAllResponseHeaders()
2826
- });
2827
- };
2828
- xhr.onload = () => {
2829
- const response = xhr.response;
2830
- const status = xhr.status;
2831
- success({
2832
- errMsg: `${apiName}:ok`,
2833
- statusCode: status,
2834
- tempFilePath: window.URL.createObjectURL(response)
2835
- });
2836
- };
2837
- xhr.onabort = () => {
2838
- clearTimeout(timeoutInter);
2839
- error({
2840
- errMsg: `${apiName}:fail abort`
2841
- });
2842
- };
2843
- xhr.onerror = (e) => {
2844
- error({
2845
- errMsg: `${apiName}:fail ${e.message}`
2846
- });
2847
- };
2848
- /**
2849
- * 中断任务
2850
- */
2851
- const abort = () => {
2852
- xhr.abort();
2853
- };
2854
- const send = () => {
2855
- xhr.send();
2856
- timeoutInter = setTimeout(() => {
2857
- xhr.onabort = null;
2858
- xhr.onload = null;
2859
- xhr.onprogress = null;
2860
- xhr.onreadystatechange = null;
2861
- xhr.onerror = null;
2862
- abort();
2863
- error({
2864
- errMsg: `${apiName}:fail timeout`
2865
- });
2866
- }, timeout || NETWORK_TIMEOUT);
2867
- };
2868
- send();
2869
- /**
2870
- * 监听 HTTP Response Header 事件。会比请求完成事件更早
2871
- * @param {HeadersReceivedCallback} callback HTTP Response Header 事件的回调函数
2872
- */
2873
- const onHeadersReceived = callbackManager.headersReceived.add;
2874
- /**
2875
- * 取消监听 HTTP Response Header 事件
2876
- * @param {HeadersReceivedCallback} callback HTTP Response Header 事件的回调函数
2877
- */
2878
- const offHeadersReceived = callbackManager.headersReceived.remove;
2879
- /**
2880
- * 监听进度变化事件
2881
- * @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
2882
- */
2883
- const onProgressUpdate = callbackManager.progressUpdate.add;
2884
- /**
2885
- * 取消监听进度变化事件
2886
- * @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
2887
- */
2888
- const offProgressUpdate = callbackManager.progressUpdate.remove;
2889
- return {
2890
- abort,
2891
- onHeadersReceived,
2892
- offHeadersReceived,
2893
- onProgressUpdate,
2894
- offProgressUpdate
2895
- };
2896
- };
2897
- /**
2898
- * 下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径。使用前请注意阅读相关说明。
2899
- * 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
2900
- */
2901
- const downloadFile = ({ url, header, withCredentials, timeout, success, fail, complete }) => {
2902
- let task;
2903
- const result = new Promise((resolve, reject) => {
2904
- task = createDownloadTask({
2905
- url,
2906
- header,
2907
- withCredentials,
2908
- timeout,
2909
- success: res => {
2910
- success && success(res);
2911
- complete && complete(res);
2912
- resolve(res);
2913
- },
2914
- error: res => {
2915
- fail && fail(res);
2916
- complete && complete(res);
2917
- reject(res);
2918
- }
2919
- });
2920
- });
2921
- result.headersReceive = task.onHeadersReceived;
2922
- result.progress = task.onProgressUpdate;
2923
- return new Proxy(result, {
2924
- get(target, prop) {
2925
- const object = prop in task ? task : target;
2926
- const value = object[prop];
2927
- return typeof value === 'function' ? value.bind(object) : value;
2928
- },
2929
- });
2930
- };
2931
-
2932
- // mDNS
2933
- const stopLocalServiceDiscovery = temporarilyNotSupport('stopLocalServiceDiscovery');
2934
- const startLocalServiceDiscovery = temporarilyNotSupport('startLocalServiceDiscovery');
2935
- const onLocalServiceResolveFail = temporarilyNotSupport('onLocalServiceResolveFail');
2936
- const onLocalServiceLost = temporarilyNotSupport('onLocalServiceLost');
2937
- const onLocalServiceFound = temporarilyNotSupport('onLocalServiceFound');
2938
- const onLocalServiceDiscoveryStop = temporarilyNotSupport('onLocalServiceDiscoveryStop');
2939
- const offLocalServiceResolveFail = temporarilyNotSupport('offLocalServiceResolveFail');
2940
- const offLocalServiceLost = temporarilyNotSupport('offLocalServiceLost');
2941
- const offLocalServiceFound = temporarilyNotSupport('offLocalServiceFound');
2942
- const offLocalServiceDiscoveryStop = temporarilyNotSupport('offLocalServiceDiscoveryStop');
2943
-
2944
- // @ts-ignore
2945
- const { Link: Link$1 } = Taro;
2946
- function generateRequestUrlWithParams(url = '', params) {
2947
- params = typeof params === 'string' ? params : serializeParams(params);
2948
- if (params) {
2949
- url += (~url.indexOf('?') ? '&' : '?') + params;
2950
- }
2951
- url = url.replace('?&', '?');
2952
- return url;
2953
- }
2954
- function _request(options = {}) {
2955
- const { success, complete, fail } = options;
2956
- let url = options.url || '';
2957
- const params = {};
2958
- const res = {};
2959
- if (options.jsonp) {
2960
- const { jsonp } = options, opts = __rest(options, ["jsonp"]);
2961
- Object.assign(params, opts);
2962
- // @ts-ignore
2963
- params.params = opts.data;
2964
- params.cache = opts.jsonpCache;
2965
- if (typeof jsonp === 'string') {
2966
- // @ts-ignore
2967
- params.name = jsonp;
2968
- }
2969
- return jsonpRetry(url, params)
2970
- .then(data => {
2971
- res.statusCode = 200;
2972
- res.data = data;
2973
- shared.isFunction(success) && success(res);
2974
- shared.isFunction(complete) && complete(res);
2975
- return res;
2976
- })
2977
- .catch(err => {
2978
- shared.isFunction(fail) && fail(err);
2979
- shared.isFunction(complete) && complete(res);
2980
- return Promise.reject(err);
2981
- });
2982
- }
2983
- params.method = options.method || 'GET';
2984
- const methodUpper = params.method.toUpperCase();
2985
- params.cache = options.cache || 'default';
2986
- if (methodUpper === 'GET' || methodUpper === 'HEAD') {
2987
- url = generateRequestUrlWithParams(url, options.data);
2988
- }
2989
- else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(options.data)) >= 0) {
2990
- options.header = options.header || {};
2991
- const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type');
2992
- if (!keyOfContentType) {
2993
- options.header['Content-Type'] = 'application/json';
2994
- }
2995
- const contentType = options.header[keyOfContentType || 'Content-Type'];
2996
- if (contentType.indexOf('application/json') >= 0) {
2997
- params.body = JSON.stringify(options.data);
2998
- }
2999
- else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {
3000
- params.body = serializeParams(options.data);
3001
- }
3002
- else {
3003
- params.body = options.data;
3004
- }
3005
- }
3006
- else {
3007
- params.body = options.data;
3008
- }
3009
- if (options.header) {
3010
- params.headers = options.header;
3011
- }
3012
- if (options.mode) {
3013
- params.mode = options.mode;
3014
- }
3015
- let timeoutTimer = null;
3016
- if (options.signal) {
3017
- params.signal = options.signal;
3018
- }
3019
- else if (typeof options.timeout === 'number') {
3020
- const controller = new window.AbortController();
3021
- params.signal = controller.signal;
3022
- timeoutTimer = setTimeout(function () {
3023
- controller.abort();
3024
- }, options.timeout);
3025
- }
3026
- params.credentials = options.credentials;
3027
- return fetch(url, params)
3028
- .then(response => {
3029
- if (timeoutTimer) {
3030
- clearTimeout(timeoutTimer);
3031
- timeoutTimer = null;
3032
- }
3033
- if (!response) {
3034
- const errorResponse = { ok: false };
3035
- throw errorResponse;
3036
- }
3037
- res.statusCode = response.status;
3038
- res.header = {};
3039
- for (const key of response.headers.keys()) {
3040
- res.header[key] = response.headers.get(key);
3041
- }
3042
- if (options.responseType === 'arraybuffer') {
3043
- return response.arrayBuffer();
3044
- }
3045
- if (res.statusCode !== 204) {
3046
- if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
3047
- return response.json().catch(() => {
3048
- return null;
3049
- });
3050
- }
3051
- }
3052
- if (options.responseType === 'text' || options.dataType === 'text') {
3053
- return response.text();
3054
- }
3055
- return Promise.resolve(null);
3056
- })
3057
- .then(data => {
3058
- res.data = data;
3059
- shared.isFunction(success) && success(res);
3060
- shared.isFunction(complete) && complete(res);
3061
- return res;
3062
- })
3063
- .catch(err => {
3064
- if (timeoutTimer) {
3065
- clearTimeout(timeoutTimer);
3066
- timeoutTimer = null;
3067
- }
3068
- shared.isFunction(fail) && fail(err);
3069
- shared.isFunction(complete) && complete(res);
3070
- err.statusCode = res.statusCode;
3071
- err.errMsg = err.message;
3072
- return Promise.reject(err);
3073
- });
3074
- }
3075
- function taroInterceptor(chain) {
3076
- return _request(chain.requestParams);
3077
- }
3078
- const link = new Link$1(taroInterceptor);
3079
- const request = ((...args) => {
3080
- const [url = '', options = {}] = args;
3081
- if (typeof url === 'string') {
3082
- options.url = url;
3083
- }
3084
- else {
3085
- Object.assign(options, url);
3086
- }
3087
- return link.request(options);
3088
- });
3089
- const addInterceptor = link.addInterceptor.bind(link);
3090
- const cleanInterceptors = link.cleanInterceptors.bind(link);
3091
-
3092
- // TCP 通信
3093
- const createTCPSocket = temporarilyNotSupport('createTCPSocket');
3094
-
3095
- // UDP 通信
3096
- const createUDPSocket = temporarilyNotSupport('createUDPSocket');
3097
-
3098
- const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, withCredentials = true, success, error }) => {
3099
- let timeoutInter;
3100
- let formKey;
3101
- const apiName = 'uploadFile';
3102
- const xhr = new XMLHttpRequest();
3103
- const form = new FormData();
3104
- const callbackManager = {
3105
- headersReceived: new CallbackManager(),
3106
- progressUpdate: new CallbackManager()
3107
- };
3108
- xhr.open('POST', url);
3109
- xhr.withCredentials = !!withCredentials;
3110
- setHeader(xhr, header);
3111
- for (formKey in formData) {
3112
- form.append(formKey, formData[formKey]);
3113
- }
3114
- xhr.upload.onprogress = e => {
3115
- const { loaded, total } = e;
3116
- callbackManager.progressUpdate.trigger({
3117
- progress: Math.round(loaded / total * 100),
3118
- totalBytesSent: loaded,
3119
- totalBytesExpectedToSend: total
3120
- });
3121
- };
3122
- xhr.onreadystatechange = () => {
3123
- if (xhr.readyState !== XHR_STATS.HEADERS_RECEIVED)
3124
- return;
3125
- callbackManager.headersReceived.trigger({
3126
- header: xhr.getAllResponseHeaders()
3127
- });
3128
- };
3129
- xhr.onload = () => {
3130
- const status = xhr.status;
3131
- clearTimeout(timeoutInter);
3132
- success({
3133
- errMsg: `${apiName}:ok`,
3134
- statusCode: status,
3135
- data: xhr.responseText || xhr.response
3136
- });
3137
- };
3138
- xhr.onabort = () => {
3139
- clearTimeout(timeoutInter);
3140
- error({
3141
- errMsg: `${apiName}:fail abort`
3142
- });
3143
- };
3144
- xhr.onerror = (e) => {
3145
- clearTimeout(timeoutInter);
3146
- error({
3147
- errMsg: `${apiName}:fail ${e.message}`
3148
- });
3149
- };
3150
- /**
3151
- * 中断任务
3152
- */
3153
- const abort = () => {
3154
- clearTimeout(timeoutInter);
3155
- xhr.abort();
3156
- };
3157
- const send = () => {
3158
- xhr.send(form);
3159
- timeoutInter = setTimeout(() => {
3160
- xhr.onabort = null;
3161
- xhr.onload = null;
3162
- xhr.upload.onprogress = null;
3163
- xhr.onreadystatechange = null;
3164
- xhr.onerror = null;
3165
- abort();
3166
- error({
3167
- errMsg: `${apiName}:fail timeout`
3168
- });
3169
- }, timeout || NETWORK_TIMEOUT);
3170
- };
3171
- convertObjectUrlToBlob(filePath)
3172
- .then((fileObj) => {
3173
- if (!fileName) {
3174
- fileName = typeof fileObj !== 'string' && fileObj.name;
3175
- }
3176
- form.append(name, fileObj, fileName || `file-${Date.now()}`);
3177
- send();
3178
- })
3179
- .catch(e => {
3180
- error({
3181
- errMsg: `${apiName}:fail ${e.message}`
3182
- });
3183
- });
3184
- /**
3185
- * 监听 HTTP Response Header 事件。会比请求完成事件更早
3186
- * @param {HeadersReceivedCallback} callback HTTP Response Header 事件的回调函数
3187
- */
3188
- const onHeadersReceived = callbackManager.headersReceived.add;
3189
- /**
3190
- * 取消监听 HTTP Response Header 事件
3191
- * @param {HeadersReceivedCallback} callback HTTP Response Header 事件的回调函数
3192
- */
3193
- const offHeadersReceived = callbackManager.headersReceived.remove;
3194
- /**
3195
- * 监听进度变化事件
3196
- * @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
3197
- */
3198
- const onProgressUpdate = callbackManager.progressUpdate.add;
3199
- /**
3200
- * 取消监听进度变化事件
3201
- * @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
3202
- */
3203
- const offProgressUpdate = callbackManager.progressUpdate.remove;
3204
- return {
3205
- abort,
3206
- onHeadersReceived,
3207
- offHeadersReceived,
3208
- onProgressUpdate,
3209
- offProgressUpdate
3210
- };
3211
- };
3212
- /**
3213
- * 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。
3214
- */
3215
- const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, withCredentials, success, fail, complete }) => {
3216
- let task;
3217
- const result = new Promise((resolve, reject) => {
3218
- task = createUploadTask({
3219
- url,
3220
- header,
3221
- name,
3222
- filePath,
3223
- formData,
3224
- timeout,
3225
- fileName,
3226
- withCredentials,
3227
- success: res => {
3228
- success && success(res);
3229
- complete && complete(res);
3230
- resolve(res);
3231
- },
3232
- error: res => {
3233
- fail && fail(res);
3234
- complete && complete(res);
3235
- reject(res);
3236
- }
3237
- });
3238
- });
3239
- result.headersReceive = task.onHeadersReceived;
3240
- result.progress = task.onProgressUpdate;
3241
- return new Proxy(result, {
3242
- get(target, prop) {
3243
- const object = prop in task ? task : target;
3244
- const value = object[prop];
3245
- return typeof value === 'function' ? value.bind(object) : value;
3246
- },
3247
- });
3248
- };
3249
-
3250
- class SocketTask {
3251
- constructor(url, protocols) {
3252
- if (protocols && protocols.length) {
3253
- this.ws = new WebSocket(url, protocols);
3254
- }
3255
- else {
3256
- this.ws = new WebSocket(url);
3257
- }
3258
- this.CONNECTING = 0;
3259
- this.OPEN = 1;
3260
- this.CLOSING = 2;
3261
- this.CLOSED = 3;
3262
- }
3263
- get readyState() {
3264
- return this.ws.readyState;
3265
- }
3266
- send(opts = {}) {
3267
- if (typeof opts !== 'object' || !opts)
3268
- opts = {};
3269
- const { data = '', success, fail, complete } = opts;
3270
- if (this.readyState !== 1) {
3271
- const res = { errMsg: 'SocketTask.send:fail SocketTask.readState is not OPEN' };
3272
- console.error(res.errMsg);
3273
- shared.isFunction(fail) && fail(res);
3274
- shared.isFunction(complete) && complete(res);
3275
- return Promise.reject(res);
3276
- }
3277
- this.ws.send(data);
3278
- const res = { errMsg: 'sendSocketMessage:ok' };
3279
- shared.isFunction(success) && success(res);
3280
- shared.isFunction(complete) && complete(res);
3281
- return Promise.resolve(res);
3282
- }
3283
- close(opts = {}) {
3284
- if (typeof opts !== 'object' || !opts)
3285
- opts = {};
3286
- const { code = 1000, reason = 'server complete,close', success, complete } = opts;
3287
- this.closeDetail = { code, reason };
3288
- // 主动断开时需要重置链接数
3289
- this._destroyWhenClose && this._destroyWhenClose();
3290
- this.ws.close();
3291
- const res = { errMsg: 'closeSocket:ok' };
3292
- shared.isFunction(success) && success(res);
3293
- shared.isFunction(complete) && complete(res);
3294
- return Promise.resolve(res);
3295
- }
3296
- onOpen(func) {
3297
- this.ws.onopen = func;
3298
- }
3299
- onMessage(func) {
3300
- this.ws.onmessage = func;
3301
- }
3302
- onClose(func) {
3303
- this.ws.onclose = () => {
3304
- // 若服务器方断掉也需要重置链接数
3305
- this._destroyWhenClose && this._destroyWhenClose();
3306
- func(this.closeDetail || { code: 1006, reason: 'abnormal closure' });
3307
- };
3308
- }
3309
- onError(func) {
3310
- this.ws.onerror = func;
3311
- }
3312
- }
3313
-
3314
- let socketTasks = [];
3315
- let socketsCounter = 1;
3316
- function sendSocketMessage() {
3317
- console.warn('Deprecated.Please use socketTask.send instead.');
3318
- }
3319
- function onSocketOpen() {
3320
- console.warn('Deprecated.Please use socketTask.onOpen instead.');
3321
- }
3322
- function onSocketMessage() {
3323
- console.warn('Deprecated.Please use socketTask.onMessage instead.');
3324
- }
3325
- function onSocketError() {
3326
- console.warn('Deprecated.Please use socketTask.onError instead.');
3327
- }
3328
- function onSocketClose() {
3329
- console.warn('Deprecated.Please use socketTask.onClose instead.');
3330
- }
3331
- function connectSocket(options) {
3332
- const name = 'connectSocket';
3333
- return new Promise((resolve, reject) => {
3334
- // options must be an Object
3335
- const isObject = shouldBeObject(options);
3336
- if (!isObject.flag) {
3337
- const res = { errMsg: `${name}:fail ${isObject.msg}` };
3338
- console.error(res.errMsg);
3339
- return reject(res);
3340
- }
3341
- const { url, protocols, success, fail, complete } = options;
3342
- const handle = new MethodHandler({ name, success, fail, complete });
3343
- // options.url must be String
3344
- if (typeof url !== 'string') {
3345
- return handle.fail({
3346
- errMsg: getParameterError({
3347
- para: 'url',
3348
- correct: 'String',
3349
- wrong: url
3350
- })
3351
- }, { resolve, reject });
3352
- }
3353
- // options.url must be invalid
3354
- if (!url.startsWith('ws://') && !url.startsWith('wss://')) {
3355
- return handle.fail({
3356
- errMsg: `request:fail invalid url "${url}"`
3357
- }, { resolve, reject });
3358
- }
3359
- // protocols must be array
3360
- const _protocols = Array.isArray(protocols) ? protocols : null;
3361
- // 2 connection at most
3362
- if (socketTasks.length > 1) {
3363
- return handle.fail({
3364
- errMsg: '同时最多发起 2 个 socket 请求,更多请参考文档。'
3365
- }, { resolve, reject });
3366
- }
3367
- const task = new SocketTask(url, _protocols);
3368
- task._destroyWhenClose = function () {
3369
- socketTasks = socketTasks.filter(socketTask => socketTask !== this);
3370
- };
3371
- socketTasks.push(task);
3372
- handle.success({
3373
- socketTaskId: socketsCounter++
3374
- });
3375
- return resolve(task);
3376
- });
3377
- }
3378
- function closeSocket() {
3379
- console.warn('Deprecated.Please use socketTask.close instead.');
3380
- }
3381
-
3382
- // 帐号信息
3383
- const getAccountInfoSync = temporarilyNotSupport('getAccountInfoSync');
3384
-
3385
- // 收货地址
3386
- const chooseAddress = temporarilyNotSupport('chooseAddress');
3387
-
3388
- // 授权
3389
- const authorizeForMiniProgram = temporarilyNotSupport('authorizeForMiniProgram');
3390
- const authorize = temporarilyNotSupport('authorize');
3391
-
3392
- // 卡券
3393
- const openCard = temporarilyNotSupport('openCard');
3394
- const addCard = temporarilyNotSupport('addCard');
3395
-
3396
- // 视频号
3397
- const reserveChannelsLive = temporarilyNotSupport('reserveChannelsLive');
3398
- const openChannelsLive = temporarilyNotSupport('openChannelsLive');
3399
- const openChannelsEvent = temporarilyNotSupport('openChannelsEvent');
3400
- const openChannelsActivity = temporarilyNotSupport('openChannelsActivity');
3401
- const getChannelsLiveNoticeInfo = temporarilyNotSupport('getChannelsLiveNoticeInfo');
3402
- const getChannelsLiveInfo = temporarilyNotSupport('getChannelsLiveInfo');
3403
-
3404
- // 微信客服
3405
- const openCustomerServiceChat = temporarilyNotSupport('openCustomerServiceChat');
3406
-
3407
- // 过往接口
3408
- const checkIsSupportFacialRecognition = temporarilyNotSupport('checkIsSupportFacialRecognition');
3409
- const startFacialRecognitionVerify = temporarilyNotSupport('startFacialRecognitionVerify');
3410
- const startFacialRecognitionVerifyAndUploadVideo = temporarilyNotSupport('startFacialRecognitionVerifyAndUploadVideo');
3411
- const faceVerifyForPay = temporarilyNotSupport('faceVerifyForPay');
3412
-
3413
- // 收藏
3414
- const addVideoToFavorites = temporarilyNotSupport('addVideoToFavorites');
3415
- const addFileToFavorites = temporarilyNotSupport('addFileToFavorites');
3416
- const checkIsAddedToMyMiniProgram = temporarilyNotSupport('checkIsAddedToMyMiniProgram');
3417
-
3418
- // 微信群
3419
- const getGroupEnterInfo = temporarilyNotSupport('getGroupEnterInfo');
3420
-
3421
- // 发票
3422
- const chooseInvoiceTitle = temporarilyNotSupport('chooseInvoiceTitle');
3423
- const chooseInvoice = temporarilyNotSupport('chooseInvoice');
3424
-
3425
- // 车牌
3426
- const chooseLicensePlate = temporarilyNotSupport('chooseLicensePlate');
3427
-
3428
- // 帐号信息
3429
- const pluginLogin = temporarilyNotSupport('pluginLogin');
3430
- const login = temporarilyNotSupport('login');
3431
- const checkSession = temporarilyNotSupport('checkSession');
3432
-
3433
- // 微信红包
3434
- const showRedPackage = temporarilyNotSupport('showRedPackage');
3435
-
3436
- // 设置
3437
- const openSetting = temporarilyNotSupport('openSetting');
3438
- const getSetting = temporarilyNotSupport('getSetting');
3439
-
3440
- // 生物认证
3441
- const startSoterAuthentication = temporarilyNotSupport('startSoterAuthentication');
3442
- const checkIsSupportSoterAuthentication = temporarilyNotSupport('checkIsSupportSoterAuthentication');
3443
- const checkIsSoterEnrolledInDevice = temporarilyNotSupport('checkIsSoterEnrolledInDevice');
3444
-
3445
- // 订阅消息
3446
- const requestSubscribeMessage = temporarilyNotSupport('requestSubscribeMessage');
3447
- // 订阅设备消息
3448
- const requestSubscribeDeviceMessage = temporarilyNotSupport('requestSubscribeDeviceMessage');
3449
-
3450
- // 用户信息
3451
- const getUserProfile = temporarilyNotSupport('getUserProfile');
3452
- const getUserInfo = temporarilyNotSupport('getUserInfo');
3453
-
3454
- // 微信运动
3455
- const shareToWeRun = temporarilyNotSupport('shareToWeRun');
3456
- const getWeRunData = temporarilyNotSupport('getWeRunData');
3457
-
3458
- // 支付
3459
- const requestPayment = temporarilyNotSupport('requestPayment');
3460
- const requestOrderPayment = temporarilyNotSupport('requestOrderPayment');
3461
-
3462
- // 打开手Q说说发表界面
3463
- const openQzonePublish = temporarilyNotSupport('openQzonePublish');
3464
-
3465
- // 路由
3466
- // FIXME 方法导出类型未对齐,后续修复
3467
-
3468
- // 转发
3469
- const updateShareMenu = temporarilyNotSupport('updateShareMenu');
3470
- const showShareMenu = temporarilyNotSupport('showShareMenu');
3471
- const showShareImageMenu = temporarilyNotSupport('showShareImageMenu');
3472
- const shareVideoMessage = temporarilyNotSupport('shareVideoMessage');
3473
- const shareFileMessage = temporarilyNotSupport('shareFileMessage');
3474
- const onCopyUrl = temporarilyNotSupport('onCopyUrl');
3475
- const offCopyUrl = temporarilyNotSupport('offCopyUrl');
3476
- const hideShareMenu = temporarilyNotSupport('hideShareMenu');
3477
- const getShareInfo = temporarilyNotSupport('getShareInfo');
3478
- const authPrivateMessage = temporarilyNotSupport('authPrivateMessage');
3479
-
3480
- const setPageInfo = temporarilyNotSupport('setPageInfo');
3481
- // 百度小程序 AI 相关
3482
- const ocrIdCard = temporarilyNotSupport('ocrIdCard');
3483
- const ocrBankCard = temporarilyNotSupport('ocrBankCard');
3484
- const ocrDrivingLicense = temporarilyNotSupport('ocrDrivingLicense');
3485
- const ocrVehicleLicense = temporarilyNotSupport('ocrVehicleLicense');
3486
- const textReview = temporarilyNotSupport('textReview');
3487
- const textToAudio = temporarilyNotSupport('textToAudio');
3488
- const imageAudit = temporarilyNotSupport('imageAudit');
3489
- const advancedGeneralIdentify = temporarilyNotSupport('advancedGeneralIdentify');
3490
- const objectDetectIdentify = temporarilyNotSupport('objectDetectIdentify');
3491
- const carClassify = temporarilyNotSupport('carClassify');
3492
- const dishClassify = temporarilyNotSupport('dishClassify');
3493
- const logoClassify = temporarilyNotSupport('logoClassify');
3494
- const animalClassify = temporarilyNotSupport('animalClassify');
3495
- const plantClassify = temporarilyNotSupport('plantClassify');
3496
- // 用户信息
3497
- const getSwanId = temporarilyNotSupport('getSwanId');
3498
- // 百度收银台支付
3499
- const requestPolymerPayment = temporarilyNotSupport('requestPolymerPayment');
3500
- // 打开小程序
3501
- const navigateToSmartGameProgram = temporarilyNotSupport('navigateToSmartGameProgram');
3502
- const navigateToSmartProgram = temporarilyNotSupport('navigateToSmartProgram');
3503
- const navigateBackSmartProgram = temporarilyNotSupport('navigateBackSmartProgram');
3504
- const preloadSubPackage = temporarilyNotSupport('preloadSubPackage');
3505
-
3506
- /**
3507
- * H5 下的 styleSheet 操作
3508
- * @author leeenx
3509
- */
3510
- class StyleSheet {
3511
- constructor() {
3512
- this.$style = null;
3513
- this.sheet = null;
3514
- this.appendStyleSheet = () => {
3515
- if (this.$style) {
3516
- const head = document.getElementsByTagName('head')[0];
3517
- this.$style.setAttribute('type', 'text/css');
3518
- this.$style.setAttribute('data-type', 'Taro');
3519
- head.appendChild(this.$style);
3520
- this.sheet = this.$style.sheet;
3521
- }
3522
- if (this.sheet && !('insertRule' in this.sheet)) {
3523
- console.warn('当前浏览器不支持 stylesheet.insertRule 接口');
3524
- }
3525
- };
3526
- // 添加样式命令
3527
- this.add = (cssText, index = 0) => {
3528
- var _a;
3529
- if (this.sheet === null) {
3530
- // $style 未插入到 DOM
3531
- this.appendStyleSheet();
3532
- }
3533
- (_a = this.sheet) === null || _a === void 0 ? void 0 : _a.insertRule(cssText, index);
3534
- };
3535
- this.$style = document.createElement('style');
3536
- }
3537
- }
3538
- const styleSheet = new StyleSheet();
3539
- // 监听事件
3540
- let TRANSITION_END = 'transitionend';
3541
- let TRANSFORM = 'transform';
3542
- const $detect = document.createElement('div');
3543
- $detect.style.cssText = '-webkit-animation-name:webkit;-moz-animation-name:moz;-ms-animation-name:ms;animation-name:standard;';
3544
- if ($detect.style['animation-name'] === 'standard') {
3545
- // 支持标准写法
3546
- TRANSITION_END = 'transitionend';
3547
- TRANSFORM = 'transform';
3548
- }
3549
- else if ($detect.style['-webkit-animation-name'] === 'webkit') {
3550
- // webkit 前缀
3551
- TRANSITION_END = 'webkitTransitionEnd';
3552
- TRANSFORM = '-webkit-transform';
3553
- }
3554
- else if ($detect.style['-moz-animation-name'] === 'moz') {
3555
- // moz 前缀
3556
- TRANSITION_END = 'mozTransitionEnd';
3557
- TRANSFORM = '-moz-transform';
3558
- }
3559
- else if ($detect.style['-ms-animation-name'] === 'ms') {
3560
- // ms 前缀
3561
- TRANSITION_END = 'msTransitionEnd';
3562
- TRANSFORM = '-ms-transform';
3563
- }
3564
- let animId = 0;
3565
- class Animation {
3566
- constructor({ duration = 400, delay = 0, timingFunction = 'linear', transformOrigin = '50% 50% 0', unit = 'px' } = {}) {
3567
- // 属性组合
3568
- this.rules = [];
3569
- // transform 对象
3570
- this.transform = [`${TRANSFORM}:`];
3571
- // 组合动画
3572
- this.steps = [];
3573
- // 动画 map ----- 永久保留
3574
- this.animationMap = {};
3575
- // animationMap 的长度
3576
- this.animationMapCount = 0;
3577
- // 默认值
3578
- this.setDefault(duration, delay, timingFunction, transformOrigin);
3579
- this.unit = unit;
3580
- // atom 环境下,animation 属性不会显示,所以要改成 data-animation
3581
- let animAttr = 'animation';
3582
- // 动画 id
3583
- this.id = ++animId;
3584
- // 监听事件
3585
- document.body.addEventListener(TRANSITION_END, (e) => {
3586
- const target = e.target;
3587
- if (target.getAttribute(animAttr) === null) {
3588
- animAttr = 'data-animation';
3589
- }
3590
- const animData = target.getAttribute(animAttr);
3591
- // 没有动画存在
3592
- if (animData === null)
3593
- return;
3594
- const [animName, animPath] = animData.split('__');
3595
- if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
3596
- const [animIndex, __stepIndex = 0] = animPath.split('--');
3597
- const stepIndex = Number(__stepIndex);
3598
- // 动画总的关键帧
3599
- const animStepsCount = this.animationMap[`${animName}__${animIndex}`];
3600
- const animStepsMaxIndex = animStepsCount - 1;
3601
- if (stepIndex < animStepsMaxIndex) {
3602
- // 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
3603
- target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`);
3604
- if (animAttr === 'animation') {
3605
- // Nerv 环境,animation & data-animation 双重保险
3606
- target.setAttribute('data-animation', `${animName}__${animIndex}--${stepIndex + 1}`);
3607
- }
3608
- }
3609
- }
3610
- });
3611
- }
3612
- transformUnit(...args) {
3613
- const ret = [];
3614
- args.forEach(each => {
3615
- ret.push(isNaN(each) ? each : `${each}${this.unit}`);
3616
- });
3617
- return ret;
3618
- }
3619
- // 设置默认值
3620
- setDefault(duration, delay, timingFunction, transformOrigin) {
3621
- this.DEFAULT = { duration, delay, timingFunction, transformOrigin };
3622
- }
3623
- matrix(a, b, c, d, tx, ty) {
3624
- this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`);
3625
- return this;
3626
- }
3627
- matrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
3628
- this.transform.push(`matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`);
3629
- return this;
3630
- }
3631
- rotate(angle) {
3632
- this.transform.push(`rotate(${angle}deg)`);
3633
- return this;
3634
- }
3635
- rotate3d(x, y, z, angle) {
3636
- if (typeof y !== 'number') {
3637
- this.transform.push(`rotate3d(${x})`);
3638
- }
3639
- else {
3640
- this.transform.push(`rotate3d(${x}, ${y || 0}, ${z || 0}, ${angle || 0}deg)`);
3641
- }
3642
- return this;
2851
+ return this;
3643
2852
  }
3644
2853
  rotateX(angle) {
3645
2854
  this.transform.push(`rotateX(${angle}deg)`);
@@ -3793,8 +3002,8 @@ const createAnimation = (option) => {
3793
3002
  };
3794
3003
 
3795
3004
  // 背景
3796
- const setBackgroundTextStyle = temporarilyNotSupport('setBackgroundTextStyle');
3797
- const setBackgroundColor = temporarilyNotSupport('setBackgroundColor');
3005
+ const setBackgroundTextStyle = /* @__PURE__ */ temporarilyNotSupport('setBackgroundTextStyle');
3006
+ const setBackgroundColor = /* @__PURE__ */ temporarilyNotSupport('setBackgroundColor');
3798
3007
 
3799
3008
  // 自定义组件
3800
3009
  const nextTick = Taro.nextTick;
@@ -4423,728 +3632,1928 @@ function init(doc) {
4423
3632
  doc.querySelector('head').appendChild(taroStyle);
4424
3633
  status = 'ready';
4425
3634
  }
4426
- const toast = new Toast();
4427
- const modal = new Modal();
4428
- const actionSheet = new ActionSheet();
4429
- const showToast = (options = { title: '' }) => {
3635
+ const toast = new Toast();
3636
+ const modal = new Modal();
3637
+ const actionSheet = new ActionSheet();
3638
+ const showToast = (options = { title: '' }) => {
3639
+ init(document);
3640
+ options = Object.assign({
3641
+ title: '',
3642
+ icon: 'success',
3643
+ image: '',
3644
+ duration: 1500,
3645
+ mask: false
3646
+ }, options);
3647
+ const { success, fail, complete } = options;
3648
+ const handle = new MethodHandler({ name: 'showToast', success, fail, complete });
3649
+ if (typeof options.title !== 'string') {
3650
+ return handle.fail({
3651
+ errMsg: getParameterError({
3652
+ para: 'title',
3653
+ correct: 'String',
3654
+ wrong: options.title
3655
+ })
3656
+ });
3657
+ }
3658
+ if (typeof options.duration !== 'number') {
3659
+ return handle.fail({
3660
+ errMsg: getParameterError({
3661
+ para: 'duration',
3662
+ correct: 'Number',
3663
+ wrong: options.duration
3664
+ })
3665
+ });
3666
+ }
3667
+ if (options.image && typeof options.image !== 'string')
3668
+ options.image = '';
3669
+ options.mask = !!options.mask;
3670
+ let errMsg = '';
3671
+ if (!toast.el) {
3672
+ errMsg = toast.create(options, 'toast');
3673
+ }
3674
+ else {
3675
+ errMsg = toast.show(options, 'toast');
3676
+ }
3677
+ return handle.success({ errMsg });
3678
+ };
3679
+ const hideToast = ({ noConflict = false, success, fail, complete } = {}) => {
3680
+ const handle = new MethodHandler({ name: 'hideToast', success, fail, complete });
3681
+ if (!toast.el)
3682
+ return handle.success();
3683
+ toast.hide(0, noConflict ? 'toast' : '');
3684
+ return handle.success();
3685
+ };
3686
+ const showLoading = (options = { title: '' }) => {
3687
+ init(document);
3688
+ options = Object.assign({
3689
+ title: '',
3690
+ mask: false
3691
+ }, options);
3692
+ const { success, fail, complete } = options;
3693
+ const handle = new MethodHandler({ name: 'showLoading', success, fail, complete });
3694
+ const config = {
3695
+ icon: 'loading',
3696
+ image: '',
3697
+ duration: -1
3698
+ };
3699
+ options = Object.assign({}, options, config);
3700
+ if (typeof options.title !== 'string') {
3701
+ return handle.fail({
3702
+ errMsg: getParameterError({
3703
+ para: 'title',
3704
+ correct: 'String',
3705
+ wrong: options.title
3706
+ })
3707
+ });
3708
+ }
3709
+ options.mask = !!options.mask;
3710
+ let errMsg = '';
3711
+ if (!toast.el) {
3712
+ errMsg = toast.create(options, 'loading');
3713
+ }
3714
+ else {
3715
+ errMsg = toast.show(options, 'loading');
3716
+ }
3717
+ return handle.success({ errMsg });
3718
+ };
3719
+ const hideLoading = ({ noConflict = false, success, fail, complete } = {}) => {
3720
+ const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete });
3721
+ if (!toast.el)
3722
+ return handle.success();
3723
+ toast.hide(0, noConflict ? 'loading' : '');
3724
+ return handle.success();
3725
+ };
3726
+ const showModal = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
3727
+ init(document);
3728
+ options = Object.assign({
3729
+ title: '',
3730
+ content: '',
3731
+ showCancel: true,
3732
+ cancelText: '取消',
3733
+ cancelColor: '#000000',
3734
+ confirmText: '确定',
3735
+ confirmColor: '#3CC51F'
3736
+ }, options);
3737
+ const { success, fail, complete } = options;
3738
+ const handle = new MethodHandler({ name: 'showModal', success, fail, complete });
3739
+ if (typeof options.title !== 'string') {
3740
+ return handle.fail({
3741
+ errMsg: getParameterError({
3742
+ para: 'title',
3743
+ correct: 'String',
3744
+ wrong: options.title
3745
+ })
3746
+ });
3747
+ }
3748
+ if (typeof options.content !== 'string') {
3749
+ return handle.fail({
3750
+ errMsg: getParameterError({
3751
+ para: 'content',
3752
+ correct: 'String',
3753
+ wrong: options.content
3754
+ })
3755
+ });
3756
+ }
3757
+ if (typeof options.cancelText !== 'string') {
3758
+ return handle.fail({
3759
+ errMsg: getParameterError({
3760
+ para: 'cancelText',
3761
+ correct: 'String',
3762
+ wrong: options.cancelText
3763
+ })
3764
+ });
3765
+ }
3766
+ if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
3767
+ return handle.fail({
3768
+ errMsg: 'cancelText length should not larger then 4 Chinese characters'
3769
+ });
3770
+ }
3771
+ if (typeof options.confirmText !== 'string') {
3772
+ return handle.fail({
3773
+ errMsg: getParameterError({
3774
+ para: 'confirmText',
3775
+ correct: 'String',
3776
+ wrong: options.confirmText
3777
+ })
3778
+ });
3779
+ }
3780
+ if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
3781
+ return handle.fail({
3782
+ errMsg: 'confirmText length should not larger then 4 Chinese characters'
3783
+ });
3784
+ }
3785
+ if (typeof options.cancelColor !== 'string') {
3786
+ return handle.fail({
3787
+ errMsg: getParameterError({
3788
+ para: 'cancelColor',
3789
+ correct: 'String',
3790
+ wrong: options.cancelColor
3791
+ })
3792
+ });
3793
+ }
3794
+ if (typeof options.confirmColor !== 'string') {
3795
+ return handle.fail({
3796
+ errMsg: getParameterError({
3797
+ para: 'confirmColor',
3798
+ correct: 'String',
3799
+ wrong: options.confirmColor
3800
+ })
3801
+ });
3802
+ }
3803
+ options.showCancel = !!options.showCancel;
3804
+ let result = '';
3805
+ if (!modal.el) {
3806
+ result = yield modal.create(options);
3807
+ }
3808
+ else {
3809
+ result = yield modal.show(options);
3810
+ }
3811
+ const res = { cancel: !1, confirm: !1 };
3812
+ res[result] = !0;
3813
+ return handle.success(res);
3814
+ });
3815
+ function hideModal() {
3816
+ if (!modal.el)
3817
+ return;
3818
+ modal.hide();
3819
+ }
3820
+ const showActionSheet = (options = { itemList: [] }, methodName = 'showActionSheet') => __awaiter(void 0, void 0, void 0, function* () {
4430
3821
  init(document);
4431
3822
  options = Object.assign({
4432
- title: '',
4433
- icon: 'success',
4434
- image: '',
4435
- duration: 1500,
4436
- mask: false
3823
+ itemColor: '#000000',
3824
+ itemList: []
4437
3825
  }, options);
4438
3826
  const { success, fail, complete } = options;
4439
- const handle = new MethodHandler({ name: 'showToast', success, fail, complete });
4440
- if (typeof options.title !== 'string') {
3827
+ const handle = new MethodHandler({ name: methodName, success, fail, complete });
3828
+ // list item String
3829
+ if (!Array.isArray(options.itemList)) {
4441
3830
  return handle.fail({
4442
3831
  errMsg: getParameterError({
4443
- para: 'title',
4444
- correct: 'String',
4445
- wrong: options.title
3832
+ para: 'itemList',
3833
+ correct: 'Array',
3834
+ wrong: options.itemList
4446
3835
  })
4447
3836
  });
4448
3837
  }
4449
- if (typeof options.duration !== 'number') {
3838
+ if (options.itemList.length < 1) {
3839
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' });
3840
+ }
3841
+ if (options.itemList.length > 6) {
3842
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' });
3843
+ }
3844
+ for (let i = 0; i < options.itemList.length; i++) {
3845
+ if (typeof options.itemList[i] !== 'string') {
3846
+ return handle.fail({
3847
+ errMsg: getParameterError({
3848
+ para: `itemList[${i}]`,
3849
+ correct: 'String',
3850
+ wrong: options.itemList[i]
3851
+ })
3852
+ });
3853
+ }
3854
+ }
3855
+ if (typeof options.itemColor !== 'string') {
4450
3856
  return handle.fail({
4451
3857
  errMsg: getParameterError({
4452
- para: 'duration',
4453
- correct: 'Number',
4454
- wrong: options.duration
3858
+ para: 'itemColor',
3859
+ correct: 'String',
3860
+ wrong: options.itemColor
4455
3861
  })
4456
3862
  });
4457
3863
  }
4458
- if (options.image && typeof options.image !== 'string')
4459
- options.image = '';
4460
- options.mask = !!options.mask;
4461
- let errMsg = '';
4462
- if (!toast.el) {
4463
- errMsg = toast.create(options, 'toast');
3864
+ let result = '';
3865
+ if (!actionSheet.el) {
3866
+ result = yield actionSheet.create(options);
4464
3867
  }
4465
3868
  else {
4466
- errMsg = toast.show(options, 'toast');
3869
+ result = yield actionSheet.show(options);
4467
3870
  }
4468
- return handle.success({ errMsg });
4469
- };
4470
- const hideToast = ({ noConflict = false, success, fail, complete } = {}) => {
4471
- const handle = new MethodHandler({ name: 'hideToast', success, fail, complete });
4472
- if (!toast.el)
4473
- return handle.success();
4474
- toast.hide(0, noConflict ? 'toast' : '');
3871
+ if (typeof result === 'string') {
3872
+ return handle.fail(({ errMsg: result }));
3873
+ }
3874
+ else {
3875
+ return handle.success(({ tapIndex: result }));
3876
+ }
3877
+ });
3878
+ Taro.eventCenter.on('__afterTaroRouterChange', () => {
3879
+ var _a, _b;
3880
+ if (toast.currentPath && toast.currentPath !== ((_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path)) {
3881
+ hideToast();
3882
+ hideLoading();
3883
+ }
3884
+ if (modal.currentPath && modal.currentPath !== ((_b = runtime.Current.page) === null || _b === void 0 ? void 0 : _b.path)) {
3885
+ hideModal();
3886
+ }
3887
+ });
3888
+ const enableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('enableAlertBeforeUnload');
3889
+ const disableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('disableAlertBeforeUnload');
3890
+
3891
+ // 菜单
3892
+ const getMenuButtonBoundingClientRect = /* @__PURE__ */ temporarilyNotSupport('getMenuButtonBoundingClientRect');
3893
+
3894
+ // 导航栏
3895
+ const showNavigationBarLoading = /* @__PURE__ */ temporarilyNotSupport('showNavigationBarLoading');
3896
+ function setNavigationBarTitle(options) {
3897
+ // options must be an Object
3898
+ const isObject = shouldBeObject(options);
3899
+ if (!isObject.flag) {
3900
+ const res = { errMsg: `setNavigationBarTitle:fail ${isObject.msg}` };
3901
+ console.error(res.errMsg);
3902
+ return Promise.reject(res);
3903
+ }
3904
+ const { title, success, fail, complete } = options;
3905
+ const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete });
3906
+ if (!title || typeof title !== 'string') {
3907
+ return handle.fail({
3908
+ errMsg: getParameterError({
3909
+ para: 'title',
3910
+ correct: 'String',
3911
+ wrong: title
3912
+ })
3913
+ });
3914
+ }
3915
+ navigate.setTitle(title);
3916
+ return handle.success();
3917
+ }
3918
+ /**
3919
+ * 设置页面导航条颜色
3920
+ */
3921
+ const setNavigationBarColor = (options) => {
3922
+ const { backgroundColor, success, fail, complete } = options;
3923
+ const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
3924
+ const meta = document.createElement('meta');
3925
+ meta.setAttribute('name', 'theme-color');
3926
+ meta.setAttribute('content', backgroundColor);
3927
+ document.head.appendChild(meta);
4475
3928
  return handle.success();
4476
3929
  };
4477
- const showLoading = (options = { title: '' }) => {
4478
- init(document);
4479
- options = Object.assign({
4480
- title: '',
4481
- mask: false
4482
- }, options);
4483
- const { success, fail, complete } = options;
4484
- const handle = new MethodHandler({ name: 'showLoading', success, fail, complete });
4485
- const config = {
4486
- icon: 'loading',
4487
- image: '',
4488
- duration: -1
4489
- };
4490
- options = Object.assign({}, options, config);
4491
- if (typeof options.title !== 'string') {
3930
+ const hideNavigationBarLoading = /* @__PURE__ */ temporarilyNotSupport('hideNavigationBarLoading');
3931
+ const hideHomeButton = /* @__PURE__ */ temporarilyNotSupport('hideHomeButton');
3932
+
3933
+ /**
3934
+ * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
3935
+ */
3936
+ const startPullDownRefresh = function ({ success, fail, complete } = {}) {
3937
+ const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete });
3938
+ return new Promise((resolve, reject) => {
3939
+ Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
3940
+ successHandler: (res = {}) => handle.success(res, { resolve, reject }),
3941
+ errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
3942
+ });
3943
+ });
3944
+ };
3945
+ /**
3946
+ * 停止当前页面下拉刷新。
3947
+ */
3948
+ const stopPullDownRefresh = function ({ success, fail, complete } = {}) {
3949
+ const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete });
3950
+ return new Promise((resolve, reject) => {
3951
+ Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
3952
+ successHandler: (res = {}) => handle.success(res, { resolve, reject }),
3953
+ errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
3954
+ });
3955
+ });
3956
+ };
3957
+
3958
+ let timer;
3959
+ const FRAME_DURATION = 17;
3960
+ /**
3961
+ * 将页面滚动到目标位置
3962
+ */
3963
+ const pageScrollTo = ({ scrollTop, selector = '', offsetTop = 0, duration = 300, success, fail, complete }) => {
3964
+ let scrollFunc;
3965
+ const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete });
3966
+ return new Promise((resolve, reject) => {
3967
+ var _a, _b;
3968
+ try {
3969
+ if (scrollTop === undefined && !selector) {
3970
+ return handle.fail({
3971
+ errMsg: 'scrollTop" 或 "selector" 需要其之一'
3972
+ }, { resolve, reject });
3973
+ }
3974
+ const id = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) === null || _b === void 0 ? void 0 : _b.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1');
3975
+ const el = (id
3976
+ ? document.querySelector(`.taro_page#${id}`)
3977
+ : document.querySelector('.taro_page') ||
3978
+ document.querySelector('.taro_router'));
3979
+ if (!scrollFunc) {
3980
+ if (!el) {
3981
+ scrollFunc = pos => {
3982
+ if (pos === undefined) {
3983
+ return window.pageYOffset;
3984
+ }
3985
+ else {
3986
+ window.scrollTo(0, pos);
3987
+ }
3988
+ };
3989
+ }
3990
+ else {
3991
+ scrollFunc = pos => {
3992
+ if (pos === undefined) {
3993
+ return el.scrollTop;
3994
+ }
3995
+ else {
3996
+ el.scrollTop = pos;
3997
+ }
3998
+ };
3999
+ }
4000
+ }
4001
+ if (scrollTop && selector) {
4002
+ console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector');
4003
+ }
4004
+ const from = scrollFunc();
4005
+ let to;
4006
+ if (selector) {
4007
+ const el = document.querySelector(selector);
4008
+ to = ((el === null || el === void 0 ? void 0 : el.offsetTop) || 0) + offsetTop;
4009
+ }
4010
+ else {
4011
+ to = typeof scrollTop === 'number' ? scrollTop : 0;
4012
+ }
4013
+ const delta = to - from;
4014
+ const frameCnt = duration / FRAME_DURATION;
4015
+ const easeFunc = getTimingFunc(easeInOut, frameCnt);
4016
+ const scroll = (frame = 0) => {
4017
+ const dest = from + delta * easeFunc(frame);
4018
+ scrollFunc(dest);
4019
+ if (frame < frameCnt) {
4020
+ timer && clearTimeout(timer);
4021
+ timer = setTimeout(() => {
4022
+ scroll(frame + 1);
4023
+ }, FRAME_DURATION);
4024
+ }
4025
+ else {
4026
+ return handle.success({}, { resolve, reject });
4027
+ }
4028
+ };
4029
+ scroll();
4030
+ }
4031
+ catch (e) {
4032
+ return handle.fail({
4033
+ errMsg: e.message
4034
+ }, { resolve, reject });
4035
+ }
4036
+ });
4037
+ };
4038
+
4039
+ // 置顶
4040
+ const setTopBarText = /* @__PURE__ */ temporarilyNotSupport('setTopBarText');
4041
+
4042
+ let tabConf;
4043
+ function initTabBarApis(config = {}) {
4044
+ tabConf = config.tabBar;
4045
+ }
4046
+ /**
4047
+ * 显示 tabBar 某一项的右上角的红点
4048
+ */
4049
+ const showTabBarRedDot = (options) => {
4050
+ // options must be an Object
4051
+ const isObject = shouldBeObject(options);
4052
+ if (!isObject.flag) {
4053
+ const res = { errMsg: `showTabBarRedDot:fail ${isObject.msg}` };
4054
+ console.error(res.errMsg);
4055
+ return Promise.reject(res);
4056
+ }
4057
+ const { index, success, fail, complete } = options;
4058
+ const handle = new MethodHandler({ name: 'showTabBarRedDot', success, fail, complete });
4059
+ if (typeof index !== 'number') {
4492
4060
  return handle.fail({
4493
4061
  errMsg: getParameterError({
4494
- para: 'title',
4495
- correct: 'String',
4496
- wrong: options.title
4062
+ para: 'index',
4063
+ correct: 'Number',
4064
+ wrong: index
4497
4065
  })
4498
4066
  });
4499
4067
  }
4500
- options.mask = !!options.mask;
4501
- let errMsg = '';
4502
- if (!toast.el) {
4503
- errMsg = toast.create(options, 'loading');
4504
- }
4505
- else {
4506
- errMsg = toast.show(options, 'loading');
4507
- }
4508
- return handle.success({ errMsg });
4509
- };
4510
- const hideLoading = ({ noConflict = false, success, fail, complete } = {}) => {
4511
- const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete });
4512
- if (!toast.el)
4513
- return handle.success();
4514
- toast.hide(0, noConflict ? 'loading' : '');
4515
- return handle.success();
4516
- };
4517
- const showModal = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
4518
- init(document);
4519
- options = Object.assign({
4520
- title: '',
4521
- content: '',
4522
- showCancel: true,
4523
- cancelText: '取消',
4524
- cancelColor: '#000000',
4525
- confirmText: '确定',
4526
- confirmColor: '#3CC51F'
4527
- }, options);
4528
- const { success, fail, complete } = options;
4529
- const handle = new MethodHandler({ name: 'showModal', success, fail, complete });
4530
- if (typeof options.title !== 'string') {
4531
- return handle.fail({
4532
- errMsg: getParameterError({
4533
- para: 'title',
4534
- correct: 'String',
4535
- wrong: options.title
4536
- })
4068
+ return new Promise((resolve, reject) => {
4069
+ Taro.eventCenter.trigger('__taroShowTabBarRedDotHandler', {
4070
+ index,
4071
+ successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4072
+ errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4537
4073
  });
4074
+ });
4075
+ };
4076
+ /**
4077
+ * 显示 tabBar
4078
+ */
4079
+ const showTabBar = (options = {}) => {
4080
+ // options must be an Object
4081
+ const isObject = shouldBeObject(options);
4082
+ if (!isObject.flag) {
4083
+ const res = { errMsg: `showTabBar:fail ${isObject.msg}` };
4084
+ console.error(res.errMsg);
4085
+ return Promise.reject(res);
4538
4086
  }
4539
- if (typeof options.content !== 'string') {
4087
+ const { animation, success, fail, complete } = options;
4088
+ const handle = new MethodHandler({ name: 'showTabBar', success, fail, complete });
4089
+ if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
4540
4090
  return handle.fail({
4541
4091
  errMsg: getParameterError({
4542
- para: 'content',
4543
- correct: 'String',
4544
- wrong: options.content
4092
+ para: 'animation',
4093
+ correct: 'Boolean',
4094
+ wrong: animation
4545
4095
  })
4546
4096
  });
4547
4097
  }
4548
- if (typeof options.cancelText !== 'string') {
4549
- return handle.fail({
4550
- errMsg: getParameterError({
4551
- para: 'cancelText',
4552
- correct: 'String',
4553
- wrong: options.cancelText
4554
- })
4098
+ return new Promise((resolve, reject) => {
4099
+ Taro.eventCenter.trigger('__taroShowTabBar', {
4100
+ animation,
4101
+ successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4102
+ errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4555
4103
  });
4104
+ });
4105
+ };
4106
+ /**
4107
+ * 动态设置 tabBar 的整体样式
4108
+ */
4109
+ const setTabBarStyle = (options = {}) => {
4110
+ // options must be an Object
4111
+ const isObject = shouldBeObject(options);
4112
+ if (!isObject.flag) {
4113
+ const res = { errMsg: `setTabBarStyle:fail ${isObject.msg}` };
4114
+ console.error(res.errMsg);
4115
+ return Promise.reject(res);
4556
4116
  }
4557
- if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
4558
- return handle.fail({
4559
- errMsg: 'cancelText length should not larger then 4 Chinese characters'
4117
+ const { color, selectedColor, backgroundColor, borderStyle, success, fail, complete } = options;
4118
+ const handle = new MethodHandler({ name: 'setTabBarStyle', success, fail, complete });
4119
+ let errMsg;
4120
+ if (color && !isValidColor(color)) {
4121
+ errMsg = 'color';
4122
+ }
4123
+ else if (selectedColor && !isValidColor(selectedColor)) {
4124
+ errMsg = 'selectedColor';
4125
+ }
4126
+ else if (backgroundColor && !isValidColor(backgroundColor)) {
4127
+ errMsg = 'backgroundColor';
4128
+ }
4129
+ else if (borderStyle && !/^(black|white)$/.test(borderStyle)) {
4130
+ errMsg = 'borderStyle';
4131
+ }
4132
+ if (errMsg) {
4133
+ return handle.fail({ errMsg: `invalid ${errMsg}` });
4134
+ }
4135
+ if (!tabConf) {
4136
+ return handle.fail();
4137
+ }
4138
+ const obj = {};
4139
+ if (color)
4140
+ obj.color = color;
4141
+ if (selectedColor)
4142
+ obj.selectedColor = selectedColor;
4143
+ if (backgroundColor)
4144
+ obj.backgroundColor = backgroundColor;
4145
+ if (borderStyle)
4146
+ obj.borderStyle = borderStyle;
4147
+ return new Promise((resolve, reject) => {
4148
+ Taro.eventCenter.trigger('__taroSetTabBarStyle', {
4149
+ color,
4150
+ selectedColor,
4151
+ backgroundColor,
4152
+ borderStyle,
4153
+ successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4154
+ errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4560
4155
  });
4156
+ });
4157
+ };
4158
+ /**
4159
+ * 动态设置 tabBar 某一项的内容
4160
+ */
4161
+ const setTabBarItem = (options) => {
4162
+ // options must be an Object
4163
+ const isObject = shouldBeObject(options);
4164
+ if (!isObject.flag) {
4165
+ const res = { errMsg: `setTabBarItem:fail ${isObject.msg}` };
4166
+ console.error(res.errMsg);
4167
+ return Promise.reject(res);
4561
4168
  }
4562
- if (typeof options.confirmText !== 'string') {
4169
+ const { index, text, iconPath, selectedIconPath, success, fail, complete } = options;
4170
+ const handle = new MethodHandler({ name: 'setTabBarItem', success, fail, complete });
4171
+ if (typeof index !== 'number') {
4563
4172
  return handle.fail({
4564
4173
  errMsg: getParameterError({
4565
- para: 'confirmText',
4566
- correct: 'String',
4567
- wrong: options.confirmText
4174
+ para: 'index',
4175
+ correct: 'Number',
4176
+ wrong: index
4568
4177
  })
4569
4178
  });
4570
4179
  }
4571
- if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
4572
- return handle.fail({
4573
- errMsg: 'confirmText length should not larger then 4 Chinese characters'
4180
+ return new Promise((resolve, reject) => {
4181
+ Taro.eventCenter.trigger('__taroSetTabBarItem', {
4182
+ index,
4183
+ text,
4184
+ iconPath,
4185
+ selectedIconPath,
4186
+ successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4187
+ errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4574
4188
  });
4189
+ });
4190
+ };
4191
+ /**
4192
+ * 为 tabBar 某一项的右上角添加文本
4193
+ */
4194
+ const setTabBarBadge = (options) => {
4195
+ // options must be an Object
4196
+ const isObject = shouldBeObject(options);
4197
+ if (!isObject.flag) {
4198
+ const res = { errMsg: `setTabBarBadge:fail ${isObject.msg}` };
4199
+ console.error(res.errMsg);
4200
+ return Promise.reject(res);
4575
4201
  }
4576
- if (typeof options.cancelColor !== 'string') {
4202
+ const { index, text, success, fail, complete } = options;
4203
+ const handle = new MethodHandler({ name: 'setTabBarBadge', success, fail, complete });
4204
+ if (typeof index !== 'number') {
4577
4205
  return handle.fail({
4578
4206
  errMsg: getParameterError({
4579
- para: 'cancelColor',
4580
- correct: 'String',
4581
- wrong: options.cancelColor
4207
+ para: 'index',
4208
+ correct: 'Number',
4209
+ wrong: index
4582
4210
  })
4583
4211
  });
4584
4212
  }
4585
- if (typeof options.confirmColor !== 'string') {
4213
+ if (typeof text !== 'string') {
4586
4214
  return handle.fail({
4587
4215
  errMsg: getParameterError({
4588
- para: 'confirmColor',
4216
+ para: 'text',
4589
4217
  correct: 'String',
4590
- wrong: options.confirmColor
4218
+ wrong: text
4591
4219
  })
4592
4220
  });
4593
4221
  }
4594
- options.showCancel = !!options.showCancel;
4595
- let result = '';
4596
- if (!modal.el) {
4597
- result = yield modal.create(options);
4222
+ return new Promise((resolve, reject) => {
4223
+ Taro.eventCenter.trigger('__taroSetTabBarBadge', {
4224
+ index,
4225
+ text,
4226
+ successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4227
+ errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4228
+ });
4229
+ });
4230
+ };
4231
+ /**
4232
+ * 移除 tabBar 某一项右上角的文本
4233
+ */
4234
+ const removeTabBarBadge = (options) => {
4235
+ // options must be an Object
4236
+ const isObject = shouldBeObject(options);
4237
+ if (!isObject.flag) {
4238
+ const res = { errMsg: `removeTabBarBadge:fail ${isObject.msg}` };
4239
+ console.error(res.errMsg);
4240
+ return Promise.reject(res);
4598
4241
  }
4599
- else {
4600
- result = yield modal.show(options);
4242
+ const { index, success, fail, complete } = options;
4243
+ const handle = new MethodHandler({ name: 'removeTabBarBadge', success, fail, complete });
4244
+ if (typeof index !== 'number') {
4245
+ return handle.fail({
4246
+ errMsg: getParameterError({
4247
+ para: 'index',
4248
+ correct: 'Number',
4249
+ wrong: index
4250
+ })
4251
+ });
4601
4252
  }
4602
- const res = { cancel: !1, confirm: !1 };
4603
- res[result] = !0;
4604
- return handle.success(res);
4605
- });
4606
- function hideModal() {
4607
- if (!modal.el)
4608
- return;
4609
- modal.hide();
4610
- }
4611
- const showActionSheet = (options = { itemList: [] }) => __awaiter(void 0, void 0, void 0, function* () {
4612
- init(document);
4613
- options = Object.assign({
4614
- itemColor: '#000000',
4615
- itemList: []
4616
- }, options);
4617
- const { success, fail, complete } = options;
4618
- const handle = new MethodHandler({ name: 'showActionSheet', success, fail, complete });
4619
- // list item String
4620
- if (!Array.isArray(options.itemList)) {
4253
+ return new Promise((resolve, reject) => {
4254
+ Taro.eventCenter.trigger('__taroRemoveTabBarBadge', {
4255
+ index,
4256
+ successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4257
+ errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4258
+ });
4259
+ });
4260
+ };
4261
+ /**
4262
+ * 隐藏 tabBar 某一项的右上角的红点
4263
+ */
4264
+ const hideTabBarRedDot = (options) => {
4265
+ // options must be an Object
4266
+ const isObject = shouldBeObject(options);
4267
+ if (!isObject.flag) {
4268
+ const res = { errMsg: `hideTabBarRedDot:fail ${isObject.msg}` };
4269
+ console.error(res.errMsg);
4270
+ return Promise.reject(res);
4271
+ }
4272
+ const { index, success, fail, complete } = options;
4273
+ const handle = new MethodHandler({ name: 'hideTabBarRedDot', success, fail, complete });
4274
+ if (typeof index !== 'number') {
4621
4275
  return handle.fail({
4622
4276
  errMsg: getParameterError({
4623
- para: 'itemList',
4624
- correct: 'Array',
4625
- wrong: options.itemList
4277
+ para: 'index',
4278
+ correct: 'Number',
4279
+ wrong: index
4626
4280
  })
4627
4281
  });
4628
4282
  }
4629
- if (options.itemList.length < 1) {
4630
- return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' });
4631
- }
4632
- if (options.itemList.length > 6) {
4633
- return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' });
4634
- }
4635
- for (let i = 0; i < options.itemList.length; i++) {
4636
- if (typeof options.itemList[i] !== 'string') {
4637
- return handle.fail({
4638
- errMsg: getParameterError({
4639
- para: `itemList[${i}]`,
4640
- correct: 'String',
4641
- wrong: options.itemList[i]
4642
- })
4643
- });
4644
- }
4283
+ return new Promise((resolve, reject) => {
4284
+ Taro.eventCenter.trigger('__taroHideTabBarRedDotHandler', {
4285
+ index,
4286
+ successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4287
+ errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4288
+ });
4289
+ });
4290
+ };
4291
+ /**
4292
+ * 隐藏 tabBar
4293
+ */
4294
+ const hideTabBar = (options = {}) => {
4295
+ // options must be an Object
4296
+ const isObject = shouldBeObject(options);
4297
+ if (!isObject.flag) {
4298
+ const res = { errMsg: `hideTabBar:fail ${isObject.msg}` };
4299
+ console.error(res.errMsg);
4300
+ return Promise.reject(res);
4645
4301
  }
4646
- if (typeof options.itemColor !== 'string') {
4302
+ const { animation, success, fail, complete } = options;
4303
+ const handle = new MethodHandler({ name: 'hideTabBar', success, fail, complete });
4304
+ if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
4647
4305
  return handle.fail({
4648
4306
  errMsg: getParameterError({
4649
- para: 'itemColor',
4650
- correct: 'String',
4651
- wrong: options.itemColor
4307
+ para: 'animation',
4308
+ correct: 'Boolean',
4309
+ wrong: animation
4652
4310
  })
4653
4311
  });
4654
4312
  }
4655
- let result = '';
4656
- if (!actionSheet.el) {
4657
- result = yield actionSheet.create(options);
4658
- }
4659
- else {
4660
- result = yield actionSheet.show(options);
4661
- }
4662
- if (typeof result === 'string') {
4663
- return handle.fail(({ errMsg: result }));
4313
+ return new Promise((resolve, reject) => {
4314
+ Taro.eventCenter.trigger('__taroHideTabBar', {
4315
+ animation,
4316
+ successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4317
+ errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4318
+ });
4319
+ });
4320
+ };
4321
+
4322
+ const callbackManager = new CallbackManager();
4323
+ const resizeListener = () => {
4324
+ callbackManager.trigger({
4325
+ windowWidth: window.screen.width,
4326
+ windowHeight: window.screen.height
4327
+ });
4328
+ };
4329
+ /**
4330
+ * 设置窗口大小,该接口仅适用于 PC 平台,使用细则请参见指南
4331
+ */
4332
+ const setWindowSize = /* @__PURE__ */ temporarilyNotSupport('setWindowSize');
4333
+ /**
4334
+ * 监听窗口尺寸变化事件
4335
+ */
4336
+ const onWindowResize = callback => {
4337
+ callbackManager.add(callback);
4338
+ if (callbackManager.count() === 1) {
4339
+ window.addEventListener('resize', resizeListener);
4664
4340
  }
4665
- else {
4666
- return handle.success(({ tapIndex: result }));
4341
+ };
4342
+ /**
4343
+ * 取消监听窗口尺寸变化事件
4344
+ */
4345
+ const offWindowResize = callback => {
4346
+ callbackManager.remove(callback);
4347
+ if (callbackManager.count() === 0) {
4348
+ window.removeEventListener('resize', resizeListener);
4667
4349
  }
4668
- });
4669
- Taro.eventCenter.on('__afterTaroRouterChange', () => {
4670
- var _a, _b;
4671
- if (toast.currentPath && toast.currentPath !== ((_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path)) {
4672
- hideToast();
4673
- hideLoading();
4350
+ };
4351
+ const checkIsPictureInPictureActive = /* @__PURE__ */ temporarilyNotSupport('checkIsPictureInPictureActive');
4352
+
4353
+ /**
4354
+ * 拍摄或从手机相册中选择图片或视频。
4355
+ */
4356
+ const chooseMedia = function (options, methodName = 'chooseMedia') {
4357
+ var _a;
4358
+ return __awaiter(this, void 0, void 0, function* () {
4359
+ // options must be an Object
4360
+ const isObject = shouldBeObject(options);
4361
+ if (!isObject.flag) {
4362
+ const res = { errMsg: `${methodName}:fail ${isObject.msg}` };
4363
+ console.error(res.errMsg);
4364
+ return Promise.reject(res);
4365
+ }
4366
+ const { count = 9, mediaId = 'taroChooseMedia', mediaType = ['image', 'video'], sourceType = ['album', 'camera'],
4367
+ // sizeType = ['original', 'compressed'], // TODO 考虑通过 ffmpeg 支持压缩
4368
+ // maxDuration = 10, // TODO 考虑通过 ffmpeg 剪裁视频
4369
+ camera = 'back', success, fail, complete, } = options;
4370
+ const handle = new MethodHandler({ name: methodName, success, fail, complete });
4371
+ const withImage = mediaType.length < 1 || mediaType.indexOf('image') > -1;
4372
+ const withVideo = mediaType.length < 1 || mediaType.indexOf('video') > -1;
4373
+ const res = {
4374
+ tempFiles: [],
4375
+ type: withImage && withVideo ? 'mix' : withImage ? 'image' : 'video',
4376
+ };
4377
+ if (count && typeof count !== 'number') {
4378
+ res.errMsg = getParameterError({
4379
+ para: 'count',
4380
+ correct: 'Number',
4381
+ wrong: count
4382
+ });
4383
+ return handle.fail(res);
4384
+ }
4385
+ let el = document.getElementById(mediaId);
4386
+ if (!el) {
4387
+ el = document.createElement('input');
4388
+ el.setAttribute('type', 'file');
4389
+ el.setAttribute('id', mediaId);
4390
+ el.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;');
4391
+ }
4392
+ if (count > 1) {
4393
+ el.setAttribute('multiple', 'multiple');
4394
+ }
4395
+ else {
4396
+ el.removeAttribute('multiple');
4397
+ }
4398
+ // Note: Input 仅在移动端支持 capture 属性,可以使用 getUserMedia 替代(暂不考虑)
4399
+ const md = navigate.getMobileDetect();
4400
+ if (md.mobile()) {
4401
+ if (sourceType.length > 1 || sourceType.length < 1) {
4402
+ try {
4403
+ const { tapIndex } = yield showActionSheet({
4404
+ itemList: ['拍摄', '从相册选择'],
4405
+ }, methodName);
4406
+ sourceType.splice(0, 1, tapIndex === 0 ? 'camera' : 'album');
4407
+ }
4408
+ catch (e) {
4409
+ return handle.fail({
4410
+ errMsg: (_a = e.errMsg) === null || _a === void 0 ? void 0 : _a.replace('^.*:fail ', '')
4411
+ });
4412
+ }
4413
+ }
4414
+ }
4415
+ if (sourceType.includes('camera')) {
4416
+ el.setAttribute('capture', camera === 'front' ? 'user' : 'environment');
4417
+ }
4418
+ else {
4419
+ el.removeAttribute('capture');
4420
+ }
4421
+ if (res.type === 'image') {
4422
+ el.setAttribute('accept', 'image/*');
4423
+ }
4424
+ else if (res.type === 'video') {
4425
+ el.setAttribute('accept', 'video/*');
4426
+ }
4427
+ else {
4428
+ el.setAttribute('accept', 'image/*, video/*');
4429
+ }
4430
+ return new Promise((resolve, reject) => {
4431
+ if (!el)
4432
+ return;
4433
+ document.body.appendChild(el);
4434
+ el.onchange = function (e) {
4435
+ return __awaiter(this, void 0, void 0, function* () {
4436
+ const target = e.target;
4437
+ if (target) {
4438
+ const files = target.files || [];
4439
+ const arr = [...files];
4440
+ yield Promise.all(arr.map((item) => __awaiter(this, void 0, void 0, function* () {
4441
+ var _a;
4442
+ try {
4443
+ (_a = res.tempFiles) === null || _a === void 0 ? void 0 : _a.push(yield loadMedia(item));
4444
+ }
4445
+ catch (error) {
4446
+ console.error(error);
4447
+ }
4448
+ })));
4449
+ }
4450
+ handle.success(res, { resolve, reject });
4451
+ target.value = '';
4452
+ });
4453
+ };
4454
+ el.onabort = () => handle.fail({ errMsg: 'abort' }, { resolve, reject });
4455
+ el.oncancel = () => handle.fail({ errMsg: 'cancel' }, { resolve, reject });
4456
+ el.onerror = e => handle.fail({ errMsg: e.toString() }, { resolve, reject });
4457
+ el.click();
4458
+ }).finally(() => {
4459
+ if (!el)
4460
+ return;
4461
+ document.body.removeChild(el);
4462
+ });
4463
+ function loadMedia(file) {
4464
+ const dataUrl = URL.createObjectURL(file);
4465
+ const res = {
4466
+ tempFilePath: dataUrl,
4467
+ size: file.size,
4468
+ duration: 0,
4469
+ height: 0,
4470
+ width: 0,
4471
+ thumbTempFilePath: '',
4472
+ fileType: file.type,
4473
+ originalFileObj: file
4474
+ };
4475
+ if (/^video\//.test(res.fileType)) {
4476
+ // Video
4477
+ const video = document.createElement('video');
4478
+ const reader = new FileReader();
4479
+ video.crossOrigin = 'Anonymous';
4480
+ video.preload = 'metadata';
4481
+ video.src = res.tempFilePath;
4482
+ return new Promise((resolve, reject) => {
4483
+ // 对齐旧版本实现
4484
+ reader.onload = (event) => {
4485
+ var _a;
4486
+ res.tempFilePath = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
4487
+ };
4488
+ reader.onerror = e => reject(e);
4489
+ reader.readAsDataURL(res.originalFileObj);
4490
+ video.onloadedmetadata = () => {
4491
+ res.duration = video.duration;
4492
+ res.height = video.videoHeight;
4493
+ res.width = video.videoWidth;
4494
+ };
4495
+ video.oncanplay = () => {
4496
+ res.thumbTempFilePath = getThumbTempFilePath(video, res.height, res.width, 0.8);
4497
+ resolve(res);
4498
+ };
4499
+ video.onerror = e => reject(e);
4500
+ });
4501
+ }
4502
+ else {
4503
+ // Image
4504
+ const img = new Image();
4505
+ /** 允许图片和 canvas 跨源使用
4506
+ * https://developer.mozilla.org/zh-CN/docs/Web/HTML/CORS_enabled_image
4507
+ */
4508
+ img.crossOrigin = 'Anonymous';
4509
+ img.src = res.tempFilePath;
4510
+ return new Promise((resolve, reject) => {
4511
+ if (img.complete) {
4512
+ res.height = img.height;
4513
+ res.width = img.width;
4514
+ res.thumbTempFilePath = getThumbTempFilePath(img, res.height, res.width, 0.8);
4515
+ resolve(res);
4516
+ }
4517
+ else {
4518
+ img.onload = () => {
4519
+ res.height = img.height;
4520
+ res.width = img.width;
4521
+ res.thumbTempFilePath = getThumbTempFilePath(img, res.height, res.width, 0.8);
4522
+ resolve(res);
4523
+ };
4524
+ img.onerror = e => reject(e);
4525
+ }
4526
+ });
4527
+ }
4528
+ }
4529
+ function getThumbTempFilePath(el, height = 0, width = height, quality = 0.8) {
4530
+ const max = 256;
4531
+ const canvas = document.createElement('canvas');
4532
+ if (height > max || width > max) {
4533
+ const radio = height / width;
4534
+ if (radio > 1) {
4535
+ height = max;
4536
+ width = height / radio;
4537
+ }
4538
+ else {
4539
+ width = max;
4540
+ height = width * radio;
4541
+ }
4542
+ }
4543
+ canvas.height = height;
4544
+ canvas.width = width;
4545
+ const ctx = canvas.getContext('2d');
4546
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(el, 0, 0, canvas.width, canvas.height);
4547
+ return canvas.toDataURL('image/jpeg', quality);
4548
+ }
4549
+ });
4550
+ };
4551
+
4552
+ /**
4553
+ * 从本地相册选择图片或使用相机拍照。
4554
+ * @deprecated 请使用 chooseMedia 接口
4555
+ */
4556
+ const chooseImage = function (options) {
4557
+ // options must be an Object
4558
+ const isObject = shouldBeObject(options);
4559
+ if (!isObject.flag) {
4560
+ const res = { errMsg: `chooseImage:fail ${isObject.msg}` };
4561
+ console.error(res.errMsg);
4562
+ return Promise.reject(res);
4674
4563
  }
4675
- if (modal.currentPath && modal.currentPath !== ((_b = runtime.Current.page) === null || _b === void 0 ? void 0 : _b.path)) {
4676
- hideModal();
4564
+ let camera = 'back';
4565
+ const { sourceType = ['album', 'camera'], success, complete, fail } = options, args = __rest(options, ["sourceType", "success", "complete", "fail"]);
4566
+ if (sourceType.includes('camera') && sourceType.indexOf('user') > -1) {
4567
+ camera = 'front';
4568
+ }
4569
+ function parseRes(res) {
4570
+ const { tempFiles = [], errMsg } = res;
4571
+ return {
4572
+ tempFilePaths: tempFiles.map(item => item.tempFilePath),
4573
+ tempFiles: tempFiles.map(item => ({
4574
+ path: item.tempFilePath,
4575
+ size: item.size,
4576
+ type: item.fileType,
4577
+ originalFileObj: item.originalFileObj,
4578
+ })),
4579
+ errMsg,
4580
+ };
4677
4581
  }
4678
- });
4679
- const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload');
4680
- const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload');
4582
+ return chooseMedia(Object.assign(Object.assign({ mediaId: 'taroChooseImage' }, args), { sourceType: sourceType, mediaType: ['image'], camera, success: (res) => {
4583
+ const param = parseRes(res);
4584
+ success === null || success === void 0 ? void 0 : success(param);
4585
+ complete === null || complete === void 0 ? void 0 : complete(param);
4586
+ }, fail: (err) => {
4587
+ fail === null || fail === void 0 ? void 0 : fail(err);
4588
+ complete === null || complete === void 0 ? void 0 : complete(err);
4589
+ } }), 'chooseImage').then(parseRes);
4590
+ };
4681
4591
 
4682
- // 菜单
4683
- const getMenuButtonBoundingClientRect = temporarilyNotSupport('getMenuButtonBoundingClientRect');
4592
+ const previewMedia = /* @__PURE__ */ temporarilyNotSupport('previewMedia');
4593
+ const compressImage = /* @__PURE__ */ temporarilyNotSupport('compressImage');
4594
+ const chooseMessageFile = /* @__PURE__ */ permanentlyNotSupport('chooseMessageFile');
4595
+ const editImage = /* @__PURE__ */ temporarilyNotSupport('editImage');
4596
+ const cropImage = /* @__PURE__ */ temporarilyNotSupport('cropImage');
4684
4597
 
4685
- // 导航栏
4686
- const showNavigationBarLoading = temporarilyNotSupport('showNavigationBarLoading');
4687
- function setNavigationBarTitle(options) {
4598
+ // 实时音视频
4599
+ const createLivePusherContext = /* @__PURE__ */ temporarilyNotSupport('createLivePusherContext');
4600
+ const createLivePlayerContext = /* @__PURE__ */ temporarilyNotSupport('createLivePlayerContext');
4601
+
4602
+ // 地图
4603
+ const createMapContext = /* @__PURE__ */ temporarilyNotSupport('createMapContext');
4604
+
4605
+ // 画面录制器
4606
+ const createMediaRecorder = /* @__PURE__ */ temporarilyNotSupport('createMediaRecorder');
4607
+
4608
+ // 录音
4609
+ const stopRecord = /* @__PURE__ */ temporarilyNotSupport('stopRecord');
4610
+ const startRecord = /* @__PURE__ */ temporarilyNotSupport('startRecord');
4611
+ const getRecorderManager = /* @__PURE__ */ temporarilyNotSupport('getRecorderManager');
4612
+
4613
+ const saveVideoToPhotosAlbum = (options) => {
4614
+ const methodName = 'saveVideoToPhotosAlbum';
4688
4615
  // options must be an Object
4689
4616
  const isObject = shouldBeObject(options);
4690
4617
  if (!isObject.flag) {
4691
- const res = { errMsg: `setNavigationBarTitle:fail ${isObject.msg}` };
4618
+ const res = { errMsg: `${methodName}:fail ${isObject.msg}` };
4692
4619
  console.error(res.errMsg);
4693
4620
  return Promise.reject(res);
4694
4621
  }
4695
- const { title, success, fail, complete } = options;
4696
- const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete });
4697
- if (!title || typeof title !== 'string') {
4622
+ const { filePath, success, fail, complete, } = options;
4623
+ const handle = new MethodHandler({ name: methodName, success, fail, complete });
4624
+ if (typeof filePath !== 'string') {
4698
4625
  return handle.fail({
4699
4626
  errMsg: getParameterError({
4700
- para: 'title',
4627
+ para: 'filePath',
4701
4628
  correct: 'String',
4702
- wrong: title
4629
+ wrong: filePath
4703
4630
  })
4704
4631
  });
4705
4632
  }
4706
- navigate.setTitle(title);
4633
+ createDownload(filePath);
4707
4634
  return handle.success();
4708
- }
4635
+ };
4636
+
4637
+ const getVideoInfo = function (options) {
4638
+ return __awaiter(this, void 0, void 0, function* () {
4639
+ // options must be an Object
4640
+ const isObject = shouldBeObject(options);
4641
+ if (!isObject.flag) {
4642
+ const res = { errMsg: `getVideoInfo:fail ${isObject.msg}` };
4643
+ console.error(res.errMsg);
4644
+ return Promise.reject(res);
4645
+ }
4646
+ const res = {
4647
+ orientation: 'up',
4648
+ type: '',
4649
+ duration: 0,
4650
+ size: 0,
4651
+ height: 0,
4652
+ width: 0,
4653
+ fps: 30,
4654
+ bitrate: 0,
4655
+ };
4656
+ const { src, success, fail, complete, } = options;
4657
+ const handle = new MethodHandler({ name: 'getVideoInfo', success, fail, complete });
4658
+ if (typeof src !== 'string') {
4659
+ res.errMsg = getParameterError({
4660
+ para: 'src',
4661
+ correct: 'String',
4662
+ wrong: src
4663
+ });
4664
+ return handle.fail(res);
4665
+ }
4666
+ const video = document.createElement('video');
4667
+ video.crossOrigin = 'Anonymous';
4668
+ video.preload = 'metadata';
4669
+ video.src = src;
4670
+ return new Promise((resolve, reject) => {
4671
+ video.onloadedmetadata = () => {
4672
+ res.duration = video.duration;
4673
+ res.height = video.videoHeight;
4674
+ res.width = video.videoWidth;
4675
+ fetch(src)
4676
+ .then((e) => __awaiter(this, void 0, void 0, function* () {
4677
+ const blob = yield e.blob();
4678
+ res.type = blob.type;
4679
+ res.size = blob.size;
4680
+ res.bitrate = blob.size / video.duration;
4681
+ handle.success(res, { resolve, reject });
4682
+ }))
4683
+ .catch(e => {
4684
+ handle.fail({
4685
+ errMsg: e.toString()
4686
+ }, { resolve, reject });
4687
+ });
4688
+ };
4689
+ });
4690
+ });
4691
+ };
4692
+
4693
+ /**
4694
+ * 拍摄视频或从手机相册中选视频。
4695
+ * @deprecated 请使用 chooseMedia 接口
4696
+ */
4697
+ const chooseVideo = (options) => {
4698
+ // options must be an Object
4699
+ const isObject = shouldBeObject(options);
4700
+ if (!isObject.flag) {
4701
+ const res = { errMsg: `chooseVideo:fail ${isObject.msg}` };
4702
+ console.error(res.errMsg);
4703
+ return Promise.reject(res);
4704
+ }
4705
+ const { sourceType = ['album', 'camera'],
4706
+ // TODO 考虑通过 ffmpeg 支持压缩
4707
+ // compressed = true,
4708
+ maxDuration = 60, camera = 'back', success, fail, complete, } = options;
4709
+ function parseRes(res) {
4710
+ const { tempFiles = [], errMsg } = res;
4711
+ const [video] = tempFiles;
4712
+ return Object.assign(Object.assign({}, video), { errMsg });
4713
+ }
4714
+ return chooseMedia({
4715
+ mediaId: 'taroChooseVideo',
4716
+ sourceType,
4717
+ mediaType: ['video'],
4718
+ maxDuration,
4719
+ camera,
4720
+ success: (res) => {
4721
+ const param = parseRes(res);
4722
+ success === null || success === void 0 ? void 0 : success(param);
4723
+ complete === null || complete === void 0 ? void 0 : complete(param);
4724
+ },
4725
+ fail: (err) => {
4726
+ fail === null || fail === void 0 ? void 0 : fail(err);
4727
+ complete === null || complete === void 0 ? void 0 : complete(err);
4728
+ },
4729
+ }, 'chooseVideo').then(parseRes);
4730
+ };
4731
+
4732
+ const openVideoEditor = /* @__PURE__ */ temporarilyNotSupport('openVideoEditor');
4709
4733
  /**
4710
- * 设置页面导航条颜色
4734
+ * 创建 video 上下文 VideoContext 对象。
4711
4735
  */
4712
- const setNavigationBarColor = (options) => {
4713
- const { backgroundColor, success, fail, complete } = options;
4714
- const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
4715
- const meta = document.createElement('meta');
4716
- meta.setAttribute('name', 'theme-color');
4717
- meta.setAttribute('content', backgroundColor);
4718
- document.head.appendChild(meta);
4719
- return handle.success();
4736
+ const createVideoContext = (id, inst) => {
4737
+ const el = findDOM(inst);
4738
+ // TODO HTMLVideoElement to VideoContext
4739
+ return el === null || el === void 0 ? void 0 : el.querySelector(`taro-video-core[id=${id}]`);
4720
4740
  };
4721
- const hideNavigationBarLoading = temporarilyNotSupport('hideNavigationBarLoading');
4722
- const hideHomeButton = temporarilyNotSupport('hideHomeButton');
4741
+ const compressVideo = /* @__PURE__ */ temporarilyNotSupport('compressVideo');
4742
+
4743
+ // 视频解码器
4744
+ const createVideoDecoder = /* @__PURE__ */ temporarilyNotSupport('createVideoDecoder');
4745
+
4746
+ // 音视频合成
4747
+ const createMediaContainer = /* @__PURE__ */ temporarilyNotSupport('createMediaContainer');
4748
+
4749
+ // 实时语音
4750
+ const updateVoIPChatMuteConfig = /* @__PURE__ */ temporarilyNotSupport('updateVoIPChatMuteConfig');
4751
+ const subscribeVoIPVideoMembers = /* @__PURE__ */ temporarilyNotSupport('subscribeVoIPVideoMembers');
4752
+ const setEnable1v1Chat = /* @__PURE__ */ temporarilyNotSupport('setEnable1v1Chat');
4753
+ const onVoIPVideoMembersChanged = /* @__PURE__ */ temporarilyNotSupport('onVoIPVideoMembersChanged');
4754
+ const onVoIPChatStateChanged = /* @__PURE__ */ temporarilyNotSupport('onVoIPChatStateChanged');
4755
+ const onVoIPChatSpeakersChanged = /* @__PURE__ */ temporarilyNotSupport('onVoIPChatSpeakersChanged');
4756
+ const onVoIPChatMembersChanged = /* @__PURE__ */ temporarilyNotSupport('onVoIPChatMembersChanged');
4757
+ const onVoIPChatInterrupted = /* @__PURE__ */ temporarilyNotSupport('onVoIPChatInterrupted');
4758
+ const offVoIPVideoMembersChanged = /* @__PURE__ */ temporarilyNotSupport('offVoIPVideoMembersChanged');
4759
+ const offVoIPChatStateChanged = /* @__PURE__ */ temporarilyNotSupport('offVoIPChatStateChanged');
4760
+ const offVoIPChatMembersChanged = /* @__PURE__ */ temporarilyNotSupport('offVoIPChatMembersChanged');
4761
+ const offVoIPChatInterrupted = /* @__PURE__ */ temporarilyNotSupport('offVoIPChatInterrupted');
4762
+ const joinVoIPChat = /* @__PURE__ */ temporarilyNotSupport('joinVoIPChat');
4763
+ const exitVoIPChat = /* @__PURE__ */ temporarilyNotSupport('exitVoIPChat');
4764
+
4765
+ // 跳转
4766
+ const openEmbeddedMiniProgram = /* @__PURE__ */ temporarilyNotSupport('openEmbeddedMiniProgram');
4767
+ const navigateToMiniProgram = /* @__PURE__ */ temporarilyNotSupport('navigateToMiniProgram');
4768
+ const navigateBackMiniProgram = /* @__PURE__ */ temporarilyNotSupport('navigateBackMiniProgram');
4769
+ const exitMiniProgram = /* @__PURE__ */ temporarilyNotSupport('exitMiniProgram');
4770
+ const openBusinessView = /* @__PURE__ */ temporarilyNotSupport('openBusinessView');
4723
4771
 
4724
4772
  /**
4725
- * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
4773
+ * HTTP Response Header 事件回调函数的参数
4774
+ * @typedef {Object} HeadersReceivedParam
4775
+ * @property {Object} header 开发者服务器返回的 HTTP Response Header
4726
4776
  */
4727
- const startPullDownRefresh = function ({ success, fail, complete } = {}) {
4728
- const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete });
4729
- return new Promise((resolve, reject) => {
4730
- Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
4731
- successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4732
- errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4733
- });
4734
- });
4777
+ /**
4778
+ * HTTP Response Header 事件的回调函数
4779
+ * @callback HeadersReceivedCallback
4780
+ * @param {HeadersReceivedParam} res 参数
4781
+ */
4782
+ /**
4783
+ * 进度变化回调函数的参数
4784
+ * @typedef {Object} ProgressUpdateParam
4785
+ * @property {number} progress 进度百分比
4786
+ * @property {number} [totalBytesWritten] 已经下载的数据长度,单位 Bytes
4787
+ * @property {number} [totalBytesSent] 已经上传的数据长度,单位 Bytes
4788
+ * @property {number} [totalBytesExpectedToWrite] 预期需要下载的数据总长度,单位 Bytes
4789
+ * @property {number} [totalBytesExpectedToSend] 预期需要上传的数据总长度,单位 Bytes
4790
+ */
4791
+ /**
4792
+ * 进度变化事件的回调函数
4793
+ * @callback ProgressUpdateCallback
4794
+ * @param {ProgressUpdateParam} res 参数
4795
+ */
4796
+ const NETWORK_TIMEOUT = 60000;
4797
+ const XHR_STATS = {
4798
+ UNSENT: 0,
4799
+ OPENED: 1,
4800
+ HEADERS_RECEIVED: 2,
4801
+ LOADING: 3,
4802
+ DONE: 4 // The operation is complete.
4735
4803
  };
4736
4804
  /**
4737
- * 停止当前页面下拉刷新。
4805
+ * 设置xhr的header
4806
+ * @param {XMLHttpRequest} xhr
4807
+ * @param {Object} header
4738
4808
  */
4739
- const stopPullDownRefresh = function ({ success, fail, complete } = {}) {
4740
- const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete });
4741
- return new Promise((resolve, reject) => {
4742
- Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
4743
- successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4744
- errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4745
- });
4746
- });
4809
+ const setHeader = (xhr, header) => {
4810
+ let headerKey;
4811
+ for (headerKey in header) {
4812
+ xhr.setRequestHeader(headerKey, header[headerKey]);
4813
+ }
4747
4814
  };
4748
-
4749
- let timer;
4750
- const FRAME_DURATION = 17;
4751
4815
  /**
4752
- * 将页面滚动到目标位置
4816
+ * 将 blob url 转化为文件
4817
+ * @param {string} url 要转换的 blob url
4818
+ * @returns {Promise<File>}
4753
4819
  */
4754
- const pageScrollTo = ({ scrollTop, selector = '', offsetTop = 0, duration = 300, success, fail, complete }) => {
4755
- let scrollFunc;
4756
- const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete });
4820
+ const convertObjectUrlToBlob = url => {
4757
4821
  return new Promise((resolve, reject) => {
4758
- var _a, _b;
4759
- try {
4760
- if (scrollTop === undefined && !selector) {
4761
- return handle.fail({
4762
- errMsg: 'scrollTop" "selector" 需要其之一'
4763
- }, { resolve, reject });
4764
- }
4765
- const id = (_b = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path) === null || _b === void 0 ? void 0 : _b.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1');
4766
- const el = (id
4767
- ? document.querySelector(`.taro_page#${id}`)
4768
- : document.querySelector('.taro_page') ||
4769
- document.querySelector('.taro_router'));
4770
- if (!scrollFunc) {
4771
- if (!el) {
4772
- scrollFunc = pos => {
4773
- if (pos === undefined) {
4774
- return window.pageYOffset;
4775
- }
4776
- else {
4777
- window.scrollTo(0, pos);
4778
- }
4779
- };
4780
- }
4781
- else {
4782
- scrollFunc = pos => {
4783
- if (pos === undefined) {
4784
- return el.scrollTop;
4785
- }
4786
- else {
4787
- el.scrollTop = pos;
4788
- }
4789
- };
4790
- }
4791
- }
4792
- if (scrollTop && selector) {
4793
- console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector');
4794
- }
4795
- const from = scrollFunc();
4796
- let to;
4797
- if (selector) {
4798
- const el = document.querySelector(selector);
4799
- to = ((el === null || el === void 0 ? void 0 : el.offsetTop) || 0) + offsetTop;
4822
+ const xhr = new XMLHttpRequest();
4823
+ xhr.open('GET', url, true);
4824
+ xhr.responseType = 'blob';
4825
+ xhr.withCredentials = true;
4826
+ xhr.onload = function () {
4827
+ if (this.status === 200) {
4828
+ resolve(this.response);
4800
4829
  }
4801
4830
  else {
4802
- to = typeof scrollTop === 'number' ? scrollTop : 0;
4831
+ /* eslint-disable prefer-promise-reject-errors */
4832
+ reject({ status: this.status });
4803
4833
  }
4804
- const delta = to - from;
4805
- const frameCnt = duration / FRAME_DURATION;
4806
- const easeFunc = getTimingFunc(easeInOut, frameCnt);
4807
- const scroll = (frame = 0) => {
4808
- const dest = from + delta * easeFunc(frame);
4809
- scrollFunc(dest);
4810
- if (frame < frameCnt) {
4811
- timer && clearTimeout(timer);
4812
- timer = setTimeout(() => {
4813
- scroll(frame + 1);
4814
- }, FRAME_DURATION);
4815
- }
4816
- else {
4817
- return handle.success({}, { resolve, reject });
4818
- }
4819
- };
4820
- scroll();
4821
- }
4822
- catch (e) {
4823
- return handle.fail({
4824
- errMsg: e.message
4825
- }, { resolve, reject });
4826
- }
4834
+ };
4835
+ xhr.send();
4827
4836
  });
4828
4837
  };
4829
-
4830
- // 置顶
4831
- const setTopBarText = temporarilyNotSupport('setTopBarText');
4832
-
4833
- let tabConf;
4834
- function initTabBarApis(config = {}) {
4835
- tabConf = config.tabBar;
4836
- }
4838
+
4839
+ const createDownloadTask = ({ url, header, withCredentials = true, timeout, success, error }) => {
4840
+ let timeoutInter;
4841
+ const apiName = 'downloadFile';
4842
+ const xhr = new XMLHttpRequest();
4843
+ const callbackManager = {
4844
+ headersReceived: new CallbackManager(),
4845
+ progressUpdate: new CallbackManager()
4846
+ };
4847
+ xhr.open('GET', url, true);
4848
+ xhr.withCredentials = !!withCredentials;
4849
+ xhr.responseType = 'blob';
4850
+ setHeader(xhr, header);
4851
+ xhr.onprogress = e => {
4852
+ const { loaded, total } = e;
4853
+ callbackManager.progressUpdate.trigger({
4854
+ progress: Math.round(loaded / total * 100),
4855
+ totalBytesWritten: loaded,
4856
+ totalBytesExpectedToWrite: total
4857
+ });
4858
+ };
4859
+ xhr.onreadystatechange = () => {
4860
+ if (xhr.readyState !== XHR_STATS.HEADERS_RECEIVED)
4861
+ return;
4862
+ callbackManager.headersReceived.trigger({
4863
+ header: xhr.getAllResponseHeaders()
4864
+ });
4865
+ };
4866
+ xhr.onload = () => {
4867
+ const response = xhr.response;
4868
+ const status = xhr.status;
4869
+ success({
4870
+ errMsg: `${apiName}:ok`,
4871
+ statusCode: status,
4872
+ tempFilePath: window.URL.createObjectURL(response)
4873
+ });
4874
+ };
4875
+ xhr.onabort = () => {
4876
+ clearTimeout(timeoutInter);
4877
+ error({
4878
+ errMsg: `${apiName}:fail abort`
4879
+ });
4880
+ };
4881
+ xhr.onerror = (e) => {
4882
+ error({
4883
+ errMsg: `${apiName}:fail ${e.message}`
4884
+ });
4885
+ };
4886
+ /**
4887
+ * 中断任务
4888
+ */
4889
+ const abort = () => {
4890
+ xhr.abort();
4891
+ };
4892
+ const send = () => {
4893
+ xhr.send();
4894
+ timeoutInter = setTimeout(() => {
4895
+ xhr.onabort = null;
4896
+ xhr.onload = null;
4897
+ xhr.onprogress = null;
4898
+ xhr.onreadystatechange = null;
4899
+ xhr.onerror = null;
4900
+ abort();
4901
+ error({
4902
+ errMsg: `${apiName}:fail timeout`
4903
+ });
4904
+ }, timeout || NETWORK_TIMEOUT);
4905
+ };
4906
+ send();
4907
+ /**
4908
+ * 监听 HTTP Response Header 事件。会比请求完成事件更早
4909
+ * @param {HeadersReceivedCallback} callback HTTP Response Header 事件的回调函数
4910
+ */
4911
+ const onHeadersReceived = callbackManager.headersReceived.add;
4912
+ /**
4913
+ * 取消监听 HTTP Response Header 事件
4914
+ * @param {HeadersReceivedCallback} callback HTTP Response Header 事件的回调函数
4915
+ */
4916
+ const offHeadersReceived = callbackManager.headersReceived.remove;
4917
+ /**
4918
+ * 监听进度变化事件
4919
+ * @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
4920
+ */
4921
+ const onProgressUpdate = callbackManager.progressUpdate.add;
4922
+ /**
4923
+ * 取消监听进度变化事件
4924
+ * @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
4925
+ */
4926
+ const offProgressUpdate = callbackManager.progressUpdate.remove;
4927
+ return {
4928
+ abort,
4929
+ onHeadersReceived,
4930
+ offHeadersReceived,
4931
+ onProgressUpdate,
4932
+ offProgressUpdate
4933
+ };
4934
+ };
4837
4935
  /**
4838
- * 显示 tabBar 某一项的右上角的红点
4936
+ * 下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径。使用前请注意阅读相关说明。
4937
+ * 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
4839
4938
  */
4840
- const showTabBarRedDot = (options) => {
4841
- // options must be an Object
4842
- const isObject = shouldBeObject(options);
4843
- if (!isObject.flag) {
4844
- const res = { errMsg: `showTabBarRedDot:fail ${isObject.msg}` };
4845
- console.error(res.errMsg);
4846
- return Promise.reject(res);
4847
- }
4848
- const { index, success, fail, complete } = options;
4849
- const handle = new MethodHandler({ name: 'showTabBarRedDot', success, fail, complete });
4850
- if (typeof index !== 'number') {
4851
- return handle.fail({
4852
- errMsg: getParameterError({
4853
- para: 'index',
4854
- correct: 'Number',
4855
- wrong: index
4856
- })
4857
- });
4858
- }
4859
- return new Promise((resolve, reject) => {
4860
- Taro.eventCenter.trigger('__taroShowTabBarRedDotHandler', {
4861
- index,
4862
- successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4863
- errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4939
+ const downloadFile = ({ url, header, withCredentials, timeout, success, fail, complete }) => {
4940
+ let task;
4941
+ const result = new Promise((resolve, reject) => {
4942
+ task = createDownloadTask({
4943
+ url,
4944
+ header,
4945
+ withCredentials,
4946
+ timeout,
4947
+ success: res => {
4948
+ success && success(res);
4949
+ complete && complete(res);
4950
+ resolve(res);
4951
+ },
4952
+ error: res => {
4953
+ fail && fail(res);
4954
+ complete && complete(res);
4955
+ reject(res);
4956
+ }
4864
4957
  });
4865
4958
  });
4959
+ result.headersReceive = task.onHeadersReceived;
4960
+ result.progress = task.onProgressUpdate;
4961
+ return new Proxy(result, {
4962
+ get(target, prop) {
4963
+ const object = prop in task ? task : target;
4964
+ const value = object[prop];
4965
+ return typeof value === 'function' ? value.bind(object) : value;
4966
+ },
4967
+ });
4866
4968
  };
4867
- /**
4868
- * 显示 tabBar
4869
- */
4870
- const showTabBar = (options = {}) => {
4871
- // options must be an Object
4872
- const isObject = shouldBeObject(options);
4873
- if (!isObject.flag) {
4874
- const res = { errMsg: `showTabBar:fail ${isObject.msg}` };
4875
- console.error(res.errMsg);
4876
- return Promise.reject(res);
4969
+
4970
+ // mDNS
4971
+ const stopLocalServiceDiscovery = /* @__PURE__ */ temporarilyNotSupport('stopLocalServiceDiscovery');
4972
+ const startLocalServiceDiscovery = /* @__PURE__ */ temporarilyNotSupport('startLocalServiceDiscovery');
4973
+ const onLocalServiceResolveFail = /* @__PURE__ */ temporarilyNotSupport('onLocalServiceResolveFail');
4974
+ const onLocalServiceLost = /* @__PURE__ */ temporarilyNotSupport('onLocalServiceLost');
4975
+ const onLocalServiceFound = /* @__PURE__ */ temporarilyNotSupport('onLocalServiceFound');
4976
+ const onLocalServiceDiscoveryStop = /* @__PURE__ */ temporarilyNotSupport('onLocalServiceDiscoveryStop');
4977
+ const offLocalServiceResolveFail = /* @__PURE__ */ temporarilyNotSupport('offLocalServiceResolveFail');
4978
+ const offLocalServiceLost = /* @__PURE__ */ temporarilyNotSupport('offLocalServiceLost');
4979
+ const offLocalServiceFound = /* @__PURE__ */ temporarilyNotSupport('offLocalServiceFound');
4980
+ const offLocalServiceDiscoveryStop = /* @__PURE__ */ temporarilyNotSupport('offLocalServiceDiscoveryStop');
4981
+
4982
+ // @ts-ignore
4983
+ const { Link: Link$1 } = Taro;
4984
+ function generateRequestUrlWithParams(url = '', params) {
4985
+ params = typeof params === 'string' ? params : serializeParams(params);
4986
+ if (params) {
4987
+ url += (~url.indexOf('?') ? '&' : '?') + params;
4877
4988
  }
4878
- const { animation, success, fail, complete } = options;
4879
- const handle = new MethodHandler({ name: 'showTabBar', success, fail, complete });
4880
- if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
4881
- return handle.fail({
4882
- errMsg: getParameterError({
4883
- para: 'animation',
4884
- correct: 'Boolean',
4885
- wrong: animation
4886
- })
4989
+ url = url.replace('?&', '?');
4990
+ return url;
4991
+ }
4992
+ function _request(options = {}) {
4993
+ const { success, complete, fail } = options;
4994
+ let url = options.url || '';
4995
+ const params = {};
4996
+ const res = {};
4997
+ if (options.jsonp) {
4998
+ const { jsonp } = options, opts = __rest(options, ["jsonp"]);
4999
+ Object.assign(params, opts);
5000
+ // @ts-ignore
5001
+ params.params = opts.data;
5002
+ params.cache = opts.jsonpCache;
5003
+ if (typeof jsonp === 'string') {
5004
+ // @ts-ignore
5005
+ params.name = jsonp;
5006
+ }
5007
+ return jsonpRetry(url, params)
5008
+ .then(data => {
5009
+ res.statusCode = 200;
5010
+ res.data = data;
5011
+ shared.isFunction(success) && success(res);
5012
+ shared.isFunction(complete) && complete(res);
5013
+ return res;
5014
+ })
5015
+ .catch(err => {
5016
+ shared.isFunction(fail) && fail(err);
5017
+ shared.isFunction(complete) && complete(res);
5018
+ return Promise.reject(err);
4887
5019
  });
4888
5020
  }
4889
- return new Promise((resolve, reject) => {
4890
- Taro.eventCenter.trigger('__taroShowTabBar', {
4891
- animation,
4892
- successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4893
- errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4894
- });
4895
- });
4896
- };
4897
- /**
4898
- * 动态设置 tabBar 的整体样式
4899
- */
4900
- const setTabBarStyle = (options = {}) => {
4901
- // options must be an Object
4902
- const isObject = shouldBeObject(options);
4903
- if (!isObject.flag) {
4904
- const res = { errMsg: `setTabBarStyle:fail ${isObject.msg}` };
4905
- console.error(res.errMsg);
4906
- return Promise.reject(res);
5021
+ params.method = options.method || 'GET';
5022
+ const methodUpper = params.method.toUpperCase();
5023
+ params.cache = options.cache || 'default';
5024
+ if (methodUpper === 'GET' || methodUpper === 'HEAD') {
5025
+ url = generateRequestUrlWithParams(url, options.data);
4907
5026
  }
4908
- const { color, selectedColor, backgroundColor, borderStyle, success, fail, complete } = options;
4909
- const handle = new MethodHandler({ name: 'setTabBarStyle', success, fail, complete });
4910
- let errMsg;
4911
- if (color && !isValidColor(color)) {
4912
- errMsg = 'color';
5027
+ else if (['[object Array]', '[object Object]'].indexOf(Object.prototype.toString.call(options.data)) >= 0) {
5028
+ options.header = options.header || {};
5029
+ const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type');
5030
+ if (!keyOfContentType) {
5031
+ options.header['Content-Type'] = 'application/json';
5032
+ }
5033
+ const contentType = options.header[keyOfContentType || 'Content-Type'];
5034
+ if (contentType.indexOf('application/json') >= 0) {
5035
+ params.body = JSON.stringify(options.data);
5036
+ }
5037
+ else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {
5038
+ params.body = serializeParams(options.data);
5039
+ }
5040
+ else {
5041
+ params.body = options.data;
5042
+ }
4913
5043
  }
4914
- else if (selectedColor && !isValidColor(selectedColor)) {
4915
- errMsg = 'selectedColor';
5044
+ else {
5045
+ params.body = options.data;
4916
5046
  }
4917
- else if (backgroundColor && !isValidColor(backgroundColor)) {
4918
- errMsg = 'backgroundColor';
5047
+ if (options.header) {
5048
+ params.headers = options.header;
4919
5049
  }
4920
- else if (borderStyle && !/^(black|white)$/.test(borderStyle)) {
4921
- errMsg = 'borderStyle';
5050
+ if (options.mode) {
5051
+ params.mode = options.mode;
4922
5052
  }
4923
- if (errMsg) {
4924
- return handle.fail({ errMsg: `invalid ${errMsg}` });
5053
+ let timeoutTimer = null;
5054
+ if (options.signal) {
5055
+ params.signal = options.signal;
4925
5056
  }
4926
- if (!tabConf) {
4927
- return handle.fail();
5057
+ else if (typeof options.timeout === 'number') {
5058
+ const controller = new window.AbortController();
5059
+ params.signal = controller.signal;
5060
+ timeoutTimer = setTimeout(function () {
5061
+ controller.abort();
5062
+ }, options.timeout);
4928
5063
  }
4929
- const obj = {};
4930
- if (color)
4931
- obj.color = color;
4932
- if (selectedColor)
4933
- obj.selectedColor = selectedColor;
4934
- if (backgroundColor)
4935
- obj.backgroundColor = backgroundColor;
4936
- if (borderStyle)
4937
- obj.borderStyle = borderStyle;
4938
- return new Promise((resolve, reject) => {
4939
- Taro.eventCenter.trigger('__taroSetTabBarStyle', {
4940
- color,
4941
- selectedColor,
4942
- backgroundColor,
4943
- borderStyle,
4944
- successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4945
- errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4946
- });
5064
+ params.credentials = options.credentials;
5065
+ return fetch(url, params)
5066
+ .then(response => {
5067
+ if (timeoutTimer) {
5068
+ clearTimeout(timeoutTimer);
5069
+ timeoutTimer = null;
5070
+ }
5071
+ if (!response) {
5072
+ const errorResponse = { ok: false };
5073
+ throw errorResponse;
5074
+ }
5075
+ res.statusCode = response.status;
5076
+ res.header = {};
5077
+ for (const key of response.headers.keys()) {
5078
+ res.header[key] = response.headers.get(key);
5079
+ }
5080
+ if (options.responseType === 'arraybuffer') {
5081
+ return response.arrayBuffer();
5082
+ }
5083
+ if (res.statusCode !== 204) {
5084
+ if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
5085
+ return response.json().catch(() => {
5086
+ return null;
5087
+ });
5088
+ }
5089
+ }
5090
+ if (options.responseType === 'text' || options.dataType === 'text') {
5091
+ return response.text();
5092
+ }
5093
+ return Promise.resolve(null);
5094
+ })
5095
+ .then(data => {
5096
+ res.data = data;
5097
+ shared.isFunction(success) && success(res);
5098
+ shared.isFunction(complete) && complete(res);
5099
+ return res;
5100
+ })
5101
+ .catch(err => {
5102
+ if (timeoutTimer) {
5103
+ clearTimeout(timeoutTimer);
5104
+ timeoutTimer = null;
5105
+ }
5106
+ shared.isFunction(fail) && fail(err);
5107
+ shared.isFunction(complete) && complete(res);
5108
+ err.statusCode = res.statusCode;
5109
+ err.errMsg = err.message;
5110
+ return Promise.reject(err);
4947
5111
  });
4948
- };
4949
- /**
4950
- * 动态设置 tabBar 某一项的内容
4951
- */
4952
- const setTabBarItem = (options) => {
4953
- // options must be an Object
4954
- const isObject = shouldBeObject(options);
4955
- if (!isObject.flag) {
4956
- const res = { errMsg: `setTabBarItem:fail ${isObject.msg}` };
4957
- console.error(res.errMsg);
4958
- return Promise.reject(res);
5112
+ }
5113
+ function taroInterceptor(chain) {
5114
+ return _request(chain.requestParams);
5115
+ }
5116
+ const link = new Link$1(taroInterceptor);
5117
+ const request = ((...args) => {
5118
+ const [url = '', options = {}] = args;
5119
+ if (typeof url === 'string') {
5120
+ options.url = url;
4959
5121
  }
4960
- const { index, text, iconPath, selectedIconPath, success, fail, complete } = options;
4961
- const handle = new MethodHandler({ name: 'setTabBarItem', success, fail, complete });
4962
- if (typeof index !== 'number') {
4963
- return handle.fail({
4964
- errMsg: getParameterError({
4965
- para: 'index',
4966
- correct: 'Number',
4967
- wrong: index
4968
- })
4969
- });
5122
+ else {
5123
+ Object.assign(options, url);
4970
5124
  }
4971
- return new Promise((resolve, reject) => {
4972
- Taro.eventCenter.trigger('__taroSetTabBarItem', {
4973
- index,
4974
- text,
4975
- iconPath,
4976
- selectedIconPath,
4977
- successHandler: (res = {}) => handle.success(res, { resolve, reject }),
4978
- errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
4979
- });
4980
- });
4981
- };
4982
- /**
4983
- * 为 tabBar 某一项的右上角添加文本
4984
- */
4985
- const setTabBarBadge = (options) => {
4986
- // options must be an Object
4987
- const isObject = shouldBeObject(options);
4988
- if (!isObject.flag) {
4989
- const res = { errMsg: `setTabBarBadge:fail ${isObject.msg}` };
4990
- console.error(res.errMsg);
4991
- return Promise.reject(res);
5125
+ return link.request(options);
5126
+ });
5127
+ const addInterceptor = link.addInterceptor.bind(link);
5128
+ const cleanInterceptors = link.cleanInterceptors.bind(link);
5129
+
5130
+ // TCP 通信
5131
+ const createTCPSocket = /* @__PURE__ */ temporarilyNotSupport('createTCPSocket');
5132
+
5133
+ // UDP 通信
5134
+ const createUDPSocket = /* @__PURE__ */ temporarilyNotSupport('createUDPSocket');
5135
+
5136
+ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, withCredentials = true, success, error }) => {
5137
+ let timeoutInter;
5138
+ let formKey;
5139
+ const apiName = 'uploadFile';
5140
+ const xhr = new XMLHttpRequest();
5141
+ const form = new FormData();
5142
+ const callbackManager = {
5143
+ headersReceived: new CallbackManager(),
5144
+ progressUpdate: new CallbackManager()
5145
+ };
5146
+ xhr.open('POST', url);
5147
+ xhr.withCredentials = !!withCredentials;
5148
+ setHeader(xhr, header);
5149
+ for (formKey in formData) {
5150
+ form.append(formKey, formData[formKey]);
4992
5151
  }
4993
- const { index, text, success, fail, complete } = options;
4994
- const handle = new MethodHandler({ name: 'setTabBarBadge', success, fail, complete });
4995
- if (typeof index !== 'number') {
4996
- return handle.fail({
4997
- errMsg: getParameterError({
4998
- para: 'index',
4999
- correct: 'Number',
5000
- wrong: index
5001
- })
5152
+ xhr.upload.onprogress = e => {
5153
+ const { loaded, total } = e;
5154
+ callbackManager.progressUpdate.trigger({
5155
+ progress: Math.round(loaded / total * 100),
5156
+ totalBytesSent: loaded,
5157
+ totalBytesExpectedToSend: total
5002
5158
  });
5003
- }
5004
- if (typeof text !== 'string') {
5005
- return handle.fail({
5006
- errMsg: getParameterError({
5007
- para: 'text',
5008
- correct: 'String',
5009
- wrong: text
5010
- })
5159
+ };
5160
+ xhr.onreadystatechange = () => {
5161
+ if (xhr.readyState !== XHR_STATS.HEADERS_RECEIVED)
5162
+ return;
5163
+ callbackManager.headersReceived.trigger({
5164
+ header: xhr.getAllResponseHeaders()
5011
5165
  });
5012
- }
5013
- return new Promise((resolve, reject) => {
5014
- Taro.eventCenter.trigger('__taroSetTabBarBadge', {
5015
- index,
5016
- text,
5017
- successHandler: (res = {}) => handle.success(res, { resolve, reject }),
5018
- errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
5166
+ };
5167
+ xhr.onload = () => {
5168
+ const status = xhr.status;
5169
+ clearTimeout(timeoutInter);
5170
+ success({
5171
+ errMsg: `${apiName}:ok`,
5172
+ statusCode: status,
5173
+ data: xhr.responseText || xhr.response
5174
+ });
5175
+ };
5176
+ xhr.onabort = () => {
5177
+ clearTimeout(timeoutInter);
5178
+ error({
5179
+ errMsg: `${apiName}:fail abort`
5180
+ });
5181
+ };
5182
+ xhr.onerror = (e) => {
5183
+ clearTimeout(timeoutInter);
5184
+ error({
5185
+ errMsg: `${apiName}:fail ${e.message}`
5186
+ });
5187
+ };
5188
+ /**
5189
+ * 中断任务
5190
+ */
5191
+ const abort = () => {
5192
+ clearTimeout(timeoutInter);
5193
+ xhr.abort();
5194
+ };
5195
+ const send = () => {
5196
+ xhr.send(form);
5197
+ timeoutInter = setTimeout(() => {
5198
+ xhr.onabort = null;
5199
+ xhr.onload = null;
5200
+ xhr.upload.onprogress = null;
5201
+ xhr.onreadystatechange = null;
5202
+ xhr.onerror = null;
5203
+ abort();
5204
+ error({
5205
+ errMsg: `${apiName}:fail timeout`
5206
+ });
5207
+ }, timeout || NETWORK_TIMEOUT);
5208
+ };
5209
+ convertObjectUrlToBlob(filePath)
5210
+ .then((fileObj) => {
5211
+ if (!fileName) {
5212
+ fileName = typeof fileObj !== 'string' && fileObj.name;
5213
+ }
5214
+ form.append(name, fileObj, fileName || `file-${Date.now()}`);
5215
+ send();
5216
+ })
5217
+ .catch(e => {
5218
+ error({
5219
+ errMsg: `${apiName}:fail ${e.message}`
5019
5220
  });
5020
5221
  });
5222
+ /**
5223
+ * 监听 HTTP Response Header 事件。会比请求完成事件更早
5224
+ * @param {HeadersReceivedCallback} callback HTTP Response Header 事件的回调函数
5225
+ */
5226
+ const onHeadersReceived = callbackManager.headersReceived.add;
5227
+ /**
5228
+ * 取消监听 HTTP Response Header 事件
5229
+ * @param {HeadersReceivedCallback} callback HTTP Response Header 事件的回调函数
5230
+ */
5231
+ const offHeadersReceived = callbackManager.headersReceived.remove;
5232
+ /**
5233
+ * 监听进度变化事件
5234
+ * @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
5235
+ */
5236
+ const onProgressUpdate = callbackManager.progressUpdate.add;
5237
+ /**
5238
+ * 取消监听进度变化事件
5239
+ * @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
5240
+ */
5241
+ const offProgressUpdate = callbackManager.progressUpdate.remove;
5242
+ return {
5243
+ abort,
5244
+ onHeadersReceived,
5245
+ offHeadersReceived,
5246
+ onProgressUpdate,
5247
+ offProgressUpdate
5248
+ };
5021
5249
  };
5022
5250
  /**
5023
- * 移除 tabBar 某一项右上角的文本
5251
+ * 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。
5024
5252
  */
5025
- const removeTabBarBadge = (options) => {
5026
- // options must be an Object
5027
- const isObject = shouldBeObject(options);
5028
- if (!isObject.flag) {
5029
- const res = { errMsg: `removeTabBarBadge:fail ${isObject.msg}` };
5030
- console.error(res.errMsg);
5031
- return Promise.reject(res);
5032
- }
5033
- const { index, success, fail, complete } = options;
5034
- const handle = new MethodHandler({ name: 'removeTabBarBadge', success, fail, complete });
5035
- if (typeof index !== 'number') {
5036
- return handle.fail({
5037
- errMsg: getParameterError({
5038
- para: 'index',
5039
- correct: 'Number',
5040
- wrong: index
5041
- })
5042
- });
5043
- }
5044
- return new Promise((resolve, reject) => {
5045
- Taro.eventCenter.trigger('__taroRemoveTabBarBadge', {
5046
- index,
5047
- successHandler: (res = {}) => handle.success(res, { resolve, reject }),
5048
- errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
5253
+ const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, withCredentials, success, fail, complete }) => {
5254
+ let task;
5255
+ const result = new Promise((resolve, reject) => {
5256
+ task = createUploadTask({
5257
+ url,
5258
+ header,
5259
+ name,
5260
+ filePath,
5261
+ formData,
5262
+ timeout,
5263
+ fileName,
5264
+ withCredentials,
5265
+ success: res => {
5266
+ success && success(res);
5267
+ complete && complete(res);
5268
+ resolve(res);
5269
+ },
5270
+ error: res => {
5271
+ fail && fail(res);
5272
+ complete && complete(res);
5273
+ reject(res);
5274
+ }
5049
5275
  });
5050
5276
  });
5277
+ result.headersReceive = task.onHeadersReceived;
5278
+ result.progress = task.onProgressUpdate;
5279
+ return new Proxy(result, {
5280
+ get(target, prop) {
5281
+ const object = prop in task ? task : target;
5282
+ const value = object[prop];
5283
+ return typeof value === 'function' ? value.bind(object) : value;
5284
+ },
5285
+ });
5051
5286
  };
5052
- /**
5053
- * 隐藏 tabBar 某一项的右上角的红点
5054
- */
5055
- const hideTabBarRedDot = (options) => {
5056
- // options must be an Object
5057
- const isObject = shouldBeObject(options);
5058
- if (!isObject.flag) {
5059
- const res = { errMsg: `hideTabBarRedDot:fail ${isObject.msg}` };
5060
- console.error(res.errMsg);
5061
- return Promise.reject(res);
5287
+
5288
+ class SocketTask {
5289
+ constructor(url, protocols) {
5290
+ if (protocols && protocols.length) {
5291
+ this.ws = new WebSocket(url, protocols);
5292
+ }
5293
+ else {
5294
+ this.ws = new WebSocket(url);
5295
+ }
5296
+ this.CONNECTING = 0;
5297
+ this.OPEN = 1;
5298
+ this.CLOSING = 2;
5299
+ this.CLOSED = 3;
5062
5300
  }
5063
- const { index, success, fail, complete } = options;
5064
- const handle = new MethodHandler({ name: 'hideTabBarRedDot', success, fail, complete });
5065
- if (typeof index !== 'number') {
5066
- return handle.fail({
5067
- errMsg: getParameterError({
5068
- para: 'index',
5069
- correct: 'Number',
5070
- wrong: index
5071
- })
5072
- });
5301
+ get readyState() {
5302
+ return this.ws.readyState;
5073
5303
  }
5074
- return new Promise((resolve, reject) => {
5075
- Taro.eventCenter.trigger('__taroHideTabBarRedDotHandler', {
5076
- index,
5077
- successHandler: (res = {}) => handle.success(res, { resolve, reject }),
5078
- errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
5079
- });
5080
- });
5081
- };
5082
- /**
5083
- * 隐藏 tabBar
5084
- */
5085
- const hideTabBar = (options = {}) => {
5086
- // options must be an Object
5087
- const isObject = shouldBeObject(options);
5088
- if (!isObject.flag) {
5089
- const res = { errMsg: `hideTabBar:fail ${isObject.msg}` };
5090
- console.error(res.errMsg);
5091
- return Promise.reject(res);
5304
+ send(opts = {}) {
5305
+ if (typeof opts !== 'object' || !opts)
5306
+ opts = {};
5307
+ const { data = '', success, fail, complete } = opts;
5308
+ if (this.readyState !== 1) {
5309
+ const res = { errMsg: 'SocketTask.send:fail SocketTask.readState is not OPEN' };
5310
+ console.error(res.errMsg);
5311
+ shared.isFunction(fail) && fail(res);
5312
+ shared.isFunction(complete) && complete(res);
5313
+ return Promise.reject(res);
5314
+ }
5315
+ this.ws.send(data);
5316
+ const res = { errMsg: 'sendSocketMessage:ok' };
5317
+ shared.isFunction(success) && success(res);
5318
+ shared.isFunction(complete) && complete(res);
5319
+ return Promise.resolve(res);
5092
5320
  }
5093
- const { animation, success, fail, complete } = options;
5094
- const handle = new MethodHandler({ name: 'hideTabBar', success, fail, complete });
5095
- if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
5096
- return handle.fail({
5097
- errMsg: getParameterError({
5098
- para: 'animation',
5099
- correct: 'Boolean',
5100
- wrong: animation
5101
- })
5102
- });
5321
+ close(opts = {}) {
5322
+ if (typeof opts !== 'object' || !opts)
5323
+ opts = {};
5324
+ const { code = 1000, reason = 'server complete,close', success, complete } = opts;
5325
+ this.closeDetail = { code, reason };
5326
+ // 主动断开时需要重置链接数
5327
+ this._destroyWhenClose && this._destroyWhenClose();
5328
+ this.ws.close();
5329
+ const res = { errMsg: 'closeSocket:ok' };
5330
+ shared.isFunction(success) && success(res);
5331
+ shared.isFunction(complete) && complete(res);
5332
+ return Promise.resolve(res);
5333
+ }
5334
+ onOpen(func) {
5335
+ this.ws.onopen = func;
5336
+ }
5337
+ onMessage(func) {
5338
+ this.ws.onmessage = func;
5339
+ }
5340
+ onClose(func) {
5341
+ this.ws.onclose = () => {
5342
+ // 若服务器方断掉也需要重置链接数
5343
+ this._destroyWhenClose && this._destroyWhenClose();
5344
+ func(this.closeDetail || { code: 1006, reason: 'abnormal closure' });
5345
+ };
5346
+ }
5347
+ onError(func) {
5348
+ this.ws.onerror = func;
5103
5349
  }
5350
+ }
5351
+
5352
+ let socketTasks = [];
5353
+ let socketsCounter = 1;
5354
+ function sendSocketMessage() {
5355
+ console.warn('Deprecated.Please use socketTask.send instead.');
5356
+ }
5357
+ function onSocketOpen() {
5358
+ console.warn('Deprecated.Please use socketTask.onOpen instead.');
5359
+ }
5360
+ function onSocketMessage() {
5361
+ console.warn('Deprecated.Please use socketTask.onMessage instead.');
5362
+ }
5363
+ function onSocketError() {
5364
+ console.warn('Deprecated.Please use socketTask.onError instead.');
5365
+ }
5366
+ function onSocketClose() {
5367
+ console.warn('Deprecated.Please use socketTask.onClose instead.');
5368
+ }
5369
+ function connectSocket(options) {
5370
+ const name = 'connectSocket';
5104
5371
  return new Promise((resolve, reject) => {
5105
- Taro.eventCenter.trigger('__taroHideTabBar', {
5106
- animation,
5107
- successHandler: (res = {}) => handle.success(res, { resolve, reject }),
5108
- errorHandler: (res = {}) => handle.fail(res, { resolve, reject })
5372
+ // options must be an Object
5373
+ const isObject = shouldBeObject(options);
5374
+ if (!isObject.flag) {
5375
+ const res = { errMsg: `${name}:fail ${isObject.msg}` };
5376
+ console.error(res.errMsg);
5377
+ return reject(res);
5378
+ }
5379
+ const { url, protocols, success, fail, complete } = options;
5380
+ const handle = new MethodHandler({ name, success, fail, complete });
5381
+ // options.url must be String
5382
+ if (typeof url !== 'string') {
5383
+ return handle.fail({
5384
+ errMsg: getParameterError({
5385
+ para: 'url',
5386
+ correct: 'String',
5387
+ wrong: url
5388
+ })
5389
+ }, { resolve, reject });
5390
+ }
5391
+ // options.url must be invalid
5392
+ if (!url.startsWith('ws://') && !url.startsWith('wss://')) {
5393
+ return handle.fail({
5394
+ errMsg: `request:fail invalid url "${url}"`
5395
+ }, { resolve, reject });
5396
+ }
5397
+ // protocols must be array
5398
+ const _protocols = Array.isArray(protocols) ? protocols : null;
5399
+ // 2 connection at most
5400
+ if (socketTasks.length > 1) {
5401
+ return handle.fail({
5402
+ errMsg: '同时最多发起 2 个 socket 请求,更多请参考文档。'
5403
+ }, { resolve, reject });
5404
+ }
5405
+ const task = new SocketTask(url, _protocols);
5406
+ task._destroyWhenClose = function () {
5407
+ socketTasks = socketTasks.filter(socketTask => socketTask !== this);
5408
+ };
5409
+ socketTasks.push(task);
5410
+ handle.success({
5411
+ socketTaskId: socketsCounter++
5109
5412
  });
5413
+ return resolve(task);
5110
5414
  });
5111
- };
5415
+ }
5416
+ function closeSocket() {
5417
+ console.warn('Deprecated.Please use socketTask.close instead.');
5418
+ }
5112
5419
 
5113
- const callbackManager = new CallbackManager();
5114
- const resizeListener = () => {
5115
- callbackManager.trigger({
5116
- windowWidth: window.screen.width,
5117
- windowHeight: window.screen.height
5118
- });
5119
- };
5120
- /**
5121
- * 设置窗口大小,该接口仅适用于 PC 平台,使用细则请参见指南
5122
- */
5123
- const setWindowSize = temporarilyNotSupport('setWindowSize');
5124
- /**
5125
- * 监听窗口尺寸变化事件
5126
- */
5127
- const onWindowResize = callback => {
5128
- callbackManager.add(callback);
5129
- if (callbackManager.count() === 1) {
5130
- window.addEventListener('resize', resizeListener);
5131
- }
5132
- };
5133
- /**
5134
- * 取消监听窗口尺寸变化事件
5135
- */
5136
- const offWindowResize = callback => {
5137
- callbackManager.remove(callback);
5138
- if (callbackManager.count() === 0) {
5139
- window.removeEventListener('resize', resizeListener);
5140
- }
5141
- };
5142
- const checkIsPictureInPictureActive = temporarilyNotSupport('checkIsPictureInPictureActive');
5420
+ // 帐号信息
5421
+ const getAccountInfoSync = /* @__PURE__ */ temporarilyNotSupport('getAccountInfoSync');
5422
+
5423
+ // 收货地址
5424
+ const chooseAddress = /* @__PURE__ */ temporarilyNotSupport('chooseAddress');
5425
+
5426
+ // 授权
5427
+ const authorizeForMiniProgram = /* @__PURE__ */ temporarilyNotSupport('authorizeForMiniProgram');
5428
+ const authorize = /* @__PURE__ */ temporarilyNotSupport('authorize');
5429
+
5430
+ // 卡券
5431
+ const openCard = /* @__PURE__ */ temporarilyNotSupport('openCard');
5432
+ const addCard = /* @__PURE__ */ temporarilyNotSupport('addCard');
5433
+
5434
+ // 视频号
5435
+ const reserveChannelsLive = /* @__PURE__ */ temporarilyNotSupport('reserveChannelsLive');
5436
+ const openChannelsLive = /* @__PURE__ */ temporarilyNotSupport('openChannelsLive');
5437
+ const openChannelsEvent = /* @__PURE__ */ temporarilyNotSupport('openChannelsEvent');
5438
+ const openChannelsActivity = /* @__PURE__ */ temporarilyNotSupport('openChannelsActivity');
5439
+ const getChannelsLiveNoticeInfo = /* @__PURE__ */ temporarilyNotSupport('getChannelsLiveNoticeInfo');
5440
+ const getChannelsLiveInfo = /* @__PURE__ */ temporarilyNotSupport('getChannelsLiveInfo');
5441
+
5442
+ // 微信客服
5443
+ const openCustomerServiceChat = /* @__PURE__ */ temporarilyNotSupport('openCustomerServiceChat');
5444
+
5445
+ // 过往接口
5446
+ const checkIsSupportFacialRecognition = /* @__PURE__ */ temporarilyNotSupport('checkIsSupportFacialRecognition');
5447
+ const startFacialRecognitionVerify = /* @__PURE__ */ temporarilyNotSupport('startFacialRecognitionVerify');
5448
+ const startFacialRecognitionVerifyAndUploadVideo = /* @__PURE__ */ temporarilyNotSupport('startFacialRecognitionVerifyAndUploadVideo');
5449
+ const faceVerifyForPay = /* @__PURE__ */ temporarilyNotSupport('faceVerifyForPay');
5450
+
5451
+ // 收藏
5452
+ const addVideoToFavorites = /* @__PURE__ */ temporarilyNotSupport('addVideoToFavorites');
5453
+ const addFileToFavorites = /* @__PURE__ */ temporarilyNotSupport('addFileToFavorites');
5454
+ const checkIsAddedToMyMiniProgram = /* @__PURE__ */ temporarilyNotSupport('checkIsAddedToMyMiniProgram');
5455
+
5456
+ // 微信群
5457
+ const getGroupEnterInfo = /* @__PURE__ */ temporarilyNotSupport('getGroupEnterInfo');
5458
+
5459
+ // 发票
5460
+ const chooseInvoiceTitle = /* @__PURE__ */ temporarilyNotSupport('chooseInvoiceTitle');
5461
+ const chooseInvoice = /* @__PURE__ */ temporarilyNotSupport('chooseInvoice');
5462
+
5463
+ // 车牌
5464
+ const chooseLicensePlate = /* @__PURE__ */ temporarilyNotSupport('chooseLicensePlate');
5465
+
5466
+ // 帐号信息
5467
+ const pluginLogin = /* @__PURE__ */ temporarilyNotSupport('pluginLogin');
5468
+ const login = /* @__PURE__ */ temporarilyNotSupport('login');
5469
+ const checkSession = /* @__PURE__ */ temporarilyNotSupport('checkSession');
5470
+
5471
+ // 微信红包
5472
+ const showRedPackage = /* @__PURE__ */ temporarilyNotSupport('showRedPackage');
5473
+
5474
+ // 设置
5475
+ const openSetting = /* @__PURE__ */ temporarilyNotSupport('openSetting');
5476
+ const getSetting = /* @__PURE__ */ temporarilyNotSupport('getSetting');
5477
+
5478
+ // 生物认证
5479
+ const startSoterAuthentication = /* @__PURE__ */ temporarilyNotSupport('startSoterAuthentication');
5480
+ const checkIsSupportSoterAuthentication = /* @__PURE__ */ temporarilyNotSupport('checkIsSupportSoterAuthentication');
5481
+ const checkIsSoterEnrolledInDevice = /* @__PURE__ */ temporarilyNotSupport('checkIsSoterEnrolledInDevice');
5482
+
5483
+ // 订阅消息
5484
+ const requestSubscribeMessage = /* @__PURE__ */ temporarilyNotSupport('requestSubscribeMessage');
5485
+ // 订阅设备消息
5486
+ const requestSubscribeDeviceMessage = /* @__PURE__ */ temporarilyNotSupport('requestSubscribeDeviceMessage');
5487
+
5488
+ // 用户信息
5489
+ const getUserProfile = /* @__PURE__ */ temporarilyNotSupport('getUserProfile');
5490
+ const getUserInfo = /* @__PURE__ */ temporarilyNotSupport('getUserInfo');
5491
+
5492
+ // 微信运动
5493
+ const shareToWeRun = /* @__PURE__ */ temporarilyNotSupport('shareToWeRun');
5494
+ const getWeRunData = /* @__PURE__ */ temporarilyNotSupport('getWeRunData');
5495
+
5496
+ // 支付
5497
+ const requestPayment = /* @__PURE__ */ temporarilyNotSupport('requestPayment');
5498
+ const requestOrderPayment = /* @__PURE__ */ temporarilyNotSupport('requestOrderPayment');
5499
+
5500
+ // 打开手Q说说发表界面
5501
+ const openQzonePublish = /* @__PURE__ */ temporarilyNotSupport('openQzonePublish');
5502
+
5503
+ // 路由
5504
+ // FIXME 方法导出类型未对齐,后续修复
5505
+
5506
+ // 转发
5507
+ /** 更新转发属性 */
5508
+ const updateShareMenu = /* @__PURE__ */ temporarilyNotSupport('updateShareMenu');
5509
+ /** 显示当前页面的转发按钮 */
5510
+ const showShareMenu = /* @__PURE__ */ temporarilyNotSupport('showShareMenu');
5511
+ /** 打开分享图片弹窗,可以将图片发送给朋友、收藏或下载 */
5512
+ const showShareImageMenu = /* @__PURE__ */ temporarilyNotSupport('showShareImageMenu');
5513
+ /** 转发视频到聊天 */
5514
+ const shareVideoMessage = /* @__PURE__ */ temporarilyNotSupport('shareVideoMessage');
5515
+ /** 转发文件到聊天 */
5516
+ const shareFileMessage = /* @__PURE__ */ temporarilyNotSupport('shareFileMessage');
5517
+ /** 监听用户点击右上角菜单的「复制链接」按钮时触发的事件 */
5518
+ const onCopyUrl = /* @__PURE__ */ temporarilyNotSupport('onCopyUrl');
5519
+ /** 移除用户点击右上角菜单的「复制链接」按钮时触发的事件的监听函数 */
5520
+ const offCopyUrl = /* @__PURE__ */ temporarilyNotSupport('offCopyUrl');
5521
+ /** 隐藏当前页面的转发按钮 */
5522
+ const hideShareMenu = /* @__PURE__ */ temporarilyNotSupport('hideShareMenu');
5523
+ /** 获取转发详细信息 */
5524
+ const getShareInfo = /* @__PURE__ */ temporarilyNotSupport('getShareInfo');
5525
+ /** 验证私密消息。 */
5526
+ const authPrivateMessage = /* @__PURE__ */ permanentlyNotSupport('authPrivateMessage');
5527
+
5528
+ const setPageInfo = /* @__PURE__ */ temporarilyNotSupport('setPageInfo');
5529
+ // 百度小程序 AI 相关
5530
+ const ocrIdCard = /* @__PURE__ */ temporarilyNotSupport('ocrIdCard');
5531
+ const ocrBankCard = /* @__PURE__ */ temporarilyNotSupport('ocrBankCard');
5532
+ const ocrDrivingLicense = /* @__PURE__ */ temporarilyNotSupport('ocrDrivingLicense');
5533
+ const ocrVehicleLicense = /* @__PURE__ */ temporarilyNotSupport('ocrVehicleLicense');
5534
+ const textReview = /* @__PURE__ */ temporarilyNotSupport('textReview');
5535
+ const textToAudio = /* @__PURE__ */ temporarilyNotSupport('textToAudio');
5536
+ const imageAudit = /* @__PURE__ */ temporarilyNotSupport('imageAudit');
5537
+ const advancedGeneralIdentify = /* @__PURE__ */ temporarilyNotSupport('advancedGeneralIdentify');
5538
+ const objectDetectIdentify = /* @__PURE__ */ temporarilyNotSupport('objectDetectIdentify');
5539
+ const carClassify = /* @__PURE__ */ temporarilyNotSupport('carClassify');
5540
+ const dishClassify = /* @__PURE__ */ temporarilyNotSupport('dishClassify');
5541
+ const logoClassify = /* @__PURE__ */ temporarilyNotSupport('logoClassify');
5542
+ const animalClassify = /* @__PURE__ */ temporarilyNotSupport('animalClassify');
5543
+ const plantClassify = /* @__PURE__ */ temporarilyNotSupport('plantClassify');
5544
+ // 用户信息
5545
+ const getSwanId = /* @__PURE__ */ temporarilyNotSupport('getSwanId');
5546
+ // 百度收银台支付
5547
+ const requestPolymerPayment = /* @__PURE__ */ temporarilyNotSupport('requestPolymerPayment');
5548
+ // 打开小程序
5549
+ const navigateToSmartGameProgram = /* @__PURE__ */ temporarilyNotSupport('navigateToSmartGameProgram');
5550
+ const navigateToSmartProgram = /* @__PURE__ */ temporarilyNotSupport('navigateToSmartProgram');
5551
+ const navigateBackSmartProgram = /* @__PURE__ */ temporarilyNotSupport('navigateBackSmartProgram');
5552
+ const preloadSubPackage = /* @__PURE__ */ temporarilyNotSupport('preloadSubPackage');
5143
5553
 
5144
5554
  // Worker
5145
- const createWorker = temporarilyNotSupport('createWorker');
5555
+ const createWorker = /* @__PURE__ */ temporarilyNotSupport('createWorker');
5146
5556
 
5147
- // pollify
5148
5557
  import('intersection-observer');
5149
5558
  class TaroH5IntersectionObserver {
5150
5559
  // selector 的容器节点
@@ -5580,7 +5989,7 @@ const taro = {
5580
5989
  getCurrentPages: router.getCurrentPages,
5581
5990
  switchTab: router.switchTab
5582
5991
  };
5583
- const requirePlugin = permanentlyNotSupport('requirePlugin');
5992
+ const requirePlugin = /* @__PURE__ */ permanentlyNotSupport('requirePlugin');
5584
5993
  function getConfig() {
5585
5994
  var _a;
5586
5995
  if (this === null || this === void 0 ? void 0 : this.pxTransformConfig)