Bump PDF.js from 4.3.118 to 4.3.136 (#1420)

Changelog: https://github.com/mozilla/pdf.js/releases/tag/v4.3.136
This commit is contained in:
Ludy
2024-06-09 11:45:25 +02:00
committed by GitHub
parent 7a15930453
commit 327a44d487
10 changed files with 398 additions and 454 deletions

View File

@@ -8912,17 +8912,18 @@ class TextHighlighter {
class TextLayerBuilder {
#enablePermissions = false;
#onAppend = null;
#textContentSource = null;
#renderingDone = false;
#textLayer = null;
static #textLayers = new Map();
static #selectionChangeAbortController = null;
constructor({
pdfPage,
highlighter = null,
accessibilityManager = null,
enablePermissions = false,
onAppend = null
}) {
this.renderingDone = false;
this.pdfPage = pdfPage;
this.highlighter = highlighter;
this.accessibilityManager = accessibilityManager;
this.#enablePermissions = enablePermissions === true;
@@ -8932,17 +8933,14 @@ class TextLayerBuilder {
this.div.className = "textLayer";
}
#finishRendering() {
this.renderingDone = true;
this.#renderingDone = true;
const endOfContent = document.createElement("div");
endOfContent.className = "endOfContent";
this.div.append(endOfContent);
this.#bindMouse(endOfContent);
}
async render(viewport) {
if (!this.#textContentSource) {
throw new Error('No "textContentSource" parameter specified.');
}
if (this.renderingDone && this.#textLayer) {
async render(viewport, textContentParams = null) {
if (this.#renderingDone && this.#textLayer) {
this.#textLayer.update({
viewport,
onBefore: this.hide.bind(this)
@@ -8952,7 +8950,10 @@ class TextLayerBuilder {
}
this.cancel();
this.#textLayer = new TextLayer({
textContentSource: this.#textContentSource,
textContentSource: this.pdfPage.streamTextContent(textContentParams || {
includeMarkedContent: true,
disableNormalization: true
}),
container: this.div,
viewport
});
@@ -8969,13 +8970,13 @@ class TextLayerBuilder {
this.accessibilityManager?.enable();
}
hide() {
if (!this.div.hidden && this.renderingDone) {
if (!this.div.hidden && this.#renderingDone) {
this.highlighter?.disable();
this.div.hidden = true;
}
}
show() {
if (this.div.hidden && this.renderingDone) {
if (this.div.hidden && this.#renderingDone) {
this.div.hidden = false;
this.highlighter?.enable();
}
@@ -8987,10 +8988,6 @@ class TextLayerBuilder {
this.accessibilityManager?.disable();
TextLayerBuilder.#removeGlobalSelectionListener(this.div);
}
setTextContentSource(source) {
this.cancel();
this.#textContentSource = source;
}
#bindMouse(end) {
const {
div
@@ -9261,6 +9258,13 @@ class PDFPageView {
findController: this.#layerProperties.findController
}));
}
#dispatchLayerRendered(name, error) {
this.eventBus.dispatch(name, {
source: this,
pageNumber: this.id,
error
});
}
async #renderAnnotationLayer() {
let error = null;
try {
@@ -9269,11 +9273,7 @@ class PDFPageView {
console.error(`#renderAnnotationLayer: "${ex}".`);
error = ex;
} finally {
this.eventBus.dispatch("annotationlayerrendered", {
source: this,
pageNumber: this.id,
error
});
this.#dispatchLayerRendered("annotationlayerrendered", error);
}
}
async #renderAnnotationEditorLayer() {
@@ -9284,11 +9284,7 @@ class PDFPageView {
console.error(`#renderAnnotationEditorLayer: "${ex}".`);
error = ex;
} finally {
this.eventBus.dispatch("annotationeditorlayerrendered", {
source: this,
pageNumber: this.id,
error
});
this.#dispatchLayerRendered("annotationeditorlayerrendered", error);
}
}
async #renderDrawLayer() {
@@ -9314,32 +9310,16 @@ class PDFPageView {
this.#addLayer(this.xfaLayer.div, "xfaLayer");
this.l10n.resume();
}
this.eventBus.dispatch("xfalayerrendered", {
source: this,
pageNumber: this.id,
error
});
this.#dispatchLayerRendered("xfalayerrendered", error);
}
}
async #renderTextLayer() {
const {
pdfPage,
textLayer,
viewport
} = this;
if (!textLayer) {
if (!this.textLayer) {
return;
}
let error = null;
try {
if (!textLayer.renderingDone) {
const readableStream = pdfPage.streamTextContent({
includeMarkedContent: true,
disableNormalization: true
});
textLayer.setTextContentSource(readableStream);
}
await textLayer.render(viewport);
await this.textLayer.render(this.viewport);
} catch (ex) {
if (ex instanceof AbortException) {
return;
@@ -9347,11 +9327,7 @@ class PDFPageView {
console.error(`#renderTextLayer: "${ex}".`);
error = ex;
}
this.eventBus.dispatch("textlayerrendered", {
source: this,
pageNumber: this.id,
error
});
this.#dispatchLayerRendered("textlayerrendered", error);
this.#renderStructTreeLayer();
}
async #renderStructTreeLayer() {
@@ -9694,6 +9670,7 @@ class PDFPageView {
if (!this.textLayer && this.#textLayerMode !== TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
this._accessibilityManager ||= new TextAccessibilityManager();
this.textLayer = new TextLayerBuilder({
pdfPage,
highlighter: this._textHighlighter,
accessibilityManager: this._accessibilityManager,
enablePermissions: this.#textLayerMode === TextLayerMode.ENABLE_PERMISSIONS,
@@ -9801,7 +9778,7 @@ class PDFPageView {
annotationCanvasMap: this._annotationCanvasMap,
pageColors
};
const renderTask = this.renderTask = this.pdfPage.render(renderContext);
const renderTask = this.renderTask = pdfPage.render(renderContext);
renderTask.onContinue = renderContinueCallback;
const resultPromise = renderTask.promise.then(async () => {
showCanvas?.(true);
@@ -9969,7 +9946,7 @@ class PDFViewer {
#scaleTimeoutId = null;
#textLayerMode = TextLayerMode.ENABLE;
constructor(options) {
const viewerVersion = "4.3.118";
const viewerVersion = "4.3.136";
if (version !== viewerVersion) {
throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`);
}
@@ -10634,7 +10611,8 @@ class PDFViewer {
#setScaleUpdatePages(newScale, newValue, {
noScroll = false,
preset = false,
drawingDelay = -1
drawingDelay = -1,
origin = null
}) {
this._currentScaleValue = newValue.toString();
if (this.#isSameScale(newScale)) {
@@ -10659,6 +10637,7 @@ class PDFViewer {
this.refresh();
}, drawingDelay);
}
const previousScale = this._currentScale;
this._currentScale = newScale;
if (!noScroll) {
let page = this._currentPageNumber,
@@ -10674,6 +10653,12 @@ class PDFViewer {
destArray: dest,
allowNegativeOffset: true
});
if (Array.isArray(origin)) {
const scaleDiff = newScale / previousScale - 1;
const [top, left] = this.containerTopLeft;
this.container.scrollLeft += (origin[0] - left) * scaleDiff;
this.container.scrollTop += (origin[1] - top) * scaleDiff;
}
}
this.eventBus.dispatch("scalechanging", {
source: this,
@@ -11281,48 +11266,46 @@ class PDFViewer {
this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
return true;
}
increaseScale({
updateScale({
drawingDelay,
scaleFactor,
steps
} = {}) {
scaleFactor = null,
steps = null,
origin
}) {
if (steps === null && scaleFactor === null) {
throw new Error("Invalid updateScale options: either `steps` or `scaleFactor` must be provided.");
}
if (!this.pdfDocument) {
return;
}
let newScale = this._currentScale;
if (scaleFactor > 1) {
if (scaleFactor > 0 && scaleFactor !== 1) {
newScale = Math.round(newScale * scaleFactor * 100) / 100;
} else {
steps ??= 1;
} else if (steps) {
const delta = steps > 0 ? DEFAULT_SCALE_DELTA : 1 / DEFAULT_SCALE_DELTA;
const round = steps > 0 ? Math.ceil : Math.floor;
steps = Math.abs(steps);
do {
newScale = Math.ceil((newScale * DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
} while (--steps > 0 && newScale < MAX_SCALE);
newScale = round((newScale * delta).toFixed(2) * 10) / 10;
} while (--steps > 0);
}
this.#setScale(Math.min(MAX_SCALE, newScale), {
newScale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, newScale));
this.#setScale(newScale, {
noScroll: false,
drawingDelay
drawingDelay,
origin
});
}
decreaseScale({
drawingDelay,
scaleFactor,
steps
} = {}) {
if (!this.pdfDocument) {
return;
}
let newScale = this._currentScale;
if (scaleFactor > 0 && scaleFactor < 1) {
newScale = Math.round(newScale * scaleFactor * 100) / 100;
} else {
steps ??= 1;
do {
newScale = Math.floor((newScale / DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
} while (--steps > 0 && newScale > MIN_SCALE);
}
this.#setScale(Math.max(MIN_SCALE, newScale), {
noScroll: false,
drawingDelay
increaseScale(options = {}) {
this.updateScale({
...options,
steps: options.steps ?? 1
});
}
decreaseScale(options = {}) {
this.updateScale({
...options,
steps: -(options.steps ?? 1)
});
}
#updateContainerHeightCss(height = this.container.clientHeight) {
@@ -12465,25 +12448,22 @@ const PDFViewerApplication = {
get initializedPromise() {
return this._initializedCapability.promise;
},
zoomIn(steps, scaleFactor) {
updateZoom(steps, scaleFactor, origin) {
if (this.pdfViewer.isInPresentationMode) {
return;
}
this.pdfViewer.increaseScale({
this.pdfViewer.updateScale({
drawingDelay: AppOptions.get("defaultZoomDelay"),
steps,
scaleFactor
scaleFactor,
origin
});
},
zoomOut(steps, scaleFactor) {
if (this.pdfViewer.isInPresentationMode) {
return;
}
this.pdfViewer.decreaseScale({
drawingDelay: AppOptions.get("defaultZoomDelay"),
steps,
scaleFactor
});
zoomIn() {
this.updateZoom(1);
},
zoomOut() {
this.updateZoom(-1);
},
zoomReset() {
if (this.pdfViewer.isInPresentationMode) {
@@ -13510,17 +13490,6 @@ const PDFViewerApplication = {
this[prop] = factor / newFactor;
return newFactor;
},
_centerAtPos(previousScale, x, y) {
const {
pdfViewer
} = this;
const scaleDiff = pdfViewer.currentScale / previousScale - 1;
if (scaleDiff !== 0) {
const [top, left] = pdfViewer.containerTopLeft;
pdfViewer.container.scrollLeft += (x - left) * scaleDiff;
pdfViewer.container.scrollTop += (y - top) * scaleDiff;
}
},
_unblockDocumentLoadEvent() {
document.blockUnblockOnload?.(false);
this._unblockDocumentLoadEvent = () => {};
@@ -13866,21 +13835,15 @@ function webViewerWheel(evt) {
let scaleFactor = Math.exp(-evt.deltaY / 100);
const isBuiltInMac = false;
const isPinchToZoom = evt.ctrlKey && !PDFViewerApplication._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && (Math.abs(scaleFactor - 1) < 0.05 || isBuiltInMac) && evt.deltaZ === 0;
const origin = [evt.clientX, evt.clientY];
if (isPinchToZoom || evt.ctrlKey && supportsMouseWheelZoomCtrlKey || evt.metaKey && supportsMouseWheelZoomMetaKey) {
evt.preventDefault();
if (PDFViewerApplication._isScrolling || zoomDisabledTimeout || document.visibilityState === "hidden" || PDFViewerApplication.overlayManager.active) {
return;
}
const previousScale = pdfViewer.currentScale;
if (isPinchToZoom && supportsPinchToZoom) {
scaleFactor = PDFViewerApplication._accumulateFactor(previousScale, scaleFactor, "_wheelUnusedFactor");
if (scaleFactor < 1) {
PDFViewerApplication.zoomOut(null, scaleFactor);
} else if (scaleFactor > 1) {
PDFViewerApplication.zoomIn(null, scaleFactor);
} else {
return;
}
scaleFactor = PDFViewerApplication._accumulateFactor(pdfViewer.currentScale, scaleFactor, "_wheelUnusedFactor");
PDFViewerApplication.updateZoom(null, scaleFactor, origin);
} else {
const delta = normalizeWheelEventDirection(evt);
let ticks = 0;
@@ -13894,15 +13857,8 @@ function webViewerWheel(evt) {
const PIXELS_PER_LINE_SCALE = 30;
ticks = PDFViewerApplication._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks");
}
if (ticks < 0) {
PDFViewerApplication.zoomOut(-ticks);
} else if (ticks > 0) {
PDFViewerApplication.zoomIn(ticks);
} else {
return;
}
PDFViewerApplication.updateZoom(ticks, null, origin);
}
PDFViewerApplication._centerAtPos(previousScale, evt.clientX, evt.clientY);
}
}
function webViewerTouchStart(evt) {
@@ -13988,30 +13944,17 @@ function webViewerTouchMove(evt) {
}
}
evt.preventDefault();
const origin = [(page0X + page1X) / 2, (page0Y + page1Y) / 2];
const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1;
const pDistance = Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1;
const previousScale = pdfViewer.currentScale;
if (supportsPinchToZoom) {
const newScaleFactor = PDFViewerApplication._accumulateFactor(previousScale, distance / pDistance, "_touchUnusedFactor");
if (newScaleFactor < 1) {
PDFViewerApplication.zoomOut(null, newScaleFactor);
} else if (newScaleFactor > 1) {
PDFViewerApplication.zoomIn(null, newScaleFactor);
} else {
return;
}
const newScaleFactor = PDFViewerApplication._accumulateFactor(pdfViewer.currentScale, distance / pDistance, "_touchUnusedFactor");
PDFViewerApplication.updateZoom(null, newScaleFactor, origin);
} else {
const PIXELS_PER_LINE_SCALE = 30;
const ticks = PDFViewerApplication._accumulateTicks((distance - pDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks");
if (ticks < 0) {
PDFViewerApplication.zoomOut(-ticks);
} else if (ticks > 0) {
PDFViewerApplication.zoomIn(ticks);
} else {
return;
}
PDFViewerApplication.updateZoom(ticks, null, origin);
}
PDFViewerApplication._centerAtPos(previousScale, (page0X + page1X) / 2, (page0Y + page1Y) / 2);
}
function webViewerTouchEnd(evt) {
if (!PDFViewerApplication._touchInfo) {
@@ -14329,8 +14272,8 @@ function webViewerReportTelemetry({
const pdfjsVersion = "4.3.118";
const pdfjsBuild = "17e09e547";
const pdfjsVersion = "4.3.136";
const pdfjsBuild = "0cec64437";
const AppConstants = {
LinkTarget: LinkTarget,
RenderingStates: RenderingStates,
@@ -14465,7 +14408,7 @@ function getViewerConfiguration() {
editorFreeHighlightThickness: document.getElementById("editorFreeHighlightThickness"),
editorHighlightShowAll: document.getElementById("editorHighlightShowAll")
},
printContainer: document.getElementById("printContainer"),
printContainer: document.getElementById("printContainer")
};
}
function webViewerLoad() {