@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
@@ -1,3 +1,5 @@
1
1
  import { temporarilyNotSupport } from '../utils';
2
+ // 判断支持版本
3
+ export const isVKSupport = temporarilyNotSupport('isVKSupport');
2
4
  // 视觉算法
3
5
  export const createVKSession = temporarilyNotSupport('createVKSession');
@@ -0,0 +1,187 @@
1
+ import MobileDetect from 'mobile-detect';
2
+ import { temporarilyNotSupport } from '../utils';
3
+ import { MethodHandler } from '../utils/handler';
4
+ /** 跳转系统蓝牙设置页 */
5
+ export const openSystemBluetoothSetting = temporarilyNotSupport('openSystemBluetoothSetting');
6
+ /** 跳转系统微信授权管理页 */
7
+ export const openAppAuthorizeSetting = temporarilyNotSupport('openAppAuthorizeSetting');
8
+ /** 获取窗口信息 */
9
+ export const getWindowInfo = () => {
10
+ const info = {
11
+ /** 设备像素比 */
12
+ pixelRatio: window.devicePixelRatio,
13
+ /** 屏幕宽度,单位px */
14
+ screenWidth: window.screen.width,
15
+ /** 屏幕高度,单位px */
16
+ screenHeight: window.screen.height,
17
+ /** 可使用窗口宽度,单位px */
18
+ windowWidth: document.documentElement.clientWidth,
19
+ /** 可使用窗口高度,单位px */
20
+ windowHeight: document.documentElement.clientHeight,
21
+ /** 状态栏的高度,单位px */
22
+ statusBarHeight: NaN,
23
+ /** 在竖屏正方向下的安全区域 */
24
+ safeArea: {
25
+ bottom: 0,
26
+ height: 0,
27
+ left: 0,
28
+ right: 0,
29
+ top: 0,
30
+ width: 0
31
+ }
32
+ };
33
+ return info;
34
+ };
35
+ /** 获取设备设置 */
36
+ export const getSystemSetting = () => {
37
+ const isLandscape = window.screen.width >= window.screen.height;
38
+ const info = {
39
+ /** 蓝牙的系统开关 */
40
+ bluetoothEnabled: false,
41
+ /** 地理位置的系统开关 */
42
+ locationEnabled: false,
43
+ /** Wi-Fi 的系统开关 */
44
+ wifiEnabled: false,
45
+ /** 设备方向 */
46
+ deviceOrientation: isLandscape ? 'landscape' : 'portrait'
47
+ };
48
+ return info;
49
+ };
50
+ /** 获取设备设置 */
51
+ export const getDeviceInfo = () => {
52
+ const md = new MobileDetect(navigator.userAgent);
53
+ const info = {
54
+ /** 应用二进制接口类型(仅 Android 支持) */
55
+ abi: '',
56
+ /** 设备性能等级(仅Android小游戏)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好,目前最高不到50) */
57
+ benchmarkLevel: -1,
58
+ /** 设备品牌 */
59
+ brand: md.mobile() || '',
60
+ /** 设备型号 */
61
+ model: md.mobile() || '',
62
+ /** 操作系统及版本 */
63
+ system: md.os(),
64
+ /** 客户端平台 */
65
+ platform: navigator.platform
66
+ };
67
+ return info;
68
+ };
69
+ /** 获取微信APP基础信息 */
70
+ export const getAppBaseInfo = () => {
71
+ var _a;
72
+ let isDarkMode = false;
73
+ if ((_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, '(prefers-color-scheme: dark)').matches) {
74
+ isDarkMode = true;
75
+ }
76
+ const info = {
77
+ /** 客户端基础库版本 */
78
+ SDKVersion: '',
79
+ /** 是否已打开调试。可通过右上角菜单或 [Taro.setEnableDebug](/docs/apis/base/debug/setEnableDebug) 打开调试。 */
80
+ enableDebug: process.env.NODE_ENV === 'development',
81
+ /** 当前小程序运行的宿主环境 */
82
+ // host: { appId: '' },
83
+ /** 微信设置的语言 */
84
+ language: navigator.language,
85
+ /** 微信版本号 */
86
+ version: '',
87
+ /** 系统当前主题,取值为light或dark,全局配置"darkmode":true时才能获取,否则为 undefined (不支持小游戏) */
88
+ theme: isDarkMode ? 'dark' : 'light'
89
+ };
90
+ return info;
91
+ };
92
+ /** 获取微信APP授权设置 */
93
+ export const getAppAuthorizeSetting = () => {
94
+ const info = {
95
+ /** 允许微信使用相册的开关(仅 iOS 有效) */
96
+ albumAuthorized: 'not determined',
97
+ /** 允许微信使用蓝牙的开关(仅 iOS 有效) */
98
+ bluetoothAuthorized: 'not determined',
99
+ /** 允许微信使用摄像头的开关 */
100
+ cameraAuthorized: 'not determined',
101
+ /** 允许微信使用定位的开关 */
102
+ locationAuthorized: 'not determined',
103
+ /** 定位准确度。true 表示模糊定位,false 表示精确定位(仅 iOS 有效) */
104
+ locationReducedAccuracy: false,
105
+ /** 允许微信使用麦克风的开关 */
106
+ microphoneAuthorized: 'not determined',
107
+ /** 允许微信通知的开关 */
108
+ notificationAuthorized: 'not determined',
109
+ /** 允许微信通知带有提醒的开关(仅 iOS 有效) */
110
+ notificationAlertAuthorized: 'not determined',
111
+ /** 允许微信通知带有标记的开关(仅 iOS 有效) */
112
+ notificationBadgeAuthorized: 'not determined',
113
+ /** 允许微信通知带有声音的开关(仅 iOS 有效) */
114
+ notificationSoundAuthorized: 'not determined',
115
+ /** 允许微信使用日历的开关 */
116
+ phoneCalendarAuthorized: 'not determined'
117
+ };
118
+ return info;
119
+ };
120
+ /** 获取设备设置 */
121
+ export const getSystemInfoSync = () => {
122
+ const windowInfo = getWindowInfo();
123
+ const systemSetting = getSystemSetting();
124
+ const deviceInfo = getDeviceInfo();
125
+ const appBaseInfo = getAppBaseInfo();
126
+ const appAuthorizeSetting = getAppAuthorizeSetting();
127
+ delete deviceInfo.abi;
128
+ const info = {
129
+ ...windowInfo,
130
+ ...systemSetting,
131
+ ...deviceInfo,
132
+ ...appBaseInfo,
133
+ /** 用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准 */
134
+ fontSizeSetting: NaN,
135
+ /** 允许微信使用相册的开关(仅 iOS 有效) */
136
+ albumAuthorized: appAuthorizeSetting.albumAuthorized === 'authorized',
137
+ /** 允许微信使用摄像头的开关 */
138
+ cameraAuthorized: appAuthorizeSetting.cameraAuthorized === 'authorized',
139
+ /** 允许微信使用定位的开关 */
140
+ locationAuthorized: appAuthorizeSetting.locationAuthorized === 'authorized',
141
+ /** 允许微信使用麦克风的开关 */
142
+ microphoneAuthorized: appAuthorizeSetting.microphoneAuthorized === 'authorized',
143
+ /** 允许微信通知的开关 */
144
+ notificationAuthorized: appAuthorizeSetting.notificationAuthorized === 'authorized',
145
+ /** 允许微信通知带有提醒的开关(仅 iOS 有效) */
146
+ notificationAlertAuthorized: appAuthorizeSetting.notificationAlertAuthorized === 'authorized',
147
+ /** 允许微信通知带有标记的开关(仅 iOS 有效) */
148
+ notificationBadgeAuthorized: appAuthorizeSetting.notificationBadgeAuthorized === 'authorized',
149
+ /** 允许微信通知带有声音的开关(仅 iOS 有效) */
150
+ notificationSoundAuthorized: appAuthorizeSetting.notificationSoundAuthorized === 'authorized',
151
+ /** 允许微信使用日历的开关 */
152
+ phoneCalendarAuthorized: appAuthorizeSetting.phoneCalendarAuthorized === 'authorized',
153
+ /** `true` 表示模糊定位,`false` 表示精确定位,仅 iOS 支持 */
154
+ locationReducedAccuracy: appAuthorizeSetting.locationReducedAccuracy,
155
+ /** 小程序当前运行环境 */
156
+ environment: ''
157
+ };
158
+ return info;
159
+ };
160
+ /** 获取系统信息 */
161
+ export const getSystemInfoAsync = async (options = {}) => {
162
+ const { success, fail, complete } = options;
163
+ const handle = new MethodHandler({ name: 'getSystemInfoAsync', success, fail, complete });
164
+ try {
165
+ const info = await getSystemInfoSync();
166
+ return handle.success(info);
167
+ }
168
+ catch (error) {
169
+ return handle.fail({
170
+ errMsg: error
171
+ });
172
+ }
173
+ };
174
+ /** 获取系统信息 */
175
+ export const getSystemInfo = async (options = {}) => {
176
+ const { success, fail, complete } = options;
177
+ const handle = new MethodHandler({ name: 'getSystemInfo', success, fail, complete });
178
+ try {
179
+ const info = await getSystemInfoSync();
180
+ return handle.success(info);
181
+ }
182
+ catch (error) {
183
+ return handle.fail({
184
+ errMsg: error
185
+ });
186
+ }
187
+ };
@@ -179,7 +179,7 @@ export class CanvasContext {
179
179
  transform(...args) { return this.enqueueActions(this.ctx.transform, ...args); }
180
180
  translate(...args) { return this.enqueueActions(this.ctx.translate, ...args); }
181
181
  measureText(text) {
182
- return this.measureText(text);
182
+ return this.ctx.measureText(text);
183
183
  }
184
184
  createCircularGradient(x, y, r) {
185
185
  const radialGradient = this.ctx.createRadialGradient(x, y, 0, x, y, r);
@@ -1,8 +1,12 @@
1
1
  import { temporarilyNotSupport } from '../utils';
2
2
  // 画布
3
+ /** 创建离屏 canvas 实例 */
3
4
  export const createOffscreenCanvas = temporarilyNotSupport('createOffscreenCanvas');
5
+ /** 创建 canvas 的绘图上下文 CanvasContext 对象 */
4
6
  export * from './createCanvasContext';
7
+ /** 把当前画布指定区域的内容导出生成指定大小的图片 */
5
8
  export * from './canvasToTempFilePath';
9
+ /** 将像素数据绘制到画布 */
6
10
  export * from './canvasPutImageData';
11
+ /** 获取 canvas 区域隐含的像素数据 */
7
12
  export * from './canvasGetImageData';
8
- export const drawCanvas = temporarilyNotSupport('drawCanvas');
@@ -3,15 +3,19 @@ export class cloud {
3
3
  constructor() {
4
4
  this.init = temporarilyNotSupport('cloud.init');
5
5
  this.CloudID = temporarilyNotSupport('cloud.CloudID');
6
+ // @ts-ignore
6
7
  this.callFunction = temporarilyNotSupport('cloud.callFunction');
7
8
  // @ts-ignore
8
9
  this.uploadFile = temporarilyNotSupport('cloud.uploadFile');
9
10
  // @ts-ignore
10
11
  this.downloadFile = temporarilyNotSupport('cloud.downloadFile');
12
+ // @ts-ignore
11
13
  this.getTempFileURL = temporarilyNotSupport('cloud.getTempFileURL');
14
+ // @ts-ignore
12
15
  this.deleteFile = temporarilyNotSupport('cloud.deleteFile');
13
16
  // @ts-ignore
14
17
  this.database = temporarilyNotSupport('cloud.database');
18
+ // @ts-ignore
15
19
  this.callContainer = temporarilyNotSupport('cloud.callContainer');
16
20
  }
17
21
  }
@@ -1,4 +1,21 @@
1
1
  import { temporarilyNotSupport } from '../utils';
2
+ import { MethodHandler } from '../utils/handler';
2
3
  // 电量
3
4
  export const getBatteryInfoSync = temporarilyNotSupport('getBatteryInfoSync');
4
- export const getBatteryInfo = temporarilyNotSupport('getBatteryInfo');
5
+ export const getBatteryInfo = async ({ success, fail, complete } = {}) => {
6
+ var _a;
7
+ const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete });
8
+ try {
9
+ // @ts-ignore
10
+ const battery = await ((_a = navigator.getBattery) === null || _a === void 0 ? void 0 : _a.call(navigator));
11
+ return handle.success({
12
+ isCharging: battery.charging,
13
+ level: Number(battery.level || 0) * 100
14
+ });
15
+ }
16
+ catch (error) {
17
+ return handle.fail({
18
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || error
19
+ });
20
+ }
21
+ };
@@ -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,5 +1,5 @@
1
- import { MethodHandler } from '../../utils/handler';
2
- import { temporarilyNotSupport } from '../../utils';
1
+ import { CallbackManager, MethodHandler } from '../utils/handler';
2
+ import { temporarilyNotSupport } from '../utils';
3
3
  function getConnection() {
4
4
  // @ts-ignore
5
5
  return navigator.connection || navigator.mozConnection || navigator.webkitConnection || navigator.msConnection;
@@ -45,19 +45,34 @@ export const getNetworkType = (options = {}) => {
45
45
  }
46
46
  return handle.success({ networkType });
47
47
  };
48
- export const onNetworkStatusChange = (cb) => {
48
+ const networkStatusManager = new CallbackManager();
49
+ const networkStatusListener = async () => {
50
+ const { networkType } = await getNetworkType();
51
+ const isConnected = networkType !== 'none';
52
+ const obj = { isConnected, networkType };
53
+ networkStatusManager.trigger(obj);
54
+ };
55
+ /**
56
+ * 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。
57
+ * - 出现三次以上连接超时
58
+ * - 出现三次 rtt 超过 400
59
+ * - 出现三次以上的丢包
60
+ * > 弱网事件通知规则是: 弱网状态变化时立即通知, 状态不变时 30s 内最多通知一次。
61
+ */
62
+ export const onNetworkWeakChange = temporarilyNotSupport('onNetworkWeakChange');
63
+ export const onNetworkStatusChange = callback => {
64
+ networkStatusManager.add(callback);
65
+ const connection = getConnection();
66
+ if (connection && networkStatusManager.count() === 1) {
67
+ connection.addEventListener('change', networkStatusListener);
68
+ }
69
+ };
70
+ export const offNetworkWeakChange = temporarilyNotSupport('offNetworkStatusChange');
71
+ export const offNetworkStatusChange = callback => {
72
+ networkStatusManager.remove(callback);
49
73
  const connection = getConnection();
50
- if (connection) {
51
- connection.addEventListener('change', function () {
52
- getNetworkType()
53
- .then(res => {
54
- const { networkType } = res;
55
- const isConnected = networkType !== 'none';
56
- const obj = { isConnected, networkType };
57
- cb(obj);
58
- });
59
- });
74
+ if (connection && networkStatusManager.count() === 0) {
75
+ connection.removeEventListener('change', networkStatusListener);
60
76
  }
61
77
  };
62
- export const offNetworkStatusChange = temporarilyNotSupport('offNetworkStatusChange');
63
78
  export const getLocalIPAddress = temporarilyNotSupport('getLocalIPAddress');
@@ -3,6 +3,7 @@ import { temporarilyNotSupport } from '../utils';
3
3
  export const stopWifi = temporarilyNotSupport('stopWifi');
4
4
  export const startWifi = temporarilyNotSupport('startWifi');
5
5
  export const setWifiList = temporarilyNotSupport('setWifiList');
6
+ export const onWifiConnectedWithPartialInfo = temporarilyNotSupport('onWifiConnectedWithPartialInfo');
6
7
  export const onWifiConnected = temporarilyNotSupport('onWifiConnected');
7
8
  export const onGetWifiList = temporarilyNotSupport('onGetWifiList');
8
9
  export const offWifiConnected = temporarilyNotSupport('offWifiConnected');
@@ -6,6 +6,7 @@ export class EditorContext {
6
6
  this.clear = temporarilyNotSupport('EditorContext.clear');
7
7
  this.format = temporarilyNotSupport('EditorContext.format');
8
8
  this.getContents = temporarilyNotSupport('EditorContext.getContents');
9
+ this.getSelectionText = temporarilyNotSupport('EditorContext.getSelectionText');
9
10
  this.insertDivider = temporarilyNotSupport('EditorContext.insertDivider');
10
11
  this.insertImage = temporarilyNotSupport('EditorContext.insertImage');
11
12
  this.insertText = temporarilyNotSupport('EditorContext.insertText');
@@ -0,0 +1,84 @@
1
+ import Taro from '@tarojs/api';
2
+ import { permanentlyNotSupport } from '../../utils';
3
+ import { CallbackManager } from '../../utils/handler';
4
+ export class InnerAudioContext {
5
+ constructor() {
6
+ this.__startTime = 0;
7
+ this.play = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.play(); };
8
+ this.pause = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.pause(); };
9
+ this.stop = () => {
10
+ this.pause();
11
+ this.seek(0);
12
+ this.stopStack.trigger();
13
+ };
14
+ this.seek = (position) => {
15
+ if (this.Instance) {
16
+ this.Instance.currentTime = position;
17
+ }
18
+ };
19
+ /**
20
+ * @TODO destroy得并不干净
21
+ */
22
+ this.destroy = () => {
23
+ this.stop();
24
+ if (this.Instance) {
25
+ document.body.removeChild(this.Instance);
26
+ this.Instance = undefined;
27
+ }
28
+ };
29
+ this.onCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('canplay', callback); };
30
+ this.onPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('play', callback); };
31
+ this.onPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('pause', callback); };
32
+ this.onStop = (callback = () => { }) => this.stopStack.add(callback);
33
+ this.onEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('ended', callback); };
34
+ this.onTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('timeupdate', callback); };
35
+ this.onError = (callback) => this.errorStack.add(callback);
36
+ this.onWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('waiting', callback); };
37
+ this.onSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeking', callback); };
38
+ this.onSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeked', callback); };
39
+ this.offCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('canplay', callback); };
40
+ this.offPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('play', callback); };
41
+ this.offPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('pause', callback); };
42
+ this.offStop = (callback = () => { }) => this.stopStack.remove(callback);
43
+ this.offEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('ended', callback); };
44
+ this.offTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('timeupdate', callback); };
45
+ this.offError = (callback = () => { }) => this.errorStack.remove(callback);
46
+ this.offWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('waiting', callback); };
47
+ this.offSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeking', callback); };
48
+ this.offSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeked', callback); };
49
+ this.Instance = new Audio();
50
+ this.errorStack = new CallbackManager();
51
+ this.stopStack = new CallbackManager();
52
+ Taro.eventCenter.on('__taroRouterChange', () => { this.stop(); });
53
+ this.onPlay(() => {
54
+ if (this.currentTime !== this.startTime) {
55
+ this.seek(this.startTime);
56
+ }
57
+ });
58
+ }
59
+ set autoplay(e) { this.setProperty('autoplay', e); }
60
+ get autoplay() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.autoplay) || false; }
61
+ get buffered() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.buffered.length) || 0; }
62
+ get currentTime() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.currentTime) || 0; }
63
+ get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
64
+ set loop(e) { this.setProperty('loop', e); }
65
+ get loop() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.loop) || false; }
66
+ get paused() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) || true; }
67
+ set src(e) { this.setProperty('src', e); }
68
+ get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
69
+ set volume(e) { this.setProperty('volume', e); }
70
+ get volume() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.volume) || 0; }
71
+ set playbackRate(e) { this.setProperty('playbackRate', e); }
72
+ get playbackRate() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.playbackRate) || 0; }
73
+ set obeyMuteSwitch(_e) { permanentlyNotSupport('InnerAudioContext.obeyMuteSwitch')(); }
74
+ get obeyMuteSwitch() { return true; }
75
+ set startTime(e) { this.__startTime = e; }
76
+ get startTime() { return this.__startTime || 0; }
77
+ set referrerPolicy(e) { var _a; (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.setAttribute('referrerpolicy', e); }
78
+ get referrerPolicy() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.getAttribute('referrerpolicy')) || 'origin'; }
79
+ setProperty(key, value) {
80
+ if (this.Instance) {
81
+ this.Instance[key] = value;
82
+ }
83
+ }
84
+ }
@@ -1,79 +1,6 @@
1
- import Taro from '@tarojs/api';
2
1
  import { temporarilyNotSupport } from '../../utils';
3
- import { CallbackManager } from '../../utils/handler';
2
+ import { InnerAudioContext } from './InnerAudioContext';
4
3
  // 音频
5
- class InnerAudioContext {
6
- constructor() {
7
- this.play = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.play(); };
8
- this.pause = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.pause(); };
9
- this.stop = () => {
10
- this.pause();
11
- this.seek(0);
12
- this.stopStack.trigger();
13
- };
14
- this.seek = (position) => {
15
- if (this.Instance) {
16
- this.Instance.currentTime = position;
17
- }
18
- };
19
- /**
20
- * @TODO destroy得并不干净
21
- */
22
- this.destroy = () => {
23
- this.stop();
24
- if (this.Instance) {
25
- document.body.removeChild(this.Instance);
26
- this.Instance = undefined;
27
- }
28
- };
29
- this.onCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('canplay', callback); };
30
- this.onPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('play', callback); };
31
- this.onPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('pause', callback); };
32
- this.onStop = (callback = () => { }) => this.stopStack.add(callback);
33
- this.onEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('ended', callback); };
34
- this.onTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('timeupdate', callback); };
35
- this.onError = (callback) => this.errorStack.add(callback);
36
- this.onWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('waiting', callback); };
37
- this.onSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeking', callback); };
38
- this.onSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeked', callback); };
39
- this.offCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('canplay', callback); };
40
- this.offPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('play', callback); };
41
- this.offPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('pause', callback); };
42
- this.offStop = (callback = () => { }) => this.stopStack.remove(callback);
43
- this.offEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('ended', callback); };
44
- this.offTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('timeupdate', callback); };
45
- this.offError = (callback = () => { }) => this.errorStack.remove(callback);
46
- this.offWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('waiting', callback); };
47
- this.offSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeking', callback); };
48
- this.offSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeked', callback); };
49
- this.Instance = new Audio();
50
- this.errorStack = new CallbackManager();
51
- this.stopStack = new CallbackManager();
52
- Taro.eventCenter.on('__taroRouterChange', () => { this.stop(); });
53
- }
54
- set autoplay(e) { this.setProperty('autoplay', e); }
55
- get autoplay() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.autoplay) || false; }
56
- get buffered() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.buffered.length) || 0; }
57
- get currentTime() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.currentTime) || 0; }
58
- get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
59
- set loop(e) { this.setProperty('loop', e); }
60
- get loop() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.loop) || false; }
61
- get paused() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) || true; }
62
- set src(e) { this.setProperty('src', e); }
63
- get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
64
- set volume(e) { this.setProperty('volume', e); }
65
- get volume() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.volume) || 0; }
66
- set playbackRate(e) { this.setProperty('playbackRate', e); }
67
- get playbackRate() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.volume) || 0; }
68
- get obeyMuteSwitch() { return true; }
69
- set startTime(e) { this.setProperty('startTime', e); }
70
- get startTime() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.volume) || 0; }
71
- setProperty(key, value) {
72
- if (this.Instance) {
73
- this.Instance[key] = value;
74
- }
75
- }
76
- }
77
4
  export const stopVoice = temporarilyNotSupport('stopVoice');
78
5
  export const setInnerAudioOption = temporarilyNotSupport('setInnerAudioOption');
79
6
  export const playVoice = temporarilyNotSupport('playVoice');
@@ -0,0 +1,86 @@
1
+ import { permanentlyNotSupport } from '../../utils';
2
+ import { CallbackManager } from '../../utils/handler';
3
+ export class BackgroundAudioManager {
4
+ constructor() {
5
+ this.__startTime = 0;
6
+ this.play = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.play(); };
7
+ this.pause = () => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.pause(); };
8
+ this.seek = (position) => {
9
+ if (this.Instance) {
10
+ this.Instance.currentTime = position;
11
+ }
12
+ };
13
+ this.stop = () => {
14
+ this.pause();
15
+ this.seek(0);
16
+ this.stopStack.trigger();
17
+ };
18
+ this.onCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('canplay', callback); };
19
+ this.onWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('waiting', callback); };
20
+ this.onError = (callback) => this.errorStack.add(callback);
21
+ this.onPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('play', callback); };
22
+ this.onPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('pause', callback); };
23
+ this.onSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeking', callback); };
24
+ this.onSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('seeked', callback); };
25
+ this.onEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('ended', callback); };
26
+ this.onStop = (callback = () => { }) => this.stopStack.add(callback);
27
+ this.onTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.addEventListener('timeupdate', callback); };
28
+ this.onPrev = permanentlyNotSupport('BackgroundAudioManager.onPrev');
29
+ this.onNext = permanentlyNotSupport('BackgroundAudioManager.onNext');
30
+ this.offCanplay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('canplay', callback); };
31
+ this.offWaiting = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('waiting', callback); };
32
+ this.offError = (callback = () => { }) => this.errorStack.remove(callback);
33
+ this.offPlay = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('play', callback); };
34
+ this.offPause = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('pause', callback); };
35
+ this.offSeeking = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeking', callback); };
36
+ this.offSeeked = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('seeked', callback); };
37
+ this.offEnded = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('ended', callback); };
38
+ this.offStop = (callback = () => { }) => this.stopStack.remove(callback);
39
+ this.offTimeUpdate = (callback = () => { }) => { var _a; return (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.removeEventListener('timeupdate', callback); };
40
+ this.offPrev = permanentlyNotSupport('BackgroundAudioManager.offPrev');
41
+ this.offNext = permanentlyNotSupport('BackgroundAudioManager.offNext');
42
+ this.Instance = new Audio();
43
+ this.errorStack = new CallbackManager();
44
+ this.stopStack = new CallbackManager();
45
+ this.Instance.autoplay = true;
46
+ this.onPlay(() => {
47
+ if (this.currentTime !== this.startTime) {
48
+ this.seek(this.startTime);
49
+ }
50
+ });
51
+ }
52
+ set src(e) { this.setProperty('src', e); }
53
+ get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
54
+ set startTime(e) { this.__startTime = e; }
55
+ get startTime() { return this.__startTime || 0; }
56
+ set title(e) { this.dataset('title', e); }
57
+ get title() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.title) || ''; }
58
+ set epname(e) { this.dataset('epname', e); }
59
+ get epname() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.epname) || ''; }
60
+ set singer(e) { this.dataset('singer', e); }
61
+ get singer() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.singer) || ''; }
62
+ set coverImgUrl(e) { this.dataset('coverImgUrl', e); }
63
+ get coverImgUrl() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.coverImgUrl) || ''; }
64
+ set webUrl(e) { this.dataset('webUrl', e); }
65
+ get webUrl() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.webUrl) || ''; }
66
+ set protocol(e) { this.dataset('protocol', e); }
67
+ get protocol() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.dataset.protocol) || ''; }
68
+ set playbackRate(e) { this.setProperty('playbackRate', e); }
69
+ get playbackRate() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.playbackRate) || 0; }
70
+ get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
71
+ get currentTime() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.currentTime) || 0; }
72
+ get paused() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) || false; }
73
+ get buffered() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.buffered.length) || 0; }
74
+ set referrerPolicy(e) { var _a; (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.setAttribute('referrerpolicy', e); }
75
+ get referrerPolicy() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.getAttribute('referrerpolicy')) || 'origin'; }
76
+ setProperty(key, value) {
77
+ if (this.Instance) {
78
+ this.Instance[key] = value;
79
+ }
80
+ }
81
+ dataset(key, value) {
82
+ if (this.Instance) {
83
+ this.Instance.dataset[key] = value;
84
+ }
85
+ }
86
+ }
@@ -1,4 +1,5 @@
1
- import { temporarilyNotSupport } from '../utils';
1
+ import { temporarilyNotSupport } from '../../utils';
2
+ import { BackgroundAudioManager } from './BackgroundAudioManager';
2
3
  // 背景音频
3
4
  export const stopBackgroundAudio = temporarilyNotSupport('stopBackgroundAudio');
4
5
  export const seekBackgroundAudio = temporarilyNotSupport('seekBackgroundAudio');
@@ -8,4 +9,7 @@ export const onBackgroundAudioStop = temporarilyNotSupport('onBackgroundAudioSto
8
9
  export const onBackgroundAudioPlay = temporarilyNotSupport('onBackgroundAudioPlay');
9
10
  export const onBackgroundAudioPause = temporarilyNotSupport('onBackgroundAudioPause');
10
11
  export const getBackgroundAudioPlayerState = temporarilyNotSupport('getBackgroundAudioPlayerState');
11
- export const getBackgroundAudioManager = temporarilyNotSupport('getBackgroundAudioManager');
12
+ /**
13
+ * 获取全局唯一的背景音频管理器
14
+ */
15
+ export const getBackgroundAudioManager = () => new BackgroundAudioManager();
@@ -1,7 +1,6 @@
1
1
  export * from './audio';
2
2
  export * from './background-audio';
3
3
  export * from './camera';
4
- export * from './editor';
5
4
  export * from './image';
6
5
  export * from './live';
7
6
  export * from './map';