declare namespace Agree {
/** 创建离屏 canvas 实例
* @supported weapp
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.createOffscreenCanvas.html
*/
function createOffscreenCanvas(): OffscreenCanvas
/** 创建 canvas 的绘图上下文 [CanvasContext](https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.html) 对象
*
* **Tip**: 需要指定 canvasId,该绘图上下文只作用于对应的 ``
* @supported weapp, h5
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.createCanvasContext.html
*/
function createCanvasContext(
/** 要获取上下文的 [canvas](https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html) 组件 canvas-id 属性 */
canvasId: string,
/** 在自定义组件下,当前组件实例的this,表示在这个自定义组件下查找拥有 canvas-id 的 [canvas](https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html) ,如果省略则不在任何自定义组件内查找 */
component?: General.IAnyObject,
): CanvasContext
/** 把当前画布指定区域的内容导出生成指定大小的图片。在 `draw()` 回调里调用该方法才能保证图片导出成功。
*
* **Bug & Tip:**
*
* 1. `tip`: 在 `draw` 回调里调用该方法才能保证图片导出成功。
* @example
* ```tsx
* Agree.canvasToTempFilePath({
* x: 100,
* y: 200,
* width: 50,
* height: 50,
* destWidth: 100,
* destHeight: 100,
* canvasId: 'myCanvas',
* success: function (res) {
* console.log(res.tempFilePath)
* }
* })
* ```
* @supported weapp, h5
* @see https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.canvasToTempFilePath.html
*/
function canvasToTempFilePath(
option: canvasToTempFilePath.Option,
/** 在自定义组件下,当前组件实例的this,以操作组件内 [canvas](https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html) 组件 */
component?: General.IAnyObject,
): Promise
namespace canvasToTempFilePath {
interface Option {
/** 画布标识,传入 [canvas](https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html) 组件实例 (canvas type="2d" 时使用该属性)。 */
canvas?: CanvasProps
/** 画布标识,传入 [canvas](https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html) 组件的 canvas-id */
canvasId?: string
/** 图片的质量,目前仅对 jpg 有效。取值范围为 (0, 1],不在范围内时当作 1.0 处理。 */
quality?: number
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: (res: General.CallbackResult) => void
/** 输出的图片的高度 */
destHeight?: number
/** 输出的图片的宽度 */
destWidth?: number
/** 接口调用失败的回调函数 */
fail?: (res: General.CallbackResult) => void
/** 目标文件的类型
* @default "png"
*/
fileType?: keyof fileType
/** 指定的画布区域的高度 */
height?: number
/** 接口调用成功的回调函数 */
success?: (result: SuccessCallbackResult) => void
/** 指定的画布区域的宽度 */
width?: number
/** 指定的画布区域的左上角横坐标 */
x?: number
/** 指定的画布区域的左上角纵坐标 */
y?: number
}
interface SuccessCallbackResult extends General.CallbackResult {
/** 生成文件的临时路径 */
tempFilePath: string
/** 调用结果 */
errMsg: string
}
interface fileType {
/** jpg 图片 */
jpg
/** png 图片 */
png
}
interface CanvasProps {
/** 指定 canvas 类型,支持 2d 和 webgl */
type?: string
/** canvas 组件的唯一标识符,若指定了 type 则无需再指定该属性 */
canvasId?: string
/** 当在 canvas 中移动时且有绑定手势事件时,禁止屏幕滚动以及下拉刷新
* @default false
*/
disableScroll?: boolean
/** 手指触摸动作开始 */
onTouchStart?: General.CommonEventFunction
/** 手指触摸后移动 */
onTouchMove?: General.CommonEventFunction
/** 手指触摸动作结束 */
onTouchEnd?: General.CommonEventFunction
/** 手指触摸动作被打断,如来电提醒,弹窗 */
onTouchCancel?: General.CommonEventFunction
/** 手指长按 500ms 之后触发,触发了长按事件后进行移动不会触发屏幕的滚动 */
onLongTap?: General.CommonEventFunction
/** 当发生错误时触发 error 事件,detail = {errMsg: 'something wrong'} */
onError?: General.CommonEventFunction
}
namespace CanvasProps {
interface onErrorEventDetail {
errMsg: string
}
}
}
/** 将像素数据绘制到画布。在自定义组件下,第二个参数传入自定义组件实例 this,以操作组件内