: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if (this.#renderingDone && this.#textLayer) {
onBefore: this.hide.bind(this)
this.#textLayer = new TextLayer({
textContentSource: this.pdfPage.streamTextContent(textContentParams || {
includeMarkedContent: true,
disableNormalization: true
this.highlighter?.setTextMapping(textDivs, textContentItemsStr);
this.accessibilityManager?.setTextMapping(textDivs);
await this.#textLayer.render();
this.#onAppend?.(this.div);
this.highlighter?.enable();
this.accessibilityManager?.enable();
if (!this.div.hidden && this.#renderingDone) {
this.highlighter?.disable();
if (this.div.hidden && this.#renderingDone) {
this.highlighter?.enable();
this.#textLayer?.cancel();
this.highlighter?.disable();
this.accessibilityManager?.disable();
TextLayerBuilder.#removeGlobalSelectionListener(this.div);
div.addEventListener("mousedown", evt => {
end.classList.add("active");
div.addEventListener("copy", event => {
if (!this.#enablePermissions) {
const selection = document.getSelection();
event.clipboardData.setData("text/plain", removeNullCharacters(normalizeUnicode(selection.toString())));
TextLayerBuilder.#textLayers.set(div, end);
TextLayerBuilder.#enableGlobalSelectionListener();
static #removeGlobalSelectionListener(textLayerDiv) {
this.#textLayers.delete(textLayerDiv);
if (this.#textLayers.size === 0) {
this.#selectionChangeAbortController?.abort();
this.#selectionChangeAbortController = null;
static #enableGlobalSelectionListener() {
if (this.#selectionChangeAbortController) {
this.#selectionChangeAbortController = new AbortController();
} = this.#selectionChangeAbortController;
const reset = (end, textLayer) => {
end.classList.remove("active");
document.addEventListener("pointerup", () => {
this.#textLayers.forEach(reset);
var isFirefox, prevRange;
document.addEventListener("selectionchange", () => {
const selection = document.getSelection();
if (selection.rangeCount === 0) {
this.#textLayers.forEach(reset);
const activeTextLayers = new Set();
for (let i = 0; i < selection.rangeCount; i++) {
const range = selection.getRangeAt(i);
for (const textLayerDiv of this.#textLayers.keys()) {
if (!activeTextLayers.has(textLayerDiv) && range.intersectsNode(textLayerDiv)) {
activeTextLayers.add(textLayerDiv);
for (const [textLayerDiv, endDiv] of this.#textLayers) {
if (activeTextLayers.has(textLayerDiv)) {
endDiv.classList.add("active");
reset(endDiv, textLayerDiv);
isFirefox ??= getComputedStyle(this.#textLayers.values().next().value).getPropertyValue("-moz-user-select") === "none";
const range = selection.getRangeAt(0);
const modifyStart = prevRange && (range.compareBoundaryPoints(Range.END_TO_END, prevRange) === 0 || range.compareBoundaryPoints(Range.START_TO_END, prevRange) === 0);
let anchor = modifyStart ? range.startContainer : range.endContainer;
if (anchor.nodeType === Node.TEXT_NODE) {
anchor = anchor.parentNode;
const parentTextLayer = anchor.parentElement.closest(".textLayer");
const endDiv = this.#textLayers.get(parentTextLayer);
endDiv.style.width = parentTextLayer.style.width;
endDiv.style.height = parentTextLayer.style.height;
anchor.parentElement.insertBefore(endDiv, modifyStart ? anchor : anchor.nextSibling);
prevRange = range.cloneRange();
;// CONCATENATED MODULE: ./web/pdf_page_view.js
const DEFAULT_LAYER_PROPERTIES = null;
const LAYERS_ORDER = new Map([["canvasWrapper", 0], ["textLayer", 1], ["annotationLayer", 2], ["annotationEditorLayer", 3], ["xfaLayer", 3]]);
#annotationMode = AnnotationMode.ENABLE_FORMS;
#hasRestrictedScaling = false;
#previousRotation = null;
#renderingState = RenderingStates.INITIAL;
#textLayerMode = TextLayerMode.ENABLE;
initialOptionalContent: true,
#viewportMap = new WeakMap();
#layers = [null, null, null, null];
const container = options.container;
const defaultViewport = options.defaultViewport;
this.renderingId = "page" + this.id;
this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
this.scale = options.scale || DEFAULT_SCALE;
this.viewport = defaultViewport;
this.pdfPageRotate = defaultViewport.rotation;
this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
this.#annotationMode = options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
this.imageResourcesPath = options.imageResourcesPath || "";
this.maxCanvasPixels = options.maxCanvasPixels ?? AppOptions.get("maxCanvasPixels");
this.pageColors = options.pageColors || null;
this.eventBus = options.eventBus;
this.renderingQueue = options.renderingQueue;
this.l10n = options.l10n;
this.l10n ||= new genericl10n_GenericL10n();
this._isStandalone = !this.renderingQueue?.hasViewer();
this._container = container;
this._annotationCanvasMap = null;
this.annotationLayer = null;
this.annotationEditorLayer = null;
this.structTreeLayer = null;
const div = document.createElement("div");
div.setAttribute("data-page-number", this.id);
div.setAttribute("role", "region");
div.setAttribute("data-l10n-id", "pdfjs-page-landmark");
div.setAttribute("data-l10n-args", JSON.stringify({
if (this._isStandalone) {
container?.style.setProperty("--scale-factor", this.scale * PixelsPerInch.PDF_TO_CSS_UNITS);
optionalContentConfigPromise
if (optionalContentConfigPromise) {
optionalContentConfigPromise.then(optionalContentConfig => {
if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
this.l10n.translate(this.div);
const pos = LAYERS_ORDER.get(name);
const oldDiv = this.#layers[pos];
for (let i = pos - 1; i >= 0; i--) {
const layer = this.#layers[i];
return this.#renderingState;
set renderingState(state) {
if (state === this.#renderingState) {
this.#renderingState = state;
clearTimeout(this.#loadingId);
case RenderingStates.PAUSED:
this.div.classList.remove("loading");
case RenderingStates.RUNNING:
this.div.classList.add("loadingIcon");
this.#loadingId = setTimeout(() => {
this.div.classList.add("loading");
case RenderingStates.INITIAL:
case RenderingStates.FINISHED:
this.div.classList.remove("loadingIcon", "loading");
if (this.#previousRotation === viewport.rotation) {
this.#previousRotation = viewport.rotation;
setLayerDimensions(this.div, viewport, true, false);
if (this._isStandalone && (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas")) {
this._container?.style.setProperty("--hcm-highlight-filter", pdfPage.filterFactory.addHighlightHCMFilter("highlight", "CanvasText", "Canvas", "HighlightText", "Highlight"));
this._container?.style.setProperty("--hcm-highlight-selected-filter", pdfPage.filterFactory.addHighlightHCMFilter("highlight_selected", "CanvasText", "Canvas", "HighlightText", "Highlight"));
this.pdfPageRotate = pdfPage.rotate;
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
this.viewport = pdfPage.getViewport({
scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
return shadow(this, "_textHighlighter", new TextHighlighter({
findController: this.#layerProperties.findController
#dispatchLayerRendered(name, error) {
this.eventBus.dispatch(name, {
async #renderAnnotationLayer() {
await this.annotationLayer.render(this.viewport, "display");
console.error(`#renderAnnotationLayer: "${ex}".`);
this.#dispatchLayerRendered("annotationlayerrendered", error);
async #renderAnnotationEditorLayer() {
await this.annotationEditorLayer.render(this.viewport, "display");
console.error(`#renderAnnotationEditorLayer: "${ex}".`);
this.#dispatchLayerRendered("annotationeditorlayerrendered", error);
async #renderDrawLayer() {
await this.drawLayer.render("display");
console.error(`#renderDrawLayer: "${ex}".`);
async #renderXfaLayer() {
const result = await this.xfaLayer.render(this.viewport, "display");
if (result?.textDivs && this._textHighlighter) {
this.#buildXfaTextContentItems(result.textDivs);
console.error(`#renderXfaLayer: "${ex}".`);
if (this.xfaLayer?.div) {
this.#addLayer(this.xfaLayer.div, "xfaLayer");
this.#dispatchLayerRendered("xfalayerrendered", error);
async #renderTextLayer() {
await this.textLayer.render(this.viewport);
if (ex instanceof AbortException) {
console.error(`#renderTextLayer: "${ex}".`);
this.#dispatchLayerRendered("textlayerrendered", error);
this.#renderStructTreeLayer();
async #renderStructTreeLayer() {
this.structTreeLayer ||= new StructTreeLayerBuilder();
const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
const treeDom = this.structTreeLayer?.render(tree);
this.canvas?.append(treeDom);
this.structTreeLayer?.show();
async #buildXfaTextContentItems(textDivs) {
const text = await this.pdfPage.getTextContent();
for (const item of text.items) {
this._textHighlighter.setTextMapping(textDivs, items);
this._textHighlighter.enable();
_resetZoomLayer(removeFromDOM = false) {
const zoomLayerCanvas = this.zoomLayer.firstChild;
this.#viewportMap.delete(zoomLayerCanvas);
zoomLayerCanvas.width = 0;
zoomLayerCanvas.height = 0;
keepAnnotationLayer = false,
keepAnnotationEditorLayer = false,
keepAnnotationEditorLayer,
this.renderingState = RenderingStates.INITIAL;
const childNodes = div.childNodes,
zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
textLayerNode = keepTextLayer && this.textLayer?.div || null;
for (let i = childNodes.length - 1; i >= 0; i--) {
const node = childNodes[i];
case annotationLayerNode:
case annotationEditorLayerNode:
const layerIndex = this.#layers.indexOf(node);
this.#layers[layerIndex] = null;
div.removeAttribute("data-loaded");
if (annotationLayerNode) {
this.annotationLayer.hide();
if (annotationEditorLayerNode) {
this.annotationEditorLayer.hide();
this.structTreeLayer?.hide();
this.#viewportMap.delete(this.canvas);
optionalContentConfigPromise = null,
this.scale = scale || this.scale;
if (typeof rotation === "number") {
this.rotation = rotation;
if (optionalContentConfigPromise instanceof Promise) {
this._optionalContentConfigPromise = optionalContentConfigPromise;