@tarojs/taro-h5 3.3.16 → 3.3.20
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 +3 -0
- package/dist/api/ai/facial.js +4 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +2 -0
- package/dist/api/alipay/index.js +2 -0
- package/dist/api/base/crypto.js +2 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +16 -0
- package/dist/api/base/performance.js +3 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +56 -0
- package/dist/api/base/system/network.js +52 -0
- package/dist/api/base/update.js +3 -0
- package/dist/api/base/weapp/app-event.js +17 -0
- package/dist/api/base/weapp/life-cycle.js +3 -0
- package/dist/api/canvas/CanvasContext.js +182 -0
- package/dist/api/canvas/canvasGetImageData.js +21 -0
- package/dist/api/canvas/canvasPutImageData.js +17 -0
- package/dist/api/canvas/canvasToTempFilePath.js +18 -0
- package/dist/api/canvas/createCanvasContext.js +13 -0
- package/dist/api/canvas/index.js +7 -0
- package/dist/api/cloud/index.js +14 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +71 -0
- package/dist/api/device/accessibility.js +2 -0
- package/dist/api/device/battery.js +3 -0
- package/dist/api/device/bluetooth-ble.js +17 -0
- package/dist/api/device/bluetooth-peripheral.js +4 -0
- package/dist/api/device/bluetooth.js +14 -0
- package/dist/api/device/calendar.js +3 -0
- package/dist/api/device/clipboard.js +48 -0
- package/dist/api/device/compass.js +52 -0
- package/dist/api/device/contact.js +3 -0
- package/dist/api/device/crypto.js +2 -0
- package/dist/api/device/gyroscope.js +5 -0
- package/dist/api/device/iBeacon.js +8 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +5 -0
- package/dist/api/device/memory.js +3 -0
- package/dist/api/device/motion.js +69 -0
- package/dist/api/device/nfc.js +8 -0
- package/dist/api/device/phone.js +23 -0
- package/dist/api/device/scan.js +5 -0
- package/dist/api/device/screen.js +7 -0
- package/dist/api/device/vibrate.js +29 -0
- package/dist/api/device/wifi.js +11 -0
- package/dist/api/ext/index.js +3 -0
- package/dist/api/files/index.js +9 -0
- package/dist/api/framework/index.js +6 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +88 -0
- package/dist/api/location/index.js +12 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/audio/index.js +81 -0
- package/dist/api/media/background-audio.js +10 -0
- package/dist/api/media/camera.js +2 -0
- package/dist/api/media/editor.js +17 -0
- package/dist/api/media/image/chooseImage.js +70 -0
- package/dist/api/media/image/getImageInfo.js +27 -0
- package/dist/api/media/image/index.js +8 -0
- package/dist/api/media/image/previewImage.js +57 -0
- package/dist/api/media/index.js +13 -0
- package/dist/api/media/live.js +3 -0
- package/dist/api/media/map.js +2 -0
- package/dist/api/media/media-recorder.js +2 -0
- package/dist/api/media/recorder.js +4 -0
- package/dist/api/media/video/index.js +65 -0
- package/dist/api/media/video-decoder.js +2 -0
- package/dist/api/media/video-processing.js +2 -0
- package/dist/api/media/voip.js +15 -0
- package/dist/api/navigate/index.js +5 -0
- package/dist/api/network/download.js +101 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +11 -0
- package/dist/api/network/request/index.js +123 -0
- package/dist/api/network/tcp.js +2 -0
- package/dist/api/network/udp.js +2 -0
- package/dist/api/network/upload.js +129 -0
- package/dist/api/network/utils.js +30 -0
- package/dist/api/network/websocket/index.js +65 -0
- package/dist/api/network/websocket/socketTask.js +61 -0
- package/dist/api/open-api/account.js +2 -0
- package/dist/api/open-api/address.js +2 -0
- package/dist/api/open-api/authorize.js +3 -0
- package/dist/api/open-api/card.js +3 -0
- package/dist/api/open-api/channels-live.js +7 -0
- package/dist/api/open-api/customer-service.js +2 -0
- package/dist/api/open-api/facial.js +5 -0
- package/dist/api/open-api/favorites.js +3 -0
- package/dist/api/open-api/group.js +2 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +3 -0
- package/dist/api/open-api/license-plate.js +2 -0
- package/dist/api/open-api/login.js +4 -0
- package/dist/api/open-api/red-package.js +2 -0
- package/dist/api/open-api/settings.js +3 -0
- package/dist/api/open-api/soter.js +4 -0
- package/dist/api/open-api/subscribe-message.js +2 -0
- package/dist/api/open-api/user-info.js +3 -0
- package/dist/api/open-api/werun.js +3 -0
- package/dist/api/payment/index.js +3 -0
- package/dist/api/route/index.js +1 -0
- package/dist/api/share/index.js +11 -0
- package/dist/api/storage/background-fetch.js +5 -0
- package/dist/api/storage/index.js +152 -0
- package/dist/api/swan/index.js +22 -0
- package/dist/api/taro.js +59 -0
- package/dist/api/ui/animation/index.js +250 -0
- package/dist/api/ui/background.js +3 -0
- package/dist/api/ui/custom-component.js +2 -0
- package/dist/api/ui/fonts.js +2 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +172 -0
- package/dist/api/ui/interaction/index.js +263 -0
- package/dist/api/ui/interaction/modal.js +185 -0
- package/dist/api/ui/interaction/toast.js +179 -0
- package/dist/api/ui/menu.js +2 -0
- package/dist/api/ui/navigation-bar/index.js +37 -0
- package/dist/api/ui/pull-down-refresh.js +20 -0
- package/dist/api/ui/scroll/index.js +80 -0
- package/dist/api/ui/sticky.js +2 -0
- package/dist/api/ui/tab-bar.js +250 -0
- package/dist/api/ui/window.js +22 -0
- package/dist/api/utils/handler.js +64 -0
- package/dist/api/utils/index.js +141 -0
- package/dist/api/worker/index.js +2 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +42 -0
- package/dist/api/wxml/selectorQuery.js +188 -0
- package/dist/index.cjs.js +7477 -10829
- package/dist/index.js +4 -0
- package/dist/taroApis.js +1 -1
- package/dist/types/type.js +2 -0
- package/package.json +12 -15
- package/src/api/ad/index.ts +5 -0
- package/src/api/ai/facial.ts +6 -0
- package/src/api/ai/index.ts +2 -0
- package/src/api/ai/visual.ts +4 -0
- package/src/api/alipay/index.ts +4 -0
- package/src/api/base/crypto.ts +4 -0
- package/src/api/base/debug.ts +5 -0
- package/src/api/base/index.ts +23 -0
- package/src/api/base/performance.ts +5 -0
- package/src/api/base/system/index.ts +2 -0
- package/src/api/base/system/info.ts +64 -0
- package/src/api/base/system/network.ts +70 -0
- package/src/api/base/update.ts +5 -0
- package/src/api/base/weapp/app-event.ts +19 -0
- package/src/api/base/weapp/life-cycle.ts +5 -0
- package/src/api/canvas/CanvasContext.ts +233 -0
- package/src/api/canvas/canvasGetImageData.ts +27 -0
- package/src/api/canvas/canvasPutImageData.ts +24 -0
- package/src/api/canvas/canvasToTempFilePath.ts +24 -0
- package/src/api/canvas/createCanvasContext.ts +18 -0
- package/src/api/canvas/index.ts +10 -0
- package/src/api/cloud/index.ts +27 -0
- package/src/api/data-analysis/index.ts +6 -0
- package/src/api/device/accelerometer.ts +87 -0
- package/src/api/device/accessibility.ts +4 -0
- package/src/api/device/battery.ts +5 -0
- package/src/api/device/bluetooth-ble.ts +19 -0
- package/src/api/device/bluetooth-peripheral.ts +6 -0
- package/src/api/device/bluetooth.ts +16 -0
- package/src/api/device/calendar.ts +5 -0
- package/src/api/device/clipboard.ts +67 -0
- package/src/api/device/compass.ts +67 -0
- package/src/api/device/contact.ts +5 -0
- package/src/api/device/crypto.ts +4 -0
- package/src/api/device/gyroscope.ts +7 -0
- package/src/api/device/iBeacon.ts +10 -0
- package/src/api/device/index.ts +22 -0
- package/src/api/device/keyboard.ts +7 -0
- package/src/api/device/memory.ts +5 -0
- package/src/api/device/motion.ts +85 -0
- package/src/api/device/nfc.ts +10 -0
- package/src/api/device/phone.ts +30 -0
- package/src/api/device/scan.ts +7 -0
- package/src/api/device/screen.ts +9 -0
- package/src/api/device/vibrate.ts +36 -0
- package/src/api/device/wifi.ts +13 -0
- package/src/api/ext/index.ts +5 -0
- package/src/api/files/index.ts +11 -0
- package/src/api/framework/index.ts +10 -0
- package/src/api/index.ts +25 -0
- package/src/api/location/chooseLocation.ts +106 -0
- package/src/api/location/index.ts +19 -0
- package/src/api/location/style.css +8 -8
- package/src/api/media/audio/index.ts +105 -0
- package/src/api/media/background-audio.ts +12 -0
- package/src/api/media/camera.ts +4 -0
- package/src/api/media/editor.ts +29 -0
- package/src/api/media/image/chooseImage.ts +78 -0
- package/src/api/media/image/getImageInfo.ts +35 -0
- package/src/api/media/image/index.ts +13 -0
- package/src/api/media/image/previewImage.ts +80 -0
- package/src/api/media/index.ts +13 -0
- package/src/api/media/live.ts +5 -0
- package/src/api/media/map.ts +4 -0
- package/src/api/media/media-recorder.ts +4 -0
- package/src/api/media/recorder.ts +6 -0
- package/src/api/media/video/index.ts +82 -0
- package/src/api/media/video-decoder.ts +4 -0
- package/src/api/media/video-processing.ts +4 -0
- package/src/api/media/voip.ts +17 -0
- package/src/api/navigate/index.ts +7 -0
- package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -27
- package/src/api/network/index.ts +7 -0
- package/src/api/network/mdns.ts +13 -0
- package/src/api/{request/index.js → network/request/index.ts} +9 -6
- package/src/api/network/tcp.ts +4 -0
- package/src/api/network/udp.ts +4 -0
- package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -32
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/network/websocket/index.ts +88 -0
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
- package/src/api/open-api/account.ts +4 -0
- package/src/api/open-api/address.ts +4 -0
- package/src/api/open-api/authorize.ts +5 -0
- package/src/api/open-api/card.ts +5 -0
- package/src/api/open-api/channels-live.ts +9 -0
- package/src/api/open-api/customer-service.ts +4 -0
- package/src/api/open-api/facial.ts +7 -0
- package/src/api/open-api/favorites.ts +5 -0
- package/src/api/open-api/group.ts +4 -0
- package/src/api/open-api/index.ts +18 -0
- package/src/api/open-api/invoice.ts +5 -0
- package/src/api/open-api/license-plate.ts +4 -0
- package/src/api/open-api/login.ts +6 -0
- package/src/api/open-api/red-package.ts +4 -0
- package/src/api/open-api/settings.ts +5 -0
- package/src/api/open-api/soter.ts +6 -0
- package/src/api/open-api/subscribe-message.ts +4 -0
- package/src/api/open-api/user-info.ts +5 -0
- package/src/api/open-api/werun.ts +5 -0
- package/src/api/payment/index.ts +5 -0
- package/src/api/route/index.ts +10 -0
- package/src/api/share/index.ts +13 -0
- package/src/api/storage/background-fetch.ts +7 -0
- package/src/api/storage/index.ts +181 -0
- package/src/api/swan/index.ts +31 -0
- package/src/{taro/index.js → api/taro.ts} +133 -149
- package/src/api/{createAnimation/index.js → ui/animation/index.ts} +52 -41
- package/src/api/ui/background.ts +5 -0
- package/src/api/ui/custom-component.ts +4 -0
- package/src/api/ui/fonts.ts +4 -0
- package/src/api/ui/index.ts +12 -0
- package/src/api/ui/interaction/actionSheet.ts +212 -0
- package/src/api/{interactive/index.js → ui/interaction/index.ts} +93 -77
- package/src/api/ui/interaction/modal.ts +237 -0
- package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
- package/src/api/ui/menu.ts +4 -0
- package/src/api/ui/navigation-bar/index.ts +52 -0
- package/src/api/ui/pull-down-refresh.ts +27 -0
- package/src/api/ui/scroll/index.ts +85 -0
- package/src/api/ui/sticky.ts +4 -0
- package/src/api/ui/tab-bar.ts +326 -0
- package/src/api/ui/window.ts +37 -0
- package/src/api/utils/handler.ts +105 -0
- package/src/api/utils/{index.js → index.ts} +36 -115
- package/src/api/worker/index.ts +4 -0
- package/src/api/wxml/index.ts +9 -0
- package/src/api/wxml/nodesRef.ts +56 -0
- package/src/api/wxml/selectorQuery.ts +219 -0
- package/src/index.ts +6 -0
- package/src/types/api.d.ts +4 -0
- package/src/types/define.d.ts +2 -0
- package/{types → src/types}/index.d.ts +0 -0
- package/{types → src/types}/type.ts +1 -1
- package/src/api/accelerometer/index.js +0 -105
- package/src/api/audio/index.js +0 -137
- package/src/api/canvas/canvasGetImageData.js +0 -44
- package/src/api/canvas/canvasPutImageData.js +0 -45
- package/src/api/canvas/canvasToTempFilePath.js +0 -49
- package/src/api/canvas/createCanvasContext.js +0 -340
- package/src/api/canvas/index.js +0 -4
- package/src/api/clipboard/index.js +0 -113
- package/src/api/compass/index.js +0 -99
- package/src/api/createSelectorQuery/index.js +0 -193
- package/src/api/deviceMotion/index.js +0 -105
- package/src/api/fileTransfer/index.js +0 -2
- package/src/api/image/chooseImage.js +0 -87
- package/src/api/image/getImageInfo.js +0 -74
- package/src/api/image/index.js +0 -7
- package/src/api/image/previewImage.js +0 -94
- package/src/api/index.js +0 -29
- package/src/api/interactive/actionSheet.js +0 -214
- package/src/api/interactive/modal.js +0 -256
- package/src/api/location/chooseLocation.js +0 -143
- package/src/api/location/index.js +0 -5
- package/src/api/navigationBar/index.js +0 -57
- package/src/api/open/index.js +0 -5
- package/src/api/others/index.js +0 -43
- package/src/api/pullDownRefresh/index.js +0 -51
- package/src/api/scroll/index.js +0 -99
- package/src/api/storage/index.js +0 -211
- package/src/api/system/index.js +0 -9
- package/src/api/system/info.js +0 -36
- package/src/api/system/network.js +0 -68
- package/src/api/tabBar/index.js +0 -402
- package/src/api/unsupportedApi/index.js +0 -278
- package/src/api/vibrate/index.js +0 -49
- package/src/api/video/index.js +0 -87
- package/src/api/webSocket/index.js +0 -103
- package/src/api/window/index.js +0 -38
- package/src/index.cjs.js +0 -11
- package/src/index.js +0 -6
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import { findDOM } from '../utils/index'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 创建 canvas 的绘图上下文 CanvasContext 对象
|
|
5
|
-
* @param {string} canvasId 要获取上下文的 <canvas> 组件 canvas-id 属性
|
|
6
|
-
*/
|
|
7
|
-
const createCanvasContext = (canvasId, inst) => {
|
|
8
|
-
/** @type {HTMLCanvasElement} */
|
|
9
|
-
const canvas = findDOM(inst).querySelector(`canvas[canvas-id="${canvasId}"]`)
|
|
10
|
-
|
|
11
|
-
/** @type {CanvasRenderingContext2D} */
|
|
12
|
-
const ctx = canvas.getContext('2d')
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {Object} Action
|
|
16
|
-
* @property {Function} func
|
|
17
|
-
* @property {any[]} args
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 操作队列
|
|
22
|
-
* @type {Action[]}
|
|
23
|
-
*/
|
|
24
|
-
const actions = []
|
|
25
|
-
const enqueueActions = (func) => {
|
|
26
|
-
return (...args) => {
|
|
27
|
-
actions.push({
|
|
28
|
-
func,
|
|
29
|
-
args
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const emptyActions = () => {
|
|
34
|
-
actions.length = 0
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 将之前在绘图上下文中的描述(路径、变形、样式)画到 canvas 中。
|
|
39
|
-
* @param {Boolean} [reserve=false] 本次绘制是否接着上一次绘制。
|
|
40
|
-
* 即 reserve 参数为 false,则在本次调用绘制之前 native 层会先清空画布再继续绘制;
|
|
41
|
-
* 若 reserve 参数为 true,则保留当前画布上的内容,本次调用 drawCanvas 绘制的内容覆盖在上面,
|
|
42
|
-
* 默认 false。
|
|
43
|
-
* @param {Function} [callback] 绘制完成后执行的回调函数
|
|
44
|
-
* @todo 每次draw都会读取width和height
|
|
45
|
-
*/
|
|
46
|
-
const draw = async (reserve = false, callback) => {
|
|
47
|
-
try {
|
|
48
|
-
if (!reserve) {
|
|
49
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 部分 action 是异步的
|
|
53
|
-
for (const { func, args } of actions) {
|
|
54
|
-
await func.apply(ctx, args)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
emptyActions()
|
|
58
|
-
callback && callback()
|
|
59
|
-
} catch (e) {
|
|
60
|
-
/* eslint-disable no-throw-literal */
|
|
61
|
-
throw {
|
|
62
|
-
errMsg: e.message
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const customProperties = [
|
|
68
|
-
/**
|
|
69
|
-
* 设置填充色。
|
|
70
|
-
* @param {String} color 填充的颜色,默认颜色为 black。
|
|
71
|
-
*/
|
|
72
|
-
[
|
|
73
|
-
'setFillStyle',
|
|
74
|
-
(color) => {
|
|
75
|
-
ctx.fillStyle = color
|
|
76
|
-
}
|
|
77
|
-
],
|
|
78
|
-
/**
|
|
79
|
-
* 设置字体的字号。
|
|
80
|
-
* @param {Number} fontSize 字体的字号
|
|
81
|
-
*/
|
|
82
|
-
[
|
|
83
|
-
'setFontSize',
|
|
84
|
-
(fontSize) => {
|
|
85
|
-
ctx.font = fontSize
|
|
86
|
-
},
|
|
87
|
-
true
|
|
88
|
-
],
|
|
89
|
-
/**
|
|
90
|
-
* 设置全局画笔透明度。
|
|
91
|
-
* @param {Number} alpha 透明度。范围 0-1,0 表示完全透明,1 表示完全不透明。
|
|
92
|
-
*/
|
|
93
|
-
[
|
|
94
|
-
'setGlobalAlpha',
|
|
95
|
-
(alpha) => {
|
|
96
|
-
ctx.globalAlpha = alpha
|
|
97
|
-
}
|
|
98
|
-
],
|
|
99
|
-
/**
|
|
100
|
-
* 设置虚线样式。
|
|
101
|
-
* @param {Number[]} pattern 一组描述交替绘制线段和间距(坐标空间单位)长度的数字
|
|
102
|
-
* @param {Number} offset 虚线偏移量
|
|
103
|
-
*/
|
|
104
|
-
[
|
|
105
|
-
'setLineDash',
|
|
106
|
-
(pattern, offset) => {
|
|
107
|
-
ctx.setLineDash(pattern)
|
|
108
|
-
ctx.lineDashOffset = offset
|
|
109
|
-
}
|
|
110
|
-
],
|
|
111
|
-
/**
|
|
112
|
-
* 设置线条的端点样式ind
|
|
113
|
-
* @param {String} lineCap 线条的结束端点样式
|
|
114
|
-
*/
|
|
115
|
-
[
|
|
116
|
-
'setLineCap',
|
|
117
|
-
(lineCap) => {
|
|
118
|
-
ctx.lineCap = lineCap
|
|
119
|
-
}
|
|
120
|
-
],
|
|
121
|
-
/**
|
|
122
|
-
* 设置线条的交点样式
|
|
123
|
-
* @param {String} lineJoin 线条的结束交点样式
|
|
124
|
-
*/
|
|
125
|
-
[
|
|
126
|
-
'setLineJoin',
|
|
127
|
-
(lineJoin) => {
|
|
128
|
-
ctx.lineJoin = lineJoin
|
|
129
|
-
}
|
|
130
|
-
],
|
|
131
|
-
/**
|
|
132
|
-
* 设置线条的宽度
|
|
133
|
-
* @param {number} lineWidth 线条的宽度,单位px
|
|
134
|
-
*/
|
|
135
|
-
[
|
|
136
|
-
'setLineWidth',
|
|
137
|
-
(lineWidth) => {
|
|
138
|
-
ctx.lineWidth = lineWidth
|
|
139
|
-
}
|
|
140
|
-
],
|
|
141
|
-
/**
|
|
142
|
-
* 设置最大斜接长度。斜接长度指的是在两条线交汇处内角和外角之间的距离。当 CanvasContext.setLineJoin() 为 miter 时才有效。超过最大倾斜长度的,连接处将以 lineJoin 为 bevel 来显示。
|
|
143
|
-
* @param {number} miterLimit 最大斜接长度
|
|
144
|
-
*/
|
|
145
|
-
[
|
|
146
|
-
'setMiterLimit',
|
|
147
|
-
(miterLimit) => {
|
|
148
|
-
ctx.miterLimit = miterLimit
|
|
149
|
-
}
|
|
150
|
-
],
|
|
151
|
-
/**
|
|
152
|
-
* 设定阴影样式。
|
|
153
|
-
* @param {number} offsetX 阴影相对于形状在水平方向的偏移,默认值为 0。
|
|
154
|
-
* @param {number} offsetY 阴影相对于形状在竖直方向的偏移,默认值为 0。
|
|
155
|
-
* @param {number} blur 阴影的模糊级别,数值越大越模糊。范围 0- 100。,默认值为 0。
|
|
156
|
-
* @param {string} color 阴影的颜色。默认值为 black。
|
|
157
|
-
*/
|
|
158
|
-
[
|
|
159
|
-
'setShadow',
|
|
160
|
-
(offsetX, offsetY, blur, color) => {
|
|
161
|
-
ctx.shadowOffsetX = offsetX
|
|
162
|
-
ctx.shadowOffsetY = offsetY
|
|
163
|
-
ctx.shadowColor = blur
|
|
164
|
-
ctx.shadowBlur = color
|
|
165
|
-
}
|
|
166
|
-
],
|
|
167
|
-
/**
|
|
168
|
-
* 设置描边颜色。
|
|
169
|
-
* @param {String} color 描边的颜色,默认颜色为 black。
|
|
170
|
-
*/
|
|
171
|
-
[
|
|
172
|
-
'setStrokeStyle',
|
|
173
|
-
(color) => {
|
|
174
|
-
ctx.strokeStyle = color
|
|
175
|
-
}
|
|
176
|
-
],
|
|
177
|
-
/**
|
|
178
|
-
* 设置文字的对齐
|
|
179
|
-
* @param {String} align 文字的对齐方式
|
|
180
|
-
*/
|
|
181
|
-
[
|
|
182
|
-
'setTextAlign',
|
|
183
|
-
(align) => {
|
|
184
|
-
ctx.textAlign = align
|
|
185
|
-
},
|
|
186
|
-
true
|
|
187
|
-
],
|
|
188
|
-
/**
|
|
189
|
-
* 设置文字的竖直对齐
|
|
190
|
-
* @param {string} textBaseline 文字的竖直对齐方式
|
|
191
|
-
*/
|
|
192
|
-
[
|
|
193
|
-
'setTextBaseline',
|
|
194
|
-
(textBaseline) => {
|
|
195
|
-
ctx.textBaseline = textBaseline
|
|
196
|
-
},
|
|
197
|
-
true
|
|
198
|
-
],
|
|
199
|
-
[
|
|
200
|
-
'drawImage',
|
|
201
|
-
(url, ...extra) => {
|
|
202
|
-
// 需要转换为 Image
|
|
203
|
-
if (typeof url === 'string') {
|
|
204
|
-
const img = new Image()
|
|
205
|
-
img.src = url
|
|
206
|
-
return new Promise((resolve, reject) => {
|
|
207
|
-
img.onload = () => {
|
|
208
|
-
ctx.drawImage(img, ...extra)
|
|
209
|
-
resolve()
|
|
210
|
-
}
|
|
211
|
-
img.onerror = reject
|
|
212
|
-
})
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
ctx.drawImage(url, ...extra)
|
|
216
|
-
}
|
|
217
|
-
]
|
|
218
|
-
]
|
|
219
|
-
|
|
220
|
-
const functionProperties = [
|
|
221
|
-
['arc'],
|
|
222
|
-
['arcTo'],
|
|
223
|
-
['beginPath'],
|
|
224
|
-
['bezierCurveTo'],
|
|
225
|
-
['clearRect'],
|
|
226
|
-
['clip'],
|
|
227
|
-
['closePath'],
|
|
228
|
-
['createLinearGradient', true],
|
|
229
|
-
['createPattern', true],
|
|
230
|
-
['fill'],
|
|
231
|
-
['fillRect'],
|
|
232
|
-
['fillText'],
|
|
233
|
-
['lineTo'],
|
|
234
|
-
['measureText', true],
|
|
235
|
-
['moveTo'],
|
|
236
|
-
['quadraticCurveTo'],
|
|
237
|
-
['rect'],
|
|
238
|
-
['restore'],
|
|
239
|
-
['rotate'],
|
|
240
|
-
['save'],
|
|
241
|
-
['scale'],
|
|
242
|
-
['setTransform'],
|
|
243
|
-
['stroke'],
|
|
244
|
-
['strokeRect'],
|
|
245
|
-
['strokeText'],
|
|
246
|
-
['transform'],
|
|
247
|
-
['translate']
|
|
248
|
-
]
|
|
249
|
-
|
|
250
|
-
const valueProperties = [
|
|
251
|
-
['fillStyle'],
|
|
252
|
-
['font', true],
|
|
253
|
-
['globalAlpha'],
|
|
254
|
-
['lineCap'],
|
|
255
|
-
['lineDashOffset'],
|
|
256
|
-
['lineJoin'],
|
|
257
|
-
['lineWidth'],
|
|
258
|
-
['miterLimit'],
|
|
259
|
-
['shadowOffsetX'],
|
|
260
|
-
['shadowOffsetY'],
|
|
261
|
-
['shadowColor'],
|
|
262
|
-
['shadowBlur'],
|
|
263
|
-
['strokeStyle'],
|
|
264
|
-
['textAlign', true],
|
|
265
|
-
['textBaseline', true],
|
|
266
|
-
['direction', true],
|
|
267
|
-
['globalCompositeOperation'],
|
|
268
|
-
['imageSmoothingEnabled '],
|
|
269
|
-
['imageSmoothingQuality'],
|
|
270
|
-
['filter']
|
|
271
|
-
]
|
|
272
|
-
|
|
273
|
-
const CanvasContext = { __raw__: ctx }
|
|
274
|
-
|
|
275
|
-
customProperties.forEach(([funcName, func, setImmediatly]) => {
|
|
276
|
-
Object.defineProperty(CanvasContext, funcName, {
|
|
277
|
-
get () {
|
|
278
|
-
const fn = enqueueActions(func)
|
|
279
|
-
|
|
280
|
-
return (...args) => {
|
|
281
|
-
// 立即触发
|
|
282
|
-
if (setImmediatly) {
|
|
283
|
-
func.apply(ctx, args)
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return fn(...args)
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
enumerable: true
|
|
290
|
-
})
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
functionProperties.forEach(([funcName, isSync]) => {
|
|
294
|
-
Object.defineProperty(CanvasContext, funcName, {
|
|
295
|
-
get: isSync
|
|
296
|
-
? () => ctx[funcName].bind(ctx)
|
|
297
|
-
: () => enqueueActions(ctx[funcName]),
|
|
298
|
-
enumerable: true
|
|
299
|
-
})
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
valueProperties.forEach(([propertyName, setImmediatly]) => {
|
|
303
|
-
Object.defineProperty(CanvasContext, propertyName, {
|
|
304
|
-
get () {
|
|
305
|
-
return ctx[propertyName]
|
|
306
|
-
},
|
|
307
|
-
set (value) {
|
|
308
|
-
if (setImmediatly) {
|
|
309
|
-
ctx[propertyName] = value
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
enqueueActions(() => {
|
|
313
|
-
ctx[propertyName] = value
|
|
314
|
-
})()
|
|
315
|
-
return true
|
|
316
|
-
}
|
|
317
|
-
})
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
Object.defineProperty(CanvasContext, 'createCircularGradient', {
|
|
321
|
-
/**
|
|
322
|
-
* @param {number} x
|
|
323
|
-
* @param {number} y
|
|
324
|
-
* @param {number} r
|
|
325
|
-
*/
|
|
326
|
-
value: (x, y, r) => {
|
|
327
|
-
const radialGradient = ctx.createRadialGradient(x, y, 0, x, y, r)
|
|
328
|
-
|
|
329
|
-
return radialGradient
|
|
330
|
-
}
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
Object.defineProperty(CanvasContext, 'draw', {
|
|
334
|
-
value: draw
|
|
335
|
-
})
|
|
336
|
-
|
|
337
|
-
return CanvasContext
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export default createCanvasContext
|
package/src/api/canvas/index.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { default as canvasGetImageData } from './canvasGetImageData'
|
|
2
|
-
export { default as canvasPutImageData } from './canvasPutImageData'
|
|
3
|
-
export { default as canvasToTempFilePath } from './canvasToTempFilePath'
|
|
4
|
-
export { default as createCanvasContext } from './createCanvasContext'
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 剪贴板部分的api参考了Chameleon项目的实现:
|
|
3
|
-
*
|
|
4
|
-
* setClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/setClipBoardData
|
|
5
|
-
* getClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/getClipBoardData
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { setStorage, getStorage } from '../storage/index'
|
|
9
|
-
|
|
10
|
-
const CLIPBOARD_STORAGE_NAME = 'taro_clipboard'
|
|
11
|
-
|
|
12
|
-
document.addEventListener('copy', () => {
|
|
13
|
-
setStorage({
|
|
14
|
-
key: CLIPBOARD_STORAGE_NAME,
|
|
15
|
-
data: window.getSelection().toString()
|
|
16
|
-
}).catch(e => {
|
|
17
|
-
console.error(e)
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 成功回调
|
|
23
|
-
* @callback SuccessCallback
|
|
24
|
-
* @param {{ errMsg: string, data: string }}
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 失败回调
|
|
29
|
-
* @callback FailCallback
|
|
30
|
-
* @param {{ errMsg: string }}
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 完成回调
|
|
35
|
-
* @callback CompleteCallback
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 设置系统剪贴板的内容
|
|
40
|
-
* @param {{ data: string, success: SuccessCallback, fail: FailCallback, complete: CompleteCallback }} object 参数
|
|
41
|
-
* @returns {Promise<{ errMsg: string, data: string }>}
|
|
42
|
-
*/
|
|
43
|
-
export const setClipboardData = ({ data, success, fail, complete }) => {
|
|
44
|
-
return new Promise((resolve, reject) => {
|
|
45
|
-
setStorage({
|
|
46
|
-
key: CLIPBOARD_STORAGE_NAME,
|
|
47
|
-
data
|
|
48
|
-
}).then(() => {
|
|
49
|
-
/**
|
|
50
|
-
* 已于 iPhone 6s Plus iOS 13.1.3 上的 Safari 测试通过
|
|
51
|
-
* iOS < 10 的系统可能无法使用编程方式访问剪贴板,参考:
|
|
52
|
-
* https://stackoverflow.com/questions/34045777/copy-to-clipboard-using-javascript-in-ios/34046084
|
|
53
|
-
*/
|
|
54
|
-
if (typeof document.execCommand === 'function') {
|
|
55
|
-
const textarea = document.createElement('textarea')
|
|
56
|
-
textarea.readOnly = true
|
|
57
|
-
textarea.value = data
|
|
58
|
-
textarea.style.position = 'absolute'
|
|
59
|
-
textarea.style.width = '100px'
|
|
60
|
-
textarea.style.left = '-10000px'
|
|
61
|
-
document.body.appendChild(textarea)
|
|
62
|
-
textarea.select()
|
|
63
|
-
textarea.setSelectionRange(0, textarea.value.length)
|
|
64
|
-
document.execCommand('copy')
|
|
65
|
-
document.body.removeChild(textarea)
|
|
66
|
-
} else {
|
|
67
|
-
throw new Error('Unsupported Function: \'document.execCommand\'.')
|
|
68
|
-
}
|
|
69
|
-
const res = {
|
|
70
|
-
errMsg: 'setClipboardData:ok',
|
|
71
|
-
data
|
|
72
|
-
}
|
|
73
|
-
success && success(res)
|
|
74
|
-
complete && complete()
|
|
75
|
-
resolve(res)
|
|
76
|
-
}).catch(e => {
|
|
77
|
-
const res = {
|
|
78
|
-
errMsg: `setClipboardData:fail ${e.message}`
|
|
79
|
-
}
|
|
80
|
-
fail && fail(res)
|
|
81
|
-
complete && complete()
|
|
82
|
-
reject(res)
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 获取系统剪贴板的内容
|
|
89
|
-
* @param {{ success: SuccessCallback, fail: FailCallback, complete: CompleteCallback }} object 参数
|
|
90
|
-
* @returns {Promise<{ errMsg: string, data: string }>}
|
|
91
|
-
*/
|
|
92
|
-
export const getClipboardData = ({ success, fail, complete } = {}) => {
|
|
93
|
-
return new Promise((resolve, reject) => {
|
|
94
|
-
getStorage({
|
|
95
|
-
key: CLIPBOARD_STORAGE_NAME
|
|
96
|
-
}).then(data => {
|
|
97
|
-
const res = {
|
|
98
|
-
errMsg: 'getClipboardData:ok',
|
|
99
|
-
data
|
|
100
|
-
}
|
|
101
|
-
success && success(res)
|
|
102
|
-
complete && complete()
|
|
103
|
-
resolve(res)
|
|
104
|
-
}).catch(e => {
|
|
105
|
-
const res = {
|
|
106
|
-
errMsg: `getClipboardData:fail ${e.message}`
|
|
107
|
-
}
|
|
108
|
-
fail && fail(res)
|
|
109
|
-
complete && complete()
|
|
110
|
-
reject(res)
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
}
|
package/src/api/compass/index.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { createCallbackManager, successHandler, errorHandler } from '../utils/index'
|
|
2
|
-
|
|
3
|
-
let compassListener
|
|
4
|
-
const callbackManager = createCallbackManager()
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 停止监听罗盘数据
|
|
8
|
-
* @param {Object} object 参数
|
|
9
|
-
* @param {function} [object.success] 接口调用成功的回调函数
|
|
10
|
-
* @param {function} [object.fail] 接口调用失败的回调函数
|
|
11
|
-
* @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
12
|
-
*/
|
|
13
|
-
const stopCompass = ({ success, fail, complete } = {}) => {
|
|
14
|
-
try {
|
|
15
|
-
window.removeEventListener('deviceorientation', compassListener, true)
|
|
16
|
-
return successHandler(success, complete)({
|
|
17
|
-
errMsg: 'stopCompass:ok'
|
|
18
|
-
})
|
|
19
|
-
} catch (e) {
|
|
20
|
-
return errorHandler(fail, complete)({
|
|
21
|
-
errMsg: `stopCompass:fail ${e.message}`
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const getDeviceOrientationListener = interval => {
|
|
27
|
-
let lock
|
|
28
|
-
let timer
|
|
29
|
-
return evt => {
|
|
30
|
-
if (lock) return
|
|
31
|
-
lock = true
|
|
32
|
-
timer && clearTimeout(timer)
|
|
33
|
-
callbackManager.trigger({
|
|
34
|
-
direction: 360 - evt.alpha
|
|
35
|
-
})
|
|
36
|
-
timer = setTimeout(() => { lock = false }, interval)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 开始监听罗盘数据
|
|
42
|
-
* @param {Object} object 参数
|
|
43
|
-
* @param {function} [object.success] 接口调用成功的回调函数
|
|
44
|
-
* @param {function} [object.fail] 接口调用失败的回调函数
|
|
45
|
-
* @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
46
|
-
*/
|
|
47
|
-
const startCompass = ({ success, fail, complete } = {}) => {
|
|
48
|
-
try {
|
|
49
|
-
if (window.DeviceOrientationEvent) {
|
|
50
|
-
if (compassListener) {
|
|
51
|
-
stopCompass()
|
|
52
|
-
}
|
|
53
|
-
compassListener = getDeviceOrientationListener(200)
|
|
54
|
-
window.addEventListener('deviceorientation', compassListener, true)
|
|
55
|
-
} else {
|
|
56
|
-
throw new Error('compass is not supported')
|
|
57
|
-
}
|
|
58
|
-
return successHandler(success, complete)({
|
|
59
|
-
errMsg: 'startCompass:ok'
|
|
60
|
-
})
|
|
61
|
-
} catch (e) {
|
|
62
|
-
return errorHandler(fail, complete)({
|
|
63
|
-
errMsg: `startCompass:fail ${e.message}`
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @typedef CompassParam 回调参数
|
|
70
|
-
* @property {number} direction 面对的方向度数
|
|
71
|
-
* @property {Accuracy} [accuracy] 精度
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @typedef {'high'|'medium'|'low'|'no-contact'|'unreliable'|'unknow'|number} Accuracy
|
|
76
|
-
* 由于平台差异,accuracy 在 iOS/Android 的值不同。
|
|
77
|
-
* iOS:accuracy 是一个 number 类型的值,表示相对于磁北极的偏差。0 表示设备指向磁北,90 表示指向东,180 表示指向南,依此类推。
|
|
78
|
-
* Android:accuracy 是一个 string 类型的枚举值。
|
|
79
|
-
* high 高精度
|
|
80
|
-
* medium 中等精度
|
|
81
|
-
* low 低精度
|
|
82
|
-
* no-contact 不可信,传感器失去连接
|
|
83
|
-
* unreliable 不可信,原因未知
|
|
84
|
-
* unknow ${value} 未知的精度枚举值,即该 Android 系统此时返回的表示精度的 value 不是一个标准的精度枚举值
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 监听罗盘数据变化事件。频率:5 次/秒,接口调用后会自动开始监听,可使用 wx.stopCompass 停止监听。
|
|
89
|
-
* @param {(obj: CompassParam) => void} callback 罗盘数据变化事件的回调函数
|
|
90
|
-
*/
|
|
91
|
-
const onCompassChange = callback => {
|
|
92
|
-
callbackManager.add(callback)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export {
|
|
96
|
-
stopCompass,
|
|
97
|
-
startCompass,
|
|
98
|
-
onCompassChange
|
|
99
|
-
}
|