Skip to content
10 changes: 2 additions & 8 deletions external/builder/builder.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ function preprocess(inFilename, outFilename, defines) {
const out = [];
let i = 0;
function readLine() {
if (i < totalLines) {
return lines[i++];
}
return null;
return i < totalLines ? lines[i++] : null;
}
const writeLine =
typeof outFilename === "function"
Expand Down Expand Up @@ -127,10 +124,7 @@ function preprocess(inFilename, outFilename, defines) {
function expand(line) {
line = line.replaceAll(/__\w+__/g, function (variable) {
variable = variable.substring(2, variable.length - 2);
if (variable in defines) {
return defines[variable];
}
return "";
return variable in defines ? defines[variable] : "";
});
writeLine(line);
}
Expand Down
7 changes: 3 additions & 4 deletions src/core/cff_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1428,10 +1428,9 @@ class CFFFDSelect {
}

getFDIndex(glyphIndex) {
if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
return -1;
}
return this.fdSelect[glyphIndex];
return glyphIndex < 0 || glyphIndex >= this.fdSelect.length
? -1
: this.fdSelect[glyphIndex];
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/chunked_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ class ChunkedStream extends Stream {
};
Object.defineProperty(ChunkedStreamSubstream.prototype, "isDataLoaded", {
get() {
if (this.numChunksLoaded === this.numChunks) {
return true;
}
return this.getMissingChunks().length === 0;
return (
this.numChunksLoaded === this.numChunks ||
this.getMissingChunks().length === 0
);
},
configurable: true,
});
Expand Down
7 changes: 3 additions & 4 deletions src/core/decode_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ class DecodeStream extends BaseStream {

async getImageData(length, decoderOptions) {
if (!this.canAsyncDecodeImageFromBuffer) {
if (this.isAsyncDecoder) {
return this.decodeImage(null, length, decoderOptions);
}
return this.getBytes(length, decoderOptions);
return this.isAsyncDecoder
? this.decodeImage(null, length, decoderOptions)
: this.getBytes(length, decoderOptions);
}
const data = await this.stream.asyncGetBytes();
return this.decodeImage(data, length, decoderOptions);
Expand Down
5 changes: 1 addition & 4 deletions src/core/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ class Parser {
}

if (typeof buf1 === "string") {
if (cipherTransform) {
return cipherTransform.decryptString(buf1);
}
return buf1;
return cipherTransform ? cipherTransform.decryptString(buf1) : buf1;
}

// simple object
Expand Down
5 changes: 1 addition & 4 deletions src/core/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ class Stream extends BaseStream {
}

getByte() {
if (this.pos >= this.end) {
return -1;
}
return this.bytes[this.pos++];
return this.pos >= this.end ? -1 : this.bytes[this.pos++];
}

getBytes(length) {
Expand Down
14 changes: 5 additions & 9 deletions src/core/string_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@
import { stringToBytes, Util, warn } from "../shared/util.js";

function isAscii(str) {
return (
typeof str === "string" &&
// eslint-disable-next-line no-control-regex
(!str || /^[\x00-\x7F]*$/.test(str))
);
// eslint-disable-next-line no-control-regex
return typeof str === "string" && (!str || /^[\x00-\x7F]*$/.test(str));
}

// If the string is null or undefined then it is returned as is.
function stringToAsciiOrUTF16BE(str) {
if (str === null || str === undefined) {
return str;
}
return isAscii(str) ? str : stringToUTF16String(str, /* bigEndian = */ true);
return str === null || str === undefined || isAscii(str)
? str
: stringToUTF16String(str, /* bigEndian = */ true);
}

function stringToUTF16HexString(str) {
Expand Down
7 changes: 3 additions & 4 deletions src/core/to_unicode_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ class IdentityToUnicodeMap {
}

get(i) {
if (this.firstChar <= i && i <= this.lastChar) {
return String.fromCharCode(i);
}
return undefined;
return this.firstChar <= i && i <= this.lastChar
? String.fromCharCode(i)
: undefined;
}

charCodeOf(v) {
Expand Down
5 changes: 1 addition & 4 deletions src/core/xfa/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ class FontFinder {

function selectFont(xfaFont, typeface) {
if (xfaFont.posture === "italic") {
if (xfaFont.weight === "bold") {
return typeface.bolditalic;
}
return typeface.italic;
return xfaFont.weight === "bold" ? typeface.bolditalic : typeface.italic;
} else if (xfaFont.weight === "bold") {
return typeface.bold;
}
Expand Down
7 changes: 3 additions & 4 deletions src/core/xfa/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -6073,10 +6073,9 @@ class Value extends XFAObject {

[$text]() {
if (this.exData) {
if (typeof this.exData[$content] === "string") {
return this.exData[$content].trim();
}
return this.exData[$content][$text]().trim();
return typeof this.exData[$content] === "string"
? this.exData[$content].trim()
: this.exData[$content][$text]().trim();
}
for (const name of Object.getOwnPropertyNames(this)) {
if (name === "image") {
Expand Down
29 changes: 10 additions & 19 deletions src/core/xfa/xfa_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,9 @@ class XFAObject {
}

[$text]() {
if (this[_children].length === 0) {
return this[$content];
}
return this[_children].map(c => c[$text]()).join("");
return this[_children].length === 0
? this[$content]
: this[_children].map(c => c[$text]()).join("");
}

get [_attributeNames]() {
Expand Down Expand Up @@ -329,11 +328,7 @@ class XFAObject {
}

[$getChildren](name = null) {
if (!name) {
return this[_children];
}

return this[name];
return !name ? this[_children] : this[name];
}

[$dump]() {
Expand Down Expand Up @@ -680,11 +675,9 @@ class XFAObject {
}

[$getChildren](name = null) {
if (!name) {
return this[_children];
}

return this[_children].filter(c => c[$nodeName] === name);
return !name
? this[_children]
: this[_children].filter(c => c[$nodeName] === name);
}

[$getChildrenByClass](name) {
Expand Down Expand Up @@ -909,11 +902,9 @@ class XmlObject extends XFAObject {
}

[$getChildren](name = null) {
if (!name) {
return this[_children];
}

return this[_children].filter(c => c[$nodeName] === name);
return !name
? this[_children]
: this[_children].filter(c => c[$nodeName] === name);
}

[$getAttributes]() {
Expand Down
7 changes: 3 additions & 4 deletions src/core/xml_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,9 @@ class SimpleDOMNode {
}

get textContent() {
if (!this.childNodes) {
return this.nodeValue || "";
}
return this.childNodes.map(child => child.textContent).join("");
return !this.childNodes
? this.nodeValue || ""
: this.childNodes.map(child => child.textContent).join("");
}

get children() {
Expand Down
5 changes: 1 addition & 4 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3122,10 +3122,7 @@ class PopupElement {
}

get isVisible() {
if (this.#commentManager) {
return false;
}
return this.#container.hidden === false;
return !this.#commentManager && this.#container.hidden === false;
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/display/canvas_dependency_tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,7 @@ class CanvasBBoxTracker {
}

getOpenMarker() {
if (this._savesStack.length === 0) {
return null;
}
return this._savesStack.at(-1);
return this._savesStack.length === 0 ? null : this._savesStack.at(-1);
}

recordCloseMarker(opIdx, onSavePopped) {
Expand Down
14 changes: 6 additions & 8 deletions src/display/editor/alt_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,15 @@ class AltText {
}

isEmpty() {
if (this.#useNewAltTextFlow) {
return this.#altText === null;
}
return !this.#altText && !this.#altTextDecorative;
return this.#useNewAltTextFlow
? this.#altText === null
: !this.#altText && !this.#altTextDecorative;
}

hasData() {
if (this.#useNewAltTextFlow) {
return this.#altText !== null || !!this.#guessedText;
}
return this.isEmpty();
return this.#useNewAltTextFlow
? this.#altText !== null || !!this.#guessedText
: this.isEmpty();
}

get guessedText() {
Expand Down
5 changes: 1 addition & 4 deletions src/display/editor/drawers/inkdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,7 @@ class InkDrawOutline extends Outline {
}

updateProperty(name, value) {
if (name === "stroke-width") {
return this.#updateThickness(value);
}
return null;
return name === "stroke-width" ? this.#updateThickness(value) : null;
}

#updateThickness(thickness) {
Expand Down
7 changes: 3 additions & 4 deletions src/display/editor/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,9 @@ class SignatureEditor extends DrawingEditor {

/** @inheritdoc */
get toolbarButtons() {
if (this._uiManager.signatureManager) {
return [["editSignature", this._uiManager.signatureManager]];
}
return super.toolbarButtons;
return this._uiManager.signatureManager
? [["editSignature", this._uiManager.signatureManager]]
: super.toolbarButtons;
}

addSignature(data, heightInPage, description, uuid) {
Expand Down
22 changes: 18 additions & 4 deletions src/display/touch_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

import { OutputScale, stopEvent } from "./display_utils.js";

function preventDefault(evt) {
evt.preventDefault();
}

class TouchManager {
#container;

Expand Down Expand Up @@ -135,8 +139,13 @@ class TouchManager {
opt.capture = true;
container.addEventListener("pointerdown", stopEvent, opt);
container.addEventListener("pointermove", stopEvent, opt);
container.addEventListener("pointercancel", stopEvent, opt);
container.addEventListener("pointerup", stopEvent, opt);
// `pointerup` and `pointercancel` are only default-prevented: a
// `stopPropagation` in the capture phase also skips the bubble-phase
// listeners of the very node it's called on, hence swallowing them here
// would prevent any session in flight, e.g. an editor being resized, from
// ever being ended.
container.addEventListener("pointercancel", preventDefault, opt);
container.addEventListener("pointerup", preventDefault, opt);
this.#onPinchStart?.();
}

Expand Down Expand Up @@ -189,7 +198,7 @@ class TouchManager {
const pDistance = Math.hypot(prevGapX, prevGapY) || 1;
if (
!this.#isPinching &&
Math.abs(pDistance - distance) <= TouchManager.MIN_TOUCH_DISTANCE_TO_PINCH
Math.abs(pDistance - distance) <= this.MIN_TOUCH_DISTANCE_TO_PINCH
) {
return;
}
Expand All @@ -207,7 +216,12 @@ class TouchManager {
return;
}

const origin = [(screen0X + screen1X) / 2, (screen0Y + screen1Y) / 2];
// The distances are in screen CSS pixels, but the origin must be in client
// coordinates, like the one coming from a wheel event.
const origin = [
(touch0.clientX + touch1.clientX) / 2,
(touch0.clientY + touch1.clientY) / 2,
];
this.#onPinching?.(origin, pDistance, distance);
}

Expand Down
18 changes: 6 additions & 12 deletions src/pdf.sandbox.external.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,12 @@ export class SandboxSupportBase {
}
this.win.alert(cMsg);
},
confirm: cMsg => {
if (typeof cMsg !== "string") {
return false;
}
return this.win.confirm(cMsg);
},
prompt: (cQuestion, cDefault) => {
if (typeof cQuestion !== "string" || typeof cDefault !== "string") {
return null;
}
return this.win.prompt(cQuestion, cDefault);
},
confirm: cMsg =>
typeof cMsg !== "string" ? false : this.win.confirm(cMsg),
prompt: (cQuestion, cDefault) =>
typeof cQuestion !== "string" || typeof cDefault !== "string"
? null
: this.win.prompt(cQuestion, cDefault),
parseURL: cUrl => {
const url = new this.win.URL(cUrl);
const props = [
Expand Down
Loading
Loading