@tarojs/taro-h5 3.5.0-canary.1 → 3.5.0
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/ad/index.js +1 -1
- package/dist/api/ai/facial.d.ts +9 -0
- package/dist/api/ai/facial.js +1 -1
- package/dist/api/ai/index.d.ts +2 -0
- package/dist/api/ai/visual.d.ts +6 -0
- package/dist/api/ai/visual.js +3 -1
- package/dist/api/alipay/index.d.ts +3 -0
- package/dist/api/alipay/index.js +1 -1
- package/dist/api/base/crypto.d.ts +3 -0
- package/dist/api/base/crypto.js +1 -1
- package/dist/api/base/debug.d.ts +9 -0
- package/dist/api/base/debug.js +1 -1
- package/dist/api/base/index.d.ts +12 -0
- package/dist/api/base/index.js +5 -5
- package/dist/api/base/performance.d.ts +6 -0
- package/dist/api/base/performance.js +1 -1
- package/dist/api/base/system.d.ts +27 -0
- package/dist/api/base/system.js +191 -0
- package/dist/api/base/update.d.ts +6 -0
- package/dist/api/base/update.js +1 -1
- package/dist/api/base/weapp/app-event.d.ts +41 -0
- package/dist/api/base/weapp/app-event.js +56 -5
- package/dist/api/base/weapp/life-cycle.d.ts +6 -0
- package/dist/api/base/weapp/life-cycle.js +1 -1
- package/dist/api/canvas/CanvasContext.d.ts +104 -0
- package/dist/api/canvas/CanvasContext.js +27 -16
- package/dist/api/canvas/canvasGetImageData.d.ts +5 -0
- package/dist/api/canvas/canvasGetImageData.js +2 -2
- package/dist/api/canvas/canvasPutImageData.d.ts +6 -0
- package/dist/api/canvas/canvasPutImageData.js +2 -2
- package/dist/api/canvas/canvasToTempFilePath.d.ts +6 -0
- package/dist/api/canvas/canvasToTempFilePath.js +2 -2
- package/dist/api/canvas/createCanvasContext.d.ts +5 -0
- package/dist/api/canvas/createCanvasContext.js +1 -1
- package/dist/api/canvas/index.d.ts +12 -0
- package/dist/api/canvas/index.js +6 -2
- package/dist/api/cloud/index.d.ts +31 -0
- package/dist/api/cloud/index.js +1 -1
- package/dist/api/data-analysis/index.d.ts +12 -0
- package/dist/api/data-analysis/index.js +1 -1
- package/dist/api/device/accelerometer.d.ts +17 -0
- package/dist/api/device/accelerometer.js +10 -18
- package/dist/api/device/accessibility.d.ts +3 -0
- package/dist/api/device/accessibility.js +1 -1
- package/dist/api/device/battery.d.ts +5 -0
- package/dist/api/device/battery.js +28 -2
- package/dist/api/device/bluetooth-ble.d.ts +48 -0
- package/dist/api/device/bluetooth-ble.js +1 -1
- package/dist/api/device/bluetooth-peripheral.d.ts +9 -0
- package/dist/api/device/bluetooth-peripheral.js +1 -1
- package/dist/api/device/bluetooth.d.ts +39 -0
- package/dist/api/device/bluetooth.js +1 -1
- package/dist/api/device/calendar.d.ts +6 -0
- package/dist/api/device/calendar.js +1 -1
- package/dist/api/device/clipboard.d.ts +15 -0
- package/dist/api/device/clipboard.js +15 -6
- package/dist/api/device/compass.d.ts +17 -0
- package/dist/api/device/compass.js +33 -19
- package/dist/api/device/contact.d.ts +6 -0
- package/dist/api/device/contact.js +1 -1
- package/dist/api/device/crypto.d.ts +3 -0
- package/dist/api/device/crypto.js +1 -1
- package/dist/api/device/gyroscope.d.ts +12 -0
- package/dist/api/device/gyroscope.js +1 -1
- package/dist/api/device/iBeacon.d.ts +21 -0
- package/dist/api/device/iBeacon.js +1 -1
- package/dist/api/device/index.d.ts +23 -0
- package/dist/api/device/index.js +1 -0
- package/dist/api/device/keyboard.d.ts +12 -0
- package/dist/api/device/keyboard.js +1 -1
- package/dist/api/device/memory.d.ts +6 -0
- package/dist/api/device/memory.js +1 -1
- package/dist/api/device/motion.d.ts +17 -0
- package/dist/api/device/motion.js +9 -18
- package/dist/api/device/network.d.ts +20 -0
- package/dist/api/device/network.js +87 -0
- package/dist/api/device/nfc.d.ts +21 -0
- package/dist/api/device/nfc.js +1 -1
- package/dist/api/device/phone.d.ts +2 -0
- package/dist/api/device/phone.js +2 -2
- package/dist/api/device/scan.d.ts +3 -0
- package/dist/api/device/scan.js +9 -5
- package/dist/api/device/screen.d.ts +18 -0
- package/dist/api/device/screen.js +1 -1
- package/dist/api/device/vibrate.d.ts +9 -0
- package/dist/api/device/vibrate.js +6 -8
- package/dist/api/device/wifi.d.ts +33 -0
- package/dist/api/device/wifi.js +2 -1
- package/dist/api/ext/index.d.ts +6 -0
- package/dist/api/ext/index.js +1 -1
- package/dist/api/files/index.d.ts +24 -0
- package/dist/api/files/index.js +1 -1
- package/dist/api/framework/index.d.ts +4 -0
- package/dist/api/index.d.ts +24 -0
- package/dist/api/index.js +2 -2
- package/dist/api/location/chooseLocation.d.ts +6 -0
- package/dist/api/location/chooseLocation.js +22 -8
- package/dist/api/location/getLocation.d.ts +2 -0
- package/dist/api/location/getLocation.js +64 -0
- package/dist/api/location/index.d.ts +32 -0
- package/dist/api/location/index.js +8 -4
- package/dist/api/media/EditorContext.d.ts +42 -0
- package/dist/api/media/EditorContext.js +2 -1
- package/dist/api/media/audio/InnerAudioContext.d.ts +58 -0
- package/dist/api/media/audio/InnerAudioContext.js +3 -3
- package/dist/api/media/audio/index.d.ts +29 -0
- package/dist/api/media/audio/index.js +1 -1
- package/dist/api/media/background-audio/BackgroundAudioManager.d.ts +71 -0
- package/dist/api/media/background-audio/BackgroundAudioManager.js +2 -2
- package/dist/api/media/background-audio/index.d.ts +29 -0
- package/dist/api/media/background-audio/index.js +1 -1
- package/dist/api/media/camera.d.ts +3 -0
- package/dist/api/media/camera.js +1 -1
- package/dist/api/media/image/chooseImage.d.ts +5 -0
- package/dist/api/media/image/chooseImage.js +14 -3
- package/dist/api/media/image/getImageInfo.d.ts +5 -0
- package/dist/api/media/image/getImageInfo.js +18 -3
- package/dist/api/media/image/index.d.ts +15 -0
- package/dist/api/media/image/index.js +2 -2
- package/dist/api/media/image/previewImage.d.ts +8 -0
- package/dist/api/media/image/previewImage.js +14 -5
- package/dist/api/media/index.d.ts +12 -0
- package/dist/api/media/live.d.ts +6 -0
- package/dist/api/media/live.js +1 -1
- package/dist/api/media/map.d.ts +3 -0
- package/dist/api/media/map.js +1 -1
- package/dist/api/media/media-recorder.d.ts +3 -0
- package/dist/api/media/media-recorder.js +1 -1
- package/dist/api/media/recorder.d.ts +9 -0
- package/dist/api/media/recorder.js +1 -1
- package/dist/api/media/video/index.d.ts +24 -0
- package/dist/api/media/video/index.js +2 -2
- package/dist/api/media/video-decoder.d.ts +3 -0
- package/dist/api/media/video-decoder.js +1 -1
- package/dist/api/media/video-processing.d.ts +3 -0
- package/dist/api/media/video-processing.js +1 -1
- package/dist/api/media/voip.d.ts +42 -0
- package/dist/api/media/voip.js +1 -1
- package/dist/api/navigate/index.d.ts +12 -0
- package/dist/api/navigate/index.js +1 -1
- package/dist/api/network/download.d.ts +6 -0
- package/dist/api/network/download.js +2 -1
- package/dist/api/network/index.d.ts +7 -0
- package/dist/api/network/mdns.d.ts +30 -0
- package/dist/api/network/mdns.js +1 -1
- package/dist/api/network/request/index.d.ts +4 -0
- package/dist/api/network/request/index.js +6 -2
- package/dist/api/network/tcp.d.ts +3 -0
- package/dist/api/network/tcp.js +1 -1
- package/dist/api/network/udp.d.ts +3 -0
- package/dist/api/network/udp.js +1 -1
- package/dist/api/network/upload.d.ts +5 -0
- package/dist/api/network/upload.js +4 -8
- 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/index.js +2 -2
- 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/account.js +1 -1
- package/dist/api/open-api/address.d.ts +3 -0
- package/dist/api/open-api/address.js +1 -1
- package/dist/api/open-api/authorize.d.ts +6 -0
- package/dist/api/open-api/authorize.js +1 -1
- package/dist/api/open-api/card.d.ts +6 -0
- package/dist/api/open-api/card.js +1 -1
- package/dist/api/open-api/channels-live.d.ts +18 -0
- package/dist/api/open-api/channels-live.js +1 -1
- package/dist/api/open-api/customer-service.d.ts +3 -0
- package/dist/api/open-api/customer-service.js +1 -1
- package/dist/api/open-api/facial.d.ts +12 -0
- package/dist/api/open-api/facial.js +1 -1
- package/dist/api/open-api/favorites.d.ts +6 -0
- package/dist/api/open-api/favorites.js +1 -1
- package/dist/api/open-api/group.d.ts +3 -0
- package/dist/api/open-api/group.js +1 -1
- 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/invoice.js +1 -1
- package/dist/api/open-api/license-plate.d.ts +3 -0
- package/dist/api/open-api/license-plate.js +1 -1
- package/dist/api/open-api/login.d.ts +9 -0
- package/dist/api/open-api/login.js +1 -1
- package/dist/api/open-api/red-package.d.ts +3 -0
- package/dist/api/open-api/red-package.js +1 -1
- package/dist/api/open-api/settings.d.ts +6 -0
- package/dist/api/open-api/settings.js +1 -1
- package/dist/api/open-api/soter.d.ts +9 -0
- package/dist/api/open-api/soter.js +1 -1
- package/dist/api/open-api/subscribe-message.d.ts +3 -0
- package/dist/api/open-api/subscribe-message.js +1 -1
- package/dist/api/open-api/user-info.d.ts +6 -0
- package/dist/api/open-api/user-info.js +1 -1
- package/dist/api/open-api/werun.d.ts +6 -0
- package/dist/api/open-api/werun.js +1 -1
- package/dist/api/payment/index.d.ts +6 -0
- package/dist/api/payment/index.js +1 -1
- package/dist/api/route/index.d.ts +1 -0
- package/dist/api/route/index.js +1 -1
- package/dist/api/share/index.d.ts +30 -0
- package/dist/api/share/index.js +1 -1
- package/dist/api/storage/background-fetch.d.ts +12 -0
- package/dist/api/storage/background-fetch.js +1 -1
- package/dist/api/storage/index.d.ts +18 -0
- package/dist/api/storage/index.js +2 -2
- package/dist/api/swan/index.d.ts +63 -0
- package/dist/api/swan/index.js +1 -1
- package/dist/api/taro.d.ts +12 -0
- package/dist/api/taro.js +4 -5
- package/dist/api/ui/animation/index.d.ts +2 -0
- package/dist/api/ui/background.d.ts +6 -0
- package/dist/api/ui/background.js +1 -1
- package/dist/api/ui/custom-component.d.ts +1 -0
- package/dist/api/ui/fonts.d.ts +2 -0
- package/dist/api/ui/fonts.js +59 -2
- package/dist/api/ui/index.d.ts +12 -0
- package/dist/api/ui/index.js +1 -1
- package/dist/api/ui/interaction/actionSheet.d.ts +61 -0
- package/dist/api/ui/interaction/actionSheet.js +4 -13
- package/dist/api/ui/interaction/index.d.ts +14 -0
- package/dist/api/ui/interaction/index.js +22 -13
- package/dist/api/ui/interaction/modal.d.ts +69 -0
- package/dist/api/ui/interaction/modal.js +8 -28
- package/dist/api/ui/interaction/toast.d.ts +85 -0
- package/dist/api/ui/interaction/toast.js +15 -41
- package/dist/api/ui/menu.d.ts +3 -0
- package/dist/api/ui/menu.js +1 -1
- package/dist/api/ui/navigation-bar/index.d.ts +15 -0
- package/dist/api/ui/navigation-bar/index.js +4 -5
- package/dist/api/ui/pull-down-refresh.d.ts +9 -0
- package/dist/api/ui/pull-down-refresh.js +1 -1
- package/dist/api/ui/scroll/index.d.ts +5 -0
- package/dist/api/ui/scroll/index.js +2 -2
- package/dist/api/ui/sticky.d.ts +3 -0
- package/dist/api/ui/sticky.js +1 -1
- package/dist/api/ui/tab-bar.d.ts +34 -0
- package/dist/api/ui/tab-bar.js +2 -2
- package/dist/api/ui/window.d.ts +15 -0
- package/dist/api/ui/window.js +2 -2
- package/dist/api/worker/index.d.ts +3 -0
- package/dist/api/worker/index.js +1 -1
- package/dist/api/wxml/index.d.ts +5 -0
- package/dist/api/wxml/index.js +1 -1
- package/dist/api/wxml/nodesRef.d.ts +13 -0
- package/dist/api/wxml/selectorQuery.d.ts +24 -0
- package/dist/api/wxml/selectorQuery.js +2 -2
- package/dist/index.cjs.d.ts +1373 -0
- package/dist/index.cjs.js +5021 -8380
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.d.ts +1373 -0
- package/dist/index.esm.js +5194 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/taroApis.d.ts +1364 -0
- package/dist/taroApis.js +2 -1
- package/dist/taroApis.js.map +1 -0
- package/dist/utils/animation.d.ts +6 -0
- package/dist/utils/animation.js +14 -0
- package/dist/utils/handler.d.ts +48 -0
- package/dist/{api/utils → utils}/handler.js +0 -0
- package/dist/utils/index.d.ts +39 -0
- package/dist/{api/utils → utils}/index.js +36 -53
- package/dist/utils/lodash.d.ts +2 -0
- package/dist/utils/lodash.js +29 -0
- package/dist/utils/valid.d.ts +2 -0
- package/dist/utils/valid.js +7 -0
- package/package.json +21 -20
- package/{src/types → types}/api.d.ts +1 -1
- 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/dist/api/base/system/index.js +0 -2
- package/dist/api/base/system/info.js +0 -57
- package/dist/api/base/system/network.js +0 -63
- package/dist/types/type.js +0 -2
- 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 -4
- 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/index.ts +0 -2
- package/src/api/base/system/info.ts +0 -64
- package/src/api/base/system/network.ts +0 -70
- 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 -27
- package/src/api/canvas/canvasPutImageData.ts +0 -24
- package/src/api/canvas/canvasToTempFilePath.ts +0 -24
- package/src/api/canvas/createCanvasContext.ts +0 -18
- package/src/api/canvas/index.ts +0 -10
- package/src/api/cloud/index.ts +0 -31
- package/src/api/data-analysis/index.ts +0 -6
- package/src/api/device/accelerometer.ts +0 -87
- package/src/api/device/accessibility.ts +0 -4
- package/src/api/device/battery.ts +0 -5
- 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 -67
- package/src/api/device/compass.ts +0 -67
- 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 -22
- package/src/api/device/keyboard.ts +0 -7
- package/src/api/device/memory.ts +0 -5
- package/src/api/device/motion.ts +0 -85
- package/src/api/device/nfc.ts +0 -10
- package/src/api/device/phone.ts +0 -30
- package/src/api/device/scan.ts +0 -7
- package/src/api/device/screen.ts +0 -9
- package/src/api/device/vibrate.ts +0 -36
- package/src/api/device/wifi.ts +0 -13
- 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 -25
- package/src/api/location/chooseLocation.ts +0 -106
- package/src/api/location/index.ts +0 -19
- package/src/api/location/style.css +0 -79
- package/src/api/media/EditorContext.ts +0 -29
- package/src/api/media/audio/InnerAudioContext.ts +0 -98
- package/src/api/media/audio/index.ts +0 -20
- package/src/api/media/background-audio/BackgroundAudioManager.ts +0 -103
- 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 -78
- package/src/api/media/image/getImageInfo.ts +0 -35
- 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 -140
- package/src/api/network/index.ts +0 -7
- package/src/api/network/mdns.ts +0 -13
- package/src/api/network/request/index.ts +0 -130
- package/src/api/network/tcp.ts +0 -4
- package/src/api/network/udp.ts +0 -4
- package/src/api/network/upload.ts +0 -174
- 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 -181
- package/src/api/swan/index.ts +0 -31
- package/src/api/taro.ts +0 -89
- 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 -4
- 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 -301
- 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 -27
- 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 -326
- package/src/api/ui/window.ts +0 -37
- package/src/api/utils/handler.ts +0 -105
- package/src/api/utils/index.ts +0 -190
- package/src/api/worker/index.ts +0 -4
- package/src/api/wxml/index.ts +0 -9
- package/src/api/wxml/nodesRef.ts +0 -56
- package/src/api/wxml/selectorQuery.ts +0 -219
- package/src/index.ts +0 -6
- package/src/types/define.d.ts +0 -2
- package/src/types/index.d.ts +0 -3
- package/src/types/type.ts +0 -32
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
const TextBaseLineMap = {
|
|
2
11
|
top: 'top',
|
|
3
12
|
bottom: 'bottom',
|
|
@@ -81,24 +90,26 @@ export class CanvasContext {
|
|
|
81
90
|
* 将之前在绘图上下文中的描述(路径、变形、样式)画到 canvas 中。
|
|
82
91
|
* @todo 每次 draw 都会读取 width 和 height
|
|
83
92
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
draw(reserve, callback) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
try {
|
|
96
|
+
if (!reserve) {
|
|
97
|
+
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
98
|
+
}
|
|
99
|
+
// 部分 action 是异步的
|
|
100
|
+
for (const { func, args } of this.actions) {
|
|
101
|
+
yield func.apply(this.ctx, args);
|
|
102
|
+
}
|
|
103
|
+
this.emptyActions();
|
|
104
|
+
callback && callback();
|
|
88
105
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
106
|
+
catch (e) {
|
|
107
|
+
/* eslint-disable no-throw-literal */
|
|
108
|
+
throw {
|
|
109
|
+
errMsg: e.message
|
|
110
|
+
};
|
|
92
111
|
}
|
|
93
|
-
|
|
94
|
-
callback && callback();
|
|
95
|
-
}
|
|
96
|
-
catch (e) {
|
|
97
|
-
/* eslint-disable no-throw-literal */
|
|
98
|
-
throw {
|
|
99
|
-
errMsg: e.message
|
|
100
|
-
};
|
|
101
|
-
}
|
|
112
|
+
});
|
|
102
113
|
}
|
|
103
114
|
drawImage(imageResource, ...extra) {
|
|
104
115
|
this.enqueueActions(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { findDOM } from '../../utils';
|
|
2
|
+
import { MethodHandler } from '../../utils/handler';
|
|
3
3
|
/**
|
|
4
4
|
* 将像素数据绘制到画布。在自定义组件下,第二个参数传入自定义组件实例 this,以操作组件内 <canvas> 组件
|
|
5
5
|
* @todo 暂未支持尺寸相关功能
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** 创建离屏 canvas 实例 */
|
|
2
|
+
export declare const createOffscreenCanvas: () => Promise<{
|
|
3
|
+
errMsg: string;
|
|
4
|
+
}>;
|
|
5
|
+
/** 创建 canvas 的绘图上下文 CanvasContext 对象 */
|
|
6
|
+
export * from './createCanvasContext';
|
|
7
|
+
/** 把当前画布指定区域的内容导出生成指定大小的图片 */
|
|
8
|
+
export * from './canvasToTempFilePath';
|
|
9
|
+
/** 将像素数据绘制到画布 */
|
|
10
|
+
export * from './canvasPutImageData';
|
|
11
|
+
/** 获取 canvas 区域隐含的像素数据 */
|
|
12
|
+
export * from './canvasGetImageData';
|
package/dist/api/canvas/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils';
|
|
2
2
|
// 画布
|
|
3
|
+
/** 创建离屏 canvas 实例 */
|
|
3
4
|
export const createOffscreenCanvas = temporarilyNotSupport('createOffscreenCanvas');
|
|
5
|
+
/** 创建 canvas 的绘图上下文 CanvasContext 对象 */
|
|
4
6
|
export * from './createCanvasContext';
|
|
7
|
+
/** 把当前画布指定区域的内容导出生成指定大小的图片 */
|
|
5
8
|
export * from './canvasToTempFilePath';
|
|
9
|
+
/** 将像素数据绘制到画布 */
|
|
6
10
|
export * from './canvasPutImageData';
|
|
11
|
+
/** 获取 canvas 区域隐含的像素数据 */
|
|
7
12
|
export * from './canvasGetImageData';
|
|
8
|
-
export const drawCanvas = temporarilyNotSupport('drawCanvas');
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Taro from '@tarojs/api';
|
|
2
|
+
export declare class cloud implements Taro.cloud {
|
|
3
|
+
Cloud: new (options: Taro.cloud.IOptions) => Taro.Cloud;
|
|
4
|
+
init: () => Promise<{
|
|
5
|
+
errMsg: string;
|
|
6
|
+
}>;
|
|
7
|
+
CloudID: () => Promise<{
|
|
8
|
+
errMsg: string;
|
|
9
|
+
}>;
|
|
10
|
+
callFunction: () => Promise<{
|
|
11
|
+
errMsg: string;
|
|
12
|
+
}>;
|
|
13
|
+
uploadFile: () => Promise<{
|
|
14
|
+
errMsg: string;
|
|
15
|
+
}>;
|
|
16
|
+
downloadFile: () => Promise<{
|
|
17
|
+
errMsg: string;
|
|
18
|
+
}>;
|
|
19
|
+
getTempFileURL: () => Promise<{
|
|
20
|
+
errMsg: string;
|
|
21
|
+
}>;
|
|
22
|
+
deleteFile: () => Promise<{
|
|
23
|
+
errMsg: string;
|
|
24
|
+
}>;
|
|
25
|
+
database: () => Promise<{
|
|
26
|
+
errMsg: string;
|
|
27
|
+
}>;
|
|
28
|
+
callContainer: () => Promise<{
|
|
29
|
+
errMsg: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
package/dist/api/cloud/index.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const reportMonitor: () => Promise<{
|
|
2
|
+
errMsg: string;
|
|
3
|
+
}>;
|
|
4
|
+
export declare const reportAnalytics: () => Promise<{
|
|
5
|
+
errMsg: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const reportEvent: () => Promise<{
|
|
8
|
+
errMsg: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const getExptInfoSync: () => Promise<{
|
|
11
|
+
errMsg: string;
|
|
12
|
+
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils';
|
|
2
2
|
export const reportMonitor = temporarilyNotSupport('reportMonitor');
|
|
3
3
|
export const reportAnalytics = temporarilyNotSupport('reportAnalytics');
|
|
4
4
|
export const reportEvent = temporarilyNotSupport('reportEvent');
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Taro from '@tarojs/api';
|
|
2
|
+
/**
|
|
3
|
+
* 停止监听加速度数据。
|
|
4
|
+
*/
|
|
5
|
+
export declare const stopAccelerometer: typeof Taro.stopAccelerometer;
|
|
6
|
+
/**
|
|
7
|
+
* 开始监听加速度数据。
|
|
8
|
+
*/
|
|
9
|
+
export declare const startAccelerometer: typeof Taro.startAccelerometer;
|
|
10
|
+
/**
|
|
11
|
+
* 监听加速度数据事件。频率根据 Taro.startAccelerometer() 的 interval 参数。可使用 Taro.stopAccelerometer() 停止监听。
|
|
12
|
+
*/
|
|
13
|
+
export declare const onAccelerometerChange: typeof Taro.onAccelerometerChange;
|
|
14
|
+
/**
|
|
15
|
+
* 取消监听加速度数据事件,参数为空,则取消所有的事件监听
|
|
16
|
+
*/
|
|
17
|
+
export declare const offAccelerometerChange: typeof Taro.offAccelerometerChange;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { throttle } from '../../utils';
|
|
2
|
+
import { CallbackManager, MethodHandler } from '../../utils/handler';
|
|
2
3
|
const callbackManager = new CallbackManager();
|
|
3
4
|
let devicemotionListener;
|
|
4
5
|
/**
|
|
@@ -30,22 +31,6 @@ const INTERVAL_MAP = {
|
|
|
30
31
|
frequency: 5
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
|
-
const getDevicemotionListener = interval => {
|
|
34
|
-
let lock;
|
|
35
|
-
let timer;
|
|
36
|
-
return evt => {
|
|
37
|
-
if (lock)
|
|
38
|
-
return;
|
|
39
|
-
lock = true;
|
|
40
|
-
timer && clearTimeout(timer);
|
|
41
|
-
callbackManager.trigger({
|
|
42
|
-
x: evt.acceleration.x || 0,
|
|
43
|
-
y: evt.acceleration.y || 0,
|
|
44
|
-
z: evt.acceleration.z || 0
|
|
45
|
-
});
|
|
46
|
-
timer = setTimeout(() => { lock = false; }, interval);
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
34
|
/**
|
|
50
35
|
* 开始监听加速度数据。
|
|
51
36
|
*/
|
|
@@ -57,7 +42,14 @@ export const startAccelerometer = ({ interval = 'normal', success, fail, complet
|
|
|
57
42
|
if (devicemotionListener) {
|
|
58
43
|
stopAccelerometer();
|
|
59
44
|
}
|
|
60
|
-
devicemotionListener =
|
|
45
|
+
devicemotionListener = throttle((evt) => {
|
|
46
|
+
var _a, _b, _c;
|
|
47
|
+
callbackManager.trigger({
|
|
48
|
+
x: ((_a = evt.acceleration) === null || _a === void 0 ? void 0 : _a.x) || 0,
|
|
49
|
+
y: ((_b = evt.acceleration) === null || _b === void 0 ? void 0 : _b.y) || 0,
|
|
50
|
+
z: ((_c = evt.acceleration) === null || _c === void 0 ? void 0 : _c.z) || 0
|
|
51
|
+
});
|
|
52
|
+
}, intervalObj.interval);
|
|
61
53
|
window.addEventListener('devicemotion', devicemotionListener, true);
|
|
62
54
|
}
|
|
63
55
|
else {
|
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { temporarilyNotSupport } from '../../utils';
|
|
11
|
+
import { MethodHandler } from '../../utils/handler';
|
|
2
12
|
// 电量
|
|
3
13
|
export const getBatteryInfoSync = temporarilyNotSupport('getBatteryInfoSync');
|
|
4
|
-
export const getBatteryInfo =
|
|
14
|
+
export const getBatteryInfo = ({ success, fail, complete } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
var _a;
|
|
16
|
+
const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete });
|
|
17
|
+
try {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const battery = yield ((_a = navigator.getBattery) === null || _a === void 0 ? void 0 : _a.call(navigator));
|
|
20
|
+
return handle.success({
|
|
21
|
+
isCharging: battery.charging,
|
|
22
|
+
level: Number(battery.level || 0) * 100
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return handle.fail({
|
|
27
|
+
errMsg: (error === null || error === void 0 ? void 0 : error.message) || error
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const writeBLECharacteristicValue: () => Promise<{
|
|
2
|
+
errMsg: string;
|
|
3
|
+
}>;
|
|
4
|
+
export declare const setBLEMTU: () => Promise<{
|
|
5
|
+
errMsg: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const readBLECharacteristicValue: () => Promise<{
|
|
8
|
+
errMsg: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const onBLEMTUChange: () => Promise<{
|
|
11
|
+
errMsg: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const onBLEConnectionStateChange: () => Promise<{
|
|
14
|
+
errMsg: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const onBLECharacteristicValueChange: () => Promise<{
|
|
17
|
+
errMsg: string;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const offBLEMTUChange: () => Promise<{
|
|
20
|
+
errMsg: string;
|
|
21
|
+
}>;
|
|
22
|
+
export declare const offBLEConnectionStateChange: () => Promise<{
|
|
23
|
+
errMsg: string;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const offBLECharacteristicValueChange: () => Promise<{
|
|
26
|
+
errMsg: string;
|
|
27
|
+
}>;
|
|
28
|
+
export declare const notifyBLECharacteristicValueChange: () => Promise<{
|
|
29
|
+
errMsg: string;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const getBLEMTU: () => Promise<{
|
|
32
|
+
errMsg: string;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const getBLEDeviceServices: () => Promise<{
|
|
35
|
+
errMsg: string;
|
|
36
|
+
}>;
|
|
37
|
+
export declare const getBLEDeviceRSSI: () => Promise<{
|
|
38
|
+
errMsg: string;
|
|
39
|
+
}>;
|
|
40
|
+
export declare const getBLEDeviceCharacteristics: () => Promise<{
|
|
41
|
+
errMsg: string;
|
|
42
|
+
}>;
|
|
43
|
+
export declare const createBLEConnection: () => Promise<{
|
|
44
|
+
errMsg: string;
|
|
45
|
+
}>;
|
|
46
|
+
export declare const closeBLEConnection: () => Promise<{
|
|
47
|
+
errMsg: string;
|
|
48
|
+
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils';
|
|
2
2
|
// 蓝牙-低功耗中心设备
|
|
3
3
|
export const writeBLECharacteristicValue = temporarilyNotSupport('writeBLECharacteristicValue');
|
|
4
4
|
export const setBLEMTU = temporarilyNotSupport('setBLEMTU');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const onBLEPeripheralConnectionStateChanged: () => Promise<{
|
|
2
|
+
errMsg: string;
|
|
3
|
+
}>;
|
|
4
|
+
export declare const offBLEPeripheralConnectionStateChanged: () => Promise<{
|
|
5
|
+
errMsg: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const createBLEPeripheralServer: () => Promise<{
|
|
8
|
+
errMsg: string;
|
|
9
|
+
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils';
|
|
2
2
|
// 蓝牙-低功耗外围设备
|
|
3
3
|
export const onBLEPeripheralConnectionStateChanged = temporarilyNotSupport('onBLEPeripheralConnectionStateChanged');
|
|
4
4
|
export const offBLEPeripheralConnectionStateChanged = temporarilyNotSupport('offBLEPeripheralConnectionStateChanged');
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const stopBluetoothDevicesDiscovery: () => Promise<{
|
|
2
|
+
errMsg: string;
|
|
3
|
+
}>;
|
|
4
|
+
export declare const startBluetoothDevicesDiscovery: () => Promise<{
|
|
5
|
+
errMsg: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const openBluetoothAdapter: () => Promise<{
|
|
8
|
+
errMsg: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const onBluetoothDeviceFound: () => Promise<{
|
|
11
|
+
errMsg: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const onBluetoothAdapterStateChange: () => Promise<{
|
|
14
|
+
errMsg: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const offBluetoothDeviceFound: () => Promise<{
|
|
17
|
+
errMsg: string;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const offBluetoothAdapterStateChange: () => Promise<{
|
|
20
|
+
errMsg: string;
|
|
21
|
+
}>;
|
|
22
|
+
export declare const makeBluetoothPair: () => Promise<{
|
|
23
|
+
errMsg: string;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const isBluetoothDevicePaired: () => Promise<{
|
|
26
|
+
errMsg: string;
|
|
27
|
+
}>;
|
|
28
|
+
export declare const getConnectedBluetoothDevices: () => Promise<{
|
|
29
|
+
errMsg: string;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const getBluetoothDevices: () => Promise<{
|
|
32
|
+
errMsg: string;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const getBluetoothAdapterState: () => Promise<{
|
|
35
|
+
errMsg: string;
|
|
36
|
+
}>;
|
|
37
|
+
export declare const closeBluetoothAdapter: () => Promise<{
|
|
38
|
+
errMsg: string;
|
|
39
|
+
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils';
|
|
2
2
|
// 蓝牙-通用
|
|
3
3
|
export const stopBluetoothDevicesDiscovery = temporarilyNotSupport('stopBluetoothDevicesDiscovery');
|
|
4
4
|
export const startBluetoothDevicesDiscovery = temporarilyNotSupport('startBluetoothDevicesDiscovery');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils';
|
|
2
2
|
// 日历
|
|
3
3
|
export const addPhoneRepeatCalendar = temporarilyNotSupport('addPhoneRepeatCalendar');
|
|
4
4
|
export const addPhoneCalendar = temporarilyNotSupport('addPhoneCalendar');
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
import Taro from '@tarojs/api';
|
|
8
|
+
/**
|
|
9
|
+
* 设置系统剪贴板的内容
|
|
10
|
+
*/
|
|
11
|
+
export declare const setClipboardData: typeof Taro.setClipboardData;
|
|
12
|
+
/**
|
|
13
|
+
* 获取系统剪贴板的内容
|
|
14
|
+
*/
|
|
15
|
+
export declare const getClipboardData: typeof Taro.getClipboardData;
|
|
@@ -4,8 +4,17 @@
|
|
|
4
4
|
* setClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/setClipBoardData
|
|
5
5
|
* getClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/getClipBoardData
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
import { MethodHandler } from '../../utils/handler';
|
|
17
|
+
import { getStorageSync, setStorage, setStorageSync } from '../storage/index';
|
|
9
18
|
const CLIPBOARD_STORAGE_NAME = 'taro_clipboard';
|
|
10
19
|
document.addEventListener('copy', () => {
|
|
11
20
|
var _a;
|
|
@@ -19,7 +28,7 @@ document.addEventListener('copy', () => {
|
|
|
19
28
|
/**
|
|
20
29
|
* 设置系统剪贴板的内容
|
|
21
30
|
*/
|
|
22
|
-
export const setClipboardData =
|
|
31
|
+
export const setClipboardData = ({ data, success, fail, complete }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
32
|
const handle = new MethodHandler({ name: 'setClipboardData', success, fail, complete });
|
|
24
33
|
try {
|
|
25
34
|
setStorageSync(CLIPBOARD_STORAGE_NAME, data);
|
|
@@ -49,11 +58,11 @@ export const setClipboardData = async ({ data, success, fail, complete }) => {
|
|
|
49
58
|
catch (e) {
|
|
50
59
|
return handle.fail({ errMsg: e.message });
|
|
51
60
|
}
|
|
52
|
-
};
|
|
61
|
+
});
|
|
53
62
|
/**
|
|
54
63
|
* 获取系统剪贴板的内容
|
|
55
64
|
*/
|
|
56
|
-
export const getClipboardData =
|
|
65
|
+
export const getClipboardData = ({ success, fail, complete } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
66
|
const handle = new MethodHandler({ name: 'getClipboardData', success, fail, complete });
|
|
58
67
|
try {
|
|
59
68
|
const data = getStorageSync(CLIPBOARD_STORAGE_NAME);
|
|
@@ -62,4 +71,4 @@ export const getClipboardData = async ({ success, fail, complete } = {}) => {
|
|
|
62
71
|
catch (e) {
|
|
63
72
|
return handle.fail({ errMsg: e.message });
|
|
64
73
|
}
|
|
65
|
-
};
|
|
74
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Taro from '@tarojs/api';
|
|
2
|
+
/**
|
|
3
|
+
* 停止监听罗盘数据
|
|
4
|
+
*/
|
|
5
|
+
export declare const stopCompass: typeof Taro.stopCompass;
|
|
6
|
+
/**
|
|
7
|
+
* 开始监听罗盘数据
|
|
8
|
+
*/
|
|
9
|
+
export declare const startCompass: typeof Taro.startCompass;
|
|
10
|
+
/**
|
|
11
|
+
* 监听罗盘数据变化事件。频率:5 次/秒,接口调用后会自动开始监听,可使用 wx.stopCompass 停止监听。
|
|
12
|
+
*/
|
|
13
|
+
export declare const onCompassChange: typeof Taro.onCompassChange;
|
|
14
|
+
/**
|
|
15
|
+
* 取消监听罗盘数据变化事件,参数为空,则取消所有的事件监听。
|
|
16
|
+
*/
|
|
17
|
+
export declare const offCompassChange: typeof Taro.offCompassChange;
|
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { throttle } from '../../utils';
|
|
2
|
+
import { CallbackManager, MethodHandler } from '../../utils/handler';
|
|
3
|
+
import { getDeviceInfo } from '../base/system';
|
|
2
4
|
const callbackManager = new CallbackManager();
|
|
3
5
|
let compassListener;
|
|
6
|
+
/**
|
|
7
|
+
* Note: 按系统类型获取对应绝对 orientation 事件名,因为安卓系统中直接监听 deviceorientation 事件得到的不是绝对 orientation
|
|
8
|
+
*/
|
|
9
|
+
const deviceorientationEventName = ['absolutedeviceorientation', 'deviceorientationabsolute', 'deviceorientation'].find(item => {
|
|
10
|
+
if ('on' + item in window) {
|
|
11
|
+
return item;
|
|
12
|
+
}
|
|
13
|
+
}) || '';
|
|
4
14
|
/**
|
|
5
15
|
* 停止监听罗盘数据
|
|
6
16
|
*/
|
|
7
17
|
export const stopCompass = ({ success, fail, complete } = {}) => {
|
|
8
18
|
const handle = new MethodHandler({ name: 'stopCompass', success, fail, complete });
|
|
9
19
|
try {
|
|
10
|
-
window.removeEventListener(
|
|
20
|
+
window.removeEventListener(deviceorientationEventName, compassListener, true);
|
|
11
21
|
return handle.success();
|
|
12
22
|
}
|
|
13
23
|
catch (e) {
|
|
14
24
|
return handle.fail({ errMsg: e.message });
|
|
15
25
|
}
|
|
16
26
|
};
|
|
17
|
-
|
|
18
|
-
let lock;
|
|
19
|
-
let timer;
|
|
20
|
-
return evt => {
|
|
21
|
-
if (lock)
|
|
22
|
-
return;
|
|
23
|
-
lock = true;
|
|
24
|
-
timer && clearTimeout(timer);
|
|
25
|
-
callbackManager.trigger({
|
|
26
|
-
direction: 360 - evt.alpha
|
|
27
|
-
});
|
|
28
|
-
timer = setTimeout(() => { lock = false; }, interval);
|
|
29
|
-
};
|
|
30
|
-
};
|
|
27
|
+
let CompassChangeTrigger = false;
|
|
31
28
|
/**
|
|
32
29
|
* 开始监听罗盘数据
|
|
33
30
|
*/
|
|
34
31
|
export const startCompass = ({ success, fail, complete } = {}) => {
|
|
35
32
|
const handle = new MethodHandler({ name: 'startCompass', success, fail, complete });
|
|
36
33
|
try {
|
|
37
|
-
if (
|
|
34
|
+
if (deviceorientationEventName !== '') {
|
|
38
35
|
if (compassListener) {
|
|
39
36
|
stopCompass();
|
|
40
37
|
}
|
|
41
|
-
compassListener =
|
|
42
|
-
|
|
38
|
+
compassListener = throttle((evt) => {
|
|
39
|
+
const isAndroid = getDeviceInfo().system === 'AndroidOS';
|
|
40
|
+
if (isAndroid && !evt.absolute && !CompassChangeTrigger) {
|
|
41
|
+
CompassChangeTrigger = true;
|
|
42
|
+
console.warn('Warning: In \'onCompassChange\', your browser is not supported to get the orientation relative to the earth, the orientation data will be related to the initial orientation of the device .');
|
|
43
|
+
}
|
|
44
|
+
const alpha = evt.alpha || 0;
|
|
45
|
+
/**
|
|
46
|
+
* 由于平台差异,accuracy 在 iOS/Android 的值不同。
|
|
47
|
+
* - iOS:accuracy 是一个 number 类型的值,表示相对于磁北极的偏差。0 表示设备指向磁北,90 表示指向东,180 表示指向南,依此类推。
|
|
48
|
+
* - Android:accuracy 是一个 string 类型的枚举值。
|
|
49
|
+
*/
|
|
50
|
+
const accuracy = isAndroid ? evt.absolute ? 'high' : 'medium' : alpha;
|
|
51
|
+
callbackManager.trigger({
|
|
52
|
+
direction: 360 - alpha,
|
|
53
|
+
accuracy: accuracy
|
|
54
|
+
});
|
|
55
|
+
}, 5000);
|
|
56
|
+
window.addEventListener(deviceorientationEventName, compassListener, true);
|
|
43
57
|
}
|
|
44
58
|
else {
|
|
45
59
|
throw new Error('compass is not supported');
|