Commit fac2a28d authored by Robert Knight's avatar Robert Knight

Convert src/annotator/anchoring to ES modules

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