import type { ProcessedAsset } from '../assets/asset-processing-service/assets.types.js'; import type { PagePackageResult } from '../../types/public-types.js'; import { type HtmlRewriterMode, type HtmlRewriterProvider } from './html-rewriter-provider.service.js'; export type HtmlDocumentContributionPlacement = 'head-prepend' | 'head-append' | 'body-prepend' | 'body-append'; export type HtmlDocumentContribution = { placement: HtmlDocumentContributionPlacement; html: string; }; export interface HtmlTransformerServiceOptions { htmlRewriterMode?: HtmlRewriterMode; htmlRewriterProvider?: HtmlRewriterProvider; } export declare class HtmlTransformerService { private processedDependencies; private pagePackage?; private htmlRewriterProvider; constructor(options?: HtmlTransformerServiceOptions); /** * Overrides the HTML rewriter runtime selection. * * This is intended for internal/runtime tests that need deterministic * selection between native, worker-tools, and string fallback behavior. * * @param mode Requested runtime selection strategy. */ setHtmlRewriterMode(mode: HtmlRewriterMode): void; private formatAttributes; private generateScriptTag; private generateStylesheetTag; private appendDependencies; private buildDependencyTags; private applyContributions; /** * Injects generated markup immediately before the closing HTML tag when it is * present, or appends/prepends a fallback insertion otherwise. */ private injectBeforeClosingTag; private injectAfterOpeningTag; private groupContributionsByPlacement; /** * Replaces the current processed dependency set used during HTML finalization. */ setProcessedDependencies(processedDependencies: ProcessedAsset[]): void; /** * Replaces the current structured page package used during HTML finalization. */ setPagePackage(pagePackage: PagePackageResult): void; /** * Returns the processed dependencies queued for the next transform pass. */ getProcessedDependencies(): ProcessedAsset[]; /** * Returns the structured page package queued for the next transform pass. */ getPagePackage(): PagePackageResult | undefined; /** * Applies attributes to the opening `` tag when present. */ applyAttributesToHtmlElement(html: string, attributes: Record): string; /** * Applies attributes to the first element nested directly under ``. */ applyAttributesToFirstBodyElement(html: string, attributes: Record): string; /** * Applies attributes to the first element in a fragment or full-document HTML * string. */ applyAttributesToFirstElement(html: string, attributes: Record): string; /** * Removes duplicate processed assets while preserving first-seen order. * * @remarks * Dedupe keys include structural asset fields and HTML attributes so repeated * orchestration passes can merge assets safely without collapsing distinct tag * variants. */ dedupeProcessedAssets(assets: ProcessedAsset[]): ProcessedAsset[]; /** * Injects the currently processed dependencies into an HTML response. * * @remarks * Native or worker-tools HTML rewriter support is preferred when available. A * string-based fallback remains in place for runtimes that cannot provide one * of those rewriter implementations. */ transform(res: Response, contributions?: HtmlDocumentContribution[], pagePackage?: PagePackageResult): Promise; /** * Splits processed assets into head and body injection groups. */ private groupDependenciesByPosition; private resolvePagePackageHtmlDependencies; /** * Builds a serialized HTML attribute string from an attribute object. */ private buildAttributeString; }