@nutrient-sdk/viewer
Version:
View and annotate PDF files in your web app. Full support for mobile and desktop. Runs in the browser using WASM.
13 lines • 22.7 kB
JavaScript
/*!
* Nutrient Web SDK 1.15.1 (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:()=>T,default:()=>I,loadModule:()=>B,normalizeCoreOptions:()=>d.DO,validateStandaloneConfiguration:()=>d.mn});var n=s(34724),a=s(57191),i=s(89339),o=s(86177),r=s(70274),c=s(64662),l=s(80695),u=s(23264),d=s(74129),h=s(39515),f=s(9855),m=s(28805),p=s(33704),y=s(58825),g=s(96584),w=s(51974),b=s(73844);function A(e){return null!==e&&(0,b.uA)(e)&&!(0,b.C5)(e)}function _(e){return"opfs"!==e.mode?"memory":e.isAuto?"auto":"opfs"}function F(e,t){const s={credentials:"same-origin"};if(e&&Object.keys(e).length>0){const t=new Headers;Object.entries(e).forEach(e=>{let[s,n]=e;t.append(s,n)}),s.headers=t}return t&&(s.signal=t),s}function P(e,t){"opfs"===e.mode&&(e.isAuto?(0,i.R8)(`OPFS storage: ${t}. Falling back to memory.`):(0,i.R8)(`OPFS storage was explicitly requested, but ${t}. Falling back to memory.`))}async function v(e){try{await e.closeOPFSStorage()}catch{}}async function D(e,t,s,n,a,o,r,c,l){const u=F(a,l);let d;r?(d=r,o?.()):d=await fetch(e,u).finally(()=>{o?.()});const h=(f=d.headers?.get("Content-Type"),f?.toLowerCase().split(";")[0].trim()||null);var f;h&&c?.(h);const m=d.headers?.get("Content-Length"),p=m?parseInt(m,10):null,y=Number.isFinite(p)?p:null,g=_(n),D=function(e,t,s){return"opfs"===e.mode&&!A(t)&&(null===e.minFileSize||null!==s&&s>=e.minFileSize)}(n,h,y);let S;if("opfs"===n.mode&&(A(h)?S="unsupported-content-type":null!==n.minFileSize&&null===y?S="file-size-unknown":null!==n.minFileSize&&null!==y&&y<n.minFileSize&&(S="below-min-file-size")),D){const a=await async function(e,t,s,n){const a=e.headers?.get("Content-Length");if(!a)return P(n,"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(n,"the Content-Length header is invalid"),{document:null,canReuseResponse:!0,fallbackReason:"content-length-invalid"};if(!await t.initOPFSStorage(o))return{document:null,canReuseResponse:!0,fallbackReason:"init-failed"};const r=1048576,c=e.body?.getReader();if(!c)return(0,i.R8)("OPFS storage: ReadableStream not available. Falling back to memory."),await v(t),{document:null,canReuseResponse:!0,fallbackReason:"readable-stream-unavailable"};let l=0,u=null;try{let e=new Uint8Array(r),s=0;for(;;){const{done:n,value:a}=await c.read();if(n){if(s>0){const n=e.subarray(0,s);await t.writeOPFSChunk(n,l-s)}break}null===u&&(u=a.slice(0,Math.min(a.byteLength,16384)));let i=0;for(;i<a.byteLength;){const n=r-s,o=Math.min(n,a.byteLength-i);e.set(a.subarray(i,i+o),s),s+=o,i+=o,l+=o,s===r&&(await t.writeOPFSChunk(e,l-s),e=new Uint8Array(r),s=0)}}}catch(e){return(0,i.R8)(`OPFS storage: error during streaming write: ${e}. Falling back to memory.`),await v(t),{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 v(t),{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 t.readOPFSBytes(0,a),r=i.slice(0,Math.min(i.byteLength,8192)),c=await(0,b.oj)(r.buffer,s,e.headers?.get("Content-Type"));return{document:{type:"opfs",isFullyAvailable:!0,fullDocument:null,opfsActive:!0,documentHeadBuffer:i.buffer,contentType:c,storageAnalytics:{storageRequested:_(n),storageActual:"opfs"}},canReuseResponse:!1}}catch(e){return(0,i.R8)(`OPFS storage: error during finalization: ${e}. Falling back to memory.`),await v(t),{document:null,canReuseResponse:!1,fallbackReason:"finalization-error"}}}(d,t,s,n);if(a.document)return a.document;S=a.fallbackReason??S,(0,w.q)("DocumentLoader: OPFS load failed; falling back to in-memory document load",{canReuseResponse:a.canReuseResponse,fallbackReason:S}),a.canReuseResponse||(d=await fetch(e,u))}const L=await d.arrayBuffer();return{type:"memory",isFullyAvailable:!0,fullDocument:L,contentType:await(0,b.oj)(L,s,d.headers?.get("Content-Type")),storageAnalytics:{storageRequested:g,storageActual:"memory",...S?{storageFallbackReason:S}:{}}}}async function S(e,t,s,n){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(e instanceof ArrayBuffer){const t=await(0,b.oj)(e,s),n=_(a);return l?.(t),{type:"memory",isFullyAvailable:!0,fullDocument:e,contentType:t,storageAnalytics:{storageRequested:n,storageActual:"memory",..."memory"!==n?{storageFallbackReason:"arraybuffer-input"}:{}}}}(0,i.V1)("string"==typeof e,"Document is not a string");let d=!1;const{linearizedDocument:h,serverSupportsRangeRequests:f,fallbackResponse:m}=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 t=await s.openLinearizedDocument(o.EA);(0,i.V1)(t,"Linearized document is not available"),t.contentType&&l&&l(t.contentType);const n=await t.initialize(e,r,u);return n.supportsRanges?{linearizedDocument:t,serverSupportsRangeRequests:!0,fallbackResponse:void 0}:{linearizedDocument:null,serverSupportsRangeRequests:!1,fallbackResponse:n.fullResponse}}return{linearizedDocument:null,serverSupportsRangeRequests:!1,fallbackResponse:void 0}})();try{if(!f)return d=!0,D(e,t,s,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,D(e,t,s,a,r,c,void 0,l,u);c?.();const n=await h.waitUntilDocumentInfoAvailable(u);return n?("undefined"!=typeof performance&&"function"==typeof performance.mark&&performance.mark("linearized-first-page-ready"),c?.(),{type:"linearized",isFullyAvailable:!1,documentResponse:n,contentType:"application/pdf",storageAnalytics:{storageRequested:_(a),storageActual:h.isUsingOPFS?"opfs":"memory",...h.opfsFallbackReason?{storageFallbackReason:h.opfsFallbackReason}:{}}}):(await h.destroyAsync(),d=!0,D(e,t,s,a,r,c,void 0,l,u))}catch(n){if(await(h?.destroyAsync()),n instanceof DOMException&&"AbortError"===n.name)throw n;if(d)throw n;return D(e,t,s,a,r,c,void 0,l,u)}}var L=s(80874),R=s(61469),C=s(82725),E=s(30435);let O;class k extends Error{}class I extends d.Ay{waitForAbandonedLoad(){return new Promise((e,t)=>{const s=this._loadSignal;s?.aborted?t((0,E.NK)()):s&&s.addEventListener("abort",()=>t((0,E.NK)()),{once:!0})})}raceWithLoadAbort(e){const t=this._loadSignal;return t?t.aborted?Promise.reject(new k):new Promise((s,n)=>{const a=()=>{n(new k)};t.addEventListener("abort",a,{once:!0}),e.then(e=>{t.removeEventListener("abort",a),s(e)},e=>{t.removeEventListener("abort",a),n(e)})}):e}retainGdPictureLoad(){this._retainedGdPictureLoad||(this._retainedGdPictureLoad=!0,(0,y.qR)())}async releaseGdPictureLoad(){this._retainedGdPictureLoad&&(this._retainedGdPictureLoad=!1,await(0,y.M7)())}async abandonLoadAfterCleanup(){throw await this.releaseGdPictureLoad(),new k}async openDocumentOrAbandon(e,t){try{const s=await this.client.openDocument(e,t);return this.destroyed&&await this.abandonLoadAfterCleanup(),s}catch(e){throw this.destroyed&&await this.abandonLoadAfterCleanup(),e}}async openDocumentWithOPFSOrAbandon(e){try{const t=await this.client.openDocumentWithOPFS(e);return this.destroyed&&await this.abandonLoadAfterCleanup(),t}catch(e){throw this.destroyed&&await this.abandonLoadAfterCleanup(),e}}stashDocumentHeadBuffer(e){const t=Math.min(e.byteLength,16384);this._documentHeadBuffer=e.slice(0,t)}constructor(e){const t=e.baseUrl||(0,u.$_)(window.document),s=e.baseCoreUrl||t,a=e.baseProcessorEngineUrl||t,o={...e,baseUrl:t,baseCoreUrl:s,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`");if(O&&O!==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,n.A)(this,"_resolvedPdfBuffer",null),(0,n.A)(this,"_documentHeadBuffer",null),(0,n.A)(this,"_loadInProgress",!1),(0,n.A)(this,"_loadSignal",null),(0,n.A)(this,"_retainedGdPictureLoad",!1),(0,n.A)(this,"_opfsActive",!1),(0,n.A)(this,"_documentStorageAnalytics",null),(0,n.A)(this,"corePDFAccess",null),(0,n.A)(this,"_pageHideListener",e=>{e.persisted||this.destroyed||"opfs"!==this._state.storage.mode||this.cleanupOPFSStorage("pagehide",!1)}),this.destroyed=!1,this.activeConfiguration=e,window.addEventListener("pagehide",this._pageHideListener)}cleanupOPFSStorage(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const s=this.corePDFAccess,n="opfs"===this._state.storage.mode&&s&&(!t||this._opfsActive);this._opfsActive=!1,n&&s.closeOPFSStorage().catch(t=>{(0,i.R8)(`OPFS storage cleanup error (${e}): ${t}`)})}async load(){let e=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=e.signal??null;try{const t=()=>{try{this.retainGdPictureLoad();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,b.XC)(this._state.baseUrl,this._state.document,this._state.productId),this._state.document instanceof ArrayBuffer&&(0,b.uA)(await(0,b.oj)(this._state.document))&&t();const n=await this.raceWithLoadAbort(B(this.client,this._state).finally(()=>{s+=.3,e.progressCallback&&e.progressCallback("loading",s)}));(0,l.lp)(),this.destroyed&&await this.abandonLoadAfterCleanup();const o=this.client.workerSpawner;(0,i.V1)(o,"WorkerSpawner is null");const u=o.getWorker();(0,i.V1)(u,"Worker is null");const d=r.LV(u);this.corePDFAccess=d,"opfs"===this._state.storage.mode&&d.cleanupOPFSOrphans().catch(e=>{(0,i.R8)(`OPFS orphan cleanup failed: ${e}`)});const h="string"==typeof this._state.dynamicFonts?this._state.dynamicFonts.split("/").slice(0,-1).join("/"):void 0;this.corePDFDocument=new C.N({corePDFAccess:d,canvasRendering:this._state.canvasRendering,dynamicFontsBaseURL:h,storage:this._state.storage},{type:"alreadyLoadedDocument"});const g=S(this._state.document,d,this.corePDFDocument,this._state.allowLinearizedLoading,this._state.storage,this._state.httpHeaders||void 0,()=>{s+=.3,e.progressCallback&&e.progressCallback("loading",s)},e=>{(0,b.uA)(e)&&t()},e.signal);(0,i.V1)(n);const{features:w,signatureFeatureAvailability:A,capabilities:_,licenseData:F}=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 i.uE(`The document origin ${e.hostname} is not authorized.`)}const P=A===f.g.ELECTRONIC_SIGNATURES&&(0,m.UX)(w)&&this._state.forceLegacySignaturesFeature?f.g.LEGACY_SIGNATURES:A;this._state=this._state.set("features",(0,a.B8)(w)).set("signatureFeatureAvailability",P),O=this._state.licenseKey;const v=await this.raceWithLoadAbort(g);this._documentStorageAnalytics=v.storageAnalytics??null;let D=null;const L={password:e.password,initialPageIndex:"number"==typeof e.initialPageIndex?e.initialPageIndex:0,formsConfiguration:this._formsConfiguration};if("memory"===v.type){let t=null;const s=(0,b.C5)(v.contentType),n=_.includes("GdPictureWASM"),a=s||!n;if(a)try{this.destroyed?D=await this.abandonLoadAfterCleanup():((this.activeConfiguration.isTextComparison||this.activeConfiguration.aiAssistant)&&(this._resolvedPdfBuffer=v.fullDocument.slice(0)),this.stashDocumentHeadBuffer(v.fullDocument),D=await this.raceWithLoadAbort(this.openDocumentOrAbandon(v.fullDocument,L)))}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.":_.includes("GdPictureWASM")||(s.message="File not in PDF format or corrupted.");t=s}const o=t?.message,r=t instanceof i.uE&&"string"==typeof o&&o.includes("File not in PDF format or corrupted.");if(!n||!r&&s){if(t)throw t}else{this.retainGdPictureLoad();let s=null;const n=t?.callArgs,o=Array.isArray(n)?n[0]:null;if(o instanceof ArrayBuffer?s=o:a?"string"==typeof this._state.document&&(s=await this.fetchDocumentBytesWithCurrentHeaders(this._state.document)):s=v.fullDocument,!(s instanceof ArrayBuffer)){if(t)throw t;throw new i.uE("Document bytes are not available")}let r=this.destroyed;const u=v.contentType;try{if(!r){(0,l.HN)();const t=await(0,y.fL)(s,u,{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,e.signal);(0,l.yq)(),(this.activeConfiguration.isTextComparison||this.activeConfiguration.aiAssistant)&&(this._resolvedPdfBuffer=t.slice(0)),this.stashDocumentHeadBuffer(t),r=this.destroyed,r||(D=await this.raceWithLoadAbort(this.openDocumentOrAbandon(t,L)))}}catch(e){if(!this.destroyed){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}r=!0}r&&(D=await this.abandonLoadAfterCleanup())}(0,i.V1)(D),await this.afterDocumentLoaded(D)}else if("opfs"===v.type)if(this.destroyed)D=await this.abandonLoadAfterCleanup();else{this._opfsActive=!0,this._documentHeadBuffer=v.documentHeadBuffer;try{D=await this.raceWithLoadAbort(this.openDocumentWithOPFSOrAbandon(L))}catch(t){const s=t,n=_.includes("GdPictureWASM"),a=s instanceof i.uE&&"string"==typeof s.message&&s.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(!n||!a||"string"!=typeof this._state.document)throw s;{this.retainGdPictureLoad();let t=this.destroyed;const s=v.contentType;try{if(!t){(0,l.HN)();const n=await(0,y.fL)(await this.fetchDocumentBytesWithCurrentHeaders(this._state.document),s,{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,e.signal);(0,l.yq)(),this.activeConfiguration.isTextComparison&&(this._resolvedPdfBuffer=n.slice(0)),this.stashDocumentHeadBuffer(n),t=this.destroyed,t||(D=await this.raceWithLoadAbort(this.openDocumentOrAbandon(n,L)))}}catch(e){if(!this.destroyed){const t=e;if("INVALID_PASSWORD"===t.message){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}t=!0}t&&(D=await this.abandonLoadAfterCleanup())}}(0,i.V1)(D),await this.afterDocumentLoaded(D)}else D=v.documentResponse;this._state=this._state.set("documentResponse",D);const R=this.mapLicenseDataToClientInfo(F);return{features:this._state.features,signatureFeatureAvailability:this._state.signatureFeatureAvailability,hasPassword:!!e.password,password:e.password,allowedTileScales:"all",evaluation:n.evaluation,linearizedLoading:!v.isFullyAvailable,documentResponse:D,clientInfo:R}}catch(e){if(e instanceof k)return this.waitForAbandonedLoad();throw e}finally{this._loadInProgress=!1,this._loadSignal=null,await this.releaseGdPictureLoad()}}mapLicenseDataToClientInfo(e){const t="1.15.1",s=(0,L.o)(this._state.productId);if(null===s)return null;if(!e)return{environment:R.n.EVALUATION,productId:s,productVersion:t,licenseId:void 0,demoKeyId:void 0};let n=R.n.DEVELOPMENT;return"p"===e.type?n=R.n.PRODUCTION:"d"===e.type?n=R.n.DEMO:"b"===e.type?n=R.n.DEVELOPMENT:"t"===e.type&&(n=R.n.EVALUATION),{environment:n,productId:s,productVersion:t,licenseId:e.li,demoKeyId:"d"===e.type?e.i:void 0}}takeResolvedPdfBuffer(){const e=this._resolvedPdfBuffer;return this._resolvedPdfBuffer=null,e}takeDocumentHeadBuffer(){const e=this._documentHeadBuffer;return this._documentHeadBuffer=null,e}getDocumentStorageAnalytics(){return this._documentStorageAnalytics}destroy(){if(this.destroyed=!0,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()}getCustomFontsPromise(){return T}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,n=s.changing??s.update;if(t.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(t.changing!==n)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(h.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()=>{const t=this.corePDFDocument.linearizedDocument.isUsingOPFS,s=await this.corePDFDocument.normallyOpenLinearizedDocument(this,{password:e,initialPageIndex:0,formsConfiguration:this._formsConfiguration});this.destroyed&&(t&&(await(this.corePDFAccess?.closeOPFSStorage().catch(e=>{(0,i.R8)(`OPFS storage cleanup error: ${e}`)})),this._opfsActive=!1),await this.waitForAbandonedLoad()),t&&(this._opfsActive=!0),this._state=this._state.set("documentResponse",s),await this.afterDocumentLoaded(s)})}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")}async fetchDocumentBytesWithCurrentHeaders(e){return(await fetch(e,F(this._state.httpHeaders||void 0))).arrayBuffer()}}const T={current:void 0};async function B(e,t){T.current=T.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,...T.current?{customFonts:await T.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})()}))}}}]);