Introduce some logical assignment in the src/core/
folder
This commit is contained in:
parent
317abd6d07
commit
d950b91c4e
@ -1556,11 +1556,10 @@ class WidgetAnnotation extends Annotation {
|
||||
|
||||
this.setDefaultAppearance(params);
|
||||
|
||||
data.hasAppearance =
|
||||
(this._needAppearances &&
|
||||
data.fieldValue !== undefined &&
|
||||
data.fieldValue !== null) ||
|
||||
data.hasAppearance;
|
||||
data.hasAppearance ||=
|
||||
this._needAppearances &&
|
||||
data.fieldValue !== undefined &&
|
||||
data.fieldValue !== null;
|
||||
|
||||
const fieldType = getInheritableProperty({ dict, key: "FT" });
|
||||
data.fieldType = fieldType instanceof Name ? fieldType.name : null;
|
||||
@ -1808,7 +1807,7 @@ class WidgetAnnotation extends Annotation {
|
||||
if (!this._hasValueFromXFA && rotation === undefined) {
|
||||
return null;
|
||||
}
|
||||
value = value || this.data.fieldValue;
|
||||
value ||= this.data.fieldValue;
|
||||
}
|
||||
|
||||
// Value can be an array (with choice list and multiple selections)
|
||||
@ -3472,7 +3471,7 @@ class LinkAnnotation extends Annotation {
|
||||
}
|
||||
|
||||
// The color entry for a link annotation is the color of the border.
|
||||
this.data.borderColor = this.data.borderColor || this.data.color;
|
||||
this.data.borderColor ||= this.data.color;
|
||||
|
||||
Catalog.parseDestDictionary({
|
||||
destDict: params.dict,
|
||||
|
@ -985,12 +985,8 @@ class Catalog {
|
||||
} else if (typeof js !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (javaScript === null) {
|
||||
javaScript = new Map();
|
||||
}
|
||||
js = stringToPDFString(js).replaceAll("\x00", "");
|
||||
javaScript.set(name, js);
|
||||
(javaScript ||= new Map()).set(name, js);
|
||||
}
|
||||
|
||||
if (obj instanceof Dict && obj.has("JavaScript")) {
|
||||
|
@ -1220,9 +1220,9 @@ const CalRGBCS = (function CalRGBCSClosure() {
|
||||
"WhitePoint missing - required for color space CalRGB"
|
||||
);
|
||||
}
|
||||
blackPoint = blackPoint || new Float32Array(3);
|
||||
gamma = gamma || new Float32Array([1, 1, 1]);
|
||||
matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
||||
blackPoint ||= new Float32Array(3);
|
||||
gamma ||= new Float32Array([1, 1, 1]);
|
||||
matrix ||= new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
||||
|
||||
// Translate arguments to spec variables.
|
||||
const XW = whitePoint[0];
|
||||
@ -1396,8 +1396,8 @@ const LabCS = (function LabCSClosure() {
|
||||
"WhitePoint missing - required for color space Lab"
|
||||
);
|
||||
}
|
||||
blackPoint = blackPoint || [0, 0, 0];
|
||||
range = range || [-100, 100, -100, 100];
|
||||
blackPoint ||= [0, 0, 0];
|
||||
range ||= [-100, 100, -100, 100];
|
||||
|
||||
// Translate args to spec variables
|
||||
this.XW = whitePoint[0];
|
||||
|
@ -137,10 +137,7 @@ function getInheritableProperty({
|
||||
if (stopWhenFound) {
|
||||
return value;
|
||||
}
|
||||
if (!values) {
|
||||
values = [];
|
||||
}
|
||||
values.push(value);
|
||||
(values ||= []).push(value);
|
||||
}
|
||||
dict = dict.get("Parent");
|
||||
}
|
||||
@ -322,7 +319,7 @@ function _collectJS(entry, xref, list, parents) {
|
||||
} else if (typeof js === "string") {
|
||||
code = js;
|
||||
}
|
||||
code = code && stringToPDFString(code).replaceAll("\x00", "");
|
||||
code &&= stringToPDFString(code).replaceAll("\x00", "");
|
||||
if (code) {
|
||||
list.push(code);
|
||||
}
|
||||
|
@ -495,12 +495,8 @@ class Page {
|
||||
for (const { opList, separateForm, separateCanvas } of opLists) {
|
||||
pageOpList.addOpList(opList);
|
||||
|
||||
if (separateForm) {
|
||||
form = separateForm;
|
||||
}
|
||||
if (separateCanvas) {
|
||||
canvas = separateCanvas;
|
||||
}
|
||||
form ||= separateForm;
|
||||
canvas ||= separateCanvas;
|
||||
}
|
||||
pageOpList.flush(
|
||||
/* lastChunk = */ true,
|
||||
@ -580,8 +576,8 @@ class Page {
|
||||
return [];
|
||||
}
|
||||
|
||||
const textContentPromises = [];
|
||||
const annotationsData = [];
|
||||
const annotationsData = [],
|
||||
textContentPromises = [];
|
||||
let partialEvaluator;
|
||||
|
||||
const intentAny = !!(intent & RenderingIntentFlag.ANY),
|
||||
@ -597,19 +593,18 @@ class Page {
|
||||
}
|
||||
|
||||
if (annotation.hasTextContent && isVisible) {
|
||||
if (!partialEvaluator) {
|
||||
partialEvaluator = new PartialEvaluator({
|
||||
xref: this.xref,
|
||||
handler,
|
||||
pageIndex: this.pageIndex,
|
||||
idFactory: this._localIdFactory,
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
standardFontDataCache: this.standardFontDataCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
options: this.evaluatorOptions,
|
||||
});
|
||||
}
|
||||
partialEvaluator ||= new PartialEvaluator({
|
||||
xref: this.xref,
|
||||
handler,
|
||||
pageIndex: this.pageIndex,
|
||||
idFactory: this._localIdFactory,
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
standardFontDataCache: this.standardFontDataCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
options: this.evaluatorOptions,
|
||||
});
|
||||
|
||||
textContentPromises.push(
|
||||
annotation
|
||||
.extractTextContent(partialEvaluator, task, this.view)
|
||||
@ -665,10 +660,7 @@ class Page {
|
||||
continue;
|
||||
}
|
||||
if (annotation instanceof PopupAnnotation) {
|
||||
if (!popupAnnotations) {
|
||||
popupAnnotations = [];
|
||||
}
|
||||
popupAnnotations.push(annotation);
|
||||
(popupAnnotations ||= []).push(annotation);
|
||||
continue;
|
||||
}
|
||||
sortedAnnotations.push(annotation);
|
||||
|
@ -519,7 +519,7 @@ class PartialEvaluator {
|
||||
}
|
||||
|
||||
if (smask && smask.backdrop) {
|
||||
colorSpace = colorSpace || ColorSpace.singletons.rgb;
|
||||
colorSpace ||= ColorSpace.singletons.rgb;
|
||||
smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
|
||||
}
|
||||
|
||||
@ -1272,10 +1272,7 @@ class PartialEvaluator {
|
||||
}
|
||||
|
||||
if (hash && descriptor instanceof Dict) {
|
||||
if (!descriptor.fontAliases) {
|
||||
descriptor.fontAliases = Object.create(null);
|
||||
}
|
||||
const fontAliases = descriptor.fontAliases;
|
||||
const fontAliases = (descriptor.fontAliases ||= Object.create(null));
|
||||
|
||||
if (fontAliases[hash]) {
|
||||
const aliasFontRef = fontAliases[hash].aliasRef;
|
||||
@ -1668,8 +1665,8 @@ class PartialEvaluator {
|
||||
}) {
|
||||
// Ensure that `resources`/`initialState` is correctly initialized,
|
||||
// even if the provided parameter is e.g. `null`.
|
||||
resources = resources || Dict.empty;
|
||||
initialState = initialState || new EvalState();
|
||||
resources ||= Dict.empty;
|
||||
initialState ||= new EvalState();
|
||||
|
||||
if (!operatorList) {
|
||||
throw new Error('getOperatorList: missing "operatorList" parameter');
|
||||
@ -2276,11 +2273,11 @@ class PartialEvaluator {
|
||||
}) {
|
||||
// Ensure that `resources`/`stateManager` is correctly initialized,
|
||||
// even if the provided parameter is e.g. `null`.
|
||||
resources = resources || Dict.empty;
|
||||
stateManager = stateManager || new StateManager(new TextState());
|
||||
resources ||= Dict.empty;
|
||||
stateManager ||= new StateManager(new TextState());
|
||||
|
||||
if (includeMarkedContent) {
|
||||
markedContentData = markedContentData || { level: 0 };
|
||||
markedContentData ||= { level: 0 };
|
||||
}
|
||||
|
||||
const textContent = {
|
||||
@ -4255,7 +4252,7 @@ class PartialEvaluator {
|
||||
}
|
||||
}
|
||||
}
|
||||
fontName = fontName || baseFont;
|
||||
fontName ||= baseFont;
|
||||
|
||||
if (!(fontName instanceof Name)) {
|
||||
throw new FormatError("invalid font name");
|
||||
|
@ -743,7 +743,7 @@ function validateOS2Table(os2, file) {
|
||||
}
|
||||
|
||||
function createOS2Table(properties, charstrings, override) {
|
||||
override = override || {
|
||||
override ||= {
|
||||
unitsPerEm: 0,
|
||||
yMax: 0,
|
||||
yMin: 0,
|
||||
@ -3090,10 +3090,7 @@ class Font {
|
||||
let charCodes = null;
|
||||
for (const charCode in charCodeToGlyphId) {
|
||||
if (glyphId === charCodeToGlyphId[charCode]) {
|
||||
if (!charCodes) {
|
||||
charCodes = [];
|
||||
}
|
||||
charCodes.push(charCode | 0);
|
||||
(charCodes ||= []).push(charCode | 0);
|
||||
}
|
||||
}
|
||||
return charCodes;
|
||||
@ -3285,8 +3282,7 @@ class Font {
|
||||
break; // the non-zero width found
|
||||
}
|
||||
}
|
||||
width = width || this.defaultWidth;
|
||||
return shadow(this, "spaceWidth", width);
|
||||
return shadow(this, "spaceWidth", width || this.defaultWidth);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,7 @@ function addState(parentState, pattern, checkFn, iterateFn, processFn) {
|
||||
let state = parentState;
|
||||
for (let i = 0, ii = pattern.length - 1; i < ii; i++) {
|
||||
const item = pattern[i];
|
||||
state = state[item] || (state[item] = []);
|
||||
state = state[item] ||= [];
|
||||
}
|
||||
state[pattern.at(-1)] = {
|
||||
checkFn,
|
||||
|
@ -896,7 +896,7 @@ class Lexer {
|
||||
throw new FormatError(msg);
|
||||
}
|
||||
|
||||
sign = sign || 1;
|
||||
sign ||= 1;
|
||||
let baseValue = ch - 0x30; // '0'
|
||||
let powerValue = 0;
|
||||
let powerValueSign = 1;
|
||||
|
@ -366,13 +366,10 @@ const getB = (function getBClosure() {
|
||||
}
|
||||
return lut;
|
||||
}
|
||||
const cache = [];
|
||||
const cache = Object.create(null);
|
||||
|
||||
return function (count) {
|
||||
if (!cache[count]) {
|
||||
cache[count] = buildB(count);
|
||||
}
|
||||
return cache[count];
|
||||
return (cache[count] ||= buildB(count));
|
||||
};
|
||||
})();
|
||||
|
||||
|
@ -48,8 +48,7 @@ class BasePdfManager {
|
||||
|
||||
// Check `OffscreenCanvas` support once, rather than repeatedly throughout
|
||||
// the worker-thread code.
|
||||
args.evaluatorOptions.isOffscreenCanvasSupported =
|
||||
args.evaluatorOptions.isOffscreenCanvasSupported &&
|
||||
args.evaluatorOptions.isOffscreenCanvasSupported &&=
|
||||
FeatureTest.isOffscreenCanvasSupported;
|
||||
this.evaluatorOptions = args.evaluatorOptions;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class Name {
|
||||
|
||||
static get(name) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return NameCache[name] || (NameCache[name] = new Name(name));
|
||||
return (NameCache[name] ||= new Name(name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ class Cmd {
|
||||
|
||||
static get(cmd) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return CmdCache[cmd] || (CmdCache[cmd] = new Cmd(cmd));
|
||||
return (CmdCache[cmd] ||= new Cmd(cmd));
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,7 +282,7 @@ class Ref {
|
||||
static get(num, gen) {
|
||||
const key = gen === 0 ? `${num}R` : `${num}R${gen}`;
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return RefCache[key] || (RefCache[key] = new Ref(num, gen));
|
||||
return (RefCache[key] ||= new Ref(num, gen));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,11 +120,7 @@ class PostScriptToken {
|
||||
}
|
||||
|
||||
static getOperator(op) {
|
||||
const opValue = PostScriptToken.opCache[op];
|
||||
if (opValue) {
|
||||
return opValue;
|
||||
}
|
||||
return (PostScriptToken.opCache[op] = new PostScriptToken(
|
||||
return (PostScriptToken.opCache[op] ||= new PostScriptToken(
|
||||
PostScriptTokenTypes.OPERATOR,
|
||||
op
|
||||
));
|
||||
|
@ -261,8 +261,7 @@ class WorkerMessageHandler {
|
||||
pdfManagerArgs.source = pdfStream;
|
||||
pdfManagerArgs.length = fullRequest.contentLength;
|
||||
// We don't need auto-fetch when streaming is enabled.
|
||||
pdfManagerArgs.disableAutoFetch =
|
||||
pdfManagerArgs.disableAutoFetch || fullRequest.isStreamingSupported;
|
||||
pdfManagerArgs.disableAutoFetch ||= fullRequest.isStreamingSupported;
|
||||
|
||||
newPdfManager = new NetworkPdfManager(pdfManagerArgs);
|
||||
// There may be a chance that `newPdfManager` is not initialized for
|
||||
@ -661,7 +660,6 @@ class WorkerMessageHandler {
|
||||
});
|
||||
}
|
||||
|
||||
const lastXRefStreamPos = xref.lastXRefStreamPos;
|
||||
newXrefInfo = {
|
||||
rootRef: xref.trailer.getRaw("Root") || null,
|
||||
encryptRef: xref.trailer.getRaw("Encrypt") || null,
|
||||
@ -669,8 +667,7 @@ class WorkerMessageHandler {
|
||||
infoRef: xref.trailer.getRaw("Info") || null,
|
||||
info: infoObj,
|
||||
fileIds: xref.trailer.get("ID") || null,
|
||||
startXRef:
|
||||
lastXRefStreamPos === null ? startXRef : lastXRefStreamPos,
|
||||
startXRef: xref.lastXRefStreamPos ?? startXRef,
|
||||
filename,
|
||||
};
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ class SimpleExprParser {
|
||||
}
|
||||
|
||||
parse(tok) {
|
||||
tok = tok || this.lexer.next();
|
||||
tok ||= this.lexer.next();
|
||||
|
||||
while (true) {
|
||||
// Token ids (see form_lexer.js) are consecutive in order
|
||||
@ -1005,7 +1005,7 @@ class Parser {
|
||||
}
|
||||
|
||||
parseExpr(tok) {
|
||||
tok = tok || this.lexer.next();
|
||||
tok ||= this.lexer.next();
|
||||
switch (tok.id) {
|
||||
case TOKEN.identifier:
|
||||
return this.parseAssigmentOrExpr(tok);
|
||||
|
@ -107,10 +107,7 @@ class XFAParser extends XMLParserBase {
|
||||
nsAttrs = attributeObj[$nsAttributes] = Object.create(null);
|
||||
}
|
||||
const [ns, attrName] = [name.slice(0, i), name.slice(i + 1)];
|
||||
let attrs = nsAttrs[ns];
|
||||
if (!attrs) {
|
||||
attrs = nsAttrs[ns] = Object.create(null);
|
||||
}
|
||||
const attrs = (nsAttrs[ns] ||= Object.create(null));
|
||||
attrs[attrName] = value;
|
||||
}
|
||||
}
|
||||
|
@ -5573,8 +5573,7 @@ class Template extends XFAObject {
|
||||
const flush = index => {
|
||||
const html = root[$flushHTML]();
|
||||
if (html) {
|
||||
hasSomething =
|
||||
hasSomething || (html.children && html.children.length !== 0);
|
||||
hasSomething ||= !!html.children && html.children.length !== 0;
|
||||
htmlContentAreas[index].children.push(html);
|
||||
}
|
||||
};
|
||||
@ -5597,9 +5596,8 @@ class Template extends XFAObject {
|
||||
const html = root[$toHTML](space);
|
||||
if (html.success) {
|
||||
if (html.html) {
|
||||
hasSomething =
|
||||
hasSomething ||
|
||||
(html.html.children && html.html.children.length !== 0);
|
||||
hasSomething ||=
|
||||
!!html.html.children && html.html.children.length !== 0;
|
||||
htmlContentAreas[i].children.push(html.html);
|
||||
} else if (!hasSomething && mainHtml.children.length > 1) {
|
||||
mainHtml.children.pop();
|
||||
|
@ -75,7 +75,7 @@ function getStringOption(data, options) {
|
||||
}
|
||||
|
||||
function getMeasurement(str, def = "0") {
|
||||
def = def || "0";
|
||||
def ||= "0";
|
||||
if (!str) {
|
||||
return getMeasurement(def);
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ class AnnotationElement {
|
||||
_createPopup(trigger, data) {
|
||||
let container = this.container;
|
||||
if (this.quadrilaterals) {
|
||||
trigger = trigger || this.quadrilaterals;
|
||||
trigger ||= this.quadrilaterals;
|
||||
container = this.quadrilaterals[0];
|
||||
}
|
||||
|
||||
|
@ -3356,9 +3356,7 @@ class InternalRenderTask {
|
||||
|
||||
operatorListChanged() {
|
||||
if (!this.graphicsReady) {
|
||||
if (!this.graphicsReadyCallback) {
|
||||
this.graphicsReadyCallback = this._continueBound;
|
||||
}
|
||||
this.graphicsReadyCallback ||= this._continueBound;
|
||||
return;
|
||||
}
|
||||
this.stepper?.updateOperatorList(this.operatorList);
|
||||
|
Loading…
x
Reference in New Issue
Block a user