"""Common interface of the render engines.""" from __future__ import annotations from abc import ABC, abstractmethod from dataclasses import dataclass, field from pathlib import Path from ..models import ConvertRequest @dataclass class ChunkRender: """Result of rendering a single chunk.""" path: Path page_count: int # Anchor name to zero based page index inside this chunk. anchor_pages: dict[str, int] = field(default_factory=dict) class RenderEngine(ABC): name: str @abstractmethod async def available(self) -> bool: """True when the engine can render right now.""" @abstractmethod async def render_chunk( self, html: str, base_url: str | None, request: ConvertRequest, output_path: Path, total_pages: int | None = None, asset_gate=None, ) -> ChunkRender: """Render one chunk into output_path.""" async def shutdown(self) -> None: """Release engine resources. Default is a no-op.""" return None @property def supports_anchor_pages(self) -> bool: """True when the engine can report on which page an anchor landed.""" return False