/*!
 * PSPDFKit for Web 2022.2.0 (https://pspdfkit.com/web)
 *
 * Copyright (c) 2016-2022 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://pspdfkit.com/acknowledgements/web/
 */
"use strict";(globalThis.webpackChunkPSPDFKit=globalThis.webpackChunkPSPDFKit||[]).push([[6377],{89930:(t,e,n)=>{n.r(e),n.d(e,{default:()=>I});var s=n(70545),a=n(14968);var o=n(33502),i=n(19491),r=n(50893),d=n(89595),c=n(35369),l=n(80614),h=n(89777),u=n(85596),p=n(11706),m=n(12130);var f=n(51534),g=n(1367),w=n(49029);class y extends(c.WV({authPayload:null,serverUrl:null,hostedBaseUrl:null,documentId:null,backendPermissions:null,documentURL:null,imageToken:null,instantSettings:null,token:null,features:(0,c.aV)(),signatureFeatureAvailability:w.H.NONE,isFormsEnabled:!0,minSearchQueryLength:1,documentHandle:null,isDocumentHandleOutdated:!1,digitalSignatures:null,defaultGroup:void 0,hasCollaborationPermissions:!1,forceLegacySignaturesFeature:!1})){}var P=n(11278),_=n(50809),S=n(16396);const b="The image can not be rendered because of an unknown error.";class v{constructor(t){let{identifier:e,url:n,token:s,payload:a,doNotRequestWebP:o=!1}=t;this.identifier=e,this.url=n,this.token=s,this.payload=a,this.doNotRequestWebP=o}abort(){this.httpRequest&&this.httpRequest.abort()}request(){return new Promise(((t,e)=>{const n=new XMLHttpRequest;this.httpRequest=n,n.open(this.payload?"POST":"GET",this.url,!0),n.setRequestHeader("X-PSPDFKit-Image-Token",this.token),n.setRequestHeader("PSPDFKit-Platform","web"),n.setRequestHeader("PSPDFKit-Version",(0,a.oM)()),_.Zy&&!this.doNotRequestWebP&&n.setRequestHeader("Accept","image/webp,*/*"),n.responseType="blob",n.onreadystatechange=(async()=>{if(4!==n.readyState)return;if(n.response&&n.response.type.startsWith("application/json")){const a=new FileReader;return a.onload=n=>{var a;const o=JSON.parse(null===(a=n.target)||void 0===a?void 0:a.result);o.attachments_not_found?t({attachmentsNotFound:o.attachments_not_found}):o.error?e(new s.p2(`The server could not render the requested image (${o.error})`)):e(new s.p2(b))},a.onerror=()=>e(new s.p2(b)),void a.readAsText(n.response)}if(!(0,P.v)(n.status))return void e(new s.p2(b));const a=n.response,o=URL.createObjectURL(a),i=new Image;i.onerror=()=>e(new s.p2(b)),i.src=o;const r="function"==typeof i.decode?i.decode():new Promise((t=>setTimeout(t,200)));await r,t(new S.Z(i,(()=>URL.revokeObjectURL(o))))}).bind(this),n.send(this.payload)}))}}var R=n(34997),F=n(94290),k=n(47291),$=n(67117),A=n(63880),T=n(29412),U=n(46232),x=n(42457),D=n(24956),j=n(5164);class I extends T.W{_password=null;type="SERVER";constructor(t){var e;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window;if(super(),"object"!=typeof t.authPayload)throw new s.p2("authPayload must be an object that contains the `jwt`. For example: `authPayload: { jwt: 'xxx.xxx.xxx'}`");const o=null===(e=t.authPayload)||void 0===e?void 0:e.accessToken;let i,r;if(o){if(i=null,r=null,function(t){if("string"!=typeof t)throw new s.p2("`accessToken` must be of type string.")}(o),"string"!=typeof t.hostedBaseUrl)throw new s.p2("`hostedBaseUrl` must be of type string.")}else{if(i=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window;const n=t.serverUrl||(0,a.SV)(e.document);if("/"!==n.substr(-1))throw new s.p2("`serverUrl` must have a slash at the end (e.g. `https://pspdfkit.example.com/`).");if(!t.serverUrl){if(n===`${e.location.protocol}//${e.location.host}/`)throw new s.p2('PSPDFKit automatically infers the URL of PSPDFKit Server from the current `<script>` tag.\nIn the current case, this URL is set to the same as the current browser\'s location.\nThis can happen when you bundle pspdfkit.js with your custom JavaScript for example.\n\nTo make sure everything works as expected, please set the `serverUrl` to the URL of PSPDFKit Server:\n\nPSPDFKit.load({\n  serverUrl: "https://pspdfkit-server.example.com/",\n  ...,\n});')}return n}(t,n),"string"!=typeof t.documentId)throw new s.p2("`documentId` must be of type string.");if(r=`${i}i/d/${t.documentId}`,"object"!=typeof t.authPayload||!("jwt"in t.authPayload)||"string"!=typeof t.authPayload.jwt)throw new s.p2("authPayload must be an object that contains the `jwt`. For example: `authPayload: { jwt: 'xxx.xxx.xxx'}`");!function(t){const e="The supplied JWT is invalid. Please refer to our guides on how to set up authentication:\n  https://pspdfkit.com/guides/web/current/server-backed/client-authentication/";if(-1!==t.indexOf('{"internal":'))return;let n;(0,s.kG)("string"==typeof t&&3===t.split(".").length,e);try{const e=m.Base64.decode(t.split(".")[1]);n=JSON.parse(e)}catch(t){throw new s.p2(e)}(0,s.kG)("string"==typeof n.document_id,"The supplied JWT is invalid. The field 'document_id' has to be a string value.\n  Please refer to our guides for further information: https://pspdfkit.com/guides/web/current/server-backed/client-authentication/")}(t.authPayload.jwt)}!function(t){let e="";if("boolean"!=typeof t&&((0,s.PO)(t)?(t.hasOwnProperty("clientsPresenceEnabled")&&"boolean"!=typeof t.clientsPresenceEnabled&&(e+="`clientsPresenceEnabled` in instance settings is not valid. Must be `true` or `false`.\n"),t.hasOwnProperty("listenToServerChangesEnabled")&&"boolean"!=typeof t.listenToServerChangesEnabled&&(e+="`listenToServerChangesEnabled` in instance settings is not valid. Must be `true` or `false`.\n")):e="`instant` flag must either be set to `true` or `false`\n",e))throw new s.p2(`${e}\nFor more information about PSPDFKit Instant please visit:\nhttps://pspdfkit.com/guides/web/current/instant/overview/`)}(t.instant);let d=null;if(t.instant)if((0,s.PO)(t.instant)){const e=t.instant;d={clientsPresenceEnabled:!1!==e.clientsPresenceEnabled,listenToServerChangesEnabled:!1!==e.listenToServerChangesEnabled}}else d=k.q;this._requestQueue=new g.Z(l.Qc);const c=!!t.electronicSignatures&&Boolean(t.electronicSignatures.forceLegacySignaturesFeature);this._state=new y({serverUrl:i,hostedBaseUrl:t.hostedBaseUrl,documentId:t.documentId,instantSettings:d,documentURL:r,authPayload:t.authPayload,isFormsEnabled:!t.disableForms,forceLegacySignaturesFeature:c}),t.trustedCAsCallback&&(0,s.ZK)("PSPDFKit.Configuration#trustedCAsCallback is only used on Standalone deployments. On a Server-backed deployment, please follow the instructions at https://pspdfkit.com/guides/web")}isUsingInstantProvider(){return null!=this._state.instantSettings}hasClientsPresence(){const t=this._state.instantSettings;return null!=t&&!1!==t.clientsPresenceEnabled}async load(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};await this.tryAuthenticateHostedViewer();const{imageToken:e,token:n,permissions:i,features:r,signatureFeatureAvailability:d,hasPassword:l,minSearchQueryLength:h,layerHandle:u,allowedTileScales:m,digitalSignatures:f,defaultGroup:g,collaborationPermissions:y,creatorName:P}=await async function(t,e,n){const o=await fetch(`${t}/auth`,{method:"POST",headers:{"Content-Type":"application/json","PSPDFKit-Platform":"web","PSPDFKit-Version":(0,a.oM)()},body:JSON.stringify({jwt:e.jwt,origin:window.location.href,password:n}),credentials:"include"});return o.ok?o.json():o.text().then((t=>{throw"INVALID_PASSWORD"===t?new s.p2(t):new s.p2(`An error occurred while connecting to PSPDFKit Server: ${t||o.statusText}`)}))}(`${this._state.serverUrl}i/d/${this._state.documentId}`,this._state.authPayload,t.password);if(this._password=t.password,this._state.instantSettings&&!r.includes(o.sw.INSTANT))throw new s.p2("Instant feature is not enabled on this server. Please set `instant` to `false`.\n\nFor more information about PSPDFKit Instant please visit:\nhttps://pspdfkit.com/guides/web/current/instant/overview/");const _=d===w.H.ELECTRONIC_SIGNATURES&&r.includes(o.sw.WEB_ANNOTATION_EDITING)&&this._state.forceLegacySignaturesFeature?w.H.LEGACY_SIGNATURES:d;if(this._state=this._state.withMutations((t=>t.set("imageToken",e).set("token",n).set("features",(0,c.aV)(r)).set("signatureFeatureAvailability",_).set("backendPermissions",new o.Fm({readOnly:-1===i.indexOf("write"),downloadingAllowed:i.indexOf("download")>=0})).set("documentURL",`${this._state.serverUrl}i/d/${this._state.documentId}/h/${u}`).set("documentHandle",u).set("isDocumentHandleOutdated",!1).set("digitalSignatures",(0,p.rS)(f)))),y&&!this._state.instantSettings)throw new s.p2("Collaboration Permissions is not supported when `instant` is disabled. Please make sure `configuration#instant` is set to `true`.");return this._state=this._state.withMutations((t=>{t.defaultGroup=g,t.hasCollaborationPermissions=Boolean(y)})),this.provider&&this.provider.destroy(),this.provider=await this._initProvider(),this._state.instantSettings&&this.provider.setDocumentHandleConflictCallback(this.handleDocumentHandleConflict),{features:this._state.features,signatureFeatureAvailability:this._state.signatureFeatureAvailability,hasPassword:l,minSearchQueryLength:h,allowedTileScales:m,jsActionChanges:[],creatorName:P,defaultGroup:g}}async tryAuthenticateHostedViewer(){if("accessToken"in this._state.authPayload){const{hostedBaseUrl:t}=this._state,e=this._state.authPayload.accessToken,{serverUrl:n,serverId:s,jwt:a}=await async function(t,e){const n=await fetch(`${t}/i/documents/auth`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","PSPDFKit-Platform":"web","PSPDFKit-Version":"cloud-protocol=1, server-protocol=4, client=2022.2.0, client-git=9a2108e332"},body:JSON.stringify({accessToken:e})});if(n.ok)return n.json();throw new Error(`An error occurred while connecting to PSPDFKit API: ${await n.text()}`)}(t,e);this._state=this._state.withMutations((t=>{t.set("serverUrl",n).set("documentId",s).set("documentURL",`${n}i/d/${s}`).set("authPayload",{jwt:a})}))}}async _initProvider(){if(this._state.instantSettings){const t=`${this._state.serverUrl}i/d/${this._state.documentId}/h/${this._state.documentHandle}`,{InstantProvider:e}=await n.e(2333).then(n.bind(n,20251));return new e(`${this._state.serverUrl}i/d/${this._state.documentId}`,t,{auth_token:this._state.token},this._state.instantSettings)}{const t=this._state.isFormsEnabled&&this._state.features.includes(o.sw.FORMS),{RESTProvider:e}=await n.e(4099).then(n.bind(n,82450));return new e(this._state.documentURL,{token:this._state.token},{isFormsEnabled:t})}}destroy(){this._destroyProvider(),this._requestQueue&&this._requestQueue.destroy()}documentInfo(){return this._fetch(`${this._state.documentURL}/document.json`).then((t=>t.json())).then((t=>t.data))}getFormJSON(){return this._fetch(`${this._state.documentURL}/form.json`).then((t=>403===t.status?{v:1,type:"pspdfkit/form",annotations:[],fields:[]}:t.json().then((t=>t.data))))}async evalFormValuesActions(){throw new Error("not implemented")}async evalScript(){throw new Error("not implemented")}permissions(){return Promise.resolve(this._state.backendPermissions)}getDefaultGroup(){return this._state.defaultGroup}isCollaborationPermissionsEnabled(){return this._state.hasCollaborationPermissions}textForPageIndex(t){const e=`${this._state.documentURL}/page-${t}-text`,n=new(this._getJSONRequestHandler())(e,this._state.token),s=this._requestQueue.enqueue(n,!0);return{promise:s.promise.then((e=>(0,d.T)(e,t))),cancel:()=>{s.cancel()}}}getTextFromRects(t,e){const n=encodeURIComponent(JSON.stringify(e.map(u.u).toArray()));return this._fetch(`${this._state.documentURL}/page-${t}-highlighted?rects=${n}`).then((t=>t.json())).then((t=>t.text))}_getJSONRequestHandler(){return f.Z}renderTile(t,e,n,a,o){var i=this;if(this._state.isDocumentHandleOutdated)return{promise:new Promise((()=>{})),cancel:()=>{}};const d=`${this._state.documentURL}/page-${t}-dimensions-${e.width}-${e.height}-tile-${n.left}-${n.top}-${n.width}-${n.height}${a?"-print":""}`,c=e.width===n.width&&e.height===n.height,h=n.width>l.pt||n.height>l.pt;let u,m,f=!1,g=!1,w=[],y=[];const P=new Promise(((t,e)=>{u=t,m=e})),_=function(){let t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(o){const n=new FormData;n.append("data",JSON.stringify({annotations:o.annotations.filter(r.d).map(p.Hs).toJS().map((t=>({content:t}))),formFieldValues:o.formFieldValues.map(p.kr).toJS(),formFields:o.formFields.map(p.vD).toJS(),signatures:o.signatures||[]})),e.length>0&&e.forEach((t=>{const e=o.attachments.get(t);(0,U.k)(e&&e.data,"Attachment data could not be found."),n.append(t,e.data)})),t=new v({identifier:d,url:d,token:i._state.imageToken,payload:n,doNotRequestWebP:h})}else t=new v({identifier:d,url:d,token:i._state.imageToken,doNotRequestWebP:h});y.push(t);const n=i._requestQueue.enqueue(t,c);n.promise.then((t=>{if(!f)return t.attachmentsNotFound&&!g?(g=!0,void _(t.attachmentsNotFound)):void(t.attachmentsNotFound?m(new s.p2("Attachment could not be found.")):u(t))})).catch((t=>{f||m(t)})),w.push(n)};return _(),{promise:P,cancel:()=>{f=!0,y.forEach((t=>{t.abort&&"function"==typeof t.abort&&t.abort()})),w.forEach((t=>{t.cancel()}))}}}_requestRenderAnnotation=(t,e,n,a,o,i)=>{var r=this;const d=`${this._state.documentURL}/render_annotation`,c=`render-annotation-${i?(0,R.SK)():t.id}`,h=JSON.stringify({data:(0,p.Hs)(t),width:a,height:o,detached:i||void 0,formFieldValue:e?(0,p.kr)(e):void 0});let u,m,f=!1,g=[];const w=new Promise(((t,e)=>{u=t,m=e})),y=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const i=new FormData;i.append("render",h),e.length>0&&t.imageAttachmentId&&n&&n.data&&i.append(t.imageAttachmentId,n.data);const p=new v({identifier:c,url:d,token:r._state.imageToken,payload:i,doNotRequestWebP:a>l.pt||o>l.pt}),w=r._requestQueue.enqueue(p,!1);w.promise.then((t=>{f||(t.attachmentsNotFound?y(t.attachmentsNotFound):t.attachmentsNotFound?m(new s.p2("Attachment could not be found.")):u(t))})).catch((t=>{f||m(t)})),g.push(w)};return y(),{promise:w,cancel:()=>{f=!0,g.forEach((t=>{t.cancel()}))}}};_requestRenderAnnotations=(t,e,n,s,a)=>{const o=`${this._state.documentURL}/render_annotations`,i=JSON.stringify({annotations:e.map(((e,a)=>({pageIndex:t,pdfObjectId:e,width:n[a],height:s[a]}))),formFieldValues:a});let r,d,c=!1;const l=new Promise(((t,e)=>{r=t,d=e}));return this._fetch(o,{method:"post",body:i,credentials:"include",headers:{"X-PSPDFKit-Image-Token":this._state.imageToken,"Content-Type":"application/json",Accept:"multipart/form-data"}}).then((t=>t.formData())).then((t=>{c||r(Array.from(t.values()))})).catch((t=>{c||d(t)})),{promise:l,cancel:()=>{c=!0}}};renderAnnotation(t,e,n,s,a){return this._requestRenderAnnotation(t,e,n,s,a)}renderPageAnnotations(t,e,n){if(!_.Rh){const e=Promise.resolve();return this.pageAPStreamsPromises=this.pageAPStreamsPromises.set(t,e),e}const a=this.provider;if(!this.provider._readStateCallbacks)return Promise.reject(new s.p2("Not initialized"));const o=[],i=e.filter((t=>{const{formField:e}=a._readStateCallbacks.getAnnotationWithFormField(t.id),n=(0,r._R)(t,e);return n&&e&&"number"==typeof t.pdfObjectId&&o.push((0,j.qM)(e,t.id)),n&&"number"==typeof t.pdfObjectId}));if(0===i.size&&0===o.length)return Promise.resolve();const d=new Promise(((e,s)=>{const{promise:a,cancel:r}=this._requestRenderAnnotations(t,i.map((t=>t.pdfObjectId)).toArray(),i.map((t=>Math.floor(t.boundingBox.width*n))).toArray(),i.map((t=>Math.floor(t.boundingBox.height*n))).toArray(),o);a.then((t=>{const n=t.map((t=>t&&(0,D.R4)(t)));n.forEach((async(t,e)=>{const n=await t,s=i.get(e);if(s){const t=this.annotationAPStreamPromises.get(s.id);t&&(this.annotationAPStreamPromises=this.annotationAPStreamPromises.delete(s.id),t(n)),n&&this.cacheAPStream(n,s)}})),Promise.all(n).then((()=>e()))})).catch((t=>{r(),s(t)}))}));return this.pageAPStreamsPromises=this.pageAPStreamsPromises.set(t,d),d}renderDetachedAnnotation(t,e,n,s){return this._requestRenderAnnotation(t,null,e,n,s,!0)}async getAttachment(t){try{const e=await this._fetch(`${this._state.documentURL}/attachments/${t}`);switch(e.status){case 404:throw new s.p2("Attachment not Found.");case 200:return await e.blob();default:throw new s.p2("Bad Request.")}}catch(t){throw new s.p2(`Could not fetch attachment from PSPDFKit Server. ${t}`)}}async search(t,e,n,s){let a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:A.S.TEXT;const i=`q=${o===A.S.PRESET?t.replace(/_/g,"-"):encodeURIComponent(t)}&start=${e}&limit=${n}&type=${o}&include_annotations=${a.toString()}&case_sensitive=${s.toString()}`,r=`${this._state.documentURL}/search?${i}`,d=await new f.Z(r,this._state.token).request();return(0,h.E)(d.data)}async searchAndRedact(t,e){const{searchType:n,annotationPreset:s,searchInAnnotations:a,caseSensitive:o}=e,{color:i,fillColor:r,outlineColor:d,...l}=s,h=await this._fetch(`${this._state.documentURL}/redactions`,{method:"post",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({strategy:n,strategyOptions:{[n]:n===A.S.PRESET?t.replace(/_/g,"-"):t,includeAnnotations:a,caseSensitive:o},content:{...l,color:i&&i.toHex(),fillColor:r&&r.toHex(),outlineColor:d&&d.toHex()}})}),{data:u}=await h.json();return(0,c.aV)(u&&u.annotations?u.annotations.map((t=>$.Z.fromJSON(t.id,t.content))):[])}exportPDF(){let{flatten:t=!1,includeComments:e=!0,excludeAnnotations:n=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const s=`${this._state.documentURL}/pdf?token=${this._state.token}&flatten=${String(t)}&comments=${String(e)}&render_ap_streams=${String(!t)}&remove_annotations=${String(n)}`;return fetch(s,{method:"GET",credentials:"include"}).then((t=>t.arrayBuffer()))}exportXFDF(){return this._fetch(`${this._state.documentURL}/document.xfdf`).then((t=>t.text()))}exportInstantJSON(){return this._fetch(`${this._state.documentURL}/instant.json`).then((t=>t.json()))}getPDFURL(){let{includeComments:t=!0,excludeAnnotations:e=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{promise:Promise.resolve(`${this._state.documentURL}/pdf?token=${this._state.token}&flatten=true&comments=${String(t)}&remove_annotations=${String(e)}`),revoke:()=>{}}}generatePDFObjectURL(){let t,{includeComments:e=!0,excludeAnnotations:n=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},s=!1;return{promise:new Promise((a=>{this.exportPDF({flatten:!0,includeComments:e,excludeAnnotations:n}).then((e=>{if(s)return;const n=new Blob([e],{type:"application/pdf"});t=window.URL.createObjectURL(n),a(t)}))})),revoke:()=>{t&&window.URL.revokeObjectURL(t),s=!0}}}async getDocumentOutline(){let t;try{t=(await this._fetch(`${this._state.documentURL}/outline.json`).then((t=>t.json()))).data}catch(e){t={}}const e=Array.isArray(t.outline)?t.outline:[];return(0,c.aV)(e.map(i.i))}onKeystrokeEvent(){throw new Error("not implemented")}async applyOperationsAndReload(t){try{const e=await O(t);this._destroyProvider(),await this._fetch(`${this._state.documentURL}/apply-operations`,{method:"post",body:e,credentials:"include"})}catch(t){throw new s.p2(`Applying operations failed: ${t}`)}return this.reloadDocument()}async applyRedactionsAndReload(){try{return this._destroyProvider(),await this._fetch(`${this._state.documentURL}/redact`,{method:"post",credentials:"include"}),this.reloadDocument()}catch(t){throw this.provider.load(),new s.p2(`Applying redactions failed: ${t}`)}}async reloadDocument(){try{return await this.load({password:this._password})}catch(t){throw new s.p2(`Reloading the document failed: ${t}`)}}async exportPDFWithOperations(t){try{const e=await O(t);return this._fetch(`${this._state.documentURL}/pdf-with-operations`,{method:"post",body:e,credentials:"include"}).then((t=>t.arrayBuffer()))}catch(t){throw new s.p2(`Exporting PDF with operations failed: ${t}`)}}async getSignaturesInfo(){return this._refreshSignaturesInfoPromise&&await this._refreshSignaturesInfoPromise,this._state.digitalSignatures}refreshSignaturesInfo(){return this._refreshSignaturesInfoPromise||(this._refreshSignaturesInfoPromise=new Promise(((t,e)=>{this._fetch(`${this._state.documentURL}/signatures`,{method:"get",credentials:"include"}).then((t=>t.json())).then((e=>{let{data:n}=e;this._state=this._state.set("digitalSignatures",(0,p.rS)(n)),this._refreshSignaturesInfoPromise=null,t()})).catch((t=>{this._state=this._state.set("digitalSignatures",null),this._refreshSignaturesInfoPromise=null,e(t)}))}))),this._refreshSignaturesInfoPromise}async signDocumentAndReload(t,e){try{if(void 0!==e&&"object"!=typeof e)throw new s.p2("Signing service data must be an object if specified.");const n={};t&&"placeholderSize"in t&&(n.signerDataSource={estimatedSize:t.placeholderSize}),t&&"flatten"in t&&(n.flatten=t.flatten);const a={...e?{signingToken:e.signingToken}:null,...n};this._destroyProvider(),await this._fetch(`${this._state.documentURL}/sign`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(a),credentials:"include"}),await this.reloadDocument()}catch(t){throw this.provider.load(),new s.p2(`Adding digital signature failed: ${t.message||t}`)}}handleDocumentHandleConflict=()=>{this._state=this._state.set("isDocumentHandleOutdated",!0),this.cancelRequests(),this._destroyProvider()};getDocumentHandle(){return this._state.documentHandle}async getEmbeddedFiles(){var t,e;const n=await this._fetch(`${this._state.documentURL}/embedded-files`,{method:"get",credentials:"include"}),s=await n.json();return(0,c.aV)(null!=s&&null!==(t=s.data)&&void 0!==t&&null!==(e=t.embeddedFiles)&&void 0!==e&&e.length?s.data.embeddedFiles.map((t=>{let{id:e,content:n}=t;return(0,x.i)(e,n)})):[])}cancelRequests(){this._requestQueue.cancelAll()}_destroyProvider(){this.provider&&(this.provider._clients&&this.provider._clients.disconnect(),this.provider.destroy())}async _fetch(t,e){const n=await fetch(t,{...e,headers:{...null==e?void 0:e.headers,"X-PSPDFKit-Token":this._state.token,"PSPDFKit-Platform":"web","PSPDFKit-Version":(0,a.oM)()}});if(!n.ok){let t=await function(t){return t.clone().json().catch((()=>t.text()))}(n);t="object"==typeof t?t.reason:t;const e=t||`${n.status} ${n.statusText}`;throw new s.p2(e)}return n}syncChanges(){return this.provider.syncChanges()}async clearAPStreamCache(){}}async function O(t){const e={},n=new WeakMap,s=await Promise.all(t.map((async(t,s)=>{if("importDocument"===t.type){const a=t.document;return(0,U.k)(a instanceof File||a instanceof Blob,"Wrong `importDocument` operation `document` value: it must be a File or a Blob"),(0,F.M)(n,e,a,t,s,"document")}if("applyInstantJson"===t.type){const a=t.instantJson;(0,U.k)("object"==typeof a&&null!==a,"Wrong `applyInstantJson` operation `instantJson` value: it must be an object");const o=JSON.stringify(a),i=new Blob([o],{type:"application/json"});return(0,F.M)(n,e,i,t,s,"dataFilePath")}if("applyXfdf"===t.type){const a=t.xfdf;(0,U.k)("string"==typeof a,"Wrong `applyXfdf` operation `xfdf` value: it must be a string");const o=new Blob([a],{type:"application/vnd.adobe.xfdf"});return(0,F.M)(n,e,o,t,s,"dataFilePath")}return t}))),a=new FormData;a.append("operations",JSON.stringify({operations:s}));for(const t in e)a.append(t,e[t]);return a}},47291:(t,e,n)=>{n.d(e,{q:()=>s});const s={clientsPresenceEnabled:!0,listenToServerChangesEnabled:!0}}}]);