Commit 273f0d26 authored by Robert Knight's avatar Robert Knight

Switch type of `root` argument from `Node` to `Element`

This will be useful for switching the position selector anchoring code to use the
`TextRange` class. The one place where a non-Element node was passed was
from `anchoring/pdf.js`, a context where we can easily create a dummy
element.
parent 4bc0beed
......@@ -21,7 +21,7 @@ async function querySelector(anchor, options = {}) {
* It encapsulates the core anchoring algorithm, using the selectors alone or
* in combination to establish the best anchor within the document.
*
* @param {Node} root - The root element of the anchoring context.
* @param {Element} root - The root element of the anchoring context.
* @param {Selector[]} selectors - The selectors to try.
* @param {Object} [options]
* @param {number} [options.hint]
......@@ -89,7 +89,7 @@ export function anchor(root, selectors, options = {}) {
}
/**
* @param {Node} root
* @param {Element} root
* @param {Range} range
*/
export function describe(root, range) {
......
......@@ -330,7 +330,8 @@ function findInPages(pageIndexes, quoteSelector, positionHint) {
const offset = getPageOffset(pageIndex);
const attempt = ([content, offset]) => {
const root = { textContent: content };
const root = document.createElement('div');
root.textContent = content;
const anchor = TextQuoteAnchor.fromSelector(root, quoteSelector);
if (positionHint) {
let hint = positionHint.start - offset;
......
......@@ -94,7 +94,7 @@ export class RangeAnchor {
*/
export class TextPositionAnchor {
/**
* @param {Node|TextContentNode} root
* @param {Element} root
* @param {number} start
* @param {number} end
*/
......@@ -105,7 +105,7 @@ export class TextPositionAnchor {
}
/**
* @param {Node} root
* @param {Element} root
* @param {Range} range
*/
static fromRange(root, range) {
......@@ -113,7 +113,7 @@ export class TextPositionAnchor {
return TextPositionAnchor.fromSelector(root, selector);
}
/**
* @param {Node} root
* @param {Element} root
* @param {TextPositionSelector} selector
*/
static fromSelector(root, selector) {
......@@ -141,7 +141,7 @@ export class TextPositionAnchor {
*/
export class TextQuoteAnchor {
/**
* @param {Node|TextContentNode} root - A root element from which to anchor.
* @param {Element} root - A root element from which to anchor.
* @param {string} exact
* @param {Object} context
* @param {string} [context.prefix]
......@@ -153,7 +153,7 @@ export class TextQuoteAnchor {
this.context = context;
}
/**
* @param {Node} root
* @param {Element} root
* @param {Range} range
*/
static fromRange(root, range) {
......@@ -162,7 +162,7 @@ export class TextQuoteAnchor {
}
/**
* @param {Node|TextContentNode} root
* @param {Element} root
* @param {TextQuoteSelector} selector
*/
static fromSelector(root, selector) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment