/*!
 * Nutrient Web SDK 1.9.1 (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:(t,e,s)=>{s.r(e),s.d(e,{corePool:()=>c.mG,customFontsPromiseRef:()=>_,default:()=>b,loadModule:()=>D,normalizeCoreOptions:()=>c.DO,validateStandaloneConfiguration:()=>c.mn});var n=s(49568),i=s(85409),a=s(55994),o=s(41204),r=s(85410),c=s(20873),u=s(37506),l=s(85553),d=s(89055),h=s(68322),m=s(37067),f=s(84318),p=s(33075);async function y(t,e,s,n){const i={credentials:"same-origin"};if(s&&Object.keys(s).length>0){const t=new Headers;Object.entries(s).forEach((e=>{let[s,n]=e;t.append(s,n)})),i.headers=t}const a=await fetch(t,i).finally((()=>{n?.()})),o=await a.arrayBuffer();return{isFullyAvailable:!0,fullDocument:o,contentType:a.headers?.get("Content-Type")||await(0,p.oj)(o,e)}}async function g(t,e,s,n,o,r){if(t instanceof ArrayBuffer){const s=await(0,p.oj)(t,e);return r?.(s),{isFullyAvailable:!0,fullDocument:t,contentType:s}}(0,i.V1)("string"==typeof t,"Document is not a string");let c=!1;const{linearizedDocument:u,serverSupportsRangeRequests:l}=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 s=await e.openLinearizedDocument(a.EA);return(0,i.V1)(s,"Linearized document is not available"),s.contentType&&r&&r(s.contentType),{linearizedDocument:s,serverSupportsRangeRequests:await s.initialize(t,n)}}return{linearizedDocument:null,serverSupportsRangeRequests:!1}})();try{if(!l)return c=!0,y(t,e,n,o);(0,i.V1)(u,"Linearized document is not available"),u.startDownload();if(!await u.waitUntilIsLinearizedIsKnown())return u.destroy(),c=!0,y(t,e,n,o);o?.();const s=await u.waitUntilDocumentInfoAvailable();return s?(o?.(),{isFullyAvailable:!1,documentResponse:s,contentType:"application/pdf"}):(u.destroy(),c=!0,y(t,e,n,o))}catch(s){if(u?.destroy(),c)throw s;return y(t,e,n,o)}}let w;class b extends c.Ay{constructor(t){const e=t.baseUrl||(0,r.$_)(window.document),s=t.baseCoreUrl||e,n=t.baseProcessorEngineUrl||e,a={...t,baseUrl:e,baseCoreUrl:s,baseProcessorEngineUrl:n};if("string"!=typeof a.baseUrl)throw new i.uE("`baseUrl` is mandatory and must be a valid URL, e.g. `https://example.com/`");if("string"!=typeof a.document&&!(a.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`");if(w&&w!==a.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 a.licenseKey&&a.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(a),this.destroyed=!1,this.activeConfiguration=t}async load(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=()=>{try{let t=(0,m.jU)();t||(t=(0,m.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,m.Pm)(t))}catch(t){console.error("Error initializing GdPicture client:",t)}};let s=.2;t.progressCallback&&t.progressCallback("loading",s),this._isPDFJavaScriptEnabled=t.isPDFJavaScriptEnabled,"string"==typeof this._state.document&&(0,p.XC)(this._state.baseUrl,this._state.document,this._state.productId),this._state.document instanceof ArrayBuffer&&(0,p.uA)(await(0,p.oj)(this._state.document))&&e();const a=await D(this.client,this._state).finally((()=>{s+=.3,t.progressCallback&&t.progressCallback("loading",s)})),r=g(this._state.document,this.corePDFDocument,this._state.allowLinearizedLoading,this._state.httpHeaders||void 0,(()=>{s+=.3,t.progressCallback&&t.progressCallback("loading",s)}),(t=>{(0,p.uA)(t)&&e()}));(0,i.V1)(a);const{features:c,signatureFeatureAvailability:u,capabilities:f}=a;if(this._state.productId===h.v.SharePoint&&"string"==typeof this._state.document&&Array.isArray(a.afu)){const t=new URL(this._state.document,this._state.baseUrl);if(!a.afu.some((e=>t.hostname.match(e))))throw new i.uE(`The document origin ${t.hostname} is not authorized.`)}const y=u===l.g.ELECTRONIC_SIGNATURES&&(0,d.UX)(c)&&this._state.forceLegacySignaturesFeature?l.g.LEGACY_SIGNATURES:u;this._state=this._state.set("features",(0,n.B8)(c)).set("signatureFeatureAvailability",y),w=this._state.licenseKey;const b=await r;let _=null;if(b.isFullyAvailable){let e=b.fullDocument.slice(0),s=null;if((0,p.C5)(b.contentType)||!f.includes("GdPictureWASM"))try{this.destroyed?(e=null,_=await new Promise((()=>{}))):(_=await this.client.openDocument(b.fullDocument,{password:t.password,initialPageIndex:"number"==typeof t.initialPageIndex?t.initialPageIndex:0,formsConfiguration:this._formsConfiguration}),e=null)}catch(t){"INVALID_PASSWORD"===t.message&&this._state.document instanceof ArrayBuffer?this._state=this._state.set("document",t.callArgs[0]):"IMAGE_DOCUMENTS_NOT_LICENSED"===t.message?t.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.":f.includes("GdPictureWASM")||(t.message="File not in PDF format or corrupted."),s=t}if(f.includes("GdPictureWASM")&&(s instanceof i.uE&&s.message.includes("File not in PDF format or corrupted.")||!(0,p.C5)(b.contentType))){(0,i.V1)(e);let n,a=(0,m.jU)();try{a||(a=(0,m.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,m.Pm)(a)),n=await a,(0,i.V1)(n);const s=await n.toPdf({document:e,officeConversionSettings:t.officeConversionSettings,contentType:b.contentType?.split(";")[0].trim()});_=await this.client.openDocument(s,{password:t.password,initialPageIndex:"number"==typeof t.initialPageIndex?t.initialPageIndex:0,formsConfiguration:this._formsConfiguration})}catch(t){throw"INVALID_PASSWORD"===t.message&&this._state.document instanceof ArrayBuffer&&(this._state=this._state.set("document",s.callArgs[0])),"IMAGE_DOCUMENTS_NOT_LICENSED"===t.message&&(t.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."),t}finally{e=null,n?.destroy(),(0,m.Pm)(null)}}else if(s)throw s;(0,i.V1)(_),await this.afterDocumentLoaded(_)}else _=b.documentResponse;return this._state=this._state.set("documentResponse",_),{features:this._state.features,signatureFeatureAvailability:this._state.signatureFeatureAvailability,hasPassword:!!t.password,password:t.password,allowedTileScales:"all",evaluation:a.evaluation,linearizedLoading:!b.isFullyAvailable,documentResponse:_}}destroy(){this.destroyed=!0,super.destroy()}getCustomFontsPromise(){return _}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,s=t.ID;if(e.permanent!==s.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.changing)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(u.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()=>{await this.corePDFDocument.normallyOpenLinearizedDocument(this,{password:t,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 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")}}const _={current:void 0};async function D(t,e){_.current=_.current||(e.customFonts?(0,f.eY)(e.customFonts):void 0);const s=(0,r.f)(e.appName);return t.loadNativeModule(e.baseCoreUrl,{mainThreadOrigin:s,disableWebAssemblyStreaming:e.disableWebAssemblyStreaming,enableAutomaticLinkExtraction:e.enableAutomaticLinkExtraction,overrideMemoryLimit:e.overrideMemoryLimit,workerSpawnerFn:()=>(0,a.pj)(e.inlineWorkers)}).then((async()=>t.load(e.baseCoreUrl,e.licenseKey,{mainThreadOrigin:s,..._.current?{customFonts:await _.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})()})))}}}]);