/** * LayoutEngine * * Manages document layouts (headers, footers, wrappers) for PDF/document generation. * * Features: * - Load layouts from filesystem (JSON format) * - Locale-based layout resolution with fallback * - Header/footer/wrapper support * - Handlebars variable support in layouts * - Layout caching for performance * - Integrates with TemplateEngine * * Layout Structure: * ``` * templates/layouts/ * ├── en/ * │ ├── headers/ * │ │ ├── default.html * │ │ └── invoice.html * │ ├── footers/ * │ │ ├── default.html * │ │ └── invoice.html * │ ├── wrappers/ * │ │ ├── default.html * │ │ └── invoice.html * │ ├── default.html (shorthand for full layout) * │ └── invoice.md (can be .md or .html) * ``` * * Template Frontmatter Options: * ```yaml * # Option 1: Full wrapper layout * layout: invoice # Uses templates/layouts/{locale}/invoice.html * * # Option 2: Separate header/footer * header: invoice # Uses templates/layouts/{locale}/headers/invoice.html * footer: default # Uses templates/layouts/{locale}/footers/default.html * * # Option 3: Custom wrapper with header/footer * wrapper: custom # Uses templates/layouts/{locale}/wrappers/custom.html * header: invoice * footer: invoice * * # Option 4: Mix and match * header: invoice * footer: default * # No wrapper, just header + content + footer * ``` */ import type { StorageLayoutEngineConfig, StorageAppliedLayout } from '@plyaz/types/storage'; /** * LayoutEngine * * Manages document layouts (headers, footers, wrappers). * * @example * ```typescript * const layoutEngine = new LayoutEngine({ * basePath: './layouts', * defaultLocale: 'en', * }); * * // Apply layout to content * const result = await layoutEngine.applyLayout( * htmlContent, * 'invoice', * { companyName: 'Acme Corp', pageNumber: 1 }, * 'en' * ); * ``` */ export declare class LayoutEngine { private readonly basePath; private readonly defaultLocale; private readonly cacheEnabled; private readonly cacheTTL; private readonly logger?; private readonly layoutCache; constructor(config?: StorageLayoutEngineConfig); /** * Apply layout to content * * @param content - HTML content to wrap * @param layoutName - Layout name (e.g., 'invoice', 'default') * @param data - Data for Handlebars variables * @param locale - Locale for layout resolution (default: engine's defaultLocale) * @returns Applied layout result */ applyLayout(content: string, layoutName: string, data?: Record, locale?: string): Promise; /** * Apply layout from template frontmatter (flexible mode) * * Supports multiple layout modes: * 1. layout: Full wrapper template * 2. header + footer: Separate components * 3. wrapper + header + footer: All three * 4. wrapper only: Just wrap content * * @param content - HTML content to wrap * @param frontmatter - Template frontmatter with layout specifications * @param data - Data for Handlebars variables * @param locale - Locale for layout resolution * @returns Applied layout result */ applyLayoutFromFrontmatter(content: string, frontmatter: { layout?: string; header?: string; footer?: string; wrapper?: string; styling?: Record; css?: string; [key: string]: unknown; }, data?: Record, locale?: string): Promise; /** * Load layout component from filesystem with caching * * Supports both .html and .md files * Tries: {locale}/{type}/{name}.html then {locale}/{type}/{name}.md * Falls back to base locale and default locale * * @param componentName - Component name * @param componentType - Component type (header/footer/wrapper) * @param locale - Locale * @returns Cached layout component * @private */ private loadLayoutComponent; /** * Load layout from filesystem with caching (for full layout templates) * * @param layoutName - Layout name * @param locale - Locale * @returns Cached layout entry * @private */ private loadLayout; /** * Resolve layout component path with locale fallback * * Supports both .html and .md files * Tries in order: * 1. Exact locale with .html (e.g., en-US/headers/invoice.html) * 2. Exact locale with .md (e.g., en-US/headers/invoice.md) * 3. Base locale with .html (e.g., en/headers/invoice.html) * 4. Base locale with .md * 5. Default locale with .html * 6. Default locale with .md * * @param componentName - Component name * @param componentType - Component type (layout/header/footer/wrapper) * @param locale - Requested locale * @returns Resolved path and file type * @private */ private resolveLayoutComponentPath; /** * Read layout file from filesystem * * @param path - Absolute path to layout file * @returns Layout JSON content * @private */ private readLayoutFile; /** * Check if file exists * * @param path - File path * @returns True if file exists * @private */ private fileExists; /** * Clear layout cache */ clearCache(): void; /** * Get cache statistics */ getCacheStats(): { size: number; entries: string[]; }; /** * Helper: Log locale fallback when using different locale than requested */ private logLocaleFallback; /** * Inject custom CSS from frontmatter into HTML * * Inserts CSS block before , before , or prepends to content * * @param html - HTML content * @param css - CSS string from frontmatter * @returns HTML with injected CSS (or original if no CSS) * @private */ private injectCustomCSS; }