UNPKG

html2canvas-pro

Version:

Screenshots with JavaScript. Next generation!

88 lines (87 loc) 2.37 kB
/** * Background Renderer * * Handles rendering of element backgrounds including: * - Background colors * - Background images (URL) * - Linear gradients * - Radial gradients * - Background patterns and repeats */ import { Context } from '../../core/context'; import { ElementContainer } from '../../dom/element-container'; /** * Dependencies required for BackgroundRenderer */ export interface BackgroundRendererDependencies { ctx: CanvasRenderingContext2D; context: Context; canvas: HTMLCanvasElement; options: { width: number; height: number; scale: number; }; } /** * Background Renderer * * Specialized renderer for element backgrounds. * Extracted from CanvasRenderer to improve code organization and maintainability. */ export declare class BackgroundRenderer { private readonly ctx; private readonly context; private readonly canvas; constructor(deps: BackgroundRendererDependencies); /** * Render background images for a container * Supports URL images, linear gradients, and radial gradients * * @param container - Element container with background styles */ renderBackgroundImage(container: ElementContainer): Promise<void>; /** * Render a URL-based background image */ private renderBackgroundURLImage; /** * Render a linear gradient background */ private renderLinearGradient; /** * Render a radial gradient background */ private renderRadialGradient; /** * Render a repeating pattern with offset * * @param path - Path to fill * @param pattern - Canvas pattern or gradient * @param offsetX - X offset for pattern * @param offsetY - Y offset for pattern */ private renderRepeat; /** * Resize an image to target dimensions * * @param image - Source image * @param width - Target width * @param height - Target height * @param imageRendering - CSS image-rendering property value * @returns Resized canvas or original image */ private resizeImage; /** * Create a canvas path from path array * * @param paths - Array of path points */ private path; /** * Format path points into canvas path * * @param paths - Array of path points */ private formatPath; }