@pierre/diffs
Version:
102 lines • 4.61 kB
TypeScript
import { Element, ElementContent } from "../node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.js";
import { BaseCodeOptions, DiffsHighlighter, FileContents, FileHeaderRenderMode, HighlightedToken, LineAnnotation, RenderFileOptions, RenderRange, ThemedFileResult } from "../types.js";
import { TextDocument } from "../editor/textDocument.js";
import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
//#region src/renderers/FileRenderer.d.ts
interface FileRenderResult {
file: FileContents;
gutterAST: ElementContent[];
contentAST: ElementContent[];
preAST: Element;
headerAST: Element | undefined;
css: string;
totalLines: number;
themeStyles: string;
baseThemeType: 'light' | 'dark' | undefined;
rowCount: number;
bufferBefore: number;
bufferAfter: number;
}
interface FileRendererOptions extends BaseCodeOptions {
headerRenderMode?: FileHeaderRenderMode;
}
declare class FileRenderer<LAnnotation = undefined> {
options: FileRendererOptions;
private annotationSlotName;
private onRenderUpdate?;
private workerManager?;
readonly __id: string;
private highlighter;
private file;
private renderCache;
private pendingHighlightResult;
private computedLang;
private lineAnnotations;
private lineCache;
private pendingStructuralRows;
private textDocumentCache;
private editSessionActive;
get fileCache(): FileContents | undefined;
constructor(options?: FileRendererOptions, annotationSlotName?: (annotation: LineAnnotation<LAnnotation>) => string, onRenderUpdate?: (() => unknown) | undefined, workerManager?: WorkerPoolManager | undefined);
setOptions(options: FileRendererOptions): void;
mergeOptions(options: Partial<FileRendererOptions>): void;
setLineAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): void;
cleanUp(): void;
/**
* Enter edit-session mode: rendering happens locally with the token
* transformer forced on, and worker-pool requests/results are suspended
* for this renderer. Called on initial editor association and whenever its
* rendering resumes after recycle.
*/
beginEditSession(file: FileContents, externalFile?: FileContents): void;
/**
* Leave edit-session mode. Rendering returns to the pool when one works.
* When `settledFile` has the content the cache already shows, the cache
* adopts it as its identity so the next render treats it as current
* instead of a new file.
*/
endEditSession(settledFile?: FileContents): void;
/**
* Ensures that the DOM is compatible with editor render updates
*/
editorRenderReady(): boolean;
recycle(): void;
clearRenderCache(): void;
hydrate(file: FileContents): void;
private getLocalHighlightTheme;
getEffectiveCodeOptions(): Pick<BaseCodeOptions, 'theme' | 'tokenizeMaxLineLength'>;
private getRenderOptions;
/**
* Returns the file that the next synchronous render can commit without
* changing the current render cache. Virtualized layouts use this to stay
* aligned with the DOM while a replacement highlight is still pending.
*/
getFileForNextRender(file: FileContents): FileContents;
private canRenderFile;
getOrCreateLineCache(file: FileContents): string[];
getLineCount(file: FileContents): number;
updateRenderCache(dirtyLines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light', lineCountChangeInFlight?: boolean): void;
applyDocumentChange(textDocument: TextDocument<'file', LAnnotation>): void;
renderFile(file?: FileContents | undefined, renderRange?: RenderRange): FileRenderResult | undefined;
asyncRender(file: FileContents, renderRange?: RenderRange): Promise<FileRenderResult>;
private asyncHighlight;
private renderFileWithHighlighter;
private processFileResult;
private renderHeader;
renderFullHTML(result: FileRenderResult): string;
renderFullAST(result: FileRenderResult, children?: ElementContent[]): Element;
renderCodeAST(result: FileRenderResult): ElementContent[];
renderPartialHTML(children: ElementContent[], includeCodeNode?: boolean): string;
initializeHighlighter(): Promise<DiffsHighlighter>;
onHighlightSuccess(file: FileContents, result: ThemedFileResult, options: RenderFileOptions, highlighted?: boolean): void;
private applyHighlightResult;
private getMatchingWorkerResultCache;
private getReadyRenderResult;
private hasHighlightedRenderCache;
onHighlightError(error: unknown): void;
private getTokenizeMaxLength;
private createPreElement;
}
//#endregion
export { FileRenderResult, FileRenderer, FileRendererOptions };
//# sourceMappingURL=FileRenderer.d.ts.map