Convert let
to const
if possible in src/display/display_utils.js
Finally, `var` usage is removed.
This commit is contained in:
parent
c43396c2b7
commit
87a70f3359
@ -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 */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
assert, CMapCompressionType, removeNullCharacters, stringToBytes,
|
assert, CMapCompressionType, removeNullCharacters, stringToBytes,
|
||||||
@ -24,10 +25,10 @@ const SVG_NS = 'http://www.w3.org/2000/svg';
|
|||||||
class DOMCanvasFactory {
|
class DOMCanvasFactory {
|
||||||
create(width, height) {
|
create(width, height) {
|
||||||
if (width <= 0 || height <= 0) {
|
if (width <= 0 || height <= 0) {
|
||||||
throw new Error('invalid canvas size');
|
throw new Error('Invalid canvas size');
|
||||||
}
|
}
|
||||||
let canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
let context = canvas.getContext('2d');
|
const context = canvas.getContext('2d');
|
||||||
canvas.width = width;
|
canvas.width = width;
|
||||||
canvas.height = height;
|
canvas.height = height;
|
||||||
return {
|
return {
|
||||||
@ -38,10 +39,10 @@ class DOMCanvasFactory {
|
|||||||
|
|
||||||
reset(canvasAndContext, width, height) {
|
reset(canvasAndContext, width, height) {
|
||||||
if (!canvasAndContext.canvas) {
|
if (!canvasAndContext.canvas) {
|
||||||
throw new Error('canvas is not specified');
|
throw new Error('Canvas is not specified');
|
||||||
}
|
}
|
||||||
if (width <= 0 || height <= 0) {
|
if (width <= 0 || height <= 0) {
|
||||||
throw new Error('invalid canvas size');
|
throw new Error('Invalid canvas size');
|
||||||
}
|
}
|
||||||
canvasAndContext.canvas.width = width;
|
canvasAndContext.canvas.width = width;
|
||||||
canvasAndContext.canvas.height = height;
|
canvasAndContext.canvas.height = height;
|
||||||
@ -49,7 +50,7 @@ class DOMCanvasFactory {
|
|||||||
|
|
||||||
destroy(canvasAndContext) {
|
destroy(canvasAndContext) {
|
||||||
if (!canvasAndContext.canvas) {
|
if (!canvasAndContext.canvas) {
|
||||||
throw new Error('canvas is not specified');
|
throw new Error('Canvas is not specified');
|
||||||
}
|
}
|
||||||
// Zeroing the width and height cause Firefox to release graphics
|
// Zeroing the width and height cause Firefox to release graphics
|
||||||
// resources immediately, which can greatly reduce memory consumption.
|
// resources immediately, which can greatly reduce memory consumption.
|
||||||
@ -137,7 +138,7 @@ class DOMSVGFactory {
|
|||||||
create(width, height) {
|
create(width, height) {
|
||||||
assert(width > 0 && height > 0, 'Invalid SVG dimensions');
|
assert(width > 0 && height > 0, 'Invalid SVG dimensions');
|
||||||
|
|
||||||
let svg = document.createElementNS(SVG_NS, 'svg:svg');
|
const svg = document.createElementNS(SVG_NS, 'svg:svg');
|
||||||
svg.setAttribute('version', '1.1');
|
svg.setAttribute('version', '1.1');
|
||||||
svg.setAttribute('width', width + 'px');
|
svg.setAttribute('width', width + 'px');
|
||||||
svg.setAttribute('height', height + 'px');
|
svg.setAttribute('height', height + 'px');
|
||||||
@ -194,8 +195,8 @@ class PageViewport {
|
|||||||
|
|
||||||
// creating transform to convert pdf coordinate system to the normal
|
// creating transform to convert pdf coordinate system to the normal
|
||||||
// canvas like coordinates taking in account scale and rotation
|
// canvas like coordinates taking in account scale and rotation
|
||||||
let centerX = (viewBox[2] + viewBox[0]) / 2;
|
const centerX = (viewBox[2] + viewBox[0]) / 2;
|
||||||
let centerY = (viewBox[3] + viewBox[1]) / 2;
|
const centerY = (viewBox[3] + viewBox[1]) / 2;
|
||||||
let rotateA, rotateB, rotateC, rotateD;
|
let rotateA, rotateB, rotateC, rotateD;
|
||||||
rotation = rotation % 360;
|
rotation = rotation % 360;
|
||||||
rotation = rotation < 0 ? rotation + 360 : rotation;
|
rotation = rotation < 0 ? rotation + 360 : rotation;
|
||||||
@ -287,9 +288,9 @@ class PageViewport {
|
|||||||
* @see {@link convertToViewportPoint}
|
* @see {@link convertToViewportPoint}
|
||||||
*/
|
*/
|
||||||
convertToViewportRectangle(rect) {
|
convertToViewportRectangle(rect) {
|
||||||
let tl = Util.applyTransform([rect[0], rect[1]], this.transform);
|
const topLeft = Util.applyTransform([rect[0], rect[1]], this.transform);
|
||||||
let br = Util.applyTransform([rect[2], rect[3]], this.transform);
|
const bottomRight = Util.applyTransform([rect[2], rect[3]], this.transform);
|
||||||
return [tl[0], tl[1], br[0], br[1]];
|
return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -306,7 +307,7 @@ class PageViewport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var RenderingCancelledException = (function RenderingCancelledException() {
|
const RenderingCancelledException = (function RenderingCancelledException() {
|
||||||
function RenderingCancelledException(msg, type) {
|
function RenderingCancelledException(msg, type) {
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -332,7 +333,7 @@ const LinkTargetStringMap = [
|
|||||||
'_self',
|
'_self',
|
||||||
'_blank',
|
'_blank',
|
||||||
'_parent',
|
'_parent',
|
||||||
'_top'
|
'_top',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,7 +356,7 @@ function addLinkAttributes(link, { url, target, rel, } = {}) {
|
|||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
const LinkTargetValues = Object.values(LinkTarget);
|
const LinkTargetValues = Object.values(LinkTarget);
|
||||||
let targetIndex =
|
const targetIndex =
|
||||||
LinkTargetValues.includes(target) ? target : LinkTarget.NONE;
|
LinkTargetValues.includes(target) ? target : LinkTarget.NONE;
|
||||||
link.target = LinkTargetStringMap[targetIndex];
|
link.target = LinkTargetStringMap[targetIndex];
|
||||||
|
|
||||||
@ -365,11 +366,10 @@ function addLinkAttributes(link, { url, target, rel, } = {}) {
|
|||||||
|
|
||||||
// Gets the file name from a given URL.
|
// Gets the file name from a given URL.
|
||||||
function getFilenameFromUrl(url) {
|
function getFilenameFromUrl(url) {
|
||||||
var anchor = url.indexOf('#');
|
const anchor = url.indexOf('#');
|
||||||
var query = url.indexOf('?');
|
const query = url.indexOf('?');
|
||||||
var end = Math.min(
|
const end = Math.min(anchor > 0 ? anchor : url.length,
|
||||||
anchor > 0 ? anchor : url.length,
|
query > 0 ? query : url.length);
|
||||||
query > 0 ? query : url.length);
|
|
||||||
return url.substring(url.lastIndexOf('/', end) + 1, end);
|
return url.substring(url.lastIndexOf('/', end) + 1, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,19 +407,17 @@ class StatTimer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
let times = this.times;
|
|
||||||
// Find the longest name for padding purposes.
|
// Find the longest name for padding purposes.
|
||||||
let out = '', longest = 0;
|
let out = '', longest = 0;
|
||||||
for (let i = 0, ii = times.length; i < ii; ++i) {
|
for (const time of this.times) {
|
||||||
let name = times[i]['name'];
|
const name = time.name;
|
||||||
if (name.length > longest) {
|
if (name.length > longest) {
|
||||||
longest = name.length;
|
longest = name.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let i = 0, ii = times.length; i < ii; ++i) {
|
for (const time of this.times) {
|
||||||
let span = times[i];
|
const duration = time.end - time.start;
|
||||||
let duration = span.end - span.start;
|
out += `${time.name.padEnd(longest)} ${duration}ms\n`;
|
||||||
out += `${span['name'].padEnd(longest)} ${duration}ms\n`;
|
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -466,7 +464,7 @@ function isValidFetchUrl(url, baseUrl) {
|
|||||||
|
|
||||||
function loadScript(src) {
|
function loadScript(src) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.src = src;
|
script.src = src;
|
||||||
|
|
||||||
script.onload = resolve;
|
script.onload = resolve;
|
||||||
|
Loading…
Reference in New Issue
Block a user