Commit 2269088f authored by Robert Knight's avatar Robert Knight

s/Pdf/PDF

Adapt to current naming conventions for identifiers.
parent 0a82f13c
......@@ -17,7 +17,7 @@ import { TextQuoteAnchor } from './types';
*/
/**
* @typedef PdfTextRange
* @typedef PDFTextRange
* @prop {number} pageIndex
* @prop {object} anchor
* @prop {number} anchor.start - Start character offset within the page's text
......@@ -55,7 +55,7 @@ const pageTextCache = new Map();
* to speed up re-anchoring an annotation that was previously anchored in the
* current session.
*
* @type {Map<string, PdfTextRange>}
* @type {Map<string, PDFTextRange>}
*/
const quotePositionCache = new Map();
......@@ -99,7 +99,7 @@ function getNodeTextLayer(node) {
*
* @return {PDFViewer}
*/
function getPdfViewer() {
function getPDFViewer() {
// @ts-ignore - TS doesn't know about PDFViewerApplication global.
return PDFViewerApplication.pdfViewer;
}
......@@ -115,7 +115,7 @@ function getPdfViewer() {
* @return {Promise<PDFPageView>}
*/
async function getPageView(pageIndex) {
const pdfViewer = getPdfViewer();
const pdfViewer = getPDFViewer();
let pageView = pdfViewer.getPageView(pageIndex);
if (!pageView || !pageView.pdfPage) {
......@@ -153,7 +153,7 @@ async function getPageView(pageIndex) {
* Return true if the document has selectable text.
*/
export async function documentHasText() {
const viewer = getPdfViewer();
const viewer = getPDFViewer();
let hasText = false;
for (let i = 0; i < viewer.pagesCount; i++) {
const pageText = await getPageTextContent(i);
......@@ -206,7 +206,7 @@ function getPageTextContent(pageIndex) {
* @return {Promise<number>} - Offset of page's text within document text
*/
async function getPageOffset(pageIndex) {
const viewer = getPdfViewer();
const viewer = getPDFViewer();
if (pageIndex >= viewer.pagesCount) {
/* istanbul ignore next - This should never be triggered */
throw new Error('Invalid page index');
......@@ -236,7 +236,7 @@ async function getPageOffset(pageIndex) {
* @return {Promise<PageOffset>}
*/
async function findPageByOffset(offset) {
const viewer = getPdfViewer();
const viewer = getPDFViewer();
let pageStartOffset = 0;
let pageEndOffset = 0;
......@@ -387,7 +387,7 @@ function stripSpaces(str) {
async function anchorQuote(quoteSelector, positionHint) {
// Determine which pages to search and in what order. If we have a position
// hint we'll try to use that. Otherwise we'll just search all pages in order.
const pageCount = getPdfViewer().pagesCount;
const pageCount = getPDFViewer().pagesCount;
const pageIndexes = Array(pageCount)
.fill(0)
.map((_, i) => i);
......
......@@ -13,7 +13,7 @@ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
* A `<hypothesis-highlight>` element in the page's text layer
* @return {HTMLCanvasElement|null}
*/
function getPdfCanvas(highlightEl) {
function getPDFCanvas(highlightEl) {
// This code assumes that PDF.js renders pages with a structure like:
//
// <div class="page">
......@@ -51,14 +51,14 @@ function getPdfCanvas(highlightEl) {
* An element that wraps the highlighted text in the transparent text layer
* above the PDF.
*/
function drawHighlightsAbovePdfCanvas(highlightEls) {
function drawHighlightsAbovePDFCanvas(highlightEls) {
if (highlightEls.length === 0) {
return;
}
// Get the <canvas> for the PDF page containing the highlight. We assume all
// the highlights are on the same page.
const canvasEl = getPdfCanvas(highlightEls[0]);
const canvasEl = getPDFCanvas(highlightEls[0]);
if (!canvasEl || !canvasEl.parentElement) {
return;
}
......@@ -276,7 +276,7 @@ export function highlightRange(range, cssClass = 'hypothesis-highlight') {
// to reduce the number of forced reflows. We also skip creating them for
// unrendered pages for performance reasons.
if (!inPlaceholder) {
drawHighlightsAbovePdfCanvas(highlights);
drawHighlightsAbovePDFCanvas(highlights);
}
return highlights;
......
......@@ -16,7 +16,7 @@ import {
*
* This is used to test PDF-specific highlighting behavior.
*/
function PdfPage({ showPlaceholder = false }) {
function PDFPage({ showPlaceholder = false }) {
return (
<div className="page">
<div className="canvasWrapper">
......@@ -45,11 +45,11 @@ function PdfPage({ showPlaceholder = false }) {
/**
* Highlight the text in a fake PDF page.
*
* @param {HTMLElement} pageContainer - HTML element into which `PdfPage`
* @param {HTMLElement} pageContainer - HTML element into which `PDFPage`
* component has been rendered
* @return {HTMLElement} - `<hypothesis-highlight>` element
*/
function highlightPdfRange(pageContainer) {
function highlightPDFRange(pageContainer) {
const textSpan = pageContainer.querySelector('.testText');
const range = new Range();
range.setStartBefore(textSpan.childNodes[0]);
......@@ -58,15 +58,15 @@ function highlightPdfRange(pageContainer) {
}
/**
* Render a fake PDF.js page (`PdfPage`) and return its container.
* Render a fake PDF.js page (`PDFPage`) and return its container.
*
* @return {HTMLElement}
*/
function createPdfPageWithHighlight() {
function createPDFPageWithHighlight() {
const container = document.createElement('div');
render(<PdfPage />, container);
render(<PDFPage />, container);
highlightPdfRange(container);
highlightPDFRange(container);
return container;
}
......@@ -245,13 +245,13 @@ describe('annotator/highlighter', () => {
context('when the highlighted text is part of a PDF.js text layer', () => {
it("removes the highlight element's background color", () => {
const page = createPdfPageWithHighlight();
const page = createPDFPageWithHighlight();
const highlight = page.querySelector('hypothesis-highlight');
assert.isTrue(highlight.classList.contains('is-transparent'));
});
it('creates an SVG layer above the PDF canvas and draws a highlight in that', () => {
const page = createPdfPageWithHighlight();
const page = createPDFPageWithHighlight();
const canvas = page.querySelector('canvas');
const svgLayer = page.querySelector('svg');
......@@ -268,10 +268,10 @@ describe('annotator/highlighter', () => {
it('re-uses the existing SVG layer for the page if present', () => {
// Create a PDF page with a single highlight.
const page = createPdfPageWithHighlight();
const page = createPDFPageWithHighlight();
// Create a second highlight on the same page.
highlightPdfRange(page);
highlightPDFRange(page);
// There should be multiple highlights.
assert.equal(page.querySelectorAll('hypothesis-highlight').length, 2);
......@@ -287,7 +287,7 @@ describe('annotator/highlighter', () => {
it('does not create an SVG highlight if the canvas is not found', () => {
const container = document.createElement('div');
render(<PdfPage />, container);
render(<PDFPage />, container);
// Remove canvas. This might be missing if the DOM structure looks like
// PDF.js but isn't, or perhaps a future PDF.js update or fork changes
......@@ -295,7 +295,7 @@ describe('annotator/highlighter', () => {
// regular CSS-based highlighting.
container.querySelector('canvas').remove();
const [highlight] = highlightPdfRange(container);
const [highlight] = highlightPDFRange(container);
assert.isFalse(highlight.classList.contains('is-transparent'));
assert.isNull(container.querySelector('rect'));
......@@ -304,8 +304,8 @@ describe('annotator/highlighter', () => {
it('does not create an SVG highlight for placeholder highlights', () => {
const container = document.createElement('div');
render(<PdfPage showPlaceholder={true} />, container);
const [highlight] = highlightPdfRange(container);
render(<PDFPage showPlaceholder={true} />, container);
const [highlight] = highlightPDFRange(container);
// If the highlight is a placeholder, the highlight element should still
// be created.
......@@ -328,10 +328,10 @@ describe('annotator/highlighter', () => {
it('renders highlights when mix-blend-mode is supported', () => {
const container = document.createElement('div');
render(<PdfPage />, container);
render(<PDFPage />, container);
CSS.supports.withArgs('mix-blend-mode', 'multiply').returns(true);
highlightPdfRange(container);
highlightPDFRange(container);
// When mix blending is available, the highlight layer has default
// opacity and highlight rects are transparent.
......@@ -345,10 +345,10 @@ describe('annotator/highlighter', () => {
it('renders highlights when mix-blend-mode is not supported', () => {
const container = document.createElement('div');
render(<PdfPage />, container);
render(<PDFPage />, container);
CSS.supports.withArgs('mix-blend-mode', 'multiply').returns(false);
highlightPdfRange(container);
highlightPDFRange(container);
// When mix blending is not available, highlight rects are opaque and
// the entire highlight layer is transparent.
......@@ -391,7 +391,7 @@ describe('annotator/highlighter', () => {
});
it('removes any associated SVG elements external to the highlight element', () => {
const page = createPdfPageWithHighlight();
const page = createPDFPageWithHighlight();
const highlight = page.querySelector('hypothesis-highlight');
assert.instanceOf(highlight.svgHighlight, SVGElement);
......@@ -475,8 +475,8 @@ describe('annotator/highlighter', () => {
it('adds class to PDF highlights when focused', () => {
const root = document.createElement('div');
render(<PdfPage />, root);
const highlights = highlightPdfRange(root);
render(<PDFPage />, root);
const highlights = highlightPDFRange(root);
setHighlightsFocused(highlights, true);
......@@ -487,9 +487,9 @@ describe('annotator/highlighter', () => {
it('raises focused highlights in PDFs', () => {
const root = document.createElement('div');
render(<PdfPage />, root);
const highlights1 = highlightPdfRange(root);
const highlights2 = highlightPdfRange(root);
render(<PDFPage />, root);
const highlights1 = highlightPDFRange(root);
const highlights2 = highlightPDFRange(root);
const svgLayer = root.querySelector('svg');
const lastSVGHighlight = highlights =>
......@@ -504,8 +504,8 @@ describe('annotator/highlighter', () => {
it('removes class from PDF highlights when not focused', () => {
const root = document.createElement('div');
render(<PdfPage />, root);
const highlights = highlightPdfRange(root);
render(<PDFPage />, root);
const highlights = highlightPDFRange(root);
setHighlightsFocused(highlights, true);
setHighlightsFocused(highlights, false);
......
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