Skip to content

Commit

Permalink
Convert types.coffee to js
Browse files Browse the repository at this point in the history
- Convert types to js
- Add missing test coverage in types module
  • Loading branch information
Kyle Keating authored and LMS007 committed Oct 2, 2020
1 parent 4033f87 commit 43f23cc
Show file tree
Hide file tree
Showing 4 changed files with 532 additions and 157 deletions.
22 changes: 7 additions & 15 deletions src/annotator/anchoring/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import RenderingStates from '../pdfjs-rendering-states';

import { BrowserRange } from './range';
import { toRange as textPositionToRange } from './text-position';

// @ts-expect-error - `./types` needs to be converted to JS.
import { TextPositionAnchor, TextQuoteAnchor } from './types';

/**
Expand Down Expand Up @@ -426,12 +424,8 @@ export function anchor(root, selectors) {
*
* @param {HTMLElement} root - The root element
* @param {Range} range
* @param {Object} options -
* Options passed to `TextQuoteAnchor` and `TextPositionAnchor`'s
* `toSelector` methods.
* @return {Promise<[TextPositionSelector, TextQuoteSelector]>}
*/
export function describe(root, range, options = {}) {
export function describe(root, range) {
const normalizedRange = new BrowserRange(range).normalize();

const startTextLayer = getNodeTextLayer(normalizedRange.start);
Expand Down Expand Up @@ -467,19 +461,17 @@ export function describe(root, range, options = {}) {
startPos += pageOffset;
endPos += pageOffset;

const position = new TextPositionAnchor(root, startPos, endPos).toSelector(
options
);
const position = new TextPositionAnchor(
root,
startPos,
endPos
).toSelector();

const quoteRange = document.createRange();
quoteRange.setStartBefore(startRange.start);
quoteRange.setEndAfter(endRange.end);

const quote = TextQuoteAnchor.fromRange(
root,
quoteRange,
options
).toSelector(options);
const quote = TextQuoteAnchor.fromRange(root, quoteRange).toSelector();

return Promise.all([position, quote]);
});
Expand Down
Loading

0 comments on commit 43f23cc

Please sign in to comment.