import type { FillRule, LineCap, LineJoin, LineStyle } from 'modern-path2d'; import type { Batchable2D, ColorValue } from '../../core'; import { Path2D } from 'modern-path2d'; import { Texture2D } from '../resources'; export type TransformUv = (uvs: Float32Array, index: number) => void; export type TransformVertex = (vertices: Float32Array, index: number) => void; export interface CanvasBatchable extends Batchable2D { type: 'stroke' | 'fill' | 'mesh'; texture?: Texture2D; transformUv?: TransformUv; transformVertex?: TransformVertex; size?: { width: number; height: number; }; /** mesh 显式 UV(0..1),绕过「由顶点位置派生 UV」。 */ meshUvs?: Float32Array; } export interface StrokeDraw extends Partial { type: 'stroke'; path: Path2D; lineStyle: LineStyle; /** 流动速度(周期/秒,符号=方向);发射 batchable 时经 encodeFlowSpeed 编成 effectParam。 */ flow?: number; } export interface FillDraw extends Partial { type: 'fill'; path: Path2D; } /** 自定义三角网格绘制:顶点(局部像素)+ 显式 UV(0..1) + 三角索引,不经路径三角化。 */ export interface MeshDraw extends Partial { type: 'mesh'; vertices: Float32Array; indices: Uint32Array; meshUvs: Float32Array; } export declare class CanvasContext extends Path2D { fillStyle?: ColorValue | Texture2D; fillRule?: FillRule; strokeStyle?: ColorValue | Texture2D; strokeAlignment?: number; lineCap?: LineCap; lineJoin?: LineJoin; lineWidth?: number; miterLimit?: number; /** 描边流动效果速度(周期/秒,符号=方向;0/undefined=关闭)。见 flowStreakEffect。 */ lineFlow?: number; transformUv?: TransformUv; transformVertex?: TransformVertex; protected _draws: (StrokeDraw | FillDraw | MeshDraw)[]; protected _triCache: { sig: string; vertices: Float32Array; indices: Uint32Array; uvs?: Float32Array; }[]; protected _parseDrawStyle(source?: ColorValue | Texture2D): { texture?: Texture2D; }; stroke(options?: Partial): void; /** * 绘制自定义三角网格(用当前 fillStyle 纹理)。顶点为局部像素坐标 [x,y,...], * UV 为归一化 [u,v,...](0..1),indices 为三角索引。用于精灵网格 / 骨骼网格变形。 */ drawMesh(vertices: ArrayLike, uvs: ArrayLike, indices: ArrayLike): void; fillRect(x: number, y: number, width: number, height: number): void; strokeRect(x: number, y: number, width: number, height: number): void; fill(options?: Partial): void; copyFrom(source: CanvasContext): this; resetStatus(): void; reset(): this; toBatchables(): CanvasBatchable[]; destroy(): void; }