@tarojs/taro-h5 3.3.14 → 3.3.18

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.
Files changed (175) hide show
  1. package/dist/index.cjs.js +6601 -8371
  2. package/dist/index.js +9493 -0
  3. package/dist/taroApis.js +1 -1
  4. package/package.json +9 -9
  5. package/src/api/ad/index.ts +5 -0
  6. package/src/api/ai/facial.ts +6 -0
  7. package/src/api/ai/index.ts +2 -0
  8. package/src/api/ai/visual.ts +4 -0
  9. package/src/api/alipay/index.ts +4 -0
  10. package/src/api/base/crypto.ts +4 -0
  11. package/src/api/base/debug.ts +5 -0
  12. package/src/api/base/index.ts +23 -0
  13. package/src/api/base/performance.ts +5 -0
  14. package/src/api/base/system/index.ts +2 -0
  15. package/src/api/base/system/info.ts +64 -0
  16. package/src/api/base/system/network.ts +70 -0
  17. package/src/api/base/update.ts +5 -0
  18. package/src/api/base/weapp/app-event.ts +19 -0
  19. package/src/api/base/weapp/life-cycle.ts +5 -0
  20. package/src/api/canvas/CanvasContext.ts +230 -0
  21. package/src/api/canvas/canvasGetImageData.ts +27 -0
  22. package/src/api/canvas/canvasPutImageData.ts +24 -0
  23. package/src/api/canvas/canvasToTempFilePath.ts +24 -0
  24. package/src/api/canvas/createCanvasContext.ts +18 -0
  25. package/src/api/canvas/index.ts +10 -0
  26. package/src/api/cloud/index.ts +27 -0
  27. package/src/api/data-analysis/index.ts +6 -0
  28. package/src/api/device/accelerometer.ts +87 -0
  29. package/src/api/device/accessibility.ts +4 -0
  30. package/src/api/device/battery.ts +5 -0
  31. package/src/api/device/bluetooth-ble.ts +19 -0
  32. package/src/api/device/bluetooth-peripheral.ts +6 -0
  33. package/src/api/device/bluetooth.ts +16 -0
  34. package/src/api/device/calendar.ts +5 -0
  35. package/src/api/device/clipboard.ts +67 -0
  36. package/src/api/device/compass.ts +67 -0
  37. package/src/api/device/contact.ts +5 -0
  38. package/src/api/device/crypto.ts +4 -0
  39. package/src/api/device/gyroscope.ts +7 -0
  40. package/src/api/device/iBeacon.ts +10 -0
  41. package/src/api/device/index.ts +22 -0
  42. package/src/api/device/keyboard.ts +7 -0
  43. package/src/api/device/memory.ts +5 -0
  44. package/src/api/device/motion.ts +85 -0
  45. package/src/api/device/nfc.ts +10 -0
  46. package/src/api/device/phone.ts +30 -0
  47. package/src/api/device/scan.ts +7 -0
  48. package/src/api/device/screen.ts +9 -0
  49. package/src/api/device/vibrate.ts +36 -0
  50. package/src/api/device/wifi.ts +13 -0
  51. package/src/api/ext/index.ts +5 -0
  52. package/src/api/files/index.ts +11 -0
  53. package/src/api/framework/index.ts +10 -0
  54. package/src/api/index.ts +25 -0
  55. package/src/api/location/chooseLocation.ts +106 -0
  56. package/src/api/location/index.ts +19 -0
  57. package/src/api/location/style.css +8 -8
  58. package/src/api/media/audio/index.ts +105 -0
  59. package/src/api/media/background-audio.ts +12 -0
  60. package/src/api/media/camera.ts +4 -0
  61. package/src/api/media/editor.ts +29 -0
  62. package/src/api/media/image/chooseImage.ts +78 -0
  63. package/src/api/media/image/getImageInfo.ts +35 -0
  64. package/src/api/media/image/index.ts +13 -0
  65. package/src/api/media/image/previewImage.ts +101 -0
  66. package/src/api/media/index.ts +13 -0
  67. package/src/api/media/live.ts +5 -0
  68. package/src/api/media/map.ts +4 -0
  69. package/src/api/media/media-recorder.ts +4 -0
  70. package/src/api/media/recorder.ts +6 -0
  71. package/src/api/media/video/index.ts +82 -0
  72. package/src/api/media/video-decoder.ts +4 -0
  73. package/src/api/media/video-processing.ts +4 -0
  74. package/src/api/media/voip.ts +17 -0
  75. package/src/api/navigate/index.ts +7 -0
  76. package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -27
  77. package/src/api/network/index.ts +7 -0
  78. package/src/api/network/mdns.ts +13 -0
  79. package/src/api/{request/index.js → network/request/index.ts} +9 -6
  80. package/src/api/network/tcp.ts +4 -0
  81. package/src/api/network/udp.ts +4 -0
  82. package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -32
  83. package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
  84. package/src/api/network/websocket/index.ts +88 -0
  85. package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
  86. package/src/api/open-api/account.ts +4 -0
  87. package/src/api/open-api/address.ts +4 -0
  88. package/src/api/open-api/authorize.ts +5 -0
  89. package/src/api/open-api/card.ts +5 -0
  90. package/src/api/open-api/channels-live.ts +9 -0
  91. package/src/api/open-api/customer-service.ts +4 -0
  92. package/src/api/open-api/facial.ts +7 -0
  93. package/src/api/open-api/favorites.ts +5 -0
  94. package/src/api/open-api/group.ts +4 -0
  95. package/src/api/open-api/index.ts +18 -0
  96. package/src/api/open-api/invoice.ts +5 -0
  97. package/src/api/open-api/license-plate.ts +4 -0
  98. package/src/api/open-api/login.ts +6 -0
  99. package/src/api/open-api/red-package.ts +4 -0
  100. package/src/api/open-api/settings.ts +5 -0
  101. package/src/api/open-api/soter.ts +6 -0
  102. package/src/api/open-api/subscribe-message.ts +4 -0
  103. package/src/api/open-api/user-info.ts +5 -0
  104. package/src/api/open-api/werun.ts +5 -0
  105. package/src/api/payment/index.ts +5 -0
  106. package/src/api/route/index.ts +10 -0
  107. package/src/api/share/index.ts +13 -0
  108. package/src/api/storage/background-fetch.ts +7 -0
  109. package/src/api/storage/index.ts +181 -0
  110. package/src/api/swan/index.ts +31 -0
  111. package/src/{taro/index.js → api/taro.ts} +133 -149
  112. package/src/api/{createAnimation/index.js → ui/animation/index.ts} +51 -35
  113. package/src/api/ui/background.ts +5 -0
  114. package/src/api/ui/custom-component.ts +4 -0
  115. package/src/api/ui/fonts.ts +4 -0
  116. package/src/api/ui/index.ts +12 -0
  117. package/src/api/ui/interaction/actionSheet.ts +212 -0
  118. package/src/api/{interactive/index.js → ui/interaction/index.ts} +93 -77
  119. package/src/api/ui/interaction/modal.ts +237 -0
  120. package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
  121. package/src/api/ui/menu.ts +4 -0
  122. package/src/api/ui/navigation-bar/index.ts +52 -0
  123. package/src/api/ui/pull-down-refresh.ts +27 -0
  124. package/src/api/ui/scroll/index.ts +85 -0
  125. package/src/api/ui/sticky.ts +4 -0
  126. package/src/api/ui/tab-bar.ts +326 -0
  127. package/src/api/ui/window.ts +37 -0
  128. package/src/api/utils/handler.ts +105 -0
  129. package/src/api/utils/{index.js → index.ts} +36 -115
  130. package/src/api/worker/index.ts +4 -0
  131. package/src/api/wxml/index.ts +9 -0
  132. package/src/api/wxml/nodesRef.ts +49 -0
  133. package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +75 -94
  134. package/src/index.ts +6 -0
  135. package/src/types/api.d.ts +4 -0
  136. package/src/types/define.d.ts +2 -0
  137. package/{types → src/types}/index.d.ts +0 -0
  138. package/{types → src/types}/type.ts +1 -1
  139. package/src/api/accelerometer/index.js +0 -105
  140. package/src/api/audio/index.js +0 -137
  141. package/src/api/canvas/canvasGetImageData.js +0 -44
  142. package/src/api/canvas/canvasPutImageData.js +0 -45
  143. package/src/api/canvas/canvasToTempFilePath.js +0 -49
  144. package/src/api/canvas/createCanvasContext.js +0 -340
  145. package/src/api/canvas/index.js +0 -4
  146. package/src/api/clipboard/index.js +0 -113
  147. package/src/api/compass/index.js +0 -99
  148. package/src/api/deviceMotion/index.js +0 -105
  149. package/src/api/fileTransfer/index.js +0 -2
  150. package/src/api/image/chooseImage.js +0 -87
  151. package/src/api/image/getImageInfo.js +0 -74
  152. package/src/api/image/index.js +0 -7
  153. package/src/api/image/previewImage.js +0 -94
  154. package/src/api/index.js +0 -29
  155. package/src/api/interactive/actionSheet.js +0 -214
  156. package/src/api/interactive/modal.js +0 -256
  157. package/src/api/location/chooseLocation.js +0 -143
  158. package/src/api/location/index.js +0 -5
  159. package/src/api/navigationBar/index.js +0 -57
  160. package/src/api/open/index.js +0 -5
  161. package/src/api/others/index.js +0 -43
  162. package/src/api/pullDownRefresh/index.js +0 -51
  163. package/src/api/scroll/index.js +0 -99
  164. package/src/api/storage/index.js +0 -211
  165. package/src/api/system/index.js +0 -9
  166. package/src/api/system/info.js +0 -36
  167. package/src/api/system/network.js +0 -68
  168. package/src/api/tabBar/index.js +0 -424
  169. package/src/api/unsupportedApi/index.js +0 -278
  170. package/src/api/vibrate/index.js +0 -49
  171. package/src/api/video/index.js +0 -87
  172. package/src/api/webSocket/index.js +0 -103
  173. package/src/api/window/index.js +0 -38
  174. package/src/index.cjs.js +0 -11
  175. package/src/index.js +0 -6
@@ -1,105 +0,0 @@
1
- import { createCallbackManager, successHandler, errorHandler } from '../utils/index'
2
-
3
- const callbackManager = createCallbackManager()
4
- let devicemotionListener
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 stopAccelerometer = ({ success, fail, complete } = {}) => {
14
- const res = {}
15
- try {
16
- window.removeEventListener('devicemotion', devicemotionListener, true)
17
- res.errMsg = 'stopAccelerometer:ok'
18
- return successHandler(success, complete)(res)
19
- } catch (e) {
20
- res.errMsg = `stopAccelerometer:fail ${e.message}`
21
- return errorHandler(fail, complete)(res)
22
- }
23
- }
24
-
25
- const INTERVALMAP = {
26
- game: {
27
- interval: 20,
28
- frequency: 50
29
- },
30
- ui: {
31
- interval: 60,
32
- frequency: 16.67
33
- },
34
- normal: {
35
- interval: 200,
36
- frequency: 5
37
- }
38
- }
39
-
40
- const getDevicemotionListener = interval => {
41
- let lock
42
- let timer
43
- return evt => {
44
- if (lock) return
45
- lock = true
46
- timer && clearTimeout(timer)
47
- callbackManager.trigger({
48
- x: evt.acceleration.x || 0,
49
- y: evt.acceleration.y || 0,
50
- z: evt.acceleration.z || 0
51
- })
52
- timer = setTimeout(() => { lock = false }, interval)
53
- }
54
- }
55
-
56
- /**
57
- * 开始监听加速度数据。
58
- * @param {Object} [object] 参数
59
- * @param {'game' | 'ui' | 'normal'} [object.interval=normal] 监听加速度数据回调函数的执行频率
60
- * game 适用于更新游戏的回调频率,在 20ms/次 左右
61
- * ui 适用于更新 UI 的回调频率,在 60ms/次 左右
62
- * normal 普通的回调频率,在 200ms/次 左右
63
- * @param {function} [object.success] 接口调用成功的回调函数
64
- * @param {function} [object.fail] 接口调用失败的回调函数
65
- * @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
66
- */
67
- const startAccelerometer = ({ interval = 'normal', success, fail, complete } = {}) => {
68
- try {
69
- if (window.DeviceMotionEvent) {
70
- const intervalObj = INTERVALMAP[interval]
71
- if (devicemotionListener) {
72
- stopAccelerometer()
73
- }
74
- devicemotionListener = getDevicemotionListener(intervalObj.interval)
75
- window.addEventListener('devicemotion', devicemotionListener, true)
76
- } else {
77
- throw new Error('accelerometer is not supported')
78
- }
79
- return successHandler(success, complete)({
80
- errMsg: 'startAccelerometer:ok'
81
- })
82
- } catch (e) {
83
- return errorHandler(fail, complete)({
84
- errMsg: `startAccelerometer:fail ${e.message}`
85
- })
86
- }
87
- }
88
-
89
- /**
90
- * 加速度数据事件的回调函数的参数
91
- * @typedef {object} AccelerometerParam
92
- * @property {number} x X 轴
93
- * @property {number} y Y 轴
94
- * @property {number} z Z 轴
95
- */
96
-
97
- /**
98
- * 监听加速度数据事件。频率根据 wx.startAccelerometer() 的 interval 参数。可使用 wx.stopAccelerometer() 停止监听。
99
- * @param {(res: AccelerometerParam) => void} callback 加速度数据事件的回调函数
100
- */
101
- const onAccelerometerChange = callback => {
102
- callbackManager.add(callback)
103
- }
104
-
105
- export { stopAccelerometer, startAccelerometer, onAccelerometerChange }
@@ -1,137 +0,0 @@
1
- import Taro from '@tarojs/api'
2
- import { createCallbackManager } from '../utils/index'
3
-
4
- /**
5
- * @typedef {object} InnerAudioContext
6
- * @property {string} src 音频资源的地址,用于直接播放。2.2.3 开始支持云文件ID
7
- * @property {number} [startTime=0] 开始播放的位置(单位:s),默认为 0
8
- * @property {boolean} [autoplay=false] 是否自动开始播放,默认为 false
9
- * @property {boolean} [loop=false] 是否循环播放,默认为 false
10
- * @property {boolean} [obeyMuteSwitch=true] 是否遵循系统静音开关,默认为 true。当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音。从 2.3.0 版本开始此参数不生效,使用 wx.setInnerAudioOption 接口统一设置。
11
- * @property {number} [volume=1] 音量。范围 0~1。默认为 1
12
- * @property {number} duration 当前音频的长度(单位 s)。只有在当前有合法的 src 时返回(只读)
13
- * @property {number} currentTime 当前音频的播放位置(单位 s)。只有在当前有合法的 src 时返回,时间保留小数点后 6 位(只读)
14
- * @property {boolean} paused 当前是是否暂停或停止状态(只读)
15
- * @property {number} buffered 音频缓冲的时间点,仅保证当前播放时间点到此时间点内容已缓冲(只读)
16
- * @property {() => void} play() 播放
17
- * @property {() => void} pause() 暂停。暂停后的音频再播放会从暂停处开始播放
18
- * @property {() => void} stop() 停止。停止后的音频再播放会从头开始播放。
19
- * @property {(position: number) => void} seek(number position) 跳转到指定位置
20
- * @property {() => void} destroy() 销毁当前实例
21
- * @property {(callback: function) => void} offCanplay(function callback) 取消监听音频进入可以播放状态的事件
22
- * @property {(callback: function) => void} offEnded(function callback) 取消监听音频自然播放至结束的事件
23
- * @property {(callback: function) => void} offError(function callback) 取消监听音频播放错误事件
24
- * @property {(callback: function) => void} offPause(function callback) 取消监听音频暂停事件
25
- * @property {(callback: function) => void} offPlay(function callback) 取消监听音频播放事件
26
- * @property {(callback: function) => void} offSeeked(function callback) 取消监听音频完成跳转操作的事件
27
- * @property {(callback: function) => void} offSeeking(function callback) 取消监听音频进行跳转操作的事件
28
- * @property {(callback: function) => void} offStop(function callback) 取消监听音频停止事件
29
- * @property {(callback: function) => void} offTimeUpdate(function callback) 取消监听音频播放进度更新事件
30
- * @property {(callback: function) => void} offWaiting(function callback) 取消监听音频加载中事件
31
- * @property {(callback: function) => void} onCanplay(function callback) 监听音频进入可以播放状态的事件。但不保证后面可以流畅播放
32
- * @property {(callback: function) => void} onEnded(function callback) 监听音频自然播放至结束的事件
33
- * @property {(callback: function) => void} onError(function callback) 监听音频播放错误事件
34
- * @property {(callback: function) => void} onPause(function callback) 监听音频暂停事件
35
- * @property {(callback: function) => void} onPlay(function callback) 监听音频播放事件
36
- * @property {(callback: function) => void} onSeeked(function callback) 监听音频完成跳转操作的事件
37
- * @property {(callback: function) => void} onSeeking(function callback) 监听音频进行跳转操作的事件
38
- * @property {(callback: function) => void} onStop(function callback) 监听音频停止事件
39
- * @property {(callback: function) => void} onTimeUpdate(function callback) 监听音频播放进度更新事件
40
- * @property {(callback: function) => void} onWaiting(function callback) 监听音频加载中事件。当音频因为数据不足,需要停下来加载时会触发
41
- */
42
-
43
- /**
44
- * 创建内部 audio 上下文 InnerAudioContext 对象。
45
- * @returns {InnerAudioContext}
46
- */
47
- export const createInnerAudioContext = () => {
48
- /** @type {HTMLAudioElement} */
49
- let audioEl = new Audio()
50
-
51
- /** @type {InnerAudioContext} */
52
- const iac = {}
53
-
54
- const callbackManagers = {
55
- error: createCallbackManager(),
56
- stop: createCallbackManager()
57
- }
58
-
59
- iac.play = () => audioEl.play()
60
- iac.pause = () => audioEl.pause()
61
- iac.stop = () => {
62
- iac.pause()
63
- iac.seek(0)
64
- callbackManagers.stop.trigger()
65
- }
66
- iac.seek = position => {
67
- audioEl.currentTime = position
68
- }
69
- /**
70
- * @todo destroy得并不干净
71
- */
72
- iac.destroy = () => {
73
- iac.stop()
74
- document.body.removeChild(audioEl)
75
- audioEl = null
76
- }
77
-
78
- const simpleProperties = ['src', 'autoplay', 'loop', 'volume', 'duration', 'currentTime', 'buffered', 'paused']
79
- simpleProperties.forEach(propertyName => {
80
- Object.defineProperty(iac, propertyName, {
81
- get: () => audioEl[propertyName],
82
- set (value) { audioEl[propertyName] = value }
83
- })
84
- })
85
-
86
- Object.defineProperty(iac, 'startTime', {
87
- value: 0
88
- })
89
- Object.defineProperty(iac, 'obeyMuteSwitch', {
90
- value: true
91
- })
92
-
93
- const simpleEvents = [
94
- 'Canplay',
95
- 'Ended',
96
- 'Pause',
97
- 'Play',
98
- 'Seeked',
99
- 'Seeking',
100
- 'TimeUpdate',
101
- 'Waiting'
102
- ]
103
- const simpleListenerTuples = [
104
- ['on', audioEl.addEventListener],
105
- ['off', audioEl.removeEventListener]
106
- ]
107
-
108
- simpleEvents.forEach(eventName => {
109
- simpleListenerTuples.forEach(([eventNamePrefix, listenerFunc]) => {
110
- Object.defineProperty(iac, `${eventNamePrefix}${eventName}`, {
111
- get () {
112
- return callback => listenerFunc.call(audioEl, eventName.toLowerCase(), callback)
113
- }
114
- })
115
- })
116
- })
117
-
118
- const customEvents = ['Stop', 'Error']
119
- const customListenerTuples = [
120
- ['on', 'add'],
121
- ['off', 'remove']
122
- ]
123
-
124
- customEvents.forEach(eventName => {
125
- customListenerTuples.forEach(([eventNamePrefix, actionName]) => {
126
- Object.defineProperty(iac, `${eventNamePrefix}${eventName}`, {
127
- get () {
128
- return callback => callbackManagers[eventName.toLowerCase()][actionName](callback)
129
- }
130
- })
131
- })
132
- })
133
-
134
- Taro.eventCenter.on('__taroRouterChange', () => { iac.stop() })
135
-
136
- return iac
137
- }
@@ -1,44 +0,0 @@
1
- import { findDOM } from '../utils/index'
2
-
3
- /**
4
- * @typedef {Object} Param
5
- * @property {String} canvasId 画布标识,传入 <canvas> 组件的 canvas-id 属性。
6
- * @property {Number} x 将要被提取的图像数据矩形区域的左上角横坐标
7
- * @property {Number} y 将要被提取的图像数据矩形区域的左上角纵坐标
8
- * @property {Number} width 将要被提取的图像数据矩形区域的宽度
9
- * @property {Number} height 将要被提取的图像数据矩形区域的高度
10
- * @property {Function} [success] 接口调用成功的回调函数
11
- * @property {Function} [fail] 接口调用失败的回调函数
12
- * @property {Function} [complete] 接口调用结束的回调函数(调用成功、失败都会执行)
13
- */
14
-
15
- /**
16
- * 获取 canvas 区域隐含的像素数据。
17
- * @param {Param} object 参数
18
- */
19
- const canvasGetImageData = ({ canvasId, success, fail, complete, x, y, width, height }, inst) => {
20
- /** @type {HTMLCanvasElement} */
21
- const canvas = findDOM(inst).querySelector(`canvas[canvas-id="${canvasId}"]`)
22
-
23
- try {
24
- const ctx = canvas.getContext('2d')
25
- const data = ctx.getImageData(x, y, width, height)
26
- const res = {
27
- width,
28
- height,
29
- data
30
- }
31
- success && success(res)
32
- complete && complete()
33
- return Promise.resolve(res)
34
- } catch (e) {
35
- const res = {
36
- errMsg: e.message
37
- }
38
- fail && fail(res)
39
- complete && complete()
40
- return Promise.reject(res)
41
- }
42
- }
43
-
44
- export default canvasGetImageData
@@ -1,45 +0,0 @@
1
- import { findDOM } from '../utils/index'
2
-
3
- /**
4
- * @typedef {Object} Param
5
- * @property {String} canvasId 画布标识,传入 <canvas> 组件的 canvas-id 属性。
6
- * @property {Uint8ClampedArray} data 图像像素点数据,一维数组,每四项表示一个像素点的 rgba
7
- * @property {Number} x 源图像数据在目标画布中的位置偏移量(x 轴方向的偏移量)
8
- * @property {Number} y 源图像数据在目标画布中的位置偏移量(y 轴方向的偏移量)
9
- * @property {Number} width 源图像数据矩形区域的宽度
10
- * @property {Number} height 源图像数据矩形区域的高度
11
- * @property {Function} [success] 接口调用成功的回调函数
12
- * @property {Function} [fail] 接口调用失败的回调函数
13
- * @property {Function} [complete] 接口调用结束的回调函数(调用成功、失败都会执行)
14
- */
15
-
16
- /**
17
- * 将像素数据绘制到画布。在自定义组件下,第二个参数传入自定义组件实例 this,以操作组件内 <canvas> 组件
18
- * @param {Param} object 参数
19
- * @todo 暂未支持尺寸相关功能
20
- */
21
- const canvasPutImageData = ({ canvasId, data, x, y, success, fail, complete }, inst) => {
22
- /** @type {HTMLCanvasElement} */
23
- const canvas = findDOM(inst).querySelector(`canvas[canvas-id="${canvasId}"]`)
24
-
25
- try {
26
- const ctx = canvas.getContext('2d')
27
-
28
- ctx.putImageData(data, x, y)
29
- const res = {
30
- errMsg: 'canvasPutImageData:ok'
31
- }
32
- success && success(res)
33
- complete && complete()
34
- return Promise.resolve(res)
35
- } catch (e) {
36
- const res = {
37
- errMsg: e.message
38
- }
39
- fail && fail(res)
40
- complete && complete()
41
- return Promise.reject(res)
42
- }
43
- }
44
-
45
- export default canvasPutImageData
@@ -1,49 +0,0 @@
1
- import { findDOM } from '../utils/index'
2
-
3
- /**
4
- * @typedef {Object} Param
5
- * @property {Number} [x] 指定的画布区域的左上角横坐标,默认值 0
6
- * @property {Number} [y] 指定的画布区域的左上角纵坐标,默认值 0
7
- * @property {Number} [width] 指定的画布区域的宽度,默认值 canvas宽度-x
8
- * @property {Number} [height] 指定的画布区域的高度,默认值 canvas宽度-y
9
- * @property {Number} [destWidth] 输出的图片的宽度,默认值 width*屏幕像素密度
10
- * @property {Number} [destHeight] 输出的图片的高度,默认值 height*屏幕像素密度
11
- * @property {String} canvasId 画布标识,传入 <canvas> 组件的 canvas-id
12
- * @property {String} [fileType] 目标文件的类型,默认值 png
13
- * @property {Number} quality 图片的质量,目前仅对 jpg 有效。取值范围为 (0, 1],不在范围内时当作 1.0 处理。
14
- * @property {Function} [success] 接口调用成功的回调函数
15
- * @property {Function} [fail] 接口调用失败的回调函数
16
- * @property {Function} [complete] 接口调用结束的回调函数(调用成功、失败都会执行)
17
- */
18
-
19
- /**
20
- * 把当前画布指定区域的内容导出生成指定大小的图片。在 draw() 回调里调用该方法才能保证图片导出成功。
21
- * @param {Param} object 参数
22
- * @todo 暂未支持尺寸相关功能
23
- */
24
- const canvasToTempFilePath = ({ canvasId, fileType, quality, success, fail, complete }, inst) => {
25
- /** @type {HTMLCanvasElement} */
26
- const canvas = findDOM(inst).querySelector(`canvas[canvas-id=${canvasId}]`)
27
-
28
- try {
29
- // /** @type {CanvasRenderingContext2D} */
30
- const dataURL = canvas.toDataURL(`image/${fileType || 'png'}`, quality)
31
- const res = {
32
- tempFilePath: dataURL,
33
- res: 'canvasToTempFilePath:ok'
34
- }
35
-
36
- success && success(res)
37
- complete && complete()
38
- return Promise.resolve(res)
39
- } catch (e) {
40
- const res = {
41
- errMsg: e.message
42
- }
43
- fail && fail(res)
44
- complete && complete()
45
- return Promise.reject(res)
46
- }
47
- }
48
-
49
- export default canvasToTempFilePath