Skip to content

Commit

Permalink
Convert range.coffee to range.js
Browse files Browse the repository at this point in the history
- Remove xpath.coffee as it is no longer needed
- Add missing unit tests for range.js module
  • Loading branch information
Kyle Keating authored and LMS007 committed Sep 25, 2020
1 parent b00d243 commit 9fb4e54
Show file tree
Hide file tree
Showing 10 changed files with 1,036 additions and 618 deletions.
9 changes: 6 additions & 3 deletions src/annotator/anchoring/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const createNodeIterator = require('dom-node-iterator/polyfill')();

import RenderingStates from '../pdfjs-rendering-states';

// @ts-expect-error - `./range` needs to be converted to JS.
import xpathRange from './range';
import { BrowserRange } from './range';
import { toRange as textPositionToRange } from './text-position';

// @ts-expect-error - `./types` needs to be converted to JS.
Expand Down Expand Up @@ -434,7 +433,7 @@ export function anchor(root, selectors) {
* @return {Promise<[TextPositionSelector, TextQuoteSelector]>}
*/
export function describe(root, range, options = {}) {
const normalizedRange = new xpathRange.BrowserRange(range).normalize();
const normalizedRange = new BrowserRange(range).normalize();

const startTextLayer = getNodeTextLayer(normalizedRange.start);
const endTextLayer = getNodeTextLayer(normalizedRange.end);
Expand All @@ -448,6 +447,10 @@ export function describe(root, range, options = {}) {
const startRange = normalizedRange.limit(startTextLayer);
const endRange = normalizedRange.limit(endTextLayer);

if (!startRange || !endRange) {
return Promise.reject(new Error('range is outside text layer'));
}

const startPageIndex = getSiblingIndex(startTextLayer.parentNode);

const iter = createNodeIterator.call(
Expand Down
Loading

0 comments on commit 9fb4e54

Please sign in to comment.