@nanggo/social-preview
Version:
Generate beautiful social media preview images from any URL
57 lines (56 loc) • 2.25 kB
TypeScript
/**
* Common utility functions shared across the project
*/
export * from './logger';
export * from './validation';
/**
* Escape XML special characters for safe SVG text rendering
*/
export declare function escapeXml(text: string): string;
/**
* Adjust color brightness by a percentage
* @param color - Color string (hex, rgb, rgba, hsl, hsla, or named color)
* @param percent - Brightness adjustment percentage (-100 to 100)
* @returns Adjusted color string (always returns hex format for consistency)
*/
export declare function adjustBrightness(color: string, percent: number): string;
/**
* Wrap text to fit within specified constraints
* @param text - Text to wrap
* @param maxWidth - Maximum width in pixels
* @param fontSize - Font size in pixels
* @param maxLines - Maximum number of lines
* @param fontFamily - Font family for width calculation (affects character width)
* @returns Array of text lines
*/
export declare function wrapText(text: string, maxWidth: number, fontSize: number, maxLines: number, fontFamily?: 'inter' | 'default'): string[];
/**
* Generate SVG gradient definition
* @param id - Gradient ID for SVG reference
* @param colors - Array of color stops
* @param direction - Gradient direction (angle in degrees or keywords)
* @returns SVG gradient definition string
*/
export declare function generateSvgGradient(id: string, colors: Array<{
offset: string;
color: string;
opacity?: number;
}>, direction?: string | number): string;
/**
* Create SVG text element with proper positioning and styling
* @param content - Text content
* @param x - X coordinate
* @param y - Y coordinate
* @param className - CSS class name
* @param attributes - Additional SVG attributes
* @returns SVG text element string
*/
export declare function createSvgText(content: string, x: number | string, y: number | string, className?: string, attributes?: Record<string, string | number>): string;
/**
* Truncate text to specified length with ellipsis
* @param text - Text to truncate
* @param maxLength - Maximum length
* @param ellipsis - Ellipsis string (default: '...')
* @returns Truncated text
*/
export declare function truncateText(text: string, maxLength: number, ellipsis?: string): string;