/** * EPUB Canonical Fragment Identifier (CFI) utilities */ /** * Options for generating CFIs */ export interface GenerateOptions { /** * Whether to include text assertions for more robust CFIs */ includeTextAssertions?: boolean; /** * The maximum length of text to use for text assertions * Default is 10 characters */ textAssertionLength?: number; /** * Whether to include a side bias assertion */ includeSideBias?: "before" | "after"; /** * Whether to include spatial coordinates (for image or video) * Values should be in the range 0-100, where (0,0) is top-left and (100,100) is bottom-right */ spatialOffset?: [number, number]; /** * Extension parameters to include in the CFI * Keys should be parameter names, values should be the parameter values * Vendor-specific parameters should be prefixed with 'vnd.' followed by the vendor name */ extensions?: Record; } /** * Position in a document, consisting of a node and optional offset */ export interface CfiPosition { /** * The DOM node */ node?: Node | null; /** * Character offset within the node (for text nodes) */ offset?: number; /** * Temporal position in seconds (for audio/video content) */ temporal?: number; /** * Spatial position as [x,y] coordinates (for image or video) * Values should be in the range 0-100, where (0,0) is top-left and (100,100) is bottom-right */ spatial?: [number, number]; /** * Spine index (0-based) for the document containing the node */ spineIndex?: number; /** * ID of the spine item */ spineId?: string; } /** * Generate a CFI from a DOM node or position * * @example * // Generate CFI for a single node * const cfi = generate(node); * * @example * // Generate CFI for a text node with offset * const cfi = generate({ node: textNode, offset: 5 }); * * @example * // Generate CFI for a video with temporal offset * const cfi = generate({ node: videoElement, temporal: 45.5 }); * * @example * // Generate CFI for an image with spatial coordinates * const cfi = generate({ node: imageElement, spatial: [50, 75] }); * * @example * // Generate a range CFI * const cfi = generate({ * start: { node: startNode, offset: 0 }, * end: { node: endNode, offset: 10 } * }); * * @example * // Generate a CFI with spine itemref reference * const cfi = generate({ * node: chapterNode, * spineIndex: 1, * spineId: 'chap01ref' * }); * * @example * // Generate a CFI for a spine item without a node * const cfi = generate({ * spineIndex: 1, * spineId: 'chap01ref' * }); * * @example * // Generate a robust CFI with text assertions * const cfi = generate(node, { * includeTextAssertions: true, * textAssertionLength: 15 * }); */ export declare function generate(position: Node | CfiPosition | { start: CfiPosition; end: CfiPosition; }, options?: GenerateOptions): string;