: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
preRenderView = views[preRenderIndex];
if (preRenderView && !this.isViewFinished(preRenderView)) {
return view.renderingState === RenderingStates.FINISHED;
switch (view.renderingState) {
case RenderingStates.FINISHED:
case RenderingStates.PAUSED:
this.highestPriorityPage = view.renderingId;
case RenderingStates.RUNNING:
this.highestPriorityPage = view.renderingId;
case RenderingStates.INITIAL:
this.highestPriorityPage = view.renderingId;
view.draw().finally(() => {
this.renderHighestPriority();
if (reason instanceof RenderingCancelledException) {
console.error(`renderView: "${reason}"`);
;// CONCATENATED MODULE: ./web/pdf_scripting_manager.js
class PDFScriptingManager {
#destroyCapability = null;
#eventAbortController = null;
#externalServices = null;
#willPrintCapability = null;
this.#eventBus = eventBus;
this.#externalServices = externalServices;
this.#docProperties = docProperties;
this.#pdfViewer = pdfViewer;
async setDocument(pdfDocument) {
await this.#destroyScripting();
this.#pdfDocument = pdfDocument;
const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
if (!objects && !docActions) {
await this.#destroyScripting();
if (pdfDocument !== this.#pdfDocument) {
this.#scripting = this.#initScripting();
console.error(`setDocument: "${error.message}".`);
await this.#destroyScripting();
const eventBus = this.#eventBus;
this.#eventAbortController = new AbortController();
} = this.#eventAbortController;
eventBus._on("updatefromsandbox", event => {
if (event?.source === window) {
this.#updateFromSandbox(event.detail);
eventBus._on("dispatcheventinsandbox", event => {
this.#scripting?.dispatchEventInSandbox(event.detail);
eventBus._on("pagechanging", ({
if (pageNumber === previous) {
this.#dispatchPageClose(previous);
this.#dispatchPageOpen(pageNumber);
eventBus._on("pagerendered", ({
if (!this._pageOpenPending.has(pageNumber)) {
if (pageNumber !== this.#pdfViewer.currentPageNumber) {
this.#dispatchPageOpen(pageNumber);
eventBus._on("pagesdestroy", async () => {
await this.#dispatchPageClose(this.#pdfViewer.currentPageNumber);
await this.#scripting?.dispatchEventInSandbox({
this.#closeCapability?.resolve();
const docProperties = await this.#docProperties(pdfDocument);
if (pdfDocument !== this.#pdfDocument) {
await this.#scripting.createSandbox({
platform: navigator.platform,
language: navigator.language
eventBus.dispatch("sandboxcreated", {
console.error(`setDocument: "${error.message}".`);
await this.#destroyScripting();
await this.#scripting?.dispatchEventInSandbox({
await this.#dispatchPageOpen(this.#pdfViewer.currentPageNumber, true);
Promise.resolve().then(() => {
if (pdfDocument === this.#pdfDocument) {
async dispatchWillSave() {
return this.#scripting?.dispatchEventInSandbox({
async dispatchDidSave() {
return this.#scripting?.dispatchEventInSandbox({
async dispatchWillPrint() {
await this.#willPrintCapability?.promise;
this.#willPrintCapability = Promise.withResolvers();
await this.#scripting.dispatchEventInSandbox({
this.#willPrintCapability.resolve();
this.#willPrintCapability = null;
await this.#willPrintCapability.promise;
async dispatchDidPrint() {
return this.#scripting?.dispatchEventInSandbox({
return this.#destroyCapability?.promise || null;
return shadow(this, "_pageOpenPending", new Set());
return shadow(this, "_visitedPages", new Map());
async #updateFromSandbox(detail) {
const pdfViewer = this.#pdfViewer;
const isInPresentationMode = pdfViewer.isInPresentationMode || pdfViewer.isChangingPresentationMode;
if (!isInPresentationMode) {
const modes = apiPageLayoutToViewerModes(value);
pdfViewer.spreadMode = modes.spreadMode;
pdfViewer.currentPageNumber = value + 1;
await pdfViewer.pagesPromise;
this.#eventBus.dispatch("print", {
if (!isInPresentationMode) {
pdfViewer.currentScaleValue = value;
this.#eventBus.dispatch("download", {
pdfViewer.currentPageNumber = 1;
pdfViewer.currentPageNumber = pdfViewer.pagesCount;
pdfViewer.previousPage();
if (!isInPresentationMode) {
pdfViewer.increaseScale();
if (!isInPresentationMode) {
pdfViewer.decreaseScale();
case "WillPrintFinished":
this.#willPrintCapability?.resolve();
this.#willPrintCapability = null;
if (isInPresentationMode && detail.focus) {
const ids = siblings ? [id, ...siblings] : [id];
for (const elementId of ids) {
const element = document.querySelector(`[data-element-id="${elementId}"]`);
element.dispatchEvent(new CustomEvent("updatefromsandbox", {
this.#pdfDocument?.annotationStorage.setValue(elementId, detail);
async #dispatchPageOpen(pageNumber, initialize = false) {
const pdfDocument = this.#pdfDocument,
visitedPages = this._visitedPages;
this.#closeCapability = Promise.withResolvers();
if (!this.#closeCapability) {
const pageView = this.#pdfViewer.getPageView(pageNumber - 1);
if (pageView?.renderingState !== RenderingStates.FINISHED) {
this._pageOpenPending.add(pageNumber);
this._pageOpenPending.delete(pageNumber);
const actionsPromise = (async () => {
const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
if (pdfDocument !== this.#pdfDocument) {
await this.#scripting?.dispatchEventInSandbox({
visitedPages.set(pageNumber, actionsPromise);
async #dispatchPageClose(pageNumber) {
const pdfDocument = this.#pdfDocument,
visitedPages = this._visitedPages;
if (!this.#closeCapability) {
if (this._pageOpenPending.has(pageNumber)) {
const actionsPromise = visitedPages.get(pageNumber);
visitedPages.set(pageNumber, null);
if (pdfDocument !== this.#pdfDocument) {
await this.#scripting?.dispatchEventInSandbox({
this.#destroyCapability = Promise.withResolvers();
throw new Error("#initScripting: Scripting already exists.");
return this.#externalServices.createScripting();
async #destroyScripting() {
this.#pdfDocument = null;
this.#destroyCapability?.resolve();
if (this.#closeCapability) {
await Promise.race([this.#closeCapability.promise, new Promise(resolve => {
setTimeout(resolve, 1000);
this.#closeCapability = null;
this.#pdfDocument = null;
await this.#scripting.destroySandbox();
this.#willPrintCapability?.reject(new Error("Scripting destroyed."));
this.#willPrintCapability = null;
this.#eventAbortController?.abort();
this.#eventAbortController = null;
this._pageOpenPending.clear();
this._visitedPages.clear();
this.#destroyCapability?.resolve();
;// CONCATENATED MODULE: ./web/pdf_sidebar.js
const SIDEBAR_WIDTH_VAR = "--sidebar-width";
const SIDEBAR_MIN_WIDTH = 200;
const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
#mouseMoveBound = this.#mouseMove.bind(this);
#mouseUpBound = this.#mouseUp.bind(this);
#outerContainerWidth = null;
this.active = SidebarView.THUMBS;
this.isInitialViewSet = false;
this.isInitialEventDispatched = false;
this.onUpdateThumbnails = null;
this.outerContainer = elements.outerContainer;
this.sidebarContainer = elements.sidebarContainer;
this.toggleButton = elements.toggleButton;
this.resizer = elements.resizer;
this.thumbnailButton = elements.thumbnailButton;
this.outlineButton = elements.outlineButton;
this.attachmentsButton = elements.attachmentsButton;
this.layersButton = elements.layersButton;
this.thumbnailView = elements.thumbnailView;
this.outlineView = elements.outlineView;
this.attachmentsView = elements.attachmentsView;
this.layersView = elements.layersView;
this._currentOutlineItemButton = elements.currentOutlineItemButton;
this.eventBus = eventBus;
this.#isRTL = l10n.getDirection() === "rtl";
this.#addEventListeners();
this.isInitialViewSet = false;
this.isInitialEventDispatched = false;
this.#hideUINotification(true);
this.switchView(SidebarView.THUMBS);
this.outlineButton.disabled = false;
this.attachmentsButton.disabled = false;
this.layersButton.disabled = false;
this._currentOutlineItemButton.disabled = true;
return this.isOpen ? this.active : SidebarView.NONE;
setInitialView(view = SidebarView.NONE) {
if (this.isInitialViewSet) {
this.isInitialViewSet = true;
if (view === SidebarView.NONE || view === SidebarView.UNKNOWN) {
this.switchView(view, true);
if (!this.isInitialEventDispatched) {
switchView(view, forceOpen = false) {
const isViewChanged = view !== this.active;
let forceRendering = false;
if (this.isOpen && isViewChanged) {
case SidebarView.OUTLINE:
if (this.outlineButton.disabled) {
case SidebarView.ATTACHMENTS:
if (this.attachmentsButton.disabled) {