UNPKG

@hmcts/annotation-ui-lib

Version:

PDF Viewer and ability to highlight text with and comment tracking

2 lines 49.7 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/forms"),require("uuid"),require("@angular/common"),require("@ng-toolkit/universal"),require("@angular/core"),require("@angular/common/http"),require("rxjs"),require("@angular/platform-browser"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@hmcts/annotation-ui-lib",["exports","@angular/forms","uuid","@angular/common","@ng-toolkit/universal","@angular/core","@angular/common/http","rxjs","@angular/platform-browser","rxjs/operators"],e):e((t.hmcts=t.hmcts||{},t.hmcts["annotation-ui-lib"]={}),t.ng.forms,t.uuid,t.ng.common,t.universal,t.ng.core,t.ng.common.http,t.rxjs,t.ng.platformBrowser,t.rxjs.operators)}(this,function(t,e,c,a,n,s,r,p,u,l){"use strict";function i(e,a,s,c){return new(s||(s=Promise))(function(t,n){function o(t){try{r(c.next(t))}catch(e){n(e)}}function i(t){try{r(c["throw"](t))}catch(e){n(e)}}function r(e){e.done?t(e.value):new s(function(t){t(e.value)}).then(o,i)}r((c=c.apply(e,a||[])).next())})}function d(o,i){var r,a,s,t,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return t={next:e(0),"throw":e(1),"return":e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function n(t){if(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,a&&(s=2&t[0]?a["return"]:t[0]?a["throw"]||((s=a["return"])&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,s&&(t=[2&t[0],s.value]),t[0]){case 0:case 1:s=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,a=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){c.label=t[1];break}if(6===t[0]&&c.label<s[1]){c.label=s[1],s=t;break}if(s&&c.label<s[2]){c.label=s[2],c.ops.push(t);break}s[2]&&c.ops.pop(),c.trys.pop();continue}t=i.call(o,c)}catch(e){t=[6,e],a=0}finally{r=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([e,t])}}}var m=function U(t,e,n,o,i,r,a,s,c){this.id=t,this.annotationId=e,this.createdBy=n,this.createdByDetails=o,this.createdDate=i,this.lastModifiedBy=r,this.lastModifiedByDetails=a,this.lastModifiedDate=s,this.content=c},h=function _(t,e,n,o,i,r,a,s,c,p,u,l,d,m){this.id=t,this.annotationSetId=e,this.createdBy=n,this.createdDate=o,this.createdByDetails=i,this.lastModifiedBy=r,this.lastModifiedByDetails=a,this.lastModifiedDate=s,this.documentId=c,this.page=p,this.color=u,this.comments=l,this.rectangles=d,this.type=m},o=function(){function t(){}return t.prototype.createPage=function(t){return PDFAnnotate.UI.createPage(t)},t.prototype.renderPage=function(t,e){return PDFAnnotate.UI.renderPage(t,e)},t.prototype.enableRect=function(t){PDFAnnotate.UI.enableRect(t)},t.prototype.disableRect=function(){PDFAnnotate.UI.disableRect()},t.prototype.setStoreAdapter=function(t){t?PDFAnnotate.setStoreAdapter(t):PDFAnnotate.setStoreAdapter(new PDFAnnotate.LocalStoreAdapter)},t.prototype.getStoreAdapter=function(){return PDFAnnotate.getStoreAdapter()},t.prototype.getUi=function(){return PDFAnnotate.UI},t}(),f=function(){function t(){}return t.prototype.setClass=function(t){this.loggingClass=t},t.prototype.error=function(t){this.buildLog("error-"+JSON.stringify(t))},t.prototype.info=function(t){this.buildLog("info-"+JSON.stringify(t))},t.prototype.buildLog=function(t){console.log(this.loggingClass+"-"+t)},t.decorators=[{type:s.Injectable}],t}(),g=function(){function t(t,e){this.log=t,this.pdfAnnotateWrapper=e,t.setClass("PdfService")}return t.prototype.preRun=function(){this.pageNumber=new p.BehaviorSubject(1)},t.prototype.getAnnotationWrapper=function(){return this.annotationWrapper},t.prototype.setAnnotationWrapper=function(t){this.annotationWrapper=t},t.prototype.getPageNumber=function(){return this.pageNumber},t.prototype.setPageNumber=function(t){this.pageNumber.next(t)},t.prototype.setHighlightTool=function(){this.log.info("Highlight cursor is enabled"),this.pdfAnnotateWrapper.enableRect("highlight")},t.prototype.setCursorTool=function(){this.pdfAnnotateWrapper.disableRect()},t.decorators=[{type:s.Injectable}],t.ctorParameters=function(){return[{type:f},{type:o}]},t}(),y=function(){function t(){}return t.prototype.buildLineRectangle=function(t){this.sortByY(t);var e=t[0].y,n=t[0].height;this.sortByX(t);var o=t[0].x;return{y:e,x:o,width:t[t.length-1].x-o+t[t.length-1].width,height:n}},t.prototype.generateRectanglePerLine=function(t,e){this.sortByY(t);var n=t[t.length-1].y,o=t[0].y,i=this.getAnnotationLineHeight(t);if(this.difference(n,o)>i){var r=t.filter(function(t){return t.y<=o+i}),a=t.filter(function(t){return t.y>o+i});e.push(this.buildLineRectangle(r)),this.generateRectanglePerLine(a,e)}else e.push(this.buildLineRectangle(t))},t.prototype.getAnnotationLineHeight=function(t){return t[0].height},t.prototype.sortByY=function(t,i){void 0===i&&(i=!0),t.sort(function(t,e){var n=t.y,o=e.y;return n<o?i?-1:1:o<n?i?1:-1:0})},t.prototype.sortByX=function(t,i){void 0===i&&(i=!0),t.sort(function(t,e){var n=t.x,o=e.x;return n<o?i?-1:1:o<n?i?1:-1:0})},t.prototype.sortByLinePosition=function(t,e){return this.sortByX(t),this.sortByX(e),t[0].x>e[0].x?1:-1},t.prototype.difference=function(t,e){return Math.abs(t-e)},t.prototype.clickIsHighlight=function(t){var e=t.target.firstElementChild;return null!=e&&!!e.id.includes("pdf-annotate-screenreader")},t.prototype.getClickedPage=function(t){for(var e=t.target,n=0;n<5;n++)if(null!=e.parentNode){var o=e.parentNode.getAttribute("data-page-number");if(null!=o)return parseInt(o,null);e=e.parentNode}},t}(),v=function(){function t(t,e,n){this.log=t,this.utils=e,this.window=n,this.annotationChangeSubject=new p.Subject,t.setClass("PdfAdapter")}return t.prototype.getAnnotationChangeSubject=function(){return this.annotationChangeSubject},t.prototype.setStoreData=function(t){var e=this;this.annotationSet=t,this.annotations=t.annotations,this.commentData=[],this.annotations.forEach(function(t){t.comments.forEach(function(t){e.commentData.push(t)})}),this.annotationSetId=t.id},t.prototype.editComment=function(n){var o=this;this.annotations.forEach(function(e){e.comments.filter(function(t){return t.id===n.id}).map(function(t){o.log.info("Editing comment:"+n.id),t.content=n.content,o.annotationChangeSubject.next({type:"editComment",annotation:e})})})},t.prototype.updateComments=function(t,e){this.commentData.push(e)},t.prototype._getAnnotations=function(t){return this.annotations||[]},t.prototype._getComments=function(t){return this.commentData||[]},t.prototype.clearSelection=function(){var t=this.window.getSelection();t&&(t.removeAllRanges?t.removeAllRanges():t.empty&&t.empty())},t.prototype.isDraftComment=function(t){return null===t.content||""===t.content},t.prototype.getStoreAdapter=function(){var s=this;return{getAnnotations:function(o,i){return new Promise(function(t,e){var n=s._getAnnotations(o).filter(function(t){return t.page===i});t({documentId:o,pageNumber:i,annotations:n})})},getComments:function(n,o){return new Promise(function(t,e){t(s._getComments(n).filter(function(t){return t.annotationId===o}))})},getAnnotation:function(n,o){return new Promise(function(t,e){t(s._getAnnotations(n).find(function(t){return t.id===o}))})},addAnnotation:function(i,r,a){return new Promise(function(t,e){s.clearSelection();var n=new h;n.id=c.v4(),n.page=r,n.color=a.color,n.type=a.type,n.comments=[],n.annotationSetId=s.annotationSetId;var o=[];s.log.info("Generating efficient rectangles for new annotation:"+n.id),s.utils.generateRectanglePerLine(a.rectangles,o),o.forEach(function(t){t.id=c.v4()}),n.rectangles=o,s._getAnnotations(i).push(n),s.log.info("Added annotation:"+a.id),s.annotationChangeSubject.next({type:"addAnnotation",annotation:n}),t(n)})},editAnnotation:function(t,e,n){return new Promise(function(t,e){s.annotationChangeSubject.next({type:"editAnnotation",annotation:n}),t(s.commentData)})},deleteAnnotation:function(t,o){return new Promise(function(t,e){var n=s.findById(s.annotations,o);s.remove(s.annotations,o),s.log.info("Deleted annotation:"+o),s.annotationChangeSubject.next({type:"deleteAnnotation",annotation:n}),t(s.annotations)})},addComment:function(i,r,a){return new Promise(function(t,e){var n=new m(c.v4(),r,null,null,new Date,null,null,null,a);s.updateComments(i,n);var o=s.findById(s.annotations,r);s.log.info("Comment:"+n.id+" has been added to annotation:"+r),o.comments.push(n),s.isDraftComment(n)?s.log.info("Removing comment box because no content exists"):(s.log.info("Add comment:"+n.id+"-annotationId:"+o.id),s.annotationChangeSubject.next({type:"addComment",annotation:o})),t(n)})},deleteComment:function(t,i){return new Promise(function(t,e){var n=s.findById(s.commentData,i),o=s.findById(s.annotations,n.annotationId);s.remove(s.commentData,i),s.remove(o.comments,i),s.isDraftComment(n)?(s.log.info("Removing comment box because no content exists"),t(n)):(s.log.info("Deleted comment:"+i+"-annotationId:"+o.id),s.annotationChangeSubject.next({type:"deleteComment",annotation:o}),t(s.annotations))})}}},t.prototype.findById=function(t,e){return t.find(function(t){return t.id===e})},t.prototype.remove=function(t,e){return t.splice(t.findIndex(function(t){return t.id===e}),1)},t.decorators=[{type:s.Injectable}],t.ctorParameters=function(){return[{type:f},{type:y},{type:undefined,decorators:[{type:s.Inject,args:[n.WINDOW]}]}]},t}(),b=function(){function t(t,e,n,o){this.log=t,this.httpClient=e,this.platformId=n,this.transferState=o,t.setClass("ApiHttpService")}return t.prototype.setBaseUrl=function(t){this.baseUrl=t},t.prototype.getBaseUrl=function(){return this.baseUrl},t.prototype.createAnnotationSet=function(t,e){return this.httpClient.post(t+"/em-anno/annotation-sets",e,{observe:"response"})},t.prototype.fetch=function(t,e){var n=this,o=u.makeStateKey("annotationSet-"+e);if(this.transferState.hasKey(o)){var i=this.transferState.get(o,null);return this.transferState.remove(o),p.of(i)}var r=t+"/em-anno/annotation-sets/"+e;return this.httpClient.get(r,{observe:"response"}).pipe(l.tap(function(t){a.isPlatformServer(n.platformId)&&n.transferState.set(o,t)}))},t.prototype.documentTask=function(t,e,n){var o=n+"/api/em-npa/document-tasks",i={inputDocumentId:t,outputDocumentId:e};return this.log.info("Calling NPA service-"+t),this.httpClient.post(o,i,{observe:"response"})},t.prototype.deleteAnnotation=function(t){var e=this.baseUrl+"/em-anno/annotations/"+t.id;return this.httpClient["delete"](e,{observe:"response"})},t.prototype.saveAnnotation=function(t){var e=this.baseUrl+"/em-anno/annotations";return this.httpClient.post(e,t,{observe:"response"})},t.decorators=[{type:s.Injectable}],t.ctorParameters=function(){return[{type:f},{type:r.HttpClient},{type:undefined,decorators:[{type:s.Inject,args:[s.PLATFORM_ID]}]},{type:u.TransferState}]},t}(),S=function(){function t(){}return t.prototype.getDocument=function(t){return PDFJS.getDocument(t)},t}(),C=function M(t,e){this.pageNumber=t,this.pageDom=e},w=function(){function t(t,e,n){this.pdfWrapper=t,this.log=e,this.pdfAnnotateWrapper=n,this.listPages=[],this.log.setClass("PdfRenderService"),this.dataLoadedSubject=new p.BehaviorSubject(!1),this.listPagesSubject=new p.Subject}return t.prototype.getDataLoadedSub=function(){return this.dataLoadedSubject},t.prototype.dataLoadedUpdate=function(t){this.dataLoadedSubject.next(t)},t.prototype.getRenderOptions=function(){return Object.assign({},this.RENDER_OPTIONS)},t.prototype.setRenderOptions=function(t){this.RENDER_OPTIONS=t},t.prototype.getViewerElementRef=function(){return this.viewerElementRef},t.prototype.getPdfPages=function(){return this.pdfPages},t.prototype.render=function(t){var r=this;null!=t&&(this.viewerElementRef=t);var a=this.getRenderOptions();this.pdfWrapper.getDocument(a.documentId).then(function(o){a.pdfDocument=o;var i=r.viewerElementRef.nativeElement;i.innerHTML="",r.pdfPages=o.pdfInfo.numPages,r.listPages=[];for(var t=function(e){var t=r.pdfAnnotateWrapper.createPage(e),n=Object.assign({},a);i.appendChild(t),r.addDomPage(t,e),o.getPage(e).then(function(t){n.rotate=r.addPageRotation(a,n,t),setTimeout(function(){r.pdfAnnotateWrapper.renderPage(e,n).then(function(){e===r.pdfPages&&(r.setRenderOptions(a),r.dataLoadedUpdate(!0),r.listPagesSubject.next(r.listPages))})})})},e=1;e<r.pdfPages+1;e++)t(e)})["catch"](function(t){var e=new Error("Unable to render your supplied PDF. "+a.documentId+". Error is: "+t);r.log.error("Encountered error while rendering the PDF:"+e)})},t.prototype.addDomPage=function(t,e){var n=new C(e,t),o=this.listPages.findIndex(function(t){return t.pageNumber===e});0<o?this.listPages[o]=n:this.listPages.push(n)},t.prototype.addPageRotation=function(t,e,n){var o=this.getPageRotation(e,n);return o||(t.rotationPages.push({page:n.pageNumber,rotate:n.rotate}),o=n.rotate),o},t.prototype.getPageRotation=function(t,e){return t.rotationPages.filter(function(t){return t.page===e.pageNumber}).map(function(t){return t.rotate})[0]},t.decorators=[{type:s.Injectable}],t.ctorParameters=function(){return[{type:S},{type:f},{type:o}]},t}(),A=function(){function t(t,e,n,o,i,r){var a=this;this.log=t,this.pdfAdapter=e,this.apiHttpService=n,this.pdfService=o,this.pdfAnnotateWrapper=i,this.pdfRenderService=r,t.setClass("AnnotationStoreService"),this.commentBtnSubject=new p.Subject,this.commentFocusSubject=new p.BehaviorSubject({annotation:new h(null,null,null,null,null,null,null,null,null,null,null,null)}),this.contextualToolBarOptions=new p.Subject,this.annotationFocusSubject=new p.Subject,this.annotationChangeSubscription=this.pdfAdapter.getAnnotationChangeSubject().subscribe(function(t){return a.handleAnnotationEvent(t)})}return t.prototype.getAnnotationFocusSubject=function(){return this.annotationFocusSubject},t.prototype.setAnnotationFocusSubject=function(t){this.annotationFocusSubject.next(t)},t.prototype.getCommentFocusSubject=function(){return this.commentFocusSubject},t.prototype.setCommentFocusSubject=function(t,e){this.commentFocusSubject.next({annotation:t,showButton:e})},t.prototype.getCommentBtnSubject=function(){return this.commentBtnSubject},t.prototype.setCommentBtnSubject=function(t){this.commentBtnSubject.next(t)},t.prototype.setToolBarUpdate=function(t,e){var n={annotation:t,showDelete:e};this.contextualToolBarOptions.next(n)},t.prototype.getToolbarUpdate=function(){return this.contextualToolBarOptions},t.prototype.preLoad=function(t){null!=t?(this.pdfAdapter.setStoreData(t),this.pdfAnnotateWrapper.setStoreAdapter(this.pdfAdapter.getStoreAdapter()),this.pdfService.setHighlightTool()):(this.pdfService.setCursorTool(),this.pdfAnnotateWrapper.setStoreAdapter())},t.prototype.handleAnnotationEvent=function(t){switch(t.type){case"addAnnotation":this.saveAnnotation(t.annotation);break;case"addComment":case"editComment":this.saveAnnotation(t.annotation,t.type);break;case"deleteComment":case"editAnnotation":this.saveAnnotation(t.annotation);break;case"deleteAnnotation":this.deleteAnnotation(t.annotation)}},t.prototype.getAnnotationSet=function(n,o){var i=this;return this.apiHttpService.fetch(n,o).pipe(l.catchError(function(t){if(t instanceof r.HttpErrorResponse)switch(t.status){case 400:return i.log.error("Bad request: "+t.error),p.throwError(t.error);case 404:var e={documentId:o,id:c.v4()};return i.log.info("Creating new annotation set for document id:"+o),i.apiHttpService.createAnnotationSet(n,e);case 500:return i.log.error("Internal server error: "+t),p.throwError("Internal server error: "+t)}}))},t.prototype.saveData=function(){var t,e,n,o=this;t=this.pdfAdapter.annotationSet,e=this.pdfAdapter.annotations,n=this.pdfAdapter.annotationSet.annotations.filter(function(t){return!o.pdfAdapter.annotations.map(function(t){return t.id}).includes(t.id)}),e.forEach(function(e){o.apiHttpService.saveAnnotation(e).subscribe(function(t){return o.log.info("Successfully saved annotation:"+t)},function(t){return o.log.error("There has been a problem saving the annotation:"+e.id+"-"+t)})}),n.forEach(function(e){o.apiHttpService.deleteAnnotation(e).subscribe(function(t){return o.log.info("Successfully deleted annotation:"+t)},function(t){return o.log.error("There has been a problem deleting annotation:"+e.id+"-"+t)})}),t.annotations.splice(0,t.annotations.length),t.annotations.concat(e),this.pdfAdapter.annotationSet=t},t.prototype.saveAnnotation=function(e,n){var o=this;this.apiHttpService.saveAnnotation(e).subscribe(function(t){"addComment"!==n&&"editComment"!==n||(o.pdfAdapter.annotationSet.annotations[o.pdfAdapter.annotationSet.annotations.findIndex(function(t){return t.id===e.id})]=t.body),o.log.info("Successfully saved annotation:"+t)},function(t){return o.log.error("There has been a problem saving the annotation:"+e.id+"-"+t)})},t.prototype.deleteAnnotation=function(e){var n=this;this.apiHttpService.deleteAnnotation(e).subscribe(function(t){n.log.info("Successfully deleted annotation:"+e.id+"-"+t)},function(t){return n.log.error("There has been a problem deleting annotation:"+e.id+"-"+t)})},t.prototype.editComment=function(t){this.pdfAdapter.editComment(t)},t.prototype.getAnnotationById=function(t){var n=this;return new Promise(function(e){n.getAnnotation(t,function(t){e(t)})})},t.prototype.getAnnotationsForPage=function(t){var n=this;return new Promise(function(e){n.getAnnotations(t,function(t){e(t)})})},t.prototype.getCommentsForAnnotation=function(t){var n=this;return new Promise(function(e){n.getComments(t,function(t){e(t)})})},t.prototype.getAnnotation=function(t,e){this.pdfAnnotateWrapper.getStoreAdapter().getAnnotation(this.pdfRenderService.getRenderOptions().documentId,t).then(e)},t.prototype.getComments=function(t,e){this.pdfAnnotateWrapper.getStoreAdapter().getComments(this.pdfRenderService.getRenderOptions().documentId,t).then(e)},t.prototype.addComment=function(t){this.pdfAnnotateWrapper.getStoreAdapter().addComment(this.pdfRenderService.getRenderOptions().documentId,t.annotationId,t.content).then()},t.prototype.getAnnotations=function(t,e){this.pdfAnnotateWrapper.getStoreAdapter().getAnnotations(this.pdfRenderService.getRenderOptions().documentId,t).then(e)},t.prototype.deleteComment=function(t){this.pdfAnnotateWrapper.getStoreAdapter().deleteComment(this.pdfRenderService.getRenderOptions().documentId,t).then()},t.prototype.deleteAnnotationById=function(n,o){return i(this,void 0,void 0,function(){var e;return d(this,function(t){switch(t.label){case 0:return e=this.pdfRenderService.getRenderOptions(),[4,this.pdfAnnotateWrapper.getStoreAdapter().deleteAnnotation(e.documentId,n)];case 1:return t.sent(),this.renderPage(e,o),[2]}})})},t.prototype.renderPage=function(t,e){t.rotate=this.pdfRenderService.getPageRotation(t,{pageNumber:e}),this.pdfAnnotateWrapper.renderPage(e,t)},t.prototype.ngOnDestroy=function(){this.annotationChangeSubscription&&this.annotationChangeSubscription.unsubscribe()},t.decorators=[{type:s.Injectable}],t.ctorParameters=function(){return[{type:f},{type:v},{type:b},{type:g},{type:o},{type:w}]},t}(),x=function(){function t(t,e,n,o,i){this.annotationStoreService=t,this.pdfService=e,this.utils=n,this.pdfRenderService=o,this.log=i,this.log.setClass("CommentsComponent")}return t.prototype.ngOnInit=function(){var e=this;this.dataLoadedSub=this.pdfRenderService.getDataLoadedSub().subscribe(function(t){t&&(e.showAllComments(),e.preRun())})},t.prototype.redrawCommentItemComponents=function(){var n=this;setTimeout(function(){var e;n.sortCommentItemComponents().forEach(function(t){e=n.isOverlapping(t,e)})})},t.prototype.sortCommentItemComponents=function(){var n=this;return this.commentItems.map(function(t){return t}).sort(function(t,e){return n.processSort(t,e)})},t.prototype.processSort=function(t,e){if(this.isAnnotationOnSameLine(t,e)){if(t.annotationLeftPos<e.annotationLeftPos)return-1;if(t.annotationLeftPos>=e.annotationLeftPos)return 1}return t.annotationTopPos<e.annotationTopPos?-1:t.annotationTopPos>=e.annotationTopPos?1:0},t.prototype.isAnnotationOnSameLine=function(t,e){var n=t.annotationHeight>=e.annotationHeight?t.annotationHeight:e.annotationHeight;return!(this.utils.difference(t.annotationTopPos,e.annotationTopPos)>n)},t.prototype.isOverlapping=function(t,e){if(t.commentTopPos=t.annotationTopPos,e){var n=e.commentTopPos+e.commentHeight;t.commentTopPos<=n&&(t.commentTopPos=n)}return t},t.prototype.ngOnDestroy=function(){this.pageNumSub&&this.pageNumSub.unsubscribe(),this.dataLoadedSub&&this.dataLoadedSub.unsubscribe()},t.prototype.preRun=function(){var e=this;this.pageNumSub=this.pdfService.getPageNumber().subscribe(function(t){e.pageNumber=t})},t.prototype.showAllComments=function(){var e=this;this.annotations=[];for(var t=0;t<this.pdfRenderService.getPdfPages()+1;t++)this.annotationStoreService.getAnnotationsForPage(t).then(function(t){e.annotations=e.annotations.concat(t.annotations.slice())})},t.prototype.handleAnnotationBlur=function(){this.showAllComments()},t.prototype.handleAnnotationClick=function(t){var e=this,n=t.getAttribute("data-pdf-annotate-id");this.annotationStoreService.getAnnotationById(n).then(function(t){e.annotationStoreService.setAnnotationFocusSubject(t),e.annotationStoreService.setCommentFocusSubject(t),e.annotationStoreService.setToolBarUpdate(t,!0)})},t.decorators=[{type:s.Component,args:[{selector:"app-comments",template:'<div *ngIf="pageNumber" id="comment-wrapper">\n <div class="comment-list-container">\n\n <div *ngFor="let annotation of annotations" class="highlight-group">\n <app-comment-item #commentItem\n *ngFor="let comment of annotation.comments"\n [annotation]="annotation"\n [comment]="comment"\n (commentSubmitted)=\'showAllComments()\'\n (commentRendered)=\'redrawCommentItemComponents()\'\n ></app-comment-item>\n </div>\n </div>\n</div>\n',styles:["#comment-wrapper{position:absolute;height:100%;width:380px;right:0;overflow:hidden;z-index:0;font-family:nta,Arial,sans-serif;-webkit-font-smoothing:antialiased;font-size:12px}#comment-wrapper .comment-list{font-size:12px;position:absolute;top:38px;left:0;right:0;bottom:0}#comment-wrapper .comment-list-container{position:absolute;top:0;left:0;right:0;bottom:47px;overflow-x:hidden;overflow-y:auto}"]}]}],t.ctorParameters=function(){return[{type:A},{type:g},{type:y},{type:w},{type:f}]},t.propDecorators={commentItems:[{type:s.ViewChildren,args:["commentItem"]}]},t}(),P=function(){function t(t,e,n,o,i,r,a){this.annotationStoreService=t,this.pdfService=e,this.pdfRenderService=n,this.ref=o,this.renderer=i,this.utils=r,this.log=a,this.commentSubmitted=new s.EventEmitter,this.commentRendered=new s.EventEmitter,this.model=new m(null,null,null,null,null,null,null,null,null),this.log.setClass("CommentItemComponent")}return t.prototype.ngOnInit=function(){var e=this;this.hideButton=!0,this.focused=!1,this.sliceComment=this.comment.content,this.commentFocusSub=this.annotationStoreService.getCommentFocusSubject().subscribe(function(t){t.annotation.id===e.comment.annotationId?(t.showButton?e.onEdit():e.handleShowBtn(),e.ref.detectChanges()):e.onBlur()}),this.commentBtnSub=this.annotationStoreService.getCommentBtnSubject().subscribe(function(t){t===e.comment.id?e.handleShowBtn():e.handleHideBtn()}),this.dataLoadedSub=this.pdfRenderService.getDataLoadedSub().subscribe(function(t){t&&(e.annotationTopPos=e.getRelativePosition(e.comment.annotationId),e.commentTopPos=e.annotationTopPos,e.utils.sortByX(e.annotation.rectangles,!0),e.annotationHeight=e.utils.getAnnotationLineHeight(e.annotation.rectangles),e.annotationLeftPos=e.annotation.rectangles[0].x,e.commentRendered.emit(!0),e.collapseComment())}),this.commentItem.statusChanges.subscribe(function(){e.focused&&e.expandComment()})},t.prototype.setHeight=function(){this.renderer.setStyle(this.commentArea.nativeElement,"height","fit-content"),this.renderer.setStyle(this.commentArea.nativeElement,"height",this.commentArea.nativeElement.scrollHeight+"px"),this.commentHeight=this.commentSelector.nativeElement.getBoundingClientRect().height,this.commentRendered.emit(!0),this.ref.destroyed||this.ref.detectChanges()},t.prototype.ngOnDestroy=function(){this.commentFocusSub&&this.commentFocusSub.unsubscribe(),this.commentBtnSub&&this.commentBtnSub.unsubscribe(),this.dataLoadedSub&&this.dataLoadedSub.unsubscribe()},t.prototype.onSubmit=function(){var t=this.convertFormToComment(this.commentItem);this.annotationStoreService.editComment(t),this.commentSubmitted.emit(this.annotation),this.viewOnly()},t.prototype.onEdit=function(){this.editOnly()},t.prototype.onCancel=function(){this.renderer.setProperty(this.commentArea.nativeElement,"value",this.comment.content),this.viewOnly()},t.prototype.viewOnly=function(){this.renderer.addClass(this.commentArea.nativeElement,"view-mode"),this.focused=!1},t.prototype.editOnly=function(){this.focused=!0,this.renderer.removeClass(this.commentArea.nativeElement,"view-mode")},t.prototype.isModified=function(){return null!==this.comment.createdDate&&(null!==this.comment.lastModifiedBy&&this.comment.createdDate!==this.comment.lastModifiedDate)},t.prototype.onBlur=function(){this.ref.destroyed||this.ref.detectChanges()},t.prototype.convertFormToComment=function(t){return new m(this.comment.id,this.comment.annotationId,null,null,new Date,null,null,null,t.value.content)},t.prototype.handleDeleteComment=function(){this.annotationStoreService.deleteComment(this.comment.id)},t.prototype.handleCommentClick=function(t){t.stopPropagation(),this.annotationStoreService.setCommentBtnSubject(this.comment.id),this.annotationStoreService.setAnnotationFocusSubject(this.annotation)},t.prototype.handleShowBtn=function(){var e=this;new Promise(function(t){e.hideButton=!1,e.expandComment(),t("Success")}).then(function(){e.setHeight(),setTimeout(function(){e.commentArea.nativeElement.focus()})})},t.prototype.handleHideBtn=function(){var e=this;new Promise(function(t){e.commentItem.value.content||e.annotationStoreService.deleteComment(e.comment.id),e.focused=!1,e.hideButton=!0,e.collapseComment(),t("Success")}).then(function(){e.setHeight()})},t.prototype.collapseComment=function(){var e=this;new Promise(function(t){e.expandComment(),t("Success")}).then(function(){e.isCommentEmpty()||e.shrinkComment(),e.renderer.addClass(e.commentArea.nativeElement,"collapsed"),e.renderer.removeClass(e.commentArea.nativeElement,"expanded"),e.renderer.addClass(e.detailsWrapper.nativeElement,"collapsed"),e.renderer.addClass(e.commentArea.nativeElement,"view-mode"),e.setHeight()})},t.prototype.isCommentEmpty=function(){return null===this.comment.content},t.prototype.isShrinkable=function(){return 31<this.commentArea.nativeElement.scrollHeight},t.prototype.shrinkComment=function(){this.isShrinkable()&&(this.sliceComment=this.removeMultipleLines().slice(0,20)+"...")},t.prototype.removeMultipleLines=function(){return this.comment.content.split("\n").join(" ")},t.prototype.expandComment=function(){this.renderer.addClass(this.commentArea.nativeElement,"expanded"),this.renderer.removeClass(this.commentArea.nativeElement,"collapsed"),this.renderer.removeClass(this.detailsWrapper.nativeElement,"collapsed"),this.renderer.addClass(this.detailsWrapper.nativeElement,"expanded"),this.sliceComment=this.comment.content,this.setHeight()},t.prototype.getRelativePosition=function(t){var e=this.pdfRenderService.getViewerElementRef().nativeElement.querySelector('g[data-pdf-annotate-id="'+t+'"]');if(null===e)return null;var n=e.getBoundingClientRect(),o=this.pdfService.getAnnotationWrapper().nativeElement.getBoundingClientRect();return n.y-o.top},t.decorators=[{type:s.Component,args:[{selector:"app-comment-item",template:'<form class="aui-comment comment-list-item"\n (ngSubmit)="onSubmit()"\n #commentSelector\n #commentItem="ngForm"\n (click)="handleCommentClick($event)"\n [style.top.px]="commentTopPos">\n <div #detailsWrapper id="detailsWrapper" class="aui-comment__header">\n <span *ngIf="comment.createdByDetails" class="aui-comment__author">{{comment.createdByDetails.forename}} {{comment.createdByDetails.surname}}</span>\n <time #commentDate class="aui-comment__meta" ng-controller="datCtrl">{{ comment.createdDate | date: \'d MMMM y h:mm a\' }}</time>\n <div *ngIf="false">\n <span>modified By: {{comment.lastModifiedByDetails.forename}} {{comment.lastModifiedByDetails.surname}}</span>\n <time class="aui-comment__meta" ng-controller="datCtrl"><br>{{ comment.lastModifiedDate | date: \'d MMMM y h:mm a\' }}</time>\n </div>\n </div>\n\n <textarea\n #commentArea\n (blur)="onBlur()"\n type="text"\n [class.mimic-focus]="focused"\n class="aui-comment__content form-control mimic-focus view-mode"\n required\n [ngModel]="sliceComment" name="content"\n value="comment.content"\n [readonly]="!focused"></textarea>\n\n <div [hidden]="hideButton" class="aui-comment__footer commentBtns">\n <button *ngIf="focused" type="submit" class="govuk-button" role="button">Save</button>\n <button *ngIf="!focused" (click)="onEdit()" class="govuk-button" role="button">Edit</button>\n <button\n *ngIf="!focused"\n class="govuk-button hmcts hmcts-button--secondary"\n role="button"\n (click)="handleDeleteComment()">Delete</button>\n <button\n *ngIf="focused"\n class="govuk-button hmcts hmcts-button--secondary"\n role="button"\n (click)="onCancel()">Cancel</button>\n </div>\n</form>\n',styles:["form{width:95%;margin-bottom:5px;position:absolute;background-color:#fff;padding:20px 20px 0}form textarea{width:95%;padding:2px;border:none;font-size:17px;font-family:nta,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-weight:400;overflow:hidden;resize:none}.mimic-focus{outline-offset:-2px;outline:#0b0c0c auto 5px}textarea.view-mode:focus{outline:0}#detailsWrapper{padding:0}#detailsWrapper.expanded{margin-bottom:15px}.commentBtns{height:50px}.expanded{margin-top:0}.collapsed{height:30px}textarea.expanded{margin-bottom:10px}textarea.collapsed{margin-top:-25px;max-height:20px}.collapsed>time{display:none}"]}]}],t.ctorParameters=function(){return[{type:A},{type:g},{type:w},{type:s.ChangeDetectorRef},{type:s.Renderer2},{type:y},{type:f}]},t.propDecorators={comment:[{type:s.Input}],annotation:[{type:s.Input}],commentSubmitted:[{type:s.Output}],commentRendered:[{type:s.Output}],commentSelector:[{type:s.ViewChild,args:["commentSelector"]}],commentArea:[{type:s.ViewChild,args:["commentArea"]}],commentItem:[{type:s.ViewChild,args:["commentItem"]}],detailsWrapper:[{type:s.ViewChild,args:["detailsWrapper"]}],commentDate:[{type:s.ViewChild,args:["commentDate"]}]},t}(),I=function(){function t(t,e){this.log=t,this.apiHttpService=e,t.setClass("NpaService"),this.outputDmDocumentId=new p.Subject,this.documentTask=new p.Subject}return t.prototype.exportPdf=function(t,e,n){return this.log.info("Calling HTTP service for NPA"),this.apiHttpService.documentTask(t,e,n)},t.decorators=[{type:s.Injectable}],t.ctorParameters=function(){return[{type:f},{type:b}]},t}(),R=function V(t,e,n,o,i){this.documentId=t,this.pdfDocument=e,this.scale=n,this.rotate=o,this.rotationPages=i},D=function(){function t(t,e){this.pdfRenderService=t,this.log=e,this.rotationStyle={},this.viewerStyle={},this.log.setClass("RotationComponent")}return t.prototype.ngOnInit=function(){var t=""+document.getElementById("pageContainer"+this.pageNumber).querySelector(".textLayer").style.height;this.rotationStyle={"margin-top":"-"+t},this.viewerStyle={top:""+t}},t.prototype.calculateRotation=function(t){return(t%360+360)%360},t.prototype.onRotateClockwise=function(){var e=this,t=this.pdfRenderService.getRenderOptions(),n=t.rotationPages.find(function(t){return t.page===e.pageNumber}).rotate;t.rotationPages.find(function(t){return t.page===e.pageNumber}).rotate=this.calculateRotation(n+90),this.pdfRenderService.setRenderOptions(t),this.pdfRenderService.render()},t.decorators=[{type:s.Component,args:[{selector:"app-rotation-toolbar",template:'<div class="viewer-menu" [ngStyle]="viewerStyle">\n <button\n [ngStyle]="rotationStyle"\n class="govuk-button hmcts hmcts-button--secondary rotate"\n title="Clockwise"\n role="button"\n (click)="onRotateClockwise()">Rotate</button>\n</div>\n',styles:[".viewer-menu{width:100%;position:-webkit-sticky;position:sticky;left:0}.rotate{background-repeat:no-repeat;background-size:14px 14px;background-position:3px 50%;background-image:url(/assets/images/viewer-rotate.svg);padding-left:25px;float:right}"]}]}],t.ctorParameters=function(){return[{type:w},{type:f}]},t.propDecorators={pageNumber:[{type:s.Input}]},t}(),B=function(){function t(t,e,n,o){this.componentFactoryResolver=t,this.log=e,this.injector=n,this.appRef=o,this.log.setClass("RotationFactoryService")}return t.prototype.addToDom=function(t){this.log.info("Adding rotate button to PDF page "+t.pageNumber);var e=this.componentFactoryResolver.resolveComponentFactory(D).create(this.injector);e.instance.pageNumber=t.pageNumber,this.appRef.attachView(e.hostView);var n=e.hostView.rootNodes[0];return t.pageDom.appendChild(n),e},t.decorators=[{type:s.Injectable}],t.ctorParameters=function(){return[{type:s.ComponentFactoryResolver},{type:f},{type:s.Injector},{type:s.ApplicationRef}]},t}(),k=function(){function t(t,e,n,o,i,r,a,s,c,p,u){this.pdfService=t,this.npaService=e,this.apiHttpService=n,this.annotationStoreService=o,this.utils=i,this.ref=r,this.renderer=a,this.pdfAnnotateWrapper=s,this.pdfRenderService=c,this.rotationFactoryService=p,this.log=u,this.rotationComponents=[]}return t.prototype.ngOnInit=function(){var e=this;this.loadAnnotations(this.annotate),this.pdfService.preRun(),this.pdfRenderService.setRenderOptions(new R(this.url,null,parseFloat("1.33"),0,[])),this.rotate&&(this.pdfPageSubscription=this.pdfRenderService.listPagesSubject.subscribe(function(t){e.rotationComponents.forEach(function(t){return t.destroy()}),t.forEach(function(t){e.rotationComponents.push(e.rotationFactoryService.addToDom(t))})})),this.pdfRenderService.render(this.viewerElementRef),this.pdfService.setAnnotationWrapper(this.annotationWrapper),this.pageNumberSubscription=this.pdfService.getPageNumber().subscribe(function(t){return e.page=t}),this.focusedAnnotationSubscription=this.annotationStoreService.getAnnotationFocusSubject().subscribe(function(t){return e.focusHighlightStyle(t)})},t.prototype.ngAfterViewInit=function(){this.pdfAnnotateWrapper.getUi().addEventListener("annotation:click",this.handleAnnotationClick.bind(this))},t.prototype.ngOnDestroy=function(){this.pageNumberSubscription&&this.pageNumberSubscription.unsubscribe(),this.focusedAnnotationSubscription&&this.focusedAnnotationSubscription.unsubscribe(),this.pdfPageSubscription&&this.pdfPageSubscription.unsubscribe()},t.prototype.loadAnnotations=function(t){t?(this.log.info("annotations are enabled"),this.apiHttpService.setBaseUrl(this.baseUrl),this.annotationStoreService.preLoad(this.annotationSet),this.npaService.outputDmDocumentId.next(this.outputDmDocumentId)):(this.log.info("annotations are disabled"),this.annotationStoreService.preLoad(null))},t.prototype.handleClick=function(t,e){this.annotate&&(this.utils.clickIsHighlight(t)||(this.unfocusAnnotation(),this.annotationStoreService.setToolBarUpdate(null,null)),this.commentsComponent.handleAnnotationBlur(),e&&this.pdfService.setPageNumber(this.utils.getClickedPage(t)))},t.prototype.renderComments=function(){this.unfocusAnnotation(),this.commentsComponent.showAllComments()},t.prototype.unfocusAnnotation=function(){this.annotationStoreService.setAnnotationFocusSubject(new h),this.annotationStoreService.setCommentBtnSubject(null),this.annotationStoreService.setCommentFocusSubject(new h,null)},t.prototype.handleAnnotationClick=function(t){var e=this;if(!this.contextualToolbar.isShowToolbar){var n=t.getAttribute("data-pdf-annotate-id");this.annotationStoreService.getAnnotationById(n).then(function(t){e.annotationStoreService.setAnnotationFocusSubject(t),e.annotationStoreService.setCommentFocusSubject(t),e.annotationStoreService.setToolBarUpdate(t,!0)})}},t.prototype.focusHighlightStyle=function(e){var n=this;Array.from(this.viewerElementRef.nativeElement.querySelector("#pageContainer"+this.page+" .annotationLayer").childNodes).forEach(function(t){t.dataset.pdfAnnotateId===e.id?n.renderer.addClass(t,"comment-selected"):n.renderer.removeClass(t,"comment-selected")}),this.ref.destroyed||this.ref.detectChanges()},t.decorators=[{type:s.Component,args:[{selector:"app-annotation-pdf-viewer",template:'\n<app-comments (click)="handleClick($event, false)" #commentsComponent\n *ngIf="annotate"></app-comments>\n\n<div id="annotation-wrapper" #annotationWrapper>\n <app-contextual-toolbar (deletedAnnotation)="renderComments()" #contextualToolbar></app-contextual-toolbar>\n\n <div id="content-wrapper"\n #contentWrapper\n (click)="handleClick($event, true)">\n <div id="viewer" #viewer class="pdfViewer"></div>\n </div>\n</div>\n',styles:["#annotation-wrapper{position:relative;width:100%}#content-wrapper{overflow:hidden}"]}]}],t.ctorParameters=function(){return[{type:g},{type:I},{type:b},{type:A},{type:y},{type:s.ChangeDetectorRef},{type:s.Renderer2},{type:o},{type:w},{type:B},{type:f}]},t.propDecorators={annotate:[{type:s.Input}],dmDocumentId:[{type:s.Input}],outputDmDocumentId:[{type:s.Input}],url:[{type:s.Input}],annotationSet:[{type:s.Input}],baseUrl:[{type:s.Input}],rotate:[{type:s.Input}],contentWrapper:[{type:s.ViewChild,args:["contentWrapper"]}],viewerElementRef:[{type:s.ViewChild,args:["viewer"]}],annotationWrapper:[{type:s.ViewChild,args:["annotationWrapper"]}],commentsComponent:[{type:s.ViewChild,args:["commentsComponent"]}],contextualToolbar:[{type:s.ViewChild,args:["contextualToolbar"]}]},t}(),j=function(){function t(t,e,n,o,i){this.annotationStoreService=t,this.ref=e,this.pdfRenderService=n,this.pdfService=o,this.log=i,this.deletedAnnotation=new s.EventEmitter,this.log.setClass("ContextualToolbarComponent"),this.toolPos={left:0,top:0}}return t.prototype.ngOnInit=function(){var e=this;this.contextualToolBarOptions=this.annotationStoreService.getToolbarUpdate().subscribe(function(t){null!=t.annotation?e.showToolBar(t.annotation,t.showDelete):e.hideToolBar()}),this.isShowToolbar=!1},t.prototype.ngOnDestroy=function(){this.ref.detach(),this.contextualToolBarOptions&&this.contextualToolBarOptions.unsubscribe()},t.prototype.showToolBar=function(t,e){this.annotation=t,this.showDelete=e,this.toolPos=this.getRelativePosition(t.id),this.isShowToolbar=!0,this.ref.destroyed||this.ref.detectChanges()},t.prototype.getRelativePosition=function(t){var e=this.pdfRenderService.getViewerElementRef().nativeElement.querySelector('g[data-pdf-annotate-id="'+t+'"]').getBoundingClientRect(),n=this.pdfService.getAnnotationWrapper().nativeElement.getBoundingClientRect();return{left:e.x-n.left-175+e.width/2,top:e.y-n.top-59-5}},t.prototype.hideToolBar=function(){this.annotation=null,this.isShowToolbar=!1,this.showDelete=!1,this.ref.destroyed||this.ref.detectChanges()},t.prototype.handleCommentBtnClick=function(){var e=this;0===this.annotation.comments.length&&this.annotationStoreService.addComment(new m(null,this.annotation.id,null,null,null,null,null,null,null)),setTimeout(function(){var t=e.annotation;e.hideToolBar(),e.annotationStoreService.setCommentFocusSubject(t,!0)},10)},t.prototype.handleHighlightBtnClick=function(){this.hideToolBar()},t.prototype.handleDeleteBtnClick=function(){return i(this,void 0,void 0,function(){return d(this,function(t){switch(t.label){case 0:return[4,this.annotationStoreService.deleteAnnotationById(this.annotation.id,this.annotation.page)];case 1:return t.sent(),this.hideToolBar(),this.deletedAnnotation.emit("deleted annotation"),[2]}})})},t.decorators=[{type:s.Component,args:[{selector:"app-contextual-toolbar",template:'<div [hidden]="!isShowToolbar" class="toolbar"\n [style.left.px]="toolPos.left"\n [style.top.px]="toolPos.top">\n\n <button\n [hidden]="showDelete"\n type="button" class="aui__toolbar-button aui__toolbar-button--comments contextual-btn leftButton"\n title="Highlight"\n (click)="handleHighlightBtnClick()"\n ><span>Add Highlight</span></button>\n\n <button\n [hidden]="!showDelete"\n type="button"\n title="Delete" class="aui__toolbar-button aui__toolbar-button--comments contextual-btn leftButton"\n (click)="handleDeleteBtnClick()"\n ><span>Remove Highlight</span></button>\n\n <button type="button" title="Comment" class="aui__toolbar-button aui__toolbar-button--comments contextual-btn rightButton"\n (click)="handleCommentBtnClick()"\n ><span>Comment</span></button>\n\n\n <div class="arrow-down">\n <div class="inner-triangle"></div>\n </div>\n\n</div>\n',styles:[".toolbar{position:absolute;background-color:#fff;height:52px;width:350px;margin:0 auto;text-shadow:1px 1px 0 #fff;z-index:1;border:1px solid #c1c1c1;box-shadow:0 2px #c1c1c1}.toolbar .spacer{display:inline-block;border-left:1px solid #c1c1c1;height:34px;margin:0 5px -11px}.toolbar button span{margin-left:20px}.toolbar button{padding:0;margin-left:2.5%;margin-right:2.5%;margin-top:6px;height:40px;border:0}.toolbar button:hover{border:1px solid #000}.contextual-btn{font-size:16px;background:5px 50%/20px 20px no-repeat #fff}.rightButton{width:124px;background-image:url(/assets/images/icon-document-comments.svg)}.leftButton{background-image:url(/assets/images/annotate-highlight.svg);width:190px}.arrow-down{margin:53px auto 0;width:0;height:0;border-left:12px solid transparent;border-right:12px solid transparent;border-top:12px solid #c1c1c1}.inner-triangle{position:relative;top:-13px;left:-10px;width:0;height:0;border-left:10px solid transparent;border-right:10px solid transparent;border-top:10px solid #fff}"]}]}],t.ctorParameters=function(){return[{type:A},{type:s.ChangeDetectorRef},{type:w},{type:g},{type:f}]},t.propDecorators={deletedAnnotation:[{type:s.Output}]},t}(),T=function(){function t(t,e){this.renderer=t,this.log=e,this.log.setClass("ImageViewerComponent")}return t.prototype.ngOnInit=function(){this.rotation=0},t.prototype.onRotateClockwise=function(){this.rotation=this.rotation+90,this.rotateImage()},t.prototype.rotateImage=function(){this.log.info("rotating to-"+this.rotation+"degrees");var t,e;try{for(var n=function r(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}(["transform","-ms-transform","-o-transform","-moz-transform","-webkit-transform"]),o=n.next();!o.done;o=n.next()){var i=o.value;this.renderer.setStyle(this.img.nativeElement,i,"rotate("+this.rotation+"deg)")}}catch(a){t={error:a}}finally{try{o&&!o.done&&(e=n["return"])&&e.call(n)}finally{if(t)throw t.error}}},t.decorators=[{type:s.Component,args:[{selector:"app-image-viewer",template:'\n <div id="viewer-wrapper">\n <button\n *ngIf="rotate"\n class="govuk-button hmcts hmcts-button--secondary rotate"\n title="Clockwise"\n role="button"\n (click)="onRotateClockwise()">Rotate</button>\n\n <img #img *ngIf="url" data-hook="dm.viewer.img" [src]="url" />\n </div>',styles:["#viewer-wrapper{position:relative;width:100%}.rotate{z-index:1;position:absolute;right:0;background-repeat:no-repeat;background-size:14px 14px;background-position:3px 50%;padding-left:25px;background-image:url(/assets/images/viewer-rotate.svg)}.anti{right:24px;-webkit-transform:scaleX(-1);transform:scaleX(-1)}img{width:100%}"]}]}],t.ctorParameters=function(){return[{type:s.Renderer2},{type:f}]},t.propDecorators={url:[{type:s.Input}],originalUrl:[{type:s.Input}],rotate:[{type:s.Input}],img:[{type:s.ViewChild,args:["img"]}]},t}(),E=function(){function t(){}return t.prototype.ngOnInit=function(){},t.decorators=[{type:s.Component,args:[{selector:"app-unsupported-viewer",template:'<p data-hook="dm.viewer.unsupported">\n This file type is not supported. Please <a href="{{url}}">click here to download</a>.\n</p>\n',styles:[""]}]}],t.ctorParameters=function(){return[]},t.propDecorators={url:[{type:s.Input}],originalUrl:[{type:s.Input}]},t}(),F=function(){function t(){}return t.prototype.fixDm=function(t,e){return t.replace(/http.*\/documents\//,e+"/documents/")},t.decorators=[{type:s.Injectable}],t}(),O=function(){function c(t,e,n,o){this.componentFactoryResolver=t,this.annotationStoreService=e,this.urlFixer=n,this.log=o,this.log.setClass("ViewerFactoryService")}return c.determineComponent=function(t){return c.isImage(t)?T:E},c.isImage=function(t){return t.startsWith("image/")||"image"===t},c.isPdf=function(t){return"application/pdf"===t||"pdf"===t},c.prototype.getDocumentId=function(t){var e=t._links.self.href.split("/");return e[e.length-1]},c.prototype.buildComponent=function(t,e,n,o,i,r,a,s){return c.isPdf(e)&&r?(this.log.info("Selected pdf viewer with annotations enabled"),this.buildAnnotateUi(n,t,o,r,a,s)):c.isPdf(e)&&!r?(this.log.info("Selected pdf viewer with annotations disabled"),this.buildAnnotateUi(n,t,o,r,null,s)):c.isImage(e)?(this.log.info("Selected image viewer"),this.createComponent(T,t,i,n,s)):(this.log.info("Unsupported type for viewer"),this.createComponent(E,t,i,n))},c.prototype.buildAnnotateUi=function(t,e,n,o,i,r){e.clear();var a=this.componentFactoryResolver.resolveComponentFactory(k),s=e.createComponent(a);return s.instance.annotate=o,s.instance.annotationSet=i,s.instance.outputDmDocumentId=null,s.instance.baseUrl=n,s.instance.url=t,s.instance.rotate=r,s.instance},c.prototype.createComponent=function(t,e,n,o,i){var r=this.componentFactoryResolver.resolveComponentFactory(t);e.clear();var a=e.createComponent(r);return a.instance.originalUrl=n,a.instance.url=o,a.instance.rotate=i,a.instance},c.decorators=[{type:s.Injectable}],c.ctorParameters=function(){return[{type:s.ComponentFactoryResolver},{type:A},{type:F},{type:f}]},c}(),H=function(){function t(t){this.viewContainerRef=t}return t.decorators=[{type:s.Directive,args:[{selector:"[appViewerAnchor]"}]}],t.ctorParameters=function(){return[{type:s.ViewContainerRef}]},t}(),N=function(){function t(t,e,n){this.log=t,this.httpClient=e,this.state=n,t.setClass("DocumentViewerService")}return t.prototype.getDocumentMetadata=function(n){var o=this,i=u.makeStateKey(n),t=this.state.get(i,null);return t?p.of(t):this.httpClient.get(n).pipe(l.map(function(t){return o.state.set(i,t),t})).pipe(l.catchError(function(t){var e={error:t};return o.state.set(i,e),o.log.error("Encountered error while downloading document:"+n+"-"+t),p.of(e)}))},t.decorators=[{type:s.Injectable,args:[{providedIn:"root"}]}],t.ctorParameters=function(){return[{type:f},{type:r.HttpClient},{type:u.TransferState}]},t.ngInjectableDef=s.defineInjectable({factory:function(){return new t(s.inject(f),s.inject(r.HttpClient),s.inject(u.TransferState))},token:t,providedIn:"root"}),t}(),W=function(){function t(t,e,n,o,i){this.log=t,this.viewerFactoryService=e,this.annotationStoreService=n,this.urlFixer=o,this.documentViewerService=i,this.url="",this.rotate=!1,t.setClass("DocumentViewerComponent")}return t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(t){(t.url||t.annotate)&&this.buildViewer()},t.prototype.buildViewer=function(){var o=this;if(!this.url)throw this.log.error("url is required argument"),new Error("url is required argument");this.isDM?this.documentViewerService.getDocumentMetadata(""+this.urlFixer.fixDm(this.url,this.baseUrl)).subscribe(function(e){if(o.log.info(e),e&&e._links){var n=o.urlFixer.fixDm(e._links.binary.href,o.baseUrl),t=o.viewerFactoryService.getDocumentId(e);o.annotate?o.annotationStoreService.getAnnotationSet(o.baseUrl,t).subscribe(function(t){o.buildComponent(e,n,t.body)}):o.buildComponent(e,n,null)}},function(t){o.log.error("An error has occured while fetching document"+t),o.error=t}):this.viewerComponent=this.viewerFactoryService.buildComponent(this.viewerAnchor.viewContainerRef,this.contentType,this.url,this.baseUrl,this.url,this.annotate,null,this.rotate)},t.prototype.buildComponent=function(t,e,n){this.viewerFactoryService.buildComponent(this.viewerAnchor.viewContainerRef,t.mimeType,e,this.baseUrl,t._links.self.href,this.annotate,n,this.rotate)},t.decorators=[{type:s.Component,args:[{selector:"app-document-viewer",template:'\n<ng-template appViewerAnchor></ng-template>\n\n<div class="grid-row">\n <div *ngIf="error" class="error-summary" role="alert" aria-labelledby="error-summary-heading-example-1" tabindex="-1">\n <h2 class="heading-medium error-summary-heading" id="error-summary-heading-example-1">There was an error while loading your document.</h2>\n <p>Response status was {{error.status}}.</p>\n </div>\n</div>\n\n'}]}],t.ctorParameters=function(){return[{type:f},{type:O},{type:A},{type:F},{type:N}]},t.propDecorators={viewerAnchor:[{type:s.ViewChild,args:[H]}],url:[{type:s.Input}],annotate:[{type:s.Input}],baseUrl:[{type:s.Input}],isDM:[{type:s.Input}],contentType:[{type:s.Input}],rotate:[{type:s.Input}]},t}(),L=function(){function t(){}return t.decorators=[{type:s.NgModule,args:[{imports:[n.NgtUniversalModule,a.CommonModule,e.FormsModule,r.HttpClientModule],declarations:[x,P,j,k,T,E,W,H,D],entryComponents:[k,T,E,D],providers:[o,S,g,A,v,I,b,y,F,O,N,B,w,f],exports:[W]}]}],t}();t.HmctsEmViewerUiModule=L,t.ɵb=A,t.ɵf=b,t.ɵh=o,t.ɵj=S,t.ɵn=I,t.ɵd=v,t.ɵi=w,t.ɵg=g,t.ɵu=F,t.ɵe=y,t.ɵr=W,t.ɵv=N,t.ɵs=H,t.ɵc=f,t.ɵm=k,t.ɵk=P,t.ɵa=x,t.ɵl=j,t.ɵo=B,t.ɵw=D,t.ɵp=T,t.ɵq=E,t.ɵt=O,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=hmcts-annotation-ui-lib.umd.min.js.map