/*!
 * Nutrient Web SDK 1.14.0-ecbc0dc (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],{8009(e,t,s){s.r(t),s.d(t,{corePool:()=>d.mG,customFontsPromiseRef:()=>C,default:()=>P,loadModule:()=>E,normalizeCoreOptions:()=>d.DO,validateStandaloneConfiguration:()=>d.mn});var n=s(34724),i=s(57191),a=s(89339),o=s(85892),r=s(70274),c=s(64662),l=s(80695),u=s(23264),d=s(74129),f=s(39515),h=s(9855),m=s(28805),p=s(33704),y=s(42428),g=s(96584),w=s(73844);function _(e){const t={credentials:"same-origin"};if(e&&Object.keys(e).length>0){const s=new Headers;Object.entries(e).forEach(e=>{let[t,n]=e;s.append(t,n)}),t.headers=s}return t}async function b(e,t,s,n,i){let a;if(i)a=i,n?.();else{const t=_(s);a=await fetch(e,t).finally(()=>{n?.()})}const o=await a.arrayBuffer();return{isFullyAvailable:!0,fullDocument:o,contentType:await(0,w.oj)(o,t,a.headers?.get("Content-Type"))}}async function D(e,t,s,n,i,r){if(e instanceof ArrayBuffer){const s=await(0,w.oj)(e,t);return r?.(s),{isFullyAvailable:!0,fullDocument:e,contentType:s}}(0,a.V1)("string"==typeof e,"Document is not a string");let c=!1;const{linearizedDocument:l,serverSupportsRangeRequests:u,fallbackResponse:d}=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(o.EA);(0,a.V1)(s,"Linearized document is not available"),s.contentType&&r&&r(s.contentType);const i=await s.initialize(e,n);return i.supportsRanges?{linearizedDocument:s,serverSupportsRangeRequests:!0,fallbackResponse:void 0}:{linearizedDocument:null,serverSupportsRangeRequests:!1,fallbackResponse:i.fullResponse}}return{linearizedDocument:null,serverSupportsRangeRequests:!1,fallbackResponse:void 0}})();try{if(!u)return c=!0,b(e,t,n,i,d);(0,a.V1)(l,"Linearized document is not available"),l.startDownload();if(!await l.waitUntilIsLinearizedIsKnown())return l.destroy(),c=!0,b(e,t,n,i);i?.();const s=await l.waitUntilDocumentInfoAvailable();return s?("undefined"!=typeof performance&&"function"==typeof performance.mark&&performance.mark("linearized-first-page-ready"),i?.(),{isFullyAvailable:!1,documentResponse:s,contentType:"application/pdf"}):(l.destroy(),c=!0,b(e,t,n,i))}catch(s){if(l?.destroy(),c)throw s;return b(e,t,n,i)}}var v=s(61469),A=s(82725);let F;class P extends d.Ay{constructor(e){const t=e.baseUrl||(0,u.$_)(window.document),s=e.baseCoreUrl||t,i=e.baseProcessorEngineUrl||t,o={...e,baseUrl:t,baseCoreUrl:s,baseProcessorEngineUrl:i};if("string"!=typeof o.baseUrl)throw new a.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 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(F&&F!==o.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 o.licenseKey&&o.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(o),(0,n.A)(this,"_resolvedPdfBuffer",null),this.destroyed=!1,this.activeConfiguration=e}async load(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._resolvedPdfBuffer=null;const t=()=>{try{let e=(0,y.jU)();e||(e=(0,y.NY)({baseUrl:this._state.baseProcessorEngineUrl,mainThreadOrigin:this._state.appName||(0,c.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,y.Pm)(e))}catch(e){console.error("Error initializing GdPicture client:",e)}};let s=.2;e.progressCallback&&e.progressCallback("loading",s),this._isPDFJavaScriptEnabled=e.isPDFJavaScriptEnabled,"string"==typeof this._state.document&&(0,w.XC)(this._state.baseUrl,this._state.document,this._state.productId),this._state.document instanceof ArrayBuffer&&(0,w.uA)(await(0,w.oj)(this._state.document))&&t();const n=await E(this.client,this._state).finally(()=>{s+=.3,e.progressCallback&&e.progressCallback("loading",s)}),o=this.client.workerSpawner;(0,a.V1)(o,"WorkerSpawner is null");const u=o.getWorker();(0,a.V1)(u,"Worker is null");const d=r.LV(u),f="string"==typeof this._state.dynamicFonts?this._state.dynamicFonts.split("/").slice(0,-1).join("/"):void 0;this.corePDFDocument=new A.N({corePDFAccess:d,canvasRendering:this._state.canvasRendering,dynamicFontsBaseURL:f},{type:"alreadyLoadedDocument"});const g=D(this._state.document,this.corePDFDocument,this._state.allowLinearizedLoading,this._state.httpHeaders||void 0,()=>{s+=.3,e.progressCallback&&e.progressCallback("loading",s)},e=>{(0,w.uA)(e)&&t()});(0,a.V1)(n);const{features:_,signatureFeatureAvailability:b,capabilities:v,licenseData:P}=n;if(this._state.productId===p.v.SharePoint&&"string"==typeof this._state.document&&Array.isArray(n.afu)){const e=new URL(this._state.document,this._state.baseUrl);if(!n.afu.some(t=>e.hostname.match(t)))throw new a.uE(`The document origin ${e.hostname} is not authorized.`)}const C=b===h.g.ELECTRONIC_SIGNATURES&&(0,m.UX)(_)&&this._state.forceLegacySignaturesFeature?h.g.LEGACY_SIGNATURES:b;this._state=this._state.set("features",(0,i.B8)(_)).set("signatureFeatureAvailability",C),F=this._state.licenseKey;const I=await g;let S=null;if(I.isFullyAvailable){let t=null;const s=(0,w.C5)(I.contentType),n=v.includes("GdPictureWASM"),i=s||!n;if(i)try{this.destroyed?S=await new Promise(()=>{}):(this.activeConfiguration.isTextComparison&&(this._resolvedPdfBuffer=I.fullDocument.slice(0)),S=await this.client.openDocument(I.fullDocument,{password:e.password,initialPageIndex:"number"==typeof e.initialPageIndex?e.initialPageIndex:0,formsConfiguration:this._formsConfiguration}))}catch(e){const s=e;if("INVALID_PASSWORD"===s.message){const e=Array.isArray(s.callArgs)?s.callArgs[0]:null;this._state.document instanceof ArrayBuffer&&e instanceof ArrayBuffer&&(this._state=this._state.set("document",e))}else"IMAGE_DOCUMENTS_NOT_LICENSED"===s.message?s.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.":v.includes("GdPictureWASM")||(s.message="File not in PDF format or corrupted.");t=s}const o=t?.message,r=t instanceof a.uE&&"string"==typeof o&&o.includes("File not in PDF format or corrupted.");if(!n||!r&&s){if(t)throw t}else{let s=null;const n=t?.callArgs,o=Array.isArray(n)?n[0]:null;if(o instanceof ArrayBuffer?s=o:i?"string"==typeof this._state.document&&(s=await this.fetchDocumentBytesWithCurrentHeaders(this._state.document)):s=I.fullDocument,!(s instanceof ArrayBuffer)){if(t)throw t;throw new a.uE("Document bytes are not available")}try{(0,l.HN)();const t=await(0,y.fL)(s,I.contentType,{baseUrl:this._state.baseProcessorEngineUrl,mainThreadOrigin:this._state.appName||(0,c.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},e.officeConversionSettings,!0);(0,l.yq)(),this.activeConfiguration.isTextComparison&&(this._resolvedPdfBuffer=t.slice(0)),S=await this.client.openDocument(t,{password:e.password,initialPageIndex:"number"==typeof e.initialPageIndex?e.initialPageIndex:0,formsConfiguration:this._formsConfiguration})}catch(e){const t=e;if("INVALID_PASSWORD"===t.message&&this._state.document instanceof ArrayBuffer){const e=Array.isArray(t.callArgs)?t.callArgs[0]:null;e instanceof ArrayBuffer&&(this._state=this._state.set("document",e))}throw"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{this.activeConfiguration.isTextComparison||await(0,y.q9)()}}(0,a.V1)(S),await this.afterDocumentLoaded(S)}else S=I.documentResponse;this._state=this._state.set("documentResponse",S);const T=this.mapLicenseDataToClientInfo(P);return{features:this._state.features,signatureFeatureAvailability:this._state.signatureFeatureAvailability,hasPassword:!!e.password,password:e.password,allowedTileScales:"all",evaluation:n.evaluation,linearizedLoading:!I.isFullyAvailable,documentResponse:S,clientInfo:T}}mapLicenseDataToClientInfo(e){const t="1.14.0-ecbc0dc";if(!e)return{environment:v.n.EVALUATION,productId:v.O.WEB,productVersion:t,licenseId:void 0,demoKeyId:void 0};let s=v.n.DEVELOPMENT;return"p"===e.type?s=v.n.PRODUCTION:"d"===e.type?s=v.n.DEMO:"b"===e.type?s=v.n.DEVELOPMENT:"t"===e.type&&(s=v.n.EVALUATION),{environment:s,productId:v.O.WEB,productVersion:t,licenseId:e.li,demoKeyId:"d"===e.type?e.i:void 0}}takeResolvedPdfBuffer(){const e=this._resolvedPdfBuffer;return this._resolvedPdfBuffer=null,e}destroy(){this.destroyed=!0,this._resolvedPdfBuffer=null,super.destroy()}getCustomFontsPromise(){return C}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(f.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")}async fetchDocumentBytesWithCurrentHeaders(e){return(await fetch(e,_(this._state.httpHeaders||void 0))).arrayBuffer()}}const C={current:void 0};async function E(e,t){C.current=C.current||(t.customFonts?(0,g.eY)(t.customFonts):void 0);const s=(0,u.f)(t.appName);return e.loadNativeModule(t.baseCoreUrl,{mainThreadOrigin:s,disableWebAssemblyStreaming:t.disableWebAssemblyStreaming,enableAutomaticLinkExtraction:t.enableAutomaticLinkExtraction,overrideMemoryLimit:t.overrideMemoryLimit,workerSpawnerFn:()=>(0,o.pj)(t.inlineWorkers)}).then(async()=>e.load(t.baseCoreUrl,t.licenseKey,{mainThreadOrigin:s,...C.current?{customFonts:await C.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})()}))}}}]);