@spcsn/taro 0.1.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.
Files changed (140) hide show
  1. package/README.md +12 -0
  2. package/dist/index.js +147 -0
  3. package/dist/index.js.map +1 -0
  4. package/index.js +9 -0
  5. package/package.json +86 -0
  6. package/types/api/ad/index.d.ts +197 -0
  7. package/types/api/ai/face.d.ts +133 -0
  8. package/types/api/ai/inference.d.ts +129 -0
  9. package/types/api/ai/visionkit.d.ts +874 -0
  10. package/types/api/alipay/index.d.ts +69 -0
  11. package/types/api/base/crypto.d.ts +104 -0
  12. package/types/api/base/debug.d.ts +329 -0
  13. package/types/api/base/env.d.ts +19 -0
  14. package/types/api/base/index.d.ts +102 -0
  15. package/types/api/base/performance.d.ts +258 -0
  16. package/types/api/base/system.d.ts +742 -0
  17. package/types/api/base/update.d.ts +130 -0
  18. package/types/api/base/weapp/app-event.d.ts +265 -0
  19. package/types/api/base/weapp/life-cycle.d.ts +155 -0
  20. package/types/api/canvas/index.d.ts +2162 -0
  21. package/types/api/cloud/index.d.ts +2622 -0
  22. package/types/api/data-analysis/index.d.ts +122 -0
  23. package/types/api/device/accelerometer.d.ts +102 -0
  24. package/types/api/device/accessibility.d.ts +26 -0
  25. package/types/api/device/battery.d.ts +46 -0
  26. package/types/api/device/bluetooth-ble.d.ts +601 -0
  27. package/types/api/device/bluetooth-peripheral.d.ts +430 -0
  28. package/types/api/device/bluetooth.d.ts +463 -0
  29. package/types/api/device/calendar.d.ts +98 -0
  30. package/types/api/device/clipboard.d.ts +81 -0
  31. package/types/api/device/compass.d.ts +105 -0
  32. package/types/api/device/contact.d.ts +110 -0
  33. package/types/api/device/gyroscope.d.ts +85 -0
  34. package/types/api/device/iBeacon.d.ts +168 -0
  35. package/types/api/device/keyboard.d.ts +97 -0
  36. package/types/api/device/memory.d.ts +52 -0
  37. package/types/api/device/motion.d.ts +88 -0
  38. package/types/api/device/network.d.ts +172 -0
  39. package/types/api/device/nfc.d.ts +1238 -0
  40. package/types/api/device/phone.d.ts +30 -0
  41. package/types/api/device/scan.d.ts +111 -0
  42. package/types/api/device/screen.d.ts +217 -0
  43. package/types/api/device/sms.d.ts +26 -0
  44. package/types/api/device/vibrate.d.ts +51 -0
  45. package/types/api/device/wifi.d.ts +301 -0
  46. package/types/api/ext/index.d.ts +64 -0
  47. package/types/api/files/index.d.ts +1472 -0
  48. package/types/api/framework/index.d.ts +51 -0
  49. package/types/api/location/index.d.ts +517 -0
  50. package/types/api/media/audio.d.ts +1013 -0
  51. package/types/api/media/background-audio.d.ts +291 -0
  52. package/types/api/media/camera.d.ts +207 -0
  53. package/types/api/media/editor.d.ts +239 -0
  54. package/types/api/media/image.d.ts +469 -0
  55. package/types/api/media/live.d.ts +461 -0
  56. package/types/api/media/map.d.ts +638 -0
  57. package/types/api/media/media-recorder.d.ts +117 -0
  58. package/types/api/media/recorder.d.ts +317 -0
  59. package/types/api/media/video-decoder.d.ts +117 -0
  60. package/types/api/media/video-processing.d.ts +84 -0
  61. package/types/api/media/video.d.ts +527 -0
  62. package/types/api/media/voip.d.ts +393 -0
  63. package/types/api/navigate/index.d.ts +327 -0
  64. package/types/api/network/download.d.ts +173 -0
  65. package/types/api/network/mdns.d.ts +191 -0
  66. package/types/api/network/request.d.ts +480 -0
  67. package/types/api/network/tcp.d.ts +181 -0
  68. package/types/api/network/udp.d.ts +218 -0
  69. package/types/api/network/upload.d.ts +201 -0
  70. package/types/api/network/websocket.d.ts +383 -0
  71. package/types/api/open-api/account.d.ts +51 -0
  72. package/types/api/open-api/address.d.ts +68 -0
  73. package/types/api/open-api/authorize.d.ts +80 -0
  74. package/types/api/open-api/card.d.ts +110 -0
  75. package/types/api/open-api/channels.d.ts +225 -0
  76. package/types/api/open-api/customer-service.d.ts +45 -0
  77. package/types/api/open-api/device-voip.d.ts +103 -0
  78. package/types/api/open-api/facial.d.ts +98 -0
  79. package/types/api/open-api/favorites.d.ts +101 -0
  80. package/types/api/open-api/group.d.ts +59 -0
  81. package/types/api/open-api/invoice.d.ts +87 -0
  82. package/types/api/open-api/license-plate.d.ts +27 -0
  83. package/types/api/open-api/login.d.ts +115 -0
  84. package/types/api/open-api/my-miniprogram.d.ts +28 -0
  85. package/types/api/open-api/privacy.d.ts +107 -0
  86. package/types/api/open-api/redpackage.d.ts +24 -0
  87. package/types/api/open-api/settings.d.ts +174 -0
  88. package/types/api/open-api/soter.d.ts +184 -0
  89. package/types/api/open-api/sticker.d.ts +83 -0
  90. package/types/api/open-api/subscribe-message.d.ts +305 -0
  91. package/types/api/open-api/user-info.d.ts +182 -0
  92. package/types/api/open-api/werun.d.ts +101 -0
  93. package/types/api/payment/index.d.ts +119 -0
  94. package/types/api/qq/index.d.ts +354 -0
  95. package/types/api/route/index.d.ts +324 -0
  96. package/types/api/share/index.d.ts +354 -0
  97. package/types/api/skyline/index.d.ts +345 -0
  98. package/types/api/storage/background-fetch.d.ts +131 -0
  99. package/types/api/storage/cache-manager.d.ts +249 -0
  100. package/types/api/storage/index.d.ts +405 -0
  101. package/types/api/swan/bookshelf.d.ts +307 -0
  102. package/types/api/swan/download-package.d.ts +80 -0
  103. package/types/api/swan/index.d.ts +251 -0
  104. package/types/api/swan/pay.d.ts +139 -0
  105. package/types/api/taro.extend.d.ts +233 -0
  106. package/types/api/taro.hooks.d.ts +148 -0
  107. package/types/api/ui/animation.d.ts +427 -0
  108. package/types/api/ui/background.d.ts +69 -0
  109. package/types/api/ui/custom-component.d.ts +23 -0
  110. package/types/api/ui/fonts.d.ts +77 -0
  111. package/types/api/ui/interaction.d.ts +281 -0
  112. package/types/api/ui/menu.d.ts +29 -0
  113. package/types/api/ui/navigation-bar.d.ts +130 -0
  114. package/types/api/ui/pull-down-refresh.d.ts +50 -0
  115. package/types/api/ui/scroll.d.ts +114 -0
  116. package/types/api/ui/sticky.d.ts +32 -0
  117. package/types/api/ui/tab-bar.d.ts +196 -0
  118. package/types/api/ui/window.d.ts +71 -0
  119. package/types/api/worker/index.d.ts +83 -0
  120. package/types/api/wxml/index.d.ts +540 -0
  121. package/types/compile/compiler.d.ts +32 -0
  122. package/types/compile/config/h5.d.ts +134 -0
  123. package/types/compile/config/harmony.d.ts +118 -0
  124. package/types/compile/config/index.d.ts +8 -0
  125. package/types/compile/config/manifest.d.ts +155 -0
  126. package/types/compile/config/mini.d.ts +118 -0
  127. package/types/compile/config/plugin.d.ts +34 -0
  128. package/types/compile/config/project.d.ts +338 -0
  129. package/types/compile/config/rn.d.ts +85 -0
  130. package/types/compile/config/util.d.ts +179 -0
  131. package/types/compile/hooks.d.ts +13 -0
  132. package/types/compile/index.d.ts +11 -0
  133. package/types/compile/viteCompilerContext.d.ts +167 -0
  134. package/types/global.d.ts +428 -0
  135. package/types/index.d.ts +190 -0
  136. package/types/taro.api.d.ts +130 -0
  137. package/types/taro.component.d.ts +168 -0
  138. package/types/taro.config.d.ts +712 -0
  139. package/types/taro.lifecycle.d.ts +220 -0
  140. package/types/taro.runtime.d.ts +9 -0
@@ -0,0 +1,291 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ namespace stopBackgroundAudio {
5
+ interface Option {
6
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
7
+ complete?: (res: TaroGeneral.CallbackResult) => void
8
+ /** 接口调用失败的回调函数 */
9
+ fail?: (res: TaroGeneral.CallbackResult) => void
10
+ /** 接口调用成功的回调函数 */
11
+ success?: (res: TaroGeneral.CallbackResult) => void
12
+ }
13
+ }
14
+
15
+ namespace seekBackgroundAudio {
16
+ interface Option {
17
+ /** 音乐位置,单位:秒 */
18
+ position: number
19
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
20
+ complete?: (res: TaroGeneral.CallbackResult) => void
21
+ /** 接口调用失败的回调函数 */
22
+ fail?: (res: TaroGeneral.CallbackResult) => void
23
+ /** 接口调用成功的回调函数 */
24
+ success?: (res: TaroGeneral.CallbackResult) => void
25
+ }
26
+ }
27
+
28
+ namespace playBackgroundAudio {
29
+ interface Option {
30
+ /** 音乐链接,目前支持的格式有 m4a, aac, mp3, wav */
31
+ dataUrl: string
32
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
33
+ complete?: (res: TaroGeneral.CallbackResult) => void
34
+ /** 封面URL */
35
+ coverImgUrl?: string
36
+ /** 接口调用失败的回调函数 */
37
+ fail?: (res: TaroGeneral.CallbackResult) => void
38
+ /** 接口调用成功的回调函数 */
39
+ success?: (res: TaroGeneral.CallbackResult) => void
40
+ /** 音乐标题 */
41
+ title?: string
42
+ }
43
+ }
44
+
45
+ namespace pauseBackgroundAudio {
46
+ interface Option {
47
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
48
+ complete?: (res: TaroGeneral.CallbackResult) => void
49
+ /** 接口调用失败的回调函数 */
50
+ fail?: (res: TaroGeneral.CallbackResult) => void
51
+ /** 接口调用成功的回调函数 */
52
+ success?: (res: TaroGeneral.CallbackResult) => void
53
+ }
54
+ }
55
+
56
+ namespace getBackgroundAudioPlayerState {
57
+ interface Option {
58
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
59
+ complete?: (res: TaroGeneral.CallbackResult) => void
60
+ /** 接口调用失败的回调函数 */
61
+ fail?: (res: TaroGeneral.CallbackResult) => void
62
+ /** 接口调用成功的回调函数 */
63
+ success?: (result: SuccessCallbackResult) => void
64
+ }
65
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
66
+ /** 选定音频的播放位置(单位:s),只有在音乐播放中时返回 */
67
+ currentPosition: number
68
+ /** 歌曲数据链接,只有在音乐播放中时返回 */
69
+ dataUrl: string
70
+ /** 音频的下载进度百分比,只有在音乐播放中时返回 */
71
+ downloadPercent: number
72
+ /** 选定音频的长度(单位:s),只有在音乐播放中时返回 */
73
+ duration: number
74
+ /** 播放状态 */
75
+ status: keyof Status
76
+ /** 调用结果 */
77
+ errMsg: string
78
+ }
79
+ interface Status {
80
+ /** 暂停中 */
81
+ 0
82
+ /** 播放中 */
83
+ 1
84
+ /** 没有音乐播放 */
85
+ 2
86
+ }
87
+ }
88
+
89
+ /** BackgroundAudioManager 实例,可通过 [Taro.getBackgroundAudioManager](/docs/apis/media/background-audio/getBackgroundAudioManager) 获取。
90
+ * @example
91
+ * ```tsx
92
+ * const backgroundAudioManager = Taro.getBackgroundAudioManager()
93
+ * backgroundAudioManager.title = '此时此刻'
94
+ * backgroundAudioManager.epname = '此时此刻'
95
+ * backgroundAudioManager.singer = '许巍'
96
+ * backgroundAudioManager.coverImgUrl = 'https://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'
97
+ * // 设置了 src 之后会自动播放
98
+ * backgroundAudioManager.src = 'https://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
99
+ * ```
100
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.html
101
+ */
102
+ interface BackgroundAudioManager {
103
+ /** 音频的数据源([2.2.3](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) 开始支持云文件ID)。默认为空字符串,**当设置了新的 src 时,会自动开始播放**,目前支持的格式有 m4a, aac, mp3, wav。 */
104
+ src: string
105
+ /** 音频开始播放的位置(单位:s)。 */
106
+ startTime: number
107
+ /** 音频标题,用于原生音频播放器音频标题(必填)。原生音频播放器中的分享功能,分享出去的卡片标题,也将使用该值。 */
108
+ title: string
109
+ /** 专辑名,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值。 */
110
+ epname: string
111
+ /** 歌手名,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值。 */
112
+ singer: string
113
+ /** 封面图 URL,用于做原生音频播放器背景图。原生音频播放器中的分享功能,分享出去的卡片配图及背景也将使用该图。 */
114
+ coverImgUrl: string
115
+ /** 页面链接,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值。 */
116
+ webUrl: string
117
+ /** 音频协议。默认值为 'http',设置 'hls' 可以支持播放 HLS 协议的直播音频。 */
118
+ protocol: string
119
+ /** 播放速度。范围 0.5-2.0。
120
+ * @default 1
121
+ */
122
+ playbackRate?: number
123
+ /** 当前音频的长度(单位:s),只有在有合法 src 时返回。
124
+ * @readonly
125
+ */
126
+ duration: number
127
+ /** 当前音频的播放位置(单位:s),只有在有合法 src 时返回。
128
+ * @readonly
129
+ */
130
+ currentTime: number
131
+ /** 当前是否暂停或停止。
132
+ * @readonly
133
+ */
134
+ paused: boolean
135
+ /** 音频已缓冲的时间,仅保证当前播放时间点到此时间点内容已缓冲。
136
+ * @readonly
137
+ */
138
+ buffered: number
139
+ /** origin: 发送完整的 referrer; no-referrer: 不发送 */
140
+ referrerPolicy?: 'origin' | 'no-referrer' | string
141
+ /** 播放 */
142
+ play(): void
143
+ /** 暂停 */
144
+ pause(): void
145
+ /** 跳转到指定位置,单位 s */
146
+ seek(position: any): void
147
+ /** 停止 */
148
+ stop(): void
149
+ /** 背景音频进入可以播放状态,但不保证后面可以流畅播放 */
150
+ onCanplay(callback?: () => void): void
151
+ /** 音频加载中事件,当音频因为数据不足,需要停下来加载时会触发 */
152
+ onWaiting(callback?: () => void): void
153
+ /** 背景音频播放错误事件 */
154
+ onError(callback?: () => void): void
155
+ /** 背景音频播放事件 */
156
+ onPlay(callback?: () => void): void
157
+ /** 背景音频暂停事件 */
158
+ onPause(callback?: () => void): void
159
+ /** 背景音频开始跳转操作事件 */
160
+ onSeeking(callback?: () => void): void
161
+ /** 背景音频完成跳转操作事件 */
162
+ onSeeked(callback?: () => void): void
163
+ /** 背景音频自然播放结束事件 */
164
+ onEnded(callback?: () => void): void
165
+ /** 背景音频停止事件 */
166
+ onStop(callback?: () => void): void
167
+ /** 背景音频播放进度更新事件 */
168
+ onTimeUpdate(callback?: () => void): void
169
+ /** 用户在系统音乐播放面板点击上一曲事件(iOS only) */
170
+ onPrev(callback?: () => void): void
171
+ /** 用户在系统音乐播放面板点击下一曲事件(iOS only) */
172
+ onNext(callback?: () => void): void
173
+ }
174
+
175
+ interface TaroStatic {
176
+ /**
177
+ * 停止播放音乐。
178
+ * @supported weapp
179
+ * @example
180
+ * ```tsx
181
+ * Taro.stopBackgroundAudio()
182
+ * ```
183
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.stopBackgroundAudio.html
184
+ */
185
+ stopBackgroundAudio(option?: stopBackgroundAudio.Option): void
186
+
187
+ /** 控制音乐播放进度。
188
+ * @supported weapp
189
+ * @example
190
+ * ```tsx
191
+ * Taro.seekBackgroundAudio({
192
+ * position: 30
193
+ * })
194
+ * ```
195
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.seekBackgroundAudio.html
196
+ */
197
+ seekBackgroundAudio(option: seekBackgroundAudio.Option): Promise<TaroGeneral.CallbackResult>
198
+
199
+ /** 使用后台播放器播放音乐,对于微信客户端来说,只能同时有一个后台音乐在播放。当用户离开小程序后,音乐将暂停播放;当用户点击“显示在聊天顶部”时,音乐不会暂停播放;当用户在其他小程序占用了音乐播放器,原有小程序内的音乐将停止播放。
200
+ * @supported weapp
201
+ * @example
202
+ * ```tsx
203
+ * Taro.playBackgroundAudio({
204
+ * dataUrl: '',
205
+ * title: '',
206
+ * coverImgUrl: ''
207
+ * })
208
+ * ```
209
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.playBackgroundAudio.html
210
+ */
211
+ playBackgroundAudio(option: playBackgroundAudio.Option): Promise<TaroGeneral.CallbackResult>
212
+
213
+ /** 暂停播放音乐。
214
+ * @supported weapp
215
+ * @example
216
+ * ```tsx
217
+ * Taro.pauseBackgroundAudio()
218
+ * ```
219
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.pauseBackgroundAudio.html
220
+ */
221
+ pauseBackgroundAudio(option?: pauseBackgroundAudio.Option): void
222
+
223
+ /** 监听音乐停止。
224
+ *
225
+ * **bug & tip:**
226
+ *
227
+ * 1. `bug`: `iOS` `6.3.30` Taro.seekBackgroundAudio 会有短暂延迟
228
+ * @supported weapp
229
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.onBackgroundAudioStop.html
230
+ */
231
+ onBackgroundAudioStop(
232
+ /** 音乐停止事件的回调函数 */
233
+ callback: (res: TaroGeneral.CallbackResult) => void,
234
+ ): void
235
+
236
+ /** 监听音乐播放。
237
+ * @supported weapp
238
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.onBackgroundAudioPlay.html
239
+ */
240
+ onBackgroundAudioPlay(
241
+ /** 音乐播放事件的回调函数 */
242
+ callback: (res: TaroGeneral.CallbackResult) => void,
243
+ ): void
244
+
245
+ /** 监听音乐暂停。
246
+ * @supported weapp
247
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.onBackgroundAudioPause.html
248
+ */
249
+ onBackgroundAudioPause(
250
+ /** 音乐暂停事件的回调函数 */
251
+ callback: (res: TaroGeneral.CallbackResult) => void,
252
+ ): void
253
+
254
+ /** 获取后台音乐播放状态。
255
+ * **注意:1.2.0 版本开始,本接口不再维护。建议使用能力更强的 [Taro.getBackgroundAudioManager](/docs/apis/media/background-audio/getBackgroundAudioManager) 接口**
256
+ * @supported weapp
257
+ * @example
258
+ * ```tsx
259
+ * Taro.getBackgroundAudioPlayerState({
260
+ * success: function (res) {
261
+ * var status = res.status
262
+ * var dataUrl = res.dataUrl
263
+ * var currentPosition = res.currentPosition
264
+ * var duration = res.duration
265
+ * var downloadPercent = res.downloadPercent
266
+ * }
267
+ * })
268
+ * ```
269
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.getBackgroundAudioPlayerState.html
270
+ */
271
+ getBackgroundAudioPlayerState(option?: getBackgroundAudioPlayerState.Option): Promise<getBackgroundAudioPlayerState.SuccessCallbackResult>
272
+
273
+ /** 获取**全局唯一**的背景音频管理器。
274
+ * 小程序切入后台,如果音频处于播放状态,可以继续播放。但是后台状态不能通过调用API操纵音频的播放状态。
275
+ *
276
+ * 从微信客户端6.7.2版本开始,若需要在小程序切后台后继续播放音频,需要在 [app.json](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html) 中配置 `requiredBackgroundModes` 属性。开发版和体验版上可以直接生效,正式版还需通过审核。
277
+ * @supported weapp, tt, harmony_hybrid
278
+ * @example
279
+ * ```tsx
280
+ * const backgroundAudioManager = Taro.getBackgroundAudioManager()
281
+ * backgroundAudioManager.title = '此时此刻'
282
+ * backgroundAudioManager.epname = '此时此刻'
283
+ * backgroundAudioManager.singer = '许巍'
284
+ * backgroundAudioManager.coverImgUrl = 'https://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'
285
+ * backgroundAudioManager.src = 'https://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46' // 设置了 src 之后会自动播放
286
+ * ```
287
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.getBackgroundAudioManager.html
288
+ */
289
+ getBackgroundAudioManager(): BackgroundAudioManager
290
+ }
291
+ }
@@ -0,0 +1,207 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ /**
5
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/CameraContext.html
6
+ */
7
+ interface CameraContext {
8
+ /** 获取 Camera 实时帧数据
9
+ *
10
+ * ****
11
+ *
12
+ * 注: 使用该接口需同时在 [camera](/docs/components/media/camera) 组件属性中指定 frame-size。
13
+ * @supported weapp, tt, alipay
14
+ * @example
15
+ * ```tsx
16
+ * const context = wx.createCameraContext()
17
+ * const listener = context.onCameraFrame((frame) => {
18
+ * console.log(frame.data instanceof ArrayBuffer, frame.width, frame.height)
19
+ * })
20
+ * listener.start()
21
+ * ```
22
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/CameraContext.onCameraFrame.html
23
+ */
24
+ onCameraFrame(
25
+ /** 回调函数 */
26
+ callback: CameraContext.OnCameraFrameCallback,
27
+ ): CameraFrameListener
28
+ /** 设置缩放级别
29
+ * @supported weapp, tt, alipay
30
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/CameraContext.setZoom.html
31
+ */
32
+ setZoom(option: CameraContext.SetZoomOption): void
33
+ /** 开始录像
34
+ * @supported weapp, rn, tt, alipay
35
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/CameraContext.startRecord.html
36
+ */
37
+ startRecord(option: CameraContext.StartRecordOption): void
38
+ /** 结束录像
39
+ * @supported weapp, rn, tt, alipay
40
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/CameraContext.stopRecord.html
41
+ */
42
+ stopRecord(option?: CameraContext.StopRecordOption): void
43
+ /** 拍摄照片
44
+ * @supported weapp, rn, tt, alipay
45
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/CameraContext.takePhoto.html
46
+ */
47
+ takePhoto(option: CameraContext.TakePhotoOption): void
48
+ }
49
+
50
+ namespace CameraContext {
51
+ interface SetZoomOption {
52
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
53
+ complete?: (res: TaroGeneral.CallbackResult) => void
54
+ /** 接口调用失败的回调函数 */
55
+ fail?: (res: TaroGeneral.CallbackResult) => void
56
+ /** 接口调用成功的回调函数 */
57
+ success?: (res: StartRecordSuccessCallbackResult) => void
58
+ /** 缩放级别,范围[1, maxZoom]。zoom 可取小数,精确到小数后一位。maxZoom 可在 bindinitdone 返回值中获取。 */
59
+ zoom: number
60
+ }
61
+ interface StartRecordSuccessCallbackResult extends TaroGeneral.CallbackResult {
62
+ /** 实际设置的缩放级别。由于系统限制,某些机型可能无法设置成指定值,会改用最接近的可设值。 */
63
+ zoom: number
64
+ /**
65
+ * @supported alipay
66
+ * @alipay on android
67
+ */
68
+ setZoom:number
69
+ }
70
+ interface StartRecordOption {
71
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
72
+ complete?: (res: TaroGeneral.CallbackResult) => void
73
+ /** 接口调用失败的回调函数 */
74
+ fail?: (res: TaroGeneral.CallbackResult) => void
75
+ /** 接口调用成功的回调函数 */
76
+ success?: (res: TaroGeneral.CallbackResult) => void
77
+ /** 超过30s或页面 `onHide` 时会结束录像 */
78
+ timeoutCallback?: StartRecordTimeoutCallback
79
+ }
80
+ /** 超过30s或页面 `onHide` 时会结束录像 */
81
+ type StartRecordTimeoutCallback = (
82
+ result: StartRecordTimeoutCallbackResult,
83
+ ) => void
84
+ interface StartRecordTimeoutCallbackResult {
85
+ /** 封面图片文件的临时路径 */
86
+ tempThumbPath: string
87
+ /** 视频的文件的临时路径 */
88
+ tempVideoPath: string
89
+ /** 视频文件的高度。
90
+ * @supported alipay
91
+ */
92
+ height: string
93
+ /** 视频文件的宽度。
94
+ * @supported alipay
95
+ */
96
+ width: string
97
+ /** 视频文件的尺寸。
98
+ * @supported alipay
99
+ */
100
+ size: string
101
+ /** 录制的持续时间。
102
+ * @supported alipay
103
+ */
104
+ duration: string
105
+ }
106
+ interface StopRecordOption {
107
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
108
+ complete?: (res: TaroGeneral.CallbackResult) => void
109
+ /** 接口调用失败的回调函数 */
110
+ fail?: (res: TaroGeneral.CallbackResult) => void
111
+ /** 接口调用成功的回调函数 */
112
+ success?: (result: StopRecordSuccessCallbackResult) => void
113
+ }
114
+ interface StopRecordSuccessCallbackResult extends TaroGeneral.CallbackResult {
115
+ /** 封面图片文件的临时路径 */
116
+ tempThumbPath: string
117
+ /** 视频的文件的临时路径 */
118
+ tempVideoPath: string
119
+ /** 调用结果 */
120
+ errMsg: string
121
+ }
122
+ interface TakePhotoOption {
123
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
124
+ complete?: (res: TaroGeneral.CallbackResult) => void
125
+ /** 接口调用失败的回调函数 */
126
+ fail?: (res: TaroGeneral.CallbackResult) => void
127
+ /** 成像质量 */
128
+ quality?: keyof Quality
129
+ /** 接口调用成功的回调函数 */
130
+ success?: (result: TakePhotoSuccessCallbackResult) => void
131
+ }
132
+ interface TakePhotoSuccessCallbackResult extends TaroGeneral.CallbackResult {
133
+ /** 照片文件的临时路径,安卓是jpg图片格式,ios是png */
134
+ tempImagePath: string
135
+ /** 调用结果 */
136
+ errMsg: string
137
+ }
138
+ /** 回调函数 */
139
+ type OnCameraFrameCallback = (result: OnCameraFrameCallbackResult) => void
140
+ interface OnCameraFrameCallbackResult {
141
+ /** 图像像素点数据,一维数组,每四项表示一个像素点的 rgba */
142
+ data: ArrayBuffer
143
+ /** 图像数据矩形的高度 */
144
+ height: number
145
+ /** 图像数据矩形的宽度 */
146
+ width: number
147
+ }
148
+ interface Quality {
149
+ /** 高质量 */
150
+ high
151
+ /** 普通质量 */
152
+ normal
153
+ /** 低质量 */
154
+ low
155
+ /** 原图 */
156
+ original
157
+ }
158
+ }
159
+
160
+ /** CameraContext.onCameraFrame() 返回的监听器。
161
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/CameraFrameListener.html
162
+ */
163
+ interface CameraFrameListener {
164
+ /** 开始监听帧数据
165
+ * @supported weapp, tt
166
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/CameraFrameListener.start.html
167
+ */
168
+ start(option?: CameraFrameListener.StartOption): void
169
+ /** 停止监听帧数据
170
+ * @supported weapp, tt
171
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/CameraFrameListener.stop.html
172
+ */
173
+ stop(option?: CameraFrameListener.StopOption): void
174
+ }
175
+
176
+ namespace CameraFrameListener {
177
+ interface StartOption {
178
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
179
+ complete?: (res: TaroGeneral.CallbackResult) => void
180
+ /** 接口调用失败的回调函数 */
181
+ fail?: (res: TaroGeneral.CallbackResult) => void
182
+ /** 接口调用成功的回调函数 */
183
+ success?: (res: TaroGeneral.CallbackResult) => void
184
+ }
185
+ interface StopOption {
186
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
187
+ complete?: (res: TaroGeneral.CallbackResult) => void
188
+ /** 接口调用失败的回调函数 */
189
+ fail?: (res: TaroGeneral.CallbackResult) => void
190
+ /** 接口调用成功的回调函数 */
191
+ success?: (res: TaroGeneral.CallbackResult) => void
192
+ }
193
+ }
194
+
195
+ interface TaroStatic {
196
+ /** 创建 camera 上下文 CameraContext 对象。
197
+ * @alipay 支付宝小程序需指定 camera 组件中的 id 属性
198
+ * @supported weapp, rn, tt, alipay
199
+ * @example
200
+ * ```tsx
201
+ * const cameraContext = Taro.createCameraContext()
202
+ * ```
203
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/wx.createCameraContext.html
204
+ */
205
+ createCameraContext(id?: string): CameraContext
206
+ }
207
+ }