@tarojs/taro 3.8.0-canary.0 → 4.0.0-alpha.2
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/html.css +9 -0
- package/package.json +16 -4
- package/types/api/ad/index.d.ts +6 -18
- package/types/api/ai/inference.d.ts +4 -8
- package/types/api/ai/visionkit.d.ts +625 -54
- package/types/api/base/debug.d.ts +8 -8
- package/types/api/base/env.d.ts +1 -1
- package/types/api/base/index.d.ts +3 -3
- package/types/api/base/performance.d.ts +5 -5
- package/types/api/base/system.d.ts +6 -6
- package/types/api/base/weapp/app-event.d.ts +10 -10
- package/types/api/base/weapp/life-cycle.d.ts +1 -1
- package/types/api/canvas/index.d.ts +389 -72
- package/types/api/data-analysis/index.d.ts +51 -1
- package/types/api/device/accelerometer.d.ts +8 -6
- package/types/api/device/accessibility.d.ts +1 -1
- package/types/api/device/battery.d.ts +3 -3
- package/types/api/device/bluetooth-ble.d.ts +40 -17
- package/types/api/device/bluetooth-peripheral.d.ts +26 -26
- package/types/api/device/bluetooth.d.ts +37 -13
- package/types/api/device/calendar.d.ts +11 -1
- package/types/api/device/clipboard.d.ts +17 -17
- package/types/api/device/compass.d.ts +5 -5
- package/types/api/device/gyroscope.d.ts +4 -4
- package/types/api/device/iBeacon.d.ts +10 -8
- package/types/api/device/keyboard.d.ts +7 -5
- package/types/api/device/memory.d.ts +3 -4
- package/types/api/device/motion.d.ts +8 -6
- package/types/api/device/network.d.ts +12 -6
- package/types/api/device/nfc.d.ts +13 -13
- package/types/api/device/phone.d.ts +1 -1
- package/types/api/device/scan.d.ts +5 -3
- package/types/api/device/screen.d.ts +28 -12
- package/types/api/device/sms.d.ts +1 -1
- package/types/api/device/vibrate.d.ts +5 -5
- package/types/api/device/wifi.d.ts +25 -13
- package/types/api/files/index.d.ts +73 -43
- package/types/api/framework/index.d.ts +2 -2
- package/types/api/location/index.d.ts +167 -19
- package/types/api/media/audio.d.ts +71 -42
- package/types/api/media/background-audio.d.ts +1 -1
- package/types/api/media/camera.d.ts +6 -3
- package/types/api/media/image.d.ts +5 -5
- package/types/api/media/video.d.ts +11 -11
- package/types/api/navigate/index.d.ts +3 -1
- package/types/api/network/download.d.ts +7 -15
- package/types/api/network/request.d.ts +7 -7
- package/types/api/network/upload.d.ts +9 -17
- package/types/api/network/websocket.d.ts +8 -8
- package/types/api/open-api/account.d.ts +1 -1
- package/types/api/open-api/address.d.ts +13 -5
- package/types/api/open-api/authorize.d.ts +1 -1
- package/types/api/open-api/channels.d.ts +16 -0
- package/types/api/open-api/device-voip.d.ts +42 -2
- package/types/api/open-api/invoice.d.ts +1 -1
- package/types/api/open-api/login.d.ts +16 -3
- package/types/api/open-api/my-miniprogram.d.ts +2 -2
- package/types/api/open-api/privacy.d.ts +107 -0
- package/types/api/open-api/settings.d.ts +3 -2
- package/types/api/open-api/sticker.d.ts +83 -0
- package/types/api/open-api/subscribe-message.d.ts +148 -6
- package/types/api/open-api/user-info.d.ts +6 -1
- package/types/api/qq/index.d.ts +306 -1
- package/types/api/route/index.d.ts +8 -5
- package/types/api/skyline/index.d.ts +59 -0
- package/types/api/storage/background-fetch.d.ts +63 -11
- package/types/api/storage/cache-manager.d.ts +61 -10
- package/types/api/storage/index.d.ts +125 -10
- package/types/api/swan/bookshelf.d.ts +307 -0
- package/types/api/swan/download-package.d.ts +80 -0
- package/types/api/swan/index.d.ts +151 -0
- package/types/api/swan/pay.d.ts +139 -0
- package/types/api/taro.extend.d.ts +15 -6
- package/types/api/taro.hooks.d.ts +9 -9
- package/types/api/ui/animation.d.ts +32 -32
- package/types/api/ui/custom-component.d.ts +1 -1
- package/types/api/ui/fonts.d.ts +4 -3
- package/types/api/ui/interaction.d.ts +6 -6
- package/types/api/ui/menu.d.ts +1 -1
- package/types/api/ui/navigation-bar.d.ts +5 -5
- package/types/api/ui/pull-down-refresh.d.ts +2 -2
- package/types/api/ui/scroll.d.ts +1 -1
- package/types/api/ui/tab-bar.d.ts +8 -8
- package/types/api/ui/window.d.ts +2 -2
- package/types/api/wxml/index.d.ts +19 -19
- package/types/compile/compiler.d.ts +9 -4
- package/types/compile/config/h5.d.ts +23 -10
- package/types/compile/config/harmony.d.ts +82 -0
- package/types/compile/config/index.d.ts +1 -0
- package/types/compile/config/mini.d.ts +58 -30
- package/types/compile/config/plugin.d.ts +34 -0
- package/types/compile/config/project.d.ts +26 -13
- package/types/compile/config/util.d.ts +22 -8
- package/types/compile/viteCompilerContext.d.ts +155 -0
- package/types/global.d.ts +3 -1
- package/types/index.d.ts +92 -44
- package/types/taro.api.d.ts +24 -13
- package/types/taro.component.d.ts +2 -1
- package/types/taro.config.d.ts +47 -6
- package/types/taro.lifecycle.d.ts +3 -0
- package/types/taro.runtime.d.ts +9 -0
|
@@ -35,6 +35,10 @@ declare module '../../index' {
|
|
|
35
35
|
interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
|
|
36
36
|
/** 生成文件的临时路径 */
|
|
37
37
|
tempFilePath: string
|
|
38
|
+
/** 图片路径(本地临时文件)。
|
|
39
|
+
* @supported alipay
|
|
40
|
+
*/
|
|
41
|
+
apFilePath?: string
|
|
38
42
|
/** 调用结果 */
|
|
39
43
|
errMsg: string
|
|
40
44
|
}
|
|
@@ -137,7 +141,46 @@ declare module '../../index' {
|
|
|
137
141
|
/** 画布宽度 */
|
|
138
142
|
width?: number
|
|
139
143
|
/** 在自定义组件下,当前组件实例的 this,以操作组件内 [canvas](/docs/components/canvas) 组件 */
|
|
140
|
-
|
|
144
|
+
compInst?: TaroGeneral.IAnyObject,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
namespace toTempFilePath {
|
|
149
|
+
interface Option {
|
|
150
|
+
/** 指定的画布区域的左上角横坐标 */
|
|
151
|
+
x?: number
|
|
152
|
+
/** 指定的画布区域的左上角纵坐标 */
|
|
153
|
+
y?: number
|
|
154
|
+
/** 指定的画布区域的宽度 */
|
|
155
|
+
width?: number
|
|
156
|
+
/** 指定的画布区域的高度 */
|
|
157
|
+
height?: number
|
|
158
|
+
/** 输出的图片的高度 */
|
|
159
|
+
destHeight?: number
|
|
160
|
+
/** 输出的图片的宽度 */
|
|
161
|
+
destWidth?: number
|
|
162
|
+
/** 目标文件的类型
|
|
163
|
+
* @default "png"
|
|
164
|
+
*/
|
|
165
|
+
fileType?: keyof FileType
|
|
166
|
+
/** 图片的质量,目前仅对 jpg 有效。取值范围为 (0, 1],不在范围内时当作 1.0 处理。 */
|
|
167
|
+
quality?: number
|
|
168
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
169
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
170
|
+
/** 接口调用失败的回调函数 */
|
|
171
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
172
|
+
/** 接口调用成功的回调函数 */
|
|
173
|
+
success?: (result: SuccessCallbackResult) => void
|
|
174
|
+
}
|
|
175
|
+
interface FileType {
|
|
176
|
+
/** jpg 图片 */
|
|
177
|
+
jpg
|
|
178
|
+
/** png 图片 */
|
|
179
|
+
png
|
|
180
|
+
}
|
|
181
|
+
interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
|
|
182
|
+
/** 生成文件的临时路径 */
|
|
183
|
+
tempFilePath: string
|
|
141
184
|
}
|
|
142
185
|
}
|
|
143
186
|
|
|
@@ -150,7 +193,7 @@ declare module '../../index' {
|
|
|
150
193
|
/** 画布宽度 */
|
|
151
194
|
width: number
|
|
152
195
|
/** 取消由 requestAnimationFrame 添加到计划中的动画帧请求。支持在 2D Canvas 和 WebGL Canvas 下使用, 但不支持混用 2D 和 WebGL 的方法。
|
|
153
|
-
* @supported weapp
|
|
196
|
+
* @supported weapp, alipay, tt
|
|
154
197
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/Canvas.cancelAnimationFrame.html
|
|
155
198
|
*/
|
|
156
199
|
cancelAnimationFrame(requestID: number): void
|
|
@@ -160,7 +203,7 @@ declare module '../../index' {
|
|
|
160
203
|
*/
|
|
161
204
|
createImageData(): ImageData
|
|
162
205
|
/** 创建一个图片对象。 支持在 2D Canvas 和 WebGL Canvas 下使用, 但不支持混用 2D 和 WebGL 的方法。
|
|
163
|
-
* @supported weapp
|
|
206
|
+
* @supported weapp, alipay, tt
|
|
164
207
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/Canvas.createImage.html
|
|
165
208
|
*/
|
|
166
209
|
createImage(): Image
|
|
@@ -172,7 +215,7 @@ declare module '../../index' {
|
|
|
172
215
|
path: Path2D
|
|
173
216
|
): Path2D
|
|
174
217
|
/** 支持获取 2D 和 WebGL 绘图上下文
|
|
175
|
-
* @supported weapp
|
|
218
|
+
* @supported weapp, alipay, tt
|
|
176
219
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/Canvas.getContext.html
|
|
177
220
|
*/
|
|
178
221
|
getContext(contextType: string): RenderingContext
|
|
@@ -194,6 +237,11 @@ declare module '../../index' {
|
|
|
194
237
|
/** 在指定图片格式为 image/jpeg 或 image/webp的情况下,可以从 0 到 1 的区间内选择图片的质量。如果超出取值范围,将会使用默认值 0.92。其他参数会被忽略。 */
|
|
195
238
|
encoderOptions: number
|
|
196
239
|
): string
|
|
240
|
+
/** 把当前画布指定区域保存为图片
|
|
241
|
+
* @supported alipay
|
|
242
|
+
* @see https://opendocs.alipay.com/mini/api/toTempFilePath?pathHash=e79fe218
|
|
243
|
+
*/
|
|
244
|
+
toTempFilePath(oprion: toTempFilePath.Option): void
|
|
197
245
|
}
|
|
198
246
|
|
|
199
247
|
/** canvas 组件的绘图上下文
|
|
@@ -242,7 +290,7 @@ declare module '../../index' {
|
|
|
242
290
|
* - 绿色: 圆心 (100, 75)
|
|
243
291
|
* - 红色: 起始弧度 (0)
|
|
244
292
|
* - 蓝色: 终止弧度 (1.5 * Math.PI)
|
|
245
|
-
* @supported weapp
|
|
293
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
246
294
|
* @example
|
|
247
295
|
* ```tsx
|
|
248
296
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -298,9 +346,13 @@ declare module '../../index' {
|
|
|
298
346
|
eAngle: number,
|
|
299
347
|
/** 弧度的方向是否是逆时针 */
|
|
300
348
|
counterclockwise?: boolean,
|
|
349
|
+
/** 弧度的方向是否是逆时针
|
|
350
|
+
* @supported tt
|
|
351
|
+
*/
|
|
352
|
+
anticlockwise?: boolean
|
|
301
353
|
): void
|
|
302
354
|
/** 根据控制点和半径绘制圆弧路径。
|
|
303
|
-
* @supported weapp
|
|
355
|
+
* @supported weapp, alipay, jd, qq, h5, harmony_hybrid
|
|
304
356
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.arcTo.html
|
|
305
357
|
*/
|
|
306
358
|
arcTo(
|
|
@@ -319,7 +371,7 @@ declare module '../../index' {
|
|
|
319
371
|
*
|
|
320
372
|
* - 在最开始的时候相当于调用了一次 `beginPath`。
|
|
321
373
|
* - 同一个路径内的多次 `setFillStyle`、`setStrokeStyle`、`setLineWidth`等设置,以最后一次设置为准。
|
|
322
|
-
* @supported weapp
|
|
374
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
323
375
|
* @example
|
|
324
376
|
* ```tsx
|
|
325
377
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -349,7 +401,7 @@ declare module '../../index' {
|
|
|
349
401
|
* - 红色:起始点(20, 20)
|
|
350
402
|
* - 蓝色:两个控制点(20, 100) (200, 100)
|
|
351
403
|
* - 绿色:终止点(200, 20)
|
|
352
|
-
* @supported weapp
|
|
404
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
353
405
|
* @example
|
|
354
406
|
* ```tsx
|
|
355
407
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -404,7 +456,7 @@ declare module '../../index' {
|
|
|
404
456
|
y: number,
|
|
405
457
|
): void
|
|
406
458
|
/** 清除画布上在该矩形区域内的内容
|
|
407
|
-
* @supported weapp
|
|
459
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
408
460
|
* @example
|
|
409
461
|
* clearRect 并非画一个白色的矩形在地址区域,而是清空,为了有直观感受,对 canvas 加了一层背景色。
|
|
410
462
|
* ```html
|
|
@@ -432,7 +484,7 @@ declare module '../../index' {
|
|
|
432
484
|
height: number,
|
|
433
485
|
): void
|
|
434
486
|
/** 从原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内(不能访问画布上的其他区域)。可以在使用 `clip` 方法前通过使用 `save` 方法对当前画布区域进行保存,并在以后的任意时间通过`restore`方法对其进行恢复。
|
|
435
|
-
* @supported weapp
|
|
487
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
436
488
|
* @example
|
|
437
489
|
* ```tsx
|
|
438
490
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -453,7 +505,7 @@ declare module '../../index' {
|
|
|
453
505
|
*/
|
|
454
506
|
clip(): void
|
|
455
507
|
/** 关闭一个路径。会连接起点和终点。如果关闭路径后没有调用 `fill` 或者 `stroke` 并开启了新的路径,那之前的路径将不会被渲染。
|
|
456
|
-
* @supported weapp
|
|
508
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
457
509
|
* @example
|
|
458
510
|
* ```tsx
|
|
459
511
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -486,7 +538,7 @@ declare module '../../index' {
|
|
|
486
538
|
*/
|
|
487
539
|
closePath(): void
|
|
488
540
|
/** 创建一个圆形的渐变颜色。起点在圆心,终点在圆环。返回的`CanvasGradient`对象需要使用 [CanvasGradient.addColorStop()](/docs/apis/canvas/CanvasGradient#addcolorstop) 来指定渐变点,至少要两个。
|
|
489
|
-
* @supported weapp
|
|
541
|
+
* @supported weapp, alipay, swan, jd, qq, h5, harmony_hybrid
|
|
490
542
|
* @example
|
|
491
543
|
* ```tsx
|
|
492
544
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -510,7 +562,7 @@ declare module '../../index' {
|
|
|
510
562
|
r: number,
|
|
511
563
|
): CanvasGradient
|
|
512
564
|
/** 创建一个线性的渐变颜色。返回的`CanvasGradient`对象需要使用 [CanvasGradient.addColorStop()](/docs/apis/canvas/CanvasGradient#addcolorstop) 来指定渐变点,至少要两个。
|
|
513
|
-
* @supported weapp
|
|
565
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
514
566
|
* @example
|
|
515
567
|
* ```tsx
|
|
516
568
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -536,7 +588,7 @@ declare module '../../index' {
|
|
|
536
588
|
y1: number,
|
|
537
589
|
): CanvasGradient
|
|
538
590
|
/** 对指定的图像创建模式的方法,可在指定的方向上重复元图像
|
|
539
|
-
* @supported weapp
|
|
591
|
+
* @supported weapp, alipay, jd, qq, h5, harmony_hybrid
|
|
540
592
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.createPattern.html
|
|
541
593
|
*/
|
|
542
594
|
createPattern(
|
|
@@ -544,9 +596,10 @@ declare module '../../index' {
|
|
|
544
596
|
image: string,
|
|
545
597
|
/** 如何重复图像 */
|
|
546
598
|
repetition: keyof CanvasContext.Repetition,
|
|
547
|
-
):
|
|
599
|
+
): CanvasPattern | null | Promise<CanvasPattern | null>
|
|
548
600
|
/** 将之前在绘图上下文中的描述(路径、变形、样式)画到 canvas 中。
|
|
549
|
-
* @supported weapp
|
|
601
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
602
|
+
* @h5 第二次调用 draw 前需要等待上一次 draw 调用结束后再调用,否则新的一次 draw 调用栈不会清空而导致结果异常。
|
|
550
603
|
* @example
|
|
551
604
|
* 第二次 draw() reserve 为 true。所以保留了上一次的绘制结果,在上下文设置的 fillStyle 'red' 也变成了默认的 'black'。
|
|
552
605
|
*
|
|
@@ -554,9 +607,10 @@ declare module '../../index' {
|
|
|
554
607
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
555
608
|
* ctx.setFillStyle('red')
|
|
556
609
|
* ctx.fillRect(10, 10, 150, 100)
|
|
557
|
-
* ctx.draw()
|
|
558
|
-
*
|
|
559
|
-
*
|
|
610
|
+
* ctx.draw(false, () => {
|
|
611
|
+
* ctx.fillRect(50, 50, 150, 100)
|
|
612
|
+
* ctx.draw(true)
|
|
613
|
+
* })
|
|
560
614
|
* ```
|
|
561
615
|
* @example
|
|
562
616
|
* 第二次 draw() reserve 为 false。所以没有保留了上一次的绘制结果和在上下文设置的 fillStyle 'red'。
|
|
@@ -565,9 +619,10 @@ declare module '../../index' {
|
|
|
565
619
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
566
620
|
* ctx.setFillStyle('red')
|
|
567
621
|
* ctx.fillRect(10, 10, 150, 100)
|
|
568
|
-
* ctx.draw()
|
|
569
|
-
*
|
|
570
|
-
*
|
|
622
|
+
* ctx.draw(false, () => {
|
|
623
|
+
* ctx.fillRect(50, 50, 150, 100)
|
|
624
|
+
* ctx.draw()
|
|
625
|
+
* })
|
|
571
626
|
* ```
|
|
572
627
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.draw.html
|
|
573
628
|
*/
|
|
@@ -576,9 +631,13 @@ declare module '../../index' {
|
|
|
576
631
|
reserve?: boolean,
|
|
577
632
|
/** 绘制完成后执行的回调函数 */
|
|
578
633
|
callback?: (...args: any[]) => any,
|
|
579
|
-
|
|
634
|
+
/** 是否使用硬件加速
|
|
635
|
+
* @supported jd
|
|
636
|
+
*/
|
|
637
|
+
useHardwareAccelerate?: boolean
|
|
638
|
+
): void | Promise<void>
|
|
580
639
|
/** 绘制图像到画布
|
|
581
|
-
* @supported weapp
|
|
640
|
+
* @supported weapp, h5, harmony_hybrid
|
|
582
641
|
* @example
|
|
583
642
|
* 有三个版本的写法:
|
|
584
643
|
*
|
|
@@ -606,7 +665,7 @@ declare module '../../index' {
|
|
|
606
665
|
dy: number,
|
|
607
666
|
): void
|
|
608
667
|
/** 绘制图像到画布
|
|
609
|
-
* @supported weapp
|
|
668
|
+
* @supported weapp, alipay, h5, harmony_hybrid
|
|
610
669
|
* @example
|
|
611
670
|
* 有三个版本的写法:
|
|
612
671
|
*
|
|
@@ -638,7 +697,7 @@ declare module '../../index' {
|
|
|
638
697
|
dHeight: number,
|
|
639
698
|
): void
|
|
640
699
|
/** 绘制图像到画布
|
|
641
|
-
* @supported weapp
|
|
700
|
+
* @supported weapp, swan, jd, qq, tt, h5, harmony_hybrid
|
|
642
701
|
* @example
|
|
643
702
|
* 有三个版本的写法:
|
|
644
703
|
*
|
|
@@ -678,7 +737,7 @@ declare module '../../index' {
|
|
|
678
737
|
dHeight: number,
|
|
679
738
|
): void
|
|
680
739
|
/** 对当前路径中的内容进行填充。默认的填充色为黑色。
|
|
681
|
-
* @supported weapp
|
|
740
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
682
741
|
* @example
|
|
683
742
|
* 如果当前路径没有闭合,fill() 方法会将起点和终点进行连接,然后填充。
|
|
684
743
|
*
|
|
@@ -715,7 +774,7 @@ declare module '../../index' {
|
|
|
715
774
|
*/
|
|
716
775
|
fill(): void
|
|
717
776
|
/** 填充一个矩形。用 [`setFillStyle`](/docs/apis/canvas/CanvasContext#setfillstyle) 设置矩形的填充色,如果没设置默认是黑色。
|
|
718
|
-
* @supported weapp
|
|
777
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
719
778
|
* @example
|
|
720
779
|
* ```tsx
|
|
721
780
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -736,7 +795,7 @@ declare module '../../index' {
|
|
|
736
795
|
height: number,
|
|
737
796
|
): void
|
|
738
797
|
/** 在画布上绘制被填充的文本
|
|
739
|
-
* @supported weapp
|
|
798
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
740
799
|
* @example
|
|
741
800
|
* ```tsx
|
|
742
801
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -758,7 +817,8 @@ declare module '../../index' {
|
|
|
758
817
|
maxWidth?: number,
|
|
759
818
|
): void
|
|
760
819
|
/** 增加一个新点,然后创建一条从上次指定点到目标点的线。用 `stroke` 方法来画线条
|
|
761
|
-
* @supported weapp
|
|
820
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
821
|
+
|
|
762
822
|
* @example
|
|
763
823
|
* ```tsx
|
|
764
824
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -776,8 +836,8 @@ declare module '../../index' {
|
|
|
776
836
|
/** 目标位置的 y 坐标 */
|
|
777
837
|
y: number,
|
|
778
838
|
): void
|
|
779
|
-
/**
|
|
780
|
-
* @supported weapp
|
|
839
|
+
/** 测量文本尺寸信息。目前仅返回文本宽度(width)。同步接口。
|
|
840
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
781
841
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.measureText.html
|
|
782
842
|
*/
|
|
783
843
|
measureText(
|
|
@@ -785,7 +845,7 @@ declare module '../../index' {
|
|
|
785
845
|
text: string,
|
|
786
846
|
): TextMetrics
|
|
787
847
|
/** 把路径移动到画布中的指定点,不创建线条。用 `stroke` 方法来画线条
|
|
788
|
-
* @supported weapp
|
|
848
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
789
849
|
* @example
|
|
790
850
|
* ```tsx
|
|
791
851
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -811,7 +871,7 @@ declare module '../../index' {
|
|
|
811
871
|
* - 红色:起始点(20, 20)
|
|
812
872
|
* - 蓝色:控制点(20, 100)
|
|
813
873
|
* - 绿色:终止点(200, 20)
|
|
814
|
-
* @supported weapp
|
|
874
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
815
875
|
* @example
|
|
816
876
|
* ```tsx
|
|
817
877
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -858,7 +918,7 @@ declare module '../../index' {
|
|
|
858
918
|
y: number,
|
|
859
919
|
): void
|
|
860
920
|
/** 创建一个矩形路径。需要用 [`fill`](/docs/apis/canvas/CanvasContext#fill) 或者 [`stroke`](/docs/apis/canvas/CanvasContext#stroke) 方法将矩形真正的画到 `canvas` 中
|
|
861
|
-
* @supported weapp
|
|
921
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
862
922
|
* @example
|
|
863
923
|
* ```tsx
|
|
864
924
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -879,8 +939,13 @@ declare module '../../index' {
|
|
|
879
939
|
/** 矩形路径的高度 */
|
|
880
940
|
height: number,
|
|
881
941
|
): void
|
|
942
|
+
/** 重置绘图上下文状态
|
|
943
|
+
* @supported h5, harmony_hybrid
|
|
944
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/reset
|
|
945
|
+
*/
|
|
946
|
+
reset(): void
|
|
882
947
|
/** 恢复之前保存的绘图上下文
|
|
883
|
-
* @supported weapp
|
|
948
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
884
949
|
* @example
|
|
885
950
|
* ```tsx
|
|
886
951
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -897,7 +962,7 @@ declare module '../../index' {
|
|
|
897
962
|
*/
|
|
898
963
|
restore(): void
|
|
899
964
|
/** 以原点为中心顺时针旋转当前坐标轴。多次调用旋转的角度会叠加。原点可以用 `translate` 方法修改。
|
|
900
|
-
* @supported weapp
|
|
965
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
901
966
|
* @example
|
|
902
967
|
* ```tsx
|
|
903
968
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -915,7 +980,7 @@ declare module '../../index' {
|
|
|
915
980
|
rotate: number,
|
|
916
981
|
): void
|
|
917
982
|
/** 保存绘图上下文。
|
|
918
|
-
* @supported weapp
|
|
983
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
919
984
|
* @example
|
|
920
985
|
* ```tsx
|
|
921
986
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -932,7 +997,7 @@ declare module '../../index' {
|
|
|
932
997
|
*/
|
|
933
998
|
save(): void
|
|
934
999
|
/** 在调用后,之后创建的路径其横纵坐标会被缩放。多次调用倍数会相乘。
|
|
935
|
-
* @supported weapp
|
|
1000
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
936
1001
|
* @example
|
|
937
1002
|
* ```tsx
|
|
938
1003
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -952,7 +1017,7 @@ declare module '../../index' {
|
|
|
952
1017
|
scaleHeight: number,
|
|
953
1018
|
): void
|
|
954
1019
|
/** 设置填充色。
|
|
955
|
-
* @supported weapp
|
|
1020
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
956
1021
|
* @example
|
|
957
1022
|
* ```tsx
|
|
958
1023
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -967,7 +1032,7 @@ declare module '../../index' {
|
|
|
967
1032
|
color: string | CanvasGradient,
|
|
968
1033
|
): void
|
|
969
1034
|
/** 设置字体的字号
|
|
970
|
-
* @supported weapp
|
|
1035
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
971
1036
|
* @example
|
|
972
1037
|
* ```tsx
|
|
973
1038
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -988,7 +1053,7 @@ declare module '../../index' {
|
|
|
988
1053
|
fontSize: number,
|
|
989
1054
|
): void
|
|
990
1055
|
/** 设置全局画笔透明度。
|
|
991
|
-
* @supported weapp
|
|
1056
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
992
1057
|
* @example
|
|
993
1058
|
* ```tsx
|
|
994
1059
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1008,7 +1073,7 @@ declare module '../../index' {
|
|
|
1008
1073
|
alpha: number,
|
|
1009
1074
|
): void
|
|
1010
1075
|
/** 设置线条的端点样式
|
|
1011
|
-
* @supported weapp
|
|
1076
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1012
1077
|
* @example
|
|
1013
1078
|
* ```tsx
|
|
1014
1079
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1043,7 +1108,7 @@ declare module '../../index' {
|
|
|
1043
1108
|
lineCap: keyof CanvasContext.LineCap,
|
|
1044
1109
|
): void
|
|
1045
1110
|
/** 设置虚线样式。
|
|
1046
|
-
* @supported weapp
|
|
1111
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1047
1112
|
* @example
|
|
1048
1113
|
* ```tsx
|
|
1049
1114
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1063,7 +1128,7 @@ declare module '../../index' {
|
|
|
1063
1128
|
offset: number,
|
|
1064
1129
|
): void
|
|
1065
1130
|
/** 设置线条的交点样式
|
|
1066
|
-
* @supported weapp
|
|
1131
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1067
1132
|
* @example
|
|
1068
1133
|
* ```tsx
|
|
1069
1134
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1102,7 +1167,7 @@ declare module '../../index' {
|
|
|
1102
1167
|
lineJoin: keyof CanvasContext.LineJoin,
|
|
1103
1168
|
): void
|
|
1104
1169
|
/** 设置线条的宽度
|
|
1105
|
-
* @supported weapp
|
|
1170
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1106
1171
|
* @example
|
|
1107
1172
|
* ```tsx
|
|
1108
1173
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1134,7 +1199,7 @@ declare module '../../index' {
|
|
|
1134
1199
|
lineWidth: number,
|
|
1135
1200
|
): void
|
|
1136
1201
|
/** 设置最大斜接长度。斜接长度指的是在两条线交汇处内角和外角之间的距离。当 [CanvasContext.setLineJoin()](/docs/apis/canvas/CanvasContext#setlinejoin) 为 miter 时才有效。超过最大倾斜长度的,连接处将以 lineJoin 为 bevel 来显示。
|
|
1137
|
-
* @supported weapp
|
|
1202
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1138
1203
|
* @example
|
|
1139
1204
|
* ```tsx
|
|
1140
1205
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1179,7 +1244,7 @@ declare module '../../index' {
|
|
|
1179
1244
|
miterLimit: number,
|
|
1180
1245
|
): void
|
|
1181
1246
|
/** 设定阴影样式。
|
|
1182
|
-
* @supported weapp
|
|
1247
|
+
* @supported weapp, alipay, swan, jd, qq, h5, harmony_hybrid
|
|
1183
1248
|
* @example
|
|
1184
1249
|
* ```tsx
|
|
1185
1250
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1201,7 +1266,7 @@ declare module '../../index' {
|
|
|
1201
1266
|
color: string,
|
|
1202
1267
|
): void
|
|
1203
1268
|
/** 设置描边颜色。
|
|
1204
|
-
* @supported weapp
|
|
1269
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1205
1270
|
* @example
|
|
1206
1271
|
* ```tsx
|
|
1207
1272
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1216,7 +1281,7 @@ declare module '../../index' {
|
|
|
1216
1281
|
color: string | CanvasGradient,
|
|
1217
1282
|
): void
|
|
1218
1283
|
/** 设置文字的对齐
|
|
1219
|
-
* @supported weapp
|
|
1284
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1220
1285
|
* @example
|
|
1221
1286
|
* ```tsx
|
|
1222
1287
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1227,11 +1292,13 @@ declare module '../../index' {
|
|
|
1227
1292
|
* ctx.setFontSize(15)
|
|
1228
1293
|
* ctx.setTextAlign('left')
|
|
1229
1294
|
* ctx.fillText('textAlign=left', 150, 60)
|
|
1295
|
+
* await ctx.draw(true)
|
|
1230
1296
|
* ctx.setTextAlign('center')
|
|
1231
1297
|
* ctx.fillText('textAlign=center', 150, 80)
|
|
1298
|
+
* await ctx.draw(true)
|
|
1232
1299
|
* ctx.setTextAlign('right')
|
|
1233
1300
|
* ctx.fillText('textAlign=right', 150, 100)
|
|
1234
|
-
* ctx.draw()
|
|
1301
|
+
* await ctx.draw(true)
|
|
1235
1302
|
* ```
|
|
1236
1303
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.setTextAlign.html
|
|
1237
1304
|
*/
|
|
@@ -1240,7 +1307,7 @@ declare module '../../index' {
|
|
|
1240
1307
|
align: keyof CanvasContext.Align,
|
|
1241
1308
|
): void
|
|
1242
1309
|
/** 设置文字的竖直对齐
|
|
1243
|
-
* @supported weapp
|
|
1310
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1244
1311
|
* @example
|
|
1245
1312
|
* ```tsx
|
|
1246
1313
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1251,13 +1318,16 @@ declare module '../../index' {
|
|
|
1251
1318
|
* ctx.setFontSize(20)
|
|
1252
1319
|
* ctx.setTextBaseline('top')
|
|
1253
1320
|
* ctx.fillText('top', 5, 75)
|
|
1321
|
+
* await ctx.draw(true)
|
|
1254
1322
|
* ctx.setTextBaseline('middle')
|
|
1255
1323
|
* ctx.fillText('middle', 50, 75)
|
|
1324
|
+
* await ctx.draw(true)
|
|
1256
1325
|
* ctx.setTextBaseline('bottom')
|
|
1257
1326
|
* ctx.fillText('bottom', 120, 75)
|
|
1327
|
+
* await ctx.draw(true)
|
|
1258
1328
|
* ctx.setTextBaseline('normal')
|
|
1259
1329
|
* ctx.fillText('normal', 200, 75)
|
|
1260
|
-
* ctx.draw()
|
|
1330
|
+
* await ctx.draw(true)
|
|
1261
1331
|
* ```
|
|
1262
1332
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.setTextBaseline.html
|
|
1263
1333
|
*/
|
|
@@ -1266,10 +1336,46 @@ declare module '../../index' {
|
|
|
1266
1336
|
textBaseline: keyof CanvasContext.TextBaseline,
|
|
1267
1337
|
): void
|
|
1268
1338
|
/** 使用矩阵重新设置(覆盖)当前变换的方法
|
|
1269
|
-
* @supported weapp
|
|
1339
|
+
* @supported weapp, swan, jd, tt, h5, harmony_hybrid
|
|
1270
1340
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.setTransform.html
|
|
1271
1341
|
*/
|
|
1272
1342
|
setTransform(
|
|
1343
|
+
/** 水平缩放 */
|
|
1344
|
+
scaleX: number,
|
|
1345
|
+
/** 水平倾斜 */
|
|
1346
|
+
skewX: number,
|
|
1347
|
+
/** 垂直倾斜 */
|
|
1348
|
+
skewY: number,
|
|
1349
|
+
/** 垂直缩放 */
|
|
1350
|
+
scaleY: number,
|
|
1351
|
+
/** 水平移动 */
|
|
1352
|
+
translateX: number,
|
|
1353
|
+
/** 垂直移动 */
|
|
1354
|
+
translateY: number,
|
|
1355
|
+
): void
|
|
1356
|
+
/** 使用矩阵重新设置(覆盖)当前变换的方法
|
|
1357
|
+
* @supported alipay
|
|
1358
|
+
* @see https://opendocs.alipay.com/mini/api/wt6glg?pathHash=1d428fc1
|
|
1359
|
+
*/
|
|
1360
|
+
setTransform(
|
|
1361
|
+
/** 水平缩放 */
|
|
1362
|
+
scaleX: number,
|
|
1363
|
+
/** 垂直倾斜 */
|
|
1364
|
+
skewY: number,
|
|
1365
|
+
/** 水平倾斜 */
|
|
1366
|
+
skewX: number,
|
|
1367
|
+
/** 垂直缩放 */
|
|
1368
|
+
scaleY: number,
|
|
1369
|
+
/** 水平移动 */
|
|
1370
|
+
translateX: number,
|
|
1371
|
+
/** 垂直移动 */
|
|
1372
|
+
translateY: number,
|
|
1373
|
+
): void
|
|
1374
|
+
/** 使用矩阵重新设置(覆盖)当前变换的方法
|
|
1375
|
+
* @supported qq
|
|
1376
|
+
* @see https://q.qq.com/wiki/develop/miniprogram/API/canvas/canvasContext.html#settransform
|
|
1377
|
+
*/
|
|
1378
|
+
setTransform(
|
|
1273
1379
|
/** 水平缩放 */
|
|
1274
1380
|
scaleX: number,
|
|
1275
1381
|
/** 垂直缩放 */
|
|
@@ -1284,7 +1390,7 @@ declare module '../../index' {
|
|
|
1284
1390
|
translateY: number,
|
|
1285
1391
|
): void
|
|
1286
1392
|
/** 画出当前路径的边框。默认颜色色为黑色。
|
|
1287
|
-
* @supported weapp
|
|
1393
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1288
1394
|
* @example
|
|
1289
1395
|
* ```tsx
|
|
1290
1396
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1319,7 +1425,7 @@ declare module '../../index' {
|
|
|
1319
1425
|
*/
|
|
1320
1426
|
stroke(): void
|
|
1321
1427
|
/** 画一个矩形(非填充)。 用 [`setStrokeStyle`](/docs/apis/canvas/CanvasContext#setstrokestyle) 设置矩形线条的颜色,如果没设置默认是黑色。
|
|
1322
|
-
* @supported weapp
|
|
1428
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1323
1429
|
* @example
|
|
1324
1430
|
* ```tsx
|
|
1325
1431
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1340,7 +1446,7 @@ declare module '../../index' {
|
|
|
1340
1446
|
height: number,
|
|
1341
1447
|
): void
|
|
1342
1448
|
/** 给定的 (x, y) 位置绘制文本描边的方法
|
|
1343
|
-
* @supported weapp
|
|
1449
|
+
* @supported weapp, alipay, swan, jd, qq, h5, harmony_hybrid
|
|
1344
1450
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.strokeText.html
|
|
1345
1451
|
*/
|
|
1346
1452
|
strokeText(
|
|
@@ -1354,9 +1460,45 @@ declare module '../../index' {
|
|
|
1354
1460
|
maxWidth?: number,
|
|
1355
1461
|
): void
|
|
1356
1462
|
/** 使用矩阵多次叠加当前变换的方法
|
|
1357
|
-
* @supported weapp
|
|
1463
|
+
* @supported weapp, jd, tt, h5, harmony_hybrid
|
|
1358
1464
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.transform.html
|
|
1359
1465
|
*/
|
|
1466
|
+
transform(
|
|
1467
|
+
/** 水平缩放 */
|
|
1468
|
+
scaleX: number,
|
|
1469
|
+
/** 水平倾斜 */
|
|
1470
|
+
skewX: number,
|
|
1471
|
+
/** 垂直倾斜 */
|
|
1472
|
+
skewY: number,
|
|
1473
|
+
/** 垂直缩放 */
|
|
1474
|
+
scaleY: number,
|
|
1475
|
+
/** 水平移动 */
|
|
1476
|
+
translateX: number,
|
|
1477
|
+
/** 垂直移动 */
|
|
1478
|
+
translateY: number,
|
|
1479
|
+
): void
|
|
1480
|
+
/** 使用矩阵叠加当前变换。矩阵由方法的参数进行描述,可以缩放、旋转、移动和倾斜上下文
|
|
1481
|
+
* @supported alipay
|
|
1482
|
+
* @see https://opendocs.alipay.com/mini/api/fv97do?pathHash=42ccd479
|
|
1483
|
+
*/
|
|
1484
|
+
transform(
|
|
1485
|
+
/** 水平缩放 */
|
|
1486
|
+
scaleX: number,
|
|
1487
|
+
/** 垂直倾斜 */
|
|
1488
|
+
skewY: number,
|
|
1489
|
+
/** 水平倾斜 */
|
|
1490
|
+
skewX: number,
|
|
1491
|
+
/** 垂直缩放 */
|
|
1492
|
+
scaleY: number,
|
|
1493
|
+
/** 水平移动 */
|
|
1494
|
+
translateX: number,
|
|
1495
|
+
/** 垂直移动 */
|
|
1496
|
+
translateY: number,
|
|
1497
|
+
): void
|
|
1498
|
+
/** 使用矩阵多次叠加当前变换的方法
|
|
1499
|
+
* @supported qq
|
|
1500
|
+
* @see https://q.qq.com/wiki/develop/miniprogram/API/canvas/canvasContext.html#transform
|
|
1501
|
+
*/
|
|
1360
1502
|
transform(
|
|
1361
1503
|
/** 水平缩放 */
|
|
1362
1504
|
scaleX: number,
|
|
@@ -1372,7 +1514,7 @@ declare module '../../index' {
|
|
|
1372
1514
|
translateY: number,
|
|
1373
1515
|
): void
|
|
1374
1516
|
/** 对当前坐标系的原点 (0, 0) 进行变换。默认的坐标系原点为页面左上角。
|
|
1375
|
-
* @supported weapp
|
|
1517
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1376
1518
|
* @example
|
|
1377
1519
|
* ```tsx
|
|
1378
1520
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1434,13 +1576,34 @@ declare module '../../index' {
|
|
|
1434
1576
|
}
|
|
1435
1577
|
/** 参数 textBaseline 可选值 */
|
|
1436
1578
|
interface TextBaseline {
|
|
1437
|
-
/** 顶部对齐
|
|
1579
|
+
/** 顶部对齐
|
|
1580
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5
|
|
1581
|
+
*/
|
|
1438
1582
|
top
|
|
1439
|
-
/** 底部对齐
|
|
1583
|
+
/** 底部对齐
|
|
1584
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5
|
|
1585
|
+
*/
|
|
1440
1586
|
bottom
|
|
1441
|
-
/** 居中对齐
|
|
1587
|
+
/** 居中对齐
|
|
1588
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5
|
|
1589
|
+
*/
|
|
1442
1590
|
middle
|
|
1591
|
+
/**
|
|
1592
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5
|
|
1593
|
+
*/
|
|
1443
1594
|
normal
|
|
1595
|
+
/** 文本基线为悬挂基线。
|
|
1596
|
+
* @supported alipay, tt, h5
|
|
1597
|
+
*/
|
|
1598
|
+
hanging
|
|
1599
|
+
/** 文本基线是标准的字母基线
|
|
1600
|
+
* @supported alipay, tt, h5
|
|
1601
|
+
*/
|
|
1602
|
+
alphabetic
|
|
1603
|
+
/** 文字基线是表意字基线。如果字符本身超出了alphabetic 基线,那么ideograhpic基线位置在字符本身的底部。
|
|
1604
|
+
* @supported alipay, tt, h5
|
|
1605
|
+
*/
|
|
1606
|
+
ideographic
|
|
1444
1607
|
}
|
|
1445
1608
|
}
|
|
1446
1609
|
|
|
@@ -1450,7 +1613,7 @@ declare module '../../index' {
|
|
|
1450
1613
|
*/
|
|
1451
1614
|
interface CanvasGradient {
|
|
1452
1615
|
/** 添加颜色的渐变点。小于最小 stop 的部分会按最小 stop 的 color 来渲染,大于最大 stop 的部分会按最大 stop 的 color 来渲染
|
|
1453
|
-
* @supported weapp
|
|
1616
|
+
* @supported weapp, alipay, swan, jd, qq, tt
|
|
1454
1617
|
* @example
|
|
1455
1618
|
* ```tsx
|
|
1456
1619
|
* const ctx = Taro.createCanvasContext('myCanvas')
|
|
@@ -1657,6 +1820,7 @@ declare module '../../index' {
|
|
|
1657
1820
|
/** origin: 发送完整的referrer; no-referrer: 不发送。
|
|
1658
1821
|
*
|
|
1659
1822
|
* 格式固定为 https://servicewechat.com/{appid}/{version}/page-frame.html,其中 {appid} 为小程序的 appid,{version} 为小程序的版本号,版本号为 0 表示为开发版、体验版以及审核版本,版本号为 devtools 表示为开发者工具,其余为正式版本
|
|
1823
|
+
* @supported weapp
|
|
1660
1824
|
*/
|
|
1661
1825
|
referrerPolicy: string
|
|
1662
1826
|
/** 图片加载发生错误后触发的回调函数 */
|
|
@@ -1683,6 +1847,10 @@ declare module '../../index' {
|
|
|
1683
1847
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/OffscreenCanvas.html
|
|
1684
1848
|
*/
|
|
1685
1849
|
interface OffscreenCanvas {
|
|
1850
|
+
/** 画布宽度 */
|
|
1851
|
+
width: number
|
|
1852
|
+
/** 画布高度 */
|
|
1853
|
+
height: number
|
|
1686
1854
|
/** 创建一个图片对象。支持在 2D Canvas 和 WebGL Canvas 下使用, 但不支持混用 2D 和 WebGL 的方法
|
|
1687
1855
|
*
|
|
1688
1856
|
* > 注意不允许混用 webgl 和 2d 画布创建的图片对象,使用时请注意尽量使用 canvas 自身的 createImage 创建图片对象。
|
|
@@ -1693,17 +1861,143 @@ declare module '../../index' {
|
|
|
1693
1861
|
/** 该方法返回 OffscreenCanvas 的绘图上下文
|
|
1694
1862
|
*
|
|
1695
1863
|
* > 当前仅支持获取 WebGL 绘图上下文
|
|
1696
|
-
* @supported weapp
|
|
1864
|
+
* @supported weapp, tt
|
|
1697
1865
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/OffscreenCanvas.getContext.html
|
|
1698
1866
|
*/
|
|
1699
|
-
getContext(contextType:
|
|
1867
|
+
getContext(contextType: 'webgl' | '2d'): RenderingContext
|
|
1700
1868
|
}
|
|
1701
1869
|
|
|
1702
1870
|
/** Canvas 2D API 的接口 Path2D 用来声明路径,此路径稍后会被CanvasRenderingContext2D 对象使用。CanvasRenderingContext2D 接口的 路径方法 也存在于 Path2D 这个接口中,允许你在 canvas 中根据需要创建可以保留并重用的路径。
|
|
1703
1871
|
* @supported weapp
|
|
1704
1872
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/Path2D.html
|
|
1705
1873
|
*/
|
|
1706
|
-
interface Path2D {
|
|
1874
|
+
interface Path2D {
|
|
1875
|
+
/** 添加路径到当前路径。
|
|
1876
|
+
* @supported weapp
|
|
1877
|
+
*/
|
|
1878
|
+
addPath(
|
|
1879
|
+
/** 添加的 Path2D 路径 */
|
|
1880
|
+
path: Path2D
|
|
1881
|
+
): void
|
|
1882
|
+
/** 添加一段圆弧路径
|
|
1883
|
+
* @supported weapp
|
|
1884
|
+
*/
|
|
1885
|
+
arc(
|
|
1886
|
+
/** 圆心横坐标 */
|
|
1887
|
+
x: number,
|
|
1888
|
+
/** 圆心纵坐标 */
|
|
1889
|
+
y: number,
|
|
1890
|
+
/** 圆形半径,必须为正数 */
|
|
1891
|
+
radius: number,
|
|
1892
|
+
/** 圆弧开始角度 */
|
|
1893
|
+
startAngle: number,
|
|
1894
|
+
/** 圆弧结束角度 */
|
|
1895
|
+
endAngle: number,
|
|
1896
|
+
/** 是否逆时针绘制。如果传 true, 则会从 endAngle 开始绘制到 startAngle */
|
|
1897
|
+
counterclockwise: boolean
|
|
1898
|
+
): void
|
|
1899
|
+
/** 通过给定控制点添加一段圆弧路径
|
|
1900
|
+
* @supported weapp
|
|
1901
|
+
*/
|
|
1902
|
+
arcTo(
|
|
1903
|
+
/** 第一个控制点横坐标 */
|
|
1904
|
+
x1: number,
|
|
1905
|
+
/** 第一个控制点纵坐标 */
|
|
1906
|
+
y1: number,
|
|
1907
|
+
/** 第二个控制点横坐标 */
|
|
1908
|
+
x2: number,
|
|
1909
|
+
/** 第二个控制点纵坐标 */
|
|
1910
|
+
y2: number,
|
|
1911
|
+
/** 圆形半径,必须为非负数 */
|
|
1912
|
+
radius: number
|
|
1913
|
+
): void
|
|
1914
|
+
/** 添加三次贝塞尔曲线路径
|
|
1915
|
+
* @supported weapp
|
|
1916
|
+
*/
|
|
1917
|
+
bezierCurveTo(
|
|
1918
|
+
/** 第一个控制点横坐标 */
|
|
1919
|
+
cp1x: number,
|
|
1920
|
+
/** 第一个控制点纵坐标 */
|
|
1921
|
+
cp1y: number,
|
|
1922
|
+
/** 第二个控制点横坐标 */
|
|
1923
|
+
cp2x: number,
|
|
1924
|
+
/** 第二个控制点纵坐标 */
|
|
1925
|
+
cp2y: number,
|
|
1926
|
+
/** 结束点横坐标 */
|
|
1927
|
+
x: number,
|
|
1928
|
+
/** 结束点纵坐标 */
|
|
1929
|
+
y: number
|
|
1930
|
+
): void
|
|
1931
|
+
/** 闭合路径到起点
|
|
1932
|
+
* @supported weapp
|
|
1933
|
+
*/
|
|
1934
|
+
closePath(): void
|
|
1935
|
+
/** 添加椭圆弧路径
|
|
1936
|
+
* @supported weapp
|
|
1937
|
+
*/
|
|
1938
|
+
ellipse(
|
|
1939
|
+
/** 椭圆圆心横坐标 */
|
|
1940
|
+
x: number,
|
|
1941
|
+
/** 椭圆圆心纵坐标 */
|
|
1942
|
+
y: number,
|
|
1943
|
+
/** 椭圆长轴半径,必须为非负数 */
|
|
1944
|
+
radiusX: number,
|
|
1945
|
+
/** 椭圆短轴半径,必须为非负数 */
|
|
1946
|
+
radiusY: number,
|
|
1947
|
+
/** 椭圆旋转角度 */
|
|
1948
|
+
rotation: number,
|
|
1949
|
+
/** 圆弧开始角度 */
|
|
1950
|
+
startAngle: number,
|
|
1951
|
+
/** 圆弧结束角度 */
|
|
1952
|
+
endAngle: number,
|
|
1953
|
+
/** 是否逆时针绘制。如果传 true, 则会从 endAngle 开始绘制到 startAngle */
|
|
1954
|
+
counterclockwise: boolean
|
|
1955
|
+
): void
|
|
1956
|
+
/** 添加直线路径
|
|
1957
|
+
* @supported weapp
|
|
1958
|
+
*/
|
|
1959
|
+
lineTo(
|
|
1960
|
+
/** 结束点横坐标 */
|
|
1961
|
+
x: number,
|
|
1962
|
+
/** 结束点纵坐标 */
|
|
1963
|
+
y: number
|
|
1964
|
+
): void
|
|
1965
|
+
/** 移动路径开始点
|
|
1966
|
+
* @supported weapp
|
|
1967
|
+
*/
|
|
1968
|
+
moveTo(
|
|
1969
|
+
/** 横坐标 */
|
|
1970
|
+
x: number,
|
|
1971
|
+
/** 纵坐标 */
|
|
1972
|
+
y: number
|
|
1973
|
+
): void
|
|
1974
|
+
/** 添加二次贝塞尔曲线路径
|
|
1975
|
+
* @supported weapp
|
|
1976
|
+
*/
|
|
1977
|
+
quadraticCurveTo(
|
|
1978
|
+
/** 控制点横坐标 */
|
|
1979
|
+
cpx: number,
|
|
1980
|
+
/** 控制点纵坐标 */
|
|
1981
|
+
cpy: number,
|
|
1982
|
+
/** 结束点横坐标 */
|
|
1983
|
+
x: number,
|
|
1984
|
+
/** 结束点纵坐标 */
|
|
1985
|
+
y: number
|
|
1986
|
+
): void
|
|
1987
|
+
/** 添加方形路径
|
|
1988
|
+
* @supported weapp
|
|
1989
|
+
*/
|
|
1990
|
+
rect(
|
|
1991
|
+
/** 开始点横坐标 */
|
|
1992
|
+
x: number,
|
|
1993
|
+
/** 开始点纵坐标 */
|
|
1994
|
+
y: number,
|
|
1995
|
+
/** 方形宽度,正数向右,负数向左 */
|
|
1996
|
+
width: number,
|
|
1997
|
+
/** 方形高度,正数向下,负数向上 */
|
|
1998
|
+
height: number
|
|
1999
|
+
): void
|
|
2000
|
+
}
|
|
1707
2001
|
|
|
1708
2002
|
/** Canvas 绘图上下文。
|
|
1709
2003
|
*
|
|
@@ -1711,14 +2005,37 @@ declare module '../../index' {
|
|
|
1711
2005
|
*
|
|
1712
2006
|
* - 通过 Canvas.getContext('2d') 接口可以获取 CanvasRenderingContext2D 对象,实现了 [HTML Canvas 2D Context](https://www.w3.org/TR/2dcontext/) 定义的属性、方法。
|
|
1713
2007
|
* - 通过 Canvas.getContext('webgl') 或 OffscreenCanvas.getContext('webgl') 接口可以获取 WebGLRenderingContext 对象,实现了 [WebGL 1.0](https://www.khronos.org/registry/webgl/specs/latest/1.0/) 定义的所有属性、方法、常量。
|
|
1714
|
-
*
|
|
2008
|
+
* - CanvasRenderingContext2D 的 drawImage 方法 2.10.0 起支持传入通过 SelectorQuery 获取的 video 对象,2.29.0 起支持传入开启了自定义渲染的 LivePusherContext 对象。
|
|
2009
|
+
* @supported weapp, alipay, tt
|
|
1715
2010
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/RenderingContext.html
|
|
1716
2011
|
*/
|
|
1717
2012
|
interface RenderingContext {}
|
|
1718
2013
|
|
|
1719
2014
|
interface TaroStatic {
|
|
1720
2015
|
/** 创建离屏 canvas 实例
|
|
1721
|
-
* @supported weapp
|
|
2016
|
+
* @supported weapp, tt
|
|
2017
|
+
* @example
|
|
2018
|
+
* ```tsx
|
|
2019
|
+
* // 创建离屏 2D canvas 实例
|
|
2020
|
+
* const canvas = Taro.createOffscreenCanvas({type: '2d', width: 300, height: 150})
|
|
2021
|
+
* // 获取 context。注意这里必须要与创建时的 type 一致
|
|
2022
|
+
* const context = canvas.getContext('2d')
|
|
2023
|
+
*
|
|
2024
|
+
* // 创建一个图片
|
|
2025
|
+
* const image = canvas.createImage()
|
|
2026
|
+
* // 等待图片加载
|
|
2027
|
+
* await new Promise(resolve => {
|
|
2028
|
+
* image.onload = resolve
|
|
2029
|
+
* image.src = IMAGE_URL // 要加载的图片 url
|
|
2030
|
+
* })
|
|
2031
|
+
*
|
|
2032
|
+
* // 把图片画到离屏 canvas 上
|
|
2033
|
+
* context.clearRect(0, 0, 300, 150)
|
|
2034
|
+
* context.drawImage(image, 0, 0, 300, 150)
|
|
2035
|
+
*
|
|
2036
|
+
* // 获取画完后的数据
|
|
2037
|
+
* const imgData = context.getImageData(0, 0, 300, 150)
|
|
2038
|
+
* ```
|
|
1722
2039
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.createOffscreenCanvas.html
|
|
1723
2040
|
*
|
|
1724
2041
|
* 有两个版本的写法:
|
|
@@ -1731,7 +2048,7 @@ declare module '../../index' {
|
|
|
1731
2048
|
/** 创建 canvas 的绘图上下文 [CanvasContext](/docs/apis/canvas/CanvasContext) 对象
|
|
1732
2049
|
*
|
|
1733
2050
|
* **Tip**: 需要指定 canvasId,该绘图上下文只作用于对应的 `<canvas/>`;另外,Web 端需要在 `useReady` 回调中执行它,否则会因为底层 canvas 渲染出来之前而去获取 CanvasContext,导致其底层的 context 为 `undefined`,从而不能正常绘图。
|
|
1734
|
-
* @supported weapp, h5
|
|
2051
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1735
2052
|
* @example
|
|
1736
2053
|
* ```tsx
|
|
1737
2054
|
* import { useReady } from '@tarojs/taro'
|
|
@@ -1785,7 +2102,7 @@ declare module '../../index' {
|
|
|
1785
2102
|
* }
|
|
1786
2103
|
* })
|
|
1787
2104
|
* ```
|
|
1788
|
-
* @supported weapp, h5
|
|
2105
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
1789
2106
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.canvasToTempFilePath.html
|
|
1790
2107
|
*/
|
|
1791
2108
|
canvasToTempFilePath(
|
|
@@ -1795,7 +2112,7 @@ declare module '../../index' {
|
|
|
1795
2112
|
): Promise<canvasToTempFilePath.SuccessCallbackResult>
|
|
1796
2113
|
|
|
1797
2114
|
/** 将像素数据绘制到画布。在自定义组件下,第二个参数传入自定义组件实例 this,以操作组件内 `<canvas>` 组件
|
|
1798
|
-
* @supported weapp, h5
|
|
2115
|
+
* @supported weapp, swan, jd, qq, h5, harmony_hybrid
|
|
1799
2116
|
* @example
|
|
1800
2117
|
* ```tsx
|
|
1801
2118
|
* const data = new Uint8ClampedArray([255, 0, 0, 1])
|
|
@@ -1817,7 +2134,7 @@ declare module '../../index' {
|
|
|
1817
2134
|
): Promise<TaroGeneral.CallbackResult>
|
|
1818
2135
|
|
|
1819
2136
|
/** 获取 canvas 区域隐含的像素数据。
|
|
1820
|
-
* @supported weapp, h5
|
|
2137
|
+
* @supported weapp, swan, jd, qq, h5, harmony_hybrid
|
|
1821
2138
|
* @example
|
|
1822
2139
|
* ```tsx
|
|
1823
2140
|
* Taro.canvasGetImageData({
|