Core API
createHighlighter, text sources, targets and the exported geometry.
The core, glyphline. The framework packages wrap it: React API, Svelte API.
createHighlighter
function createHighlighter(svg: SVGSVGElement, source: TextSource, options?: HighlighterOptions): Highlighter;Adds its paths to svg, sets its viewBox from the source and returns:
Prop
Type
HighlightState
Prop
Type
HighlighterOptions
Prop
Type
TextSource
Anything that can be highlighted. domSource and pdfSource return one; you can write your own (a canvas editor, a custom renderer).
interface TextSource {
text: string;
words: Word[]; // { index, start, end, text, sentence }
sentences: Sentence[]; // { index, start, end, text, firstWord, lastWord }
boxes(start: number, end: number, overlay: Element): Box[]; // one per line fragment
viewBox(overlay: Element): Box;
live?: boolean; // re-measure on overlay resize
rangeFromSelection?(selection: Selection | null): TextRange | null;
}segment(text, { breakAt, locale }) gives you words and sentences for your own text.
domSource
function domSource(root: Element, options?: { locale?: string; skip?: string }): DomTextSource;Adds root, rangeFromSelection(selection), charAtPoint(x, y) and toRange(start, end).
pdfSource
function pdfSource(page: PDFPageProxy, options: { OPS: Record<string, number>; locale?: string }): Promise<PdfTextSource>;Adds page, pageText, width and height (the page at scale 1), geometry (per-character boxes and which method placed each item), fallbackItems, methods (each method's raw boxes), withTextLayer(textDivs, container, scale) and rangeFromSelection(selection).
Helpers
| Export | |
|---|---|
wordAtPoint(source, svg, x, y) | word index under a viewport point, or -1 |
toOverlay(svg, x, y) | viewport point to overlay units |
wordAt(words, charIndex) | word index containing a character |
snapToWords(source, range) | grow a range to whole words |
wordRange, sentenceRange | index to { start, end } |
sentenceShape, shapePath, outlinePath, wordPath | outline geometry |
interpolateWord, interpolateSentence, easeOutCubic | motion |
walkGlyphs, geometryFromGlyphs, geometryFromItems, geometryFromTextLayer, withFallback (from glyphline/pdf) | the PDF positioning methods on their own |
Made by Lucas Piera