@alauda/doom
Version:
Doctor Doom making docs.
48 lines (47 loc) • 2 kB
TypeScript
import type { PDFDocument, PDFObject, PDFRef } from 'pdf-lib';
import { PDFName } from 'pdf-lib';
import type { Page } from 'playwright';
export type DictMap = Map<PDFName, PDFObject>;
export interface RootOutlineNode {
children: OutlineNode[];
depth: number;
parent?: OutlineNode | RootOutlineNode;
}
export interface OutlineNode {
title: string;
destination: string;
children: OutlineNode[];
depth: number;
parent?: OutlineNode | RootOutlineNode;
italic?: boolean;
bold?: boolean;
color?: number[];
}
export interface OutlineRef extends OutlineNode {
children: OutlineRef[];
ref: PDFRef;
parentRef: PDFRef;
}
/**
* Format the outline container selector by removing extra spaces and ensuring trailing space.
*
* @param {string} outlineContainerSelector - The selector for the outline container.
* @returns The formatted selector.
*/
export declare function formatOutlineContainerSelector(outlineContainerSelector: string): string;
/**
* Gets the outline of a webpage using a headless browser.
* @param {Page} page - The page to evaluate.
* @param {string[]} tags - An array of tag names to use for the outline.
* @param outlineContainerSelector - Outline Container Selector
* @returns A Promise that resolves to an array of top-level OutlineNode objects representing the parsed outline.
*/
export declare function getOutlineNodes(page: Page, tags: string[], outlineContainerSelector?: string): Promise<OutlineNode[]>;
/**
* Sets the outlines of a PDF document from a nested outline tree.
* @param {PDFDocument} pdfDoc - The PDF document to set outlines on.
* @param {OutlineNode[]} outlineNodes - The nested outline tree to use as outlines.
* @param {boolean} [enableWarnings=false] - Whether to generate warnings for missing destinations.
* @returns The PDF document with outlines set.
*/
export declare function setOutlineNodes(pdfDoc: PDFDocument, outlineNodes: OutlineNode[], enableWarnings?: boolean): OutlineRef[];