UNPKG

3.24 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction, CanvasTouchEventFunction, CanvasTouchEvent } from './common'
3interface CanvasProps extends StandardProps<any, CanvasTouchEvent> {
4 /** 指定 canvas 类型,支持 2d 和 webgl
5 * @supported weapp, alipay, tt
6 */
7 type?: string
8 /** canvas 组件的唯一标识符,若指定了 type 则无需再指定该属性
9 * @supported weapp, swan, tt, qq, jd, h5, harmony_hybrid
10 */
11 canvasId?: string
12 /** 当在 canvas 中移动时且有绑定手势事件时,禁止屏幕滚动以及下拉刷新
13 * @default false
14 * @supported weapp, alipay, swan, qq, jd
15 */
16 disableScroll?: boolean
17 /** 组件唯一标识符。
18 * 注意:同一页面中的 id 不可重复。
19 * @supported alipay, h5, harmony_hybrid
20 */
21 id?: string
22 /**
23 * @supported alipay, h5, harmony_hybrid
24 */
25 width?: string
26 /**
27 * @supported alipay, h5, harmony_hybrid
28 */
29 height?: string
30 /** 用于透传 `WebComponents` 上的属性到内部 H5 标签上
31 * @supported h5, harmony_hybrid
32 */
33 nativeProps?: Record<string, unknown>
34 /** 手指触摸动作开始
35 * @supported weapp, alipay, swan, tt, qq, jd, h5, harmony_hybrid
36 */
37 onTouchStart?: CanvasTouchEventFunction
38 /** 手指触摸后移动
39 * @supported weapp, alipay, swan, tt, qq, jd, h5, harmony_hybrid
40 */
41 onTouchMove?: CanvasTouchEventFunction
42 /** 手指触摸动作结束
43 * @supported weapp, alipay, swan, tt, qq, jd, h5, harmony_hybrid
44 */
45 onTouchEnd?: CanvasTouchEventFunction
46 /** 手指触摸动作被打断,如来电提醒,弹窗
47 * @supported weapp, alipay, swan, tt, qq, jd, h5, harmony_hybrid
48 */
49 onTouchCancel?: CanvasTouchEventFunction
50 /** 手指长按 500ms 之后触发,触发了长按事件后进行移动不会触发屏幕的滚动
51 * @supported weapp, alipay, swan, qq, jd, h5, harmony_hybrid
52 */
53 onLongTap?: CommonEventFunction
54 /** 当发生错误时触发 error 事件,detail = {errMsg: 'something wrong'}
55 * @supported weapp, swan, qq, jd
56 */
57 onError?: CommonEventFunction<CanvasProps.onErrorEventDetail>
58 /** 点击。
59 * @supported alipay
60 */
61 onTap?: CommonEventFunction
62 /** canvas 组件初始化成功触发。
63 * @supported alipay
64 */
65 onReady?: CommonEventFunction
66}
67declare namespace CanvasProps {
68 interface onErrorEventDetail {
69 errMsg: string
70 }
71}
72/** 画布
73 *
74 * `<Canvas />` 组件的 RN 版本尚未实现。
75 * @classification canvas
76 * @supported weapp, alipay, swan, tt, qq, jd, h5, harmony_hybrid
77 * @example_react
78 * ```tsx
79 * class App extends Components {
80 * render () {
81 * // 如果是支付宝小程序,则要加上 id 属性,值和canvasId一致
82 * return (
83 * <Canvas style='width: 300px; height: 200px;' canvasId='canvas' />
84 * )
85 * }
86 * }
87 * ```
88 * @example_vue
89 * ```html
90 * <template>
91 * <!-- 如果是支付宝小程序,则要加上 id 属性,值和canvasId一致 -->
92 * <canvas style="width: 300px; height: 200px;" canvas-id="canvas" />
93 * </template>
94 * ```
95 * @see https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html
96 */
97declare const Canvas: ComponentType<CanvasProps>
98export { Canvas, CanvasProps }