/*!
 * Nutrient Web SDK 1.7.0-24b29af (https://www.nutrient.io/sdk/web)
 *
 * Copyright (c) 2016-2025 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],{63993:(e,t,s)=>{s.r(t),s.d(t,{corePool:()=>l.mG,customFontsPromiseRef:()=>_,default:()=>b,loadModule:()=>D,normalizeCoreOptions:()=>l.DO,validateStandaloneConfiguration:()=>l.mn});var n=s(49568),a=s(85409),i=s(55994),o=s(41204),r=s(85410),l=s(20873),u=s(37506),c=s(85553),d=s(89055),m=s(68322),h=s(78603),f=s(84318),p=s(33075);async function g(e,t){const s=await fetch(e,{credentials:"same-origin"}).finally((()=>{t?.()})),n=await s.arrayBuffer();return{isFullyAvailable:!0,fullDocument:n,contentType:s.headers?.get("Content-Type")||(0,p.oj)(n)}}async function y(e,t,s,n){if(e instanceof ArrayBuffer)return{isFullyAvailable:!0,fullDocument:e,contentType:(0,p.oj)(e)};(0,a.V1)("string"==typeof e,"Document is not a string");let o=!1;const{linearizedDocument:r,serverSupportsRangeRequests:l}=await(async()=>{if(s&&function(e){if(e.startsWith("/"))return!0;try{const t=new URL(e);return"http:"===t.protocol||"https:"===t.protocol}catch(e){return!1}}(e)){const s=await t.openLinearizedDocument(i.EA);return(0,a.V1)(s,"Linearized document is not available"),{linearizedDocument:s,serverSupportsRangeRequests:await s.initialize(e)}}return{linearizedDocument:null,serverSupportsRangeRequests:!1}})();try{if(!l)return o=!0,g(e,n);(0,a.V1)(r,"Linearized document is not available"),r.startDownload();if(!await r.waitUntilIsLinearizedIsKnown())return r.destroy(),o=!0,g(e,n);n?.();const t=await r.waitUntilDocumentInfoAvailable();return t?(n?.(),{isFullyAvailable:!1,documentResponse:t,contentType:"application/pdf"}):(r.destroy(),o=!0,g(e,n))}catch(t){if(r?.destroy(),o)throw t;return g(e,n)}}let w;class b extends l.Ay{constructor(e){const t=e.baseUrl||(0,r.$_)(window.document),s=e.baseCoreUrl||t,n=e.baseProcessorEngineUrl||t,i={...e,baseUrl:t,baseCoreUrl:s,baseProcessorEngineUrl:n};if("string"!=typeof i.baseUrl)throw new a.uE("`baseUrl` is mandatory and must be a valid URL, e.g. `https://example.com/`");if("string"!=typeof i.document&&!(i.document instanceof ArrayBuffer))throw new a.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`");if(w&&w!==i.licenseKey)throw new a.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 i.licenseKey&&i.licenseKey.startsWith("TRIAL-"))throw new a.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(i),this.destroyed=!1,this.activeConfiguration=e}async load(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=.2;e.progressCallback&&e.progressCallback("loading",t),this._isPDFJavaScriptEnabled=e.isPDFJavaScriptEnabled,"string"==typeof this._state.document&&(0,p.XC)(this._state.baseUrl,this._state.document,this._state.productId);const s=await D(this.client,this._state).finally((()=>{t+=.3,e.progressCallback&&e.progressCallback("loading",t)})),i=y(this._state.document,this.corePDFDocument,this._state.allowLinearizedLoading,(()=>{t+=.3,e.progressCallback&&e.progressCallback("loading",t)}));(0,a.V1)(s);const{features:r,signatureFeatureAvailability:l,capabilities:u}=s;if(this._state.productId===m.v.SharePoint&&"string"==typeof this._state.document&&Array.isArray(s.afu)){const e=new URL(this._state.document,this._state.baseUrl);if(!s.afu.some((t=>e.hostname.match(t))))throw new a.uE(`The document origin ${e.hostname} is not authorized.`)}const f=l===c.g.ELECTRONIC_SIGNATURES&&(0,d.UX)(r)&&this._state.forceLegacySignaturesFeature?c.g.LEGACY_SIGNATURES:l;this._state=this._state.set("features",(0,n.B8)(r)).set("signatureFeatureAvailability",f),w=this._state.licenseKey;const g=await i;let b=null;if(g.isFullyAvailable){let t=g.fullDocument.slice(0),s=null;if((0,p.C5)(g.contentType)||!u.includes("GdPictureWASM"))try{this.destroyed?(t=null,b=await new Promise((()=>{}))):(b=await this.client.openDocument(g.fullDocument,{password:e.password,initialPageIndex:"number"==typeof e.initialPageIndex?e.initialPageIndex:0,formsConfiguration:this._formsConfiguration}),t=null)}catch(e){"INVALID_PASSWORD"===e.message&&this._state.document instanceof ArrayBuffer?this._state=this._state.set("document",e.callArgs[0]):"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.":u.includes("GdPictureWASM")||(e.message="File not in PDF format or corrupted."),s=e}if(u.includes("GdPictureWASM")&&(s instanceof a.uE&&s.message.includes("File not in PDF format or corrupted.")||!(0,p.C5)(g.contentType))){(0,a.V1)(t);let n,i=(0,h.jU)();try{i||(i=(0,h.NY)({baseUrl:this._state.baseProcessorEngineUrl,mainThreadOrigin:this._state.appName||(0,o.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,h.Pm)(i)),n=await i,(0,a.V1)(n);const s=await n.toPdf(t,null,e.officeConversionSettings);b=await this.client.openDocument(s,{password:e.password,initialPageIndex:"number"==typeof e.initialPageIndex?e.initialPageIndex:0,formsConfiguration:this._formsConfiguration})}catch(e){throw"INVALID_PASSWORD"===e.message&&this._state.document instanceof ArrayBuffer&&(this._state=this._state.set("document",s.callArgs[0])),"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}finally{t=null,n?.destroy(),(0,h.Pm)(null)}}else if(s)throw s;(0,a.V1)(b),await this.afterDocumentLoaded(b)}else b=g.documentResponse;return this._state=this._state.set("documentResponse",b),{features:this._state.features,signatureFeatureAvailability:this._state.signatureFeatureAvailability,hasPassword:!!e.password,password:e.password,allowedTileScales:"all",evaluation:s.evaluation,linearizedLoading:!g.isFullyAvailable,documentResponse:b}}destroy(){this.destroyed=!0,super.destroy()}getCustomFontsPromise(){return _}async afterDocumentLoaded(e){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&&e.ID.permanent){const t=this._instantJSON.pdfId,s=e.ID;if(t.permanent!==s.permanent)throw new a.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(t.changing!==s.changing)throw new a.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 e=await this._trustedCAsCallback();if(!Array.isArray(e))throw new a.uE("Certificates response must be an array");if(e.some((e=>!(e instanceof ArrayBuffer)&&"string"!=typeof e)))throw new a.uE("All certificates must be passed as ArrayBuffer (DER) or string (PEM)");await this.client.loadCertificates(e.map(u.PI))}catch(e){throw new a.uE(`Could not retrieve certificates for digital signatures validation: ${e.message}.`)}}async waitUntilFullyLoaded(e){return this.corePDFDocument.linearizedDocument.waitUntilDownloaded().then((async()=>{await this.corePDFDocument.normallyOpenLinearizedDocument(this,{password:e,initialPageIndex:0,formsConfiguration:this._formsConfiguration}),await this.afterDocumentLoaded(this._state.documentResponse)}))}async getDocumentBytes(){if(this._state.document instanceof ArrayBuffer)return this._state.document;if("string"==typeof this._state.document){const e=await fetch(this._state.document);if(!e.ok)throw new a.uE(`Failed to fetch document: ${e.statusText}`);return e.arrayBuffer()}throw new a.uE("Document bytes are not available")}}const _={current:void 0};async function D(e,t){_.current=_.current||(t.customFonts?(0,f.eY)(t.customFonts):void 0);const s=(0,r.f)(t.appName);return e.loadNativeModule(t.baseCoreUrl,{mainThreadOrigin:s,disableWebAssemblyStreaming:t.disableWebAssemblyStreaming,enableAutomaticLinkExtraction:t.enableAutomaticLinkExtraction,overrideMemoryLimit:t.overrideMemoryLimit,workerSpawnerFn:()=>(0,i.pj)(t.inlineWorkers)}).then((async()=>e.load(t.baseCoreUrl,t.licenseKey,{mainThreadOrigin:s,..._.current?{customFonts:await _.current}:null,dynamicFonts:t.dynamicFonts,productId:t.productId,featureFlags:(()=>{const e=[];return t.enableCoreUnifiedComments&&e.push("UnifiedComments"),t.enableCorePreservePDFAccessibility&&e.push("PreservePDFAccessibility"),e.length>0?e:void 0})()})))}}}]);