export interface CaptchaEvents { onSuccess?: (options: GraphicCaptchaOptions | SliderCaptchaOptions | PuzzleCaptchaOptions) => void; onFail?: (options: GraphicCaptchaOptions | SliderCaptchaOptions | PuzzleCaptchaOptions) => void; onRefresh?: () => void; onTimeout?: () => void; } export interface GraphicCaptchaOptions extends CaptchaEvents { container: HTMLElement; length?: number; lineCount?: number; dotCount?: number; fontSize?: number; chars?: string; strictCase?: boolean; refreshOnFail?: boolean; fonts?: string[]; timeout?: number; /** * 刷新验证码 */ refresh: () => void; /** * 验证用户输入 * @param input 用户输入的验证码 * @returns 是否验证成功 */ verify(input?: string | number): boolean; /** * 销毁验证码实例 */ destroy(): void; } export interface SliderCaptchaOptions extends CaptchaEvents { container: HTMLElement; threshold?: number; resetOnFail?: boolean; timeout?: number; sliderColor?: string; trackColor?: string; textColor?: string; hintText?: string; successColor?: string; failColor?: string; successText?: string; failText?: string; /** * 刷新验证码 */ refresh(): void; /** * 销毁验证码实例 */ destroy(): void; } export interface PuzzleCaptchaOptions extends CaptchaEvents { container: HTMLElement; width?: number; height?: number; puzzleWidth?: number; puzzleHeight?: number; backgroundImage?: string | string[]; shape?: 'triangle' | 'square' | 'hexagon' | 'pentagon' | 'star'; threshold?: number; resetOnFail?: boolean; showAsPopup?: boolean; textColor?: string; successColor?: string; sliderColor?: string; mismatchColor?: string; hintText?: string; failText?: string; successText?: string; } export type CaptchaOptions = (GraphicCaptchaOptions & { mode?: 'graphic'; }) | (SliderCaptchaOptions & { mode?: 'slider'; }) | (PuzzleCaptchaOptions & { mode?: 'puzzle'; }); export type CaptchaType = 'graphic' | 'slider' | 'puzzle';