UNPKG

split-with-kerning

Version:

Split a text into words and letters and respect the kerning

100 lines (84 loc) 2.47 kB
export declare function applyKerningFromExport(element: HTMLElement, kernings: KerningData, options?: KerningOptions): void; export declare function applyKerningFromFont(element: HTMLElement, font: FontLike, options?: KerningOptions): void; export declare function convertOptimizedToKerningPairs(optimizedData: KerningDataOptimized): KerningData; /** * Type for the font parameter in applyKerningFromFont * This is a minimal type that matches the required properties from opentype.js */ export declare interface FontLike { getKerningValue: (left: string, right: string) => number; unitsPerEm: number; } /** * Calculates kerning value between two characters * @param leftChar - The left character * @param rightChar - The right character * @returns The kerning value in font units */ export declare function getKerningValue(font: any, leftChar: string, rightChar: string): number; /** * Interface for kerning data exported from a font */ export declare interface KerningData { kerningPairs: Record<string, number>; unitsPerEm: number; } /** * Interface for kerning data optimized for performance */ export declare interface KerningDataOptimized { kerningPairs: KerningPairOptimized[]; unitsPerEm: number; } /** * Options for applying kerning */ export declare interface KerningOptions { wordSelector?: string; charSelector?: string; } /** * Interface for kerning pair optimized for performance */ export declare interface KerningPairOptimized { left: string[]; right: string[]; value: number; } /** * Represents a single letter */ export declare interface Letter { value: string; kerning?: number; element?: HTMLElement; } /** * Represents the complete text structure after splitting */ export declare interface SplittedText { reset: () => void; splitted: TextElement; } export declare function splitText(element: HTMLElement, splitType?: SplitType): SplittedText; /** * Type of hierarchical splitting */ export declare type SplitType = 'letter' | 'word' | 'none'; /** * Represents a text element */ export declare interface TextElement { value: string; words?: Word[]; element?: HTMLElement; } /** * Represents a word composed of letters */ export declare interface Word { value: string; element?: HTMLElement; letters?: Letter[]; } export { }