/*!
 * PSPDFKit for Web 2019.2.0 (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.__PSPDFKitChunk=window.__PSPDFKitChunk||[]).push([[3],{794:function(e,t){},795:function(e,t,n){"use strict";n.d(t,"a",function(){return o});var r=n(127),i=n(6),s=n(4),a=n(247);function o(e){return Object(s.h)(Array.isArray(e),"Wrong `json` field"),Object(i.a)(e.map(function(e){if(Object(s.h)("number"==typeof e.pageIndex,"Wrong `pageIndex` field"),Object(s.h)("string"==typeof e.previewText,"Wrong `previewText` field"),Object(s.h)(Array.isArray(e.rangeInPreview),"Wrong `rangeInPreview` field"),Object(s.h)(Array.isArray(e.rectsOnPage),"Wrong `rectsOnPage` field"),!e.isAnnotation)return new a.a({pageIndex:e.pageIndex,previewText:e.previewText,locationInPreview:e.rangeInPreview[0],lengthInPreview:e.rangeInPreview[1],rectsOnPage:Object(i.a)(e.rectsOnPage).map(function(e){return Object(r.a)(e)})})}).filter(Boolean))}},796:function(e,t,n){"use strict";var r=n(5),i=n.n(r),s=n(10),a=n.n(s),o=n(6),u=(n(419),n(4)),c=n(8),h=n.n(c),d=n(7),f=n.n(d),l=n(9),p=n.n(l),v=function(e){function t(){return i()(this,t),h()(this,f()(t).apply(this,arguments))}return p()(t,e),t}(Object(o.e)({request:null,promises:Object(o.a)()}));n.d(t,"a",function(){return m});var m=function(){function e(t){i()(this,e),this.queue=Object(o.c)(),this.priorityQueue=Object(o.c)(),this.inFlightRequests=Object(o.b)(),this.inflightRequestLimit=t,this.isDestroyed=!1}return a()(e,[{key:"enqueue",value:function(e){var t,n,r=this,i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.isDestroyed)return new Promise(function(){});var s=new Promise(function(e,r){t=e,n=r});if(this.inFlightRequests.has(e.identifier))return this.inFlightRequests=this.inFlightRequests.updateIn([e.identifier,"promises"],function(e){return e.push({promise:s,resolve:t,reject:n})}),s;var a=!1;if(this.queue.has(e.identifier)?(i=!1,a=!0):this.priorityQueue.has(e.identifier)&&(i=!0,a=!0),a){var u=(i?this.priorityQueue:this.queue).updateIn([e.identifier,"promises"],function(e){return e.push({promise:s,resolve:t,reject:n})});return i?this.priorityQueue=u:this.queue=u,s}var c=function(){var a=(i?r.priorityQueue:r.queue).set(e.identifier,new v({request:e,promises:Object(o.a)([{promise:s,resolve:t,reject:n}])}));i?r.priorityQueue=a:r.queue=a,r.next()};return i?c():setTimeout(c,35),s}},{key:"cancel",value:function(e,t){if(this.queue.has(e)){var n=this.queue.get(e).promises.findIndex(function(e){return e.promise===t});this.queue=this.queue.deleteIn([e,"promises",n]),0===this.queue.get(e).promises.size&&(this.queue=this.queue.delete(e))}if(this.priorityQueue.has(e)){var r=this.priorityQueue.get(e).promises.findIndex(function(e){return e.promise===t});this.priorityQueue=this.priorityQueue.deleteIn([e,"promises",r]),0===this.priorityQueue.get(e).promises.size&&(this.priorityQueue=this.priorityQueue.delete(e))}if(this.inFlightRequests.has(e)){var i=this.inFlightRequests.get(e).promises.findIndex(function(e){return e.promise===t});this.inFlightRequests=this.inFlightRequests.deleteIn([e,"promises",i])}}},{key:"requestFinished",value:function(e,t){if(!this.isDestroyed){var n=this.inFlightRequests.get(e);Object(u.h)(n),n.promises.forEach(function(e){return e.resolve(t)}),this.inFlightRequests=this.inFlightRequests.delete(e),this.next()}}},{key:"requestFailed",value:function(e,t){if(!this.isDestroyed&&this.inFlightRequests.has(e)){var n=this.inFlightRequests.get(e);Object(u.h)(n),n.promises.forEach(function(e){return e.reject(t)}),this.inFlightRequests=this.inFlightRequests.delete(e),this.next()}}},{key:"next",value:function(){var e=this;if(!(this.isDestroyed||this.inFlightRequests.size>=this.inflightRequestLimit)){if(this.priorityQueue.size>=1){var t=this.priorityQueue.last();Object(u.h)(t);var n=t.request.identifier;return this.priorityQueue=this.priorityQueue.delete(n),this.inFlightRequests=this.inFlightRequests.set(n,t),void t.request.request().then(function(t){return e.requestFinished(n,t)}).catch(function(t){return e.requestFailed(n,t)})}if(this.queue.size>=1){var r=this.queue.first();Object(u.h)(r);var i=r.request.identifier;return this.queue=this.queue.delete(i),this.inFlightRequests=this.inFlightRequests.set(i,r),void r.request.request().then(function(t){return e.requestFinished(i,t)}).catch(function(t){return e.requestFailed(i,t)})}}}},{key:"destroy",value:function(){this.isDestroyed=!0}}]),e}()},830:function(e,t,n){"use strict";n.r(t);var r=n(16),i=n.n(r),s=n(22),a=n.n(s),o=n(27),u=n.n(o),c=n(5),h=n.n(c),d=n(10),f=n.n(d),l=n(1),p=n.n(l),v=n(4);function m(e,t,n){return g.apply(this,arguments)}function g(){return(g=a()(i.a.mark(function e(t,n,r){var s;return i.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch("".concat(t,"/auth"),{method:"POST",headers:{"Content-Type":"application/json","PSPDFKit-Platform":"web","PSPDFKit-Version":"protocol=".concat(3,", client=").concat("2019.2.0",", client-git=").concat("69b430e3ae")},body:JSON.stringify({jwt:n.jwt,origin:window.location.href,password:r}),credentials:"include"});case 2:if(!(s=e.sent).ok){e.next=7;break}return e.abrupt("return",s.json());case 7:return e.abrupt("return",s.text().then(function(e){throw"INVALID_PASSWORD"===e?new v.a(e):new v.a("An error ocurred while connecting to PSPDFKit Server: ".concat(e||s.statusText))}));case 8:case"end":return e.stop()}},e)}))).apply(this,arguments)}n(794);var w=n(2),y=n(18),b=n(299),k=n(126),P=n(21),q=n(144),_=n(6),F=n(14),R=n(795),x=n(127),j=n(37);n(419);var O=n(189),I=function(){function e(t,n){h()(this,e),this.identifier=this.url=t,this.token=n}return f()(e,[{key:"request",value:function(){var e=this;return new Promise(function(t,n){var r=new Image;r.onload=function(){return t(new O.a(r,function(){}))},r.onerror=function(){return n()},r.src=e.url})}}]),e}(),S=n(368),U=n(796),D=n(8),T=n.n(D),L=n(7),A=n.n(L),Q=n(9),N=n.n(Q),J=(n(213),function(e){function t(){return h()(this,t),T()(this,A()(t).apply(this,arguments))}return N()(t,e),t}(Object(_.e)({authPayload:null,serverUrl:null,documentId:null,backendPermissions:null,documentURL:null,imageToken:null,syncProvider:null,instantProvider:null,token:null,features:Object(_.a)(),isFormsEnabled:!0}))),K=n(369),E=n(130),W="The image can not be rendered because of an unknown error.",C=function(){function e(t,n,r,i){h()(this,e),this.identifier=t,this.url=n,this.token=r,this.payload=i}return f()(e,[{key:"request",value:function(){var e=this;return new Promise(function(t,n){var r=new XMLHttpRequest;r.open(e.payload?"POST":"GET",e.url,!0),r.setRequestHeader("X-PSPDFKit-Image-Token",e.token),E.b&&r.setRequestHeader("Accept","image/webp,*/*"),r.responseType="blob",r.onreadystatechange=function(){if(4===r.readyState){if("application/json"===r.response.type){var e=new FileReader;return e.onload=function(e){var r=JSON.parse(e.target.result);r.attachments_not_found?t({attachmentsNotFound:r.attachments_not_found}):r.error?n(new v.a("The server could not render the requested image (".concat(r.error,")"))):n(new v.a(W))},e.onerror=function(){return n(new v.a(W))},void e.readAsText(r.response)}if(Object(K.a)(r.status)){var i=r.response,s=URL.createObjectURL(i),a=new Image;a.onload=function(){var e=new O.a(a,function(){return URL.revokeObjectURL(s)});t(e)},a.onerror=function(){return n(new v.a(W))},a.src=s}else n(new v.a(W))}}.bind(e),r.send(e.payload)})}}]),e}(),H=n(97);n.d(t,"default",function(){return V});var V=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window;h()(this,e),p()(this,"type","SERVER"),p()(this,"_requestRenderAnnotation",function(e,t,r,i,s){var a,o,u="".concat(n._state.documentURL,"/render_annotation"),c="render-annotation-".concat(s?Object(H.a)():e.id),h=JSON.stringify({data:Object(j.i)(e),width:r,height:i,detached:s||void 0}),d=!1,f=[],l=new Promise(function(e,t){a=e,o=t});return function r(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],s=new FormData;s.append("render",h),i.length>0&&e.imageAttachmentId&&t&&t.data&&s.append(e.imageAttachmentId,t.data);var l=new C(c,u,n._state.imageToken,s),p=n._requestQueue.enqueue(l,!1);p.then(function(e){d||(e.attachmentsNotFound?r(e.attachmentsNotFound):e.attachmentsNotFound?o(new v.a("Attachment could not be found.")):a(e))}).catch(function(e){d||o(e)}),f.push(p)}(),{promise:l,cancel:function(){d=!0,f.forEach(function(e){return n._requestQueue.cancel(c,e)})}}});var i=t.serverUrl||Object(k.a)(r.document);if("/"!==i.substr(-1))throw new v.a("`serverUrl` must have a slash at the end (e.g. `https://pspdfkit.example.com/`).");if(!t.serverUrl&&i==="".concat(r.location.protocol,"//").concat(r.location.host,"/"))throw new v.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 t.documentId)throw new v.a("`documentId` must be of type string.");if("object"!==u()(t.authPayload)||"string"!=typeof t.authPayload.jwt)throw new v.a("authPayload must be an object that contains the `jwt`. For example: `authPayload: { jwt: 'xxx.xxx.xxx'}`");if(function(e){var 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":')){var n;Object(v.h)("string"==typeof e&&3===e.split(".").length,t);try{n=JSON.parse(atob(e.split(".")[1]))}catch(e){throw new v.a(t)}Object(v.h)("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),"boolean"!=typeof t.instant)throw new v.a("`instant` flag must either be set to `true` or `false`.\n\nFor more information about PSPDFKit Instant please visit:\nhttps://pspdfkit.com/guides/web/current/instant/overview/");this._requestQueue=new U.a(F.y),this._state=new J({serverUrl:i,documentId:t.documentId,instantProvider:Boolean(t.instant),documentURL:"".concat(i,"i/d/").concat(t.documentId),authPayload:t.authPayload,isFormsEnabled:!t.disableForms})}return f()(e,[{key:"isUsingInstantProvider",value:function(){return this._state.instantProvider}},{key:"load",value:function(){var e=a()(i.a.mark(function e(t){var n,r,s,a,o,u;return i.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,m(this._state.documentURL,this._state.authPayload,t);case 2:if(n=e.sent,r=n.imageToken,s=n.token,a=n.permissions,o=n.features,u=n.hasPassword,!this._state.instantProvider||o.includes("instant")){e.next=10;break}throw new v.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/");case 10:return this._state=this._state.withMutations(function(e){return e.set("imageToken",r).set("token",s).set("features",Object(_.a)(o)).set("backendPermissions",new w.c({readOnly:-1===a.indexOf("write"),downloadingAllowed:a.indexOf("download")>=0}))}),e.next=13,this._initProvider();case 13:return this.provider=e.sent,e.abrupt("return",{features:this._state.features,hasPassword:u});case 15:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_initProvider",value:function(){var e=a()(i.a.mark(function e(){var t,r,s,a,o,u;return i.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._state.instantProvider){e.next=9;break}return t="".concat(this._state.serverUrl,"i/d/").concat(this._state.documentId),e.next=4,Promise.resolve().then(n.bind(null,418));case 4:return r=e.sent,s=r.InstantProvider,e.abrupt("return",new s(t,{auth_token:this._state.token}));case 9:return a=this._state.isFormsEnabled&&this._state.features.includes("acro_forms"),e.next=12,n.e(5).then(n.bind(null,831));case 12:return o=e.sent,u=o.RESTProvider,e.abrupt("return",new u(this._state.documentURL,{token:this._state.token},{isFormsEnabled:a}));case 15:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"destroy",value:function(){this.provider&&this.provider.destroy(),this._requestQueue&&this._requestQueue.destroy()}},{key:"documentInfo",value:function(){return this._fetch("".concat(this._state.documentURL,"/document.json")).then(function(e){return e.json()}).then(function(e){return e.totalPages=e.pageCount,e})}},{key:"getFormJSON",value:function(){return this._fetch("".concat(this._state.documentURL,"/form.json")).then(function(e){return 403===e.status?{v:1,type:"pspdfkit/form",annotations:[],fields:[]}:e.json().then(function(e){return e.data})})}},{key:"permissions",value:function(){return Promise.resolve(this._state.backendPermissions)}},{key:"textForPageIndex",value:function(e){var t=this,n="".concat(this._state.documentURL,"/page-").concat(e,"-text"),r=new(this._getJSONRequestHandler())(n,this._state.token),i=this._requestQueue.enqueue(r,!0).then(function(t){return Object(q.b)(t,e)});return{promise:i,cancel:function(){t._requestQueue.cancel(n,i)}}}},{key:"getTextFromRects",value:function(e,t){var n=encodeURIComponent(JSON.stringify(t.map(x.b).toArray()));return this._fetch("".concat(this._state.documentURL,"/page-").concat(e,"-highlighted?rects=").concat(n)).then(function(e){return e.json()}).then(function(e){return e.text})}},{key:"_getJSONRequestHandler",value:function(){return S.a}},{key:"renderTile",value:function(e,t,n,r,i){var s,a,o=this,u="".concat(this._state.documentURL,"/page-").concat(e,"-dimensions-").concat(t.width,"-").concat(t.height,"-tile-").concat(n.left,"-").concat(n.top,"-").concat(n.width,"-").concat(n.height).concat(r?"-print":""),c=t.width===n.width&&t.height===n.height,h=!1,d=!1,f=[],l=new Promise(function(e,t){s=e,a=t});return function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(i){var r=new FormData;r.append("data",JSON.stringify({annotations:i.annotations.filter(P.n).map(j.i).toJS().map(function(e){return{content:e}}),formFieldValues:i.formFieldValues.map(j.k).toJS(),formFields:i.formFields.map(j.j).toJS()})),n.length>0&&n.forEach(function(e){var t=i.attachments.get(e);Object(v.h)(t&&t.data,"Attachment data could not be found."),r.append(e,t.data)}),t=new C(u,u,o._state.imageToken,r)}else t=new(o._getImageRequestHandler())(u,u,o._state.imageToken);var l=o._requestQueue.enqueue(t,c);l.then(function(t){if(!h)return t.attachmentsNotFound&&!d?(d=!0,void e(t.attachmentsNotFound)):void(t.attachmentsNotFound?a(new v.a("Attachment could not be found.")):s(t))}).catch(function(e){h||a(e)}),f.push(l)}(),{promise:l,cancel:function(){h=!0,f.forEach(function(e){return o._requestQueue.cancel(u,e)})}}}},{key:"renderAnnotation",value:function(e,t,n,r){return this._requestRenderAnnotation(e,t,n,r)}},{key:"renderDetachedAnnotation",value:function(e,t,n,r){return this._requestRenderAnnotation(e,t,n,r,!0)}},{key:"getAttachment",value:function(){var e=a()(i.a.mark(function e(t){var n;return i.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._fetch("".concat(this._state.documentURL,"/attachments/").concat(t));case 3:n=e.sent,e.t0=n.status,e.next=404===e.t0?7:200===e.t0?8:11;break;case 7:throw new v.a("Attachment not Found.");case 8:return e.next=10,n.blob();case 10:return e.abrupt("return",e.sent);case 11:throw new v.a("Bad Request.");case 12:e.next=17;break;case 14:throw e.prev=14,e.t1=e.catch(0),new v.a("Could not fetch attachment from PSPDFKit Server. ".concat(e.t1));case 17:case"end":return e.stop()}},e,this,[[0,14]])}));return function(t){return e.apply(this,arguments)}}()},{key:"_getImageRequestHandler",value:function(){return"blink"===y.a&&y.b<60||"gecko"===y.a?I:C}},{key:"search",value:function(e,t,n){var r,i,s="q=".concat(encodeURIComponent(e))+"&start=".concat(t)+"&limit=".concat(n),a="".concat(this._state.documentURL,"/search?").concat(s),o=new S.a(a,this._state.token),u=o.request(),c=!1,h=new Promise(function(e,t){r=e,i=t});return u.then(function(e){var t=e.data;return Object(R.a)(t)}).then(function(e){c||r(e)}).catch(function(e){c||i(e)}),{promise:h,cancel:function(){c=!0,o.abort()}}}},{key:"exportPDF",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t="".concat(this._state.serverUrl,"i/d/").concat(this._state.documentId,"/pdf?token=").concat(this._state.token,"&flatten=").concat(String(e));return fetch(t,{method:"GET",credentials:"include"}).then(function(e){return e.arrayBuffer()})}},{key:"exportXFDF",value:function(){return this._fetch("".concat(this._state.documentURL,"/document.xfdf")).then(function(e){return e.text()})}},{key:"exportInstantJSON",value:function(){return this._fetch("".concat(this._state.documentURL,"/instant.json")).then(function(e){return e.json()})}},{key:"getPDFURL",value:function(){return{promise:Promise.resolve("".concat(this._state.serverUrl,"i/d/").concat(this._state.documentId,"/pdf?token=").concat(this._state.token,"&flatten=true")),revoke:function(){}}}},{key:"generatePDFObjectURL",value:function(){var e,t=this,n=!1;return{promise:new Promise(function(r){t.exportPDF().then(function(t){if(!n){var i=new Blob([t],{type:"application/pdf"});e=window.URL.createObjectURL(i),r(e)}})}),revoke:function(){e&&window.URL.revokeObjectURL(e),n=!0}}}},{key:"getDocumentOutline",value:function(){var e=a()(i.a.mark(function e(){var t,n,r;return i.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._fetch("".concat(this._state.documentURL,"/outline.json")).then(function(e){return e.json()});case 3:n=e.sent,t=n.data,e.next=10;break;case 7:e.prev=7,e.t0=e.catch(0),t={};case 10:return r=Array.isArray(t.outline)?t.outline:[],e.abrupt("return",Object(_.a)(r.map(b.a)));case 12:case"end":return e.stop()}},e,this,[[0,7]])}));return function(){return e.apply(this,arguments)}}()},{key:"_fetch",value:function(e){return fetch(e,{headers:{"X-PSPDFKit-Token":this._state.token,"PSPDFKit-Platform":"web","PSPDFKit-Version":"protocol=".concat(3,", client=").concat("2019.2.0",", client-git=").concat("69b430e3ae")}})}}]),e}()}}]);