@tarojs/taro-h5 3.4.0 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/canvas/CanvasContext.js +1 -1
- package/dist/api/cloud/index.js +4 -0
- package/dist/api/media/{editor.js → EditorContext.js} +0 -0
- package/dist/api/media/audio/InnerAudioContext.js +84 -0
- package/dist/api/media/audio/index.js +1 -74
- package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
- package/dist/api/media/{background-audio.js → background-audio/index.js} +6 -2
- package/dist/api/media/index.js +0 -1
- package/dist/api/network/upload.js +1 -1
- package/dist/api/ui/animation/index.js +9 -5
- package/dist/api/ui/scroll/index.js +3 -3
- package/dist/api/utils/index.js +36 -12
- package/dist/index.cjs.js +158 -47
- package/dist/taroApis.js +1 -1
- package/package.json +7 -7
- package/src/api/canvas/CanvasContext.ts +1 -1
- package/src/api/cloud/index.ts +4 -0
- package/src/api/media/{editor.ts → EditorContext.ts} +0 -0
- package/src/api/media/audio/InnerAudioContext.ts +98 -0
- package/src/api/media/audio/index.ts +1 -86
- package/src/api/media/background-audio/BackgroundAudioManager.ts +103 -0
- package/src/api/media/{background-audio.ts → background-audio/index.ts} +7 -2
- package/src/api/media/index.ts +0 -1
- package/src/api/network/upload.ts +1 -1
- package/src/api/ui/animation/index.ts +10 -6
- package/src/api/ui/scroll/index.ts +3 -3
- package/src/api/utils/index.ts +33 -12
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { permanentlyNotSupport } from '../../utils'
|
|
3
|
+
import { CallbackManager } from '../../utils/handler'
|
|
4
|
+
|
|
5
|
+
export class BackgroundAudioManager implements Taro.BackgroundAudioManager {
|
|
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
|
+
this.Instance.autoplay = true
|
|
16
|
+
this.onPlay(() => {
|
|
17
|
+
if (this.currentTime !== this.startTime) {
|
|
18
|
+
this.seek(this.startTime)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
set src (e) { this.setProperty('src', e) }
|
|
24
|
+
get src () { return this.Instance?.src || '' }
|
|
25
|
+
set startTime (e) { this.__startTime = e }
|
|
26
|
+
get startTime () { return this.__startTime || 0 }
|
|
27
|
+
set title (e) { this.dataset('title', e) }
|
|
28
|
+
get title () { return this.Instance?.dataset.title || '' }
|
|
29
|
+
set epname (e) { this.dataset('epname', e) }
|
|
30
|
+
get epname () { return this.Instance?.dataset.epname || '' }
|
|
31
|
+
set singer (e) { this.dataset('singer', e) }
|
|
32
|
+
get singer () { return this.Instance?.dataset.singer || '' }
|
|
33
|
+
set coverImgUrl (e) { this.dataset('coverImgUrl', e) }
|
|
34
|
+
get coverImgUrl () { return this.Instance?.dataset.coverImgUrl || '' }
|
|
35
|
+
set webUrl (e) { this.dataset('webUrl', e) }
|
|
36
|
+
get webUrl () { return this.Instance?.dataset.webUrl || '' }
|
|
37
|
+
set protocol (e) { this.dataset('protocol', e) }
|
|
38
|
+
get protocol () { return this.Instance?.dataset.protocol || '' }
|
|
39
|
+
set playbackRate (e) { this.setProperty('playbackRate', e) }
|
|
40
|
+
get playbackRate () { return this.Instance?.playbackRate || 0 }
|
|
41
|
+
get duration () { return this.Instance?.duration || 0 }
|
|
42
|
+
get currentTime () { return this.Instance?.currentTime || 0 }
|
|
43
|
+
get paused () { return this.Instance?.paused || false }
|
|
44
|
+
get buffered () { return this.Instance?.buffered.length || 0 }
|
|
45
|
+
set referrerPolicy (e) { this.Instance?.setAttribute('referrerpolicy', e) }
|
|
46
|
+
get referrerPolicy () { return this.Instance?.getAttribute('referrerpolicy') || 'origin' }
|
|
47
|
+
|
|
48
|
+
private setProperty (key: string, value: unknown) {
|
|
49
|
+
if (this.Instance) {
|
|
50
|
+
this.Instance[key] = value
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private dataset (key: string, value: string) {
|
|
55
|
+
if (this.Instance) {
|
|
56
|
+
this.Instance.dataset[key] = value
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
play = () => this.Instance?.play()
|
|
61
|
+
|
|
62
|
+
pause = () => this.Instance?.pause()
|
|
63
|
+
|
|
64
|
+
seek = (position: number) => {
|
|
65
|
+
if (this.Instance) {
|
|
66
|
+
this.Instance.currentTime = position
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
stop = () => {
|
|
71
|
+
this.pause()
|
|
72
|
+
this.seek(0)
|
|
73
|
+
this.stopStack.trigger()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
onCanplay = (callback = () => {}) => this.Instance?.addEventListener('canplay', callback)
|
|
77
|
+
onWaiting = (callback = () => {}) => this.Instance?.addEventListener('waiting', callback)
|
|
78
|
+
onError = (callback?: ((res: Taro.InnerAudioContext.onErrorDetail) => void)) => this.errorStack.add(callback)
|
|
79
|
+
onPlay = (callback = () => {}) => this.Instance?.addEventListener('play', callback)
|
|
80
|
+
onPause = (callback = () => {}) => this.Instance?.addEventListener('pause', callback)
|
|
81
|
+
onSeeking = (callback = () => {}) => this.Instance?.addEventListener('seeking', callback)
|
|
82
|
+
onSeeked = (callback = () => {}) => this.Instance?.addEventListener('seeked', callback)
|
|
83
|
+
|
|
84
|
+
onEnded = (callback = () => {}) => this.Instance?.addEventListener('ended', callback)
|
|
85
|
+
onStop = (callback = () => {}) => this.stopStack.add(callback)
|
|
86
|
+
onTimeUpdate = (callback = () => {}) => this.Instance?.addEventListener('timeupdate', callback)
|
|
87
|
+
onPrev = permanentlyNotSupport('BackgroundAudioManager.onPrev')
|
|
88
|
+
onNext = permanentlyNotSupport('BackgroundAudioManager.onNext')
|
|
89
|
+
|
|
90
|
+
offCanplay = (callback = () => {}) => this.Instance?.removeEventListener('canplay', callback)
|
|
91
|
+
offWaiting = (callback = () => {}) => this.Instance?.removeEventListener('waiting', callback)
|
|
92
|
+
offError = (callback = () => {}) => this.errorStack.remove(callback)
|
|
93
|
+
offPlay = (callback = () => {}) => this.Instance?.removeEventListener('play', callback)
|
|
94
|
+
offPause = (callback = () => {}) => this.Instance?.removeEventListener('pause', callback)
|
|
95
|
+
offSeeking = (callback = () => {}) => this.Instance?.removeEventListener('seeking', callback)
|
|
96
|
+
offSeeked = (callback = () => {}) => this.Instance?.removeEventListener('seeked', callback)
|
|
97
|
+
|
|
98
|
+
offEnded = (callback = () => {}) => this.Instance?.removeEventListener('ended', callback)
|
|
99
|
+
offStop = (callback = () => {}) => this.stopStack.remove(callback)
|
|
100
|
+
offTimeUpdate = (callback = () => {}) => this.Instance?.removeEventListener('timeupdate', callback)
|
|
101
|
+
offPrev = permanentlyNotSupport('BackgroundAudioManager.offPrev')
|
|
102
|
+
offNext = permanentlyNotSupport('BackgroundAudioManager.offNext')
|
|
103
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils'
|
|
2
|
+
import { BackgroundAudioManager } from './BackgroundAudioManager'
|
|
2
3
|
|
|
3
4
|
// 背景音频
|
|
4
5
|
export const stopBackgroundAudio = temporarilyNotSupport('stopBackgroundAudio')
|
|
@@ -9,4 +10,8 @@ export const onBackgroundAudioStop = temporarilyNotSupport('onBackgroundAudioSto
|
|
|
9
10
|
export const onBackgroundAudioPlay = temporarilyNotSupport('onBackgroundAudioPlay')
|
|
10
11
|
export const onBackgroundAudioPause = temporarilyNotSupport('onBackgroundAudioPause')
|
|
11
12
|
export const getBackgroundAudioPlayerState = temporarilyNotSupport('getBackgroundAudioPlayerState')
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 获取全局唯一的背景音频管理器
|
|
16
|
+
*/
|
|
17
|
+
export const getBackgroundAudioManager = () => new BackgroundAudioManager()
|
package/src/api/media/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
XHR_STATS
|
|
9
9
|
} from './utils'
|
|
10
10
|
|
|
11
|
-
const createUploadTask = ({ url, filePath, formData, name, header, timeout, fileName, success, error }): Taro.UploadTask => {
|
|
11
|
+
const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, success, error }): Taro.UploadTask => {
|
|
12
12
|
let timeoutInter
|
|
13
13
|
let formKey
|
|
14
14
|
const apiName = 'uploadFile'
|
|
@@ -9,13 +9,17 @@ class StyleSheet {
|
|
|
9
9
|
this.$style = document.createElement('style')
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
$style
|
|
13
|
-
sheet?: CSSStyleSheet | null
|
|
12
|
+
$style?: HTMLStyleElement | null = null
|
|
13
|
+
sheet?: CSSStyleSheet | null = null
|
|
14
|
+
|
|
14
15
|
appendStyleSheet = () => {
|
|
15
|
-
this.$style
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (this.$style) {
|
|
17
|
+
const head = document.getElementsByTagName('head')[0]
|
|
18
|
+
this.$style.setAttribute('type', 'text/css')
|
|
19
|
+
this.$style.setAttribute('data-type', 'Taro')
|
|
20
|
+
head.appendChild(this.$style)
|
|
21
|
+
this.sheet = this.$style.sheet
|
|
22
|
+
}
|
|
19
23
|
if (this.sheet && !('insertRule' in this.sheet)) {
|
|
20
24
|
console.warn('当前浏览器不支持 stylesheet.insertRule 接口')
|
|
21
25
|
}
|
|
@@ -4,7 +4,7 @@ import { Current } from '@tarojs/runtime'
|
|
|
4
4
|
import { MethodHandler } from '../../utils/handler'
|
|
5
5
|
import { getTimingFunc, easeInOut } from '../../utils'
|
|
6
6
|
|
|
7
|
-
let timer:
|
|
7
|
+
let timer: NodeJS.Timer
|
|
8
8
|
const FRAME_DURATION = 17
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -21,9 +21,9 @@ export const pageScrollTo: typeof Taro.pageScrollTo = ({ scrollTop, selector = '
|
|
|
21
21
|
}, reject)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const id = Current.page?.path
|
|
24
|
+
const id = Current.page?.path?.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1')
|
|
25
25
|
const el: HTMLDivElement | null = (id
|
|
26
|
-
? document.
|
|
26
|
+
? document.querySelector(`.taro_page#${id}`)
|
|
27
27
|
: document.querySelector('.taro_page') ||
|
|
28
28
|
document.querySelector('.taro_router')) as HTMLDivElement
|
|
29
29
|
|
package/src/api/utils/index.ts
CHANGED
|
@@ -88,30 +88,51 @@ export function serializeParams (params) {
|
|
|
88
88
|
export function temporarilyNotSupport (apiName) {
|
|
89
89
|
return () => {
|
|
90
90
|
const errMsg = `暂时不支持 API ${apiName}`
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
92
|
+
console.error(errMsg)
|
|
93
|
+
return Promise.reject({
|
|
94
|
+
errMsg
|
|
95
|
+
})
|
|
96
|
+
} else {
|
|
97
|
+
console.warn(errMsg)
|
|
98
|
+
return Promise.resolve({
|
|
99
|
+
errMsg
|
|
100
|
+
})
|
|
101
|
+
}
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
export function weixinCorpSupport (apiName) {
|
|
99
106
|
return () => {
|
|
100
107
|
const errMsg = `h5端仅在微信公众号中支持 API ${apiName}`
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
109
|
+
console.error(errMsg)
|
|
110
|
+
return Promise.reject({
|
|
111
|
+
errMsg
|
|
112
|
+
})
|
|
113
|
+
} else {
|
|
114
|
+
console.warn(errMsg)
|
|
115
|
+
return Promise.resolve({
|
|
116
|
+
errMsg
|
|
117
|
+
})
|
|
118
|
+
}
|
|
105
119
|
}
|
|
106
120
|
}
|
|
107
121
|
|
|
108
122
|
export function permanentlyNotSupport (apiName) {
|
|
109
123
|
return () => {
|
|
110
124
|
const errMsg = `不支持 API ${apiName}`
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
125
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
126
|
+
console.error(errMsg)
|
|
127
|
+
return Promise.reject({
|
|
128
|
+
errMsg
|
|
129
|
+
})
|
|
130
|
+
} else {
|
|
131
|
+
console.warn(errMsg)
|
|
132
|
+
return Promise.resolve({
|
|
133
|
+
errMsg
|
|
134
|
+
})
|
|
135
|
+
}
|
|
115
136
|
}
|
|
116
137
|
}
|
|
117
138
|
|