Use const in text_layer_builder.js

This commit is contained in:
Wojciech Maj 2019-12-22 18:18:29 +01:00
parent 6316b2a195
commit 8a8f75cf68
No known key found for this signature in database
GPG Key ID: 24A586806A31F908

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint no-var: error, prefer-const: error */
import { getGlobalEventBus } from './ui_utils'; import { getGlobalEventBus } from './ui_utils';
import { renderTextLayer } from 'pdfjs-lib'; import { renderTextLayer } from 'pdfjs-lib';
@ -64,7 +65,7 @@ class TextLayerBuilder {
this.renderingDone = true; this.renderingDone = true;
if (!this.enhanceTextSelection) { if (!this.enhanceTextSelection) {
let endOfContent = document.createElement('div'); const endOfContent = document.createElement('div');
endOfContent.className = 'endOfContent'; endOfContent.className = 'endOfContent';
this.textLayerDiv.appendChild(endOfContent); this.textLayerDiv.appendChild(endOfContent);
} }
@ -89,7 +90,7 @@ class TextLayerBuilder {
this.cancel(); this.cancel();
this.textDivs = []; this.textDivs = [];
let textLayerFrag = document.createDocumentFragment(); const textLayerFrag = document.createDocumentFragment();
this.textLayerRenderTask = renderTextLayer({ this.textLayerRenderTask = renderTextLayer({
textContent: this.textContent, textContent: this.textContent,
textContentStream: this.textContentStream, textContentStream: this.textContentStream,
@ -171,7 +172,7 @@ class TextLayerBuilder {
console.error('Could not find a matching mapping'); console.error('Could not find a matching mapping');
} }
let match = { const match = {
begin: { begin: {
divIdx: i, divIdx: i,
offset: matchIdx - iIndex, offset: matchIdx - iIndex,
@ -213,23 +214,24 @@ class TextLayerBuilder {
const selectedMatchIdx = findController.selected.matchIdx; const selectedMatchIdx = findController.selected.matchIdx;
const highlightAll = findController.state.highlightAll; const highlightAll = findController.state.highlightAll;
let prevEnd = null; let prevEnd = null;
let infinity = { const infinity = {
divIdx: -1, divIdx: -1,
offset: undefined, offset: undefined,
}; };
function beginText(begin, className) { function beginText(begin, className) {
let divIdx = begin.divIdx; const divIdx = begin.divIdx;
textDivs[divIdx].textContent = ''; textDivs[divIdx].textContent = '';
appendTextToDiv(divIdx, 0, begin.offset, className); appendTextToDiv(divIdx, 0, begin.offset, className);
} }
function appendTextToDiv(divIdx, fromOffset, toOffset, className) { function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
let div = textDivs[divIdx]; const div = textDivs[divIdx];
let content = textContentItemsStr[divIdx].substring(fromOffset, toOffset); const content =
let node = document.createTextNode(content); textContentItemsStr[divIdx].substring(fromOffset, toOffset);
const node = document.createTextNode(content);
if (className) { if (className) {
let span = document.createElement('span'); const span = document.createElement('span');
span.className = className; span.className = className;
span.appendChild(node); span.appendChild(node);
div.appendChild(span); div.appendChild(span);
@ -248,9 +250,9 @@ class TextLayerBuilder {
} }
for (let i = i0; i < i1; i++) { for (let i = i0; i < i1; i++) {
let match = matches[i]; const match = matches[i];
let begin = match.begin; const begin = match.begin;
let end = match.end; const end = match.end;
const isSelected = (isSelectedPage && i === selectedMatchIdx); const isSelected = (isSelectedPage && i === selectedMatchIdx);
const highlightSuffix = (isSelected ? ' selected' : ''); const highlightSuffix = (isSelected ? ' selected' : '');
@ -305,10 +307,10 @@ class TextLayerBuilder {
// Clear all current matches. // Clear all current matches.
for (let i = 0, ii = matches.length; i < ii; i++) { for (let i = 0, ii = matches.length; i < ii; i++) {
let match = matches[i]; const match = matches[i];
let begin = Math.max(clearedUntilDivIdx, match.begin.divIdx); const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
for (let n = begin, end = match.end.divIdx; n <= end; n++) { for (let n = begin, end = match.end.divIdx; n <= end; n++) {
let div = textDivs[n]; const div = textDivs[n];
div.textContent = textContentItemsStr[n]; div.textContent = textContentItemsStr[n];
div.className = ''; div.className = '';
} }
@ -335,7 +337,7 @@ class TextLayerBuilder {
* @private * @private
*/ */
_bindMouse() { _bindMouse() {
let div = this.textLayerDiv; const div = this.textLayerDiv;
let expandDivsTimer = null; let expandDivsTimer = null;
div.addEventListener('mousedown', (evt) => { div.addEventListener('mousedown', (evt) => {
@ -350,7 +352,7 @@ class TextLayerBuilder {
return; return;
} }
let end = div.querySelector('.endOfContent'); const end = div.querySelector('.endOfContent');
if (!end) { if (!end) {
return; return;
} }
@ -366,8 +368,8 @@ class TextLayerBuilder {
getPropertyValue('-moz-user-select') !== 'none'; getPropertyValue('-moz-user-select') !== 'none';
} }
if (adjustTop) { if (adjustTop) {
let divBounds = div.getBoundingClientRect(); const divBounds = div.getBoundingClientRect();
let r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height); const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
end.style.top = (r * 100).toFixed(2) + '%'; end.style.top = (r * 100).toFixed(2) + '%';
} }
} }
@ -390,7 +392,7 @@ class TextLayerBuilder {
return; return;
} }
let end = div.querySelector('.endOfContent'); const end = div.querySelector('.endOfContent');
if (!end) { if (!end) {
return; return;
} }