/*!
 * Nutrient Web SDK 1.11.0-541b242 (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,n)=>{n.r(t),n.d(t,{corePool:()=>c.mG,customFontsPromiseRef:()=>D,default:()=>_,loadModule:()=>F,normalizeCoreOptions:()=>c.DO,validateStandaloneConfiguration:()=>c.mn});var s=n(49568),i=n(85409),a=n(55994),o=n(41204),r=n(85410),c=n(20873),l=n(37506),u=n(85553),d=n(89055),m=n(68322),h=n(72011),f=n(84318),p=n(33075);async function y(e,t,n,s,i){let a;if(i)a=i,s?.();else{const t={credentials:"same-origin"};if(n&&Object.keys(n).length>0){const e=new Headers;Object.entries(n).forEach((t=>{let[n,s]=t;e.append(n,s)})),t.headers=e}a=await fetch(e,t).finally((()=>{s?.()}))}const o=await a.arrayBuffer();return{isFullyAvailable:!0,fullDocument:o,contentType:a.headers?.get("Content-Type")||await(0,p.oj)(o,t)}}async function g(e,t,n,s,o,r){if(e instanceof ArrayBuffer){const n=await(0,p.oj)(e,t);return r?.(n),{isFullyAvailable:!0,fullDocument:e,contentType:n}}(0,i.V1)("string"==typeof e,"Document is not a string");let c=!1;const{linearizedDocument:l,serverSupportsRangeRequests:u,fallbackResponse:d}=await(async()=>{if(n&&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 n=await t.openLinearizedDocument(a.EA);(0,i.V1)(n,"Linearized document is not available"),n.contentType&&r&&r(n.contentType);const o=await n.initialize(e,s);return o.supportsRanges?{linearizedDocument:n,serverSupportsRangeRequests:!0,fallbackResponse:void 0}:{linearizedDocument:null,serverSupportsRangeRequests:!1,fallbackResponse:o.fullResponse}}return{linearizedDocument:null,serverSupportsRangeRequests:!1,fallbackResponse:void 0}})();try{if(!u)return c=!0,y(e,t,s,o,d);(0,i.V1)(l,"Linearized document is not available"),l.startDownload();if(!await l.waitUntilIsLinearizedIsKnown())return l.destroy(),c=!0,y(e,t,s,o);o?.();const n=await l.waitUntilDocumentInfoAvailable();return n?(o?.(),{isFullyAvailable:!1,documentResponse:n,contentType:"application/pdf"}):(l.destroy(),c=!0,y(e,t,s,o))}catch(n){if(l?.destroy(),c)throw n;return y(e,t,s,o)}}var w=n(13483);let b;class _ extends c.Ay{constructor(e){const t=e.baseUrl||(0,r.$_)(window.document),n=e.baseCoreUrl||t,s=e.baseProcessorEngineUrl||t,a={...e,baseUrl:t,baseCoreUrl:n,baseProcessorEngineUrl:s};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(b&&b!==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=e}async load(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=()=>{try{let e=(0,h.jU)();e||(e=(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)(e))}catch(e){console.error("Error initializing GdPicture client:",e)}};let n=.2;e.progressCallback&&e.progressCallback("loading",n),this._isPDFJavaScriptEnabled=e.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))&&t();const a=await F(this.client,this._state).finally((()=>{n+=.3,e.progressCallback&&e.progressCallback("loading",n)})),r=g(this._state.document,this.corePDFDocument,this._state.allowLinearizedLoading,this._state.httpHeaders||void 0,(()=>{n+=.3,e.progressCallback&&e.progressCallback("loading",n)}),(e=>{(0,p.uA)(e)&&t()}));(0,i.V1)(a);const{features:c,signatureFeatureAvailability:l,capabilities:f,licenseData:y}=a;if(this._state.productId===m.v.SharePoint&&"string"==typeof this._state.document&&Array.isArray(a.afu)){const e=new URL(this._state.document,this._state.baseUrl);if(!a.afu.some((t=>e.hostname.match(t))))throw new i.uE(`The document origin ${e.hostname} is not authorized.`)}const w=l===u.g.ELECTRONIC_SIGNATURES&&(0,d.UX)(c)&&this._state.forceLegacySignaturesFeature?u.g.LEGACY_SIGNATURES:l;this._state=this._state.set("features",(0,s.B8)(c)).set("signatureFeatureAvailability",w),b=this._state.licenseKey;const _=await r;let D=null;if(_.isFullyAvailable){let t=_.fullDocument.slice(0),n=null;if((0,p.C5)(_.contentType)||!f.includes("GdPictureWASM"))try{this.destroyed?(t=null,D=await new Promise((()=>{}))):(D=await this.client.openDocument(_.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.":f.includes("GdPictureWASM")||(e.message="File not in PDF format or corrupted."),n=e}if(f.includes("GdPictureWASM")&&(n instanceof i.uE&&n.message.includes("File not in PDF format or corrupted.")||!(0,p.C5)(_.contentType))){(0,i.V1)(t);let s,a=(0,h.jU)();try{a||(a=(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)(a)),s=await a,(0,i.V1)(s);const n=await s.toPdf({document:t,officeConversionSettings:e.officeConversionSettings,contentType:_.contentType?.split(";")[0].trim()});D=await this.client.openDocument(n,{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",n.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,s?.destroy(),(0,h.Pm)(null)}}else if(n)throw n;(0,i.V1)(D),await this.afterDocumentLoaded(D)}else D=_.documentResponse;this._state=this._state.set("documentResponse",D);const v=this.mapLicenseDataToClientInfo(y);return{features:this._state.features,signatureFeatureAvailability:this._state.signatureFeatureAvailability,hasPassword:!!e.password,password:e.password,allowedTileScales:"all",evaluation:a.evaluation,linearizedLoading:!_.isFullyAvailable,documentResponse:D,clientInfo:v}}mapLicenseDataToClientInfo(e){if(!e)return null;let t=w.n.DEVELOPMENT;"p"===e.type?t=w.n.PRODUCTION:"d"===e.type?t=w.n.DEMO:"b"===e.type?t=w.n.DEVELOPMENT:"t"===e.type&&(t=w.n.EVALUATION);return{environment:t,productId:w.O.WEB,productVersion:"1.11.0-541b242",licenseId:e.li,demoKeyId:"d"===e.type?e.i:void 0}}destroy(){this.destroyed=!0,super.destroy()}getCustomFontsPromise(){return D}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,n=e.ID;if(t.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(t.changing!==n.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 e=await this._trustedCAsCallback();if(!Array.isArray(e))throw new i.uE("Certificates response must be an array");if(e.some((e=>!(e instanceof ArrayBuffer)&&"string"!=typeof e)))throw new i.uE("All certificates must be passed as ArrayBuffer (DER) or string (PEM)");await this.client.loadCertificates(e.map(l.PI))}catch(e){throw new i.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 i.uE(`Failed to fetch document: ${e.statusText}`);return e.arrayBuffer()}throw new i.uE("Document bytes are not available")}}const D={current:void 0};async function F(e,t){D.current=D.current||(t.customFonts?(0,f.eY)(t.customFonts):void 0);const n=(0,r.f)(t.appName);return e.loadNativeModule(t.baseCoreUrl,{mainThreadOrigin:n,disableWebAssemblyStreaming:t.disableWebAssemblyStreaming,enableAutomaticLinkExtraction:t.enableAutomaticLinkExtraction,overrideMemoryLimit:t.overrideMemoryLimit,workerSpawnerFn:()=>(0,a.pj)(t.inlineWorkers)}).then((async()=>e.load(t.baseCoreUrl,t.licenseKey,{mainThreadOrigin:n,...D.current?{customFonts:await D.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})()})))}}}]);