vite-plugin-taro-runtime 0.8.10 → 0.8.11
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/components/dist/components/taro-pull-to-refresh-core.js +6 -2
- package/dist/components/dist/components/taro-video-core.js +1 -1
- package/dist/components/dist/components/video-control.js +2 -1
- package/dist/components/types/ScrollView.d.ts +5 -0
- package/dist/plugin-framework-react/runtime.js +3 -1
- package/dist/plugin-framework-react/runtime.js.map +1 -1
- package/dist/plugin-platform-h5/definition.json +13 -17
- package/dist/plugin-platform-weapp/runtime-utils.js +1 -0
- package/dist/plugin-platform-weapp/runtime-utils.js.map +1 -1
- package/dist/plugin-platform-weapp/runtime.js +1 -0
- package/dist/plugin-platform-weapp/runtime.js.map +1 -1
- package/dist/plugin-platform-weapp/types/components.d.ts +1 -0
- package/dist/router/dist/index.esm.js +32 -20
- package/dist/router/dist/router/mpa.d.ts +6 -1
- package/dist/router/dist/router/navigation-bar.d.ts +1 -1
- package/dist/router/dist/router/spa.d.ts +7 -1
- package/dist/runtime/current.js +36 -1
- package/dist/runtime/current.js.map +1 -1
- package/dist/runtime/dsl/common.js.map +1 -1
- package/dist/runtime/runtime.esm.js +40 -3
- package/dist/runtime/runtime.esm.js.map +1 -1
- package/dist/taro/package.json +9 -9
- package/dist/taro/types/api/base/crypto.d.ts +2 -1
- package/dist/taro/types/api/device/gyroscope.d.ts +4 -4
- package/dist/taro/types/api/device/keyboard.d.ts +1 -1
- package/dist/taro/types/api/device/screen.d.ts +2 -1
- package/dist/taro/types/api/storage/index.d.ts +11 -4
- package/dist/taro-h5/dist/api/device/crypto.d.ts +6 -1
- package/dist/taro-h5/dist/api/device/crypto.js +47 -2
- package/dist/taro-h5/dist/api/device/crypto.js.map +1 -1
- package/dist/taro-h5/dist/api/device/gyroscope.d.ts +18 -4
- package/dist/taro-h5/dist/api/device/gyroscope.js +115 -6
- package/dist/taro-h5/dist/api/device/gyroscope.js.map +1 -1
- package/dist/taro-h5/dist/api/device/keyboard.d.ts +3 -1
- package/dist/taro-h5/dist/api/device/keyboard.js +11 -1
- package/dist/taro-h5/dist/api/device/keyboard.js.map +1 -1
- package/dist/taro-h5/dist/api/device/screen.d.ts +6 -1
- package/dist/taro-h5/dist/api/device/screen.js +103 -2
- package/dist/taro-h5/dist/api/device/screen.js.map +1 -1
- package/dist/taro-h5/dist/api/location/chooseLocation.js +46 -18
- package/dist/taro-h5/dist/api/location/chooseLocation.js.map +1 -1
- package/dist/taro-h5/dist/api/media/image/previewImage.js +7 -3
- package/dist/taro-h5/dist/api/media/image/previewImage.js.map +1 -1
- package/dist/taro-h5/dist/api/media/video/getVideoInfo.js +5 -2
- package/dist/taro-h5/dist/api/media/video/getVideoInfo.js.map +1 -1
- package/dist/taro-h5/dist/api/network/download.js +27 -19
- package/dist/taro-h5/dist/api/network/download.js.map +1 -1
- package/dist/taro-h5/dist/api/network/request/index.js +15 -9
- package/dist/taro-h5/dist/api/network/request/index.js.map +1 -1
- package/dist/taro-h5/dist/api/network/upload.js +29 -21
- package/dist/taro-h5/dist/api/network/upload.js.map +1 -1
- package/dist/taro-h5/dist/api/network/utils.d.ts +7 -0
- package/dist/taro-h5/dist/api/network/utils.js +10 -1
- package/dist/taro-h5/dist/api/network/utils.js.map +1 -1
- package/dist/taro-h5/dist/api/ui/animation/index.js +54 -34
- package/dist/taro-h5/dist/api/ui/animation/index.js.map +1 -1
- package/dist/taro-h5/dist/api/ui/interaction/actionSheet.d.ts +1 -0
- package/dist/taro-h5/dist/api/ui/interaction/actionSheet.js +12 -5
- package/dist/taro-h5/dist/api/ui/interaction/actionSheet.js.map +1 -1
- package/dist/taro-h5/dist/api/ui/interaction/modal.d.ts +1 -0
- package/dist/taro-h5/dist/api/ui/interaction/modal.js +12 -5
- package/dist/taro-h5/dist/api/ui/interaction/modal.js.map +1 -1
- package/dist/taro-h5/dist/api/ui/interaction/toast.js +9 -5
- package/dist/taro-h5/dist/api/ui/interaction/toast.js.map +1 -1
- package/dist/taro-h5/dist/api/ui/pull-down-refresh.js +23 -16
- package/dist/taro-h5/dist/api/ui/pull-down-refresh.js.map +1 -1
- package/dist/taro-h5/dist/api/ui/scroll/index.js +54 -23
- package/dist/taro-h5/dist/api/ui/scroll/index.js.map +1 -1
- package/dist/taro-h5/dist/api/ui/window.js +2 -2
- package/dist/taro-h5/dist/api/ui/window.js.map +1 -1
- package/dist/taro-h5/dist/api/wxml/MediaQueryObserver.d.ts +2 -2
- package/dist/taro-h5/dist/api/wxml/MediaQueryObserver.js +7 -2
- package/dist/taro-h5/dist/api/wxml/MediaQueryObserver.js.map +1 -1
- package/dist/taro-h5/dist/api/wxml/selectorQuery.js +4 -4
- package/dist/taro-h5/dist/api/wxml/selectorQuery.js.map +1 -1
- package/dist/taro-h5/dist/utils/index.js +1 -1
- package/dist/taro-h5/dist/utils/index.js.map +1 -1
- package/package.json +15 -15
package/dist/taro/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/taro",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.3",
|
|
4
4
|
"description": "Taro framework",
|
|
5
5
|
"author": "O2Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@types/postcss-url": "^10.0.4",
|
|
27
|
-
"@tarojs/
|
|
28
|
-
"@tarojs/
|
|
27
|
+
"@tarojs/api": "4.3.3",
|
|
28
|
+
"@tarojs/runtime": "4.3.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"html-webpack-plugin": "^5.6.0",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"webpack-chain": "^6.5.1",
|
|
34
34
|
"webpack-dev-server": "^4.15.2",
|
|
35
35
|
"rollup": "^3.29.4",
|
|
36
|
-
"@tarojs/components": "4.3.
|
|
37
|
-
"@tarojs/helper": "4.3.
|
|
38
|
-
"@tarojs/shared": "4.3.
|
|
36
|
+
"@tarojs/components": "4.3.3",
|
|
37
|
+
"@tarojs/helper": "4.3.3",
|
|
38
|
+
"@tarojs/shared": "4.3.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@types/react": "^18",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"webpack": "^5",
|
|
47
47
|
"webpack-chain": "^6",
|
|
48
48
|
"webpack-dev-server": "^4",
|
|
49
|
-
"@tarojs/
|
|
50
|
-
"@tarojs/
|
|
51
|
-
"@tarojs/shared": "4.3.
|
|
49
|
+
"@tarojs/helper": "4.3.3",
|
|
50
|
+
"@tarojs/components": "4.3.3",
|
|
51
|
+
"@tarojs/shared": "4.3.3"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
54
|
"@types/react": {
|
|
@@ -53,19 +53,19 @@ declare module '../../index' {
|
|
|
53
53
|
|
|
54
54
|
interface TaroStatic {
|
|
55
55
|
/** 停止监听陀螺仪数据。
|
|
56
|
-
* @supported weapp, alipay, swan, jd, qq, tt, rn
|
|
56
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn
|
|
57
57
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/gyroscope/wx.stopGyroscope.html
|
|
58
58
|
*/
|
|
59
59
|
stopGyroscope(option?: stopGyroscope.Option): Promise<TaroGeneral.CallbackResult>
|
|
60
60
|
|
|
61
61
|
/** 开始监听陀螺仪数据。
|
|
62
|
-
* @supported weapp,
|
|
62
|
+
* @supported weapp, tt, h5, rn
|
|
63
63
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/gyroscope/wx.startGyroscope.html
|
|
64
64
|
*/
|
|
65
65
|
startGyroscope(option: startGyroscope.Option): Promise<TaroGeneral.CallbackResult>
|
|
66
66
|
|
|
67
67
|
/** 监听陀螺仪数据变化事件。频率根据 Taro.startGyroscope() 的 interval 参数。可以使用 Taro.stopGyroscope() 停止监听。
|
|
68
|
-
* @supported weapp, alipay, swan, jd, qq, tt, rn
|
|
68
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn
|
|
69
69
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/gyroscope/wx.onGyroscopeChange.html
|
|
70
70
|
*/
|
|
71
71
|
onGyroscopeChange(
|
|
@@ -74,7 +74,7 @@ declare module '../../index' {
|
|
|
74
74
|
): void
|
|
75
75
|
|
|
76
76
|
/** 取消监听陀螺仪数据变化事件。
|
|
77
|
-
* @supported weapp, alipay, swan, jd, tt, rn
|
|
77
|
+
* @supported weapp, alipay, swan, jd, tt, h5, rn
|
|
78
78
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/gyroscope/wx.offGyroscopeChange.html
|
|
79
79
|
*/
|
|
80
80
|
offGyroscopeChange(
|
|
@@ -57,7 +57,7 @@ declare module '../../index' {
|
|
|
57
57
|
hideKeyboard(option?: hideKeyboard.Option): Promise<TaroGeneral.CallbackResult>
|
|
58
58
|
|
|
59
59
|
/** 在input、textarea等focus之后,获取输入框的光标位置。注意:只有在focus的时候调用此接口才有效。
|
|
60
|
-
* @supported weapp
|
|
60
|
+
* @supported weapp, h5
|
|
61
61
|
* @example
|
|
62
62
|
* ```tsx
|
|
63
63
|
* Taro.getSelectedTextRange({
|
|
@@ -123,7 +123,8 @@ declare module '../../index' {
|
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* 设置是否保持常亮状态。仅在当前小程序生效,离开小程序后设置失效。
|
|
126
|
-
* @supported weapp, alipay, swan, jd, qq, tt, rn, harmony_hybrid
|
|
126
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn, harmony_hybrid
|
|
127
|
+
* @h5 基于 Screen Wake Lock API 实现,仅在安全上下文(如 HTTPS 或 localhost)中可用
|
|
127
128
|
* @example
|
|
128
129
|
* ```tsx
|
|
129
130
|
* // 保持屏幕常亮
|
|
@@ -14,17 +14,24 @@ declare module '../../index' {
|
|
|
14
14
|
| Float64Array
|
|
15
15
|
|
|
16
16
|
namespace setStorage {
|
|
17
|
+
interface Result extends TaroGeneral.CallbackResult {
|
|
18
|
+
/** 是否执行成功
|
|
19
|
+
* @supported alipay
|
|
20
|
+
*/
|
|
21
|
+
success?: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
17
24
|
interface Option {
|
|
18
25
|
/** 需要存储的内容。只支持原生类型、Date、及能够通过`JSON.stringify`序列化的对象。 */
|
|
19
26
|
data: any
|
|
20
27
|
/** 本地缓存中指定的 key */
|
|
21
28
|
key: string
|
|
22
29
|
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
23
|
-
complete?: (res:
|
|
30
|
+
complete?: (res: Result) => void
|
|
24
31
|
/** 接口调用失败的回调函数 */
|
|
25
|
-
fail?: (res:
|
|
32
|
+
fail?: (res: Result) => void
|
|
26
33
|
/** 接口调用成功的回调函数 */
|
|
27
|
-
success?: (res:
|
|
34
|
+
success?: (res: Result) => void
|
|
28
35
|
}
|
|
29
36
|
}
|
|
30
37
|
|
|
@@ -179,7 +186,7 @@ declare module '../../index' {
|
|
|
179
186
|
* ```
|
|
180
187
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.setStorage.html
|
|
181
188
|
*/
|
|
182
|
-
setStorage(option: setStorage.Option): Promise<
|
|
189
|
+
setStorage(option: setStorage.Option): Promise<setStorage.Result>
|
|
183
190
|
|
|
184
191
|
/** 根据 URL 销毁存在内存中的数据
|
|
185
192
|
* @supported weapp
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="types/api" />
|
|
2
|
+
import Taro from 'vite-plugin-taro-runtime/api';
|
|
3
|
+
/**
|
|
4
|
+
* 获取密码学安全随机数
|
|
5
|
+
*/
|
|
6
|
+
export declare const getRandomValues: typeof Taro.getRandomValues;
|
|
@@ -1,7 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { shouldBeObject, getParameterError } from '../../utils/index.js';
|
|
2
|
+
import { MethodHandler } from '../../utils/handler.js';
|
|
2
3
|
|
|
4
|
+
/** 单次最多可生成的随机数字节数 */
|
|
5
|
+
const MAX_LENGTH = 1048576;
|
|
6
|
+
/** Note: crypto.getRandomValues 单次最多只能填充 65536 字节,超出会抛出 QuotaExceededError */
|
|
7
|
+
const MAX_CHUNK_LENGTH = 65536;
|
|
3
8
|
// 加密
|
|
4
|
-
|
|
9
|
+
/**
|
|
10
|
+
* 获取密码学安全随机数
|
|
11
|
+
*/
|
|
12
|
+
const getRandomValues = (options) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const name = 'getRandomValues';
|
|
15
|
+
// options must be an Object
|
|
16
|
+
const isObject = shouldBeObject(options);
|
|
17
|
+
if (!isObject.flag) {
|
|
18
|
+
const res = { errMsg: `${name}:fail ${isObject.msg}` };
|
|
19
|
+
console.error(res.errMsg);
|
|
20
|
+
return Promise.reject(res);
|
|
21
|
+
}
|
|
22
|
+
const { length, success, fail, complete } = options;
|
|
23
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
24
|
+
if (typeof length !== 'number') {
|
|
25
|
+
return handle.fail({
|
|
26
|
+
errMsg: getParameterError({
|
|
27
|
+
para: 'length',
|
|
28
|
+
correct: 'Number',
|
|
29
|
+
wrong: length
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (!Number.isInteger(length) || length <= 0 || length > MAX_LENGTH) {
|
|
34
|
+
return handle.fail({ errMsg: `parameter error: parameter.length should be an integer between 1 and ${MAX_LENGTH}` });
|
|
35
|
+
}
|
|
36
|
+
if (typeof ((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.getRandomValues) !== 'function') {
|
|
37
|
+
return handle.fail({ errMsg: 'crypto.getRandomValues is not supported' });
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const randomValues = new ArrayBuffer(length);
|
|
41
|
+
for (let offset = 0; offset < length; offset += MAX_CHUNK_LENGTH) {
|
|
42
|
+
window.crypto.getRandomValues(new Uint8Array(randomValues, offset, Math.min(MAX_CHUNK_LENGTH, length - offset)));
|
|
43
|
+
}
|
|
44
|
+
return handle.success({ randomValues });
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
return handle.fail({ errMsg: e.message });
|
|
48
|
+
}
|
|
49
|
+
};
|
|
5
50
|
|
|
6
51
|
export { getRandomValues };
|
|
7
52
|
//# sourceMappingURL=crypto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sources":["../../../src/api/device/crypto.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"crypto.js","sources":["../../../src/api/device/crypto.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAKA;AACA,MAAM,UAAU,GAAG,OAAO,CAAA;AAC1B;AACA,MAAM,gBAAgB,GAAG,KAAK,CAAA;AAE9B;AACA;;AAEG;AACU,MAAA,eAAe,GAAgC,CAAC,OAAO,KAAI;;IACtE,MAAM,IAAI,GAAG,iBAAiB,CAAA;;AAE9B,IAAA,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;AACxC,IAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;AAClB,QAAA,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,CAAA,EAAG,IAAI,CAAA,MAAA,EAAS,QAAQ,CAAC,GAAG,CAAA,CAAE,EAAE,CAAA;AACtD,QAAA,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACzB,QAAA,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;KAC3B;IAED,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;AACnD,IAAA,MAAM,MAAM,GAAG,IAAI,aAAa,CAA+D,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;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,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;KAC1C;AACH;;;;"}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/// <reference types="types/api" />
|
|
2
|
+
import Taro from 'vite-plugin-taro-runtime/api';
|
|
3
|
+
/**
|
|
4
|
+
* 停止监听陀螺仪数据。
|
|
5
|
+
*/
|
|
6
|
+
export declare const stopGyroscope: typeof Taro.stopGyroscope;
|
|
7
|
+
/**
|
|
8
|
+
* 开始监听陀螺仪数据。
|
|
9
|
+
*/
|
|
10
|
+
export declare const startGyroscope: typeof Taro.startGyroscope;
|
|
11
|
+
/**
|
|
12
|
+
* 监听陀螺仪数据变化事件。频率根据 Taro.startGyroscope() 的 interval 参数。可以使用 Taro.stopGyroscope() 停止监听。
|
|
13
|
+
*/
|
|
14
|
+
export declare const onGyroscopeChange: typeof Taro.onGyroscopeChange;
|
|
15
|
+
/**
|
|
16
|
+
* 取消监听陀螺仪数据变化事件,参数为空,则取消所有的事件监听。
|
|
17
|
+
*/
|
|
18
|
+
export declare const offGyroscopeChange: typeof Taro.offGyroscopeChange;
|
|
@@ -1,10 +1,119 @@
|
|
|
1
|
-
import
|
|
1
|
+
import throttle from 'lodash-es/throttle';
|
|
2
|
+
import { CallbackManager, MethodHandler } from '../../utils/handler.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
4
|
+
const callbackManager = new CallbackManager();
|
|
5
|
+
let gyroscopeListener;
|
|
6
|
+
let gyroscopeThrottled;
|
|
7
|
+
const INTERVAL_MAP = {
|
|
8
|
+
game: {
|
|
9
|
+
interval: 20,
|
|
10
|
+
frequency: 50
|
|
11
|
+
},
|
|
12
|
+
ui: {
|
|
13
|
+
interval: 60,
|
|
14
|
+
frequency: 16.67
|
|
15
|
+
},
|
|
16
|
+
normal: {
|
|
17
|
+
interval: 200,
|
|
18
|
+
frequency: 5
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/** Note: devicemotion 事件中 rotationRate 的单位为 deg/s,小程序端陀螺仪数据的单位为 rad/s */
|
|
22
|
+
const DEG_TO_RAD = Math.PI / 180;
|
|
23
|
+
/** 每次 start / stop 递增,用于丢弃等待授权期间已被取代的 startGyroscope 请求 */
|
|
24
|
+
let startToken = 0;
|
|
25
|
+
function removeGyroscopeListener() {
|
|
26
|
+
if (gyroscopeListener) {
|
|
27
|
+
window.removeEventListener('devicemotion', gyroscopeListener, true);
|
|
28
|
+
gyroscopeThrottled === null || gyroscopeThrottled === void 0 ? void 0 : gyroscopeThrottled.cancel();
|
|
29
|
+
gyroscopeListener = undefined;
|
|
30
|
+
gyroscopeThrottled = undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 停止监听陀螺仪数据。
|
|
35
|
+
*/
|
|
36
|
+
const stopGyroscope = ({ success, fail, complete } = {}) => {
|
|
37
|
+
const handle = new MethodHandler({ name: 'stopGyroscope', success, fail, complete });
|
|
38
|
+
try {
|
|
39
|
+
startToken++;
|
|
40
|
+
removeGyroscopeListener();
|
|
41
|
+
return handle.success();
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return handle.fail({ errMsg: e.message });
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 开始监听陀螺仪数据。
|
|
49
|
+
*/
|
|
50
|
+
const startGyroscope = ({ interval = 'normal', success, fail, complete } = {}) => {
|
|
51
|
+
const handle = new MethodHandler({ name: 'startGyroscope', success, fail, complete });
|
|
52
|
+
try {
|
|
53
|
+
if (!window.DeviceMotionEvent) {
|
|
54
|
+
throw new Error('gyroscope is not supported');
|
|
55
|
+
}
|
|
56
|
+
const intervalObj = INTERVAL_MAP[interval];
|
|
57
|
+
if (!intervalObj) {
|
|
58
|
+
throw new Error('invalid interval');
|
|
59
|
+
}
|
|
60
|
+
const token = ++startToken;
|
|
61
|
+
const listen = () => {
|
|
62
|
+
removeGyroscopeListener();
|
|
63
|
+
/**
|
|
64
|
+
* Note: rotationRate 的 alpha、beta、gamma 分别为设备绕 x、y、z 轴旋转的角速度
|
|
65
|
+
* @see https://w3c.github.io/deviceorientation/#devicemotioneventrotationrate
|
|
66
|
+
*/
|
|
67
|
+
gyroscopeThrottled = throttle((rotationRate) => {
|
|
68
|
+
callbackManager.trigger({
|
|
69
|
+
x: (rotationRate.alpha || 0) * DEG_TO_RAD,
|
|
70
|
+
y: (rotationRate.beta || 0) * DEG_TO_RAD,
|
|
71
|
+
z: (rotationRate.gamma || 0) * DEG_TO_RAD
|
|
72
|
+
});
|
|
73
|
+
}, intervalObj.interval);
|
|
74
|
+
const throttled = gyroscopeThrottled;
|
|
75
|
+
gyroscopeListener = (evt) => {
|
|
76
|
+
// 设备无法提供陀螺仪数据时 rotationRate 为 null,此时不应当作静止读数上报。
|
|
77
|
+
// 需要在节流之前过滤,否则空读数会顶掉节流窗口内待派发的有效读数
|
|
78
|
+
if (!evt.rotationRate)
|
|
79
|
+
return;
|
|
80
|
+
throttled(evt.rotationRate);
|
|
81
|
+
};
|
|
82
|
+
window.addEventListener('devicemotion', gyroscopeListener, true);
|
|
83
|
+
};
|
|
84
|
+
// iOS 13+ Safari 需要在用户交互中调用 requestPermission,授权后才会派发 devicemotion 事件
|
|
85
|
+
const requestPermission = window.DeviceMotionEvent.requestPermission;
|
|
86
|
+
if (typeof requestPermission !== 'function') {
|
|
87
|
+
listen();
|
|
88
|
+
return handle.success();
|
|
89
|
+
}
|
|
90
|
+
return requestPermission.call(window.DeviceMotionEvent).then(state => {
|
|
91
|
+
if (state !== 'granted') {
|
|
92
|
+
return handle.fail({ errMsg: 'permission denied' });
|
|
93
|
+
}
|
|
94
|
+
if (token !== startToken) {
|
|
95
|
+
return handle.fail({ errMsg: 'start was interrupted by a later start or stop call' });
|
|
96
|
+
}
|
|
97
|
+
listen();
|
|
98
|
+
return handle.success();
|
|
99
|
+
}, (e) => handle.fail({ errMsg: (e === null || e === void 0 ? void 0 : e.message) || 'permission request failed' }));
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
return handle.fail({ errMsg: e.message });
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* 监听陀螺仪数据变化事件。频率根据 Taro.startGyroscope() 的 interval 参数。可以使用 Taro.stopGyroscope() 停止监听。
|
|
107
|
+
*/
|
|
108
|
+
const onGyroscopeChange = callback => {
|
|
109
|
+
callbackManager.add(callback);
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* 取消监听陀螺仪数据变化事件,参数为空,则取消所有的事件监听。
|
|
113
|
+
*/
|
|
114
|
+
const offGyroscopeChange = callback => {
|
|
115
|
+
callbackManager.remove(callback);
|
|
116
|
+
};
|
|
8
117
|
|
|
9
118
|
export { offGyroscopeChange, onGyroscopeChange, startGyroscope, stopGyroscope };
|
|
10
119
|
//# sourceMappingURL=gyroscope.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gyroscope.js","sources":["../../../src/api/device/gyroscope.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"gyroscope.js","sources":["../../../src/api/device/gyroscope.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAKA,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;AAC7C,IAAI,iBAAiE,CAAA;AACrE,IAAI,kBAA2D,CAAA;AAE/D,MAAM,YAAY,GAAG;AACnB,IAAA,IAAI,EAAE;AACJ,QAAA,QAAQ,EAAE,EAAE;AACZ,QAAA,SAAS,EAAE,EAAE;AACd,KAAA;AACD,IAAA,EAAE,EAAE;AACF,QAAA,QAAQ,EAAE,EAAE;AACZ,QAAA,SAAS,EAAE,KAAK;AACjB,KAAA;AACD,IAAA,MAAM,EAAE;AACN,QAAA,QAAQ,EAAE,GAAG;AACb,QAA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...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
|
|
2
4
|
export declare const offKeyboardHeightChange: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
|
|
3
5
|
export declare const hideKeyboard: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
|
|
4
|
-
export declare const getSelectedTextRange:
|
|
6
|
+
export declare const getSelectedTextRange: typeof Taro.getSelectedTextRange;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { temporarilyNotSupport } from '../../utils/index.js';
|
|
2
|
+
import { MethodHandler } from '../../utils/handler.js';
|
|
2
3
|
|
|
3
4
|
// 键盘
|
|
4
5
|
const onKeyboardHeightChange = /* @__PURE__ */ temporarilyNotSupport('onKeyboardHeightChange');
|
|
5
6
|
const offKeyboardHeightChange = /* @__PURE__ */ temporarilyNotSupport('offKeyboardHeightChange');
|
|
6
7
|
const hideKeyboard = /* @__PURE__ */ temporarilyNotSupport('hideKeyboard');
|
|
7
|
-
const getSelectedTextRange =
|
|
8
|
+
const getSelectedTextRange = ({ success, fail, complete } = {}) => {
|
|
9
|
+
const handle = new MethodHandler({ name: 'getSelectedTextRange', success, fail, complete });
|
|
10
|
+
const input = typeof document === 'undefined' ? null : document.activeElement;
|
|
11
|
+
if (input && (input instanceof HTMLInputElement || input instanceof HTMLTextAreaElement)) {
|
|
12
|
+
const { selectionStart: start, selectionEnd: end } = input;
|
|
13
|
+
if (start !== null && end !== null)
|
|
14
|
+
return handle.success({ start, end });
|
|
15
|
+
}
|
|
16
|
+
return handle.fail({ errMsg: 'no focused input with a text selection' });
|
|
17
|
+
};
|
|
8
18
|
|
|
9
19
|
export { getSelectedTextRange, hideKeyboard, offKeyboardHeightChange, onKeyboardHeightChange };
|
|
10
20
|
//# sourceMappingURL=keyboard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard.js","sources":["../../../src/api/device/keyboard.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyboard.js","sources":["../../../src/api/device/keyboard.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAKA;AACa,MAAA,sBAAsB,mBAAmB,qBAAqB,CAAC,wBAAwB,EAAC;AACxF,MAAA,uBAAuB,mBAAmB,qBAAqB,CAAC,yBAAyB,EAAC;AAC1F,MAAA,YAAY,mBAAmB,qBAAqB,CAAC,cAAc,EAAC;AAC1E,MAAM,oBAAoB,GAAqC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAI;AACzG,IAAA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAkD,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;AAC5I,IAAA,MAAM,KAAK,GAAG,OAAO,QAAQ,KAAK,WAAW,GAAG,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAA;AAC7E,IAAA,IAAI,KAAK,KAAK,KAAK,YAAY,gBAAgB,IAAI,KAAK,YAAY,mBAAmB,CAAC,EAAE;QACxF,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,GAAG,KAAK,CAAA;AAC1D,QAAA,IAAI,KAAK,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;KAC1E;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,wCAAwC,EAAE,CAAC,CAAA;AAC1E;;;;"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
/// <reference types="types/api" />
|
|
2
|
+
import Taro from 'vite-plugin-taro-runtime/api';
|
|
1
3
|
export declare const setVisualEffectOnCapture: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
|
|
2
4
|
export declare const setScreenBrightness: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
|
|
3
|
-
|
|
5
|
+
/**
|
|
6
|
+
* 设置是否保持常亮状态。基于 Screen Wake Lock API 实现,需要在安全上下文(如 HTTPS 或 localhost)中使用。
|
|
7
|
+
*/
|
|
8
|
+
export declare const setKeepScreenOn: typeof Taro.setKeepScreenOn;
|
|
4
9
|
export declare const onUserCaptureScreen: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
|
|
5
10
|
export declare const offUserCaptureScreen: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
|
|
6
11
|
export declare const getScreenBrightness: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
|
|
@@ -1,9 +1,110 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { temporarilyNotSupport, shouldBeObject, getParameterError } from '../../utils/index.js';
|
|
3
|
+
import { MethodHandler } from '../../utils/handler.js';
|
|
2
4
|
|
|
3
5
|
// 屏幕
|
|
4
6
|
const setVisualEffectOnCapture = /* @__PURE__ */ temporarilyNotSupport('setVisualEffectOnCapture');
|
|
5
7
|
const setScreenBrightness = /* @__PURE__ */ temporarilyNotSupport('setScreenBrightness');
|
|
6
|
-
|
|
8
|
+
let keepScreenOnEnabled = false;
|
|
9
|
+
let keepScreenOnCallId = 0;
|
|
10
|
+
let wakeLock = null;
|
|
11
|
+
let pendingRequest = null;
|
|
12
|
+
function requestWakeLock() {
|
|
13
|
+
// Note: 复用尚未完成的申请,避免并发调用各自申请后,一方失败时误释放另一方已获取的 wake lock
|
|
14
|
+
if (!pendingRequest) {
|
|
15
|
+
const request = acquireWakeLock().finally(() => {
|
|
16
|
+
if (pendingRequest === request) {
|
|
17
|
+
pendingRequest = null;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
pendingRequest = request;
|
|
21
|
+
}
|
|
22
|
+
return pendingRequest;
|
|
23
|
+
}
|
|
24
|
+
function acquireWakeLock() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const sentinel = yield navigator.wakeLock.request('screen');
|
|
27
|
+
// Note: 申请期间可能已经取消了常亮,或者已经由其他调用持有了 wake lock
|
|
28
|
+
if (!keepScreenOnEnabled || wakeLock) {
|
|
29
|
+
yield sentinel.release();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
wakeLock = sentinel;
|
|
33
|
+
sentinel.addEventListener('release', () => {
|
|
34
|
+
if (wakeLock === sentinel) {
|
|
35
|
+
wakeLock = null;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Note: 页面不可见时浏览器会自动释放 wake lock,需要在页面重新可见时重新申请
|
|
42
|
+
* @see https://w3c.github.io/screen-wake-lock/#handling-document-loss-of-visibility
|
|
43
|
+
*/
|
|
44
|
+
function handleVisibilityChange() {
|
|
45
|
+
if (keepScreenOnEnabled && !wakeLock && document.visibilityState === 'visible') {
|
|
46
|
+
// Note: 视为一次新的请求,避免更早发起的请求失败后关闭这次已获取的 wake lock
|
|
47
|
+
keepScreenOnCallId++;
|
|
48
|
+
requestWakeLock().catch(e => {
|
|
49
|
+
console.warn(`setKeepScreenOn: failed to reacquire the screen wake lock, ${e.message}`);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function disableKeepScreenOn() {
|
|
54
|
+
keepScreenOnEnabled = false;
|
|
55
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
56
|
+
const sentinel = wakeLock;
|
|
57
|
+
wakeLock = null;
|
|
58
|
+
return sentinel === null || sentinel === void 0 ? void 0 : sentinel.release();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 设置是否保持常亮状态。基于 Screen Wake Lock API 实现,需要在安全上下文(如 HTTPS 或 localhost)中使用。
|
|
62
|
+
*/
|
|
63
|
+
const setKeepScreenOn = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const name = 'setKeepScreenOn';
|
|
65
|
+
// options must be an Object
|
|
66
|
+
const isObject = shouldBeObject(options);
|
|
67
|
+
if (!isObject.flag) {
|
|
68
|
+
const res = { errMsg: `${name}:fail ${isObject.msg}` };
|
|
69
|
+
console.error(res.errMsg);
|
|
70
|
+
return Promise.reject(res);
|
|
71
|
+
}
|
|
72
|
+
const { keepScreenOn, success, fail, complete } = options;
|
|
73
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
74
|
+
if (typeof keepScreenOn !== 'boolean') {
|
|
75
|
+
return handle.fail({
|
|
76
|
+
errMsg: getParameterError({
|
|
77
|
+
para: 'keepScreenOn',
|
|
78
|
+
correct: 'Boolean',
|
|
79
|
+
wrong: keepScreenOn
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!('wakeLock' in navigator)) {
|
|
84
|
+
return handle.fail({ errMsg: 'wakeLock is not supported' });
|
|
85
|
+
}
|
|
86
|
+
const callId = ++keepScreenOnCallId;
|
|
87
|
+
try {
|
|
88
|
+
if (keepScreenOn) {
|
|
89
|
+
keepScreenOnEnabled = true;
|
|
90
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
91
|
+
if (!wakeLock) {
|
|
92
|
+
yield requestWakeLock();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
yield disableKeepScreenOn();
|
|
97
|
+
}
|
|
98
|
+
return handle.success();
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
// Note: 申请失败时不保留常亮状态,除非期间已有新的调用修改了该状态
|
|
102
|
+
if (keepScreenOn && callId === keepScreenOnCallId) {
|
|
103
|
+
disableKeepScreenOn();
|
|
104
|
+
}
|
|
105
|
+
return handle.fail({ errMsg: e.message });
|
|
106
|
+
}
|
|
107
|
+
});
|
|
7
108
|
const onUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('onUserCaptureScreen');
|
|
8
109
|
const offUserCaptureScreen = /* @__PURE__ */ temporarilyNotSupport('offUserCaptureScreen');
|
|
9
110
|
const getScreenBrightness = /* @__PURE__ */ temporarilyNotSupport('getScreenBrightness');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screen.js","sources":["../../../src/api/device/screen.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"screen.js","sources":["../../../src/api/device/screen.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKA;AACa,MAAA,wBAAwB,mBAAmB,qBAAqB,CAAC,0BAA0B,EAAC;AAC5F,MAAA,mBAAmB,mBAAmB,qBAAqB,CAAC,qBAAqB,EAAC;AAE/F,IAAI,mBAAmB,GAAG,KAAK,CAAA;AAC/B,IAAI,kBAAkB,GAAG,CAAC,CAAA;AAC1B,IAAI,QAAQ,GAA4B,IAAI,CAAA;AAC5C,IAAI,cAAc,GAAyB,IAAI,CAAA;AAE/C,SAAS,eAAe,GAAA;;IAEtB,IAAI,CAAC,cAAc,EAAE;QACnB,MAAM,OAAO,GAAG,eAAe,EAAE,CAAC,OAAO,CAAC,MAAK;AAC7C,YAAA,IAAI,cAAc,KAAK,OAAO,EAAE;gBAC9B,cAAc,GAAG,IAAI,CAAA;aACtB;AACH,SAAC,CAAC,CAAA;QACF,cAAc,GAAG,OAAO,CAAA;KACzB;AACD,IAAA,OAAO,cAAc,CAAA;AACvB,CAAC;AAED,SAAe,eAAe,GAAA;;QAC5B,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,QAAQ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