captcha-canvas
Version:
A captcha generator by using skia-canvas module.
183 lines (182 loc) • 5.56 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateCaptchaOptions = exports.defaultDimension = exports.defaultDecoyOptions = exports.defaultTraceOptions = exports.defaultCaptchaOption = exports.defaultDrawCaptchaOption = void 0;
/**
* Default configuration for CAPTCHA text drawing operations.
*
* These defaults provide a good balance between security and readability,
* with moderate styling that makes the text challenging for OCR while
* remaining accessible to humans.
*
* @example Using defaults
* ```typescript
* const captcha = new Captcha(300, 100);
* captcha.drawCaptcha(); // Uses all default values
* ```
*
* @example Overriding specific defaults
* ```typescript
* const captcha = new Captcha(300, 100);
* captcha.drawCaptcha({
* ...defaultDrawCaptchaOption,
* text: 'CUSTOM',
* size: 60
* });
* ```
*/
exports.defaultDrawCaptchaOption = {
/** Default font size in pixels */
size: 40,
/** Default font family */
font: 'Sans',
/** Enable skewing by default for security */
skew: true,
/** Empty colors array - uses color property instead */
colors: [],
/** Default rotation range (±5 degrees) */
rotate: 5,
/** Default text color (green) */
color: '#32cf7e',
/** Default text opacity */
opacity: 0.8,
};
/**
* Default configuration for CAPTCHA text generation and appearance.
*
* These settings provide secure defaults suitable for most use cases,
* generating 6-character random text with moderate visual distortions
* that balance security against readability.
*
* @example Using defaults with CaptchaGenerator
* ```typescript
* const captcha = new CaptchaGenerator();
* // Uses defaultCaptchaOption settings automatically
* ```
*
* @example Customizing specific properties
* ```typescript
* const captcha = new CaptchaGenerator()
* .setCaptcha({
* ...defaultCaptchaOption,
* characters: 8, // Override just the length
* size: 50 // Override just the size
* });
* ```
*/
exports.defaultCaptchaOption = {
/** Default number of random characters to generate */
characters: 6,
/** Default font size in pixels */
size: 40,
/** Default font family */
font: 'Sans',
/** Enable skewing by default for security */
skew: true,
/** Empty colors array - uses color property instead */
colors: [],
/** Default rotation range (±5 degrees) */
rotate: 5,
/** Default text color (green) */
color: '#32cf7e',
/** Default text opacity */
opacity: 0.8,
};
/**
* Default configuration for trace lines connecting CAPTCHA characters.
*
* Trace lines provide additional security by making character segmentation
* more difficult for automated systems. These defaults create visible but
* not overwhelming connecting lines.
*
* @example Using default trace
* ```typescript
* const captcha = new CaptchaGenerator()
* .setCaptcha({ text: 'HELLO' })
* .setTrace({}); // Uses all defaults
* ```
*
* @example Customizing trace appearance
* ```typescript
* const captcha = new CaptchaGenerator()
* .setTrace({
* ...defaultTraceOptions,
* color: '#95a5a6', // Different color
* opacity: 0.7 // More subtle
* });
* ```
*/
exports.defaultTraceOptions = {
/** Default trace line width in pixels */
size: 3,
/** Default trace line color (matches text color) */
color: '#32cf7e',
/** Default trace line opacity (fully opaque) */
opacity: 1,
};
/**
* Default configuration for decoy characters that add security noise.
*
* Decoy characters are fake letters scattered around the CAPTCHA to confuse
* OCR systems. These defaults create subtle noise that doesn't interfere
* with human readability while significantly increasing security.
*
* @example Using default decoys
* ```typescript
* const captcha = new CaptchaGenerator()
* .setCaptcha({ text: 'HELLO' })
* .setDecoy({}); // Uses all defaults, total calculated automatically
* ```
*
* @example Customizing decoy appearance
* ```typescript
* const captcha = new CaptchaGenerator()
* .setDecoy({
* ...defaultDecoyOptions,
* total: 50, // More decoys for higher security
* opacity: 0.3 // More subtle appearance
* });
* ```
*/
exports.defaultDecoyOptions = {
/** Default decoy character color (gray) */
color: '#646566',
/** Default font family for decoys */
font: 'Sans',
/** Default decoy character size (smaller than main text) */
size: 20,
/** Default decoy opacity (semi-transparent) */
opacity: 0.8,
};
/**
* Default dimensions for CAPTCHA images.
*
* These dimensions provide a good balance between readability and file size,
* suitable for most web applications and forms. The 3:1 aspect ratio allows
* for comfortable text spacing.
*
* @example Using default dimensions
* ```typescript
* const captcha = new Captcha(); // Uses 300x100 by default
* ```
*
* @example Scaling from defaults
* ```typescript
* const largeCaptcha = new Captcha(
* defaultDimension.width * 1.5, // 450px wide
* defaultDimension.height * 1.5 // 150px tall
* );
* ```
*/
exports.defaultDimension = {
/** Default CAPTCHA height in pixels */
height: 100,
/** Default CAPTCHA width in pixels */
width: 300
};
/**
* Empty object for JSDoc compatibility.
* The actual CreateCaptchaOptions interface is defined above.
*
* @deprecated Use the CreateCaptchaOptions interface instead
*/
exports.CreateCaptchaOptions = {};