license import type { TextPositionSelector } from '../types.js' ; import type { Chunk , Chunker , ChunkRange } from './chunker.js' ; import { CodePointSeeker } from './code-point-seeker.js' ; import { TextSeeker } from './seeker.js' ; /**
 * Returns a  TextPositionSelector that points at the target text within
 * the given scope.
 *
 * This is an abstract implementation of the function’s logic, which expects a
 * generic  Chunker to represent the text, and a  ChunkRange to
 * represent the target.
 *
 * See  dom . describeTextPosition for a wrapper around
 * this implementation which applies it to the text of an HTML DOM.
 *
 *  param target param scope - The text, presented as a  Chunker , which contains the
 * target range, and relative to which its position will be measured
 *  returns The  TextPositionSelector that describes `target` relative
 * to `scope`
 *
 *  public export async function describeTextPosition < TChunk extends Chunk < string > > ( target , scope ) { const codeUnitSeeker = new TextSeeker ( scope ) ; const codePointSeeker = new CodePointSeeker ( codeUnitSeeker ) ; codePointSeeker . seekToChunk ( target . startChunk , target . startIndex ) ; const start = codePointSeeker . position ; codePointSeeker . seekToChunk ( target . endChunk , target . endIndex ) ; const end = codePointSeeker . position ; return { type : 'TextPositionSelector' , start , end , } ; }