Commit fac2a28d authored by Robert Knight's avatar Robert Knight

Convert src/annotator/anchoring to ES modules

parent f2d13a01
/* global PDFViewerApplication */
const seek = require('dom-seek');
import seek from 'dom-seek';
// `dom-node-iterator` polyfills optional arguments of `createNodeIterator`
// and properties of the returned `NodeIterator` for IE 11 compatibility.
const createNodeIterator = require('dom-node-iterator/polyfill')();
const xpathRange = require('./range');
const RenderingStates = require('../pdfjs-rendering-states');
const { TextPositionAnchor, TextQuoteAnchor } = require('./types');
const { toRange: textPositionToRange } = require('./text-position');
import RenderingStates from '../pdfjs-rendering-states';
import xpathRange from './range';
import { toRange as textPositionToRange } from './text-position';
import { TextPositionAnchor, TextQuoteAnchor } from './types';
// Caches for performance.
......@@ -342,7 +343,7 @@ function prioritizePages(position) {
* @param {Array} selectors - Selector objects to anchor
* @return {Promise<Range>}
*/
function anchor(root, selectors) {
export function anchor(root, selectors) {
const position = selectors.find(s => s.type === 'TextPositionSelector');
const quote = selectors.find(s => s.type === 'TextQuoteSelector');
......@@ -406,7 +407,7 @@ function anchor(root, selectors) {
* `toSelector` methods.
* @return {Promise<[TextPositionSelector, TextQuoteSelector]>}
*/
function describe(root, range, options = {}) {
export function describe(root, range, options = {}) {
const normalizedRange = new xpathRange.BrowserRange(range).normalize();
const startTextLayer = getNodeTextLayer(normalizedRange.start);
......@@ -461,13 +462,7 @@ function describe(root, range, options = {}) {
*
* This exists mainly as a helper for use in tests.
*/
function purgeCache() {
export function purgeCache() {
pageTextCache = {};
quotePositionCache = {};
}
module.exports = {
anchor,
describe,
purgeCache,
};
......@@ -9,7 +9,7 @@
* each of the relevant classes in PDF.js.
*/
const RenderingStates = require('../../pdfjs-rendering-states');
import RenderingStates from '../../pdfjs-rendering-states';
/**
* Create the DOM structure for a page which matches the structure produced by
......@@ -197,7 +197,7 @@ class FakePDFViewer {
*
* The original is defined at https://github.com/mozilla/pdf.js/blob/master/web/app.js
*/
class FakePDFViewerApplication {
export default class FakePDFViewerApplication {
/**
* @param {Options} options
*/
......@@ -215,5 +215,3 @@ class FakePDFViewerApplication {
this.pdfViewer.dispose();
}
}
module.exports = FakePDFViewerApplication;
......@@ -21,7 +21,7 @@
// them as `<fixture name>.json` in this directory
// 4. Add an entry to the fixture list below.
module.exports = [
export default [
{
name: 'Minimal Document',
html: require('./minimal.html'),
......
const html = require('../html');
import { toResult } from '../../../shared/test/promise-util';
import * as html from '../html';
const { toResult } = require('../../../shared/test/promise-util');
const fixture = require('./html-anchoring-fixture.html');
const htmlBaselines = require('./html-baselines');
import fixture from './html-anchoring-fixture.html';
import htmlBaselines from './html-baselines';
/** Return all text node children of `container`. */
function textNodes(container) {
......
const domAnchorTextQuote = require('dom-anchor-text-quote');
import * as domAnchorTextQuote from 'dom-anchor-text-quote';
const FakePDFViewerApplication = require('./fake-pdf-viewer-application');
const pdfAnchoring = require('../pdf');
import * as pdfAnchoring from '../pdf';
import FakePDFViewerApplication from './fake-pdf-viewer-application';
/**
* Return a DOM Range which refers to the specified `text` in `container`.
......
const { toRange } = require('../text-position');
import { toRange } from '../text-position';
describe('text-position', () => {
let container;
......
const types = require('../types');
import * as types from '../types';
const TextQuoteAnchor = types.TextQuoteAnchor;
const TextPositionAnchor = types.TextPositionAnchor;
......
......@@ -21,7 +21,7 @@
* @param {number} end - Character offset within `root.textContent`
* @return {Range} Range spanning text from `start` to `end`
*/
function toRange(root, start, end) {
export function toRange(root, start, end) {
// The `filter` and `expandEntityReferences` arguments are mandatory in IE
// although optional according to the spec.
const nodeIter = root.ownerDocument.createNodeIterator(
......@@ -76,7 +76,3 @@ function toRange(root, start, end) {
return range;
}
module.exports = {
toRange,
};
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