@tarojs/taro-h5 3.3.13 → 3.3.17
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/index.cjs.js +6134 -8352
- package/dist/index.js +9044 -0
- package/dist/taroApis.js +1 -1
- package/package.json +9 -9
- 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 +230 -0
- package/src/api/canvas/canvasGetImageData.ts +29 -0
- package/src/api/canvas/canvasPutImageData.ts +26 -0
- package/src/api/canvas/canvasToTempFilePath.ts +26 -0
- package/src/api/canvas/createCanvasContext.ts +20 -0
- package/src/api/canvas/{index.js → index.ts} +9 -3
- package/src/api/cloud/index.ts +27 -0
- package/src/api/data-analysis/index.ts +6 -0
- package/src/api/device/accelerometer.ts +89 -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 +74 -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 +92 -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 +99 -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 +80 -0
- package/src/api/{image → media/image}/getImageInfo.js +0 -0
- package/src/api/media/image/index.ts +13 -0
- package/src/api/{image → media/image}/previewImage.js +4 -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 -25
- 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 -30
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/{webSocket/index.js → network/websocket/index.ts} +50 -57
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +16 -6
- 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 +193 -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} +26 -14
- 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} +102 -90
- 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 +32 -0
- package/src/api/{scroll/index.js → ui/scroll/index.ts} +16 -28
- 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} +24 -87
- package/src/api/worker/index.ts +4 -0
- package/src/api/wxml/index.ts +9 -0
- package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +86 -59
- 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/clipboard/index.js +0 -113
- package/src/api/compass/index.js +0 -99
- 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/index.js +0 -7
- 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/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 -424
- 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/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
|
|
@@ -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
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { createCallbackManager, successHandler, errorHandler } from '../utils/index'
|
|
2
|
-
|
|
3
|
-
let deviceMotionListener
|
|
4
|
-
const callbackManager = createCallbackManager()
|
|
5
|
-
|
|
6
|
-
const INTERVALMAP = {
|
|
7
|
-
game: {
|
|
8
|
-
interval: 20,
|
|
9
|
-
frequency: 50
|
|
10
|
-
},
|
|
11
|
-
ui: {
|
|
12
|
-
interval: 60,
|
|
13
|
-
frequency: 16.67
|
|
14
|
-
},
|
|
15
|
-
normal: {
|
|
16
|
-
interval: 200,
|
|
17
|
-
frequency: 5
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 停止监听设备方向的变化。
|
|
23
|
-
* @param {Object} object 参数
|
|
24
|
-
* @param {function} [object.success] 接口调用成功的回调函数
|
|
25
|
-
* @param {function} [object.fail] 接口调用失败的回调函数
|
|
26
|
-
* @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
27
|
-
*/
|
|
28
|
-
const stopDeviceMotionListening = ({ success, fail, complete }) => {
|
|
29
|
-
try {
|
|
30
|
-
window.removeEventListener('deviceorientation', deviceMotionListener, true)
|
|
31
|
-
return successHandler(success, complete)({
|
|
32
|
-
errMsg: 'stopDeviceMotionListening:ok'
|
|
33
|
-
})
|
|
34
|
-
} catch (e) {
|
|
35
|
-
return errorHandler(fail, complete)({
|
|
36
|
-
errMsg: `stopDeviceMotionListening:fail ${e.message}`
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const getDeviceOrientationListener = interval => {
|
|
42
|
-
let lock
|
|
43
|
-
let timer
|
|
44
|
-
return evt => {
|
|
45
|
-
if (lock) return
|
|
46
|
-
lock = true
|
|
47
|
-
timer && clearTimeout(timer)
|
|
48
|
-
callbackManager.trigger({
|
|
49
|
-
alpha: evt.alpha,
|
|
50
|
-
beta: evt.beta,
|
|
51
|
-
gamma: evt.gamma
|
|
52
|
-
})
|
|
53
|
-
timer = setTimeout(() => { lock = false }, interval)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 开始监听设备方向的变化。
|
|
59
|
-
* @param {Object} object 参数
|
|
60
|
-
* @param {function} [object.success] 接口调用成功的回调函数
|
|
61
|
-
* @param {function} [object.fail] 接口调用失败的回调函数
|
|
62
|
-
* @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
63
|
-
*/
|
|
64
|
-
const startDeviceMotionListening = ({ interval = 'normal', success, fail, complete } = {}) => {
|
|
65
|
-
try {
|
|
66
|
-
const intervalObj = INTERVALMAP[interval]
|
|
67
|
-
if (window.DeviceOrientationEvent) {
|
|
68
|
-
if (deviceMotionListener) {
|
|
69
|
-
stopDeviceMotionListening()
|
|
70
|
-
}
|
|
71
|
-
deviceMotionListener = getDeviceOrientationListener(intervalObj.interval)
|
|
72
|
-
window.addEventListener('deviceorientation', deviceMotionListener, true)
|
|
73
|
-
} else {
|
|
74
|
-
throw new Error('deviceMotion is not supported')
|
|
75
|
-
}
|
|
76
|
-
return successHandler(success, complete)({
|
|
77
|
-
errMsg: 'startDeviceMotionListening:ok'
|
|
78
|
-
})
|
|
79
|
-
} catch (e) {
|
|
80
|
-
return errorHandler(fail, complete)({
|
|
81
|
-
errMsg: `startDeviceMotionListening:fail ${e.message}`
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @typedef DeviceMotionParam 回调参数
|
|
88
|
-
* @property {number} alpha 当手机坐标 X/Y 和 地球 X/Y 重合时,绕着 Z 轴转动的夹角为 alpha,范围值为 [0, 2*PI)。逆时针转动为正。
|
|
89
|
-
* @property {number} beta 当手机坐标 Y/Z 和地球 Y/Z 重合时,绕着 X 轴转动的夹角为 beta。范围值为 [-1*PI, PI) 。顶部朝着地球表面转动为正。也有可能朝着用户为正。
|
|
90
|
-
* @property {number} gamma 当手机 X/Z 和地球 X/Z 重合时,绕着 Y 轴转动的夹角为 gamma。范围值为 [-1*PI/2, PI/2)。右边朝着地球表面转动为正。
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 监听设备方向变化事件。频率根据 wx.startDeviceMotionListeningListening() 的 interval 参数。可以使用 wx.stopDeviceMotionListeningListening() 停止监听。
|
|
95
|
-
* @param {(obj: DeviceMotionParam) => void} callback 罗盘数据变化事件的回调函数
|
|
96
|
-
*/
|
|
97
|
-
const onDeviceMotionChange = callback => {
|
|
98
|
-
callbackManager.add(callback)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export {
|
|
102
|
-
stopDeviceMotionListening,
|
|
103
|
-
startDeviceMotionListening,
|
|
104
|
-
onDeviceMotionChange
|
|
105
|
-
}
|