@tarojs/taro-h5 3.4.0 → 3.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/api/ai/visual.js +2 -0
  2. package/dist/api/base/system.js +187 -0
  3. package/dist/api/canvas/CanvasContext.js +1 -1
  4. package/dist/api/canvas/index.js +5 -1
  5. package/dist/api/cloud/index.js +4 -0
  6. package/dist/api/device/battery.js +18 -1
  7. package/dist/api/device/index.js +1 -0
  8. package/dist/api/{base/system → device}/network.js +29 -14
  9. package/dist/api/device/wifi.js +1 -0
  10. package/dist/api/media/{editor.js → EditorContext.js} +1 -0
  11. package/dist/api/media/audio/InnerAudioContext.js +84 -0
  12. package/dist/api/media/audio/index.js +1 -74
  13. package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
  14. package/dist/api/media/{background-audio.js → background-audio/index.js} +6 -2
  15. package/dist/api/media/index.js +0 -1
  16. package/dist/api/network/upload.js +2 -7
  17. package/dist/api/ui/animation/index.js +9 -5
  18. package/dist/api/ui/fonts.js +50 -2
  19. package/dist/api/ui/scroll/index.js +3 -3
  20. package/dist/api/utils/handler.js +45 -45
  21. package/dist/api/utils/index.js +36 -12
  22. package/dist/index.cjs.js +517 -188
  23. package/dist/taroApis.js +1 -1
  24. package/package.json +7 -7
  25. package/src/api/ai/visual.ts +3 -0
  26. package/src/api/base/system.ts +207 -0
  27. package/src/api/canvas/CanvasContext.ts +7 -7
  28. package/src/api/canvas/index.ts +10 -2
  29. package/src/api/cloud/index.ts +4 -0
  30. package/src/api/device/battery.ts +18 -1
  31. package/src/api/device/index.ts +1 -0
  32. package/src/api/{base/system → device}/network.ts +35 -15
  33. package/src/api/device/wifi.ts +1 -0
  34. package/src/api/media/{editor.ts → EditorContext.ts} +2 -0
  35. package/src/api/media/audio/InnerAudioContext.ts +98 -0
  36. package/src/api/media/audio/index.ts +1 -86
  37. package/src/api/media/background-audio/BackgroundAudioManager.ts +103 -0
  38. package/src/api/media/{background-audio.ts → background-audio/index.ts} +7 -2
  39. package/src/api/media/index.ts +0 -1
  40. package/src/api/network/upload.ts +2 -8
  41. package/src/api/ui/animation/index.ts +10 -6
  42. package/src/api/ui/fonts.ts +61 -2
  43. package/src/api/ui/scroll/index.ts +3 -3
  44. package/src/api/utils/handler.ts +4 -4
  45. package/src/api/utils/index.ts +33 -12
  46. package/dist/api/base/system/index.js +0 -2
  47. package/dist/api/base/system/info.js +0 -57
  48. package/src/api/base/system/index.ts +0 -2
  49. package/src/api/base/system/info.ts +0 -64
package/dist/taroApis.js CHANGED
@@ -1 +1 @@
1
- module.exports = new Set(["EditorContext","addCard","addFileToFavorites","addInterceptor","addPhoneCalendar","addPhoneContact","addPhoneRepeatCalendar","addVideoToFavorites","advancedGeneralIdentify","animalClassify","arrayBufferToBase64","authPrivateMessage","authorize","authorizeForMiniProgram","base64ToArrayBuffer","canIUse","canvasGetImageData","canvasPutImageData","canvasToTempFilePath","carClassify","checkIsOpenAccessibility","checkIsSoterEnrolledInDevice","checkIsSupportFacialRecognition","checkIsSupportSoterAuthentication","checkSession","chooseAddress","chooseContact","chooseImage","chooseInvoice","chooseInvoiceTitle","chooseLicensePlate","chooseLocation","chooseMedia","chooseMessageFile","choosePoi","chooseVideo","clearStorage","clearStorageSync","closeBLEConnection","closeBluetoothAdapter","closeSocket","cloud","compressImage","compressVideo","connectSocket","connectWifi","createAnimation","createAudioContext","createBLEConnection","createBLEPeripheralServer","createBufferURL","createCameraContext","createCanvasContext","createInnerAudioContext","createIntersectionObserver","createInterstitialAd","createLivePlayerContext","createLivePusherContext","createMapContext","createMediaAudioPlayer","createMediaContainer","createMediaRecorder","createOffscreenCanvas","createRewardedVideoAd","createSelectorQuery","createTCPSocket","createUDPSocket","createVKSession","createVideoContext","createVideoDecoder","createWebAudioContext","createWorker","disableAlertBeforeUnload","dishClassify","downloadFile","drawCanvas","enableAlertBeforeUnload","exitMiniProgram","exitVoIPChat","faceDetect","faceVerifyForPay","getAccountInfoSync","getApp","getAvailableAudioSources","getBLEDeviceCharacteristics","getBLEDeviceRSSI","getBLEDeviceServices","getBLEMTU","getBackgroundAudioManager","getBackgroundAudioPlayerState","getBackgroundFetchData","getBackgroundFetchToken","getBatteryInfo","getBatteryInfoSync","getBeacons","getBluetoothAdapterState","getBluetoothDevices","getChannelsLiveInfo","getChannelsLiveNoticeInfo","getClipboardData","getConnectedBluetoothDevices","getConnectedWifi","getCurrentInstance","getCurrentPages","getEnterOptionsSync","getExptInfoSync","getExtConfig","getExtConfigSync","getFileInfo","getFileSystemManager","getGroupEnterInfo","getHCEState","getImageInfo","getLaunchOptionsSync","getLocalIPAddress","getLocation","getLogManager","getMenuButtonBoundingClientRect","getNFCAdapter","getNetworkType","getOpenUserInfo","getPerformance","getRandomValues","getRealtimeLogManager","getRecorderManager","getSavedFileInfo","getSavedFileList","getScreenBrightness","getSelectedTextRange","getSetting","getShareInfo","getStorage","getStorageInfo","getStorageInfoSync","getStorageSync","getSwanId","getSystemInfo","getSystemInfoSync","getUpdateManager","getUserCryptoManager","getUserInfo","getUserProfile","getVideoInfo","getWeRunData","getWifiList","hideHomeButton","hideKeyboard","hideLoading","hideNavigationBarLoading","hideShareMenu","hideTabBar","hideTabBarRedDot","hideToast","imageAudit","initFaceDetect","initTabBarApis","isBluetoothDevicePaired","joinVoIPChat","loadFontFace","login","logoClassify","makeBluetoothPair","makePhoneCall","navigateBack","navigateBackMiniProgram","navigateBackSmartProgram","navigateTo","navigateToMiniProgram","navigateToSmartGameProgram","navigateToSmartProgram","nextTick","notifyBLECharacteristicValueChange","objectDetectIdentify","ocrBankCard","ocrDrivingLicense","ocrIdCard","ocrVehicleLicense","offAccelerometerChange","offAppHide","offAppShow","offAudioInterruptionBegin","offAudioInterruptionEnd","offBLECharacteristicValueChange","offBLEConnectionStateChange","offBLEMTUChange","offBLEPeripheralConnectionStateChanged","offBeaconServiceChange","offBeaconUpdate","offBluetoothAdapterStateChange","offBluetoothDeviceFound","offCompassChange","offCopyUrl","offDeviceMotionChange","offError","offGetWifiList","offGyroscopeChange","offHCEMessage","offKeyboardHeightChange","offLocalServiceDiscoveryStop","offLocalServiceFound","offLocalServiceLost","offLocalServiceResolveFail","offLocationChange","offLocationChangeError","offMemoryWarning","offNetworkStatusChange","offPageNotFound","offThemeChange","offUnhandledRejection","offUserCaptureScreen","offVoIPChatInterrupted","offVoIPChatMembersChanged","offVoIPChatStateChanged","offVoIPVideoMembersChanged","offWifiConnected","offWindowResize","onAccelerometerChange","onAppHide","onAppShow","onAudioInterruptionBegin","onAudioInterruptionEnd","onBLECharacteristicValueChange","onBLEConnectionStateChange","onBLEMTUChange","onBLEPeripheralConnectionStateChanged","onBackgroundAudioPause","onBackgroundAudioPlay","onBackgroundAudioStop","onBackgroundFetchData","onBeaconServiceChange","onBeaconUpdate","onBluetoothAdapterStateChange","onBluetoothDeviceFound","onCompassChange","onCopyUrl","onDeviceMotionChange","onError","onGetWifiList","onGyroscopeChange","onHCEMessage","onKeyboardHeightChange","onLocalServiceDiscoveryStop","onLocalServiceFound","onLocalServiceLost","onLocalServiceResolveFail","onLocationChange","onLocationChangeError","onMemoryWarning","onNetworkStatusChange","onPageNotFound","onSocketClose","onSocketError","onSocketMessage","onSocketOpen","onThemeChange","onUnhandledRejection","onUserCaptureScreen","onVoIPChatInterrupted","onVoIPChatMembersChanged","onVoIPChatSpeakersChanged","onVoIPChatStateChanged","onVoIPVideoMembersChanged","onWifiConnected","onWindowResize","openBluetoothAdapter","openCard","openChannelsActivity","openChannelsEvent","openChannelsLive","openCustomerServiceChat","openDocument","openEmbeddedMiniProgram","openLocation","openSetting","openVideoEditor","pageScrollTo","pauseBackgroundAudio","pauseVoice","plantClassify","playBackgroundAudio","playVoice","pluginLogin","preloadSubPackage","previewImage","previewMedia","reLaunch","readBLECharacteristicValue","redirectTo","removeSavedFile","removeStorage","removeStorageSync","removeTabBarBadge","reportAnalytics","reportEvent","reportMonitor","reportPerformance","request","requestOrderPayment","requestPayment","requestPolymerPayment","requestSubscribeMessage","reserveChannelsLive","revokeBufferURL","saveFile","saveFileToDisk","saveImageToPhotosAlbum","saveVideoToPhotosAlbum","scanCode","seekBackgroundAudio","sendHCEMessage","sendSocketMessage","setBLEMTU","setBackgroundColor","setBackgroundFetchToken","setBackgroundTextStyle","setClipboardData","setEnable1v1Chat","setEnableDebug","setInnerAudioOption","setKeepScreenOn","setNavigationBarColor","setNavigationBarTitle","setPageInfo","setScreenBrightness","setStorage","setStorageSync","setTabBarBadge","setTabBarItem","setTabBarStyle","setTopBarText","setVisualEffectOnCapture","setWifiList","setWindowSize","shareFileMessage","shareToWeRun","shareVideoMessage","showActionSheet","showLoading","showModal","showNavigationBarLoading","showRedPackage","showShareImageMenu","showShareMenu","showTabBar","showTabBarRedDot","showToast","startAccelerometer","startBeaconDiscovery","startBluetoothDevicesDiscovery","startCompass","startDeviceMotionListening","startFacialRecognitionVerify","startFacialRecognitionVerifyAndUploadVideo","startGyroscope","startHCE","startLocalServiceDiscovery","startLocationUpdate","startLocationUpdateBackground","startPullDownRefresh","startRecord","startSoterAuthentication","startWifi","stopAccelerometer","stopBackgroundAudio","stopBeaconDiscovery","stopBluetoothDevicesDiscovery","stopCompass","stopDeviceMotionListening","stopFaceDetect","stopGyroscope","stopHCE","stopLocalServiceDiscovery","stopLocationUpdate","stopPullDownRefresh","stopRecord","stopVoice","stopWifi","subscribeVoIPVideoMembers","switchTab","textReview","textToAudio","updateShareMenu","updateVoIPChatMuteConfig","updateWeChatApp","uploadFile","vibrateLong","vibrateShort","writeBLECharacteristicValue"])
1
+ module.exports = new Set(["addCard","addFileToFavorites","addInterceptor","addPhoneCalendar","addPhoneContact","addPhoneRepeatCalendar","addVideoToFavorites","advancedGeneralIdentify","animalClassify","arrayBufferToBase64","authPrivateMessage","authorize","authorizeForMiniProgram","base64ToArrayBuffer","canIUse","canvasGetImageData","canvasPutImageData","canvasToTempFilePath","carClassify","checkIsOpenAccessibility","checkIsSoterEnrolledInDevice","checkIsSupportFacialRecognition","checkIsSupportSoterAuthentication","checkSession","chooseAddress","chooseContact","chooseImage","chooseInvoice","chooseInvoiceTitle","chooseLicensePlate","chooseLocation","chooseMedia","chooseMessageFile","choosePoi","chooseVideo","clearStorage","clearStorageSync","closeBLEConnection","closeBluetoothAdapter","closeSocket","cloud","compressImage","compressVideo","connectSocket","connectWifi","createAnimation","createAudioContext","createBLEConnection","createBLEPeripheralServer","createBufferURL","createCameraContext","createCanvasContext","createInnerAudioContext","createIntersectionObserver","createInterstitialAd","createLivePlayerContext","createLivePusherContext","createMapContext","createMediaAudioPlayer","createMediaContainer","createMediaRecorder","createOffscreenCanvas","createRewardedVideoAd","createSelectorQuery","createTCPSocket","createUDPSocket","createVKSession","createVideoContext","createVideoDecoder","createWebAudioContext","createWorker","disableAlertBeforeUnload","dishClassify","downloadFile","enableAlertBeforeUnload","exitMiniProgram","exitVoIPChat","faceDetect","faceVerifyForPay","getAccountInfoSync","getApp","getAppAuthorizeSetting","getAppBaseInfo","getAvailableAudioSources","getBLEDeviceCharacteristics","getBLEDeviceRSSI","getBLEDeviceServices","getBLEMTU","getBackgroundAudioManager","getBackgroundAudioPlayerState","getBackgroundFetchData","getBackgroundFetchToken","getBatteryInfo","getBatteryInfoSync","getBeacons","getBluetoothAdapterState","getBluetoothDevices","getChannelsLiveInfo","getChannelsLiveNoticeInfo","getClipboardData","getConnectedBluetoothDevices","getConnectedWifi","getCurrentInstance","getCurrentPages","getDeviceInfo","getEnterOptionsSync","getExptInfoSync","getExtConfig","getExtConfigSync","getFileInfo","getFileSystemManager","getGroupEnterInfo","getHCEState","getImageInfo","getLaunchOptionsSync","getLocalIPAddress","getLocation","getLogManager","getMenuButtonBoundingClientRect","getNFCAdapter","getNetworkType","getOpenUserInfo","getPerformance","getRandomValues","getRealtimeLogManager","getRecorderManager","getSavedFileInfo","getSavedFileList","getScreenBrightness","getSelectedTextRange","getSetting","getShareInfo","getStorage","getStorageInfo","getStorageInfoSync","getStorageSync","getSwanId","getSystemInfo","getSystemInfoAsync","getSystemInfoSync","getSystemSetting","getUpdateManager","getUserCryptoManager","getUserInfo","getUserProfile","getVideoInfo","getWeRunData","getWifiList","getWindowInfo","hideHomeButton","hideKeyboard","hideLoading","hideNavigationBarLoading","hideShareMenu","hideTabBar","hideTabBarRedDot","hideToast","imageAudit","initFaceDetect","initTabBarApis","isBluetoothDevicePaired","isVKSupport","joinVoIPChat","loadFontFace","login","logoClassify","makeBluetoothPair","makePhoneCall","navigateBack","navigateBackMiniProgram","navigateBackSmartProgram","navigateTo","navigateToMiniProgram","navigateToSmartGameProgram","navigateToSmartProgram","nextTick","notifyBLECharacteristicValueChange","objectDetectIdentify","ocrBankCard","ocrDrivingLicense","ocrIdCard","ocrVehicleLicense","offAccelerometerChange","offAppHide","offAppShow","offAudioInterruptionBegin","offAudioInterruptionEnd","offBLECharacteristicValueChange","offBLEConnectionStateChange","offBLEMTUChange","offBLEPeripheralConnectionStateChanged","offBeaconServiceChange","offBeaconUpdate","offBluetoothAdapterStateChange","offBluetoothDeviceFound","offCompassChange","offCopyUrl","offDeviceMotionChange","offError","offGetWifiList","offGyroscopeChange","offHCEMessage","offKeyboardHeightChange","offLocalServiceDiscoveryStop","offLocalServiceFound","offLocalServiceLost","offLocalServiceResolveFail","offLocationChange","offLocationChangeError","offMemoryWarning","offNetworkStatusChange","offNetworkWeakChange","offPageNotFound","offThemeChange","offUnhandledRejection","offUserCaptureScreen","offVoIPChatInterrupted","offVoIPChatMembersChanged","offVoIPChatStateChanged","offVoIPVideoMembersChanged","offWifiConnected","offWindowResize","onAccelerometerChange","onAppHide","onAppShow","onAudioInterruptionBegin","onAudioInterruptionEnd","onBLECharacteristicValueChange","onBLEConnectionStateChange","onBLEMTUChange","onBLEPeripheralConnectionStateChanged","onBackgroundAudioPause","onBackgroundAudioPlay","onBackgroundAudioStop","onBackgroundFetchData","onBeaconServiceChange","onBeaconUpdate","onBluetoothAdapterStateChange","onBluetoothDeviceFound","onCompassChange","onCopyUrl","onDeviceMotionChange","onError","onGetWifiList","onGyroscopeChange","onHCEMessage","onKeyboardHeightChange","onLocalServiceDiscoveryStop","onLocalServiceFound","onLocalServiceLost","onLocalServiceResolveFail","onLocationChange","onLocationChangeError","onMemoryWarning","onNetworkStatusChange","onNetworkWeakChange","onPageNotFound","onSocketClose","onSocketError","onSocketMessage","onSocketOpen","onThemeChange","onUnhandledRejection","onUserCaptureScreen","onVoIPChatInterrupted","onVoIPChatMembersChanged","onVoIPChatSpeakersChanged","onVoIPChatStateChanged","onVoIPVideoMembersChanged","onWifiConnected","onWifiConnectedWithPartialInfo","onWindowResize","openAppAuthorizeSetting","openBluetoothAdapter","openCard","openChannelsActivity","openChannelsEvent","openChannelsLive","openCustomerServiceChat","openDocument","openEmbeddedMiniProgram","openLocation","openSetting","openSystemBluetoothSetting","openVideoEditor","pageScrollTo","pauseBackgroundAudio","pauseVoice","plantClassify","playBackgroundAudio","playVoice","pluginLogin","preloadSubPackage","previewImage","previewMedia","reLaunch","readBLECharacteristicValue","redirectTo","removeSavedFile","removeStorage","removeStorageSync","removeTabBarBadge","reportAnalytics","reportEvent","reportMonitor","reportPerformance","request","requestOrderPayment","requestPayment","requestPolymerPayment","requestSubscribeMessage","reserveChannelsLive","revokeBufferURL","saveFile","saveFileToDisk","saveImageToPhotosAlbum","saveVideoToPhotosAlbum","scanCode","seekBackgroundAudio","sendHCEMessage","sendSocketMessage","setBLEMTU","setBackgroundColor","setBackgroundFetchToken","setBackgroundTextStyle","setClipboardData","setEnable1v1Chat","setEnableDebug","setInnerAudioOption","setKeepScreenOn","setNavigationBarColor","setNavigationBarTitle","setPageInfo","setScreenBrightness","setStorage","setStorageSync","setTabBarBadge","setTabBarItem","setTabBarStyle","setTopBarText","setVisualEffectOnCapture","setWifiList","setWindowSize","shareFileMessage","shareToWeRun","shareVideoMessage","showActionSheet","showLoading","showModal","showNavigationBarLoading","showRedPackage","showShareImageMenu","showShareMenu","showTabBar","showTabBarRedDot","showToast","startAccelerometer","startBeaconDiscovery","startBluetoothDevicesDiscovery","startCompass","startDeviceMotionListening","startFacialRecognitionVerify","startFacialRecognitionVerifyAndUploadVideo","startGyroscope","startHCE","startLocalServiceDiscovery","startLocationUpdate","startLocationUpdateBackground","startPullDownRefresh","startRecord","startSoterAuthentication","startWifi","stopAccelerometer","stopBackgroundAudio","stopBeaconDiscovery","stopBluetoothDevicesDiscovery","stopCompass","stopDeviceMotionListening","stopFaceDetect","stopGyroscope","stopHCE","stopLocalServiceDiscovery","stopLocationUpdate","stopPullDownRefresh","stopRecord","stopVoice","stopWifi","subscribeVoIPVideoMembers","switchTab","textReview","textToAudio","updateShareMenu","updateVoIPChatMuteConfig","updateWeChatApp","uploadFile","vibrateLong","vibrateShort","writeBLECharacteristicValue"])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/taro-h5",
3
- "version": "3.4.0",
3
+ "version": "3.4.3",
4
4
  "description": "Taro h5 framework",
5
5
  "main:h5": "dist/index.js",
6
6
  "main": "dist/index.cjs.js",
@@ -17,7 +17,7 @@
17
17
  "test:dev": "jest --watch",
18
18
  "test:coverage": "jest --coverage",
19
19
  "copy:assets": "copy src/**/*.css dist",
20
- "build": "tsc & rollup -c & npm run copy:assets",
20
+ "build": "rollup -c && npm run copy:assets && tsc",
21
21
  "dev": "tsc -w & npm run copy:assets"
22
22
  },
23
23
  "repository": {
@@ -30,14 +30,14 @@
30
30
  "author": "O2Team",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@tarojs/api": "3.4.0",
34
- "@tarojs/router": "3.4.0",
35
- "@tarojs/runtime": "3.4.0",
36
- "@tarojs/taro": "3.4.0",
33
+ "@tarojs/api": "3.4.3",
34
+ "@tarojs/router": "3.4.3",
35
+ "@tarojs/runtime": "3.4.3",
36
+ "@tarojs/taro": "3.4.3",
37
37
  "base64-js": "^1.3.0",
38
38
  "jsonp-retry": "^1.0.3",
39
39
  "mobile-detect": "^1.4.2",
40
40
  "whatwg-fetch": "^3.4.0"
41
41
  },
42
- "gitHead": "a0e97bc937f878cc059f54748c9a3829fa3f4664"
42
+ "gitHead": "de55da7a845e9c09ba65528e74c7310e5082c2d5"
43
43
  }
@@ -1,4 +1,7 @@
1
1
  import { temporarilyNotSupport } from '../utils'
2
2
 
3
+ // 判断支持版本
4
+ export const isVKSupport = temporarilyNotSupport('isVKSupport')
5
+
3
6
  // 视觉算法
4
7
  export const createVKSession = temporarilyNotSupport('createVKSession')
@@ -0,0 +1,207 @@
1
+ import Taro from '@tarojs/api'
2
+ import MobileDetect from 'mobile-detect'
3
+
4
+ import { temporarilyNotSupport } from '../utils'
5
+ import { MethodHandler } from '../utils/handler'
6
+
7
+ /** 跳转系统蓝牙设置页 */
8
+ export const openSystemBluetoothSetting = temporarilyNotSupport('openSystemBluetoothSetting')
9
+
10
+ /** 跳转系统微信授权管理页 */
11
+ export const openAppAuthorizeSetting = temporarilyNotSupport('openAppAuthorizeSetting')
12
+
13
+ /** 获取窗口信息 */
14
+ export const getWindowInfo: typeof Taro.getWindowInfo = () => {
15
+ const info: ReturnType<typeof Taro.getWindowInfo> = {
16
+ /** 设备像素比 */
17
+ pixelRatio: window.devicePixelRatio,
18
+ /** 屏幕宽度,单位px */
19
+ screenWidth: window.screen.width,
20
+ /** 屏幕高度,单位px */
21
+ screenHeight: window.screen.height,
22
+ /** 可使用窗口宽度,单位px */
23
+ windowWidth: document.documentElement.clientWidth,
24
+ /** 可使用窗口高度,单位px */
25
+ windowHeight: document.documentElement.clientHeight,
26
+ /** 状态栏的高度,单位px */
27
+ statusBarHeight: NaN,
28
+ /** 在竖屏正方向下的安全区域 */
29
+ safeArea: {
30
+ bottom: 0,
31
+ height: 0,
32
+ left: 0,
33
+ right: 0,
34
+ top: 0,
35
+ width: 0
36
+ }
37
+ }
38
+
39
+ return info
40
+ }
41
+
42
+ /** 获取设备设置 */
43
+ export const getSystemSetting: typeof Taro.getSystemSetting = () => {
44
+ const isLandscape = window.screen.width >= window.screen.height
45
+ const info: ReturnType<typeof Taro.getSystemSetting> = {
46
+ /** 蓝牙的系统开关 */
47
+ bluetoothEnabled: false,
48
+ /** 地理位置的系统开关 */
49
+ locationEnabled: false,
50
+ /** Wi-Fi 的系统开关 */
51
+ wifiEnabled: false,
52
+ /** 设备方向 */
53
+ deviceOrientation: isLandscape ? 'landscape' : 'portrait'
54
+ }
55
+
56
+ return info
57
+ }
58
+
59
+ /** 获取设备设置 */
60
+ export const getDeviceInfo: typeof Taro.getDeviceInfo = () => {
61
+ const md = new MobileDetect(navigator.userAgent)
62
+
63
+ const info: ReturnType<typeof Taro.getDeviceInfo> = {
64
+ /** 应用二进制接口类型(仅 Android 支持) */
65
+ abi: '',
66
+ /** 设备性能等级(仅Android小游戏)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好,目前最高不到50) */
67
+ benchmarkLevel: -1,
68
+ /** 设备品牌 */
69
+ brand: md.mobile() || '',
70
+ /** 设备型号 */
71
+ model: md.mobile() || '',
72
+ /** 操作系统及版本 */
73
+ system: md.os(),
74
+ /** 客户端平台 */
75
+ platform: navigator.platform
76
+ }
77
+
78
+ return info
79
+ }
80
+
81
+ /** 获取微信APP基础信息 */
82
+ export const getAppBaseInfo: typeof Taro.getAppBaseInfo = () => {
83
+ let isDarkMode = false
84
+ if (window.matchMedia?.('(prefers-color-scheme: dark)').matches) {
85
+ isDarkMode = true
86
+ }
87
+
88
+ const info: ReturnType<typeof Taro.getAppBaseInfo> = {
89
+ /** 客户端基础库版本 */
90
+ SDKVersion: '',
91
+ /** 是否已打开调试。可通过右上角菜单或 [Taro.setEnableDebug](/docs/apis/base/debug/setEnableDebug) 打开调试。 */
92
+ enableDebug: process.env.NODE_ENV === 'development',
93
+ /** 当前小程序运行的宿主环境 */
94
+ // host: { appId: '' },
95
+ /** 微信设置的语言 */
96
+ language: navigator.language,
97
+ /** 微信版本号 */
98
+ version: '',
99
+ /** 系统当前主题,取值为light或dark,全局配置"darkmode":true时才能获取,否则为 undefined (不支持小游戏) */
100
+ theme: isDarkMode ? 'dark' : 'light'
101
+ }
102
+
103
+ return info
104
+ }
105
+
106
+ /** 获取微信APP授权设置 */
107
+ export const getAppAuthorizeSetting: typeof Taro.getAppAuthorizeSetting = () => {
108
+ const info: ReturnType<typeof Taro.getAppAuthorizeSetting> = {
109
+ /** 允许微信使用相册的开关(仅 iOS 有效) */
110
+ albumAuthorized: 'not determined',
111
+ /** 允许微信使用蓝牙的开关(仅 iOS 有效) */
112
+ bluetoothAuthorized: 'not determined',
113
+ /** 允许微信使用摄像头的开关 */
114
+ cameraAuthorized: 'not determined',
115
+ /** 允许微信使用定位的开关 */
116
+ locationAuthorized: 'not determined',
117
+ /** 定位准确度。true 表示模糊定位,false 表示精确定位(仅 iOS 有效) */
118
+ locationReducedAccuracy: false,
119
+ /** 允许微信使用麦克风的开关 */
120
+ microphoneAuthorized: 'not determined',
121
+ /** 允许微信通知的开关 */
122
+ notificationAuthorized: 'not determined',
123
+ /** 允许微信通知带有提醒的开关(仅 iOS 有效) */
124
+ notificationAlertAuthorized: 'not determined',
125
+ /** 允许微信通知带有标记的开关(仅 iOS 有效) */
126
+ notificationBadgeAuthorized: 'not determined',
127
+ /** 允许微信通知带有声音的开关(仅 iOS 有效) */
128
+ notificationSoundAuthorized: 'not determined',
129
+ /** 允许微信使用日历的开关 */
130
+ phoneCalendarAuthorized: 'not determined'
131
+ }
132
+
133
+ return info
134
+ }
135
+
136
+ /** 获取设备设置 */
137
+ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = () => {
138
+ const windowInfo = getWindowInfo()
139
+ const systemSetting = getSystemSetting()
140
+ const deviceInfo: Taro.getDeviceInfo.Result = getDeviceInfo()
141
+ const appBaseInfo = getAppBaseInfo()
142
+ const appAuthorizeSetting = getAppAuthorizeSetting()
143
+ delete deviceInfo.abi
144
+
145
+ const info: ReturnType<typeof Taro.getSystemInfoSync> = {
146
+ ...windowInfo,
147
+ ...systemSetting,
148
+ ...deviceInfo,
149
+ ...appBaseInfo,
150
+ /** 用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准 */
151
+ fontSizeSetting: NaN,
152
+ /** 允许微信使用相册的开关(仅 iOS 有效) */
153
+ albumAuthorized: appAuthorizeSetting.albumAuthorized === 'authorized',
154
+ /** 允许微信使用摄像头的开关 */
155
+ cameraAuthorized: appAuthorizeSetting.cameraAuthorized === 'authorized',
156
+ /** 允许微信使用定位的开关 */
157
+ locationAuthorized: appAuthorizeSetting.locationAuthorized === 'authorized',
158
+ /** 允许微信使用麦克风的开关 */
159
+ microphoneAuthorized: appAuthorizeSetting.microphoneAuthorized === 'authorized',
160
+ /** 允许微信通知的开关 */
161
+ notificationAuthorized: appAuthorizeSetting.notificationAuthorized === 'authorized',
162
+ /** 允许微信通知带有提醒的开关(仅 iOS 有效) */
163
+ notificationAlertAuthorized: appAuthorizeSetting.notificationAlertAuthorized === 'authorized',
164
+ /** 允许微信通知带有标记的开关(仅 iOS 有效) */
165
+ notificationBadgeAuthorized: appAuthorizeSetting.notificationBadgeAuthorized === 'authorized',
166
+ /** 允许微信通知带有声音的开关(仅 iOS 有效) */
167
+ notificationSoundAuthorized: appAuthorizeSetting.notificationSoundAuthorized === 'authorized',
168
+ /** 允许微信使用日历的开关 */
169
+ phoneCalendarAuthorized: appAuthorizeSetting.phoneCalendarAuthorized === 'authorized',
170
+ /** `true` 表示模糊定位,`false` 表示精确定位,仅 iOS 支持 */
171
+ locationReducedAccuracy: appAuthorizeSetting.locationReducedAccuracy,
172
+ /** 小程序当前运行环境 */
173
+ environment: ''
174
+ }
175
+
176
+ return info
177
+ }
178
+
179
+ /** 获取系统信息 */
180
+ export const getSystemInfoAsync: typeof Taro.getSystemInfoAsync = async (options = {}) => {
181
+ const { success, fail, complete } = options
182
+ const handle = new MethodHandler({ name: 'getSystemInfoAsync', success, fail, complete })
183
+
184
+ try {
185
+ const info = await getSystemInfoSync()
186
+ return handle.success(info)
187
+ } catch (error) {
188
+ return handle.fail({
189
+ errMsg: error
190
+ })
191
+ }
192
+ }
193
+
194
+ /** 获取系统信息 */
195
+ export const getSystemInfo: typeof Taro.getSystemInfo = async (options = {}) => {
196
+ const { success, fail, complete } = options
197
+ const handle = new MethodHandler({ name: 'getSystemInfo', success, fail, complete })
198
+
199
+ try {
200
+ const info = await getSystemInfoSync()
201
+ return handle.success(info)
202
+ } catch (error) {
203
+ return handle.fail({
204
+ errMsg: error
205
+ })
206
+ }
207
+ }
@@ -5,7 +5,7 @@ interface IAction {
5
5
  args: any[]
6
6
  }
7
7
 
8
- const TextBaseLineMap: Record<keyof Taro.CanvasContext.textBaseline, CanvasTextBaseline> = {
8
+ const TextBaseLineMap: Record<keyof Taro.CanvasContext.TextBaseline, CanvasTextBaseline> = {
9
9
  top: 'top',
10
10
  bottom: 'bottom',
11
11
  middle: 'middle',
@@ -93,7 +93,7 @@ export class CanvasContext implements Taro.CanvasContext {
93
93
  clip (...args) { return this.enqueueActions(this.ctx.clip, ...args) }
94
94
  closePath (...args) { return this.enqueueActions(this.ctx.closePath, ...args) }
95
95
 
96
- createPattern (image: string, repetition: keyof Taro.CanvasContext.repetition): void {
96
+ createPattern (image: string, repetition: keyof Taro.CanvasContext.Repetition): void {
97
97
  return this.createPattern(image, repetition)
98
98
  }
99
99
 
@@ -166,7 +166,7 @@ export class CanvasContext implements Taro.CanvasContext {
166
166
  this.globalAlpha = alpha
167
167
  }
168
168
 
169
- setLineCap (lineCap: keyof Taro.CanvasContext.lineCap): void {
169
+ setLineCap (lineCap: keyof Taro.CanvasContext.LineCap): void {
170
170
  this.lineCap = lineCap
171
171
  }
172
172
 
@@ -177,7 +177,7 @@ export class CanvasContext implements Taro.CanvasContext {
177
177
  })
178
178
  }
179
179
 
180
- setLineJoin (lineJoin: keyof Taro.CanvasContext.lineJoin): void {
180
+ setLineJoin (lineJoin: keyof Taro.CanvasContext.LineJoin): void {
181
181
  this.lineJoin = lineJoin
182
182
  }
183
183
 
@@ -202,11 +202,11 @@ export class CanvasContext implements Taro.CanvasContext {
202
202
  this.enqueueActions(() => { this.ctx.strokeStyle = color })
203
203
  }
204
204
 
205
- setTextAlign (align: keyof Taro.CanvasContext.align): void {
205
+ setTextAlign (align: keyof Taro.CanvasContext.Align): void {
206
206
  this.textAlign = align
207
207
  }
208
208
 
209
- setTextBaseline (textBaseline: keyof Taro.CanvasContext.textBaseline): void {
209
+ setTextBaseline (textBaseline: keyof Taro.CanvasContext.TextBaseline): void {
210
210
  this.textBaseline = TextBaseLineMap[textBaseline] || 'alphabetic'
211
211
  }
212
212
 
@@ -218,7 +218,7 @@ export class CanvasContext implements Taro.CanvasContext {
218
218
  translate (...args) { return this.enqueueActions(this.ctx.translate, ...args) }
219
219
 
220
220
  measureText (text: string): TextMetrics {
221
- return this.measureText(text)
221
+ return this.ctx.measureText(text)
222
222
  }
223
223
 
224
224
  createCircularGradient (x: number, y: number, r: number): CanvasGradient {
@@ -1,10 +1,18 @@
1
1
  import { temporarilyNotSupport } from '../utils'
2
2
 
3
3
  // 画布
4
+
5
+ /** 创建离屏 canvas 实例 */
4
6
  export const createOffscreenCanvas = temporarilyNotSupport('createOffscreenCanvas')
7
+
8
+ /** 创建 canvas 的绘图上下文 CanvasContext 对象 */
5
9
  export * from './createCanvasContext'
10
+
11
+ /** 把当前画布指定区域的内容导出生成指定大小的图片 */
6
12
  export * from './canvasToTempFilePath'
13
+
14
+ /** 将像素数据绘制到画布 */
7
15
  export * from './canvasPutImageData'
8
- export * from './canvasGetImageData'
9
16
 
10
- export const drawCanvas = temporarilyNotSupport('drawCanvas')
17
+ /** 获取 canvas 区域隐含的像素数据 */
18
+ export * from './canvasGetImageData'
@@ -8,6 +8,7 @@ export class cloud implements Taro.cloud {
8
8
 
9
9
  CloudID = temporarilyNotSupport('cloud.CloudID')
10
10
 
11
+ // @ts-ignore
11
12
  callFunction = temporarilyNotSupport('cloud.callFunction')
12
13
 
13
14
  // @ts-ignore
@@ -16,12 +17,15 @@ export class cloud implements Taro.cloud {
16
17
  // @ts-ignore
17
18
  downloadFile = temporarilyNotSupport('cloud.downloadFile')
18
19
 
20
+ // @ts-ignore
19
21
  getTempFileURL = temporarilyNotSupport('cloud.getTempFileURL')
20
22
 
23
+ // @ts-ignore
21
24
  deleteFile = temporarilyNotSupport('cloud.deleteFile')
22
25
 
23
26
  // @ts-ignore
24
27
  database = temporarilyNotSupport('cloud.database')
25
28
 
29
+ // @ts-ignore
26
30
  callContainer = temporarilyNotSupport('cloud.callContainer')
27
31
  }
@@ -1,5 +1,22 @@
1
+ import Taro from '@tarojs/api'
1
2
  import { temporarilyNotSupport } from '../utils'
3
+ import { MethodHandler } from '../utils/handler'
2
4
 
3
5
  // 电量
4
6
  export const getBatteryInfoSync = temporarilyNotSupport('getBatteryInfoSync')
5
- export const getBatteryInfo = temporarilyNotSupport('getBatteryInfo')
7
+
8
+ export const getBatteryInfo: typeof Taro.getBatteryInfo = async ({ success, fail, complete } = {}) => {
9
+ const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete })
10
+ try {
11
+ // @ts-ignore
12
+ const battery = await navigator.getBattery?.()
13
+ return handle.success({
14
+ isCharging: battery.charging,
15
+ level: Number(battery.level || 0) * 100
16
+ })
17
+ } catch (error) {
18
+ return handle.fail({
19
+ errMsg: error?.message || error
20
+ })
21
+ }
22
+ }
@@ -14,6 +14,7 @@ export * from './iBeacon'
14
14
  export * from './keyboard'
15
15
  export * from './memory'
16
16
  export * from './motion'
17
+ export * from './network'
17
18
  export * from './nfc'
18
19
  export * from './phone'
19
20
  export * from './scan'
@@ -1,7 +1,7 @@
1
1
  import Taro from '@tarojs/api'
2
2
 
3
- import { MethodHandler } from '../../utils/handler'
4
- import { temporarilyNotSupport } from '../../utils'
3
+ import { CallbackManager, MethodHandler } from '../utils/handler'
4
+ import { temporarilyNotSupport } from '../utils'
5
5
 
6
6
  function getConnection () {
7
7
  // @ts-ignore
@@ -13,7 +13,7 @@ export const getNetworkType: typeof Taro.getNetworkType = (options = {}) => {
13
13
  const { success, fail, complete } = options
14
14
  const handle = new MethodHandler<Taro.getNetworkType.SuccessCallbackResult>({ name: 'getNetworkType', success, fail, complete })
15
15
 
16
- let networkType: keyof Taro.getNetworkType.networkType = 'unknown'
16
+ let networkType: keyof Taro.getNetworkType.NetworkType = 'unknown'
17
17
  // 浏览器不支持获取网络状态
18
18
  if (!connection) {
19
19
  return handle.success({ networkType })
@@ -51,20 +51,40 @@ export const getNetworkType: typeof Taro.getNetworkType = (options = {}) => {
51
51
  return handle.success({ networkType })
52
52
  }
53
53
 
54
- export const onNetworkStatusChange: typeof Taro.onNetworkStatusChange = (cb) => {
54
+ const networkStatusManager = new CallbackManager()
55
+
56
+ const networkStatusListener = async () => {
57
+ const { networkType } = await getNetworkType()
58
+ const isConnected = networkType !== 'none'
59
+ const obj = { isConnected, networkType }
60
+ networkStatusManager.trigger(obj)
61
+ }
62
+
63
+ /**
64
+ * 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。
65
+ * - 出现三次以上连接超时
66
+ * - 出现三次 rtt 超过 400
67
+ * - 出现三次以上的丢包
68
+ * > 弱网事件通知规则是: 弱网状态变化时立即通知, 状态不变时 30s 内最多通知一次。
69
+ */
70
+ export const onNetworkWeakChange = temporarilyNotSupport('onNetworkWeakChange')
71
+
72
+ export const onNetworkStatusChange: typeof Taro.onNetworkStatusChange = callback => {
73
+ networkStatusManager.add(callback)
74
+ const connection = getConnection()
75
+ if (connection && networkStatusManager.count() === 1) {
76
+ connection.addEventListener('change', networkStatusListener)
77
+ }
78
+ }
79
+
80
+ export const offNetworkWeakChange = temporarilyNotSupport('offNetworkStatusChange')
81
+
82
+ export const offNetworkStatusChange: typeof Taro.offNetworkStatusChange = callback => {
83
+ networkStatusManager.remove(callback)
55
84
  const connection = getConnection()
56
- if (connection) {
57
- connection.addEventListener('change', function () {
58
- getNetworkType()
59
- .then(res => {
60
- const { networkType } = res
61
- const isConnected = networkType !== 'none'
62
- const obj = { isConnected, networkType }
63
- cb(obj)
64
- })
65
- })
85
+ if (connection && networkStatusManager.count() === 0) {
86
+ connection.removeEventListener('change', networkStatusListener)
66
87
  }
67
88
  }
68
89
 
69
- export const offNetworkStatusChange = temporarilyNotSupport('offNetworkStatusChange')
70
90
  export const getLocalIPAddress = temporarilyNotSupport('getLocalIPAddress')
@@ -4,6 +4,7 @@ import { temporarilyNotSupport } from '../utils'
4
4
  export const stopWifi = temporarilyNotSupport('stopWifi')
5
5
  export const startWifi = temporarilyNotSupport('startWifi')
6
6
  export const setWifiList = temporarilyNotSupport('setWifiList')
7
+ export const onWifiConnectedWithPartialInfo = temporarilyNotSupport('onWifiConnectedWithPartialInfo')
7
8
  export const onWifiConnected = temporarilyNotSupport('onWifiConnected')
8
9
  export const onGetWifiList = temporarilyNotSupport('onGetWifiList')
9
10
  export const offWifiConnected = temporarilyNotSupport('offWifiConnected')
@@ -11,6 +11,8 @@ export class EditorContext implements Taro.EditorContext {
11
11
 
12
12
  getContents = temporarilyNotSupport('EditorContext.getContents')
13
13
 
14
+ getSelectionText = temporarilyNotSupport('EditorContext.getSelectionText')
15
+
14
16
  insertDivider = temporarilyNotSupport('EditorContext.insertDivider')
15
17
 
16
18
  insertImage = temporarilyNotSupport('EditorContext.insertImage')
@@ -0,0 +1,98 @@
1
+ import Taro from '@tarojs/api'
2
+ import { permanentlyNotSupport } from '../../utils'
3
+ import { CallbackManager } from '../../utils/handler'
4
+
5
+ export class InnerAudioContext implements Taro.InnerAudioContext {
6
+ Instance?: HTMLAudioElement
7
+ errorStack: CallbackManager
8
+ stopStack: CallbackManager
9
+ __startTime = 0
10
+
11
+ constructor () {
12
+ this.Instance = new Audio()
13
+ this.errorStack = new CallbackManager()
14
+ this.stopStack = new CallbackManager()
15
+
16
+ Taro.eventCenter.on('__taroRouterChange', () => { this.stop() })
17
+ this.onPlay(() => {
18
+ if (this.currentTime !== this.startTime) {
19
+ this.seek(this.startTime)
20
+ }
21
+ })
22
+ }
23
+
24
+ set autoplay (e) { this.setProperty('autoplay', e) }
25
+ get autoplay () { return this.Instance?.autoplay || false }
26
+ get buffered () { return this.Instance?.buffered.length || 0 }
27
+ get currentTime () { return this.Instance?.currentTime || 0 }
28
+ get duration () { return this.Instance?.duration || 0 }
29
+ set loop (e) { this.setProperty('loop', e) }
30
+ get loop () { return this.Instance?.loop || false }
31
+ get paused () { return this.Instance?.paused || true }
32
+ set src (e) { this.setProperty('src', e) }
33
+ get src () { return this.Instance?.src || '' }
34
+ set volume (e) { this.setProperty('volume', e) }
35
+ get volume () { return this.Instance?.volume || 0 }
36
+ set playbackRate (e) { this.setProperty('playbackRate', e) }
37
+ get playbackRate () { return this.Instance?.playbackRate || 0 }
38
+ set obeyMuteSwitch (_e) { permanentlyNotSupport('InnerAudioContext.obeyMuteSwitch')() }
39
+ get obeyMuteSwitch () { return true }
40
+ set startTime (e) { this.__startTime = e }
41
+ get startTime () { return this.__startTime || 0 }
42
+ set referrerPolicy (e) { this.Instance?.setAttribute('referrerpolicy', e) }
43
+ get referrerPolicy () { return this.Instance?.getAttribute('referrerpolicy') || 'origin' }
44
+
45
+ private setProperty (key: string, value: unknown) {
46
+ if (this.Instance) {
47
+ this.Instance[key] = value
48
+ }
49
+ }
50
+
51
+ play = () => this.Instance?.play()
52
+
53
+ pause = () => this.Instance?.pause()
54
+
55
+ stop = () => {
56
+ this.pause()
57
+ this.seek(0)
58
+ this.stopStack.trigger()
59
+ }
60
+
61
+ seek = (position: number) => {
62
+ if (this.Instance) {
63
+ this.Instance.currentTime = position
64
+ }
65
+ }
66
+
67
+ /**
68
+ * @TODO destroy得并不干净
69
+ */
70
+ destroy = () => {
71
+ this.stop()
72
+ if (this.Instance) {
73
+ document.body.removeChild(this.Instance)
74
+ this.Instance = undefined
75
+ }
76
+ }
77
+
78
+ onCanplay = (callback = () => {}) => this.Instance?.addEventListener('canplay', callback)
79
+ onPlay = (callback = () => {}) => this.Instance?.addEventListener('play', callback)
80
+ onPause = (callback = () => {}) => this.Instance?.addEventListener('pause', callback)
81
+ onStop = (callback = () => {}) => this.stopStack.add(callback)
82
+ onEnded = (callback = () => {}) => this.Instance?.addEventListener('ended', callback)
83
+ onTimeUpdate = (callback = () => {}) => this.Instance?.addEventListener('timeupdate', callback)
84
+ onError = (callback?: ((res: Taro.InnerAudioContext.onErrorDetail) => void)) => this.errorStack.add(callback)
85
+ onWaiting = (callback = () => {}) => this.Instance?.addEventListener('waiting', callback)
86
+ onSeeking = (callback = () => {}) => this.Instance?.addEventListener('seeking', callback)
87
+ onSeeked = (callback = () => {}) => this.Instance?.addEventListener('seeked', callback)
88
+ offCanplay = (callback = () => {}) => this.Instance?.removeEventListener('canplay', callback)
89
+ offPlay = (callback = () => {}) => this.Instance?.removeEventListener('play', callback)
90
+ offPause = (callback = () => {}) => this.Instance?.removeEventListener('pause', callback)
91
+ offStop = (callback = () => {}) => this.stopStack.remove(callback)
92
+ offEnded = (callback = () => {}) => this.Instance?.removeEventListener('ended', callback)
93
+ offTimeUpdate = (callback = () => {}) => this.Instance?.removeEventListener('timeupdate', callback)
94
+ offError = (callback = () => {}) => this.errorStack.remove(callback)
95
+ offWaiting = (callback = () => {}) => this.Instance?.removeEventListener('waiting', callback)
96
+ offSeeking = (callback = () => {}) => this.Instance?.removeEventListener('seeking', callback)
97
+ offSeeked = (callback = () => {}) => this.Instance?.removeEventListener('seeked', callback)
98
+ }