@tarojs/taro-h5 3.5.0-alpha.13 → 3.5.0-alpha.16
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.d.ts +6 -0
- package/dist/api/ai/facial.d.ts +9 -0
- package/dist/api/ai/index.d.ts +2 -0
- package/dist/api/ai/visual.d.ts +6 -0
- package/dist/api/alipay/index.d.ts +3 -0
- package/dist/api/base/crypto.d.ts +3 -0
- package/dist/api/base/debug.d.ts +9 -0
- package/dist/api/base/index.d.ts +12 -0
- package/dist/api/base/performance.d.ts +6 -0
- package/dist/api/base/system.d.ts +27 -0
- package/dist/api/base/system.js +2 -2
- package/dist/api/base/update.d.ts +6 -0
- package/dist/api/base/weapp/app-event.d.ts +41 -0
- package/dist/api/base/weapp/app-event.js +55 -4
- package/dist/api/base/weapp/life-cycle.d.ts +6 -0
- package/dist/api/canvas/CanvasContext.d.ts +104 -0
- package/dist/api/canvas/canvasGetImageData.d.ts +5 -0
- package/dist/api/canvas/canvasPutImageData.d.ts +6 -0
- package/dist/api/canvas/canvasToTempFilePath.d.ts +6 -0
- package/dist/api/canvas/canvasToTempFilePath.js +1 -1
- package/dist/api/canvas/createCanvasContext.d.ts +5 -0
- package/dist/api/canvas/index.d.ts +12 -0
- package/dist/api/cloud/index.d.ts +31 -0
- package/dist/api/data-analysis/index.d.ts +12 -0
- package/dist/api/device/accelerometer.d.ts +17 -0
- package/dist/api/device/accessibility.d.ts +3 -0
- package/dist/api/device/battery.d.ts +5 -0
- package/dist/api/device/bluetooth-ble.d.ts +48 -0
- package/dist/api/device/bluetooth-peripheral.d.ts +9 -0
- package/dist/api/device/bluetooth.d.ts +39 -0
- package/dist/api/device/calendar.d.ts +6 -0
- package/dist/api/device/clipboard.d.ts +15 -0
- package/dist/api/device/compass.d.ts +17 -0
- package/dist/api/device/contact.d.ts +6 -0
- package/dist/api/device/crypto.d.ts +3 -0
- package/dist/api/device/gyroscope.d.ts +12 -0
- package/dist/api/device/iBeacon.d.ts +21 -0
- package/dist/api/device/index.d.ts +23 -0
- package/dist/api/device/keyboard.d.ts +12 -0
- package/dist/api/device/memory.d.ts +6 -0
- package/dist/api/device/motion.d.ts +17 -0
- package/dist/api/device/network.d.ts +20 -0
- package/dist/api/device/nfc.d.ts +21 -0
- package/dist/api/device/phone.d.ts +2 -0
- package/dist/api/device/scan.d.ts +3 -0
- package/dist/api/device/screen.d.ts +18 -0
- package/dist/api/device/vibrate.d.ts +9 -0
- package/dist/api/device/vibrate.js +5 -7
- package/dist/api/device/wifi.d.ts +33 -0
- package/dist/api/ext/index.d.ts +6 -0
- package/dist/api/files/index.d.ts +24 -0
- package/dist/api/framework/index.d.ts +4 -0
- package/dist/api/index.d.ts +24 -0
- package/dist/api/location/chooseLocation.d.ts +6 -0
- package/dist/api/location/getLocation.d.ts +2 -0
- package/dist/api/location/index.d.ts +32 -0
- package/dist/api/location/index.js +1 -0
- package/dist/api/media/EditorContext.d.ts +42 -0
- package/dist/api/media/audio/InnerAudioContext.d.ts +58 -0
- package/dist/api/media/audio/InnerAudioContext.js +1 -1
- package/dist/api/media/audio/index.d.ts +29 -0
- package/dist/api/media/background-audio/BackgroundAudioManager.d.ts +71 -0
- package/dist/api/media/background-audio/index.d.ts +29 -0
- package/dist/api/media/camera.d.ts +3 -0
- package/dist/api/media/image/chooseImage.d.ts +5 -0
- package/dist/api/media/image/getImageInfo.d.ts +5 -0
- package/dist/api/media/image/index.d.ts +15 -0
- package/dist/api/media/image/previewImage.d.ts +8 -0
- package/dist/api/media/index.d.ts +12 -0
- package/dist/api/media/live.d.ts +6 -0
- package/dist/api/media/map.d.ts +3 -0
- package/dist/api/media/media-recorder.d.ts +3 -0
- package/dist/api/media/recorder.d.ts +9 -0
- package/dist/api/media/video/index.d.ts +24 -0
- package/dist/api/media/video-decoder.d.ts +3 -0
- package/dist/api/media/video-processing.d.ts +3 -0
- package/dist/api/media/voip.d.ts +42 -0
- package/dist/api/navigate/index.d.ts +12 -0
- package/dist/api/network/download.d.ts +6 -0
- package/dist/api/network/download.js +1 -0
- package/dist/api/network/index.d.ts +7 -0
- package/dist/api/network/mdns.d.ts +30 -0
- package/dist/api/network/request/index.d.ts +4 -0
- package/dist/api/network/tcp.d.ts +3 -0
- package/dist/api/network/udp.d.ts +3 -0
- package/dist/api/network/upload.d.ts +5 -0
- package/dist/api/network/upload.js +2 -1
- package/{src/api/network/utils.ts → dist/api/network/utils.d.ts} +44 -71
- package/dist/api/network/utils.js +1 -0
- package/dist/api/network/websocket/index.d.ts +7 -0
- package/dist/api/network/websocket/socketTask.d.ts +25 -0
- package/dist/api/open-api/account.d.ts +3 -0
- package/dist/api/open-api/address.d.ts +3 -0
- package/dist/api/open-api/authorize.d.ts +6 -0
- package/dist/api/open-api/card.d.ts +6 -0
- package/dist/api/open-api/channels-live.d.ts +18 -0
- package/dist/api/open-api/customer-service.d.ts +3 -0
- package/dist/api/open-api/facial.d.ts +12 -0
- package/dist/api/open-api/favorites.d.ts +6 -0
- package/dist/api/open-api/group.d.ts +3 -0
- package/dist/api/open-api/index.d.ts +18 -0
- package/dist/api/open-api/invoice.d.ts +6 -0
- package/dist/api/open-api/license-plate.d.ts +3 -0
- package/dist/api/open-api/login.d.ts +9 -0
- package/dist/api/open-api/red-package.d.ts +3 -0
- package/dist/api/open-api/settings.d.ts +6 -0
- package/dist/api/open-api/soter.d.ts +9 -0
- package/dist/api/open-api/subscribe-message.d.ts +3 -0
- package/dist/api/open-api/user-info.d.ts +6 -0
- package/dist/api/open-api/werun.d.ts +6 -0
- package/dist/api/payment/index.d.ts +6 -0
- package/dist/api/route/index.d.ts +1 -0
- package/dist/api/share/index.d.ts +30 -0
- package/dist/api/storage/background-fetch.d.ts +12 -0
- package/dist/api/storage/index.d.ts +18 -0
- package/dist/api/swan/index.d.ts +63 -0
- package/dist/api/taro.d.ts +12 -0
- package/dist/api/ui/animation/index.d.ts +2 -0
- package/dist/api/ui/background.d.ts +6 -0
- package/dist/api/ui/custom-component.d.ts +1 -0
- package/dist/api/ui/fonts.d.ts +2 -0
- package/dist/api/ui/index.d.ts +12 -0
- package/dist/api/ui/interaction/actionSheet.d.ts +61 -0
- package/dist/api/ui/interaction/index.d.ts +14 -0
- package/dist/api/ui/interaction/modal.d.ts +69 -0
- package/dist/api/ui/interaction/modal.js +1 -0
- package/dist/api/ui/interaction/toast.d.ts +85 -0
- package/dist/api/ui/menu.d.ts +3 -0
- package/dist/api/ui/navigation-bar/index.d.ts +15 -0
- package/dist/api/ui/navigation-bar/index.js +2 -3
- package/dist/api/ui/pull-down-refresh.d.ts +9 -0
- package/dist/api/ui/scroll/index.d.ts +5 -0
- package/dist/api/ui/sticky.d.ts +3 -0
- package/dist/api/ui/tab-bar.d.ts +34 -0
- package/dist/api/ui/window.d.ts +15 -0
- package/dist/api/worker/index.d.ts +3 -0
- package/dist/api/wxml/index.d.ts +5 -0
- package/dist/api/wxml/nodesRef.d.ts +13 -0
- package/dist/api/wxml/selectorQuery.d.ts +24 -0
- package/dist/api/wxml/selectorQuery.js +1 -1
- package/dist/index.cjs.d.ts +1373 -0
- package/dist/index.cjs.js +105 -81
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.d.ts +1373 -0
- package/dist/index.esm.js +93 -69
- package/dist/index.esm.js.map +1 -1
- package/dist/taroApis.d.ts +1364 -0
- package/dist/taroApis.js +1 -1
- package/dist/utils/animation.d.ts +6 -0
- package/dist/utils/handler.d.ts +48 -0
- package/dist/utils/index.d.ts +39 -0
- package/dist/utils/index.js +3 -7
- package/dist/utils/lodash.d.ts +2 -0
- package/dist/utils/valid.d.ts +2 -0
- package/package.json +17 -19
- package/types/api.d.ts +4 -0
- package/types/define.d.ts +2 -0
- package/types/index.d.ts +33 -0
- package/types/overlay.d.ts +9 -0
- package/LICENSE +0 -21
- package/src/api/ad/index.ts +0 -5
- package/src/api/ai/facial.ts +0 -6
- package/src/api/ai/index.ts +0 -2
- package/src/api/ai/visual.ts +0 -7
- package/src/api/alipay/index.ts +0 -4
- package/src/api/base/crypto.ts +0 -4
- package/src/api/base/debug.ts +0 -5
- package/src/api/base/index.ts +0 -23
- package/src/api/base/performance.ts +0 -5
- package/src/api/base/system.ts +0 -207
- package/src/api/base/update.ts +0 -5
- package/src/api/base/weapp/app-event.ts +0 -19
- package/src/api/base/weapp/life-cycle.ts +0 -5
- package/src/api/canvas/CanvasContext.ts +0 -233
- package/src/api/canvas/canvasGetImageData.ts +0 -28
- package/src/api/canvas/canvasPutImageData.ts +0 -25
- package/src/api/canvas/canvasToTempFilePath.ts +0 -25
- package/src/api/canvas/createCanvasContext.ts +0 -19
- package/src/api/canvas/index.ts +0 -18
- package/src/api/cloud/index.ts +0 -32
- package/src/api/data-analysis/index.ts +0 -6
- package/src/api/device/accelerometer.ts +0 -79
- package/src/api/device/accessibility.ts +0 -4
- package/src/api/device/battery.ts +0 -23
- package/src/api/device/bluetooth-ble.ts +0 -19
- package/src/api/device/bluetooth-peripheral.ts +0 -6
- package/src/api/device/bluetooth.ts +0 -16
- package/src/api/device/calendar.ts +0 -5
- package/src/api/device/clipboard.ts +0 -68
- package/src/api/device/compass.ts +0 -83
- package/src/api/device/contact.ts +0 -5
- package/src/api/device/crypto.ts +0 -4
- package/src/api/device/gyroscope.ts +0 -7
- package/src/api/device/iBeacon.ts +0 -10
- package/src/api/device/index.ts +0 -23
- package/src/api/device/keyboard.ts +0 -7
- package/src/api/device/memory.ts +0 -5
- package/src/api/device/motion.ts +0 -77
- package/src/api/device/network.ts +0 -90
- package/src/api/device/nfc.ts +0 -10
- package/src/api/device/phone.ts +0 -31
- package/src/api/device/scan.ts +0 -11
- package/src/api/device/screen.ts +0 -9
- package/src/api/device/vibrate.ts +0 -37
- package/src/api/device/wifi.ts +0 -14
- package/src/api/ext/index.ts +0 -5
- package/src/api/files/index.ts +0 -11
- package/src/api/framework/index.ts +0 -10
- package/src/api/index.ts +0 -24
- package/src/api/location/chooseLocation.ts +0 -117
- package/src/api/location/getLocation.ts +0 -81
- package/src/api/location/index.ts +0 -22
- package/src/api/location/style.css +0 -79
- package/src/api/media/EditorContext.ts +0 -32
- package/src/api/media/audio/InnerAudioContext.ts +0 -99
- package/src/api/media/audio/index.ts +0 -21
- package/src/api/media/background-audio/BackgroundAudioManager.ts +0 -104
- package/src/api/media/background-audio/index.ts +0 -17
- package/src/api/media/camera.ts +0 -4
- package/src/api/media/image/chooseImage.ts +0 -95
- package/src/api/media/image/getImageInfo.ts +0 -50
- package/src/api/media/image/index.ts +0 -13
- package/src/api/media/image/previewImage.ts +0 -80
- package/src/api/media/index.ts +0 -12
- package/src/api/media/live.ts +0 -5
- package/src/api/media/map.ts +0 -4
- package/src/api/media/media-recorder.ts +0 -4
- package/src/api/media/recorder.ts +0 -6
- package/src/api/media/video/index.ts +0 -82
- package/src/api/media/video-decoder.ts +0 -4
- package/src/api/media/video-processing.ts +0 -4
- package/src/api/media/voip.ts +0 -17
- package/src/api/navigate/index.ts +0 -7
- package/src/api/network/download.ts +0 -141
- package/src/api/network/index.ts +0 -7
- package/src/api/network/mdns.ts +0 -13
- package/src/api/network/request/index.ts +0 -135
- package/src/api/network/tcp.ts +0 -4
- package/src/api/network/udp.ts +0 -4
- package/src/api/network/upload.ts +0 -169
- package/src/api/network/websocket/index.ts +0 -88
- package/src/api/network/websocket/socketTask.ts +0 -89
- package/src/api/open-api/account.ts +0 -4
- package/src/api/open-api/address.ts +0 -4
- package/src/api/open-api/authorize.ts +0 -5
- package/src/api/open-api/card.ts +0 -5
- package/src/api/open-api/channels-live.ts +0 -9
- package/src/api/open-api/customer-service.ts +0 -4
- package/src/api/open-api/facial.ts +0 -7
- package/src/api/open-api/favorites.ts +0 -5
- package/src/api/open-api/group.ts +0 -4
- package/src/api/open-api/index.ts +0 -18
- package/src/api/open-api/invoice.ts +0 -5
- package/src/api/open-api/license-plate.ts +0 -4
- package/src/api/open-api/login.ts +0 -6
- package/src/api/open-api/red-package.ts +0 -4
- package/src/api/open-api/settings.ts +0 -5
- package/src/api/open-api/soter.ts +0 -6
- package/src/api/open-api/subscribe-message.ts +0 -4
- package/src/api/open-api/user-info.ts +0 -5
- package/src/api/open-api/werun.ts +0 -5
- package/src/api/payment/index.ts +0 -5
- package/src/api/route/index.ts +0 -10
- package/src/api/share/index.ts +0 -13
- package/src/api/storage/background-fetch.ts +0 -7
- package/src/api/storage/index.ts +0 -182
- package/src/api/swan/index.ts +0 -31
- package/src/api/taro.ts +0 -84
- package/src/api/ui/animation/index.ts +0 -356
- package/src/api/ui/background.ts +0 -5
- package/src/api/ui/custom-component.ts +0 -4
- package/src/api/ui/fonts.ts +0 -64
- package/src/api/ui/index.ts +0 -12
- package/src/api/ui/interaction/actionSheet.ts +0 -212
- package/src/api/ui/interaction/index.ts +0 -302
- package/src/api/ui/interaction/modal.ts +0 -237
- package/src/api/ui/interaction/toast.ts +0 -220
- package/src/api/ui/menu.ts +0 -4
- package/src/api/ui/navigation-bar/index.ts +0 -52
- package/src/api/ui/pull-down-refresh.ts +0 -28
- package/src/api/ui/scroll/index.ts +0 -85
- package/src/api/ui/sticky.ts +0 -4
- package/src/api/ui/tab-bar.ts +0 -327
- package/src/api/ui/window.ts +0 -38
- package/src/api/worker/index.ts +0 -4
- package/src/api/wxml/index.ts +0 -10
- package/src/api/wxml/nodesRef.ts +0 -56
- package/src/api/wxml/selectorQuery.ts +0 -220
- package/src/index.ts +0 -6
- package/src/utils/animation.ts +0 -15
- package/src/utils/handler.ts +0 -105
- package/src/utils/index.ts +0 -184
- package/src/utils/lodash.ts +0 -30
- package/src/utils/valid.ts +0 -8
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { CanvasGradient } from '@tarojs/api'
|
|
2
|
-
|
|
3
|
-
interface IAction {
|
|
4
|
-
func: (...arr: any[]) => void
|
|
5
|
-
args: any[]
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const TextBaseLineMap: Record<keyof Taro.CanvasContext.TextBaseline, CanvasTextBaseline> = {
|
|
9
|
-
top: 'top',
|
|
10
|
-
bottom: 'bottom',
|
|
11
|
-
middle: 'middle',
|
|
12
|
-
normal: 'alphabetic'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class CanvasContext implements Taro.CanvasContext {
|
|
16
|
-
__raw__: CanvasRenderingContext2D
|
|
17
|
-
actions: IAction[] = []
|
|
18
|
-
|
|
19
|
-
constructor (canvas, ctx) {
|
|
20
|
-
this.canvas = canvas
|
|
21
|
-
this.ctx = ctx
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
set ctx (e: CanvasRenderingContext2D) {
|
|
25
|
-
this.__raw__ = e
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get ctx () {
|
|
29
|
-
return this.__raw__ || {}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
canvas: HTMLCanvasElement
|
|
33
|
-
|
|
34
|
-
protected emptyActions () {
|
|
35
|
-
this.actions.length = 0
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected enqueueActions (func: IAction['func'], ...args) {
|
|
39
|
-
this.actions.push({
|
|
40
|
-
func,
|
|
41
|
-
args
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
set fillStyle (e) { this.enqueueActions(() => { this.ctx.fillStyle = e }) }
|
|
46
|
-
get fillStyle () { return this.ctx.fillStyle as string }
|
|
47
|
-
set font (e) { this.ctx.font = e }
|
|
48
|
-
get font () { return this.ctx.font }
|
|
49
|
-
set globalAlpha (e) { this.enqueueActions(() => { this.ctx.globalAlpha = e }) }
|
|
50
|
-
get globalAlpha () { return this.ctx.globalAlpha }
|
|
51
|
-
set globalCompositeOperation (e) { this.enqueueActions(() => { this.ctx.globalCompositeOperation = e }) }
|
|
52
|
-
get globalCompositeOperation () { return this.ctx.globalCompositeOperation }
|
|
53
|
-
set lineCap (e) { this.enqueueActions(() => { this.ctx.lineCap = e }) }
|
|
54
|
-
get lineCap () { return this.ctx.lineCap }
|
|
55
|
-
set lineDashOffset (e) { this.enqueueActions(() => { this.ctx.lineDashOffset = e }) }
|
|
56
|
-
get lineDashOffset () { return this.ctx.lineDashOffset }
|
|
57
|
-
set lineJoin (e) { this.enqueueActions(() => { this.ctx.lineJoin = e }) }
|
|
58
|
-
get lineJoin () { return this.ctx.lineJoin }
|
|
59
|
-
set lineWidth (e) { this.enqueueActions(() => { this.ctx.lineWidth = e }) }
|
|
60
|
-
get lineWidth () { return this.ctx.lineWidth }
|
|
61
|
-
set miterLimit (e) { this.enqueueActions(() => { this.ctx.miterLimit = e }) }
|
|
62
|
-
get miterLimit () { return this.ctx.miterLimit }
|
|
63
|
-
set shadowBlur (e) { this.enqueueActions(() => { this.ctx.shadowBlur = e }) }
|
|
64
|
-
get shadowBlur () { return this.ctx.shadowBlur }
|
|
65
|
-
set shadowColor (e) { this.enqueueActions(() => { this.ctx.shadowColor = e }) }
|
|
66
|
-
get shadowColor () { return this.ctx.shadowColor }
|
|
67
|
-
set shadowOffsetX (e) { this.enqueueActions(() => { this.ctx.shadowOffsetX = e }) }
|
|
68
|
-
get shadowOffsetX () { return this.ctx.shadowOffsetX }
|
|
69
|
-
set shadowOffsetY (e) { this.enqueueActions(() => { this.ctx.shadowOffsetY = e }) }
|
|
70
|
-
get shadowOffsetY () { return this.ctx.shadowOffsetY }
|
|
71
|
-
set strokeStyle (e) { this.enqueueActions(() => { this.ctx.strokeStyle = e }) }
|
|
72
|
-
get strokeStyle () { return this.ctx.strokeStyle as string }
|
|
73
|
-
/** 小程序文档中不包括 ↓↓↓ */
|
|
74
|
-
set textAlign (e) { this.ctx.textAlign = e }
|
|
75
|
-
get textAlign () { return this.ctx.textAlign }
|
|
76
|
-
set textBaseline (e) { this.ctx.textBaseline = e }
|
|
77
|
-
get textBaseline () { return this.ctx.textBaseline }
|
|
78
|
-
set direction (e) { this.ctx.direction = e }
|
|
79
|
-
get direction () { return this.ctx.direction }
|
|
80
|
-
set imageSmoothingEnabled (e) { this.enqueueActions(() => { this.ctx.imageSmoothingEnabled = e }) }
|
|
81
|
-
get imageSmoothingEnabled () { return this.ctx.imageSmoothingEnabled }
|
|
82
|
-
set imageSmoothingQuality (e) { this.enqueueActions(() => { this.ctx.imageSmoothingQuality = e }) }
|
|
83
|
-
get imageSmoothingQuality () { return this.ctx.imageSmoothingQuality }
|
|
84
|
-
set filter (e) { this.enqueueActions(() => { this.ctx.filter = e }) }
|
|
85
|
-
get filter () { return this.ctx.filter }
|
|
86
|
-
/** 小程序文档中不包括 ↑↑↑ */
|
|
87
|
-
|
|
88
|
-
arc (...args) { return this.enqueueActions(this.ctx.arc, ...args) }
|
|
89
|
-
arcTo (...args) { return this.enqueueActions(this.ctx.arcTo, ...args) }
|
|
90
|
-
beginPath (...args) { return this.enqueueActions(this.ctx.beginPath, ...args) }
|
|
91
|
-
bezierCurveTo (...args) { return this.enqueueActions(this.ctx.bezierCurveTo, ...args) }
|
|
92
|
-
clearRect (...args) { return this.enqueueActions(this.ctx.clearRect, ...args) }
|
|
93
|
-
clip (...args) { return this.enqueueActions(this.ctx.clip, ...args) }
|
|
94
|
-
closePath (...args) { return this.enqueueActions(this.ctx.closePath, ...args) }
|
|
95
|
-
|
|
96
|
-
createPattern (image: string, repetition: keyof Taro.CanvasContext.Repetition): void {
|
|
97
|
-
return this.createPattern(image, repetition)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 将之前在绘图上下文中的描述(路径、变形、样式)画到 canvas 中。
|
|
102
|
-
* @todo 每次 draw 都会读取 width 和 height
|
|
103
|
-
*/
|
|
104
|
-
async draw (reserve?: boolean, callback?: (...args: any[]) => any): Promise<void> {
|
|
105
|
-
try {
|
|
106
|
-
if (!reserve) {
|
|
107
|
-
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// 部分 action 是异步的
|
|
111
|
-
for (const { func, args } of this.actions) {
|
|
112
|
-
await func.apply(this.ctx, args)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
this.emptyActions()
|
|
116
|
-
callback && callback()
|
|
117
|
-
} catch (e) {
|
|
118
|
-
/* eslint-disable no-throw-literal */
|
|
119
|
-
throw {
|
|
120
|
-
errMsg: e.message
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
drawImage (imageResource: string, ...extra: any[]): void {
|
|
126
|
-
type TExtra = [number, number]
|
|
127
|
-
this.enqueueActions(() => {
|
|
128
|
-
// 需要转换为 Image
|
|
129
|
-
if (typeof imageResource === 'string') {
|
|
130
|
-
const img = new Image()
|
|
131
|
-
img.src = imageResource
|
|
132
|
-
return new Promise<void>((resolve, reject) => {
|
|
133
|
-
img.onload = () => {
|
|
134
|
-
this.ctx.drawImage(img, ...extra as TExtra)
|
|
135
|
-
resolve()
|
|
136
|
-
}
|
|
137
|
-
img.onerror = reject
|
|
138
|
-
})
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
this.ctx.drawImage(imageResource, ...extra as TExtra)
|
|
142
|
-
})
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
fill (...args) { return this.enqueueActions(this.ctx.fill, ...args) }
|
|
146
|
-
fillRect (...args) { return this.enqueueActions(this.ctx.fillRect, ...args) }
|
|
147
|
-
fillText (...args) { return this.enqueueActions(this.ctx.fillText, ...args) }
|
|
148
|
-
lineTo (...args) { return this.enqueueActions(this.ctx.lineTo, ...args) }
|
|
149
|
-
moveTo (...args) { return this.enqueueActions(this.ctx.moveTo, ...args) }
|
|
150
|
-
quadraticCurveTo (...args) { return this.enqueueActions(this.ctx.quadraticCurveTo, ...args) }
|
|
151
|
-
rect (...args) { return this.enqueueActions(this.ctx.rect, ...args) }
|
|
152
|
-
restore (...args) { return this.enqueueActions(this.ctx.restore, ...args) }
|
|
153
|
-
rotate (...args) { return this.enqueueActions(this.ctx.rotate, ...args) }
|
|
154
|
-
save (...args) { return this.enqueueActions(this.ctx.save, ...args) }
|
|
155
|
-
scale (...args) { return this.enqueueActions(this.ctx.scale, ...args) }
|
|
156
|
-
|
|
157
|
-
setFillStyle (color: string | CanvasGradient): void {
|
|
158
|
-
this.enqueueActions(() => { this.ctx.fillStyle = color })
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
setFontSize (fontSize: number): void {
|
|
162
|
-
this.font = `${fontSize}px`
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
setGlobalAlpha (alpha: number): void {
|
|
166
|
-
this.globalAlpha = alpha
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
setLineCap (lineCap: keyof Taro.CanvasContext.LineCap): void {
|
|
170
|
-
this.lineCap = lineCap
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
setLineDash (pattern: number[], offset: number): void {
|
|
174
|
-
this.enqueueActions(() => {
|
|
175
|
-
this.ctx.setLineDash(pattern)
|
|
176
|
-
this.ctx.lineDashOffset = offset
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
setLineJoin (lineJoin: keyof Taro.CanvasContext.LineJoin): void {
|
|
181
|
-
this.lineJoin = lineJoin
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
setLineWidth (lineWidth: number): void {
|
|
185
|
-
this.lineWidth = lineWidth
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
setMiterLimit (miterLimit: number): void {
|
|
189
|
-
this.miterLimit = miterLimit
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
setShadow (offsetX: number, offsetY: number, blur: number, color: string): void {
|
|
193
|
-
this.enqueueActions(() => {
|
|
194
|
-
this.ctx.shadowOffsetX = offsetX
|
|
195
|
-
this.ctx.shadowOffsetY = offsetY
|
|
196
|
-
this.ctx.shadowColor = color
|
|
197
|
-
this.ctx.shadowBlur = blur
|
|
198
|
-
})
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
setStrokeStyle (color: string | CanvasGradient): void {
|
|
202
|
-
this.enqueueActions(() => { this.ctx.strokeStyle = color })
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
setTextAlign (align: keyof Taro.CanvasContext.Align): void {
|
|
206
|
-
this.textAlign = align
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
setTextBaseline (textBaseline: keyof Taro.CanvasContext.TextBaseline): void {
|
|
210
|
-
this.textBaseline = TextBaseLineMap[textBaseline] || 'alphabetic'
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
setTransform (...args) { return this.enqueueActions(this.ctx.setTransform, ...args) }
|
|
214
|
-
stroke (...args) { return this.enqueueActions(this.ctx.stroke, ...args) }
|
|
215
|
-
strokeRect (...args) { return this.enqueueActions(this.ctx.strokeRect, ...args) }
|
|
216
|
-
strokeText (...args) { return this.enqueueActions(this.ctx.strokeText, ...args) }
|
|
217
|
-
transform (...args) { return this.enqueueActions(this.ctx.transform, ...args) }
|
|
218
|
-
translate (...args) { return this.enqueueActions(this.ctx.translate, ...args) }
|
|
219
|
-
|
|
220
|
-
measureText (text: string): TextMetrics {
|
|
221
|
-
return this.ctx.measureText(text)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
createCircularGradient (x: number, y: number, r: number): CanvasGradient {
|
|
225
|
-
const radialGradient = this.ctx.createRadialGradient(x, y, 0, x, y, r)
|
|
226
|
-
|
|
227
|
-
return radialGradient
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
createLinearGradient (x0: number, y0: number, x1: number, y1: number): CanvasGradient {
|
|
231
|
-
return this.createLinearGradient(x0, y0, x1, y1)
|
|
232
|
-
}
|
|
233
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
|
|
3
|
-
import { findDOM } from '../../utils'
|
|
4
|
-
import { MethodHandler } from '../../utils/handler'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 获取 canvas 区域隐含的像素数据。
|
|
8
|
-
*/
|
|
9
|
-
export const canvasGetImageData: typeof Taro.canvasGetImageData = ({ canvasId, success, fail, complete, x, y, width, height }, inst) => {
|
|
10
|
-
const handle = new MethodHandler({ name: 'canvasGetImageData', success, fail, complete })
|
|
11
|
-
const el = findDOM(inst) as HTMLElement
|
|
12
|
-
const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
const ctx = canvas?.getContext('2d')
|
|
16
|
-
// TODO ImageData => Uint8ClampedArray
|
|
17
|
-
const data = ctx?.getImageData(x, y, width, height) as unknown as Uint8ClampedArray
|
|
18
|
-
return handle.success({
|
|
19
|
-
width,
|
|
20
|
-
height,
|
|
21
|
-
data
|
|
22
|
-
})
|
|
23
|
-
} catch (e) {
|
|
24
|
-
return handle.fail({
|
|
25
|
-
errMsg: e.message
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
|
|
3
|
-
import { findDOM } from '../../utils'
|
|
4
|
-
import { MethodHandler } from '../../utils/handler'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 将像素数据绘制到画布。在自定义组件下,第二个参数传入自定义组件实例 this,以操作组件内 <canvas> 组件
|
|
8
|
-
* @todo 暂未支持尺寸相关功能
|
|
9
|
-
*/
|
|
10
|
-
export const canvasPutImageData: typeof Taro.canvasPutImageData = ({ canvasId, data, x, y, success, fail, complete }, inst) => {
|
|
11
|
-
const handle = new MethodHandler({ name: 'canvasPutImageData', success, fail, complete })
|
|
12
|
-
const el = findDOM(inst) as HTMLElement
|
|
13
|
-
const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
const ctx = canvas.getContext('2d')
|
|
17
|
-
// TODO Uint8ClampedArray => ImageData
|
|
18
|
-
ctx?.putImageData(data as unknown as ImageData, x, y)
|
|
19
|
-
return handle.success()
|
|
20
|
-
} catch (e) {
|
|
21
|
-
return handle.fail({
|
|
22
|
-
errMsg: e.message
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
|
|
3
|
-
import { findDOM } from '../../utils'
|
|
4
|
-
import { MethodHandler } from '../../utils/handler'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 把当前画布指定区域的内容导出生成指定大小的图片。在 draw() 回调里调用该方法才能保证图片导出成功。
|
|
8
|
-
* @todo 暂未支持尺寸相关功能
|
|
9
|
-
*/
|
|
10
|
-
export const canvasToTempFilePath: typeof Taro.canvasToTempFilePath = ({ canvasId, fileType, quality, success, fail, complete }, inst) => {
|
|
11
|
-
const handle = new MethodHandler({ name: 'canvasToTempFilePath', success, fail, complete })
|
|
12
|
-
const el = findDOM(inst) as HTMLElement
|
|
13
|
-
const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
const dataURL = canvas?.toDataURL(`image/${fileType || 'png'}`, quality)
|
|
17
|
-
return handle.success({
|
|
18
|
-
tempFilePath: dataURL
|
|
19
|
-
})
|
|
20
|
-
} catch (e) {
|
|
21
|
-
return handle.fail({
|
|
22
|
-
errMsg: e.message
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
|
|
3
|
-
import { findDOM } from '../../utils'
|
|
4
|
-
import { CanvasContext } from './CanvasContext'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 创建 canvas 的绘图上下文 CanvasContext 对象
|
|
8
|
-
*/
|
|
9
|
-
export const createCanvasContext: typeof Taro.createCanvasContext = (canvasId, inst) => {
|
|
10
|
-
const el = findDOM(inst) as HTMLElement
|
|
11
|
-
const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement
|
|
12
|
-
const ctx = canvas?.getContext('2d') as CanvasRenderingContext2D
|
|
13
|
-
const context = new CanvasContext(canvas, ctx)
|
|
14
|
-
if (!ctx) return context
|
|
15
|
-
context.canvas = canvas
|
|
16
|
-
context.ctx = ctx
|
|
17
|
-
|
|
18
|
-
return context
|
|
19
|
-
}
|
package/src/api/canvas/index.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '../../utils'
|
|
2
|
-
|
|
3
|
-
// 画布
|
|
4
|
-
|
|
5
|
-
/** 创建离屏 canvas 实例 */
|
|
6
|
-
export const createOffscreenCanvas = temporarilyNotSupport('createOffscreenCanvas')
|
|
7
|
-
|
|
8
|
-
/** 创建 canvas 的绘图上下文 CanvasContext 对象 */
|
|
9
|
-
export * from './createCanvasContext'
|
|
10
|
-
|
|
11
|
-
/** 把当前画布指定区域的内容导出生成指定大小的图片 */
|
|
12
|
-
export * from './canvasToTempFilePath'
|
|
13
|
-
|
|
14
|
-
/** 将像素数据绘制到画布 */
|
|
15
|
-
export * from './canvasPutImageData'
|
|
16
|
-
|
|
17
|
-
/** 获取 canvas 区域隐含的像素数据 */
|
|
18
|
-
export * from './canvasGetImageData'
|
package/src/api/cloud/index.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
|
|
3
|
-
import { temporarilyNotSupport } from '../../utils'
|
|
4
|
-
|
|
5
|
-
export class cloud implements Taro.cloud {
|
|
6
|
-
Cloud: new (options: Taro.cloud.IOptions) => Taro.Cloud
|
|
7
|
-
|
|
8
|
-
init = temporarilyNotSupport('cloud.init')
|
|
9
|
-
|
|
10
|
-
CloudID = temporarilyNotSupport('cloud.CloudID')
|
|
11
|
-
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
callFunction = temporarilyNotSupport('cloud.callFunction')
|
|
14
|
-
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
uploadFile = temporarilyNotSupport('cloud.uploadFile')
|
|
17
|
-
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
downloadFile = temporarilyNotSupport('cloud.downloadFile')
|
|
20
|
-
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
getTempFileURL = temporarilyNotSupport('cloud.getTempFileURL')
|
|
23
|
-
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
deleteFile = temporarilyNotSupport('cloud.deleteFile')
|
|
26
|
-
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
database = temporarilyNotSupport('cloud.database')
|
|
29
|
-
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
callContainer = temporarilyNotSupport('cloud.callContainer')
|
|
32
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '../../utils'
|
|
2
|
-
|
|
3
|
-
export const reportMonitor = temporarilyNotSupport('reportMonitor')
|
|
4
|
-
export const reportAnalytics = temporarilyNotSupport('reportAnalytics')
|
|
5
|
-
export const reportEvent = temporarilyNotSupport('reportEvent')
|
|
6
|
-
export const getExptInfoSync = temporarilyNotSupport('getExptInfoSync')
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
|
|
3
|
-
import { throttle } from '../../utils'
|
|
4
|
-
import { CallbackManager, MethodHandler } from '../../utils/handler'
|
|
5
|
-
|
|
6
|
-
const callbackManager = new CallbackManager()
|
|
7
|
-
let devicemotionListener
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 停止监听加速度数据。
|
|
11
|
-
*/
|
|
12
|
-
export const stopAccelerometer: typeof Taro.stopAccelerometer = ({ success, fail, complete } = {}) => {
|
|
13
|
-
const res: Partial<TaroGeneral.CallbackResult> = {}
|
|
14
|
-
const handle = new MethodHandler({ name: 'stopAccelerometer', success, fail, complete })
|
|
15
|
-
try {
|
|
16
|
-
window.removeEventListener('devicemotion', devicemotionListener, true)
|
|
17
|
-
return handle.success(res)
|
|
18
|
-
} catch (e) {
|
|
19
|
-
res.errMsg = e.message
|
|
20
|
-
return handle.fail(res)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const INTERVAL_MAP = {
|
|
25
|
-
game: {
|
|
26
|
-
interval: 20,
|
|
27
|
-
frequency: 50
|
|
28
|
-
},
|
|
29
|
-
ui: {
|
|
30
|
-
interval: 60,
|
|
31
|
-
frequency: 16.67
|
|
32
|
-
},
|
|
33
|
-
normal: {
|
|
34
|
-
interval: 200,
|
|
35
|
-
frequency: 5
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 开始监听加速度数据。
|
|
41
|
-
*/
|
|
42
|
-
export const startAccelerometer: typeof Taro.startAccelerometer = ({ interval = 'normal', success, fail, complete } = {}) => {
|
|
43
|
-
const handle = new MethodHandler({ name: 'startAccelerometer', success, fail, complete })
|
|
44
|
-
try {
|
|
45
|
-
if (window.DeviceMotionEvent) {
|
|
46
|
-
const intervalObj = INTERVAL_MAP[interval]
|
|
47
|
-
if (devicemotionListener) {
|
|
48
|
-
stopAccelerometer()
|
|
49
|
-
}
|
|
50
|
-
devicemotionListener = throttle((evt: DeviceMotionEvent) => {
|
|
51
|
-
callbackManager.trigger({
|
|
52
|
-
x: evt.acceleration?.x || 0,
|
|
53
|
-
y: evt.acceleration?.y || 0,
|
|
54
|
-
z: evt.acceleration?.z || 0
|
|
55
|
-
})
|
|
56
|
-
}, intervalObj.interval)
|
|
57
|
-
window.addEventListener('devicemotion', devicemotionListener, true)
|
|
58
|
-
} else {
|
|
59
|
-
throw new Error('accelerometer is not supported')
|
|
60
|
-
}
|
|
61
|
-
return handle.success()
|
|
62
|
-
} catch (e) {
|
|
63
|
-
return handle.fail({ errMsg: e.message })
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 监听加速度数据事件。频率根据 Taro.startAccelerometer() 的 interval 参数。可使用 Taro.stopAccelerometer() 停止监听。
|
|
69
|
-
*/
|
|
70
|
-
export const onAccelerometerChange: typeof Taro.onAccelerometerChange = callback => {
|
|
71
|
-
callbackManager.add(callback)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 取消监听加速度数据事件,参数为空,则取消所有的事件监听
|
|
76
|
-
*/
|
|
77
|
-
export const offAccelerometerChange: typeof Taro.offAccelerometerChange = callback => {
|
|
78
|
-
callbackManager.remove(callback)
|
|
79
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
|
|
3
|
-
import { temporarilyNotSupport } from '../../utils'
|
|
4
|
-
import { MethodHandler } from '../../utils/handler'
|
|
5
|
-
|
|
6
|
-
// 电量
|
|
7
|
-
export const getBatteryInfoSync = temporarilyNotSupport('getBatteryInfoSync')
|
|
8
|
-
|
|
9
|
-
export const getBatteryInfo: typeof Taro.getBatteryInfo = async ({ success, fail, complete } = {}) => {
|
|
10
|
-
const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete })
|
|
11
|
-
try {
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
const battery = await navigator.getBattery?.()
|
|
14
|
-
return handle.success({
|
|
15
|
-
isCharging: battery.charging,
|
|
16
|
-
level: Number(battery.level || 0) * 100
|
|
17
|
-
})
|
|
18
|
-
} catch (error) {
|
|
19
|
-
return handle.fail({
|
|
20
|
-
errMsg: error?.message || error
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '../../utils'
|
|
2
|
-
|
|
3
|
-
// 蓝牙-低功耗中心设备
|
|
4
|
-
export const writeBLECharacteristicValue = temporarilyNotSupport('writeBLECharacteristicValue')
|
|
5
|
-
export const setBLEMTU = temporarilyNotSupport('setBLEMTU')
|
|
6
|
-
export const readBLECharacteristicValue = temporarilyNotSupport('readBLECharacteristicValue')
|
|
7
|
-
export const onBLEMTUChange = temporarilyNotSupport('onBLEMTUChange')
|
|
8
|
-
export const onBLEConnectionStateChange = temporarilyNotSupport('onBLEConnectionStateChange')
|
|
9
|
-
export const onBLECharacteristicValueChange = temporarilyNotSupport('onBLECharacteristicValueChange')
|
|
10
|
-
export const offBLEMTUChange = temporarilyNotSupport('offBLEMTUChange')
|
|
11
|
-
export const offBLEConnectionStateChange = temporarilyNotSupport('offBLEConnectionStateChange')
|
|
12
|
-
export const offBLECharacteristicValueChange = temporarilyNotSupport('offBLECharacteristicValueChange')
|
|
13
|
-
export const notifyBLECharacteristicValueChange = temporarilyNotSupport('notifyBLECharacteristicValueChange')
|
|
14
|
-
export const getBLEMTU = temporarilyNotSupport('getBLEMTU')
|
|
15
|
-
export const getBLEDeviceServices = temporarilyNotSupport('getBLEDeviceServices')
|
|
16
|
-
export const getBLEDeviceRSSI = temporarilyNotSupport('getBLEDeviceRSSI')
|
|
17
|
-
export const getBLEDeviceCharacteristics = temporarilyNotSupport('getBLEDeviceCharacteristics')
|
|
18
|
-
export const createBLEConnection = temporarilyNotSupport('createBLEConnection')
|
|
19
|
-
export const closeBLEConnection = temporarilyNotSupport('closeBLEConnection')
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '../../utils'
|
|
2
|
-
|
|
3
|
-
// 蓝牙-低功耗外围设备
|
|
4
|
-
export const onBLEPeripheralConnectionStateChanged = temporarilyNotSupport('onBLEPeripheralConnectionStateChanged')
|
|
5
|
-
export const offBLEPeripheralConnectionStateChanged = temporarilyNotSupport('offBLEPeripheralConnectionStateChanged')
|
|
6
|
-
export const createBLEPeripheralServer = temporarilyNotSupport('createBLEPeripheralServer')
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '../../utils'
|
|
2
|
-
|
|
3
|
-
// 蓝牙-通用
|
|
4
|
-
export const stopBluetoothDevicesDiscovery = temporarilyNotSupport('stopBluetoothDevicesDiscovery')
|
|
5
|
-
export const startBluetoothDevicesDiscovery = temporarilyNotSupport('startBluetoothDevicesDiscovery')
|
|
6
|
-
export const openBluetoothAdapter = temporarilyNotSupport('openBluetoothAdapter')
|
|
7
|
-
export const onBluetoothDeviceFound = temporarilyNotSupport('onBluetoothDeviceFound')
|
|
8
|
-
export const onBluetoothAdapterStateChange = temporarilyNotSupport('onBluetoothAdapterStateChange')
|
|
9
|
-
export const offBluetoothDeviceFound = temporarilyNotSupport('offBluetoothDeviceFound')
|
|
10
|
-
export const offBluetoothAdapterStateChange = temporarilyNotSupport('offBluetoothAdapterStateChange')
|
|
11
|
-
export const makeBluetoothPair = temporarilyNotSupport('makeBluetoothPair')
|
|
12
|
-
export const isBluetoothDevicePaired = temporarilyNotSupport('isBluetoothDevicePaired')
|
|
13
|
-
export const getConnectedBluetoothDevices = temporarilyNotSupport('getConnectedBluetoothDevices')
|
|
14
|
-
export const getBluetoothDevices = temporarilyNotSupport('getBluetoothDevices')
|
|
15
|
-
export const getBluetoothAdapterState = temporarilyNotSupport('getBluetoothAdapterState')
|
|
16
|
-
export const closeBluetoothAdapter = temporarilyNotSupport('closeBluetoothAdapter')
|
|
@@ -1,68 +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 Taro from '@tarojs/api'
|
|
9
|
-
|
|
10
|
-
import { MethodHandler } from '../../utils/handler'
|
|
11
|
-
import { getStorageSync, setStorage, setStorageSync } from '../storage/index'
|
|
12
|
-
|
|
13
|
-
const CLIPBOARD_STORAGE_NAME = 'taro_clipboard'
|
|
14
|
-
|
|
15
|
-
document.addEventListener('copy', () => {
|
|
16
|
-
setStorage({
|
|
17
|
-
key: CLIPBOARD_STORAGE_NAME,
|
|
18
|
-
data: window.getSelection()?.toString()
|
|
19
|
-
}).catch(e => {
|
|
20
|
-
console.error(e)
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 设置系统剪贴板的内容
|
|
26
|
-
*/
|
|
27
|
-
export const setClipboardData: typeof Taro.setClipboardData = async ({ data, success, fail, complete }) => {
|
|
28
|
-
const handle = new MethodHandler({ name: 'setClipboardData', success, fail, complete })
|
|
29
|
-
try {
|
|
30
|
-
setStorageSync(CLIPBOARD_STORAGE_NAME, data)
|
|
31
|
-
/**
|
|
32
|
-
* 已于 iPhone 6s Plus iOS 13.1.3 上的 Safari 测试通过
|
|
33
|
-
* iOS < 10 的系统可能无法使用编程方式访问剪贴板,参考:
|
|
34
|
-
* https://stackoverflow.com/questions/34045777/copy-to-clipboard-using-javascript-in-ios/34046084
|
|
35
|
-
*/
|
|
36
|
-
if (typeof document.execCommand === 'function') {
|
|
37
|
-
const textarea = document.createElement('textarea')
|
|
38
|
-
textarea.readOnly = true
|
|
39
|
-
textarea.value = data
|
|
40
|
-
textarea.style.position = 'absolute'
|
|
41
|
-
textarea.style.width = '100px'
|
|
42
|
-
textarea.style.left = '-10000px'
|
|
43
|
-
document.body.appendChild(textarea)
|
|
44
|
-
textarea.select()
|
|
45
|
-
textarea.setSelectionRange(0, textarea.value.length)
|
|
46
|
-
document.execCommand('copy')
|
|
47
|
-
document.body.removeChild(textarea)
|
|
48
|
-
} else {
|
|
49
|
-
throw new Error('Unsupported Function: \'document.execCommand\'.')
|
|
50
|
-
}
|
|
51
|
-
return handle.success()
|
|
52
|
-
} catch (e) {
|
|
53
|
-
return handle.fail({ errMsg: e.message })
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 获取系统剪贴板的内容
|
|
59
|
-
*/
|
|
60
|
-
export const getClipboardData: typeof Taro.getClipboardData = async ({ success, fail, complete } = {}) => {
|
|
61
|
-
const handle = new MethodHandler<Taro.getClipboardData.SuccessCallbackOption>({ name: 'getClipboardData', success, fail, complete })
|
|
62
|
-
try {
|
|
63
|
-
const data: string = getStorageSync(CLIPBOARD_STORAGE_NAME)
|
|
64
|
-
return handle.success({ data })
|
|
65
|
-
} catch (e) {
|
|
66
|
-
return handle.fail({ errMsg: e.message })
|
|
67
|
-
}
|
|
68
|
-
}
|