/*!
 * PSPDFKit for Web 2021.4.1 (https://pspdfkit.com/web)
 * 
 * Copyright (c) 2016-2019 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/
 */
(window.webpackJsonpPSPDFKit=window.webpackJsonpPSPDFKit||[]).push([[59],{637:function(e,t,n){"use strict";n.d(t,"a",(function(){return u}));var s=n(1),i=n.n(s),a=n(4),r=n(2),o=n(3),c=n(18);class u{constructor(){i()(this,"cachedAPStreams",Object(a.b)()),i()(this,"pageAPStreamsPromises",Object(a.b)()),i()(this,"annotationAPStreamPromises",Object(a.b)())}cachedRenderAnnotation(e,t,n,s){const i=this.provider;Object(o.k)(i instanceof i.constructor,"Backend can only use backend annotation provider");const a=e instanceof r.fb?i._readStateCallbacks.getFormFieldByName(e.formFieldName):null,u=!a||a instanceof r.N?null:new r.s({name:a.name,value:void 0!==a.formattedValue?a.formattedValue:"string"==typeof a.value?a.value:a.values});if(!Object(c.t)(e,a))return this.renderAnnotation(e,u,t,n,s);let d=!1,h=()=>{d=!0};return{promise:new Promise((async(i,a)=>{const r=t=>{const n=this.annotationAPStreamPromises.get(e.id);n&&(this.annotationAPStreamPromises=this.annotationAPStreamPromises.delete(e.id),n(t))},o=this.annotationAPStreamPromises.get(e.id);this.annotationAPStreamPromises=this.annotationAPStreamPromises.set(e.id,i),o&&o(null);try{const a=this.pageAPStreamsPromises.get(e.pageIndex);if(!a){const t=new Promise((t=>{this.annotationAPStreamPromises=this.annotationAPStreamPromises.set(e.id,t)}));return void i(await t)}await a;const o=this.cachedAPStreams.get(e.pageIndex);if(o){const t=o?o.get(e.id):null;if(t)return void r(t)}const{promise:c,cancel:l}=this.renderAnnotation(e,u,t,n,s);if(d)r(null);else{h=l;const t=await c;r(t),t&&this.cacheAPStream(t,e)}}catch(e){a(e)}})),cancel:h}}cacheAPStream(e,t){let n=this.cachedAPStreams.get(t.pageIndex);n||(this.cachedAPStreams=this.cachedAPStreams.set(t.pageIndex,Object(a.b)()),n=this.cachedAPStreams.get(t.pageIndex));const s=n.get(t.id);s&&s.release(),this.cachedAPStreams=this.cachedAPStreams.setIn([t.pageIndex,t.id],e)}clearAllPageAPStreams(e){const t=this.cachedAPStreams.get(e);t&&(t.forEach((e=>e.release())),this.cachedAPStreams=this.cachedAPStreams.delete(e)),this.pageAPStreamsPromises=this.pageAPStreamsPromises.delete(e)}clearPageAPStreams(e,t){const n=this.cachedAPStreams.get(e);n&&(n.filter(((e,n)=>t.has(n))).forEach((e=>e.release())),this.cachedAPStreams=this.cachedAPStreams.updateIn([e],(e=>e.filter(((e,n)=>!t.has(n))))))}}},638:function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var s=n(140),i=n(4),a=n(3),r=n(274);function o(e){return Object(a.k)(Array.isArray(e),"Wrong `json` field"),Object(i.a)(e.map((e=>(Object(a.k)("number"==typeof e.pageIndex,"Wrong `pageIndex` field"),Object(a.k)("string"==typeof e.previewText,"Wrong `previewText` field"),Object(a.k)(Array.isArray(e.rangeInPreview),"Wrong `rangeInPreview` field"),Object(a.k)(Array.isArray(e.rectsOnPage),"Wrong `rectsOnPage` field"),new r.a({pageIndex:e.pageIndex,previewText:e.previewText,locationInPreview:e.rangeInPreview[0],lengthInPreview:e.rangeInPreview[1],rectsOnPage:Object(i.a)(e.rectsOnPage).map((e=>Object(s.a)(e))),isAnnotation:!!e.isAnnotation,annotationRect:e.annotationRect?Object(s.a)(e.annotationRect):null})))).filter(Boolean))}},639:function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));var s=n(4),i=n(7);function a(){return!0}class r{constructor(e){this.queue=Object(s.c)(),this.priorityQueue=Object(s.c)(),this.inFlightRequests=Object(s.b)(),this.inflightRequestLimit=e,this.isDestroyed=!1}enqueue(e,t=!1){if(this.isDestroyed)return{promise:new Promise((()=>{})),cancel:()=>{}};let n=null,i=null;const a=new Promise(((e,t)=>{n=e,i=t})),r=t?this.priorityQueue:this.queue,o=Object(s.j)(r,e,{promise:a,resolve:n,reject:i});return t?this.priorityQueue=o:this.queue=o,t?this.next():setTimeout((()=>this.next()),35),{promise:a,cancel:()=>this._cancel(e)}}_cancel(e){this.queue.has(e)&&(this.queue=this.queue.delete(e)),this.priorityQueue.has(e)&&(this.priorityQueue=this.priorityQueue.delete(e)),this.inFlightRequests.has(e)&&(this.inFlightRequests=this.inFlightRequests.delete(e))}cancelAll(){this.queue=Object(s.c)(),this.priorityQueue=Object(s.c)(),this.inFlightRequests=Object(s.b)()}_requestFinished(e,t){if(this.isDestroyed)return;const n=this.inFlightRequests.get(e);n&&(n.resolve(t),this.inFlightRequests=this.inFlightRequests.delete(e)),this.next()}_requestFailed(e,t){if(this.isDestroyed)return;const n=this.inFlightRequests.get(e);n&&(n.reject(t),this.inFlightRequests=this.inFlightRequests.delete(e)),this.next()}next(){if(!(this.isDestroyed||this.inFlightRequests.size>=this.inflightRequestLimit)){if(this.priorityQueue.size>=1){const e=this.priorityQueue.findLastEntry(a);Object(i.a)(e);const[t,n]=e;return this.priorityQueue=this.priorityQueue.delete(t),this.inFlightRequests=this.inFlightRequests.set(t,n),void t.request().then((e=>this._requestFinished(t,e))).catch((e=>this._requestFailed(t,e)))}if(this.queue.size>=1){const e=this.queue.findEntry(a);Object(i.a)(e);const[t,n]=e;this.queue=this.queue.delete(t),this.inFlightRequests=this.inFlightRequests.set(t,n),t.request().then((e=>this._requestFinished(t,e))).catch((e=>this._requestFailed(t,e)))}}}destroy(){this.isDestroyed=!0}}},640:function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var s=n(1),i=n.n(s);function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,s)}return n}function r(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){i()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e,t,n,s,i,a){let o;return e.has(n)?o=e.get(n):(o=i.toString(),t[o]=n,e.set(n,o)),r(r({},s),{},{[a]:o})}},641:function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));const s={clientsPresenceEnabled:!0,listenToServerChangesEnabled:!0}},724:function(e,t,n){"use strict";n.r(t),n.d(t,"default",(function(){return U}));var s=n(70),i=n.n(s),a=n(1),r=n.n(a),o=n(3);var c=n(2),u=n(337),d=n(155),h=n(18),l=n(192),p=n(4),m=n(9),f=n(638),g=n(140),b=n(42),P=n(288);var w=n(367),y=n(639),S=n(139);class _ extends(p.e({authPayload:null,serverUrl:null,documentId:null,backendPermissions:null,documentURL:null,imageToken:null,instantSettings:null,token:null,features:Object(p.a)(),signatureFeatureAvailability:S.a.NONE,isFormsEnabled:!0,minSearchQueryLength:1,documentHandle:null,isDocumentHandleOutdated:!1,digitalSignatures:null,defaultGroup:void 0,hasCollaborationPermissions:!1,forceLegacySignaturesFeature:!1})){}var v=n(221),O=n(130),j=n(251);const R="The image can not be rendered because of an unknown error.";class A{constructor({identifier:e,url:t,token:n,payload:s,doNotRequestWebP:i=!1}){this.identifier=e,this.url=t,this.token=n,this.payload=s,this.doNotRequestWebP=i}abort(){this.httpRequest&&this.httpRequest.abort()}request(){return new Promise(((e,t)=>{const n=new XMLHttpRequest;this.httpRequest=n,n.open(this.payload?"POST":"GET",this.url,!0),n.setRequestHeader("X-PSPDFKit-Image-Token",this.token),O.c&&!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 s=new FileReader;return s.onload=n=>{var s;const i=JSON.parse(null===(s=n.target)||void 0===s?void 0:s.result);i.attachments_not_found?e({attachmentsNotFound:i.attachments_not_found}):i.error?t(new o.a(`The server could not render the requested image (${i.error})`)):t(new o.a(R))},s.onerror=()=>t(new o.a(R)),void s.readAsText(n.response)}if(!Object(v.a)(n.status))return void t(new o.a(R));const s=n.response,i=URL.createObjectURL(s),a=new Image;a.onerror=()=>t(new o.a(R)),a.src=i;const r="function"==typeof a.decode?a.decode():new Promise((e=>setTimeout(e,200)));await r,e(new j.a(a,(()=>URL.revokeObjectURL(i))))}).bind(this),n.send(this.payload)}))}}var F=n(76),k=n(640),q=n(641),$=n(323),I=n(157),D=n(637),x=n(7);function T(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,s)}return n}function E(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?T(Object(n),!0).forEach((function(t){r()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):T(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}class U extends D.a{constructor(e,t=window){super(e),r()(this,"_password",null),r()(this,"type","SERVER"),r()(this,"_requestRenderAnnotation",((e,t,n,s,i,a)=>{const r=`${this._state.documentURL}/render_annotation`,c=`render-annotation-${a?Object(F.a)():e.id}`,u=JSON.stringify({data:Object(b.o)(e),width:s,height:i,detached:a||void 0,formFieldValue:t?Object(b.s)(t):void 0});let d,h,l=!1,p=[];const f=new Promise(((e,t)=>{d=e,h=t})),g=(t=[])=>{const a=new FormData;a.append("render",u),t.length>0&&e.imageAttachmentId&&n&&n.data&&a.append(e.imageAttachmentId,n.data);const f=new A({identifier:c,url:r,token:this._state.imageToken,payload:a,doNotRequestWebP:s>m.E||i>m.E}),b=this._requestQueue.enqueue(f,!1);b.promise.then((e=>{l||(e.attachmentsNotFound?g(e.attachmentsNotFound):e.attachmentsNotFound?h(new o.a("Attachment could not be found.")):d(e))})).catch((e=>{l||h(e)})),p.push(b)};return g(),{promise:f,cancel:()=>{l=!0,p.forEach((e=>e.cancel()))}}})),r()(this,"handleDocumentHandleConflict",(()=>{this._state=this._state.set("isDocumentHandleOutdated",!0),this.cancelRequests(),this._destroyProvider()}));const n=e.serverUrl||Object(d.a)(t.document);if("/"!==n.substr(-1))throw new o.a("`serverUrl` must have a slash at the end (e.g. `https://pspdfkit.example.com/`).");if(!e.serverUrl){if(n===`${t.location.protocol}//${t.location.host}/`)throw new o.a('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});')}if("string"!=typeof e.documentId)throw new o.a("`documentId` must be of type string.");if("object"!=typeof e.authPayload||"string"!=typeof e.authPayload.jwt)throw new o.a("authPayload must be an object that contains the `jwt`. For example: `authPayload: { jwt: 'xxx.xxx.xxx'}`");!function(e){const t="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!==e.indexOf('{"internal":'))return;let n;Object(o.k)("string"==typeof e&&3===e.split(".").length,t);try{const t=P.Base64.decode(e.split(".")[1]);n=JSON.parse(t)}catch(e){throw new o.a(t)}Object(o.k)("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/")}(e.authPayload.jwt),function(e){let t="";if("boolean"!=typeof e&&(Object(o.l)(e)?(e.hasOwnProperty("clientsPresenceEnabled")&&"boolean"!=typeof e.clientsPresenceEnabled&&(t+="`clientsPresenceEnabled` in instance settings is not valid. Must be `true` or `false`.\n"),e.hasOwnProperty("listenToServerChangesEnabled")&&"boolean"!=typeof e.listenToServerChangesEnabled&&(t+="`listenToServerChangesEnabled` in instance settings is not valid. Must be `true` or `false`.\n")):t="`instant` flag must either be set to `true` or `false`\n",t))throw new o.a(`${t}\nFor more information about PSPDFKit Instant please visit:\nhttps://pspdfkit.com/guides/web/current/instant/overview/`)}(e.instant);let s=null;if(e.instant)if(Object(o.l)(e.instant)){const t=e.instant;s={clientsPresenceEnabled:!1!==t.clientsPresenceEnabled,listenToServerChangesEnabled:!1!==t.listenToServerChangesEnabled}}else s=q.a;this._requestQueue=new y.a(m.C);const i=!!e.electronicSignatures&&Boolean(e.electronicSignatures.forceLegacySignaturesFeature);this._state=new _({serverUrl:n,documentId:e.documentId,instantSettings:s,documentURL:`${n}i/d/${e.documentId}`,authPayload:e.authPayload,isFormsEnabled:!e.disableForms,forceLegacySignaturesFeature:i}),e.trustedCAsCallback&&Object(o.p)("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 e=this._state.instantSettings;return null!=e&&!1!==e.clientsPresenceEnabled}async load(e={}){const{imageToken:t,token:n,permissions:s,features:i,signatureFeatureAvailability:a,hasPassword:r,minSearchQueryLength:u,layerHandle:d,allowedTileScales:h,digitalSignatures:l,defaultGroup:m,collaborationPermissions:f,creatorName:g}=await async function(e,t,n){const s=await fetch(`${e}/auth`,{method:"POST",headers:{"Content-Type":"application/json","PSPDFKit-Platform":"web","PSPDFKit-Version":"protocol=4, client=2021.4.1, client-git=960843e0b3"},body:JSON.stringify({jwt:t.jwt,origin:window.location.href,password:n}),credentials:"include"});return s.ok?s.json():s.text().then((e=>{throw"INVALID_PASSWORD"===e?new o.a(e):new o.a(`An error occurred while connecting to PSPDFKit Server: ${e||s.statusText}`)}))}(`${this._state.serverUrl}i/d/${this._state.documentId}`,this._state.authPayload,e.password);if(this._password=e.password,this._state.instantSettings&&!i.includes(c.z.INSTANT))throw new o.a("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 P=a===S.a.ELECTRONIC_SIGNATURES&&i.includes(c.z.WEB_ANNOTATION_EDITING)&&this._state.forceLegacySignaturesFeature?S.a.LEGACY_SIGNATURES:a;if(this._state=this._state.withMutations((e=>e.set("imageToken",t).set("token",n).set("features",Object(p.a)(i)).set("signatureFeatureAvailability",P).set("backendPermissions",new c.c({readOnly:-1===s.indexOf("write"),downloadingAllowed:s.indexOf("download")>=0})).set("documentURL",`${this._state.serverUrl}i/d/${this._state.documentId}/h/${d}`).set("documentHandle",d).set("isDocumentHandleOutdated",!1).set("digitalSignatures",Object(b.g)(l)))),f&&!this._state.instantSettings)throw new o.a("Collaboration Permissions is not supported when `instant` is disabled. Please make sure `configuration#instant` is set to `true`.");return this._state=this._state.withMutations((e=>{e.defaultGroup=m,e.hasCollaborationPermissions=Boolean(f)})),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:r,minSearchQueryLength:u,allowedTileScales:h,jsActionChanges:[],creatorName:g,defaultGroup:m}}async _initProvider(){if(this._state.instantSettings){const e=`${this._state.serverUrl}i/d/${this._state.documentId}/h/${this._state.documentHandle}`,{InstantProvider:t}=await n.e(60).then(n.bind(null,722));return new t(`${this._state.serverUrl}i/d/${this._state.documentId}`,e,{auth_token:this._state.token},this._state.instantSettings)}{const e=this._state.isFormsEnabled&&this._state.features.includes(c.z.FORMS),{RESTProvider:t}=await n.e(61).then(n.bind(null,725));return new t(this._state.documentURL,{token:this._state.token},{isFormsEnabled:e})}}destroy(){this._destroyProvider(),this._requestQueue&&this._requestQueue.destroy()}documentInfo(){return this._fetch(`${this._state.documentURL}/document.json`).then((e=>e.json())).then((e=>(e.data.totalPages=e.data.pageCount,e.data)))}getFormJSON(){return this._fetch(`${this._state.documentURL}/form.json`).then((e=>403===e.status?{v:1,type:"pspdfkit/form",annotations:[],fields:[]}:e.json().then((e=>e.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(e){const t=`${this._state.documentURL}/page-${e}-text`,n=new(this._getJSONRequestHandler())(t,this._state.token),s=this._requestQueue.enqueue(n,!0);return{promise:s.promise.then((t=>Object(l.b)(t,e))),cancel:()=>{s.cancel()}}}getTextFromRects(e,t){const n=encodeURIComponent(JSON.stringify(t.map(g.b).toArray()));return this._fetch(`${this._state.documentURL}/page-${e}-highlighted?rects=${n}`).then((e=>e.json())).then((e=>e.text))}_getJSONRequestHandler(){return w.a}renderTile(e,t,n,s,i){if(this._state.isDocumentHandleOutdated)return{promise:new Promise((()=>{})),cancel:()=>{}};const a=`${this._state.documentURL}/page-${e}-dimensions-${t.width}-${t.height}-tile-${n.left}-${n.top}-${n.width}-${n.height}${s?"-print":""}`,r=t.width===n.width&&t.height===n.height,c=n.width>m.E||n.height>m.E;let u,d,l=!1,p=!1,f=[],g=[];const P=new Promise(((e,t)=>{u=e,d=t})),w=(e=[])=>{let t;if(i){const n=new FormData;n.append("data",JSON.stringify({annotations:i.annotations.filter(h.u).map(b.o).toJS().map((e=>({content:e}))),formFieldValues:i.formFieldValues.map(b.s).toJS(),formFields:i.formFields.map(b.r).toJS(),signatures:i.signatures||[]})),e.length>0&&e.forEach((e=>{const t=i.attachments.get(e);Object(x.a)(t&&t.data,"Attachment data could not be found."),n.append(e,t.data)})),t=new A({identifier:a,url:a,token:this._state.imageToken,payload:n,doNotRequestWebP:c})}else t=new A({identifier:a,url:a,token:this._state.imageToken,doNotRequestWebP:c});g.push(t);const n=this._requestQueue.enqueue(t,r);n.promise.then((e=>{if(!l)return e.attachmentsNotFound&&!p?(p=!0,void w(e.attachmentsNotFound)):void(e.attachmentsNotFound?d(new o.a("Attachment could not be found.")):u(e))})).catch((e=>{l||d(e)})),f.push(n)};return w(),{promise:P,cancel:()=>{l=!0,g.forEach((e=>{e.abort&&"function"==typeof e.abort&&e.abort()})),f.forEach((e=>e.cancel()))}}}renderAnnotation(e,t,n,s,i){return this._requestRenderAnnotation(e,t,n,s,i)}renderPageAnnotations(e){const t=Promise.resolve();return this.pageAPStreamsPromises=this.pageAPStreamsPromises.set(e,t),t}renderDetachedAnnotation(e,t,n,s){return this._requestRenderAnnotation(e,null,t,n,s,!0)}async getAttachment(e){try{const t=await this._fetch(`${this._state.documentURL}/attachments/${e}`);switch(t.status){case 404:throw new o.a("Attachment not Found.");case 200:return await t.blob();default:throw new o.a("Bad Request.")}}catch(e){throw new o.a(`Could not fetch attachment from PSPDFKit Server. ${e}`)}}async search(e,t,n,s,i=!1,a=I.a.TEXT){const r=`q=${a===I.a.PRESET?e.replace(/_/g,"-"):encodeURIComponent(e)}&start=${t}&limit=${n}&type=${a}&include_annotations=${i.toString()}&case_sensitive=${s.toString()}`,o=`${this._state.documentURL}/search?${r}`,c=await new w.a(o,this._state.token).request();return Object(f.a)(c.data)}async searchAndRedact(e,t){const{searchType:n,annotationPreset:s,searchInAnnotations:a,caseSensitive:r}=t,{color:o,fillColor:c,outlineColor:u}=s,d=i()(s,["color","fillColor","outlineColor"]),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===I.a.PRESET?e.replace(/_/g,"-"):e,includeAnnotations:a,caseSensitive:r},content:E(E({},d),{},{color:o&&o.toHex(),fillColor:c&&c.toHex(),outlineColor:u&&u.toHex()})})}),{data:l}=await h.json();return Object(p.a)(l&&l.annotations?l.annotations.map((e=>$.a.fromJSON(e.id,e.content))):[])}exportPDF({flatten:e=!1,includeComments:t=!0}={}){const n=`${this._state.documentURL}/pdf?token=${this._state.token}&flatten=${String(e)}&comments=${String(t)}&render_ap_streams=${String(!e)}`;return fetch(n,{method:"GET",credentials:"include"}).then((e=>e.arrayBuffer()))}exportXFDF(){return this._fetch(`${this._state.documentURL}/document.xfdf`).then((e=>e.text()))}exportInstantJSON(){return this._fetch(`${this._state.documentURL}/instant.json`).then((e=>e.json()))}getPDFURL({includeComments:e=!0}={}){return{promise:Promise.resolve(`${this._state.documentURL}/pdf?token=${this._state.token}&flatten=true&comments=${String(e)}`),revoke:()=>{}}}generatePDFObjectURL({includeComments:e=!0}={}){let t,n=!1;return{promise:new Promise((s=>{this.exportPDF({flatten:!0,includeComments:e}).then((e=>{if(n)return;const i=new Blob([e],{type:"application/pdf"});t=window.URL.createObjectURL(i),s(t)}))})),revoke:()=>{t&&window.URL.revokeObjectURL(t),n=!0}}}async getDocumentOutline(){let e;try{e=(await this._fetch(`${this._state.documentURL}/outline.json`).then((e=>e.json()))).data}catch(t){e={}}const t=Array.isArray(e.outline)?e.outline:[];return Object(p.a)(t.map(u.a))}onKeystrokeEvent(){throw new Error("not implemented")}async applyOperationsAndReload(e){try{const t=await L(e);this._destroyProvider(),await this._fetch(`${this._state.documentURL}/apply-operations`,{method:"post",body:t,credentials:"include"})}catch(e){throw new o.a(`Applying operations failed: ${e}`)}return this.reloadDocument()}async applyRedactionsAndReload(){try{return this._destroyProvider(),await this._fetch(`${this._state.documentURL}/redact`,{method:"post",credentials:"include"}),this.reloadDocument()}catch(e){throw this.provider.load(),new o.a(`Applying redactions failed: ${e}`)}}async reloadDocument(){try{return await this.load({password:this._password})}catch(e){throw new o.a(`Reloading the document failed: ${e}`)}}async exportPDFWithOperations(e){try{const t=await L(e);return this._fetch(`${this._state.documentURL}/pdf-with-operations`,{method:"post",body:t,credentials:"include"}).then((e=>e.arrayBuffer()))}catch(e){throw new o.a(`Exporting PDF with operations failed: ${e}`)}}async getSignaturesInfo(){return this._refreshSignaturesInfoPromise&&await this._refreshSignaturesInfoPromise,this._state.digitalSignatures}refreshSignaturesInfo(){return this._refreshSignaturesInfoPromise||(this._refreshSignaturesInfoPromise=new Promise(((e,t)=>{this._fetch(`${this._state.documentURL}/signatures`,{method:"get",credentials:"include"}).then((e=>e.json())).then((({data:t})=>{this._state=this._state.set("digitalSignatures",Object(b.g)(t)),this._refreshSignaturesInfoPromise=null,e()})).catch((e=>{this._state=this._state.set("digitalSignatures",null),this._refreshSignaturesInfoPromise=null,t(e)}))}))),this._refreshSignaturesInfoPromise}async signDocumentAndReload(e,t){try{if(void 0!==t&&"object"!=typeof t)throw new o.a("Signing service data must be an object if specified.");const n={};e&&"placeholderSize"in e&&(n.signerDataSource={estimatedSize:e.placeholderSize}),e&&"flatten"in e&&(n.flatten=e.flatten);const s=E(E({},t?{signingToken:t.signingToken}:null),n);this._destroyProvider(),await this._fetch(`${this._state.documentURL}/sign`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(s),credentials:"include"}),await this.reloadDocument()}catch(e){throw this.provider.load(),new o.a(`Adding digital signature failed: ${e.message||e}`)}}getDocumentHandle(){return this._state.documentHandle}cancelRequests(){this._requestQueue.cancelAll()}_destroyProvider(){this.provider&&(this.provider._clients&&this.provider._clients.disconnect(),this.provider.destroy())}async _fetch(e,t){const n=await fetch(e,E(E({},t),{},{headers:E(E({},t&&t.headers),{},{"X-PSPDFKit-Token":this._state.token,"PSPDFKit-Platform":"web","PSPDFKit-Version":"protocol=4, client=2021.4.1, client-git=960843e0b3"})}));if(!n.ok){let e=await function(e){return e.clone().json().catch((()=>e.text()))}(n);e="object"==typeof e?e.reason:e;const t=e||`${n.status} ${n.statusText}`;throw new o.a(t)}return n}syncChanges(){return this.provider.syncChanges()}async clearAPStreamCache(){}}async function L(e){const t={},n=new WeakMap,s=await Promise.all(e.map((async(e,s)=>{if("importDocument"===e.type){const i=e.document;return Object(x.a)(i instanceof File||i instanceof Blob,"Wrong `importDocument` operation `document` value: it must be a File or a Blob"),Object(k.a)(n,t,i,e,s,"document")}if("applyInstantJson"===e.type){const i=e.instantJson;Object(x.a)("object"==typeof i&&null!==i,"Wrong `applyInstantJson` operation `instantJson` value: it must be an object");const a=JSON.stringify(i),r=new Blob([a],{type:"application/json"});return Object(k.a)(n,t,r,e,s,"dataFilePath")}if("applyXfdf"===e.type){const i=e.xfdf;Object(x.a)("string"==typeof i,"Wrong `applyXfdf` operation `xfdf` value: it must be a string");const a=new Blob([i],{type:"application/vnd.adobe.xfdf"});return Object(k.a)(n,t,a,e,s,"dataFilePath")}return e}))),i=new FormData;i.append("operations",JSON.stringify({operations:s}));for(const e in t)i.append(e,t[e]);return i}}}]);