Enable the unicorn/prefer-ternary ESLint plugin rule

To limit the readability impact of these changes, the `only-single-line` option was used; please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-ternary.md

These changes were done automatically, using the `gulp lint --fix` command.
This commit is contained in:
Jonas Jenwald 2023-07-27 09:18:26 +02:00
parent 8f83a1359e
commit 674e7ee381
31 changed files with 123 additions and 265 deletions

View File

@ -78,6 +78,7 @@
"unicorn/prefer-regexp-test": "error", "unicorn/prefer-regexp-test": "error",
"unicorn/prefer-string-replace-all": "error", "unicorn/prefer-string-replace-all": "error",
"unicorn/prefer-string-starts-ends-with": "error", "unicorn/prefer-string-starts-ends-with": "error",
"unicorn/prefer-ternary": ["error", "only-single-line"],
// Possible errors // Possible errors
"for-direction": "error", "for-direction": "error",

View File

@ -784,11 +784,10 @@ class Annotation {
* @param {Array} rectangle - The rectangle array with exactly four entries * @param {Array} rectangle - The rectangle array with exactly four entries
*/ */
setRectangle(rectangle) { setRectangle(rectangle) {
if (Array.isArray(rectangle) && rectangle.length === 4) { this.rectangle =
this.rectangle = Util.normalizeRect(rectangle); Array.isArray(rectangle) && rectangle.length === 4
} else { ? Util.normalizeRect(rectangle)
this.rectangle = [0, 0, 0, 0]; : [0, 0, 0, 0];
}
} }
/** /**
@ -841,11 +840,7 @@ class Annotation {
setRotation(mk, dict) { setRotation(mk, dict) {
this.rotation = 0; this.rotation = 0;
let angle; let angle;
if (mk instanceof Dict) { angle = mk instanceof Dict ? mk.get("R") || 0 : dict.get("Rotate") || 0;
angle = mk.get("R") || 0;
} else {
angle = dict.get("Rotate") || 0;
}
if (Number.isInteger(angle) && angle !== 0) { if (Number.isInteger(angle) && angle !== 0) {
angle %= 360; angle %= 360;
if (angle < 0) { if (angle < 0) {
@ -2815,11 +2810,9 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
if (value === null || value === undefined) { if (value === null || value === undefined) {
// There is no default appearance so use the one derived // There is no default appearance so use the one derived
// from the field value. // from the field value.
if (this.data.checkBox) { value = this.data.checkBox
value = this.data.fieldValue === this.data.exportValue; ? this.data.fieldValue === this.data.exportValue
} else { : this.data.fieldValue === this.data.buttonValue;
value = this.data.fieldValue === this.data.buttonValue;
}
} }
const appearance = value const appearance = value
@ -3610,11 +3603,10 @@ class PopupAnnotation extends Annotation {
} }
const parentRect = parentItem.getArray("Rect"); const parentRect = parentItem.getArray("Rect");
if (Array.isArray(parentRect) && parentRect.length === 4) { this.data.parentRect =
this.data.parentRect = Util.normalizeRect(parentRect); Array.isArray(parentRect) && parentRect.length === 4
} else { ? Util.normalizeRect(parentRect)
this.data.parentRect = null; : null;
}
const rt = parentItem.get("RT"); const rt = parentItem.get("RT");
if (isName(rt, AnnotationReplyType.GROUP)) { if (isName(rt, AnnotationReplyType.GROUP)) {

View File

@ -786,11 +786,10 @@ class CCITTFaxDecoder {
} }
} }
if (codingLine[0] > 0) { this.outputBits =
this.outputBits = codingLine[(this.codingPos = 0)]; codingLine[0] > 0
} else { ? codingLine[(this.codingPos = 0)]
this.outputBits = codingLine[(this.codingPos = 1)]; : codingLine[(this.codingPos = 1)];
}
this.row++; this.row++;
} }
@ -964,11 +963,7 @@ class CCITTFaxDecoder {
return 1; return 1;
} }
if (code >> 5 === 0) { p = code >> 5 === 0 ? whiteTable1[code] : whiteTable2[code >> 3];
p = whiteTable1[code];
} else {
p = whiteTable2[code >> 3];
}
if (p[0] > 0) { if (p[0] > 0) {
this._eatBits(p[0]); this._eatBits(p[0]);

View File

@ -559,11 +559,7 @@ class CFFParser {
validationCommand = CharstringValidationData[value]; validationCommand = CharstringValidationData[value];
} else if (value === 10 || value === 29) { } else if (value === 10 || value === 29) {
let subrsIndex; let subrsIndex;
if (value === 10) { subrsIndex = value === 10 ? localSubrIndex : globalSubrIndex;
subrsIndex = localSubrIndex;
} else {
subrsIndex = globalSubrIndex;
}
if (!subrsIndex) { if (!subrsIndex) {
validationCommand = CharstringValidationData[value]; validationCommand = CharstringValidationData[value];
warn("Missing subrsIndex for " + validationCommand.id); warn("Missing subrsIndex for " + validationCommand.id);

View File

@ -1306,11 +1306,7 @@ const LabCS = (function LabCSClosure() {
// Function g(x) from spec // Function g(x) from spec
function fn_g(x) { function fn_g(x) {
let result; let result;
if (x >= 6 / 29) { result = x >= 6 / 29 ? x ** 3 : (108 / 841) * (x - 4 / 29);
result = x ** 3;
} else {
result = (108 / 841) * (x - 4 / 29);
}
return result; return result;
} }

View File

@ -795,11 +795,7 @@ class AESBaseCipher {
this._mixCol = new Uint8Array(256); this._mixCol = new Uint8Array(256);
for (let i = 0; i < 256; i++) { for (let i = 0; i < 256; i++) {
if (i < 128) { this._mixCol[i] = i < 128 ? i << 1 : (i << 1) ^ 0x1b;
this._mixCol[i] = i << 1;
} else {
this._mixCol[i] = (i << 1) ^ 0x1b;
}
} }
this.buffer = new Uint8Array(16); this.buffer = new Uint8Array(16);
@ -1450,11 +1446,7 @@ const CipherTransformFactory = (function CipherTransformFactoryClosure() {
password = []; password = [];
} }
let pdfAlgorithm; let pdfAlgorithm;
if (revision === 6) { pdfAlgorithm = revision === 6 ? new PDF20() : new PDF17();
pdfAlgorithm = new PDF20();
} else {
pdfAlgorithm = new PDF17();
}
if ( if (
pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword) pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)

View File

@ -1707,11 +1707,7 @@ class PDFDocument {
const field = this.xref.fetchIfRef(fieldRef); const field = this.xref.fetchIfRef(fieldRef);
if (field.has("T")) { if (field.has("T")) {
const partName = stringToPDFString(field.get("T")); const partName = stringToPDFString(field.get("T"));
if (name === "") { name = name === "" ? partName : `${name}.${partName}`;
name = partName;
} else {
name = `${name}.${partName}`;
}
} }
if (!field.has("Kids") && /\[\d+\]$/.test(name)) { if (!field.has("Kids") && /\[\d+\]$/.test(name)) {

View File

@ -463,11 +463,10 @@ class PartialEvaluator {
const dict = xobj.dict; const dict = xobj.dict;
const matrix = dict.getArray("Matrix"); const matrix = dict.getArray("Matrix");
let bbox = dict.getArray("BBox"); let bbox = dict.getArray("BBox");
if (Array.isArray(bbox) && bbox.length === 4) { bbox =
bbox = Util.normalizeRect(bbox); Array.isArray(bbox) && bbox.length === 4
} else { ? Util.normalizeRect(bbox)
bbox = null; : null;
}
let optionalContent, groupOptions; let optionalContent, groupOptions;
if (dict.has("OC")) { if (dict.has("OC")) {
@ -795,11 +794,9 @@ class PartialEvaluator {
if (cacheKey && imageRef && cacheGlobally) { if (cacheKey && imageRef && cacheGlobally) {
let length = 0; let length = 0;
if (imgData.bitmap) { length = imgData.bitmap
length = imgData.width * imgData.height * 4; ? imgData.width * imgData.height * 4
} else { : imgData.data.length;
length = imgData.data.length;
}
this.globalImageCache.addByteSize(imageRef, length); this.globalImageCache.addByteSize(imageRef, length);
} }
@ -3953,11 +3950,7 @@ class PartialEvaluator {
if (!(lookupName in Metrics)) { if (!(lookupName in Metrics)) {
// Use default fonts for looking up font metrics if the passed // Use default fonts for looking up font metrics if the passed
// font is not a base font // font is not a base font
if (this.isSerifFont(name)) { lookupName = this.isSerifFont(name) ? "Times-Roman" : "Helvetica";
lookupName = "Times-Roman";
} else {
lookupName = "Helvetica";
}
} }
const glyphWidths = Metrics[lookupName]; const glyphWidths = Metrics[lookupName];

View File

@ -376,17 +376,9 @@ function getFontFileType(file, { type, subtype, composite }) {
let fileType, fileSubtype; let fileType, fileSubtype;
if (isTrueTypeFile(file) || isTrueTypeCollectionFile(file)) { if (isTrueTypeFile(file) || isTrueTypeCollectionFile(file)) {
if (composite) { fileType = composite ? "CIDFontType2" : "TrueType";
fileType = "CIDFontType2";
} else {
fileType = "TrueType";
}
} else if (isOpenTypeFile(file)) { } else if (isOpenTypeFile(file)) {
if (composite) { fileType = composite ? "CIDFontType2" : "OpenType";
fileType = "CIDFontType2";
} else {
fileType = "OpenType";
}
} else if (isType1File(file)) { } else if (isType1File(file)) {
if (composite) { if (composite) {
fileType = "CIDFontType0"; fileType = "CIDFontType0";

View File

@ -247,11 +247,7 @@ class PDFFunction {
} }
let decode = toNumberArray(dict.getArray("Decode")); let decode = toNumberArray(dict.getArray("Decode"));
if (!decode) { decode = !decode ? range : toMultiArray(decode);
decode = range;
} else {
decode = toMultiArray(decode);
}
const samples = this.getSampleArray(size, outputSize, bps, fn); const samples = this.getSampleArray(size, outputSize, bps, fn);
// const mask = 2 ** bps - 1; // const mask = 2 ** bps - 1;

View File

@ -386,11 +386,10 @@ function decodeScan(
let mcu = 0, let mcu = 0,
fileMarker; fileMarker;
let mcuExpected; let mcuExpected;
if (componentsLength === 1) { mcuExpected =
mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn; componentsLength === 1
} else { ? components[0].blocksPerLine * components[0].blocksPerColumn
mcuExpected = mcusPerLine * frame.mcusPerColumn; : mcusPerLine * frame.mcusPerColumn;
}
let h, v; let h, v;
while (mcu <= mcuExpected) { while (mcu <= mcuExpected) {

View File

@ -1384,11 +1384,7 @@ function copyCoefficients(
} }
nb = bitsDecoded[position]; nb = bitsDecoded[position];
const pos = interleave ? levelOffset + (offset << 1) : offset; const pos = interleave ? levelOffset + (offset << 1) : offset;
if (reversible && nb >= mb) { coefficients[pos] = reversible && nb >= mb ? n : n * (1 << (mb - nb));
coefficients[pos] = n;
} else {
coefficients[pos] = n * (1 << (mb - nb));
}
} }
offset++; offset++;
position++; position++;

View File

@ -589,11 +589,10 @@ class OperatorList {
this._streamSink = streamSink; this._streamSink = streamSink;
this.fnArray = []; this.fnArray = [];
this.argsArray = []; this.argsArray = [];
if (streamSink && !(intent & RenderingIntentFlag.OPLIST)) { this.optimizer =
this.optimizer = new QueueOptimizer(this); streamSink && !(intent & RenderingIntentFlag.OPLIST)
} else { ? new QueueOptimizer(this)
this.optimizer = new NullOptimizer(this); : new NullOptimizer(this);
}
this.dependencies = new Set(); this.dependencies = new Set();
this._totalLength = 0; this._totalLength = 0;
this.weight = 0; this.weight = 0;

View File

@ -116,11 +116,10 @@ class RadialAxialShading extends BaseShading {
localColorSpaceCache, localColorSpaceCache,
}); });
const bbox = dict.getArray("BBox"); const bbox = dict.getArray("BBox");
if (Array.isArray(bbox) && bbox.length === 4) { this.bbox =
this.bbox = Util.normalizeRect(bbox); Array.isArray(bbox) && bbox.length === 4
} else { ? Util.normalizeRect(bbox)
this.bbox = null; : null;
}
let t0 = 0.0, let t0 = 0.0,
t1 = 1.0; t1 = 1.0;
@ -458,11 +457,10 @@ class MeshShading extends BaseShading {
const dict = stream.dict; const dict = stream.dict;
this.shadingType = dict.get("ShadingType"); this.shadingType = dict.get("ShadingType");
const bbox = dict.getArray("BBox"); const bbox = dict.getArray("BBox");
if (Array.isArray(bbox) && bbox.length === 4) { this.bbox =
this.bbox = Util.normalizeRect(bbox); Array.isArray(bbox) && bbox.length === 4
} else { ? Util.normalizeRect(bbox)
this.bbox = null; : null;
}
const cs = ColorSpace.parse({ const cs = ColorSpace.parse({
cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"), cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
xref, xref,

View File

@ -33,11 +33,7 @@ class PredictorStream extends DecodeStream {
throw new FormatError(`Unsupported predictor: ${predictor}`); throw new FormatError(`Unsupported predictor: ${predictor}`);
} }
if (predictor === 2) { this.readBlock = predictor === 2 ? this.readBlockTiff : this.readBlockPng;
this.readBlock = this.readBlockTiff;
} else {
this.readBlock = this.readBlockPng;
}
this.str = str; this.str = str;
this.dict = str.dict; this.dict = str.dict;

View File

@ -203,11 +203,9 @@ function writeXFADataForAcroform(str, newRefs) {
node = xml.documentElement.searchNode([nodePath.at(-1)], 0); node = xml.documentElement.searchNode([nodePath.at(-1)], 0);
} }
if (node) { if (node) {
if (Array.isArray(value)) { node.childNodes = Array.isArray(value)
node.childNodes = value.map(val => new SimpleDOMNode("value", val)); ? value.map(val => new SimpleDOMNode("value", val))
} else { : [new SimpleDOMNode("#text", value)];
node.childNodes = [new SimpleDOMNode("#text", value)];
}
} else { } else {
warn(`Node not found for path: ${path}`); warn(`Node not found for path: ${path}`);
} }

View File

@ -55,11 +55,9 @@ class Binder {
constructor(root) { constructor(root) {
this.root = root; this.root = root;
this.datasets = root.datasets; this.datasets = root.datasets;
if (root.datasets?.data) { this.data = root.datasets?.data
this.data = root.datasets.data; ? root.datasets.data
} else { : new XmlObject(NamespaceIds.datasets.id, "data");
this.data = new XmlObject(NamespaceIds.datasets.id, "data");
}
this.emptyMerge = this.data[$getChildren]().length === 0; this.emptyMerge = this.data[$getChildren]().length === 0;
this.root.form = this.form = root.template[$clone](); this.root.form = this.form = root.template[$clone]();

View File

@ -103,17 +103,9 @@ const converters = {
} }
} }
if (width !== "") { style.width = width !== "" ? measureToString(width) : "auto";
style.width = measureToString(width);
} else {
style.width = "auto";
}
if (height !== "") { style.height = height !== "" ? measureToString(height) : "auto";
style.height = measureToString(height);
} else {
style.height = "auto";
}
}, },
position(node, style) { position(node, style) {
const parent = node[$getSubformParent](); const parent = node[$getSubformParent]();
@ -305,11 +297,7 @@ function computeBbox(node, html, availableSpace) {
if (width === "") { if (width === "") {
if (node.maxW === 0) { if (node.maxW === 0) {
const parent = node[$getSubformParent](); const parent = node[$getSubformParent]();
if (parent.layout === "position" && parent.w !== "") { width = parent.layout === "position" && parent.w !== "" ? 0 : node.minW;
width = 0;
} else {
width = node.minW;
}
} else { } else {
width = Math.min(node.maxW, availableSpace.width); width = Math.min(node.maxW, availableSpace.width);
} }
@ -320,11 +308,8 @@ function computeBbox(node, html, availableSpace) {
if (height === "") { if (height === "") {
if (node.maxH === 0) { if (node.maxH === 0) {
const parent = node[$getSubformParent](); const parent = node[$getSubformParent]();
if (parent.layout === "position" && parent.h !== "") { height =
height = 0; parent.layout === "position" && parent.h !== "" ? 0 : node.minH;
} else {
height = node.minH;
}
} else { } else {
height = Math.min(node.maxH, availableSpace.height); height = Math.min(node.maxH, availableSpace.height);
} }
@ -510,11 +495,8 @@ function createWrapper(node, html) {
} }
} }
if (style.position === "absolute") { wrapper.attributes.style.position =
wrapper.attributes.style.position = "absolute"; style.position === "absolute" ? "absolute" : "relative";
} else {
wrapper.attributes.style.position = "relative";
}
delete style.position; delete style.position;
if (style.alignSelf) { if (style.alignSelf) {

View File

@ -211,11 +211,9 @@ function searchNode(
break; break;
case operators.dotHash: case operators.dotHash:
children = node[$getChildrenByClass](name); children = node[$getChildrenByClass](name);
if (children.isXFAObjectArray) { children = children.isXFAObjectArray
children = children.children; ? children.children
} else { : [children];
children = [children];
}
break; break;
default: default:
break; break;
@ -244,11 +242,9 @@ function searchNode(
continue; continue;
} }
if (isFinite(index)) { root = isFinite(index)
root = nodes.filter(node => index < node.length).map(node => node[index]); ? nodes.filter(node => index < node.length).map(node => node[index])
} else { : nodes.flat();
root = nodes.flat();
}
} }
if (root.length === 0) { if (root.length === 0) {
@ -294,11 +290,7 @@ function createDataNode(root, container, expr) {
break; break;
case operators.dotHash: case operators.dotHash:
children = root[$getChildrenByClass](name); children = root[$getChildrenByClass](name);
if (children.isXFAObjectArray) { children = children.isXFAObjectArray ? children.children : [children];
children = children.children;
} else {
children = [children];
}
break; break;
default: default:
break; break;

View File

@ -271,11 +271,7 @@ function applyAssist(obj, attributes) {
} else { } else {
const parent = obj[$getParent](); const parent = obj[$getParent]();
if (parent.layout === "row") { if (parent.layout === "row") {
if (parent.assist?.role === "TH") { attributes.role = parent.assist?.role === "TH" ? "columnheader" : "cell";
attributes.role = "columnheader";
} else {
attributes.role = "cell";
}
} }
} }
} }

View File

@ -657,11 +657,10 @@ class XFAObject {
continue; continue;
} }
const value = this[name]; const value = this[name];
if (value instanceof XFAObjectArray) { clone[name] =
clone[name] = new XFAObjectArray(value[_max]); value instanceof XFAObjectArray
} else { ? new XFAObjectArray(value[_max])
clone[name] = null; : null;
}
} }
for (const child of this[_children]) { for (const child of this[_children]) {

View File

@ -127,18 +127,13 @@ function mapStyle(styleStr, node, richText) {
} }
let newValue = value; let newValue = value;
if (mapping) { if (mapping) {
if (typeof mapping === "string") { newValue =
newValue = mapping; typeof mapping === "string" ? mapping : mapping(value, original);
} else {
newValue = mapping(value, original);
}
} }
if (key.endsWith("scale")) { if (key.endsWith("scale")) {
if (style.transform) { style.transform = style.transform
style.transform = `${style[key]} ${newValue}`; ? `${style[key]} ${newValue}`
} else { : newValue;
style.transform = newValue;
}
} else { } else {
style[key.replaceAll(/-([a-zA-Z])/g, (_, x) => x.toUpperCase())] = style[key.replaceAll(/-([a-zA-Z])/g, (_, x) => x.toUpperCase())] =
newValue; newValue;

View File

@ -225,11 +225,9 @@ function getXfaFontWidths(name) {
const { baseWidths, baseMapping, factors } = info; const { baseWidths, baseMapping, factors } = info;
let rescaledBaseWidths; let rescaledBaseWidths;
if (!factors) { rescaledBaseWidths = !factors
rescaledBaseWidths = baseWidths; ? baseWidths
} else { : baseWidths.map((w, i) => w * factors[i]);
rescaledBaseWidths = baseWidths.map((w, i) => w * factors[i]);
}
let currentCode = -2; let currentCode = -2;
let currentArray; let currentArray;

View File

@ -814,11 +814,9 @@ class XRef {
this._pendingRefs.put(ref); this._pendingRefs.put(ref);
try { try {
if (xrefEntry.uncompressed) { xrefEntry = xrefEntry.uncompressed
xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption); ? this.fetchUncompressed(ref, xrefEntry, suppressEncryption)
} else { : this.fetchCompressed(ref, xrefEntry, suppressEncryption);
xrefEntry = this.fetchCompressed(ref, xrefEntry, suppressEncryption);
}
this._pendingRefs.remove(ref); this._pendingRefs.remove(ref);
} catch (ex) { } catch (ex) {
this._pendingRefs.remove(ref); this._pendingRefs.remove(ref);
@ -873,11 +871,10 @@ class XRef {
} }
throw new XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`); throw new XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`);
} }
if (this.encrypt && !suppressEncryption) { xrefEntry =
xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen)); this.encrypt && !suppressEncryption
} else { ? parser.getObj(this.encrypt.createCipherTransform(num, gen))
xrefEntry = parser.getObj(); : parser.getObj();
}
if (!(xrefEntry instanceof BaseStream)) { if (!(xrefEntry instanceof BaseStream)) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
assert( assert(

View File

@ -855,11 +855,8 @@ function genericComposeSMask(
const b0 = hasBackdrop ? backdrop[2] : 0; const b0 = hasBackdrop ? backdrop[2] : 0;
let composeFn; let composeFn;
if (subtype === "Luminosity") { composeFn =
composeFn = composeSMaskLuminosity; subtype === "Luminosity" ? composeSMaskLuminosity : composeSMaskAlpha;
} else {
composeFn = composeSMaskAlpha;
}
// processing image in chunks to save memory // processing image in chunks to save memory
const PIXELS_TO_PROCESS = 1048576; const PIXELS_TO_PROCESS = 1048576;
@ -2258,11 +2255,9 @@ class CanvasGraphics {
} }
let charWidth; let charWidth;
if (vertical) { charWidth = vertical
charWidth = width * widthAdvanceScale - spacing * fontDirection; ? width * widthAdvanceScale - spacing * fontDirection
} else { : width * widthAdvanceScale + spacing * fontDirection;
charWidth = width * widthAdvanceScale + spacing * fontDirection;
}
x += charWidth; x += charWidth;
if (restoreNeeded) { if (restoreNeeded) {

View File

@ -201,11 +201,7 @@ function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
for (let y = minY; y <= maxY; y++) { for (let y = minY; y <= maxY; y++) {
if (y < y2) { if (y < y2) {
let k; let k;
if (y < y1) { k = y < y1 ? 0 : (y1 - y) / (y1 - y2);
k = 0;
} else {
k = (y1 - y) / (y1 - y2);
}
xa = x1 - (x1 - x2) * k; xa = x1 - (x1 - x2) * k;
car = c1r - (c1r - c2r) * k; car = c1r - (c1r - c2r) * k;
cag = c1g - (c1g - c2g) * k; cag = c1g - (c1g - c2g) * k;

View File

@ -78,11 +78,7 @@ const convertImgDataToPng = (function () {
for (let i = 0; i < 256; i++) { for (let i = 0; i < 256; i++) {
let c = i; let c = i;
for (let h = 0; h < 8; h++) { for (let h = 0; h < 8; h++) {
if (c & 1) { c = c & 1 ? 0xedb88320 ^ ((c >> 1) & 0x7fffffff) : (c >> 1) & 0x7fffffff;
c = 0xedb88320 ^ ((c >> 1) & 0x7fffffff);
} else {
c = (c >> 1) & 0x7fffffff;
}
} }
crcTable[i] = c; crcTable[i] = c;
} }
@ -862,11 +858,9 @@ class SVGGraphics {
} }
let charWidth; let charWidth;
if (vertical) { charWidth = vertical
charWidth = width * widthAdvanceScale - spacing * fontDirection; ? width * widthAdvanceScale - spacing * fontDirection
} else { : width * widthAdvanceScale + spacing * fontDirection;
charWidth = width * widthAdvanceScale + spacing * fontDirection;
}
x += charWidth; x += charWidth;
} }

View File

@ -213,11 +213,9 @@ class XfaLayer {
} }
let childHtml; let childHtml;
if (child?.attributes?.xmlns) { childHtml = child?.attributes?.xmlns
childHtml = document.createElementNS(child.attributes.xmlns, name); ? document.createElementNS(child.attributes.xmlns, name)
} else { : document.createElement(name);
childHtml = document.createElement(name);
}
html.append(childHtml); html.append(childHtml);
if (child.attributes) { if (child.attributes) {

View File

@ -147,11 +147,9 @@ class AForm {
} catch {} } catch {}
if (!date) { if (!date) {
date = Date.parse(cDate); date = Date.parse(cDate);
if (isNaN(date)) { date = isNaN(date)
date = this._tryToGuessDate(cFormat, cDate); ? this._tryToGuessDate(cFormat, cDate)
} else { : new Date(date);
date = new Date(date);
}
} }
return date; return date;
} }
@ -348,11 +346,7 @@ class AForm {
const formatStr = `%,${sepStyle}.${nDec}f`; const formatStr = `%,${sepStyle}.${nDec}f`;
value = this._util.printf(formatStr, value * 100); value = this._util.printf(formatStr, value * 100);
if (percentPrepend) { event.value = percentPrepend ? `%${value}` : `${value}%`;
event.value = `%${value}`;
} else {
event.value = `${value}%`;
}
} }
AFPercent_Keystroke(nDec, sepStyle) { AFPercent_Keystroke(nDec, sepStyle) {
@ -541,11 +535,10 @@ class AForm {
formatStr = "99999-9999"; formatStr = "99999-9999";
break; break;
case 2: case 2:
if (this._util.printx("9999999999", event.value).length >= 10) { formatStr =
formatStr = "(999) 999-9999"; this._util.printx("9999999999", event.value).length >= 10
} else { ? "(999) 999-9999"
formatStr = "999-9999"; : "999-9999";
}
break; break;
case 3: case 3:
formatStr = "999-99-9999"; formatStr = "999-99-9999";
@ -648,11 +641,10 @@ class AForm {
break; break;
case 2: case 2:
const value = this.AFMergeChange(event); const value = this.AFMergeChange(event);
if (value.length > 8 || value.startsWith("(")) { formatStr =
formatStr = "(999) 999-9999"; value.length > 8 || value.startsWith("(")
} else { ? "(999) 999-9999"
formatStr = "999-9999"; : "999-9999";
}
break; break;
case 3: case 3:
formatStr = "999-99-9999"; formatStr = "999-99-9999";

View File

@ -1126,17 +1126,9 @@ class Doc extends PDFObject {
nEnd = printParams.lastPage; nEnd = printParams.lastPage;
} }
if (typeof nStart === "number") { nStart = typeof nStart === "number" ? Math.max(0, Math.trunc(nStart)) : 0;
nStart = Math.max(0, Math.trunc(nStart));
} else {
nStart = 0;
}
if (typeof nEnd === "number") { nEnd = typeof nEnd === "number" ? Math.max(0, Math.trunc(nEnd)) : -1;
nEnd = Math.max(0, Math.trunc(nEnd));
} else {
nEnd = -1;
}
this._send({ command: "print", start: nStart, end: nEnd }); this._send({ command: "print", start: nStart, end: nEnd });
} }

View File

@ -148,11 +148,10 @@ class Util extends PDFObject {
let decPart = ""; let decPart = "";
if (cConvChar === "f") { if (cConvChar === "f") {
if (nPrecision !== undefined) { decPart =
decPart = Math.abs(arg - intPart).toFixed(nPrecision); nPrecision !== undefined
} else { ? Math.abs(arg - intPart).toFixed(nPrecision)
decPart = Math.abs(arg - intPart).toString(); : Math.abs(arg - intPart).toString();
}
if (decPart.length > 2) { if (decPart.length > 2) {
decPart = `${decimalSep}${decPart.substring(2)}`; decPart = `${decimalSep}${decPart.substring(2)}`;
} else { } else {