This is an automated email from the ASF dual-hosted git repository. gerben pushed a commit to branch chunking in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit 701c8d0dfceb3e23c7f0053b37440baa61c96e45 Author: Gerben <[email protected]> AuthorDate: Wed Sep 16 17:03:57 2020 +0200 rename stuff --- packages/dom/src/text-iterator.ts | 9 ++++++++- packages/dom/src/text-quote/match.ts | 13 +++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/dom/src/text-iterator.ts b/packages/dom/src/text-iterator.ts index dfc1384..17fdf1c 100644 --- a/packages/dom/src/text-iterator.ts +++ b/packages/dom/src/text-iterator.ts @@ -45,8 +45,15 @@ export interface Chunk { toString(): string; } +export interface ChunkRange<TChunk> { + startChunk: TChunk; + startIndex: number; + endChunk: TChunk; + endIndex: number; +} + // Yields ranges whose start and end nodes are both the *same* Text node. -export async function* chunkRange(scope: Range): AsyncIterable<TextRange> { +export async function* rangeToTextChunks(scope: Range): AsyncIterable<TextRange> { const document = ownerDocument(scope); const iter = document.createNodeIterator( diff --git a/packages/dom/src/text-quote/match.ts b/packages/dom/src/text-quote/match.ts index c3fb43d..3ec4b68 100644 --- a/packages/dom/src/text-quote/match.ts +++ b/packages/dom/src/text-quote/match.ts @@ -20,7 +20,7 @@ import type { TextQuoteSelector } from '@annotator/selector'; -import { chunkRange, Chunk, TextRange } from '../text-iterator'; +import { rangeToTextChunks, Chunk, TextRange, ChunkRange } from '../text-iterator'; export function createTextQuoteSelectorMatcher( selector: TextQuoteSelector, @@ -30,7 +30,7 @@ export function createTextQuoteSelectorMatcher( // Turn the scope into a stream of ranges, each wrapping exactly one text node. We wrap it in // a range such that the first and last text node can be partially included. Could be changed // to e.g. be an object { node: Text, startOffset, endOffset }. - const textChunks = chunkRange(scope); + const textChunks = rangeToTextChunks(scope); for await (const abstractMatch of abstractMatcher(textChunks)) { const match = document.createRange() as TextRange; @@ -44,16 +44,9 @@ export function createTextQuoteSelectorMatcher( } } -interface AbstractRange<TChunk> { - startChunk: TChunk; - startIndex: number; - endChunk: TChunk; - endIndex: number; -} - export function abstractTextQuoteSelectorMatcher( selector: TextQuoteSelector, -): <TChunk extends Chunk>(textChunks: AsyncIterable<TChunk>) => AsyncGenerator<AbstractRange<TChunk>, void, void> { +): <TChunk extends Chunk>(textChunks: AsyncIterable<TChunk>) => AsyncGenerator<ChunkRange<TChunk>, void, void> { return async function* matchAll<TChunk extends Chunk>(textChunks: AsyncIterable<TChunk>) { const exact = selector.exact; const prefix = selector.prefix || '';
