@tarojs/taro-h5 3.3.16 → 3.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +5863 -8163
- package/dist/index.js +9044 -0
- package/dist/taroApis.js +1 -1
- package/package.json +9 -9
- package/src/api/ad/index.ts +5 -0
- package/src/api/ai/facial.ts +6 -0
- package/src/api/ai/index.ts +2 -0
- package/src/api/ai/visual.ts +4 -0
- package/src/api/alipay/index.ts +4 -0
- package/src/api/base/crypto.ts +4 -0
- package/src/api/base/debug.ts +5 -0
- package/src/api/base/index.ts +23 -0
- package/src/api/base/performance.ts +5 -0
- package/src/api/base/system/index.ts +2 -0
- package/src/api/base/system/info.ts +64 -0
- package/src/api/base/system/network.ts +70 -0
- package/src/api/base/update.ts +5 -0
- package/src/api/base/weapp/app-event.ts +19 -0
- package/src/api/base/weapp/life-cycle.ts +5 -0
- package/src/api/canvas/CanvasContext.ts +230 -0
- package/src/api/canvas/canvasGetImageData.ts +29 -0
- package/src/api/canvas/canvasPutImageData.ts +26 -0
- package/src/api/canvas/canvasToTempFilePath.ts +26 -0
- package/src/api/canvas/createCanvasContext.ts +20 -0
- package/src/api/canvas/{index.js → index.ts} +9 -3
- package/src/api/cloud/index.ts +27 -0
- package/src/api/data-analysis/index.ts +6 -0
- package/src/api/device/accelerometer.ts +89 -0
- package/src/api/device/accessibility.ts +4 -0
- package/src/api/device/battery.ts +5 -0
- package/src/api/device/bluetooth-ble.ts +19 -0
- package/src/api/device/bluetooth-peripheral.ts +6 -0
- package/src/api/device/bluetooth.ts +16 -0
- package/src/api/device/calendar.ts +5 -0
- package/src/api/device/clipboard.ts +67 -0
- package/src/api/device/compass.ts +74 -0
- package/src/api/device/contact.ts +5 -0
- package/src/api/device/crypto.ts +4 -0
- package/src/api/device/gyroscope.ts +7 -0
- package/src/api/device/iBeacon.ts +10 -0
- package/src/api/device/index.ts +22 -0
- package/src/api/device/keyboard.ts +7 -0
- package/src/api/device/memory.ts +5 -0
- package/src/api/device/motion.ts +92 -0
- package/src/api/device/nfc.ts +10 -0
- package/src/api/device/phone.ts +30 -0
- package/src/api/device/scan.ts +7 -0
- package/src/api/device/screen.ts +9 -0
- package/src/api/device/vibrate.ts +36 -0
- package/src/api/device/wifi.ts +13 -0
- package/src/api/ext/index.ts +5 -0
- package/src/api/files/index.ts +11 -0
- package/src/api/framework/index.ts +10 -0
- package/src/api/index.ts +25 -0
- package/src/api/location/chooseLocation.ts +106 -0
- package/src/api/location/index.ts +19 -0
- package/src/api/location/style.css +8 -8
- package/src/api/media/audio/index.ts +99 -0
- package/src/api/media/background-audio.ts +12 -0
- package/src/api/media/camera.ts +4 -0
- package/src/api/media/editor.ts +29 -0
- package/src/api/media/image/chooseImage.ts +80 -0
- package/src/api/{image → media/image}/getImageInfo.js +0 -0
- package/src/api/media/image/index.ts +13 -0
- package/src/api/{image → media/image}/previewImage.js +4 -0
- package/src/api/media/index.ts +13 -0
- package/src/api/media/live.ts +5 -0
- package/src/api/media/map.ts +4 -0
- package/src/api/media/media-recorder.ts +4 -0
- package/src/api/media/recorder.ts +6 -0
- package/src/api/media/video/index.ts +82 -0
- package/src/api/media/video-decoder.ts +4 -0
- package/src/api/media/video-processing.ts +4 -0
- package/src/api/media/voip.ts +17 -0
- package/src/api/navigate/index.ts +7 -0
- package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -25
- package/src/api/network/index.ts +7 -0
- package/src/api/network/mdns.ts +13 -0
- package/src/api/{request/index.js → network/request/index.ts} +9 -6
- package/src/api/network/tcp.ts +4 -0
- package/src/api/network/udp.ts +4 -0
- package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -30
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/{webSocket/index.js → network/websocket/index.ts} +49 -56
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +16 -6
- package/src/api/open-api/account.ts +4 -0
- package/src/api/open-api/address.ts +4 -0
- package/src/api/open-api/authorize.ts +5 -0
- package/src/api/open-api/card.ts +5 -0
- package/src/api/open-api/channels-live.ts +9 -0
- package/src/api/open-api/customer-service.ts +4 -0
- package/src/api/open-api/facial.ts +7 -0
- package/src/api/open-api/favorites.ts +5 -0
- package/src/api/open-api/group.ts +4 -0
- package/src/api/open-api/index.ts +18 -0
- package/src/api/open-api/invoice.ts +5 -0
- package/src/api/open-api/license-plate.ts +4 -0
- package/src/api/open-api/login.ts +6 -0
- package/src/api/open-api/red-package.ts +4 -0
- package/src/api/open-api/settings.ts +5 -0
- package/src/api/open-api/soter.ts +6 -0
- package/src/api/open-api/subscribe-message.ts +4 -0
- package/src/api/open-api/user-info.ts +5 -0
- package/src/api/open-api/werun.ts +5 -0
- package/src/api/payment/index.ts +5 -0
- package/src/api/route/index.ts +10 -0
- package/src/api/share/index.ts +13 -0
- package/src/api/storage/background-fetch.ts +7 -0
- package/src/api/storage/index.ts +193 -0
- package/src/api/swan/index.ts +31 -0
- package/src/{taro/index.js → api/taro.ts} +133 -149
- package/src/api/{createAnimation/index.js → ui/animation/index.ts} +26 -14
- package/src/api/ui/background.ts +5 -0
- package/src/api/ui/custom-component.ts +4 -0
- package/src/api/ui/fonts.ts +4 -0
- package/src/api/ui/index.ts +12 -0
- package/src/api/ui/interaction/actionSheet.ts +212 -0
- package/src/api/{interactive/index.js → ui/interaction/index.ts} +102 -90
- package/src/api/ui/interaction/modal.ts +237 -0
- package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
- package/src/api/ui/menu.ts +4 -0
- package/src/api/ui/navigation-bar/index.ts +52 -0
- package/src/api/ui/pull-down-refresh.ts +32 -0
- package/src/api/{scroll/index.js → ui/scroll/index.ts} +16 -28
- package/src/api/ui/sticky.ts +4 -0
- package/src/api/ui/tab-bar.ts +326 -0
- package/src/api/ui/window.ts +37 -0
- package/src/api/utils/handler.ts +105 -0
- package/src/api/utils/{index.js → index.ts} +23 -86
- package/src/api/worker/index.ts +4 -0
- package/src/api/wxml/index.ts +9 -0
- package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +86 -59
- package/src/index.ts +6 -0
- package/src/types/api.d.ts +4 -0
- package/src/types/define.d.ts +2 -0
- package/{types → src/types}/index.d.ts +0 -0
- package/{types → src/types}/type.ts +1 -1
- package/src/api/accelerometer/index.js +0 -105
- package/src/api/audio/index.js +0 -137
- package/src/api/canvas/canvasGetImageData.js +0 -44
- package/src/api/canvas/canvasPutImageData.js +0 -45
- package/src/api/canvas/canvasToTempFilePath.js +0 -49
- package/src/api/canvas/createCanvasContext.js +0 -340
- package/src/api/clipboard/index.js +0 -113
- package/src/api/compass/index.js +0 -99
- package/src/api/deviceMotion/index.js +0 -105
- package/src/api/fileTransfer/index.js +0 -2
- package/src/api/image/chooseImage.js +0 -87
- package/src/api/image/index.js +0 -7
- package/src/api/index.js +0 -29
- package/src/api/interactive/actionSheet.js +0 -214
- package/src/api/interactive/modal.js +0 -256
- package/src/api/location/chooseLocation.js +0 -143
- package/src/api/location/index.js +0 -5
- package/src/api/navigationBar/index.js +0 -57
- package/src/api/open/index.js +0 -5
- package/src/api/others/index.js +0 -43
- package/src/api/pullDownRefresh/index.js +0 -51
- package/src/api/storage/index.js +0 -211
- package/src/api/system/index.js +0 -9
- package/src/api/system/info.js +0 -36
- package/src/api/system/network.js +0 -68
- package/src/api/tabBar/index.js +0 -402
- package/src/api/unsupportedApi/index.js +0 -278
- package/src/api/vibrate/index.js +0 -49
- package/src/api/video/index.js +0 -87
- package/src/api/window/index.js +0 -38
- package/src/index.cjs.js +0 -11
- package/src/index.js +0 -6
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 文件
|
|
4
|
+
export const saveFileToDisk = temporarilyNotSupport('saveFileToDisk')
|
|
5
|
+
export const saveFile = temporarilyNotSupport('saveFile')
|
|
6
|
+
export const removeSavedFile = temporarilyNotSupport('removeSavedFile')
|
|
7
|
+
export const openDocument = temporarilyNotSupport('openDocument')
|
|
8
|
+
export const getSavedFileList = temporarilyNotSupport('getSavedFileList')
|
|
9
|
+
export const getSavedFileInfo = temporarilyNotSupport('getSavedFileInfo')
|
|
10
|
+
export const getFileSystemManager = temporarilyNotSupport('getFileSystemManager')
|
|
11
|
+
export const getFileInfo = temporarilyNotSupport('getFileInfo')
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
|
|
3
|
+
export const getApp: typeof Taro.getApp = function <T = TaroGeneral.IAnyObject> () {
|
|
4
|
+
return Taro.getCurrentInstance().app as unknown as Taro.getApp.Instance<T>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { getCurrentPages } from '@tarojs/router'
|
|
8
|
+
|
|
9
|
+
// 自定义组件
|
|
10
|
+
export const getCurrentInstance = Taro.getCurrentInstance
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './ad'
|
|
2
|
+
export * from './ai'
|
|
3
|
+
export * from './base'
|
|
4
|
+
export * from './canvas'
|
|
5
|
+
export * from './cloud'
|
|
6
|
+
export * from './data-analysis'
|
|
7
|
+
export * from './device'
|
|
8
|
+
export * from './ext'
|
|
9
|
+
export * from './files'
|
|
10
|
+
export * from './framework'
|
|
11
|
+
export * from './location'
|
|
12
|
+
export * from './media'
|
|
13
|
+
export * from './navigate'
|
|
14
|
+
export * from './network'
|
|
15
|
+
export * from './open-api'
|
|
16
|
+
export * from './payment'
|
|
17
|
+
export * from './route'
|
|
18
|
+
export * from './share'
|
|
19
|
+
export * from './storage'
|
|
20
|
+
export * from './ui'
|
|
21
|
+
export * from './worker'
|
|
22
|
+
export * from './wxml'
|
|
23
|
+
|
|
24
|
+
export * from './alipay'
|
|
25
|
+
export * from './swan'
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { MethodHandler } from '../utils/handler'
|
|
3
|
+
import './style.css'
|
|
4
|
+
|
|
5
|
+
function createLocationChooser (handler, key = LOCATION_APIKEY) {
|
|
6
|
+
const html = `
|
|
7
|
+
<div class='taro_choose_location'>
|
|
8
|
+
<div class='taro_choose_location_bar'>
|
|
9
|
+
<div class='taro_choose_location_back'></div>
|
|
10
|
+
<p class='taro_choose_location_title'>位置</p>
|
|
11
|
+
<button class='taro_choose_location_submit'>完成</button>
|
|
12
|
+
</div>
|
|
13
|
+
<iframe class='taro_choose_location_frame' frameborder='0' src='https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=${key}&referer=myapp'></iframe>
|
|
14
|
+
</div>
|
|
15
|
+
`
|
|
16
|
+
const container = document.createElement('div')
|
|
17
|
+
container.innerHTML = html
|
|
18
|
+
const main: HTMLDivElement = container.querySelector('.taro_choose_location') as HTMLDivElement
|
|
19
|
+
|
|
20
|
+
function show () {
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
main.style.top = '0'
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function hide () {
|
|
27
|
+
main.style.top = '100%'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function back () {
|
|
31
|
+
handler({ errMsg: 'cancel' })
|
|
32
|
+
hide()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function submit () {
|
|
36
|
+
handler()
|
|
37
|
+
hide()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function remove () {
|
|
41
|
+
container.remove()
|
|
42
|
+
window.removeEventListener('popstate', back)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
container.querySelector('.taro_choose_location_back')?.addEventListener('click', back)
|
|
46
|
+
container.querySelector('.taro_choose_location_submit')?.addEventListener('click', submit)
|
|
47
|
+
|
|
48
|
+
window.addEventListener('popstate', back)
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
show,
|
|
52
|
+
remove,
|
|
53
|
+
container
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 打开地图选择位置。
|
|
59
|
+
*/
|
|
60
|
+
export const chooseLocation: typeof Taro.chooseLocation = ({ success, fail, complete } = {}) => {
|
|
61
|
+
const key = LOCATION_APIKEY
|
|
62
|
+
const handle = new MethodHandler({ name: 'chooseLocation', success, fail, complete })
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const chooseLocation: Partial<Taro.chooseLocation.SuccessCallbackResult> = {}
|
|
65
|
+
if (!key) {
|
|
66
|
+
console.warn('chooseLocation api 依赖腾讯地图定位api,需要在 defineConstants 中配置 LOCATION_APIKEY')
|
|
67
|
+
return handle.fail({
|
|
68
|
+
errMsg: 'LOCATION_APIKEY needed'
|
|
69
|
+
}, reject)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const onMessage = event => {
|
|
73
|
+
// 接收位置信息,用户选择确认位置点后选点组件会触发该事件,回传用户的位置信息
|
|
74
|
+
const loc = event.data
|
|
75
|
+
|
|
76
|
+
// 防止其他应用也会向该页面 post 信息,需判断 module 是否为'locationPicker'
|
|
77
|
+
if (!loc || loc.module !== 'locationPicker') return
|
|
78
|
+
|
|
79
|
+
chooseLocation.name = loc.poiname
|
|
80
|
+
chooseLocation.address = loc.poiaddress
|
|
81
|
+
chooseLocation.latitude = loc.latlng.lat
|
|
82
|
+
chooseLocation.longitude = loc.latlng.lng
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const chooser = createLocationChooser(res => {
|
|
86
|
+
window.removeEventListener('message', onMessage, false)
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
chooser.remove()
|
|
89
|
+
}, 300)
|
|
90
|
+
if (res) {
|
|
91
|
+
return handle.fail(res, reject)
|
|
92
|
+
} else {
|
|
93
|
+
if (chooseLocation.latitude && chooseLocation.longitude) {
|
|
94
|
+
return handle.success(chooseLocation, resolve)
|
|
95
|
+
} else {
|
|
96
|
+
return handle.fail({}, reject)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}, key)
|
|
100
|
+
|
|
101
|
+
document.body.appendChild(chooser.container)
|
|
102
|
+
|
|
103
|
+
window.addEventListener('message', onMessage, false)
|
|
104
|
+
chooser.show()
|
|
105
|
+
})
|
|
106
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { processOpenApi, temporarilyNotSupport } from '../utils/index'
|
|
2
|
+
|
|
3
|
+
// 位置
|
|
4
|
+
export const stopLocationUpdate = temporarilyNotSupport('stopLocationUpdate')
|
|
5
|
+
export const startLocationUpdateBackground = temporarilyNotSupport('startLocationUpdateBackground')
|
|
6
|
+
export const startLocationUpdate = temporarilyNotSupport('startLocationUpdate')
|
|
7
|
+
|
|
8
|
+
export const openLocation = processOpenApi('openLocation', { scale: 18 })
|
|
9
|
+
|
|
10
|
+
export const onLocationChangeError = temporarilyNotSupport('onLocationChangeError')
|
|
11
|
+
export const onLocationChange = temporarilyNotSupport('onLocationChange')
|
|
12
|
+
export const offLocationChangeError = temporarilyNotSupport('offLocationChangeError')
|
|
13
|
+
export const offLocationChange = temporarilyNotSupport('offLocationChange')
|
|
14
|
+
|
|
15
|
+
export const getLocation = processOpenApi('getLocation')
|
|
16
|
+
|
|
17
|
+
export const choosePoi = temporarilyNotSupport('choosePoi')
|
|
18
|
+
|
|
19
|
+
export { chooseLocation } from './chooseLocation'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.
|
|
1
|
+
.taro_choose_location {
|
|
2
2
|
position: fixed;
|
|
3
3
|
display: flex;
|
|
4
4
|
flex-direction: column;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
z-index: 1;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
.
|
|
13
|
+
.taro_choose_location_bar {
|
|
14
14
|
display: flex;
|
|
15
15
|
flex: 0 95px;
|
|
16
16
|
height: 95px;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
color: #090909;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
.
|
|
21
|
+
.taro_choose_location_back {
|
|
22
22
|
flex: 0 45px;
|
|
23
23
|
position: relative;
|
|
24
24
|
width: 33px;
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
margin-top: 30px;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
.
|
|
29
|
+
.taro_choose_location_back::before {
|
|
30
30
|
content: '';
|
|
31
31
|
position: absolute;
|
|
32
32
|
top: 0;
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
border-left-color: transparent;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
.
|
|
44
|
+
.taro_choose_location_back::after {
|
|
45
45
|
content: '';
|
|
46
46
|
position: absolute;
|
|
47
47
|
display: block;
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
border-left-color: transparent;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
.
|
|
59
|
+
.taro_choose_location_title {
|
|
60
60
|
flex: 1;
|
|
61
61
|
line-height: 95px;
|
|
62
62
|
padding-left: 30px;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
.
|
|
65
|
+
.taro_choose_location_submit {
|
|
66
66
|
width: 110px;
|
|
67
67
|
height: 60px;
|
|
68
68
|
color: #fff;
|
|
@@ -74,6 +74,6 @@
|
|
|
74
74
|
margin: 18px 30px 0 0;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
.
|
|
77
|
+
.taro_choose_location_frame {
|
|
78
78
|
flex: 1;
|
|
79
79
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { temporarilyNotSupport } from '../../utils'
|
|
3
|
+
import { CallbackManager } from '../../utils/handler'
|
|
4
|
+
|
|
5
|
+
// 音频
|
|
6
|
+
class InnerAudioContext implements Taro.InnerAudioContext {
|
|
7
|
+
Instance?: HTMLAudioElement
|
|
8
|
+
errorStack: CallbackManager
|
|
9
|
+
stopStack: CallbackManager
|
|
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
|
+
}
|
|
18
|
+
|
|
19
|
+
set autoplay (e) { Object.defineProperty(this.Instance, 'autoplay', { value: e }) }
|
|
20
|
+
get autoplay () { return this.Instance?.autoplay || false }
|
|
21
|
+
get buffered () { return this.Instance?.buffered.length || 0 }
|
|
22
|
+
get currentTime () { return this.Instance?.currentTime || 0 }
|
|
23
|
+
get duration () { return this.Instance?.duration || 0 }
|
|
24
|
+
set loop (e) { Object.defineProperty(this.Instance, 'loop', { value: e }) }
|
|
25
|
+
get loop () { return this.Instance?.loop || false }
|
|
26
|
+
get paused () { return this.Instance?.paused || true }
|
|
27
|
+
set src (e) { Object.defineProperty(this.Instance, 'src', { value: e }) }
|
|
28
|
+
get src () { return this.Instance?.src || '' }
|
|
29
|
+
set volume (e) { Object.defineProperty(this.Instance, 'volume', { value: e }) }
|
|
30
|
+
get volume () { return this.Instance?.volume || 0 }
|
|
31
|
+
set playbackRate (e) { Object.defineProperty(this.Instance, 'playbackRate', { value: e }) }
|
|
32
|
+
get playbackRate () { return this.Instance?.volume || 0 }
|
|
33
|
+
get obeyMuteSwitch () { return true }
|
|
34
|
+
set startTime (e) { Object.defineProperty(this.Instance, 'startTime', { value: e }) }
|
|
35
|
+
get startTime () { return this.Instance?.volume || 0 }
|
|
36
|
+
|
|
37
|
+
play = () => this.Instance?.play()
|
|
38
|
+
|
|
39
|
+
pause = () => this.Instance?.pause()
|
|
40
|
+
|
|
41
|
+
stop = () => {
|
|
42
|
+
this.pause()
|
|
43
|
+
this.seek(0)
|
|
44
|
+
this.stopStack.trigger()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
seek = (position: number) => {
|
|
48
|
+
if (this.Instance) {
|
|
49
|
+
this.Instance.currentTime = position
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @TODO destroy得并不干净
|
|
55
|
+
*/
|
|
56
|
+
destroy = () => {
|
|
57
|
+
this.stop()
|
|
58
|
+
if (this.Instance) {
|
|
59
|
+
document.body.removeChild(this.Instance)
|
|
60
|
+
this.Instance = undefined
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
onCanplay = (callback = () => {}) => this.Instance?.addEventListener('oncanplay', callback)
|
|
65
|
+
onPlay = (callback = () => {}) => this.Instance?.addEventListener('onplay', callback)
|
|
66
|
+
onPause = (callback = () => {}) => this.Instance?.addEventListener('onpause', callback)
|
|
67
|
+
onStop = (callback = () => {}) => this.stopStack.add(callback)
|
|
68
|
+
onEnded = (callback = () => {}) => this.Instance?.addEventListener('onended', callback)
|
|
69
|
+
onTimeUpdate = (callback = () => {}) => this.Instance?.addEventListener('ontimeUpdate', callback)
|
|
70
|
+
onError = (callback?: ((res: Taro.InnerAudioContext.onErrorDetail) => void)) => this.errorStack.add(callback)
|
|
71
|
+
onWaiting = (callback = () => {}) => this.Instance?.addEventListener('onwaiting', callback)
|
|
72
|
+
onSeeking = (callback = () => {}) => this.Instance?.addEventListener('onseeking', callback)
|
|
73
|
+
onSeeked = (callback = () => {}) => this.Instance?.addEventListener('onseeked', callback)
|
|
74
|
+
offCanplay = (callback = () => {}) => this.Instance?.removeEventListener('offcanplay', callback)
|
|
75
|
+
offPlay = (callback = () => {}) => this.Instance?.removeEventListener('offplay', callback)
|
|
76
|
+
offPause = (callback = () => {}) => this.Instance?.removeEventListener('offpause', callback)
|
|
77
|
+
offStop = (callback = () => {}) => this.stopStack.remove(callback)
|
|
78
|
+
offEnded = (callback = () => {}) => this.Instance?.removeEventListener('offended', callback)
|
|
79
|
+
offTimeUpdate = (callback = () => {}) => this.Instance?.removeEventListener('offtimeUpdate', callback)
|
|
80
|
+
offError = (callback = () => {}) => this.errorStack.remove(callback)
|
|
81
|
+
offWaiting = (callback = () => {}) => this.Instance?.removeEventListener('offwaiting', callback)
|
|
82
|
+
offSeeking = (callback = () => {}) => this.Instance?.removeEventListener('offseeking', callback)
|
|
83
|
+
offSeeked = (callback = () => {}) => this.Instance?.removeEventListener('offseeked', callback)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const stopVoice = temporarilyNotSupport('stopVoice')
|
|
87
|
+
export const setInnerAudioOption = temporarilyNotSupport('setInnerAudioOption')
|
|
88
|
+
export const playVoice = temporarilyNotSupport('playVoice')
|
|
89
|
+
export const pauseVoice = temporarilyNotSupport('pauseVoice')
|
|
90
|
+
export const getAvailableAudioSources = temporarilyNotSupport('getAvailableAudioSources')
|
|
91
|
+
export const createWebAudioContext = temporarilyNotSupport('createWebAudioContext')
|
|
92
|
+
export const createMediaAudioPlayer = temporarilyNotSupport('createMediaAudioPlayer')
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 创建内部 audio 上下文 InnerAudioContext 对象。
|
|
96
|
+
*/
|
|
97
|
+
export const createInnerAudioContext: typeof Taro.createInnerAudioContext = () => new InnerAudioContext()
|
|
98
|
+
|
|
99
|
+
export const createAudioContext = temporarilyNotSupport('createAudioContext')
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 背景音频
|
|
4
|
+
export const stopBackgroundAudio = temporarilyNotSupport('stopBackgroundAudio')
|
|
5
|
+
export const seekBackgroundAudio = temporarilyNotSupport('seekBackgroundAudio')
|
|
6
|
+
export const playBackgroundAudio = temporarilyNotSupport('playBackgroundAudio')
|
|
7
|
+
export const pauseBackgroundAudio = temporarilyNotSupport('pauseBackgroundAudio')
|
|
8
|
+
export const onBackgroundAudioStop = temporarilyNotSupport('onBackgroundAudioStop')
|
|
9
|
+
export const onBackgroundAudioPlay = temporarilyNotSupport('onBackgroundAudioPlay')
|
|
10
|
+
export const onBackgroundAudioPause = temporarilyNotSupport('onBackgroundAudioPause')
|
|
11
|
+
export const getBackgroundAudioPlayerState = temporarilyNotSupport('getBackgroundAudioPlayerState')
|
|
12
|
+
export const getBackgroundAudioManager = temporarilyNotSupport('getBackgroundAudioManager')
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { temporarilyNotSupport } from '../utils'
|
|
3
|
+
|
|
4
|
+
// 富文本
|
|
5
|
+
export class EditorContext implements Taro.EditorContext {
|
|
6
|
+
blur = temporarilyNotSupport('EditorContext.blur')
|
|
7
|
+
|
|
8
|
+
clear = temporarilyNotSupport('EditorContext.clear')
|
|
9
|
+
|
|
10
|
+
format = temporarilyNotSupport('EditorContext.format')
|
|
11
|
+
|
|
12
|
+
getContents = temporarilyNotSupport('EditorContext.getContents')
|
|
13
|
+
|
|
14
|
+
insertDivider = temporarilyNotSupport('EditorContext.insertDivider')
|
|
15
|
+
|
|
16
|
+
insertImage = temporarilyNotSupport('EditorContext.insertImage')
|
|
17
|
+
|
|
18
|
+
insertText = temporarilyNotSupport('EditorContext.insertText')
|
|
19
|
+
|
|
20
|
+
redo = temporarilyNotSupport('EditorContext.redo')
|
|
21
|
+
|
|
22
|
+
removeFormat = temporarilyNotSupport('EditorContext.removeFormat')
|
|
23
|
+
|
|
24
|
+
scrollIntoView = temporarilyNotSupport('EditorContext.scrollIntoView')
|
|
25
|
+
|
|
26
|
+
setContents = temporarilyNotSupport('EditorContext.setContents')
|
|
27
|
+
|
|
28
|
+
undo = temporarilyNotSupport('EditorContext.undo')
|
|
29
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
|
|
3
|
+
import { MethodHandler } from '../../utils/handler'
|
|
4
|
+
import { shouldBeObject, getParameterError } from '../../utils'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 从本地相册选择图片或使用相机拍照。
|
|
8
|
+
*/
|
|
9
|
+
const chooseImage: typeof Taro.chooseImage = function (options) {
|
|
10
|
+
// options must be an Object
|
|
11
|
+
const isObject = shouldBeObject(options)
|
|
12
|
+
if (!isObject.flag) {
|
|
13
|
+
const res = { errMsg: `chooseImage:fail ${isObject.msg}` }
|
|
14
|
+
console.error(res.errMsg)
|
|
15
|
+
return Promise.reject(res)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { count = 1, success, fail, complete, imageId = 'taroChooseImage' } = options
|
|
19
|
+
const handle = new MethodHandler({ name: 'chooseImage', success, fail, complete })
|
|
20
|
+
const res: Partial<Taro.chooseImage.SuccessCallbackResult> = {
|
|
21
|
+
tempFilePaths: [],
|
|
22
|
+
tempFiles: []
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (count && typeof count !== 'number') {
|
|
26
|
+
res.errMsg = getParameterError({
|
|
27
|
+
para: 'count',
|
|
28
|
+
correct: 'Number',
|
|
29
|
+
wrong: count
|
|
30
|
+
})
|
|
31
|
+
return handle.fail(res)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let el = document.getElementById(imageId)
|
|
35
|
+
if (!el) {
|
|
36
|
+
const obj = document.createElement('input')
|
|
37
|
+
obj.setAttribute('type', 'file')
|
|
38
|
+
obj.setAttribute('id', imageId)
|
|
39
|
+
if (count > 1) {
|
|
40
|
+
obj.setAttribute('multiple', 'multiple')
|
|
41
|
+
}
|
|
42
|
+
obj.setAttribute('accept', 'image/*')
|
|
43
|
+
obj.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;')
|
|
44
|
+
document.body.appendChild(obj)
|
|
45
|
+
el = document.getElementById(imageId)
|
|
46
|
+
} else {
|
|
47
|
+
if (count > 1) {
|
|
48
|
+
el.setAttribute('multiple', 'multiple')
|
|
49
|
+
} else {
|
|
50
|
+
el.removeAttribute('multiple')
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return new Promise(resolve => {
|
|
55
|
+
const TaroMouseEvents = document.createEvent('MouseEvents')
|
|
56
|
+
TaroMouseEvents.initEvent('click', true, true)
|
|
57
|
+
if (el) {
|
|
58
|
+
el.dispatchEvent(TaroMouseEvents)
|
|
59
|
+
el.onchange = function (e) {
|
|
60
|
+
const target = e.target as HTMLInputElement
|
|
61
|
+
if (target) {
|
|
62
|
+
const files = target.files || []
|
|
63
|
+
const arr = [...files]
|
|
64
|
+
arr && arr.forEach(item => {
|
|
65
|
+
const blob = new Blob([item], {
|
|
66
|
+
type: item.type
|
|
67
|
+
})
|
|
68
|
+
const url = URL.createObjectURL(blob)
|
|
69
|
+
res.tempFilePaths?.push(url)
|
|
70
|
+
res.tempFiles?.push({ path: url, size: item.size, type: item.type, originalFileObj: item })
|
|
71
|
+
})
|
|
72
|
+
handle.success(res, resolve)
|
|
73
|
+
target.value = ''
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default chooseImage
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils'
|
|
2
|
+
|
|
3
|
+
// 图片
|
|
4
|
+
export const saveImageToPhotosAlbum = temporarilyNotSupport('saveImageToPhotosAlbum')
|
|
5
|
+
export const previewMedia = temporarilyNotSupport('previewMedia')
|
|
6
|
+
|
|
7
|
+
export { previewImage } from './previewImage'
|
|
8
|
+
export { default as getImageInfo } from './getImageInfo'
|
|
9
|
+
|
|
10
|
+
export const compressImage = temporarilyNotSupport('compressImage')
|
|
11
|
+
export const chooseMessageFile = temporarilyNotSupport('chooseMessageFile')
|
|
12
|
+
|
|
13
|
+
export { default as chooseImage } from './chooseImage'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './audio'
|
|
2
|
+
export * from './background-audio'
|
|
3
|
+
export * from './camera'
|
|
4
|
+
export * from './editor'
|
|
5
|
+
export * from './image'
|
|
6
|
+
export * from './live'
|
|
7
|
+
export * from './map'
|
|
8
|
+
export * from './media-recorder'
|
|
9
|
+
export * from './recorder'
|
|
10
|
+
export * from './video'
|
|
11
|
+
export * from './video-decoder'
|
|
12
|
+
export * from './video-processing'
|
|
13
|
+
export * from './voip'
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
|
|
3
|
+
import { MethodHandler } from '../../utils/handler'
|
|
4
|
+
import { findDOM, shouldBeObject, temporarilyNotSupport } from '../../utils'
|
|
5
|
+
|
|
6
|
+
// 视频
|
|
7
|
+
export const saveVideoToPhotosAlbum = temporarilyNotSupport('saveVideoToPhotosAlbum')
|
|
8
|
+
export const openVideoEditor = temporarilyNotSupport('openVideoEditor')
|
|
9
|
+
export const getVideoInfo = temporarilyNotSupport('getVideoInfo')
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 创建 video 上下文 VideoContext 对象。
|
|
13
|
+
*/
|
|
14
|
+
export const createVideoContext: typeof Taro.createVideoContext = (id, inst) => {
|
|
15
|
+
const el = findDOM(inst) as HTMLVideoElement
|
|
16
|
+
// TODO HTMLVideoElement to VideoContext
|
|
17
|
+
return el?.querySelector(`taro-video-core[id=${id}]`) as unknown as Taro.VideoContext
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const compressVideo = temporarilyNotSupport('compressVideo')
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 拍摄视频或从手机相册中选视频。
|
|
24
|
+
*/
|
|
25
|
+
export const chooseVideo: typeof Taro.chooseVideo = (options) => {
|
|
26
|
+
// options must be an Object
|
|
27
|
+
const isObject = shouldBeObject(options)
|
|
28
|
+
if (!isObject.flag) {
|
|
29
|
+
const res = { errMsg: `chooseVideo:fail ${isObject.msg}` }
|
|
30
|
+
console.error(res.errMsg)
|
|
31
|
+
return Promise.reject(res)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const { success, fail, complete } = options
|
|
35
|
+
const handle = new MethodHandler<Taro.chooseVideo.SuccessCallbackResult>({ name: 'chooseVideo', success, fail, complete })
|
|
36
|
+
const res: Partial<Taro.chooseVideo.SuccessCallbackResult> = {
|
|
37
|
+
tempFilePath: '',
|
|
38
|
+
duration: 0,
|
|
39
|
+
size: 0,
|
|
40
|
+
height: 0,
|
|
41
|
+
width: 0
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const inputEl = document.createElement('input')
|
|
45
|
+
inputEl.setAttribute('type', 'file')
|
|
46
|
+
inputEl.setAttribute('multiple', 'multiple')
|
|
47
|
+
inputEl.setAttribute('accept', 'video/*')
|
|
48
|
+
inputEl.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;')
|
|
49
|
+
document.body.appendChild(inputEl)
|
|
50
|
+
|
|
51
|
+
return new Promise<Taro.chooseVideo.SuccessCallbackResult>(resolve => {
|
|
52
|
+
const TaroMouseEvents = document.createEvent('MouseEvents')
|
|
53
|
+
TaroMouseEvents.initEvent('click', true, true)
|
|
54
|
+
inputEl.dispatchEvent(TaroMouseEvents)
|
|
55
|
+
inputEl.onchange = function (e) {
|
|
56
|
+
const target = e.target as HTMLInputElement
|
|
57
|
+
const file = target.files?.[0]
|
|
58
|
+
const reader = new FileReader()
|
|
59
|
+
reader.onload = function (event: ProgressEvent<FileReader>) {
|
|
60
|
+
const videoEl = document.createElement('video')
|
|
61
|
+
const url = event.target?.result as string
|
|
62
|
+
videoEl.preload = 'metadata'
|
|
63
|
+
videoEl.src = url
|
|
64
|
+
videoEl.onloadedmetadata = () => {
|
|
65
|
+
res.tempFilePath = url
|
|
66
|
+
res.duration = videoEl.duration
|
|
67
|
+
res.size = event.total
|
|
68
|
+
res.height = videoEl.videoHeight
|
|
69
|
+
res.width = videoEl.videoHeight
|
|
70
|
+
return handle.success(res, resolve)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (file) {
|
|
74
|
+
reader.readAsDataURL(file)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}).finally(() => {
|
|
78
|
+
document.body.removeChild(inputEl)
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const chooseMedia = temporarilyNotSupport('chooseMedia')
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 实时语音
|
|
4
|
+
export const updateVoIPChatMuteConfig = temporarilyNotSupport('updateVoIPChatMuteConfig')
|
|
5
|
+
export const subscribeVoIPVideoMembers = temporarilyNotSupport('subscribeVoIPVideoMembers')
|
|
6
|
+
export const setEnable1v1Chat = temporarilyNotSupport('setEnable1v1Chat')
|
|
7
|
+
export const onVoIPVideoMembersChanged = temporarilyNotSupport('onVoIPVideoMembersChanged')
|
|
8
|
+
export const onVoIPChatStateChanged = temporarilyNotSupport('onVoIPChatStateChanged')
|
|
9
|
+
export const onVoIPChatSpeakersChanged = temporarilyNotSupport('onVoIPChatSpeakersChanged')
|
|
10
|
+
export const onVoIPChatMembersChanged = temporarilyNotSupport('onVoIPChatMembersChanged')
|
|
11
|
+
export const onVoIPChatInterrupted = temporarilyNotSupport('onVoIPChatInterrupted')
|
|
12
|
+
export const offVoIPVideoMembersChanged = temporarilyNotSupport('offVoIPVideoMembersChanged')
|
|
13
|
+
export const offVoIPChatStateChanged = temporarilyNotSupport('offVoIPChatStateChanged')
|
|
14
|
+
export const offVoIPChatMembersChanged = temporarilyNotSupport('offVoIPChatMembersChanged')
|
|
15
|
+
export const offVoIPChatInterrupted = temporarilyNotSupport('offVoIPChatInterrupted')
|
|
16
|
+
export const joinVoIPChat = temporarilyNotSupport('joinVoIPChat')
|
|
17
|
+
export const exitVoIPChat = temporarilyNotSupport('exitVoIPChat')
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 跳转
|
|
4
|
+
export const openEmbeddedMiniProgram = temporarilyNotSupport('openEmbeddedMiniProgram')
|
|
5
|
+
export const navigateToMiniProgram = temporarilyNotSupport('navigateToMiniProgram')
|
|
6
|
+
export const navigateBackMiniProgram = temporarilyNotSupport('navigateBackMiniProgram')
|
|
7
|
+
export const exitMiniProgram = temporarilyNotSupport('exitMiniProgram')
|