@tarojs/taro-h5 3.4.1 → 3.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/ai/visual.js +2 -0
- package/dist/api/base/system.js +187 -0
- package/dist/api/canvas/index.js +5 -1
- package/dist/api/device/battery.js +18 -1
- package/dist/api/device/index.js +1 -0
- package/dist/api/{base/system → device}/network.js +29 -14
- package/dist/api/device/wifi.js +1 -0
- package/dist/api/media/EditorContext.js +1 -0
- package/dist/api/network/upload.js +1 -6
- package/dist/api/ui/fonts.js +50 -2
- package/dist/api/utils/handler.js +45 -45
- package/dist/index.cjs.js +359 -141
- package/dist/taroApis.js +1 -1
- package/package.json +6 -6
- package/src/api/ai/visual.ts +3 -0
- package/src/api/base/system.ts +207 -0
- package/src/api/canvas/CanvasContext.ts +6 -6
- package/src/api/canvas/index.ts +10 -2
- package/src/api/device/battery.ts +18 -1
- package/src/api/device/index.ts +1 -0
- package/src/api/{base/system → device}/network.ts +35 -15
- package/src/api/device/wifi.ts +1 -0
- package/src/api/media/EditorContext.ts +2 -0
- package/src/api/network/upload.ts +1 -7
- package/src/api/ui/fonts.ts +61 -2
- package/src/api/utils/handler.ts +4 -4
- package/dist/api/base/system/index.js +0 -2
- package/dist/api/base/system/info.js +0 -57
- package/src/api/base/system/index.ts +0 -2
- package/src/api/base/system/info.ts +0 -64
package/dist/taroApis.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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","
|
|
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.
|
|
3
|
+
"version": "3.4.4",
|
|
4
4
|
"description": "Taro h5 framework",
|
|
5
5
|
"main:h5": "dist/index.js",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"author": "O2Team",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@tarojs/api": "3.4.
|
|
34
|
-
"@tarojs/router": "3.4.
|
|
35
|
-
"@tarojs/runtime": "3.4.
|
|
36
|
-
"@tarojs/taro": "3.4.
|
|
33
|
+
"@tarojs/api": "3.4.4",
|
|
34
|
+
"@tarojs/router": "3.4.4",
|
|
35
|
+
"@tarojs/runtime": "3.4.4",
|
|
36
|
+
"@tarojs/taro": "3.4.4",
|
|
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": "
|
|
42
|
+
"gitHead": "099d062d74faa3f124ca2499de1154fae0adc4f9"
|
|
43
43
|
}
|
package/src/api/ai/visual.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
205
|
+
setTextAlign (align: keyof Taro.CanvasContext.Align): void {
|
|
206
206
|
this.textAlign = align
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
setTextBaseline (textBaseline: keyof Taro.CanvasContext.
|
|
209
|
+
setTextBaseline (textBaseline: keyof Taro.CanvasContext.TextBaseline): void {
|
|
210
210
|
this.textBaseline = TextBaseLineMap[textBaseline] || 'alphabetic'
|
|
211
211
|
}
|
|
212
212
|
|
package/src/api/canvas/index.ts
CHANGED
|
@@ -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
|
-
|
|
17
|
+
/** 获取 canvas 区域隐含的像素数据 */
|
|
18
|
+
export * from './canvasGetImageData'
|
|
@@ -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
|
-
|
|
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
|
+
}
|
package/src/api/device/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Taro from '@tarojs/api'
|
|
2
2
|
|
|
3
|
-
import { MethodHandler } from '
|
|
4
|
-
import { temporarilyNotSupport } from '
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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')
|
package/src/api/device/wifi.ts
CHANGED
|
@@ -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')
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Taro from '@tarojs/api'
|
|
2
|
-
import { temporarilyNotSupport } from '../utils'
|
|
3
2
|
import { CallbackManager } from '../utils/handler'
|
|
4
3
|
import {
|
|
5
4
|
convertObjectUrlToBlob,
|
|
@@ -125,17 +124,12 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
|
|
|
125
124
|
*/
|
|
126
125
|
const offProgressUpdate = callbackManager.progressUpdate.remove
|
|
127
126
|
|
|
128
|
-
const headersReceived = temporarilyNotSupport('UploadTask.headersReceived')
|
|
129
|
-
const progress = temporarilyNotSupport('UploadTask.progress')
|
|
130
|
-
|
|
131
127
|
return {
|
|
132
128
|
abort,
|
|
133
129
|
onHeadersReceived,
|
|
134
130
|
offHeadersReceived,
|
|
135
131
|
onProgressUpdate,
|
|
136
|
-
offProgressUpdate
|
|
137
|
-
headersReceived,
|
|
138
|
-
progress
|
|
132
|
+
offProgressUpdate
|
|
139
133
|
}
|
|
140
134
|
}
|
|
141
135
|
|
package/src/api/ui/fonts.ts
CHANGED
|
@@ -1,4 +1,63 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { MethodHandler } from '../utils/handler'
|
|
2
3
|
|
|
3
4
|
// 字体
|
|
4
|
-
export const loadFontFace =
|
|
5
|
+
export const loadFontFace: typeof Taro.loadFontFace = async options => {
|
|
6
|
+
options = Object.assign({ global: false }, options)
|
|
7
|
+
const { success, fail, complete, family, source, desc = {} } = options
|
|
8
|
+
const handle = new MethodHandler({ name: 'loadFontFace', success, fail, complete })
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const fonts = document.fonts
|
|
11
|
+
if (fonts) {
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
const fontFace = new FontFace(family, source, desc)
|
|
14
|
+
try {
|
|
15
|
+
await fontFace.load()
|
|
16
|
+
fonts.add(fontFace)
|
|
17
|
+
return handle.success({})
|
|
18
|
+
} catch (error) {
|
|
19
|
+
return handle.fail({
|
|
20
|
+
errMsg: error.message || error
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
const style = document.createElement('style')
|
|
25
|
+
let innerText = `font-family:"${
|
|
26
|
+
family
|
|
27
|
+
}";src:${
|
|
28
|
+
source
|
|
29
|
+
};font-style:${
|
|
30
|
+
desc.style || 'normal'
|
|
31
|
+
};font-weight:${
|
|
32
|
+
desc.weight || 'normal'
|
|
33
|
+
};font-variant:${
|
|
34
|
+
desc.variant || 'normal'
|
|
35
|
+
};`
|
|
36
|
+
|
|
37
|
+
if (desc.ascentOverride) {
|
|
38
|
+
innerText += `ascent-override:${desc.ascentOverride};`
|
|
39
|
+
}
|
|
40
|
+
if (desc.descentOverride) {
|
|
41
|
+
innerText += `descent-override:${desc.descentOverride};`
|
|
42
|
+
}
|
|
43
|
+
if (desc.featureSettings) {
|
|
44
|
+
innerText += `font-feature-settings:${desc.featureSettings};`
|
|
45
|
+
}
|
|
46
|
+
if (desc.lineGapOverride) {
|
|
47
|
+
innerText += `line-gap-override:${desc.lineGapOverride};`
|
|
48
|
+
}
|
|
49
|
+
if (desc.stretch) {
|
|
50
|
+
innerText += `font-stretch:${desc.stretch};`
|
|
51
|
+
}
|
|
52
|
+
if (desc.unicodeRange) {
|
|
53
|
+
innerText += `unicode-range:${desc.unicodeRange};`
|
|
54
|
+
}
|
|
55
|
+
if (desc.variationSettings) {
|
|
56
|
+
innerText += `font-variation-settings:${desc.variationSettings};`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
style.innerText = `@font-face{${innerText}}`
|
|
60
|
+
document.head.appendChild(style)
|
|
61
|
+
return handle.success()
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/api/utils/handler.ts
CHANGED
|
@@ -58,7 +58,7 @@ export class CallbackManager {
|
|
|
58
58
|
* 添加回调
|
|
59
59
|
* @param {{ callback: function, ctx: any } | function} opt
|
|
60
60
|
*/
|
|
61
|
-
add (opt?: TCallbackManagerListItem) {
|
|
61
|
+
add = (opt?: TCallbackManagerListItem) => {
|
|
62
62
|
if (opt) this.callbacks.push(opt)
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -66,7 +66,7 @@ export class CallbackManager {
|
|
|
66
66
|
* 移除回调
|
|
67
67
|
* @param {{ callback: function, ctx: any } | function} opt
|
|
68
68
|
*/
|
|
69
|
-
remove (opt?: TCallbackManagerListItem) {
|
|
69
|
+
remove = (opt?: TCallbackManagerListItem) => {
|
|
70
70
|
if (opt) {
|
|
71
71
|
let pos = -1
|
|
72
72
|
this.callbacks.forEach((callback, k) => {
|
|
@@ -84,7 +84,7 @@ export class CallbackManager {
|
|
|
84
84
|
* 获取回调函数数量
|
|
85
85
|
* @return {number}
|
|
86
86
|
*/
|
|
87
|
-
count () {
|
|
87
|
+
count = () => {
|
|
88
88
|
return this.callbacks.length
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -92,7 +92,7 @@ export class CallbackManager {
|
|
|
92
92
|
* 触发回调
|
|
93
93
|
* @param {...any} args 回调的调用参数
|
|
94
94
|
*/
|
|
95
|
-
trigger (...args: TCallbackManagerList) {
|
|
95
|
+
trigger = (...args: TCallbackManagerList) => {
|
|
96
96
|
this.callbacks.forEach(opt => {
|
|
97
97
|
if (typeof opt === 'function') {
|
|
98
98
|
opt(...args)
|