@tarojs/taro-h5 3.4.0-beta.1 → 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/ad/index.js +4 -0
- package/dist/api/ai/facial.js +5 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +3 -0
- package/dist/api/alipay/index.js +3 -0
- package/dist/api/base/crypto.js +3 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +17 -0
- package/dist/api/base/performance.js +4 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +57 -0
- package/dist/api/base/system/network.js +63 -0
- package/dist/api/base/update.js +4 -0
- package/dist/api/base/weapp/app-event.js +18 -0
- package/dist/api/base/weapp/life-cycle.js +4 -0
- package/dist/api/canvas/CanvasContext.js +191 -0
- package/dist/api/canvas/canvasGetImageData.js +25 -0
- package/dist/api/canvas/canvasPutImageData.js +22 -0
- package/dist/api/canvas/canvasToTempFilePath.js +22 -0
- package/dist/api/canvas/createCanvasContext.js +16 -0
- package/dist/api/canvas/index.js +8 -0
- package/dist/api/cloud/index.js +21 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +83 -0
- package/dist/api/device/accessibility.js +3 -0
- package/dist/api/device/battery.js +4 -0
- package/dist/api/device/bluetooth-ble.js +18 -0
- package/dist/api/device/bluetooth-peripheral.js +5 -0
- package/dist/api/device/bluetooth.js +15 -0
- package/dist/api/device/calendar.js +4 -0
- package/dist/api/device/clipboard.js +65 -0
- package/dist/api/device/compass.js +64 -0
- package/dist/api/device/contact.js +4 -0
- package/dist/api/device/crypto.js +3 -0
- package/dist/api/device/gyroscope.js +6 -0
- package/dist/api/device/iBeacon.js +9 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +6 -0
- package/dist/api/device/memory.js +4 -0
- package/dist/api/device/motion.js +81 -0
- package/dist/api/device/nfc.js +9 -0
- package/dist/api/device/phone.js +24 -0
- package/dist/api/device/scan.js +6 -0
- package/dist/api/device/screen.js +8 -0
- package/dist/api/device/vibrate.js +35 -0
- package/dist/api/device/wifi.js +12 -0
- package/dist/api/ext/index.js +4 -0
- package/dist/api/files/index.js +10 -0
- package/dist/api/framework/index.js +7 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +93 -0
- package/dist/api/location/index.js +13 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/EditorContext.js +18 -0
- package/dist/api/media/audio/InnerAudioContext.js +84 -0
- package/dist/api/media/audio/index.js +15 -0
- package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
- package/dist/api/media/background-audio/index.js +15 -0
- package/dist/api/media/camera.js +3 -0
- package/dist/api/media/image/chooseImage.js +74 -0
- package/dist/api/media/image/getImageInfo.js +31 -0
- package/dist/api/media/image/index.js +9 -0
- package/dist/api/media/image/previewImage.js +67 -0
- package/dist/api/media/index.js +12 -0
- package/dist/api/media/live.js +4 -0
- package/dist/api/media/map.js +3 -0
- package/dist/api/media/media-recorder.js +3 -0
- package/dist/api/media/recorder.js +5 -0
- package/dist/api/media/video/index.js +74 -0
- package/dist/api/media/video-decoder.js +3 -0
- package/dist/api/media/video-processing.js +3 -0
- package/dist/api/media/voip.js +16 -0
- package/dist/api/navigate/index.js +6 -0
- package/dist/api/network/download.js +124 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +12 -0
- package/dist/api/network/request/index.js +125 -0
- package/dist/api/network/tcp.js +3 -0
- package/dist/api/network/udp.js +3 -0
- package/dist/api/network/upload.js +151 -0
- package/dist/api/network/utils.js +65 -0
- package/dist/api/network/websocket/index.js +70 -0
- package/dist/api/network/websocket/socketTask.js +63 -0
- package/dist/api/open-api/account.js +3 -0
- package/dist/api/open-api/address.js +3 -0
- package/dist/api/open-api/authorize.js +4 -0
- package/dist/api/open-api/card.js +4 -0
- package/dist/api/open-api/channels-live.js +8 -0
- package/dist/api/open-api/customer-service.js +3 -0
- package/dist/api/open-api/facial.js +6 -0
- package/dist/api/open-api/favorites.js +4 -0
- package/dist/api/open-api/group.js +3 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +4 -0
- package/dist/api/open-api/license-plate.js +3 -0
- package/dist/api/open-api/login.js +5 -0
- package/dist/api/open-api/red-package.js +3 -0
- package/dist/api/open-api/settings.js +4 -0
- package/dist/api/open-api/soter.js +5 -0
- package/dist/api/open-api/subscribe-message.js +3 -0
- package/dist/api/open-api/user-info.js +4 -0
- package/dist/api/open-api/werun.js +4 -0
- package/dist/api/payment/index.js +4 -0
- package/dist/api/route/index.js +3 -0
- package/dist/api/share/index.js +12 -0
- package/dist/api/storage/background-fetch.js +6 -0
- package/dist/api/storage/index.js +157 -0
- package/dist/api/swan/index.js +26 -0
- package/dist/api/taro.js +47 -0
- package/dist/api/ui/animation/index.js +288 -0
- package/dist/api/ui/background.js +4 -0
- package/dist/api/ui/custom-component.js +3 -0
- package/dist/api/ui/fonts.js +3 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +188 -0
- package/dist/api/ui/interaction/index.js +268 -0
- package/dist/api/ui/interaction/modal.js +207 -0
- package/dist/api/ui/interaction/toast.js +195 -0
- package/dist/api/ui/menu.js +3 -0
- package/dist/api/ui/navigation-bar/index.js +42 -0
- package/dist/api/ui/pull-down-refresh.js +26 -0
- package/dist/api/ui/scroll/index.js +83 -0
- package/dist/api/ui/sticky.js +3 -0
- package/dist/api/ui/tab-bar.js +282 -0
- package/dist/api/ui/window.js +31 -0
- package/dist/api/utils/handler.js +80 -0
- package/dist/api/utils/index.js +172 -0
- package/dist/api/worker/index.js +3 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +42 -0
- package/dist/api/wxml/selectorQuery.js +201 -0
- package/dist/index.cjs.js +4756 -6934
- package/dist/index.js +4 -10767
- package/dist/taroApis.js +1 -1
- package/dist/types/type.js +2 -0
- package/package.json +11 -13
- package/src/api/canvas/CanvasContext.ts +36 -33
- package/src/api/canvas/createCanvasContext.ts +2 -2
- package/src/api/cloud/index.ts +4 -0
- package/src/api/location/chooseLocation.ts +2 -2
- 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/image/previewImage.ts +4 -25
- package/src/api/media/index.ts +0 -1
- package/src/api/network/download.ts +5 -5
- package/src/api/network/upload.ts +6 -6
- package/src/api/network/websocket/index.ts +1 -1
- package/src/api/ui/animation/index.ts +11 -12
- package/src/api/ui/interaction/index.ts +12 -10
- package/src/api/ui/navigation-bar/index.ts +2 -2
- package/src/api/ui/scroll/index.ts +3 -3
- package/src/api/utils/index.ts +34 -13
- package/src/api/wxml/nodesRef.ts +10 -3
- package/src/api/wxml/selectorQuery.ts +68 -23
- package/src/index.ts +2 -2
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
export const setEnableDebug = temporarilyNotSupport('setEnableDebug');
|
|
3
|
+
export const getRealtimeLogManager = temporarilyNotSupport('getRealtimeLogManager');
|
|
4
|
+
export const getLogManager = temporarilyNotSupport('getLogManager');
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { fromByteArray, toByteArray } from 'base64-js';
|
|
2
|
+
import { temporarilyNotSupport } from '../utils';
|
|
3
|
+
// TODO env 环境变量
|
|
4
|
+
export const canIUse = temporarilyNotSupport('canIUse');
|
|
5
|
+
export function arrayBufferToBase64(arrayBuffer) {
|
|
6
|
+
return fromByteArray(arrayBuffer);
|
|
7
|
+
}
|
|
8
|
+
export function base64ToArrayBuffer(base64) {
|
|
9
|
+
return toByteArray(base64);
|
|
10
|
+
}
|
|
11
|
+
export * from './system';
|
|
12
|
+
export * from './update';
|
|
13
|
+
export * from './weapp/life-cycle';
|
|
14
|
+
export * from './weapp/app-event';
|
|
15
|
+
export * from './debug';
|
|
16
|
+
export * from './performance';
|
|
17
|
+
export * from './crypto';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import MobileDetect from 'mobile-detect';
|
|
2
|
+
import { MethodHandler } from '../../utils/handler';
|
|
3
|
+
export const getSystemInfoSync = () => {
|
|
4
|
+
const md = new MobileDetect(navigator.userAgent);
|
|
5
|
+
const info = {
|
|
6
|
+
brand: md.mobile() || '',
|
|
7
|
+
model: md.mobile() || '',
|
|
8
|
+
system: md.os(),
|
|
9
|
+
pixelRatio: window.devicePixelRatio,
|
|
10
|
+
screenWidth: window.screen.width,
|
|
11
|
+
screenHeight: window.screen.height,
|
|
12
|
+
windowWidth: document.documentElement.clientWidth,
|
|
13
|
+
windowHeight: document.documentElement.clientHeight,
|
|
14
|
+
version: '',
|
|
15
|
+
statusBarHeight: NaN,
|
|
16
|
+
platform: navigator.platform,
|
|
17
|
+
language: navigator.language,
|
|
18
|
+
fontSizeSetting: NaN,
|
|
19
|
+
SDKVersion: '',
|
|
20
|
+
// TODO
|
|
21
|
+
albumAuthorized: false,
|
|
22
|
+
benchmarkLevel: 0,
|
|
23
|
+
bluetoothEnabled: false,
|
|
24
|
+
cameraAuthorized: false,
|
|
25
|
+
enableDebug: false,
|
|
26
|
+
locationAuthorized: false,
|
|
27
|
+
locationEnabled: false,
|
|
28
|
+
microphoneAuthorized: false,
|
|
29
|
+
notificationAlertAuthorized: false,
|
|
30
|
+
notificationAuthorized: false,
|
|
31
|
+
notificationBadgeAuthorized: false,
|
|
32
|
+
notificationSoundAuthorized: false,
|
|
33
|
+
safeArea: {
|
|
34
|
+
bottom: 0,
|
|
35
|
+
height: 0,
|
|
36
|
+
left: 0,
|
|
37
|
+
right: 0,
|
|
38
|
+
top: 0,
|
|
39
|
+
width: 0
|
|
40
|
+
},
|
|
41
|
+
wifiEnabled: false
|
|
42
|
+
};
|
|
43
|
+
return info;
|
|
44
|
+
};
|
|
45
|
+
export const getSystemInfo = async (options = {}) => {
|
|
46
|
+
const { success, fail, complete } = options;
|
|
47
|
+
const handle = new MethodHandler({ name: 'getSystemInfo', success, fail, complete });
|
|
48
|
+
try {
|
|
49
|
+
const info = await getSystemInfoSync();
|
|
50
|
+
return handle.success(info);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return handle.fail({
|
|
54
|
+
errMsg: error
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { MethodHandler } from '../../utils/handler';
|
|
2
|
+
import { temporarilyNotSupport } from '../../utils';
|
|
3
|
+
function getConnection() {
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
return navigator.connection || navigator.mozConnection || navigator.webkitConnection || navigator.msConnection;
|
|
6
|
+
}
|
|
7
|
+
export const getNetworkType = (options = {}) => {
|
|
8
|
+
const connection = getConnection();
|
|
9
|
+
const { success, fail, complete } = options;
|
|
10
|
+
const handle = new MethodHandler({ name: 'getNetworkType', success, fail, complete });
|
|
11
|
+
let networkType = 'unknown';
|
|
12
|
+
// 浏览器不支持获取网络状态
|
|
13
|
+
if (!connection) {
|
|
14
|
+
return handle.success({ networkType });
|
|
15
|
+
}
|
|
16
|
+
// Supports only the navigator.connection.type value which doesn't match the latest spec.
|
|
17
|
+
// https://www.davidbcalhoun.com/2010/using-navigator-connection-android/
|
|
18
|
+
if (!isNaN(Number(connection.type))) {
|
|
19
|
+
switch (connection.type) {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
case connection.WIFI:
|
|
22
|
+
networkType = 'wifi';
|
|
23
|
+
break;
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
case connection.CELL_3G:
|
|
26
|
+
networkType = '3g';
|
|
27
|
+
break;
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
case connection.CELL_2G:
|
|
30
|
+
networkType = '2g';
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
// ETHERNET, UNKNOWN
|
|
34
|
+
networkType = 'unknown';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (connection.type) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
networkType = connection.type; // Only supports the type value.
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
}
|
|
42
|
+
else if (connection.effectiveType) {
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
networkType = connection.effectiveType;
|
|
45
|
+
}
|
|
46
|
+
return handle.success({ networkType });
|
|
47
|
+
};
|
|
48
|
+
export const onNetworkStatusChange = (cb) => {
|
|
49
|
+
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
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export const offNetworkStatusChange = temporarilyNotSupport('offNetworkStatusChange');
|
|
63
|
+
export const getLocalIPAddress = temporarilyNotSupport('getLocalIPAddress');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils';
|
|
2
|
+
// 应用级事件
|
|
3
|
+
export const onUnhandledRejection = temporarilyNotSupport('onUnhandledRejection');
|
|
4
|
+
export const onThemeChange = temporarilyNotSupport('onThemeChange');
|
|
5
|
+
export const onPageNotFound = temporarilyNotSupport('onPageNotFound');
|
|
6
|
+
export const onError = temporarilyNotSupport('onError');
|
|
7
|
+
export const onAudioInterruptionEnd = temporarilyNotSupport('onAudioInterruptionEnd');
|
|
8
|
+
export const onAudioInterruptionBegin = temporarilyNotSupport('onAudioInterruptionBegin');
|
|
9
|
+
export const onAppShow = temporarilyNotSupport('onAppShow');
|
|
10
|
+
export const onAppHide = temporarilyNotSupport('onAppHide');
|
|
11
|
+
export const offUnhandledRejection = temporarilyNotSupport('offUnhandledRejection');
|
|
12
|
+
export const offThemeChange = temporarilyNotSupport('offThemeChange');
|
|
13
|
+
export const offPageNotFound = temporarilyNotSupport('offPageNotFound');
|
|
14
|
+
export const offError = temporarilyNotSupport('offError');
|
|
15
|
+
export const offAudioInterruptionEnd = temporarilyNotSupport('offAudioInterruptionEnd');
|
|
16
|
+
export const offAudioInterruptionBegin = temporarilyNotSupport('offAudioInterruptionBegin');
|
|
17
|
+
export const offAppShow = temporarilyNotSupport('offAppShow');
|
|
18
|
+
export const offAppHide = temporarilyNotSupport('offAppHide');
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
const TextBaseLineMap = {
|
|
2
|
+
top: 'top',
|
|
3
|
+
bottom: 'bottom',
|
|
4
|
+
middle: 'middle',
|
|
5
|
+
normal: 'alphabetic'
|
|
6
|
+
};
|
|
7
|
+
export class CanvasContext {
|
|
8
|
+
constructor(canvas, ctx) {
|
|
9
|
+
this.actions = [];
|
|
10
|
+
this.canvas = canvas;
|
|
11
|
+
this.ctx = ctx;
|
|
12
|
+
}
|
|
13
|
+
set ctx(e) {
|
|
14
|
+
this.__raw__ = e;
|
|
15
|
+
}
|
|
16
|
+
get ctx() {
|
|
17
|
+
return this.__raw__ || {};
|
|
18
|
+
}
|
|
19
|
+
emptyActions() {
|
|
20
|
+
this.actions.length = 0;
|
|
21
|
+
}
|
|
22
|
+
enqueueActions(func, ...args) {
|
|
23
|
+
this.actions.push({
|
|
24
|
+
func,
|
|
25
|
+
args
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
set fillStyle(e) { this.enqueueActions(() => { this.ctx.fillStyle = e; }); }
|
|
29
|
+
get fillStyle() { return this.ctx.fillStyle; }
|
|
30
|
+
set font(e) { this.ctx.font = e; }
|
|
31
|
+
get font() { return this.ctx.font; }
|
|
32
|
+
set globalAlpha(e) { this.enqueueActions(() => { this.ctx.globalAlpha = e; }); }
|
|
33
|
+
get globalAlpha() { return this.ctx.globalAlpha; }
|
|
34
|
+
set globalCompositeOperation(e) { this.enqueueActions(() => { this.ctx.globalCompositeOperation = e; }); }
|
|
35
|
+
get globalCompositeOperation() { return this.ctx.globalCompositeOperation; }
|
|
36
|
+
set lineCap(e) { this.enqueueActions(() => { this.ctx.lineCap = e; }); }
|
|
37
|
+
get lineCap() { return this.ctx.lineCap; }
|
|
38
|
+
set lineDashOffset(e) { this.enqueueActions(() => { this.ctx.lineDashOffset = e; }); }
|
|
39
|
+
get lineDashOffset() { return this.ctx.lineDashOffset; }
|
|
40
|
+
set lineJoin(e) { this.enqueueActions(() => { this.ctx.lineJoin = e; }); }
|
|
41
|
+
get lineJoin() { return this.ctx.lineJoin; }
|
|
42
|
+
set lineWidth(e) { this.enqueueActions(() => { this.ctx.lineWidth = e; }); }
|
|
43
|
+
get lineWidth() { return this.ctx.lineWidth; }
|
|
44
|
+
set miterLimit(e) { this.enqueueActions(() => { this.ctx.miterLimit = e; }); }
|
|
45
|
+
get miterLimit() { return this.ctx.miterLimit; }
|
|
46
|
+
set shadowBlur(e) { this.enqueueActions(() => { this.ctx.shadowBlur = e; }); }
|
|
47
|
+
get shadowBlur() { return this.ctx.shadowBlur; }
|
|
48
|
+
set shadowColor(e) { this.enqueueActions(() => { this.ctx.shadowColor = e; }); }
|
|
49
|
+
get shadowColor() { return this.ctx.shadowColor; }
|
|
50
|
+
set shadowOffsetX(e) { this.enqueueActions(() => { this.ctx.shadowOffsetX = e; }); }
|
|
51
|
+
get shadowOffsetX() { return this.ctx.shadowOffsetX; }
|
|
52
|
+
set shadowOffsetY(e) { this.enqueueActions(() => { this.ctx.shadowOffsetY = e; }); }
|
|
53
|
+
get shadowOffsetY() { return this.ctx.shadowOffsetY; }
|
|
54
|
+
set strokeStyle(e) { this.enqueueActions(() => { this.ctx.strokeStyle = e; }); }
|
|
55
|
+
get strokeStyle() { return this.ctx.strokeStyle; }
|
|
56
|
+
/** 小程序文档中不包括 ↓↓↓ */
|
|
57
|
+
set textAlign(e) { this.ctx.textAlign = e; }
|
|
58
|
+
get textAlign() { return this.ctx.textAlign; }
|
|
59
|
+
set textBaseline(e) { this.ctx.textBaseline = e; }
|
|
60
|
+
get textBaseline() { return this.ctx.textBaseline; }
|
|
61
|
+
set direction(e) { this.ctx.direction = e; }
|
|
62
|
+
get direction() { return this.ctx.direction; }
|
|
63
|
+
set imageSmoothingEnabled(e) { this.enqueueActions(() => { this.ctx.imageSmoothingEnabled = e; }); }
|
|
64
|
+
get imageSmoothingEnabled() { return this.ctx.imageSmoothingEnabled; }
|
|
65
|
+
set imageSmoothingQuality(e) { this.enqueueActions(() => { this.ctx.imageSmoothingQuality = e; }); }
|
|
66
|
+
get imageSmoothingQuality() { return this.ctx.imageSmoothingQuality; }
|
|
67
|
+
set filter(e) { this.enqueueActions(() => { this.ctx.filter = e; }); }
|
|
68
|
+
get filter() { return this.ctx.filter; }
|
|
69
|
+
/** 小程序文档中不包括 ↑↑↑ */
|
|
70
|
+
arc(...args) { return this.enqueueActions(this.ctx.arc, ...args); }
|
|
71
|
+
arcTo(...args) { return this.enqueueActions(this.ctx.arcTo, ...args); }
|
|
72
|
+
beginPath(...args) { return this.enqueueActions(this.ctx.beginPath, ...args); }
|
|
73
|
+
bezierCurveTo(...args) { return this.enqueueActions(this.ctx.bezierCurveTo, ...args); }
|
|
74
|
+
clearRect(...args) { return this.enqueueActions(this.ctx.clearRect, ...args); }
|
|
75
|
+
clip(...args) { return this.enqueueActions(this.ctx.clip, ...args); }
|
|
76
|
+
closePath(...args) { return this.enqueueActions(this.ctx.closePath, ...args); }
|
|
77
|
+
createPattern(image, repetition) {
|
|
78
|
+
return this.createPattern(image, repetition);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 将之前在绘图上下文中的描述(路径、变形、样式)画到 canvas 中。
|
|
82
|
+
* @todo 每次 draw 都会读取 width 和 height
|
|
83
|
+
*/
|
|
84
|
+
async draw(reserve, callback) {
|
|
85
|
+
try {
|
|
86
|
+
if (!reserve) {
|
|
87
|
+
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
88
|
+
}
|
|
89
|
+
// 部分 action 是异步的
|
|
90
|
+
for (const { func, args } of this.actions) {
|
|
91
|
+
await func.apply(this.ctx, args);
|
|
92
|
+
}
|
|
93
|
+
this.emptyActions();
|
|
94
|
+
callback && callback();
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
/* eslint-disable no-throw-literal */
|
|
98
|
+
throw {
|
|
99
|
+
errMsg: e.message
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
drawImage(imageResource, ...extra) {
|
|
104
|
+
this.enqueueActions(() => {
|
|
105
|
+
// 需要转换为 Image
|
|
106
|
+
if (typeof imageResource === 'string') {
|
|
107
|
+
const img = new Image();
|
|
108
|
+
img.src = imageResource;
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
img.onload = () => {
|
|
111
|
+
this.ctx.drawImage(img, ...extra);
|
|
112
|
+
resolve();
|
|
113
|
+
};
|
|
114
|
+
img.onerror = reject;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
this.ctx.drawImage(imageResource, ...extra);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
fill(...args) { return this.enqueueActions(this.ctx.fill, ...args); }
|
|
121
|
+
fillRect(...args) { return this.enqueueActions(this.ctx.fillRect, ...args); }
|
|
122
|
+
fillText(...args) { return this.enqueueActions(this.ctx.fillText, ...args); }
|
|
123
|
+
lineTo(...args) { return this.enqueueActions(this.ctx.lineTo, ...args); }
|
|
124
|
+
moveTo(...args) { return this.enqueueActions(this.ctx.moveTo, ...args); }
|
|
125
|
+
quadraticCurveTo(...args) { return this.enqueueActions(this.ctx.quadraticCurveTo, ...args); }
|
|
126
|
+
rect(...args) { return this.enqueueActions(this.ctx.rect, ...args); }
|
|
127
|
+
restore(...args) { return this.enqueueActions(this.ctx.restore, ...args); }
|
|
128
|
+
rotate(...args) { return this.enqueueActions(this.ctx.rotate, ...args); }
|
|
129
|
+
save(...args) { return this.enqueueActions(this.ctx.save, ...args); }
|
|
130
|
+
scale(...args) { return this.enqueueActions(this.ctx.scale, ...args); }
|
|
131
|
+
setFillStyle(color) {
|
|
132
|
+
this.enqueueActions(() => { this.ctx.fillStyle = color; });
|
|
133
|
+
}
|
|
134
|
+
setFontSize(fontSize) {
|
|
135
|
+
this.font = `${fontSize}px`;
|
|
136
|
+
}
|
|
137
|
+
setGlobalAlpha(alpha) {
|
|
138
|
+
this.globalAlpha = alpha;
|
|
139
|
+
}
|
|
140
|
+
setLineCap(lineCap) {
|
|
141
|
+
this.lineCap = lineCap;
|
|
142
|
+
}
|
|
143
|
+
setLineDash(pattern, offset) {
|
|
144
|
+
this.enqueueActions(() => {
|
|
145
|
+
this.ctx.setLineDash(pattern);
|
|
146
|
+
this.ctx.lineDashOffset = offset;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
setLineJoin(lineJoin) {
|
|
150
|
+
this.lineJoin = lineJoin;
|
|
151
|
+
}
|
|
152
|
+
setLineWidth(lineWidth) {
|
|
153
|
+
this.lineWidth = lineWidth;
|
|
154
|
+
}
|
|
155
|
+
setMiterLimit(miterLimit) {
|
|
156
|
+
this.miterLimit = miterLimit;
|
|
157
|
+
}
|
|
158
|
+
setShadow(offsetX, offsetY, blur, color) {
|
|
159
|
+
this.enqueueActions(() => {
|
|
160
|
+
this.ctx.shadowOffsetX = offsetX;
|
|
161
|
+
this.ctx.shadowOffsetY = offsetY;
|
|
162
|
+
this.ctx.shadowColor = color;
|
|
163
|
+
this.ctx.shadowBlur = blur;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
setStrokeStyle(color) {
|
|
167
|
+
this.enqueueActions(() => { this.ctx.strokeStyle = color; });
|
|
168
|
+
}
|
|
169
|
+
setTextAlign(align) {
|
|
170
|
+
this.textAlign = align;
|
|
171
|
+
}
|
|
172
|
+
setTextBaseline(textBaseline) {
|
|
173
|
+
this.textBaseline = TextBaseLineMap[textBaseline] || 'alphabetic';
|
|
174
|
+
}
|
|
175
|
+
setTransform(...args) { return this.enqueueActions(this.ctx.setTransform, ...args); }
|
|
176
|
+
stroke(...args) { return this.enqueueActions(this.ctx.stroke, ...args); }
|
|
177
|
+
strokeRect(...args) { return this.enqueueActions(this.ctx.strokeRect, ...args); }
|
|
178
|
+
strokeText(...args) { return this.enqueueActions(this.ctx.strokeText, ...args); }
|
|
179
|
+
transform(...args) { return this.enqueueActions(this.ctx.transform, ...args); }
|
|
180
|
+
translate(...args) { return this.enqueueActions(this.ctx.translate, ...args); }
|
|
181
|
+
measureText(text) {
|
|
182
|
+
return this.ctx.measureText(text);
|
|
183
|
+
}
|
|
184
|
+
createCircularGradient(x, y, r) {
|
|
185
|
+
const radialGradient = this.ctx.createRadialGradient(x, y, 0, x, y, r);
|
|
186
|
+
return radialGradient;
|
|
187
|
+
}
|
|
188
|
+
createLinearGradient(x0, y0, x1, y1) {
|
|
189
|
+
return this.createLinearGradient(x0, y0, x1, y1);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MethodHandler } from '../utils/handler';
|
|
2
|
+
import { findDOM } from '../utils';
|
|
3
|
+
/**
|
|
4
|
+
* 获取 canvas 区域隐含的像素数据。
|
|
5
|
+
*/
|
|
6
|
+
export const canvasGetImageData = ({ canvasId, success, fail, complete, x, y, width, height }, inst) => {
|
|
7
|
+
const handle = new MethodHandler({ name: 'canvasGetImageData', success, fail, complete });
|
|
8
|
+
const el = findDOM(inst);
|
|
9
|
+
const canvas = el === null || el === void 0 ? void 0 : el.querySelector(`canvas[canvas-id="${canvasId}"]`);
|
|
10
|
+
try {
|
|
11
|
+
const ctx = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d');
|
|
12
|
+
// TODO ImageData => Uint8ClampedArray
|
|
13
|
+
const data = ctx === null || ctx === void 0 ? void 0 : ctx.getImageData(x, y, width, height);
|
|
14
|
+
return handle.success({
|
|
15
|
+
width,
|
|
16
|
+
height,
|
|
17
|
+
data
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
return handle.fail({
|
|
22
|
+
errMsg: e.message
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MethodHandler } from '../utils/handler';
|
|
2
|
+
import { findDOM } from '../utils';
|
|
3
|
+
/**
|
|
4
|
+
* 将像素数据绘制到画布。在自定义组件下,第二个参数传入自定义组件实例 this,以操作组件内 <canvas> 组件
|
|
5
|
+
* @todo 暂未支持尺寸相关功能
|
|
6
|
+
*/
|
|
7
|
+
export const canvasPutImageData = ({ canvasId, data, x, y, success, fail, complete }, inst) => {
|
|
8
|
+
const handle = new MethodHandler({ name: 'canvasPutImageData', success, fail, complete });
|
|
9
|
+
const el = findDOM(inst);
|
|
10
|
+
const canvas = el === null || el === void 0 ? void 0 : el.querySelector(`canvas[canvas-id="${canvasId}"]`);
|
|
11
|
+
try {
|
|
12
|
+
const ctx = canvas.getContext('2d');
|
|
13
|
+
// TODO Uint8ClampedArray => ImageData
|
|
14
|
+
ctx === null || ctx === void 0 ? void 0 : ctx.putImageData(data, x, y);
|
|
15
|
+
return handle.success();
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
return handle.fail({
|
|
19
|
+
errMsg: e.message
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { findDOM } from '../utils';
|
|
2
|
+
import { MethodHandler } from '../utils/handler';
|
|
3
|
+
/**
|
|
4
|
+
* 把当前画布指定区域的内容导出生成指定大小的图片。在 draw() 回调里调用该方法才能保证图片导出成功。
|
|
5
|
+
* @todo 暂未支持尺寸相关功能
|
|
6
|
+
*/
|
|
7
|
+
export const canvasToTempFilePath = ({ canvasId, fileType, quality, success, fail, complete }, inst) => {
|
|
8
|
+
const handle = new MethodHandler({ name: 'canvasToTempFilePath', success, fail, complete });
|
|
9
|
+
const el = findDOM(inst);
|
|
10
|
+
const canvas = el === null || el === void 0 ? void 0 : el.querySelector(`canvas[canvas-id="${canvasId}"]`);
|
|
11
|
+
try {
|
|
12
|
+
const dataURL = canvas === null || canvas === void 0 ? void 0 : canvas.toDataURL(`image/${fileType || 'png'}`, quality);
|
|
13
|
+
return handle.success({
|
|
14
|
+
tempFilePath: dataURL
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
return handle.fail({
|
|
19
|
+
errMsg: e.message
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { findDOM } from '../utils';
|
|
2
|
+
import { CanvasContext } from './CanvasContext';
|
|
3
|
+
/**
|
|
4
|
+
* 创建 canvas 的绘图上下文 CanvasContext 对象
|
|
5
|
+
*/
|
|
6
|
+
export const createCanvasContext = (canvasId, inst) => {
|
|
7
|
+
const el = findDOM(inst);
|
|
8
|
+
const canvas = el === null || el === void 0 ? void 0 : el.querySelector(`canvas[canvas-id="${canvasId}"]`);
|
|
9
|
+
const ctx = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d');
|
|
10
|
+
const context = new CanvasContext(canvas, ctx);
|
|
11
|
+
if (!ctx)
|
|
12
|
+
return context;
|
|
13
|
+
context.canvas = canvas;
|
|
14
|
+
context.ctx = ctx;
|
|
15
|
+
return context;
|
|
16
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 画布
|
|
3
|
+
export const createOffscreenCanvas = temporarilyNotSupport('createOffscreenCanvas');
|
|
4
|
+
export * from './createCanvasContext';
|
|
5
|
+
export * from './canvasToTempFilePath';
|
|
6
|
+
export * from './canvasPutImageData';
|
|
7
|
+
export * from './canvasGetImageData';
|
|
8
|
+
export const drawCanvas = temporarilyNotSupport('drawCanvas');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
export class cloud {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.init = temporarilyNotSupport('cloud.init');
|
|
5
|
+
this.CloudID = temporarilyNotSupport('cloud.CloudID');
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
this.callFunction = temporarilyNotSupport('cloud.callFunction');
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
this.uploadFile = temporarilyNotSupport('cloud.uploadFile');
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
this.downloadFile = temporarilyNotSupport('cloud.downloadFile');
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
this.getTempFileURL = temporarilyNotSupport('cloud.getTempFileURL');
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
this.deleteFile = temporarilyNotSupport('cloud.deleteFile');
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
this.database = temporarilyNotSupport('cloud.database');
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
this.callContainer = temporarilyNotSupport('cloud.callContainer');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
export const reportMonitor = temporarilyNotSupport('reportMonitor');
|
|
3
|
+
export const reportAnalytics = temporarilyNotSupport('reportAnalytics');
|
|
4
|
+
export const reportEvent = temporarilyNotSupport('reportEvent');
|
|
5
|
+
export const getExptInfoSync = temporarilyNotSupport('getExptInfoSync');
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { CallbackManager, MethodHandler } from '../utils/handler';
|
|
2
|
+
const callbackManager = new CallbackManager();
|
|
3
|
+
let devicemotionListener;
|
|
4
|
+
/**
|
|
5
|
+
* 停止监听加速度数据。
|
|
6
|
+
*/
|
|
7
|
+
export const stopAccelerometer = ({ success, fail, complete } = {}) => {
|
|
8
|
+
const res = {};
|
|
9
|
+
const handle = new MethodHandler({ name: 'stopAccelerometer', success, fail, complete });
|
|
10
|
+
try {
|
|
11
|
+
window.removeEventListener('devicemotion', devicemotionListener, true);
|
|
12
|
+
return handle.success(res);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
res.errMsg = e.message;
|
|
16
|
+
return handle.fail(res);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const INTERVAL_MAP = {
|
|
20
|
+
game: {
|
|
21
|
+
interval: 20,
|
|
22
|
+
frequency: 50
|
|
23
|
+
},
|
|
24
|
+
ui: {
|
|
25
|
+
interval: 60,
|
|
26
|
+
frequency: 16.67
|
|
27
|
+
},
|
|
28
|
+
normal: {
|
|
29
|
+
interval: 200,
|
|
30
|
+
frequency: 5
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const getDevicemotionListener = interval => {
|
|
34
|
+
let lock;
|
|
35
|
+
let timer;
|
|
36
|
+
return evt => {
|
|
37
|
+
if (lock)
|
|
38
|
+
return;
|
|
39
|
+
lock = true;
|
|
40
|
+
timer && clearTimeout(timer);
|
|
41
|
+
callbackManager.trigger({
|
|
42
|
+
x: evt.acceleration.x || 0,
|
|
43
|
+
y: evt.acceleration.y || 0,
|
|
44
|
+
z: evt.acceleration.z || 0
|
|
45
|
+
});
|
|
46
|
+
timer = setTimeout(() => { lock = false; }, interval);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* 开始监听加速度数据。
|
|
51
|
+
*/
|
|
52
|
+
export const startAccelerometer = ({ interval = 'normal', success, fail, complete } = {}) => {
|
|
53
|
+
const handle = new MethodHandler({ name: 'startAccelerometer', success, fail, complete });
|
|
54
|
+
try {
|
|
55
|
+
if (window.DeviceMotionEvent) {
|
|
56
|
+
const intervalObj = INTERVAL_MAP[interval];
|
|
57
|
+
if (devicemotionListener) {
|
|
58
|
+
stopAccelerometer();
|
|
59
|
+
}
|
|
60
|
+
devicemotionListener = getDevicemotionListener(intervalObj.interval);
|
|
61
|
+
window.addEventListener('devicemotion', devicemotionListener, true);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new Error('accelerometer is not supported');
|
|
65
|
+
}
|
|
66
|
+
return handle.success();
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
return handle.fail({ errMsg: e.message });
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* 监听加速度数据事件。频率根据 Taro.startAccelerometer() 的 interval 参数。可使用 Taro.stopAccelerometer() 停止监听。
|
|
74
|
+
*/
|
|
75
|
+
export const onAccelerometerChange = callback => {
|
|
76
|
+
callbackManager.add(callback);
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* 取消监听加速度数据事件,参数为空,则取消所有的事件监听
|
|
80
|
+
*/
|
|
81
|
+
export const offAccelerometerChange = callback => {
|
|
82
|
+
callbackManager.remove(callback);
|
|
83
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 蓝牙-低功耗中心设备
|
|
3
|
+
export const writeBLECharacteristicValue = temporarilyNotSupport('writeBLECharacteristicValue');
|
|
4
|
+
export const setBLEMTU = temporarilyNotSupport('setBLEMTU');
|
|
5
|
+
export const readBLECharacteristicValue = temporarilyNotSupport('readBLECharacteristicValue');
|
|
6
|
+
export const onBLEMTUChange = temporarilyNotSupport('onBLEMTUChange');
|
|
7
|
+
export const onBLEConnectionStateChange = temporarilyNotSupport('onBLEConnectionStateChange');
|
|
8
|
+
export const onBLECharacteristicValueChange = temporarilyNotSupport('onBLECharacteristicValueChange');
|
|
9
|
+
export const offBLEMTUChange = temporarilyNotSupport('offBLEMTUChange');
|
|
10
|
+
export const offBLEConnectionStateChange = temporarilyNotSupport('offBLEConnectionStateChange');
|
|
11
|
+
export const offBLECharacteristicValueChange = temporarilyNotSupport('offBLECharacteristicValueChange');
|
|
12
|
+
export const notifyBLECharacteristicValueChange = temporarilyNotSupport('notifyBLECharacteristicValueChange');
|
|
13
|
+
export const getBLEMTU = temporarilyNotSupport('getBLEMTU');
|
|
14
|
+
export const getBLEDeviceServices = temporarilyNotSupport('getBLEDeviceServices');
|
|
15
|
+
export const getBLEDeviceRSSI = temporarilyNotSupport('getBLEDeviceRSSI');
|
|
16
|
+
export const getBLEDeviceCharacteristics = temporarilyNotSupport('getBLEDeviceCharacteristics');
|
|
17
|
+
export const createBLEConnection = temporarilyNotSupport('createBLEConnection');
|
|
18
|
+
export const closeBLEConnection = temporarilyNotSupport('closeBLEConnection');
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 蓝牙-低功耗外围设备
|
|
3
|
+
export const onBLEPeripheralConnectionStateChanged = temporarilyNotSupport('onBLEPeripheralConnectionStateChanged');
|
|
4
|
+
export const offBLEPeripheralConnectionStateChanged = temporarilyNotSupport('offBLEPeripheralConnectionStateChanged');
|
|
5
|
+
export const createBLEPeripheralServer = temporarilyNotSupport('createBLEPeripheralServer');
|