ng2-pdfjs-viewer 26.3.0 → 26.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng2-pdfjs-viewer",
3
- "version": "26.3.0",
3
+ "version": "26.3.1",
4
4
  "description": "The most comprehensive Angular PDF viewer, powered by Mozilla PDF.js 6 — view, annotate, sign, fill forms, search, and read aloud from one component. 8.3M+ downloads, mobile-first, production-ready.",
5
5
  "author": {
6
6
  "name": "Aneesh Goapalakrishnan",
@@ -110,6 +110,14 @@ body #outerContainer.sidebar-right.viewsManagerOpen #loadingBar {
110
110
  pointer-events: none !important;
111
111
  }
112
112
 
113
+ /* A toolbar button forced hidden by [controlVisibility]. Uses our own class,
114
+ not PDF.js's `hidden`, so that PDF.js re-asserting `hidden` on document load
115
+ (the print button via its `printingallowed` handler - Issue #373, seen with
116
+ fast Blob loads) can't bring a hidden button back. */
117
+ .ng2-btn-hidden {
118
+ display: none !important;
119
+ }
120
+
113
121
  /* Whole toolbar hidden (custom host toolbars) - viewer reclaims the height */
114
122
  #outerContainer.ng2-toolbar-hidden #toolbarContainer {
115
123
  display: none !important;
@@ -1 +1 @@
1
- !function(){"use strict";const e="/";let t=null,n=!0;try{const e=new URLSearchParams(window.location.search),o=e.get("urlValidation");if(null!==o){const e=String(o).toLowerCase();n=!("0"===e||"false"===e||"off"===e)}t=e.get("file")}catch(e){}function o(){if(!n||!t)return!0;return new URLSearchParams(window.location.search).get("file")===t||(p(`Security warning: ${o="Unauthorized file access detected. The file URL has been tampered with."}`,"warn"),window.parent&&window.parent!==window&&window.parent.postMessage({type:"ng2-pdfjs-viewer-security-warning",message:o,originalUrl:t,currentUrl:new URLSearchParams(window.location.search).get("file")},e),!1);var o}window.addEventListener("hashchange",o),window.addEventListener("popstate",o);const r=new Set(["enableSignatureEditor","enableComment","enableXfa","enableScripting","enablePermissions","enableAutoLinking","enableHighlightFloatingButton","forcePageColors","pageColorsBackground","pageColorsForeground","highlightEditorColors","defaultZoomValue","viewOnLoad","sidebarViewOnLoad","scrollModeOnLoad","spreadModeOnLoad","cursorToolOnLoad","printResolution","maxCanvasPixels","textLayerMode","disablePageLabels","ignoreDestinationZoom","historyUpdateUrl","disableHistory","enableMerge","enableSplitMerge","enableUpdatedAddImage"]);let a=!1;function i(){if(!a&&"undefined"!=typeof PDFViewerApplicationOptions){a=!0;try{const e=new URLSearchParams(window.location.search).get("pjsOptions");if(!e)return;const t=JSON.parse(e);for(const e of Object.keys(t)){const n=t[e],o=["string","number","boolean"].includes(typeof n);r.has(e)&&o?PDFViewerApplicationOptions.set(e,n):p(`Ignoring pjsOptions key outside allowlist: ${e}`,"warn")}}catch(e){p(`Failed to apply init-time options: ${e.message}`,"error")}}}const s=e=>{e.detail&&e.detail.source&&e.detail.source!==window||(i(),F(),k())};document.addEventListener("webviewerloaded",s);try{window.parent!==window&&window.parent.document&&(window.parent.document.addEventListener("webviewerloaded",s),window.addEventListener("pagehide",()=>{try{window.parent.document.removeEventListener("webviewerloaded",s)}catch(e){}}))}catch(e){}document.addEventListener("DOMContentLoaded",()=>{"undefined"!=typeof PDFViewerApplication&&(i(),F(),k())});const c={activeZoomCommand:!1,markZoomCommandStart(){this.activeZoomCommand=!0},markZoomCommandEnd(){this.activeZoomCommand=!1},isZoomCommandActive(){return this.activeZoomCommand}},d={NOT_LOADED:0,VIEWER_LOADED:1,VIEWER_INITIALIZED:2,EVENTBUS_READY:3,COMPONENTS_READY:4,DOCUMENT_LOADED:5};let l=d.NOT_LOADED,u=!1;function p(e,t="info"){if(!u)return;const n=(new Date).toISOString(),o="[PostMessage]";switch(t){case"error":console.error(`${o} ${n} ERROR: ${e}`);break;case"warn":console.warn(`${o} ${n} WARN: ${e}`);break;default:console.log(`${o} ${n} INFO: ${e}`)}}function g(e,t,n){const o=document.getElementById(e),r=t?document.getElementById(t):null;o&&o.classList.toggle("hidden",!n),r&&r.classList.toggle("hidden",!n)}function m(e,t){const n=document.getElementById(e);n?n.classList.toggle("hidden",!t):p(`Element not found for visibility toggle: ${e}`,"warn")}function f(e,t){const n=document.getElementById(e);n?n.classList.toggle("ng2-hidden-section",!t):p(`Toolbar section not found for visibility toggle: ${e}`,"warn")}function w(t){t<=l||(p(`Readiness state changed: ${l} → ${t}`),l=t,l>=d.EVENTBUS_READY&&function(){P||(P=!0,window.addEventListener("message",D),window.Ng2PdfJsViewerAPI={updateControl:M,getState:b,isReady:()=>l>=d.EVENTBUS_READY,getReadiness:()=>l},function(){const e=PDFViewerApplication;if(!e||!e.eventBus)return;if(function(){if(se)return;const e=PDFViewerApplication;if(!e||!e.eventBus)return void p("Cannot setup error listeners: EventBus not available","warn");e.eventBus.on("documenterror",e=>{p(`🔴 DOCUMENT ERROR EVENT FIRED: ${e.message}`,"error"),h("loading",!1,"system");if(h("error",e.message||"An error occurred while loading the PDF.","system"),oe.documentError){p(`Document error event received: ${e.message}`);v("documentError",{message:e.message||"Unknown document error",source:e.source?"PDFViewerApplication":"unknown",name:e.name||"DocumentError"})}}),e.eventBus.on("loaderror",e=>{p(`🔴 LOAD ERROR EVENT FIRED: ${e.message}`,"error"),h("loading",!1,"system")}),e.eventBus.on("error",e=>{p(`🔴 GENERIC ERROR EVENT FIRED: ${e.message}`,"error"),h("loading",!1,"system")}),se=!0,p("Error event listeners set up successfully","info")}(),e.eventBus.on("documentinit",()=>h("loading",!0,"system")),e.eventBus.on("pagesinit",()=>h("loading",!0,"system")),e.eventBus.on("pagerendered",()=>h("loading",!1,"system")),e.eventBus.on("pagesloaded",()=>h("loading",!1,"system")),e.eventBus.on("documentloaded",()=>{w(d.DOCUMENT_LOADED),function(){if(ce)return;window.addEventListener("error",e=>{p(`🔴 GLOBAL ERROR: ${e.message}`,"error"),h("loading",!1,"system")}),window.addEventListener("unhandledrejection",e=>{p(`🔴 UNHANDLED PROMISE REJECTION: ${e.reason}`,"error"),h("loading",!1,"system")}),ce=!0;const e=PDFViewerApplication;if(!e||!e.eventBus)return void p("Cannot setup bidirectional listeners: EventBus not available","warn");e.eventBus&&(e.eventBus.on("scalechanging",t=>{if(c.isZoomCommandActive())return void p("Skipping zoom notification - programmatic change from our command");let n,o=!1;t.presetValue&&"string"==typeof t.presetValue?(o=!0,n=t.presetValue):"number"!=typeof t.scale||t.presetValue||(p("Assuming user-initiated scale change (mouse wheel, etc.)"),o=!0,n=function(e,t){if("string"==typeof e)return e;if(t?.pdfViewer){const n=t.pdfViewer;if(["page-fit","page-width","page-actual","auto"].includes(n.currentScaleValue))return n.currentScaleValue;const o={.5:"0.5",.75:"0.75",1:"1",1.25:"1.25",1.5:"1.5",2:"2",3:"3",4:"4"};for(const[t,n]of Object.entries(o))if(Math.abs(e-parseFloat(t))<.01)return n}return"number"==typeof e?`${Math.round(100*e)}%`:"auto"}(t.scale,e)),o?h("zoom",n,"user"):p("Skipping zoom notification - not identified as user-initiated")}),e.eventBus.on("switchscrollmode",e=>{const t={0:"vertical",1:"horizontal",2:"wrapped",3:"page"}[e.mode]||"vertical";p(`Scroll mode changed via event to: ${t}`),h("scroll",t,"user")}),e.eventBus.on("switchspreadmode",e=>{const t={0:"none",1:"odd",2:"even"}[e.mode]||"none";p(`Spread mode changed via event to: ${t}`),h("spread",t,"user")}),e.eventBus.on("switchcursortool",e=>{const t={0:"select",1:"hand",2:"zoom"}[e.tool]||"select";p(`Cursor changed via event to: ${t}`),h("cursor",t,"user")}),e.eventBus.on("sidebarviewchanged",e=>{const t={0:"none",1:"thumbs",2:"bookmarks",3:"attachments",4:"layers"}[e.view]||"none";p(`Page mode changed via event to: ${t}`),h("pageMode",t,"user")}),e.eventBus.on("rotationchanging",e=>{p(`Rotation changed via event to: ${e.pagesRotation}`),h("rotation",e.pagesRotation,"user")}),e.eventBus.on("documentinit",e=>{oe.documentInit&&v("documentInit",null)}),e.eventBus.on("pagesinit",t=>{if(oe.pagesInit){v("pagesInit",{pagesCount:e.pagesCount||0})}}),e.eventBus.on("presentationmodechanged",e=>{if(oe.presentationModeChanged){v("presentationModeChanged",{active:3===e.state,switchInProgress:2===e.state})}}),e.eventBus.on("fileinputchange",e=>{oe.openFile&&v("openFile",null)}),e.eventBus.on("find",e=>{if(oe.find){v("find",{query:e.query||"",phraseSearch:!1,caseSensitive:e.caseSensitive||!1,entireWord:e.entireWord||!1,highlightAll:e.highlightAll||!1,findPrevious:e.findPrevious||!1})}}),e.eventBus.on("updatefindmatchescount",e=>{if(oe.updateFindMatchesCount){v("updateFindMatchesCount",{current:e.matchesCount?.current||0,total:e.matchesCount?.total||0})}}),e.eventBus.on("metadataloaded",t=>{if(oe.metadataLoaded){const t=e.documentInfo;v("metadataLoaded",{title:t?.Title,author:t?.Author,subject:t?.Subject,keywords:t?.Keywords,creator:t?.Creator,producer:t?.Producer,creationDate:t?.CreationDate,modificationDate:t?.ModDate,pdfFormatVersion:t?.PDFFormatVersion,isLinearized:t?.IsLinearized,isAcroFormPresent:t?.IsAcroFormPresent,isXFAPresent:t?.IsXFAPresent,isCollectionPresent:t?.IsCollectionPresent})}}),e.eventBus.on("outlineloaded",e=>{if(oe.outlineLoaded){v("outlineLoaded",{items:[],hasOutline:(e.outlineCount||0)>0})}}),e.eventBus.on("pagerendered",e=>{if(oe.pageRendered){v("pageRendered",{pageNumber:e.pageNumber||1,timestamp:Date.now()})}}),e.eventBus.on("sidebarviewchanged",e=>{if(oe.sidebarViewChanged){v("sidebarViewChanged",{view:{0:"none",1:"thumbs",2:"outline",3:"attachments",4:"layers"}[e.view]||"unknown"})}}),e.eventBus.on("layersloaded",e=>{oe.layersChanged&&v("layersChanged",{reason:"loaded",layersCount:e.layersCount||0})}),e.eventBus.on("optionalcontentconfigchanged",()=>{oe.layersChanged&&v("layersChanged",{reason:"changed"})}),e.eventBus.on("namedaction",e=>{oe.namedAction&&v("namedAction",{action:e.action||""})}),e.eventBus.on("documentproperties",()=>{oe.documentProperties&&v("documentProperties",{})}),e.eventBus.on("annotationlayerrendered",e=>{if(oe.annotationLayerRendered){v("annotationLayerRendered",{pageNumber:e.pageNumber||1,error:e.error||null,timestamp:Date.now()})}}),e.eventBus.on("documentloaded",ge));!function(e){oe.idle&&fe();he(e)}(e)}()}),e.eventBus.on("pagesloaded",()=>{l<d.COMPONENTS_READY&&w(d.COMPONENTS_READY)}),function(){document.addEventListener("change",J,!0),document.addEventListener("input",J,!0)}(),e.eventBus.on("pagesedited",t=>{v("pagesEdited",{operation:t&&(t.type||t.operation)||"edit",pagesCount:e.pagesCount})}),e.eventBus.on("pagerendered",e=>{K&&e&&e.source&&e.source.div&&X(e.source.div)}),!window._ng2PrintWrapped){window._ng2PrintWrapped=!0;const e=window.print.bind(window);window.print=function(){G.blockPrint?p("Printing blocked by content protection","warn"):e()}}e.eventBus.on("editingstateschanged",e=>{const t=e&&e.details||e||{};v("annotationEditorStateChange",{isEditing:!0===t.isEditing,isEmpty:!0===t.isEmpty,hasSomethingToUndo:!0===t.hasSomethingToUndo,hasSomethingToRedo:!0===t.hasSomethingToRedo,hasSelectedEditor:!0===t.hasSelectedEditor})}),e.eventBus.on("switchannotationeditormode",e=>{v("annotationEditorModeChange",{mode:{"-1":"disable",0:"none",3:"freetext",9:"highlight",13:"stamp",15:"ink",101:"signature",102:"comment"}[String(e.mode)]??"none"})});try{const t=e.passwordPrompt;if(t&&"function"==typeof t.open&&!t._ng2OpenPatched){const e=t.open.bind(t);t.open=function(...t){return h("loading",!1,"system"),v("passwordPrompt",{}),e(...t)},t._ng2OpenPatched=!0}}catch(e){}}());window.parent.postMessage({type:"postmessage-ready",timestamp:Date.now(),readiness:l},e)}())}function h(t,n,o="user"){try{const r={type:"state-change",property:t,value:n,source:o,timestamp:Date.now()};window.parent.postMessage(r,e)}catch(e){p(`Failed to send state change notification: ${e.message}`,"error")}}function v(t,n){try{const o={type:"event-notification",eventName:t,eventData:n,timestamp:Date.now()};window.parent.postMessage(o,e)}catch(e){p(`Failed to send event notification: ${e.message}`,"error")}}function y(t,n){t&&window.parent&&window.parent.postMessage({type:"control-response",id:t,...n,timestamp:Date.now()},e)}function b(){const e=PDFViewerApplication;return e?{ready:e.initialized,page:e.page,pagesCount:e.pagesCount,currentScale:e.pdfViewer?e.pdfViewer.currentScale:null,currentScaleValue:e.pdfViewer?e.pdfViewer.currentScaleValue:null,pagesRotation:e.pdfViewer?e.pdfViewer.pagesRotation:null,scrollMode:e.pdfViewer?e.pdfViewer.scrollMode:null,spreadMode:e.pdfViewer?e.pdfViewer.spreadMode:null}:{ready:!1}}const E={updateModeViaEventBus:function(e,t,n,o){const r=PDFViewerApplication;if(r?.eventBus)try{const a=n["string"==typeof t?t.toUpperCase():t];void 0!==a?r.eventBus.dispatch(e,{mode:a}):p(`Unknown ${o} mode: ${t}`,"warn")}catch(e){p(`Error updating ${o} mode: ${e.message}`,"error")}else p("EventBus not available for mode update","error")}};function k(){const e=PDFViewerApplication;e?(w(d.VIEWER_LOADED),e.initializedPromise?e.initializedPromise.then(()=>{w(d.VIEWER_INITIALIZED),e.eventBus&&"function"==typeof e.eventBus.dispatch&&(w(d.EVENTBUS_READY),e.pdfViewer&&e.pdfCursorTools&&w(d.COMPONENTS_READY))}).catch(e=>{p(`PDFViewerApplication initialization failed: ${e.message}`,"error")}):e.initialized&&(w(d.VIEWER_INITIALIZED),e.eventBus&&"function"==typeof e.eventBus.dispatch&&(w(d.EVENTBUS_READY),e.pdfViewer&&e.pdfCursorTools&&w(d.COMPONENTS_READY)))):w(d.NOT_LOADED)}let P=!1;function D(e){if(e.source!==window.parent||!e.data)return;const{type:t,action:n,payload:o,id:r}=e.data;if("host-response"===t){const t=C.get(e.data.requestId);return void(t&&(C.delete(e.data.requestId),e.data.error?t.reject(new Error(e.data.error)):t.resolve(e.data.data)))}if("control-update"===t)try{const e=M(n,o);Promise.resolve(e).then(e=>y(r,void 0!==e?{success:!0,action:n,data:e}:{success:!0,action:n,payload:o}),e=>{const t=`Error processing ${n}: ${e.message}`;p(t,"error"),y(r,{success:!1,error:t})})}catch(e){const t=`Error processing ${n}: ${e.message}`;p(t,"error"),y(r,{success:!1,error:t})}}let V=!1,A=0;const C=new Map;function B(t,n){return new Promise((o,r)=>{const a="host-"+ ++A;C.set(a,{resolve:o,reject:r}),window.parent.postMessage({type:"host-request",requestId:a,action:t,payload:n,timestamp:Date.now()},e),setTimeout(()=>{C.delete(a)&&r(new Error("Host request timed out: "+t))},1e4)})}let S=0;let L=!1;function F(){if(L)return;const e="undefined"!=typeof PDFViewerApplication?PDFViewerApplication:null,t=e&&e.externalServices;if(!t||"function"!=typeof t.createSignatureStorage)return;L=!0;const n=t.createSignatureStorage.bind(t);t.createSignatureStorage=(e,t)=>{const o=n(e,t);return{async getAll(){if(!V)return o.getAll();try{const e=await B("signature-storage-get-all",null);return new Map(Object.entries(e||{}))}catch(e){return p("signatureStorage getAll failed: "+e.message,"warn"),new Map}},async size(){return V?(await this.getAll()).size:o.size()},async isFull(){return V?await this.size()>=5:o.isFull()},async create(e){if(!V)return o.create(e);try{if(await this.isFull())return null;const t=function(){if("undefined"!=typeof crypto&&crypto.randomUUID)return crypto.randomUUID();if("undefined"!=typeof crypto&&crypto.getRandomValues){const e=crypto.getRandomValues(new Uint8Array(8));let t="";for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,"0");return"sig-"+t}return"sig-"+Date.now().toString(36)+"-"+(++S).toString(36)}();return await B("signature-storage-save",{uuid:t,data:e}),t}catch(e){return p("signatureStorage save failed: "+e.message,"warn"),null}},async delete(e){if(!V)return o.delete(e);try{return await B("signature-storage-delete",{uuid:e}),!0}catch(e){return p("signatureStorage delete failed: "+e.message,"warn"),!1}}}}}function I(e){let t=0;try{for(const n of e){const e=n&&n[1];e&&!0===e.isClone&&"function"!=typeof e.serialize&&t++}}catch(e){}return t}function O(e){const t=[e[4],e[5]];for(let n=6;n+5<e.length;n+=6)t.push(e[n+4],e[n+5]);return t}function R(e){const t={};for(const n of Object.keys(e))"__proto__"!==n&&"constructor"!==n&&"prototype"!==n&&(t[n]=e[n]);return!0===t.isSignature&&!t.paths&&Array.isArray(t.lines)&&(t.paths={lines:t.lines,points:t.lines.map(O)}),t}function M(e,t){const o=PDFViewerApplication;var r;if(o)try{switch(e){case"show-download":g("downloadButton","secondaryDownload",t);break;case"show-print":g("printButton","secondaryPrint",t);break;case"show-fullscreen":g("presentationMode",null,t);break;case"show-find":g("viewFindButton",null,t);break;case"show-bookmark":g("viewBookmark",null,t);break;case"show-openfile":g("openFile","secondaryOpenFile",t);break;case"show-annotations":!function(e){const t=PDFViewerApplication;try{const n=e?0:-1;t?.eventBus&&t?.pdfViewer?.pdfDocument&&t.pdfViewer.annotationEditorMode!==n&&t.eventBus.dispatch("switchannotationeditormode",{source:null,mode:n})}catch(e){}m("editorModeButtons",e),m("editorModeSeparator",e)}(t);break;case"set-toolbar-density":{const e=document.getElementById("toolbarContainer");if(e){e.classList.remove("density-default","density-compact","density-comfortable");const n="string"==typeof t?t:"default";e.classList.add(`density-${n}`)}break}case"set-sidebar-width":{const e=document.getElementById("outerContainer");e&&"string"==typeof t&&""!==t.trim()&&e.style.setProperty("--ng2-sidebar-width",t);break}case"set-toolbar-position":{const e=document.getElementById("outerContainer");e&&(e.classList.remove("toolbar-bottom"),"bottom"===t&&e.classList.add("toolbar-bottom"));break}case"set-sidebar-position":{const e=document.getElementById("outerContainer");e&&(e.classList.remove("sidebar-right"),"right"===t&&e.classList.add("sidebar-right"));break}case"set-responsive-breakpoint":{const e="number"==typeof t?`${t}px`:`${t}`,n=document.getElementById("outerContainer");n&&e&&n.style.setProperty("--ng2-responsive-breakpoint",e);break}case"show-toolbar-left":f("toolbarViewerLeft",t);break;case"show-toolbar-middle":f("toolbarViewerMiddle",t);break;case"show-toolbar-right":f("toolbarViewerRight",t);break;case"show-secondary-toolbar-toggle":m("secondaryToolbarToggle",t);break;case"show-sidebar":m("viewsManager",t),m("viewsManagerToggleButton",t);break;case"show-sidebar-left":m("viewsManagerSelector",t);break;case"show-sidebar-right":m("viewsManagerCurrentOutlineButton",t);break;case"set-zoom":!function(e){const t=PDFViewerApplication;if(!t||!t.pdfViewer||!t.eventBus)return void p("PDFViewerApplication, pdfViewer, or eventBus not ready for zoom update","warn");if(!t.isInitialViewSet&&"undefined"!=typeof PDFViewerApplicationOptions)try{return void PDFViewerApplicationOptions.set("defaultZoomValue",String(e))}catch(e){}c.markZoomCommandStart();try{if(["auto","page-actual","page-fit","page-width","page-height"].includes(e))return void t.eventBus.dispatch("scalechanged",{source:t.toolbar,value:e});const n=Number(e);if(!isNaN(n)&&n>0)return void t.eventBus.dispatch("scalechanged",{source:t.toolbar,value:e});p(`Invalid zoom value: ${e}`,"warn")}finally{c.markZoomCommandEnd()}}(t);break;case"set-cursor":!function(e){const t=PDFViewerApplication;try{const n=e?e.toUpperCase():"SELECT";let o=0;switch(n){case"HAND":case"H":o=1;break;case"SELECT":case"S":o=0;break;case"ZOOM":case"Z":o=2;break;default:p(`Unknown cursor tool: ${n}, defaulting to SELECT`,"warn"),o=0}t.eventBus&&"function"==typeof t.eventBus.dispatch?t.eventBus.dispatch("switchcursortool",{tool:o}):p("EventBus not available for cursor update","warn")}catch(e){p(`Error updating cursor: ${e.message}`,"error")}}(t);break;case"set-scroll":E.updateModeViaEventBus("switchscrollmode",t,{VERTICAL:0,V:0,HORIZONTAL:1,H:1,WRAPPED:2,W:2,PAGE:3,P:3},"scroll mode");break;case"set-spread":E.updateModeViaEventBus("switchspreadmode",t,{NONE:0,N:0,ODD:1,O:1,EVEN:2,E:2},"spread mode");break;case"set-page":const a=parseInt(t,10);a>0&&a<=PDFViewerApplication.pagesCount?PDFViewerApplication.isInitialViewSet?PDFViewerApplication.page=a:PDFViewerApplication.initialBookmark=`page=${a}`:p(`Invalid page number: ${t}`,"warn");break;case"set-rotation":const i=parseInt(t,10);[0,90,180,270].includes(i)?PDFViewerApplication.pdfViewer.pagesRotation=i:p(`Invalid rotation: ${t}`,"warn");break;case"go-to-last-page":if(!0===t){const e=PDFViewerApplication.pagesCount;PDFViewerApplication.page=e}break;case"go-to-named-dest":if(!t||"string"!=typeof t||""===t.trim()){p(`Skipping invalid named destination: "${t}"`);break}PDFViewerApplication.pdfLinkService.goToDestination(t);break;case"update-page-mode":const s=t?t.toLowerCase():"none";PDFViewerApplication.eventBus.dispatch("pagemode",{mode:s});break;case"set-download-filename":!function(e){try{if(e&&PDFViewerApplication){const t=e.endsWith(".pdf")?e:`${e}.pdf`;PDFViewerApplication._contentDispositionFilename=t}else p("Cannot set download filename - invalid filename or PDFViewerApplication not available","warn")}catch(e){p(`Error setting download filename: ${e.message}`,"error")}}(t);break;case"trigger-download":!0===t&&PDFViewerApplication.eventBus.dispatch("download");break;case"trigger-print":!0===t&&PDFViewerApplication.eventBus.dispatch("print");break;case"trigger-rotate-cw":!0===t&&PDFViewerApplication.eventBus.dispatch("rotatecw");break;case"trigger-rotate-ccw":!0===t&&PDFViewerApplication.eventBus.dispatch("rotateccw");break;case"set-external-link-target":{const e={none:0,self:1,blank:2,parent:3,top:4},n="string"==typeof t?t.toLowerCase():"blank";n in e&&PDFViewerApplication.pdfLinkService?PDFViewerApplication.pdfLinkService.externalLinkTarget=e[n]:p(`Invalid external link target: ${t}`,"warn");break}case"set-remember-last-view":"undefined"!=typeof PDFViewerApplicationOptions&&PDFViewerApplicationOptions.set("viewOnLoad",!1===t?1:0);break;case"set-css-zoom":!function(e){try{"undefined"!=typeof PDFViewerApplicationOptions&&PDFViewerApplicationOptions&&(null===ne&&(ne=PDFViewerApplicationOptions.get("maxCanvasPixels")),PDFViewerApplicationOptions.set("maxCanvasPixels",!0===e?0:ne))}catch(e){p(`Error setting CSS zoom: ${e.message}`,"error")}}(t);break;case"set-theme":!function(e){re=e||"light";const t=document.body;if(t){if(t.classList.remove("ng2-theme-light","ng2-theme-dark","ng2-theme-auto","ng2-theme-dark-active","ng2-theme-light-active"),t.classList.add(`ng2-theme-${re}`),"auto"===re){const e=window.matchMedia("(prefers-color-scheme: dark)").matches?"ng2-theme-dark-active":"ng2-theme-light-active";if(t.classList.add(e),!window.ng2ThemeMediaListener){const e=window.matchMedia("(prefers-color-scheme: dark)");e.addListener(e=>{if("auto"===re){t.classList.remove("ng2-theme-dark-active","ng2-theme-light-active");const n=e.matches?"ng2-theme-dark-active":"ng2-theme-light-active";t.classList.add(n)}}),window.ng2ThemeMediaListener=e}}t.offsetHeight}}(t);break;case"set-primary-color":ie("--ng2-primary-color",t);break;case"set-background-color":!function(e){ie("--ng2-background-color",e)}(t);break;case"set-page-border-color":!function(e){ie("--ng2-page-border-color",e)}(t);break;case"set-page-spacing":t&&function(e,t,n){void 0!==e&&ie("--page-margin",e);void 0!==t&&ie("--spreadHorizontalWrapped-margin-LR",t);void 0!==n&&ie("--page-border",n)}(t.margin,t.spreadMargin,t.border);break;case"set-toolbar-color":!function(e){ie("--ng2-toolbar-color",e)}(t);break;case"set-text-color":!function(e){ie("--ng2-text-color",e)}(t);break;case"set-border-radius":ie("--ng2-border-radius",t);break;case"set-custom-css":"string"==typeof t?ae(t,null):t&&"object"==typeof t&&ae(t.css,t.nonce);break;case"set-diagnostic-logs":u=t;break;case"set-url-validation":n=!0===t,p("URL validation "+(n?"enabled":"disabled"));break;case"set-annotation-editor-mode":{const e={disable:-1,none:0,freetext:3,highlight:9,stamp:13,ink:15,signature:101,comment:102},n="string"==typeof t?t.toLowerCase():"none";if(!(n in e))throw new Error(`Invalid annotation editor mode: ${t}`);o.eventBus.dispatch("switchannotationeditormode",{source:null,mode:e[n]});break}case"set-highlight-editor-colors":"string"==typeof t&&""!==t.trim()&&"undefined"!=typeof PDFViewerApplicationOptions&&PDFViewerApplicationOptions.set("highlightEditorColors",t);break;case"get-annotations":{const e=o.pdfDocument&&o.pdfDocument.annotationStorage;if(!e)throw new Error("No document loaded");const t=e.serializable,n=(t&&t.map?Array.from(t.map.values()):[]).filter(e=>e&&"number"==typeof e.pageIndex);return JSON.parse(JSON.stringify(n,(e,t)=>{if(!("object"==typeof t&&null!==t&&"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap))return ArrayBuffer.isView(t)?Array.from(t):t}))}case"set-signature-storage":V=!0===t;break;case"set-annotations":if(!o.pdfDocument)throw new Error("No document loaded");return function(e){const t=PDFViewerApplication,n=t.pdfDocument.annotationStorage,o=t.pdfViewer&&t.pdfViewer._layerProperties,r=o&&o.annotationEditorUIManager;if(!r||"function"!=typeof r.getId||"function"!=typeof r.findClonesForPage)throw new Error("Annotation editor is not initialized - cannot restore annotations");const a=new Set,i=I(n);let s=0,c=0;for(const o of e){if(!o||!Number.isInteger(o.pageIndex)||o.pageIndex<0||o.pageIndex>=t.pagesCount){c++;continue}const e=R(o),i=r.getId();n.setValue(i,Object.assign(e,{id:i,isCopy:!0,isClone:!0})),a.add(e.pageIndex),s++}const d=[];for(const e of a){const n=t.pdfViewer.getPageView(e),o=n&&n.annotationEditorLayer,a=o&&o.annotationEditorLayer;a&&a.div&&d.push(Promise.resolve(r.findClonesForPage(a)).then(()=>{a.div.hidden=a.isEmpty}).catch(()=>{}))}return Promise.all(d).then(()=>{const e=Math.max(0,I(n)-i);return{restored:Math.max(0,s-e),pending:e,rejected:c}})}(Array.isArray(t)?t:[]);case"save-document":if(!o.pdfDocument)throw new Error("No document loaded");return o.pdfDocument.saveDocument().then(e=>({bytes:e,filename:o._contentDispositionFilename||"document.pdf"}));case"show-toolbar":{const e=document.getElementById("outerContainer");e&&e.classList.toggle("ng2-toolbar-hidden",!1===t);break}case"get-document-text":return N(t||{});case"read-aloud":return function(e){const t=window.speechSynthesis;if(!t)return Promise.reject(new Error("Speech synthesis not supported in this browser"));const n=e.command||"start";switch(n){case"start":t.cancel(),t.resume(),$.active=!0,$.session++,$.rate="number"==typeof e.rate?e.rate:1;q(Math.max(1,e.fromPage||PDFViewerApplication.page||1),$.session);break;case"pause":t.pause(),T("paused");break;case"resume":t.resume(),T("reading");break;case"stop":$.active=!1,$.session++,t.cancel(),t.resume(),x(),T("stopped");break;default:return Promise.reject(new Error(`Unknown read-aloud command: ${n}`))}return Promise.resolve({status:n,page:$.page})}(t||{});case"get-form-data":return W();case"set-form-data":return Z(t||{});case"set-form-field":if(!t||"string"!=typeof t.name)throw new Error("set-form-field requires { name, value }");return Z({[t.name]:t.value});case"set-content-protection":!function(e){G.blockPrint=!0===e.blockPrint,G.blockDownload=!0===e.blockDownload;const t=document.getElementById("viewerContainer");t&&t.classList.toggle("ng2-no-text-select",!0===e.disableTextSelection)}(t||{});break;case"set-watermark":K=(r=t)&&"string"==typeof r.text&&""!==r.text.trim()?r:null,document.querySelectorAll(".ng2-watermark").forEach(e=>e.remove()),K&&document.querySelectorAll(".pdfViewer .page").forEach(e=>X(e));break;case"search":return function(e){const t=PDFViewerApplication;if(!t.pdfDocument)return Promise.reject(new Error("No document loaded"));const n="string"==typeof e?{query:e}:e||{};if(!n.query||"string"==typeof n.query&&""===n.query.trim())return Promise.reject(new Error("Search query is required"));return Q={source:null,type:"",query:n.query,caseSensitive:!0===n.caseSensitive,entireWord:!0===n.entireWord,highlightAll:!1!==n.highlightAll,matchDiacritics:!0===n.matchDiacritics,findPrevious:!1},ee(Q)}(t);case"search-next":return te(!1);case"search-previous":return te(!0);case"clear-search":o.eventBus.dispatch("findbarclose",{source:null}),Q=null;break;case"configure":{const e=[];for(const n of Array.isArray(t)?t:[])try{M(n.action,n.payload)}catch(t){e.push(n.action)}if(e.length>0)throw new Error(`configure failed for: ${e.join(", ")}`);break}default:if(e.startsWith("enable-")){const n=e.slice(7).replace(/-([a-z])/g,(e,t)=>t.toUpperCase());if(n in oe){oe[n]=!0===t,"idle"===n&&(!0===t?fe():me());break}}e.startsWith("set-error-")||p(`Unknown action: ${e}`,"warn")}}catch(t){throw p(`Error in updateControl for action ${e}: ${t.message}`,"error"),t}else p("PDFViewerApplication not available","error")}function N(e){const t=PDFViewerApplication.pdfDocument;if(!t)return Promise.reject(new Error("No document loaded"));const n=Math.max(1,e.from||1),o=Math.min(t.numPages,e.to||t.numPages),r=[];for(let e=n;e<=o;e++)r.push(t.getPage(e).then(t=>t.getTextContent().then(t=>({page:e,text:t.items.map(e=>e.str).join(" ").replace(/\s+/g," ").trim()}))));return Promise.all(r)}const $={active:!1,page:0,rate:1,highlighted:[],session:0};function T(e,t){v("readAloudStateChange",{status:e,page:$.page,sentence:t||void 0})}function x(){for(const e of $.highlighted)e.classList.remove("ng2-tts-current");$.highlighted=[]}function U(e){const t=PDFViewerApplication,n=t.pdfViewer&&t.pdfViewer.getPageView(e-1),o=n&&n.textLayer;return o&&o.div||null}const _=/[^.!?]+[.!?]+["')\]]*\s*|[^.!?]+$/g;function j(e){return $.active&&$.session===e}function z(e,t,n,o){if(!j(o))return;if(n>=t.length)return x(),void q(e+1,o);const r=t[n];x();for(const e of r.els)e.classList.add("ng2-tts-current");$.highlighted=r.els.slice();const a=new SpeechSynthesisUtterance(r.text);a.rate=$.rate,a.onend=()=>{j(o)&&z(e,t,n+1,o)},a.onerror=e=>{const t=e&&e.error;j(o)&&"interrupted"!==t&&"canceled"!==t&&($.active=!1,x(),T("error"))},T("reading",r.text),window.speechSynthesis.speak(a)}function q(e,t){const n=PDFViewerApplication;if(j(t)){if(!n.pdfDocument||e>n.pagesCount)return $.active=!1,x(),void T("finished");$.page=e,n.page!==e&&(n.page=e),function(e,t){const n=U(e);return n&&n.childNodes.length>0?Promise.resolve(n):new Promise(n=>{const o=PDFViewerApplication;let r=!1;const a=()=>{r||(r=!0,o.eventBus.off("textlayerrendered",i),n(U(e)))},i=t=>{t&&t.pageNumber===e&&a()};o.eventBus.on("textlayerrendered",i),setTimeout(a,t)})}(e,1500).then(n=>{if(j(t)){if(n){const o=function(e){let t="";const n=[];for(const o of e){const e=t.length;t+=o.textContent,n.push({start:e,end:t.length,el:o}),t+=" "}const o=[];let r;for(;null!==(r=_.exec(t));){const e=r[0].replace(/\s+/g," ").trim();if(!e)continue;const t=r.index,a=r.index+r[0].length,i=[];for(const e of n)e.start<a&&e.end>t&&i.push(e.el);o.push({text:e,els:i})}return o}(function(e){const t=[];return e.querySelectorAll("span").forEach(e=>{if(e.firstElementChild)return;const n=e.textContent;n&&""!==n.trim()&&t.push(e)}),t}(n));return 0===o.length?void q(e+1,t):void z(e,o,0,t)}N({from:e,to:e}).then(n=>{if(!j(t))return;const o=n[0]&&n[0].text;if(!o)return void q(e+1,t);const r=function(e){const t=[];let n;for(;null!==(n=_.exec(e));){const e=n[0].replace(/\s+/g," ").trim();e&&t.push({text:e,els:[]})}return t}(o);0!==r.length?z(e,r,0,t):q(e+1,t)}).catch(()=>{j(t)&&($.active=!1,x(),T("error"))})}})}}function W(){const e=PDFViewerApplication;return e.pdfDocument?e.pdfDocument.getFieldObjects().then(t=>{const n=e.pdfDocument.annotationStorage,o={};for(const e of Object.keys(t||{}))for(const r of t[e]){let t=r.value;try{const e=n.getRawValue(r.id);e&&void 0!==e.value&&(t=e.value)}catch(e){}o[e]=void 0===t?null:t}return o}):Promise.reject(new Error("No document loaded"))}function Z(e){const t=PDFViewerApplication;return t.pdfDocument?t.pdfDocument.getFieldObjects().then(n=>{if(!n)throw new Error("Document has no form fields");const o=t.pdfDocument.annotationStorage,r=[];let a=0;for(const t of Object.keys(e)){const i=n[t];if(i){for(const n of i)H(o,n,e[t]);a++}else r.push(t)}return r.length>0&&p(`Unknown form fields ignored: ${r.join(", ")}`,"warn"),{applied:a,unknown:r}}):Promise.reject(new Error("No document loaded"))}function H(e,t,n){const o=document.querySelector(`[data-annotation-id="${t.id}"]`),r=o&&o.querySelector("input, textarea, select");if("checkbox"===t.type){const o=!0===n||"true"===n||"string"==typeof n&&"false"!==n&&n===t.exportValues;r&&"checkbox"===r.type?(r.checked=o,r.dispatchEvent(new Event("change",{bubbles:!0}))):e.setValue(t.id,{value:o})}else if("radiobutton"===t.type){const o=n===t.exportValues;r&&"radio"===r.type?o&&(r.checked=!0,r.dispatchEvent(new Event("change",{bubbles:!0}))):e.setValue(t.id,{value:o})}else r?(r.value=null==n?"":String(n),r.dispatchEvent(new Event("input",{bubbles:!0})),r.dispatchEvent(new Event("change",{bubbles:!0}))):e.setValue(t.id,{value:null==n?"":String(n)})}let Y=null;function J(e){const t=e.target;t&&t.closest&&t.closest(".annotationLayer")&&(clearTimeout(Y),Y=setTimeout(()=>{W().then(e=>h("formData",e,"user"),()=>{})},150))}const G={blockPrint:!1,blockDownload:!1};window.addEventListener("keydown",function(e){if(!e.ctrlKey&&!e.metaKey)return;const t=(e.key||"").toLowerCase();(G.blockPrint&&"p"===t||G.blockDownload&&"s"===t)&&(e.preventDefault(),e.stopPropagation())},!0);let K=null;function X(e){if(!K||e.querySelector(".ng2-watermark"))return;const t=document.createElement("div");t.className="ng2-watermark";const n=document.createElement("span");n.textContent=K.text,K.color&&t.style.setProperty("--ng2-watermark-color",K.color),void 0!==K.opacity&&t.style.setProperty("--ng2-watermark-opacity",String(K.opacity)),K.fontSize&&t.style.setProperty("--ng2-watermark-font-size",K.fontSize),void 0!==K.rotation&&t.style.setProperty("--ng2-watermark-rotation",`${K.rotation}deg`),t.appendChild(n),e.appendChild(t)}let Q=null;function ee(e){const t=PDFViewerApplication;return new Promise((n,o)=>{let r=!1,a=null;const i=()=>{t.eventBus.off("updatefindcontrolstate",c),t.eventBus.off("updatefindmatchescount",c),clearTimeout(a),clearTimeout(d)},s=()=>{r||(r=!0,i(),n(function(){const e=PDFViewerApplication.findController,t=e&&e.pageMatches?e.pageMatches.map(e=>e?e.length:0):[],n=[];for(let e=0;e<t.length;e++)t[e]>0&&n.push(e+1);const o=e&&e.selected?e.selected:null;return{total:t.reduce((e,t)=>e+t,0),current:o&&o.pageIdx>=0?{page:o.pageIdx+1,matchIndex:o.matchIdx}:null,matchesPerPage:t,pagesWithMatches:n}}()))},c=()=>{clearTimeout(a),a=setTimeout(s,300)},d=setTimeout(s,1e4);t.eventBus.on("updatefindcontrolstate",c),t.eventBus.on("updatefindmatchescount",c),a=setTimeout(s,900);try{t.eventBus.dispatch("find",e)}catch(e){r=!0,i(),o(e)}})}function te(e){if(!Q)return Promise.reject(new Error("No active search - call search() first"));return ee(Object.assign({},Q,{type:"again",findPrevious:!0===e}))}let ne=null;const oe={beforePrint:!1,afterPrint:!1,pagesLoaded:!1,pageChange:!1,documentError:!0,documentInit:!1,pagesInit:!1,presentationModeChanged:!1,openFile:!1,find:!1,updateFindMatchesCount:!1,metadataLoaded:!1,outlineLoaded:!1,pageRendered:!1,annotationLayerRendered:!1,bookmarkClick:!1,idle:!1,sidebarViewChanged:!1,layersChanged:!1,namedAction:!1,documentProperties:!1};let re="light";function ae(e,t){const n=document.getElementById("ng2-custom-css");if(n&&n.remove(),e){const n=document.createElement("style");n.id="ng2-custom-css",n.textContent=e,t&&n.setAttribute("nonce",t),document.head.appendChild(n)}}function ie(e,t){t?(document.documentElement.style.setProperty(e,t),document.body.style.setProperty(e,t)):(document.documentElement.style.removeProperty(e),document.body.style.removeProperty(e))}let se=!1;let ce=!1;let de=null,le=!1,ue=[];const pe=3e4;function ge(){de&&(clearTimeout(de),de=null),oe.idle&&(de=setTimeout(()=>{v("idle",null)},pe))}function me(){de&&(clearTimeout(de),de=null),ue.forEach(({element:e,event:t,handler:n,options:o})=>{e.removeEventListener(t,n,o)}),ue=[],le=!1,p("Idle detection cleanup completed")}function fe(){if(le)return void p("Idle detection already setup, skipping");le=!0;const e=(e,t,n,o)=>{e.addEventListener(t,n,o),ue.push({element:e,event:t,handler:n,options:o})};e(document,"mousemove",ge,{passive:!0}),e(document,"mousedown",ge,{passive:!0}),e(document,"click",ge,{passive:!0}),e(document,"keydown",ge,{passive:!0}),e(document,"keypress",ge,{passive:!0}),e(document,"scroll",ge,{passive:!0}),e(document,"wheel",ge,{passive:!0}),e(document,"touchstart",ge,{passive:!0}),e(document,"touchmove",ge,{passive:!0}),ge();e(window,"beforeunload",()=>{me()},{passive:!0})}let we=!1;function he(e){if(we)p("Bookmark click interception already setup, skipping");else if(e&&e.pdfOutlineViewer&&e.pdfOutlineViewer._bindLink){const t=e.pdfOutlineViewer._bindLink;e.pdfOutlineViewer._bindLink=function(e,n){if(t.call(this,e,n),oe.bookmarkClick){const t=e.onclick;e.onclick=function(o){const r={title:e.textContent?.trim()||"Unknown",dest:n.dest||null,action:n.action||void 0,url:n.url||void 0,pageNumber:void 0,isCurrentItem:e.classList.contains("currentTreeItem")};return p(`Bookmark clicked: ${r.title}`),v("bookmarkClick",r),!!t&&t.call(this,o)}}},we=!0}else if(e&&e.eventBus){const t=()=>{we||he(e)};e.eventBus.on("outlineloaded",t),p("Bookmark click interception deferred until outline loads")}else p("Unable to setup bookmark click interception - event bus not available","warn")}window.addEventListener("load",()=>{l===d.NOT_LOADED&&"undefined"!=typeof PDFViewerApplication&&k()})}();
1
+ !function(){"use strict";const e="/";let t=null,n=!0;try{const e=new URLSearchParams(window.location.search),o=e.get("urlValidation");if(null!==o){const e=String(o).toLowerCase();n=!("0"===e||"false"===e||"off"===e)}t=e.get("file")}catch(e){}function o(){if(!n||!t)return!0;return new URLSearchParams(window.location.search).get("file")===t||(p(`Security warning: ${o="Unauthorized file access detected. The file URL has been tampered with."}`,"warn"),window.parent&&window.parent!==window&&window.parent.postMessage({type:"ng2-pdfjs-viewer-security-warning",message:o,originalUrl:t,currentUrl:new URLSearchParams(window.location.search).get("file")},e),!1);var o}window.addEventListener("hashchange",o),window.addEventListener("popstate",o);const r=new Set(["enableSignatureEditor","enableComment","enableXfa","enableScripting","enablePermissions","enableAutoLinking","enableHighlightFloatingButton","forcePageColors","pageColorsBackground","pageColorsForeground","highlightEditorColors","defaultZoomValue","viewOnLoad","sidebarViewOnLoad","scrollModeOnLoad","spreadModeOnLoad","cursorToolOnLoad","printResolution","maxCanvasPixels","textLayerMode","disablePageLabels","ignoreDestinationZoom","historyUpdateUrl","disableHistory","enableMerge","enableSplitMerge","enableUpdatedAddImage"]);let a=!1;function i(){if(!a&&"undefined"!=typeof PDFViewerApplicationOptions){a=!0;try{const e=new URLSearchParams(window.location.search).get("pjsOptions");if(!e)return;const t=JSON.parse(e);for(const e of Object.keys(t)){const n=t[e],o=["string","number","boolean"].includes(typeof n);r.has(e)&&o?PDFViewerApplicationOptions.set(e,n):p(`Ignoring pjsOptions key outside allowlist: ${e}`,"warn")}}catch(e){p(`Failed to apply init-time options: ${e.message}`,"error")}}}const s=e=>{e.detail&&e.detail.source&&e.detail.source!==window||(i(),F(),k())};document.addEventListener("webviewerloaded",s);try{window.parent!==window&&window.parent.document&&(window.parent.document.addEventListener("webviewerloaded",s),window.addEventListener("pagehide",()=>{try{window.parent.document.removeEventListener("webviewerloaded",s)}catch(e){}}))}catch(e){}document.addEventListener("DOMContentLoaded",()=>{"undefined"!=typeof PDFViewerApplication&&(i(),F(),k())});const c={activeZoomCommand:!1,markZoomCommandStart(){this.activeZoomCommand=!0},markZoomCommandEnd(){this.activeZoomCommand=!1},isZoomCommandActive(){return this.activeZoomCommand}},d={NOT_LOADED:0,VIEWER_LOADED:1,VIEWER_INITIALIZED:2,EVENTBUS_READY:3,COMPONENTS_READY:4,DOCUMENT_LOADED:5};let l=d.NOT_LOADED,u=!1;function p(e,t="info"){if(!u)return;const n=(new Date).toISOString(),o="[PostMessage]";switch(t){case"error":console.error(`${o} ${n} ERROR: ${e}`);break;case"warn":console.warn(`${o} ${n} WARN: ${e}`);break;default:console.log(`${o} ${n} INFO: ${e}`)}}function g(e,t,n){const o=t?[e,t]:[e];for(const e of o){const t=document.getElementById(e);t&&(t.classList.toggle("hidden",!n),t.classList.toggle("ng2-btn-hidden",!n))}}function m(e,t){const n=document.getElementById(e);n?n.classList.toggle("hidden",!t):p(`Element not found for visibility toggle: ${e}`,"warn")}function f(e,t){const n=document.getElementById(e);n?n.classList.toggle("ng2-hidden-section",!t):p(`Toolbar section not found for visibility toggle: ${e}`,"warn")}function w(t){t<=l||(p(`Readiness state changed: ${l} → ${t}`),l=t,l>=d.EVENTBUS_READY&&function(){P||(P=!0,window.addEventListener("message",D),window.Ng2PdfJsViewerAPI={updateControl:M,getState:b,isReady:()=>l>=d.EVENTBUS_READY,getReadiness:()=>l},function(){const e=PDFViewerApplication;if(!e||!e.eventBus)return;if(function(){if(se)return;const e=PDFViewerApplication;if(!e||!e.eventBus)return void p("Cannot setup error listeners: EventBus not available","warn");e.eventBus.on("documenterror",e=>{p(`🔴 DOCUMENT ERROR EVENT FIRED: ${e.message}`,"error"),h("loading",!1,"system");if(h("error",e.message||"An error occurred while loading the PDF.","system"),oe.documentError){p(`Document error event received: ${e.message}`);v("documentError",{message:e.message||"Unknown document error",source:e.source?"PDFViewerApplication":"unknown",name:e.name||"DocumentError"})}}),e.eventBus.on("loaderror",e=>{p(`🔴 LOAD ERROR EVENT FIRED: ${e.message}`,"error"),h("loading",!1,"system")}),e.eventBus.on("error",e=>{p(`🔴 GENERIC ERROR EVENT FIRED: ${e.message}`,"error"),h("loading",!1,"system")}),se=!0,p("Error event listeners set up successfully","info")}(),e.eventBus.on("documentinit",()=>h("loading",!0,"system")),e.eventBus.on("pagesinit",()=>h("loading",!0,"system")),e.eventBus.on("pagerendered",()=>h("loading",!1,"system")),e.eventBus.on("pagesloaded",()=>h("loading",!1,"system")),e.eventBus.on("documentloaded",()=>{w(d.DOCUMENT_LOADED),function(){if(ce)return;window.addEventListener("error",e=>{p(`🔴 GLOBAL ERROR: ${e.message}`,"error"),h("loading",!1,"system")}),window.addEventListener("unhandledrejection",e=>{p(`🔴 UNHANDLED PROMISE REJECTION: ${e.reason}`,"error"),h("loading",!1,"system")}),ce=!0;const e=PDFViewerApplication;if(!e||!e.eventBus)return void p("Cannot setup bidirectional listeners: EventBus not available","warn");e.eventBus&&(e.eventBus.on("scalechanging",t=>{if(c.isZoomCommandActive())return void p("Skipping zoom notification - programmatic change from our command");let n,o=!1;t.presetValue&&"string"==typeof t.presetValue?(o=!0,n=t.presetValue):"number"!=typeof t.scale||t.presetValue||(p("Assuming user-initiated scale change (mouse wheel, etc.)"),o=!0,n=function(e,t){if("string"==typeof e)return e;if(t?.pdfViewer){const n=t.pdfViewer;if(["page-fit","page-width","page-actual","auto"].includes(n.currentScaleValue))return n.currentScaleValue;const o={.5:"0.5",.75:"0.75",1:"1",1.25:"1.25",1.5:"1.5",2:"2",3:"3",4:"4"};for(const[t,n]of Object.entries(o))if(Math.abs(e-parseFloat(t))<.01)return n}return"number"==typeof e?`${Math.round(100*e)}%`:"auto"}(t.scale,e)),o?h("zoom",n,"user"):p("Skipping zoom notification - not identified as user-initiated")}),e.eventBus.on("switchscrollmode",e=>{const t={0:"vertical",1:"horizontal",2:"wrapped",3:"page"}[e.mode]||"vertical";p(`Scroll mode changed via event to: ${t}`),h("scroll",t,"user")}),e.eventBus.on("switchspreadmode",e=>{const t={0:"none",1:"odd",2:"even"}[e.mode]||"none";p(`Spread mode changed via event to: ${t}`),h("spread",t,"user")}),e.eventBus.on("switchcursortool",e=>{const t={0:"select",1:"hand",2:"zoom"}[e.tool]||"select";p(`Cursor changed via event to: ${t}`),h("cursor",t,"user")}),e.eventBus.on("sidebarviewchanged",e=>{const t={0:"none",1:"thumbs",2:"bookmarks",3:"attachments",4:"layers"}[e.view]||"none";p(`Page mode changed via event to: ${t}`),h("pageMode",t,"user")}),e.eventBus.on("rotationchanging",e=>{p(`Rotation changed via event to: ${e.pagesRotation}`),h("rotation",e.pagesRotation,"user")}),e.eventBus.on("documentinit",e=>{oe.documentInit&&v("documentInit",null)}),e.eventBus.on("pagesinit",t=>{if(oe.pagesInit){v("pagesInit",{pagesCount:e.pagesCount||0})}}),e.eventBus.on("presentationmodechanged",e=>{if(oe.presentationModeChanged){v("presentationModeChanged",{active:3===e.state,switchInProgress:2===e.state})}}),e.eventBus.on("fileinputchange",e=>{oe.openFile&&v("openFile",null)}),e.eventBus.on("find",e=>{if(oe.find){v("find",{query:e.query||"",phraseSearch:!1,caseSensitive:e.caseSensitive||!1,entireWord:e.entireWord||!1,highlightAll:e.highlightAll||!1,findPrevious:e.findPrevious||!1})}}),e.eventBus.on("updatefindmatchescount",e=>{if(oe.updateFindMatchesCount){v("updateFindMatchesCount",{current:e.matchesCount?.current||0,total:e.matchesCount?.total||0})}}),e.eventBus.on("metadataloaded",t=>{if(oe.metadataLoaded){const t=e.documentInfo;v("metadataLoaded",{title:t?.Title,author:t?.Author,subject:t?.Subject,keywords:t?.Keywords,creator:t?.Creator,producer:t?.Producer,creationDate:t?.CreationDate,modificationDate:t?.ModDate,pdfFormatVersion:t?.PDFFormatVersion,isLinearized:t?.IsLinearized,isAcroFormPresent:t?.IsAcroFormPresent,isXFAPresent:t?.IsXFAPresent,isCollectionPresent:t?.IsCollectionPresent})}}),e.eventBus.on("outlineloaded",e=>{if(oe.outlineLoaded){v("outlineLoaded",{items:[],hasOutline:(e.outlineCount||0)>0})}}),e.eventBus.on("pagerendered",e=>{if(oe.pageRendered){v("pageRendered",{pageNumber:e.pageNumber||1,timestamp:Date.now()})}}),e.eventBus.on("sidebarviewchanged",e=>{if(oe.sidebarViewChanged){v("sidebarViewChanged",{view:{0:"none",1:"thumbs",2:"outline",3:"attachments",4:"layers"}[e.view]||"unknown"})}}),e.eventBus.on("layersloaded",e=>{oe.layersChanged&&v("layersChanged",{reason:"loaded",layersCount:e.layersCount||0})}),e.eventBus.on("optionalcontentconfigchanged",()=>{oe.layersChanged&&v("layersChanged",{reason:"changed"})}),e.eventBus.on("namedaction",e=>{oe.namedAction&&v("namedAction",{action:e.action||""})}),e.eventBus.on("documentproperties",()=>{oe.documentProperties&&v("documentProperties",{})}),e.eventBus.on("annotationlayerrendered",e=>{if(oe.annotationLayerRendered){v("annotationLayerRendered",{pageNumber:e.pageNumber||1,error:e.error||null,timestamp:Date.now()})}}),e.eventBus.on("documentloaded",ge));!function(e){oe.idle&&fe();he(e)}(e)}()}),e.eventBus.on("pagesloaded",()=>{l<d.COMPONENTS_READY&&w(d.COMPONENTS_READY)}),function(){document.addEventListener("change",J,!0),document.addEventListener("input",J,!0)}(),e.eventBus.on("pagesedited",t=>{v("pagesEdited",{operation:t&&(t.type||t.operation)||"edit",pagesCount:e.pagesCount})}),e.eventBus.on("pagerendered",e=>{K&&e&&e.source&&e.source.div&&X(e.source.div)}),!window._ng2PrintWrapped){window._ng2PrintWrapped=!0;const e=window.print.bind(window);window.print=function(){G.blockPrint?p("Printing blocked by content protection","warn"):e()}}e.eventBus.on("editingstateschanged",e=>{const t=e&&e.details||e||{};v("annotationEditorStateChange",{isEditing:!0===t.isEditing,isEmpty:!0===t.isEmpty,hasSomethingToUndo:!0===t.hasSomethingToUndo,hasSomethingToRedo:!0===t.hasSomethingToRedo,hasSelectedEditor:!0===t.hasSelectedEditor})}),e.eventBus.on("switchannotationeditormode",e=>{v("annotationEditorModeChange",{mode:{"-1":"disable",0:"none",3:"freetext",9:"highlight",13:"stamp",15:"ink",101:"signature",102:"comment"}[String(e.mode)]??"none"})});try{const t=e.passwordPrompt;if(t&&"function"==typeof t.open&&!t._ng2OpenPatched){const e=t.open.bind(t);t.open=function(...t){return h("loading",!1,"system"),v("passwordPrompt",{}),e(...t)},t._ng2OpenPatched=!0}}catch(e){}}());window.parent.postMessage({type:"postmessage-ready",timestamp:Date.now(),readiness:l},e)}())}function h(t,n,o="user"){try{const r={type:"state-change",property:t,value:n,source:o,timestamp:Date.now()};window.parent.postMessage(r,e)}catch(e){p(`Failed to send state change notification: ${e.message}`,"error")}}function v(t,n){try{const o={type:"event-notification",eventName:t,eventData:n,timestamp:Date.now()};window.parent.postMessage(o,e)}catch(e){p(`Failed to send event notification: ${e.message}`,"error")}}function y(t,n){t&&window.parent&&window.parent.postMessage({type:"control-response",id:t,...n,timestamp:Date.now()},e)}function b(){const e=PDFViewerApplication;return e?{ready:e.initialized,page:e.page,pagesCount:e.pagesCount,currentScale:e.pdfViewer?e.pdfViewer.currentScale:null,currentScaleValue:e.pdfViewer?e.pdfViewer.currentScaleValue:null,pagesRotation:e.pdfViewer?e.pdfViewer.pagesRotation:null,scrollMode:e.pdfViewer?e.pdfViewer.scrollMode:null,spreadMode:e.pdfViewer?e.pdfViewer.spreadMode:null}:{ready:!1}}const E={updateModeViaEventBus:function(e,t,n,o){const r=PDFViewerApplication;if(r?.eventBus)try{const a=n["string"==typeof t?t.toUpperCase():t];void 0!==a?r.eventBus.dispatch(e,{mode:a}):p(`Unknown ${o} mode: ${t}`,"warn")}catch(e){p(`Error updating ${o} mode: ${e.message}`,"error")}else p("EventBus not available for mode update","error")}};function k(){const e=PDFViewerApplication;e?(w(d.VIEWER_LOADED),e.initializedPromise?e.initializedPromise.then(()=>{w(d.VIEWER_INITIALIZED),e.eventBus&&"function"==typeof e.eventBus.dispatch&&(w(d.EVENTBUS_READY),e.pdfViewer&&e.pdfCursorTools&&w(d.COMPONENTS_READY))}).catch(e=>{p(`PDFViewerApplication initialization failed: ${e.message}`,"error")}):e.initialized&&(w(d.VIEWER_INITIALIZED),e.eventBus&&"function"==typeof e.eventBus.dispatch&&(w(d.EVENTBUS_READY),e.pdfViewer&&e.pdfCursorTools&&w(d.COMPONENTS_READY)))):w(d.NOT_LOADED)}let P=!1;function D(e){if(e.source!==window.parent||!e.data)return;const{type:t,action:n,payload:o,id:r}=e.data;if("host-response"===t){const t=C.get(e.data.requestId);return void(t&&(C.delete(e.data.requestId),e.data.error?t.reject(new Error(e.data.error)):t.resolve(e.data.data)))}if("control-update"===t)try{const e=M(n,o);Promise.resolve(e).then(e=>y(r,void 0!==e?{success:!0,action:n,data:e}:{success:!0,action:n,payload:o}),e=>{const t=`Error processing ${n}: ${e.message}`;p(t,"error"),y(r,{success:!1,error:t})})}catch(e){const t=`Error processing ${n}: ${e.message}`;p(t,"error"),y(r,{success:!1,error:t})}}let V=!1,A=0;const C=new Map;function B(t,n){return new Promise((o,r)=>{const a="host-"+ ++A;C.set(a,{resolve:o,reject:r}),window.parent.postMessage({type:"host-request",requestId:a,action:t,payload:n,timestamp:Date.now()},e),setTimeout(()=>{C.delete(a)&&r(new Error("Host request timed out: "+t))},1e4)})}let S=0;let L=!1;function F(){if(L)return;const e="undefined"!=typeof PDFViewerApplication?PDFViewerApplication:null,t=e&&e.externalServices;if(!t||"function"!=typeof t.createSignatureStorage)return;L=!0;const n=t.createSignatureStorage.bind(t);t.createSignatureStorage=(e,t)=>{const o=n(e,t);return{async getAll(){if(!V)return o.getAll();try{const e=await B("signature-storage-get-all",null);return new Map(Object.entries(e||{}))}catch(e){return p("signatureStorage getAll failed: "+e.message,"warn"),new Map}},async size(){return V?(await this.getAll()).size:o.size()},async isFull(){return V?await this.size()>=5:o.isFull()},async create(e){if(!V)return o.create(e);try{if(await this.isFull())return null;const t=function(){if("undefined"!=typeof crypto&&crypto.randomUUID)return crypto.randomUUID();if("undefined"!=typeof crypto&&crypto.getRandomValues){const e=crypto.getRandomValues(new Uint8Array(8));let t="";for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,"0");return"sig-"+t}return"sig-"+Date.now().toString(36)+"-"+(++S).toString(36)}();return await B("signature-storage-save",{uuid:t,data:e}),t}catch(e){return p("signatureStorage save failed: "+e.message,"warn"),null}},async delete(e){if(!V)return o.delete(e);try{return await B("signature-storage-delete",{uuid:e}),!0}catch(e){return p("signatureStorage delete failed: "+e.message,"warn"),!1}}}}}function I(e){let t=0;try{for(const n of e){const e=n&&n[1];e&&!0===e.isClone&&"function"!=typeof e.serialize&&t++}}catch(e){}return t}function O(e){const t=[e[4],e[5]];for(let n=6;n+5<e.length;n+=6)t.push(e[n+4],e[n+5]);return t}function R(e){const t={};for(const n of Object.keys(e))"__proto__"!==n&&"constructor"!==n&&"prototype"!==n&&(t[n]=e[n]);return!0===t.isSignature&&!t.paths&&Array.isArray(t.lines)&&(t.paths={lines:t.lines,points:t.lines.map(O)}),t}function M(e,t){const o=PDFViewerApplication;var r;if(o)try{switch(e){case"show-download":g("downloadButton","secondaryDownload",t);break;case"show-print":g("printButton","secondaryPrint",t);break;case"show-fullscreen":g("presentationMode",null,t);break;case"show-find":g("viewFindButton",null,t);break;case"show-bookmark":g("viewBookmark",null,t);break;case"show-openfile":g("openFile","secondaryOpenFile",t);break;case"show-annotations":!function(e){const t=PDFViewerApplication;try{const n=e?0:-1;t?.eventBus&&t?.pdfViewer?.pdfDocument&&t.pdfViewer.annotationEditorMode!==n&&t.eventBus.dispatch("switchannotationeditormode",{source:null,mode:n})}catch(e){}m("editorModeButtons",e),m("editorModeSeparator",e)}(t);break;case"set-toolbar-density":{const e=document.getElementById("toolbarContainer");if(e){e.classList.remove("density-default","density-compact","density-comfortable");const n="string"==typeof t?t:"default";e.classList.add(`density-${n}`)}break}case"set-sidebar-width":{const e=document.getElementById("outerContainer");e&&"string"==typeof t&&""!==t.trim()&&e.style.setProperty("--ng2-sidebar-width",t);break}case"set-toolbar-position":{const e=document.getElementById("outerContainer");e&&(e.classList.remove("toolbar-bottom"),"bottom"===t&&e.classList.add("toolbar-bottom"));break}case"set-sidebar-position":{const e=document.getElementById("outerContainer");e&&(e.classList.remove("sidebar-right"),"right"===t&&e.classList.add("sidebar-right"));break}case"set-responsive-breakpoint":{const e="number"==typeof t?`${t}px`:`${t}`,n=document.getElementById("outerContainer");n&&e&&n.style.setProperty("--ng2-responsive-breakpoint",e);break}case"show-toolbar-left":f("toolbarViewerLeft",t);break;case"show-toolbar-middle":f("toolbarViewerMiddle",t);break;case"show-toolbar-right":f("toolbarViewerRight",t);break;case"show-secondary-toolbar-toggle":m("secondaryToolbarToggle",t);break;case"show-sidebar":m("viewsManager",t),m("viewsManagerToggleButton",t);break;case"show-sidebar-left":m("viewsManagerSelector",t);break;case"show-sidebar-right":m("viewsManagerCurrentOutlineButton",t);break;case"set-zoom":!function(e){const t=PDFViewerApplication;if(!t||!t.pdfViewer||!t.eventBus)return void p("PDFViewerApplication, pdfViewer, or eventBus not ready for zoom update","warn");if(!t.isInitialViewSet&&"undefined"!=typeof PDFViewerApplicationOptions)try{return void PDFViewerApplicationOptions.set("defaultZoomValue",String(e))}catch(e){}c.markZoomCommandStart();try{if(["auto","page-actual","page-fit","page-width","page-height"].includes(e))return void t.eventBus.dispatch("scalechanged",{source:t.toolbar,value:e});const n=Number(e);if(!isNaN(n)&&n>0)return void t.eventBus.dispatch("scalechanged",{source:t.toolbar,value:e});p(`Invalid zoom value: ${e}`,"warn")}finally{c.markZoomCommandEnd()}}(t);break;case"set-cursor":!function(e){const t=PDFViewerApplication;try{const n=e?e.toUpperCase():"SELECT";let o=0;switch(n){case"HAND":case"H":o=1;break;case"SELECT":case"S":o=0;break;case"ZOOM":case"Z":o=2;break;default:p(`Unknown cursor tool: ${n}, defaulting to SELECT`,"warn"),o=0}t.eventBus&&"function"==typeof t.eventBus.dispatch?t.eventBus.dispatch("switchcursortool",{tool:o}):p("EventBus not available for cursor update","warn")}catch(e){p(`Error updating cursor: ${e.message}`,"error")}}(t);break;case"set-scroll":E.updateModeViaEventBus("switchscrollmode",t,{VERTICAL:0,V:0,HORIZONTAL:1,H:1,WRAPPED:2,W:2,PAGE:3,P:3},"scroll mode");break;case"set-spread":E.updateModeViaEventBus("switchspreadmode",t,{NONE:0,N:0,ODD:1,O:1,EVEN:2,E:2},"spread mode");break;case"set-page":const a=parseInt(t,10);a>0&&a<=PDFViewerApplication.pagesCount?PDFViewerApplication.isInitialViewSet?PDFViewerApplication.page=a:PDFViewerApplication.initialBookmark=`page=${a}`:p(`Invalid page number: ${t}`,"warn");break;case"set-rotation":const i=parseInt(t,10);[0,90,180,270].includes(i)?PDFViewerApplication.pdfViewer.pagesRotation=i:p(`Invalid rotation: ${t}`,"warn");break;case"go-to-last-page":if(!0===t){const e=PDFViewerApplication.pagesCount;PDFViewerApplication.page=e}break;case"go-to-named-dest":if(!t||"string"!=typeof t||""===t.trim()){p(`Skipping invalid named destination: "${t}"`);break}PDFViewerApplication.pdfLinkService.goToDestination(t);break;case"update-page-mode":const s=t?t.toLowerCase():"none";PDFViewerApplication.eventBus.dispatch("pagemode",{mode:s});break;case"set-download-filename":!function(e){try{if(e&&PDFViewerApplication){const t=e.endsWith(".pdf")?e:`${e}.pdf`;PDFViewerApplication._contentDispositionFilename=t}else p("Cannot set download filename - invalid filename or PDFViewerApplication not available","warn")}catch(e){p(`Error setting download filename: ${e.message}`,"error")}}(t);break;case"trigger-download":!0===t&&PDFViewerApplication.eventBus.dispatch("download");break;case"trigger-print":!0===t&&PDFViewerApplication.eventBus.dispatch("print");break;case"trigger-rotate-cw":!0===t&&PDFViewerApplication.eventBus.dispatch("rotatecw");break;case"trigger-rotate-ccw":!0===t&&PDFViewerApplication.eventBus.dispatch("rotateccw");break;case"set-external-link-target":{const e={none:0,self:1,blank:2,parent:3,top:4},n="string"==typeof t?t.toLowerCase():"blank";n in e&&PDFViewerApplication.pdfLinkService?PDFViewerApplication.pdfLinkService.externalLinkTarget=e[n]:p(`Invalid external link target: ${t}`,"warn");break}case"set-remember-last-view":"undefined"!=typeof PDFViewerApplicationOptions&&PDFViewerApplicationOptions.set("viewOnLoad",!1===t?1:0);break;case"set-css-zoom":!function(e){try{"undefined"!=typeof PDFViewerApplicationOptions&&PDFViewerApplicationOptions&&(null===ne&&(ne=PDFViewerApplicationOptions.get("maxCanvasPixels")),PDFViewerApplicationOptions.set("maxCanvasPixels",!0===e?0:ne))}catch(e){p(`Error setting CSS zoom: ${e.message}`,"error")}}(t);break;case"set-theme":!function(e){re=e||"light";const t=document.body;if(t){if(t.classList.remove("ng2-theme-light","ng2-theme-dark","ng2-theme-auto","ng2-theme-dark-active","ng2-theme-light-active"),t.classList.add(`ng2-theme-${re}`),"auto"===re){const e=window.matchMedia("(prefers-color-scheme: dark)").matches?"ng2-theme-dark-active":"ng2-theme-light-active";if(t.classList.add(e),!window.ng2ThemeMediaListener){const e=window.matchMedia("(prefers-color-scheme: dark)");e.addListener(e=>{if("auto"===re){t.classList.remove("ng2-theme-dark-active","ng2-theme-light-active");const n=e.matches?"ng2-theme-dark-active":"ng2-theme-light-active";t.classList.add(n)}}),window.ng2ThemeMediaListener=e}}t.offsetHeight}}(t);break;case"set-primary-color":ie("--ng2-primary-color",t);break;case"set-background-color":!function(e){ie("--ng2-background-color",e)}(t);break;case"set-page-border-color":!function(e){ie("--ng2-page-border-color",e)}(t);break;case"set-page-spacing":t&&function(e,t,n){void 0!==e&&ie("--page-margin",e);void 0!==t&&ie("--spreadHorizontalWrapped-margin-LR",t);void 0!==n&&ie("--page-border",n)}(t.margin,t.spreadMargin,t.border);break;case"set-toolbar-color":!function(e){ie("--ng2-toolbar-color",e)}(t);break;case"set-text-color":!function(e){ie("--ng2-text-color",e)}(t);break;case"set-border-radius":ie("--ng2-border-radius",t);break;case"set-custom-css":"string"==typeof t?ae(t,null):t&&"object"==typeof t&&ae(t.css,t.nonce);break;case"set-diagnostic-logs":u=t;break;case"set-url-validation":n=!0===t,p("URL validation "+(n?"enabled":"disabled"));break;case"set-annotation-editor-mode":{const e={disable:-1,none:0,freetext:3,highlight:9,stamp:13,ink:15,signature:101,comment:102},n="string"==typeof t?t.toLowerCase():"none";if(!(n in e))throw new Error(`Invalid annotation editor mode: ${t}`);o.eventBus.dispatch("switchannotationeditormode",{source:null,mode:e[n]});break}case"set-highlight-editor-colors":"string"==typeof t&&""!==t.trim()&&"undefined"!=typeof PDFViewerApplicationOptions&&PDFViewerApplicationOptions.set("highlightEditorColors",t);break;case"get-annotations":{const e=o.pdfDocument&&o.pdfDocument.annotationStorage;if(!e)throw new Error("No document loaded");const t=e.serializable,n=(t&&t.map?Array.from(t.map.values()):[]).filter(e=>e&&"number"==typeof e.pageIndex);return JSON.parse(JSON.stringify(n,(e,t)=>{if(!("object"==typeof t&&null!==t&&"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap))return ArrayBuffer.isView(t)?Array.from(t):t}))}case"set-signature-storage":V=!0===t;break;case"set-annotations":if(!o.pdfDocument)throw new Error("No document loaded");return function(e){const t=PDFViewerApplication,n=t.pdfDocument.annotationStorage,o=t.pdfViewer&&t.pdfViewer._layerProperties,r=o&&o.annotationEditorUIManager;if(!r||"function"!=typeof r.getId||"function"!=typeof r.findClonesForPage)throw new Error("Annotation editor is not initialized - cannot restore annotations");const a=new Set,i=I(n);let s=0,c=0;for(const o of e){if(!o||!Number.isInteger(o.pageIndex)||o.pageIndex<0||o.pageIndex>=t.pagesCount){c++;continue}const e=R(o),i=r.getId();n.setValue(i,Object.assign(e,{id:i,isCopy:!0,isClone:!0})),a.add(e.pageIndex),s++}const d=[];for(const e of a){const n=t.pdfViewer.getPageView(e),o=n&&n.annotationEditorLayer,a=o&&o.annotationEditorLayer;a&&a.div&&d.push(Promise.resolve(r.findClonesForPage(a)).then(()=>{a.div.hidden=a.isEmpty}).catch(()=>{}))}return Promise.all(d).then(()=>{const e=Math.max(0,I(n)-i);return{restored:Math.max(0,s-e),pending:e,rejected:c}})}(Array.isArray(t)?t:[]);case"save-document":if(!o.pdfDocument)throw new Error("No document loaded");return o.pdfDocument.saveDocument().then(e=>({bytes:e,filename:o._contentDispositionFilename||"document.pdf"}));case"show-toolbar":{const e=document.getElementById("outerContainer");e&&e.classList.toggle("ng2-toolbar-hidden",!1===t);break}case"get-document-text":return N(t||{});case"read-aloud":return function(e){const t=window.speechSynthesis;if(!t)return Promise.reject(new Error("Speech synthesis not supported in this browser"));const n=e.command||"start";switch(n){case"start":t.cancel(),t.resume(),$.active=!0,$.session++,$.rate="number"==typeof e.rate?e.rate:1;q(Math.max(1,e.fromPage||PDFViewerApplication.page||1),$.session);break;case"pause":t.pause(),T("paused");break;case"resume":t.resume(),T("reading");break;case"stop":$.active=!1,$.session++,t.cancel(),t.resume(),x(),T("stopped");break;default:return Promise.reject(new Error(`Unknown read-aloud command: ${n}`))}return Promise.resolve({status:n,page:$.page})}(t||{});case"get-form-data":return W();case"set-form-data":return Z(t||{});case"set-form-field":if(!t||"string"!=typeof t.name)throw new Error("set-form-field requires { name, value }");return Z({[t.name]:t.value});case"set-content-protection":!function(e){G.blockPrint=!0===e.blockPrint,G.blockDownload=!0===e.blockDownload;const t=document.getElementById("viewerContainer");t&&t.classList.toggle("ng2-no-text-select",!0===e.disableTextSelection)}(t||{});break;case"set-watermark":K=(r=t)&&"string"==typeof r.text&&""!==r.text.trim()?r:null,document.querySelectorAll(".ng2-watermark").forEach(e=>e.remove()),K&&document.querySelectorAll(".pdfViewer .page").forEach(e=>X(e));break;case"search":return function(e){const t=PDFViewerApplication;if(!t.pdfDocument)return Promise.reject(new Error("No document loaded"));const n="string"==typeof e?{query:e}:e||{};if(!n.query||"string"==typeof n.query&&""===n.query.trim())return Promise.reject(new Error("Search query is required"));return Q={source:null,type:"",query:n.query,caseSensitive:!0===n.caseSensitive,entireWord:!0===n.entireWord,highlightAll:!1!==n.highlightAll,matchDiacritics:!0===n.matchDiacritics,findPrevious:!1},ee(Q)}(t);case"search-next":return te(!1);case"search-previous":return te(!0);case"clear-search":o.eventBus.dispatch("findbarclose",{source:null}),Q=null;break;case"configure":{const e=[];for(const n of Array.isArray(t)?t:[])try{M(n.action,n.payload)}catch(t){e.push(n.action)}if(e.length>0)throw new Error(`configure failed for: ${e.join(", ")}`);break}default:if(e.startsWith("enable-")){const n=e.slice(7).replace(/-([a-z])/g,(e,t)=>t.toUpperCase());if(n in oe){oe[n]=!0===t,"idle"===n&&(!0===t?fe():me());break}}e.startsWith("set-error-")||p(`Unknown action: ${e}`,"warn")}}catch(t){throw p(`Error in updateControl for action ${e}: ${t.message}`,"error"),t}else p("PDFViewerApplication not available","error")}function N(e){const t=PDFViewerApplication.pdfDocument;if(!t)return Promise.reject(new Error("No document loaded"));const n=Math.max(1,e.from||1),o=Math.min(t.numPages,e.to||t.numPages),r=[];for(let e=n;e<=o;e++)r.push(t.getPage(e).then(t=>t.getTextContent().then(t=>({page:e,text:t.items.map(e=>e.str).join(" ").replace(/\s+/g," ").trim()}))));return Promise.all(r)}const $={active:!1,page:0,rate:1,highlighted:[],session:0};function T(e,t){v("readAloudStateChange",{status:e,page:$.page,sentence:t||void 0})}function x(){for(const e of $.highlighted)e.classList.remove("ng2-tts-current");$.highlighted=[]}function U(e){const t=PDFViewerApplication,n=t.pdfViewer&&t.pdfViewer.getPageView(e-1),o=n&&n.textLayer;return o&&o.div||null}const _=/[^.!?]+[.!?]+["')\]]*\s*|[^.!?]+$/g;function j(e){return $.active&&$.session===e}function z(e,t,n,o){if(!j(o))return;if(n>=t.length)return x(),void q(e+1,o);const r=t[n];x();for(const e of r.els)e.classList.add("ng2-tts-current");$.highlighted=r.els.slice();const a=new SpeechSynthesisUtterance(r.text);a.rate=$.rate,a.onend=()=>{j(o)&&z(e,t,n+1,o)},a.onerror=e=>{const t=e&&e.error;j(o)&&"interrupted"!==t&&"canceled"!==t&&($.active=!1,x(),T("error"))},T("reading",r.text),window.speechSynthesis.speak(a)}function q(e,t){const n=PDFViewerApplication;if(j(t)){if(!n.pdfDocument||e>n.pagesCount)return $.active=!1,x(),void T("finished");$.page=e,n.page!==e&&(n.page=e),function(e,t){const n=U(e);return n&&n.childNodes.length>0?Promise.resolve(n):new Promise(n=>{const o=PDFViewerApplication;let r=!1;const a=()=>{r||(r=!0,o.eventBus.off("textlayerrendered",i),n(U(e)))},i=t=>{t&&t.pageNumber===e&&a()};o.eventBus.on("textlayerrendered",i),setTimeout(a,t)})}(e,1500).then(n=>{if(j(t)){if(n){const o=function(e){let t="";const n=[];for(const o of e){const e=t.length;t+=o.textContent,n.push({start:e,end:t.length,el:o}),t+=" "}const o=[];let r;for(;null!==(r=_.exec(t));){const e=r[0].replace(/\s+/g," ").trim();if(!e)continue;const t=r.index,a=r.index+r[0].length,i=[];for(const e of n)e.start<a&&e.end>t&&i.push(e.el);o.push({text:e,els:i})}return o}(function(e){const t=[];return e.querySelectorAll("span").forEach(e=>{if(e.firstElementChild)return;const n=e.textContent;n&&""!==n.trim()&&t.push(e)}),t}(n));return 0===o.length?void q(e+1,t):void z(e,o,0,t)}N({from:e,to:e}).then(n=>{if(!j(t))return;const o=n[0]&&n[0].text;if(!o)return void q(e+1,t);const r=function(e){const t=[];let n;for(;null!==(n=_.exec(e));){const e=n[0].replace(/\s+/g," ").trim();e&&t.push({text:e,els:[]})}return t}(o);0!==r.length?z(e,r,0,t):q(e+1,t)}).catch(()=>{j(t)&&($.active=!1,x(),T("error"))})}})}}function W(){const e=PDFViewerApplication;return e.pdfDocument?e.pdfDocument.getFieldObjects().then(t=>{const n=e.pdfDocument.annotationStorage,o={};for(const e of Object.keys(t||{}))for(const r of t[e]){let t=r.value;try{const e=n.getRawValue(r.id);e&&void 0!==e.value&&(t=e.value)}catch(e){}o[e]=void 0===t?null:t}return o}):Promise.reject(new Error("No document loaded"))}function Z(e){const t=PDFViewerApplication;return t.pdfDocument?t.pdfDocument.getFieldObjects().then(n=>{if(!n)throw new Error("Document has no form fields");const o=t.pdfDocument.annotationStorage,r=[];let a=0;for(const t of Object.keys(e)){const i=n[t];if(i){for(const n of i)H(o,n,e[t]);a++}else r.push(t)}return r.length>0&&p(`Unknown form fields ignored: ${r.join(", ")}`,"warn"),{applied:a,unknown:r}}):Promise.reject(new Error("No document loaded"))}function H(e,t,n){const o=document.querySelector(`[data-annotation-id="${t.id}"]`),r=o&&o.querySelector("input, textarea, select");if("checkbox"===t.type){const o=!0===n||"true"===n||"string"==typeof n&&"false"!==n&&n===t.exportValues;r&&"checkbox"===r.type?(r.checked=o,r.dispatchEvent(new Event("change",{bubbles:!0}))):e.setValue(t.id,{value:o})}else if("radiobutton"===t.type){const o=n===t.exportValues;r&&"radio"===r.type?o&&(r.checked=!0,r.dispatchEvent(new Event("change",{bubbles:!0}))):e.setValue(t.id,{value:o})}else r?(r.value=null==n?"":String(n),r.dispatchEvent(new Event("input",{bubbles:!0})),r.dispatchEvent(new Event("change",{bubbles:!0}))):e.setValue(t.id,{value:null==n?"":String(n)})}let Y=null;function J(e){const t=e.target;t&&t.closest&&t.closest(".annotationLayer")&&(clearTimeout(Y),Y=setTimeout(()=>{W().then(e=>h("formData",e,"user"),()=>{})},150))}const G={blockPrint:!1,blockDownload:!1};window.addEventListener("keydown",function(e){if(!e.ctrlKey&&!e.metaKey)return;const t=(e.key||"").toLowerCase();(G.blockPrint&&"p"===t||G.blockDownload&&"s"===t)&&(e.preventDefault(),e.stopPropagation())},!0);let K=null;function X(e){if(!K||e.querySelector(".ng2-watermark"))return;const t=document.createElement("div");t.className="ng2-watermark";const n=document.createElement("span");n.textContent=K.text,K.color&&t.style.setProperty("--ng2-watermark-color",K.color),void 0!==K.opacity&&t.style.setProperty("--ng2-watermark-opacity",String(K.opacity)),K.fontSize&&t.style.setProperty("--ng2-watermark-font-size",K.fontSize),void 0!==K.rotation&&t.style.setProperty("--ng2-watermark-rotation",`${K.rotation}deg`),t.appendChild(n),e.appendChild(t)}let Q=null;function ee(e){const t=PDFViewerApplication;return new Promise((n,o)=>{let r=!1,a=null;const i=()=>{t.eventBus.off("updatefindcontrolstate",c),t.eventBus.off("updatefindmatchescount",c),clearTimeout(a),clearTimeout(d)},s=()=>{r||(r=!0,i(),n(function(){const e=PDFViewerApplication.findController,t=e&&e.pageMatches?e.pageMatches.map(e=>e?e.length:0):[],n=[];for(let e=0;e<t.length;e++)t[e]>0&&n.push(e+1);const o=e&&e.selected?e.selected:null;return{total:t.reduce((e,t)=>e+t,0),current:o&&o.pageIdx>=0?{page:o.pageIdx+1,matchIndex:o.matchIdx}:null,matchesPerPage:t,pagesWithMatches:n}}()))},c=()=>{clearTimeout(a),a=setTimeout(s,300)},d=setTimeout(s,1e4);t.eventBus.on("updatefindcontrolstate",c),t.eventBus.on("updatefindmatchescount",c),a=setTimeout(s,900);try{t.eventBus.dispatch("find",e)}catch(e){r=!0,i(),o(e)}})}function te(e){if(!Q)return Promise.reject(new Error("No active search - call search() first"));return ee(Object.assign({},Q,{type:"again",findPrevious:!0===e}))}let ne=null;const oe={beforePrint:!1,afterPrint:!1,pagesLoaded:!1,pageChange:!1,documentError:!0,documentInit:!1,pagesInit:!1,presentationModeChanged:!1,openFile:!1,find:!1,updateFindMatchesCount:!1,metadataLoaded:!1,outlineLoaded:!1,pageRendered:!1,annotationLayerRendered:!1,bookmarkClick:!1,idle:!1,sidebarViewChanged:!1,layersChanged:!1,namedAction:!1,documentProperties:!1};let re="light";function ae(e,t){const n=document.getElementById("ng2-custom-css");if(n&&n.remove(),e){const n=document.createElement("style");n.id="ng2-custom-css",n.textContent=e,t&&n.setAttribute("nonce",t),document.head.appendChild(n)}}function ie(e,t){t?(document.documentElement.style.setProperty(e,t),document.body.style.setProperty(e,t)):(document.documentElement.style.removeProperty(e),document.body.style.removeProperty(e))}let se=!1;let ce=!1;let de=null,le=!1,ue=[];const pe=3e4;function ge(){de&&(clearTimeout(de),de=null),oe.idle&&(de=setTimeout(()=>{v("idle",null)},pe))}function me(){de&&(clearTimeout(de),de=null),ue.forEach(({element:e,event:t,handler:n,options:o})=>{e.removeEventListener(t,n,o)}),ue=[],le=!1,p("Idle detection cleanup completed")}function fe(){if(le)return void p("Idle detection already setup, skipping");le=!0;const e=(e,t,n,o)=>{e.addEventListener(t,n,o),ue.push({element:e,event:t,handler:n,options:o})};e(document,"mousemove",ge,{passive:!0}),e(document,"mousedown",ge,{passive:!0}),e(document,"click",ge,{passive:!0}),e(document,"keydown",ge,{passive:!0}),e(document,"keypress",ge,{passive:!0}),e(document,"scroll",ge,{passive:!0}),e(document,"wheel",ge,{passive:!0}),e(document,"touchstart",ge,{passive:!0}),e(document,"touchmove",ge,{passive:!0}),ge();e(window,"beforeunload",()=>{me()},{passive:!0})}let we=!1;function he(e){if(we)p("Bookmark click interception already setup, skipping");else if(e&&e.pdfOutlineViewer&&e.pdfOutlineViewer._bindLink){const t=e.pdfOutlineViewer._bindLink;e.pdfOutlineViewer._bindLink=function(e,n){if(t.call(this,e,n),oe.bookmarkClick){const t=e.onclick;e.onclick=function(o){const r={title:e.textContent?.trim()||"Unknown",dest:n.dest||null,action:n.action||void 0,url:n.url||void 0,pageNumber:void 0,isCurrentItem:e.classList.contains("currentTreeItem")};return p(`Bookmark clicked: ${r.title}`),v("bookmarkClick",r),!!t&&t.call(this,o)}}},we=!0}else if(e&&e.eventBus){const t=()=>{we||he(e)};e.eventBus.on("outlineloaded",t),p("Bookmark click interception deferred until outline loads")}else p("Unable to setup bookmark click interception - event bus not available","warn")}window.addEventListener("load",()=>{l===d.NOT_LOADED&&"undefined"!=typeof PDFViewerApplication&&k()})}();