/*!
 * Nutrient Web SDK 1.18.0-d151a78 (https://www.nutrient.io/sdk/web)
 *
 * Copyright (c) 2016-2026 PSPDFKit GmbH. All rights reserved.
 *
 * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
 * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
 * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
 * This notice may not be removed from this file.
 *
 * PSPDFKit uses several open source third-party components: https://www.nutrient.io/legal/acknowledgements/web-acknowledgements/
 */
"use strict";(globalThis.webpackChunkNutrientViewer=globalThis.webpackChunkNutrientViewer||[]).push([[362],{96576(t,e,n){n.r(e),n.d(e,{corePool:()=>u.mG,customFontsPromiseRef:()=>N,default:()=>z,loadModule:()=>W,normalizeCoreOptions:()=>u.DO,validateStandaloneConfiguration:()=>u.mn});var s=n(34724),a=n(29484),i=n(49807),o=n(35560),r=n(15243),c=n(15156),l=n(47739),u=n(69331),d=n(1798),h=n(81054),f=n(91202),m=n(95267),p=n(75336),y=n(81124),g=n(48242),w=n(1155);function A(t){return null!==t&&(0,w.uA)(t)&&!(0,w.C5)(t)}function b(t){return"opfs"!==t.mode?"memory":t.isAuto?"auto":"opfs"}function _(t,e){const n={credentials:"same-origin"};if(t&&Object.keys(t).length>0){const e=new Headers;Object.entries(t).forEach(t=>{let[n,s]=t;e.append(n,s)}),n.headers=e}return e&&(n.signal=e),n}function P(t,e){"opfs"===t.mode&&(t.isAuto?(0,i.R8)(`OPFS storage: ${e}. Falling back to memory.`):(0,i.R8)(`OPFS storage was explicitly requested, but ${e}. Falling back to memory.`))}async function S(t){try{await t.closeOPFSStorage()}catch{}}async function v(t,e,n,s,a,o,r,c,l){const u=_(a,l);let d;r?(d=r,o?.()):d=await fetch(t,u).finally(()=>{o?.()});const h=(f=d.headers?.get("Content-Type"),f?.toLowerCase().split(";")[0].trim()||null);var f;c?.(h);const m=d.headers?.get("Content-Length"),p=m?parseInt(m,10):null,y=Number.isFinite(p)?p:null,v=b(s),D=function(t,e,n){return"opfs"===t.mode&&!A(e)&&(null===t.minFileSize||null!==n&&n>=t.minFileSize)}(s,h,y);let F;if("opfs"===s.mode&&(A(h)?F="unsupported-content-type":null!==s.minFileSize&&null===y?F="file-size-unknown":null!==s.minFileSize&&null!==y&&y<s.minFileSize&&(F="below-min-file-size")),D){const a=await async function(t,e,n,s){const a=t.headers?.get("Content-Length");if(!a)return P(s,"the Content-Length header is missing"),{document:null,canReuseResponse:!0,fallbackReason:"content-length-missing"};const o=parseInt(a,10);if(isNaN(o)||o<=0)return P(s,"the Content-Length header is invalid"),{document:null,canReuseResponse:!0,fallbackReason:"content-length-invalid"};if(!await e.initOPFSStorage(o))return{document:null,canReuseResponse:!0,fallbackReason:"init-failed"};const r=1048576,c=t.body?.getReader();if(!c)return(0,i.R8)("OPFS storage: ReadableStream not available. Falling back to memory."),await S(e),{document:null,canReuseResponse:!0,fallbackReason:"readable-stream-unavailable"};let l=0,u=null;try{let t=new Uint8Array(r),n=0;for(;;){const{done:s,value:a}=await c.read();if(s){if(n>0){const s=t.subarray(0,n);await e.writeOPFSChunk(s,l-n)}break}null===u&&(u=a.slice(0,Math.min(a.byteLength,16384)));let i=0;for(;i<a.byteLength;){const s=r-n,o=Math.min(s,a.byteLength-i);t.set(a.subarray(i,i+o),n),n+=o,i+=o,l+=o,n===r&&(await e.writeOPFSChunk(t,l-n),t=new Uint8Array(r),n=0)}}}catch(t){return(0,i.R8)(`OPFS storage: error during streaming write: ${t}. Falling back to memory.`),await S(e),{document:null,canReuseResponse:!1,fallbackReason:"streaming-write-error"}}if(l!==o)return(0,i.R8)(`OPFS storage: short response (${l} of ${o} bytes). Falling back to memory.`),await S(e),{document:null,canReuseResponse:!1,fallbackReason:"short-response"};try{const a=Math.min(o,16384),i=null!==u&&u.byteLength>=a?u.slice(0,a):await e.readOPFSBytes(0,a),r=i.slice(0,Math.min(i.byteLength,8192)),c=await(0,w.oj)(r.buffer,n,t.headers?.get("Content-Type"));return{document:{type:"opfs",isFullyAvailable:!0,fullDocument:null,opfsActive:!0,documentHeadBuffer:i.buffer,contentType:c,storageAnalytics:{storageRequested:b(s),storageActual:"opfs"}},canReuseResponse:!1}}catch(t){return(0,i.R8)(`OPFS storage: error during finalization: ${t}. Falling back to memory.`),await S(e),{document:null,canReuseResponse:!1,fallbackReason:"finalization-error"}}}(d,e,n,s);if(a.document)return a.document;F=a.fallbackReason??F,(0,g.q)("DocumentLoader: OPFS load failed; falling back to in-memory document load",{canReuseResponse:a.canReuseResponse,fallbackReason:F}),a.canReuseResponse||(d=await fetch(t,u))}const C=await d.arrayBuffer();return{type:"memory",isFullyAvailable:!0,fullDocument:C,contentType:await(0,w.oj)(C,n,d.headers?.get("Content-Type")),storageAnalytics:{storageRequested:v,storageActual:"memory",...F?{storageFallbackReason:F}:{}}}}async function D(t,e,n,s){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{mode:"memory"},r=arguments.length>5?arguments[5]:void 0,c=arguments.length>6?arguments[6]:void 0,l=arguments.length>7?arguments[7]:void 0,u=arguments.length>8?arguments[8]:void 0;if(t instanceof ArrayBuffer){const e=await(0,w.oj)(t,n),s=b(a);return l?.(e),{type:"memory",isFullyAvailable:!0,fullDocument:t,contentType:e,storageAnalytics:{storageRequested:s,storageActual:"memory",..."memory"!==s?{storageFallbackReason:"arraybuffer-input"}:{}}}}(0,i.V1)("string"==typeof t,"Document is not a string");let d=!1;const{linearizedDocument:h,serverSupportsRangeRequests:f,fallbackResponse:m,firstChunk:p}=await(async()=>{if(s&&function(t){if(t.startsWith("/"))return!0;try{const e=new URL(t);return"http:"===e.protocol||"https:"===e.protocol}catch(t){return!1}}(t)){const e=await n.openLinearizedDocument(o.EA);(0,i.V1)(e,"Linearized document is not available");const s=await e.initialize(t,r,u);return s.supportsRanges?(l?.(e.contentType??null),{linearizedDocument:e,serverSupportsRangeRequests:!0,fallbackResponse:void 0,firstChunk:s.firstChunk}):{linearizedDocument:null,serverSupportsRangeRequests:!1,fallbackResponse:s.fullResponse,firstChunk:void 0}}return{linearizedDocument:null,serverSupportsRangeRequests:!1,fallbackResponse:void 0,firstChunk:void 0}})();try{if(!f)return d=!0,v(t,e,n,a,r,c,m,l,u);(0,i.V1)(h,"Linearized document is not available"),h.startDownload();if(!await h.waitUntilIsLinearizedIsKnown(u))return await h.destroyAsync(),d=!0,v(t,e,n,a,r,c,void 0,l,u);c?.();const s=await h.waitUntilDocumentInfoAvailable(u);if(!s)return await h.destroyAsync(),d=!0,v(t,e,n,a,r,c,void 0,l,u);"undefined"!=typeof performance&&"function"==typeof performance.mark&&performance.mark("linearized-first-page-ready"),c?.();const o=p?p.slice(0,Math.min(p.byteLength,16384)).buffer:void 0;return{type:"linearized",isFullyAvailable:!1,documentResponse:s,contentType:"application/pdf",storageAnalytics:{storageRequested:b(a),storageActual:h.isUsingOPFS?"opfs":"memory",...h.opfsFallbackReason?{storageFallbackReason:h.opfsFallbackReason}:{}},...o?{documentHeadBuffer:o}:{}}}catch(s){if(await(h?.destroyAsync()),s instanceof DOMException&&"AbortError"===s.name)throw s;if(d)throw s;return v(t,e,n,a,r,c,void 0,l,u)}}var F=n(605),C=n(62578),L=n(15026),R=n(10788);const I=/^[0-9A-HJKMNP-TV-Z]{26}$/i;function E(t,e,n){const s=new i.uE(t);return s.status=e,s.body=n,s}async function k(t,e,n){let s;try{s=await fetch(function(t){const e=t??"https://api.pspdfkit.com/";return(0,R.Me)(e),`${e}i/viewer/standalone/auth`}(e),{method:"POST",headers:{Accept:"application/json",Authorization:`Bearer ${t}`,"Content-Type":"application/json","PSPDFKit-Platform":"web","PSPDFKit-Version":"cloud-protocol=1, server-protocol=5, client=1.18.0-d151a78, client-git=d151a78d29"},body:JSON.stringify({}),signal:n??void 0})}catch(t){if("undefined"!=typeof DOMException&&t instanceof DOMException&&"AbortError"===t.name||t instanceof Error&&"AbortError"===t.name)throw t;const e=t instanceof Error?t.message:String(t);throw new i.uE(`DWS Viewer API authorization failed while connecting to the authorization endpoint: ${e}`)}if(!s.ok){const t=await s.text();throw function(t,e){return 401===t.status?E("DWS Viewer API authorization failed: the publishable key or session is invalid, expired, or missing.",t.status,e):403===t.status?E("DWS Viewer API authorization failed: the publishable key, session type, origin, local document entitlement, or policy was rejected.",t.status,e):402===t.status?E("DWS Viewer API authorization failed: the viewer session quota is exhausted.",t.status,e):422===t.status?E("DWS Viewer API authorization failed: the viewer session limit is exhausted.",t.status,e):429===t.status?E("DWS Viewer API authorization failed: the authorization endpoint rate limit was exceeded.",t.status,e):E("DWS Viewer API authorization failed while connecting to the authorization endpoint.",t.status,e)}(s,t)}const a=await s.json();if("string"!=typeof a.wasmAuthToken||0===a.wasmAuthToken.length)throw new i.uE("DWS Viewer API authorization failed: response is missing wasmAuthToken.");if("string"!=typeof(o=a.tenantId)||!I.test(o))throw new i.uE("DWS Viewer API authorization failed: response is missing a valid tenantId.");var o;return{wasmAuthToken:a.wasmAuthToken,tenantId:a.tenantId}}class O{constructor(t){(0,s.A)(this,"_destroyed",!1),(0,s.A)(this,"_authorizationAbortController",null),(0,s.A)(this,"_tenantId",null),this._session=t.session,this._hostedBaseUrl=t.hostedBaseUrl}get tenantId(){return this._tenantId}async authorizeInitial(t){const e=await this.authorize(t);return this._tenantId=e.tenantId,e}destroy(){this._destroyed=!0,this._authorizationAbortController?.abort(),this._authorizationAbortController=null}async authorize(t){if(this._destroyed)throw new i.uE("DWS Viewer API auth module was destroyed.");const e=new AbortController,n=()=>e.abort();this._authorizationAbortController=e,t?.aborted?n():t?.addEventListener("abort",n,{once:!0});try{return await k(this._session,this._hostedBaseUrl,e.signal)}finally{t?.removeEventListener("abort",n),this._authorizationAbortController===e&&(this._authorizationAbortController=null)}}}var B=n(36260);let T;class U extends Error{}class z extends u.Ay{waitForAbandonedLoad(){return new Promise((t,e)=>{const n=this._loadSignal;n?.aborted?e((0,B.NK)()):n&&n.addEventListener("abort",()=>e((0,B.NK)()),{once:!0})})}raceWithLoadAbort(t){const e=this._loadSignal;return e?e.aborted?Promise.reject(new U):new Promise((n,s)=>{const a=()=>{s(new U)};e.addEventListener("abort",a,{once:!0}),t.then(t=>{e.removeEventListener("abort",a),n(t)},t=>{e.removeEventListener("abort",a),s(t)})}):t}retainGdPictureLoad(){this._retainedGdPictureLoad||(this._retainedGdPictureLoad=!0,(0,p.qR)())}async releaseGdPictureLoad(){this._retainedGdPictureLoad&&(this._retainedGdPictureLoad=!1,await(0,p.M7)())}async abandonLoadAfterCleanup(){throw await this.releaseGdPictureLoad(),new U}async openDocumentOrAbandon(t,e){try{const n=await this.client.openDocument(t,e);return this.destroyed&&await this.abandonLoadAfterCleanup(),n}catch(t){throw this.destroyed&&await this.abandonLoadAfterCleanup(),t}}async openDocumentWithOPFSOrAbandon(t){try{const e=await this.client.openDocumentWithOPFS(t);return this.destroyed&&await this.abandonLoadAfterCleanup(),e}catch(t){throw this.destroyed&&await this.abandonLoadAfterCleanup(),t}}stashDocumentHeadBuffer(t){const e=Math.min(t.byteLength,16384);this._documentHeadBuffer=t.slice(0,e)}constructor(t){const e=t.baseUrl||(0,l.$_)(window.document),n=t.baseCoreUrl||e,a=t.baseProcessorEngineUrl||e,o={...t,baseUrl:e,baseCoreUrl:n,baseProcessorEngineUrl:a};if("string"!=typeof o.baseUrl)throw new i.uE("`baseUrl` is mandatory and must be a valid URL, e.g. `https://example.com/`");if("string"!=typeof o.document&&!(o.document instanceof ArrayBuffer))throw new i.uE("document must be either an URL to a supported document type (PDF and images), e.g. `https://example.com/document.pdf`, or an `ArrayBuffer`");const r="string"==typeof o.session;if(!r&&T&&T!==o.licenseKey)throw new i.uE("Trying to re-use instance with a different licenseKey.\nUnfortunately we only allow one licenseKey per instance.\nPlease contact support for further assistance.");if("string"==typeof o.licenseKey&&o.licenseKey.startsWith("TRIAL-"))throw new i.uE("You're using the npm key instead of the license key. This key is used to download the Nutrient Web SDK package via the node package manager.\n\nLeave out the license key to activate as a trial.");super(o),(0,s.A)(this,"_resolvedPdfBuffer",null),(0,s.A)(this,"_documentHeadBuffer",null),(0,s.A)(this,"_loadInProgress",!1),(0,s.A)(this,"_loadSignal",null),(0,s.A)(this,"_retainedGdPictureLoad",!1),(0,s.A)(this,"_opfsActive",!1),(0,s.A)(this,"_documentStorageAnalytics",null),(0,s.A)(this,"_dwsStandaloneAuthModule",null),(0,s.A)(this,"corePDFAccess",null),(0,s.A)(this,"_pageHideListener",t=>{t.persisted||this.destroyed||"opfs"!==this._state.storage.mode||this.cleanupOPFSStorage("pagehide",!1)}),this.destroyed=!1,this.activeConfiguration=t,this._usesDWSStandaloneAuth=r,r&&(this.client.destroy(),this._dwsStandaloneAuthModule=new O({session:o.session,hostedBaseUrl:o.hostedBaseUrl})),window.addEventListener("pagehide",this._pageHideListener)}cleanupOPFSStorage(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const n=this.corePDFAccess,s="opfs"===this._state.storage.mode&&n&&(!e||this._opfsActive);this._opfsActive=!1,s&&n.closeOPFSStorage().catch(e=>{(0,i.R8)(`OPFS storage cleanup error (${t}): ${e}`)})}async load(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._resolvedPdfBuffer=null,this._documentHeadBuffer=null,this._opfsActive=!1,this._documentStorageAnalytics=null,this._loadInProgress=!0,this._loadSignal=t.signal??null;let e=!0,n=null;try{const s=()=>{try{const e=this._retainedGdPictureLoad;if(this.retainGdPictureLoad(),e)return;t.onGdPicturePreloadStart?.();let n=(0,p.jU)();n||(n=(0,p.NY)({baseUrl:this._state.baseProcessorEngineUrl,mainThreadOrigin:this._state.appName||(0,r.D5)()||window.location.origin,licenseKey:this._state.licenseKey||void 0,customFonts:this._state.customFonts||void 0,dynamicFonts:this._state.dynamicFonts||void 0,fontSubstitutions:this._state.fontSubstitutions,processorEngine:this._state.processorEngine}),(0,p.Pm)(n)),t.onGdPictureReady&&n.then(t.onGdPictureReady).catch(()=>{})}catch(t){console.error("Error initializing GdPicture client:",t)}};let o,l=.2;t.progressCallback&&t.progressCallback("loading",l),this._isPDFJavaScriptEnabled=t.isPDFJavaScriptEnabled,"string"==typeof this._state.document&&(0,w.XC)(this._state.baseUrl,this._state.document,this._state.productId);const u=t=>{e&&!1!==n&&(0,w.uA)(t)&&s()};let d;this._state.document instanceof ArrayBuffer&&(0,w.oj)(this._state.document).then(t=>{o=t,u(t)}).catch(t=>{(0,i.R8)(`GdPicture preload MIME detection failed: ${t}`)});try{const e=await(this._dwsStandaloneAuthModule?.authorizeInitial(t.signal));d=e?.wasmAuthToken}catch(t){throw this.destroyed&&await this.abandonLoadAfterCleanup(),t}this.destroyed&&await this.abandonLoadAfterCleanup();const y=await this.raceWithLoadAbort(W(this.client,this._state,d).finally(()=>{l+=.3,t.progressCallback&&t.progressCallback("loading",l)}));(0,c.lp)(),t.onWasmReady?.(),this.destroyed&&await this.abandonLoadAfterCleanup();const g=this.client.corePDFAccess;this.corePDFAccess=g,"opfs"===this._state.storage.mode&&g.cleanupOPFSOrphans().catch(t=>{(0,i.R8)(`OPFS orphan cleanup failed: ${t}`)});const A="string"==typeof this._state.dynamicFonts?this._state.dynamicFonts.split("/").slice(0,-1).join("/"):void 0;this.corePDFDocument=new L.N({corePDFAccess:g,canvasRendering:this._state.canvasRendering,dynamicFontsBaseURL:A,storage:this._state.storage},{type:"alreadyLoadedDocument"}),(0,i.V1)(y);const{features:b,signatureFeatureAvailability:_,capabilities:P,licenseData:S}=y,v=P.includes("GdPictureWASM");n=v,v?void 0!==o&&u(o):(e=!1,this.releaseGdPictureLoad().catch(t=>{(0,i.R8)(`GdPicture preload cleanup failed: ${t}`)}));const F=D(this._state.document,g,this.corePDFDocument,this._state.allowLinearizedLoading,this._state.storage,this._state.httpHeaders||void 0,()=>{l+=.3,t.progressCallback&&t.progressCallback("loading",l)},t=>{this._state.document instanceof ArrayBuffer||u(t)},t.signal);if(this._state.productId===m.v.SharePoint&&"string"==typeof this._state.document&&Array.isArray(y.afu)){const t=new URL(this._state.document,this._state.baseUrl);if(!y.afu.some(e=>t.hostname.match(e)))throw new i.uE(`The document origin ${t.hostname} is not authorized.`)}const C=_===h.g.ELECTRONIC_SIGNATURES&&(0,f.UX)(b)&&this._state.forceLegacySignaturesFeature?h.g.LEGACY_SIGNATURES:_;this._state=this._state.set("features",(0,a.B8)(b)).set("signatureFeatureAvailability",C),this._dwsStandaloneAuthModule||(T=this._state.licenseKey);const R=await this.raceWithLoadAbort(F);this._documentStorageAnalytics=R.storageAnalytics??null;let I=null;const E={password:t.password,initialPageIndex:"number"==typeof t.initialPageIndex?t.initialPageIndex:0,formsConfiguration:this._formsConfiguration};if("memory"===R.type){let e=null;const n=(0,w.C5)(R.contentType),s=n||!v;if(s)try{this.destroyed?I=await this.abandonLoadAfterCleanup():((this.activeConfiguration.isTextComparison||this.activeConfiguration.aiAssistant)&&(this._resolvedPdfBuffer=R.fullDocument.slice(0)),this.stashDocumentHeadBuffer(R.fullDocument),I=await this.raceWithLoadAbort(this.openDocumentOrAbandon(R.fullDocument,E)))}catch(t){const n=t;if("INVALID_PASSWORD"===n.message){const t=Array.isArray(n.callArgs)?n.callArgs[0]:null;this._state.document instanceof ArrayBuffer&&t instanceof ArrayBuffer&&(this._state=this._state.set("document",t))}else"IMAGE_DOCUMENTS_NOT_LICENSED"===n.message&&(n.message="The image documents feature is not enabled for your license key. Please contact support or sales to purchase the UI module for your product.");e=n}const a=e?.message,o=e instanceof i.uE&&"string"==typeof a&&a.includes("File not in PDF format or corrupted.");if(!v||!o&&n){if(e)throw e}else{this.retainGdPictureLoad();let n=null;const a=e?.callArgs,o=Array.isArray(a)?a[0]:null;if(o instanceof ArrayBuffer?n=o:s?"string"==typeof this._state.document&&(n=await this.fetchDocumentBytesWithCurrentHeaders(this._state.document)):n=R.fullDocument,!(n instanceof ArrayBuffer)){if(e)throw e;throw new i.uE("Document bytes are not available")}let l=this.destroyed;const u=R.contentType;try{if(!l){(0,c.HN)();const e=await(0,p.fL)(n,u,{baseUrl:this._state.baseProcessorEngineUrl,mainThreadOrigin:this._state.appName||(0,r.D5)()||window.location.origin,licenseKey:this._state.licenseKey||void 0,processorEngine:this._state.processorEngine,customFonts:this._state.customFonts||void 0,dynamicFonts:this._state.dynamicFonts||void 0,fontSubstitutions:this._state.fontSubstitutions},t.officeConversionSettings,!0,t.signal);(0,c.yq)(),(this.activeConfiguration.isTextComparison||this.activeConfiguration.aiAssistant)&&(this._resolvedPdfBuffer=e.slice(0)),this.stashDocumentHeadBuffer(e),l=this.destroyed,l||(I=await this.raceWithLoadAbort(this.openDocumentOrAbandon(e,E)))}}catch(t){if(!this.destroyed){const e=t;if("INVALID_PASSWORD"===e.message&&this._state.document instanceof ArrayBuffer){const t=Array.isArray(e.callArgs)?e.callArgs[0]:null;t instanceof ArrayBuffer&&(this._state=this._state.set("document",t))}throw"IMAGE_DOCUMENTS_NOT_LICENSED"===e.message&&(e.message="The image documents feature is not enabled for your license key. Please contact support or sales to purchase the UI module for your product."),e}l=!0}l&&(I=await this.abandonLoadAfterCleanup())}(0,i.V1)(I),await this.afterDocumentLoaded(I)}else if("opfs"===R.type)if(this.destroyed)I=await this.abandonLoadAfterCleanup();else{this._opfsActive=!0,this._documentHeadBuffer=R.documentHeadBuffer;try{I=await this.raceWithLoadAbort(this.openDocumentWithOPFSOrAbandon(E))}catch(e){const n=e,s=n instanceof i.uE&&"string"==typeof n.message&&n.message.includes("File not in PDF format or corrupted.");this._opfsActive=!1,this._documentStorageAnalytics&&(this._documentStorageAnalytics={...this._documentStorageAnalytics,storageActual:"memory",storageFallbackReason:"open-document-failed"});try{await(this.corePDFAccess?.closeOPFSStorage())}catch{}if(!v||!s||"string"!=typeof this._state.document)throw n;{this.retainGdPictureLoad();let e=this.destroyed;const n=R.contentType;try{if(!e){(0,c.HN)();const s=await(0,p.fL)(await this.fetchDocumentBytesWithCurrentHeaders(this._state.document),n,{baseUrl:this._state.baseProcessorEngineUrl,mainThreadOrigin:this._state.appName||(0,r.D5)()||window.location.origin,licenseKey:this._state.licenseKey||void 0,processorEngine:this._state.processorEngine,customFonts:this._state.customFonts||void 0,dynamicFonts:this._state.dynamicFonts||void 0,fontSubstitutions:this._state.fontSubstitutions},t.officeConversionSettings,!0,t.signal);(0,c.yq)(),this.activeConfiguration.isTextComparison&&(this._resolvedPdfBuffer=s.slice(0)),this.stashDocumentHeadBuffer(s),e=this.destroyed,e||(I=await this.raceWithLoadAbort(this.openDocumentOrAbandon(s,E)))}}catch(t){if(!this.destroyed){const e=t;if("INVALID_PASSWORD"===e.message){const t=Array.isArray(e.callArgs)?e.callArgs[0]:null;t instanceof ArrayBuffer&&(this._state=this._state.set("document",t))}throw"IMAGE_DOCUMENTS_NOT_LICENSED"===e.message&&(e.message="The image documents feature is not enabled for your license key. Please contact support or sales to purchase the UI module for your product."),e}e=!0}e&&(I=await this.abandonLoadAfterCleanup())}}(0,i.V1)(I),await this.afterDocumentLoaded(I)}else I=R.documentResponse,R.documentHeadBuffer&&(this._documentHeadBuffer=R.documentHeadBuffer);this._state=this._state.set("documentResponse",I);const k=this._dwsStandaloneAuthModule?this.mapDWSStandaloneClientInfo(this._dwsStandaloneAuthModule):this.mapLicenseDataToClientInfo(S);return{features:this._state.features,signatureFeatureAvailability:this._state.signatureFeatureAvailability,hasPassword:!!t.password,password:t.password,allowedTileScales:"all",evaluation:y.evaluation,linearizedLoading:!R.isFullyAvailable,documentResponse:I,clientInfo:k}}catch(t){if(t instanceof U)return this.waitForAbandonedLoad();throw t}finally{e=!1,this._loadInProgress=!1,this._loadSignal=null,await this.releaseGdPictureLoad()}}mapLicenseDataToClientInfo(t){const e="1.18.0-d151a78",n=(0,F.o)(this._state.productId);if(null===n)return null;if(!t)return{environment:C.n.EVALUATION,productId:n,productVersion:e,licenseId:void 0,demoKeyId:void 0};let s=C.n.DEVELOPMENT;return"p"===t.type?s=C.n.PRODUCTION:"d"===t.type?s=C.n.DEMO:"b"===t.type?s=C.n.DEVELOPMENT:"t"===t.type&&(s=C.n.EVALUATION),{environment:s,productId:n,productVersion:e,licenseId:t.li,demoKeyId:"d"===t.type?t.i:void 0}}mapDWSStandaloneClientInfo(t){const e=(0,F.o)(this._state.productId);return null===e?null:((0,i.V1)(null!==t.tenantId,"DWS Viewer API tenantId is missing after authorization."),{environment:C.n.PRODUCTION,productId:e,productVersion:"1.18.0-d151a78",tenantId:t.tenantId})}takeResolvedPdfBuffer(){const t=this._resolvedPdfBuffer;return this._resolvedPdfBuffer=null,t}takeDocumentHeadBuffer(){const t=this._documentHeadBuffer;return this._documentHeadBuffer=null,t}getDocumentStorageAnalytics(){return this._documentStorageAnalytics}prepareClientForCheckIn(){this._usesDWSStandaloneAuth&&this.client.destroy()}destroy(){if(!this.destroyed){if(this.destroyed=!0,this._dwsStandaloneAuthModule?.destroy(),this._dwsStandaloneAuthModule=null,this._resolvedPdfBuffer=null,this._documentHeadBuffer=null,this._documentStorageAnalytics=null,window.removeEventListener("pagehide",this._pageHideListener),this._loadInProgress)return this.releaseGdPictureLoad(),this.destroyResources(),this.client.destroy(),this._opfsActive=!1,void(this.corePDFAccess=null);this.cleanupOPFSStorage("destroy"),this.corePDFAccess=null,super.destroy()}}setSession(t){(0,i.R8)("`setSession` is only supported in server-backed mode. DWS Viewer API app-provided document loading does not refresh sessions after load.")}getCustomFontsPromise(){return N}async afterDocumentLoaded(t){if(this._isPDFJavaScriptEnabled&&(this._initialChanges=await this.client.enablePDFJavaScriptSupport()),this._XFDF&&await this.client.importXFDF(this._XFDF.source,this._XFDF.keepCurrentAnnotations,this._XFDF.ignorePageRotation,this._XFDF.richTextEnabled),this._instantJSON&&this._instantJSON.pdfId&&t.ID.permanent){const e=this._instantJSON.pdfId,n=t.ID,s=n.changing??n.update;if(e.permanent!==n.permanent)throw new i.uE("Could not instantiate from Instant JSON: Permanent PDF ID mismatch.\nPlease use the same PDF document that was used to create this Instant JSON.\nFor more information, please visit: https://www.nutrient.io/guides/web/importing-exporting/instant-json/");if(e.changing!==s)throw new i.uE("Could not instantiate from Instant JSON: Changing PDF ID mismatch.\nPlease use the same revision of this PDF document that was used to create this Instant JSON.\nFor more information, please visit: https://www.nutrient.io/guides/web/importing-exporting/instant-json/")}if(this._trustedCAsCallback)try{const t=await this._trustedCAsCallback();if(!Array.isArray(t))throw new i.uE("Certificates response must be an array");if(t.some(t=>!(t instanceof ArrayBuffer)&&"string"!=typeof t))throw new i.uE("All certificates must be passed as ArrayBuffer (DER) or string (PEM)");await this.client.loadCertificates(t.map(d.PI))}catch(t){throw new i.uE(`Could not retrieve certificates for digital signatures validation: ${t.message}.`)}}async waitUntilFullyLoaded(t){return this.corePDFDocument.linearizedDocument.waitUntilDownloaded().then(async()=>{const e=this.corePDFDocument.linearizedDocument.isUsingOPFS,n=await this.corePDFDocument.normallyOpenLinearizedDocument(this,{password:t,initialPageIndex:0,formsConfiguration:this._formsConfiguration});this.destroyed&&(e&&(await(this.corePDFAccess?.closeOPFSStorage().catch(t=>{(0,i.R8)(`OPFS storage cleanup error: ${t}`)})),this._opfsActive=!1),await this.waitForAbandonedLoad()),e&&(this._opfsActive=!0),this._state=this._state.set("documentResponse",n),await this.afterDocumentLoaded(n)})}async getDocumentBytes(){if(this._state.document instanceof ArrayBuffer)return this._state.document;if("string"==typeof this._state.document){const t=await fetch(this._state.document);if(!t.ok)throw new i.uE(`Failed to fetch document: ${t.statusText}`);return t.arrayBuffer()}throw new i.uE("Document bytes are not available")}async fetchDocumentBytesWithCurrentHeaders(t){return(await fetch(t,_(this._state.httpHeaders||void 0))).arrayBuffer()}}const N={current:void 0};async function W(t,e,n){N.current=N.current||(e.customFonts?(0,y.eY)(e.customFonts):void 0);const s=(0,l.f)(e.appName);return t.loadNativeModule(e.baseCoreUrl,{mainThreadOrigin:s,disableWebAssemblyStreaming:e.disableWebAssemblyStreaming,enableAutomaticLinkExtraction:e.enableAutomaticLinkExtraction,overrideMemoryLimit:e.overrideMemoryLimit,workerSpawnerFn:()=>(0,o.pj)(e.inlineWorkers)}).then(async()=>t.load(e.baseCoreUrl,n??e.licenseKey,{mainThreadOrigin:s,...N.current?{customFonts:await N.current}:null,dynamicFonts:e.dynamicFonts,productId:e.productId,featureFlags:(()=>{const t=[];return e.enableCoreUnifiedComments&&t.push("UnifiedComments"),e.enableCorePreservePDFAccessibility&&t.push("PreservePDFAccessibility"),t.length>0?t:void 0})()}))}}}]);