UNPKG

@tindtechnologies/universalviewer

Version:

The Universal Viewer is a community-developed open source project on a mission to help you share your 📚📜📰📽️📻🗿 with the 🌎

22 lines (21 loc) 20.5 kB
import{a as A}from"./chunk-CHPN5XCG.js";import{a as F}from"./chunk-VQAXEBVY.js";import{a as y}from"./chunk-QBSATBVB.js";import"./chunk-2SUYJOML.js";import{c as I,f as C,h as S,i as T,k as O,l as H,m as R}from"./chunk-BIWUBEGG.js";import{a as M,c as z}from"./chunk-UYLDA6E6.js";import{b as r,n as m,p as s}from"./chunk-2YE6NNA6.js";import{d as D,g as p}from"./chunk-R6HAKAEO.js";import{c as w}from"./chunk-YAXTLTJC.js";var b=class extends y{constructor(e){super(e)}create(){this.setConfig("downloadDialogue"),super.create()}open(e){super.open(e),this.addEntireFileDownloadOptions(),this.$downloadOptions.find("li:visible").length?this.$noneAvailable.hide():this.$noneAvailable.show(),this.resize()}isDownloadOptionAvailable(e){return super.isDownloadOptionAvailable(e)}};var c=class{},n=c;n.namespace="pdfExtension.",n.PDF_LOADED=c.namespace+"pdfLoaded",n.PAGE_INDEX_CHANGE=c.namespace+"pageIndexChange",n.SEARCH=c.namespace+"search";var l=window.$,v=class extends I{constructor(e){super(e);this._lastMediaUri=null;this._maxScale=5;this._minScale=.7;this._nextButtonEnabled=!1;this._pageIndex=1;this._pageIndexPending=null;this._pageRendering=!1;this._pdfDoc=null;this._pdfjsLib=null;this._prevButtonEnabled=!1;this._scale=.7}create(){this.setConfig("pdfCenterPanel"),super.create(),this._$pdfContainer=l('<div class="pdfContainer"></div>'),this._$canvas=l("<canvas></canvas>"),this._$progress=l('<progress max="100" value="0"></progress>'),this._canvas=this._$canvas[0],this._ctx=this._canvas.getContext("2d"),this._$prevButton=l('<div class="btn prev" tabindex="0"></div>'),this._$nextButton=l('<div class="btn next" tabindex="0"></div>'),this._$zoomInButton=l('<div class="btn zoomIn" tabindex="0"></div>'),this._$zoomOutButton=l('<div class="btn zoomOut" tabindex="0"></div>'),r.getBool(this.options.usePdfJs,!1)&&(this.$content.append(this._$progress),this.$content.append(this._$prevButton),this.$content.append(this._$nextButton),this.$content.append(this._$zoomInButton),this.$content.append(this._$zoomOutButton)),this._$pdfContainer.append(this._$canvas),this.$content.prepend(this._$pdfContainer),this.extensionHost.subscribe(s.OPEN_EXTERNAL_RESOURCE,e=>{this.openMedia(e)}),this.extensionHost.subscribe(s.FIRST,()=>{!this._pdfDoc||(this._pageIndex=1,this._queueRenderPage(this._pageIndex))}),this.extensionHost.subscribe(s.PREV,()=>{!this._pdfDoc||this._pageIndex<=1||(this._pageIndex--,this._queueRenderPage(this._pageIndex))}),this.extensionHost.subscribe(s.NEXT,()=>{!this._pdfDoc||this._pageIndex>=this._pdfDoc.numPages||(this._pageIndex++,this._queueRenderPage(this._pageIndex))}),this.extensionHost.subscribe(s.LAST,()=>{!this._pdfDoc||(this._pageIndex=this._pdfDoc.numPages,this._queueRenderPage(this._pageIndex))}),this.extensionHost.subscribe(s.CANVAS_INDEX_CHANGE,()=>{!this._pdfDoc||(this._pageIndex=1,this._queueRenderPage(this._pageIndex))}),this.extensionHost.subscribe(n.SEARCH,e=>{!this._pdfDoc||e<1||e>this._pdfDoc.numPages||(this._pageIndex=e,this._queueRenderPage(this._pageIndex))}),this._$prevButton.onPressed(e=>{e.preventDefault(),!!this._prevButtonEnabled&&this.extensionHost.publish(s.PREV)}),this.disablePrevButton(),this._$nextButton.onPressed(e=>{e.preventDefault(),!!this._nextButtonEnabled&&this.extensionHost.publish(s.NEXT)}),this.disableNextButton(),this._$zoomInButton.onPressed(e=>{e.preventDefault();let t=this._scale+.5;t<this._maxScale?this._scale=t:this._scale=this._maxScale,this._render(this._pageIndex)}),this._$zoomOutButton.onPressed(e=>{e.preventDefault();let t=this._scale-.5;t>this._minScale?this._scale=t:this._scale=this._minScale,this._render(this._pageIndex)})}disablePrevButton(){this._prevButtonEnabled=!1,this._$prevButton.addClass("disabled")}enablePrevButton(){this._prevButtonEnabled=!0,this._$prevButton.removeClass("disabled")}hidePrevButton(){this.disablePrevButton(),this._$prevButton.hide()}showPrevButton(){this.enablePrevButton(),this._$prevButton.show()}disableNextButton(){this._nextButtonEnabled=!1,this._$nextButton.addClass("disabled")}enableNextButton(){this._nextButtonEnabled=!0,this._$nextButton.removeClass("disabled")}hideNextButton(){this.disableNextButton(),this._$nextButton.hide()}showNextButton(){this.enableNextButton(),this._$nextButton.show()}async openMedia(e){await this.extension.getExternalResources(e);let t=null,o=this.extension.helper.getCurrentCanvas(),a=this.extension.getMediaFormats(o),h=o.id;if(a&&a.length?t=a[0].id:t=o.id,t!==this._lastMediaUri){if(this._lastMediaUri=t,!r.getBool(this.options.usePdfJs,!1))window.PDFObject=await import("./pdfobject-RVTYN2PB.js"),window.PDFObject.embed(h,".pdfContainer",{id:"PDF"});else{this._pdfjsLib?(this._$progress[0].setAttribute("value","0"),this._$progress.show(),this._$canvas.hide()):(await D(["//cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"]),this._pdfjsLib=window["pdfjs-dist/build/pdf"],this._pdfjsLib.GlobalWorkerOptions.workerSrc="//cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js");let f={url:t,withCredentials:o.externalResource.isAccessControlled()},P=this._pdfjsLib.getDocument(f);P.onProgress=u=>{let B=u.loaded/u.total*100;this._$progress[0].setAttribute("value",String(B)),B===100&&(this._$progress.hide(),this._$canvas.show())},P.promise.then(u=>{this._pdfDoc=u,this._render(this._pageIndex),this.extensionHost.publish(n.PDF_LOADED,u)})}this.extensionHost.publish(p.EXTERNAL_RESOURCE_OPENED),this.extensionHost.publish(p.LOAD)}}_render(e){if(!r.getBool(this.options.usePdfJs,!1))return;this._pageRendering=!0,this._$zoomOutButton.enable(),this._$zoomInButton.enable();let t=this._scale-.5,o=this._scale+.5;t<this._minScale&&this._$zoomOutButton.disable(),o>this._maxScale&&this._$zoomInButton.disable(),this._pdfDoc.getPage(e).then(a=>{this._renderTask&&this._renderTask.cancel(),this._viewport=a.getViewport({scale:this._scale}),this._canvas.height=this._viewport.height,this._canvas.width=this._viewport.width;let h={canvasContext:this._ctx,viewport:this._viewport};this._renderTask=a.render(h),this._renderTask.promise.then(()=>{this.extensionHost.publish(n.PAGE_INDEX_CHANGE,this._pageIndex),this._pageRendering=!1,this._pageIndexPending!==null&&(this._render(this._pageIndexPending),this._pageIndexPending=null),this._pageIndex===1?this.disablePrevButton():this.enablePrevButton(),this._pageIndex===this._pdfDoc.numPages?this.disableNextButton():this.enableNextButton()}).catch(f=>{})})}_queueRenderPage(e){this._pageRendering?this._pageIndexPending=e:this._render(e)}resize(){super.resize(),this._$pdfContainer.width(this.$content.width()),this._$pdfContainer.height(this.$content.height()),this._$progress.css("top",this.$content.height()/2-this._$progress.height()/2),this._$progress.css("left",this.$content.width()/2-this._$progress.width()/2),this._$prevButton.css({top:(this.$content.height()-this._$prevButton.height())/2,left:this._$prevButton.horizontalMargins()}),this._$nextButton.css({top:(this.$content.height()-this._$nextButton.height())/2,left:this.$content.width()-(this._$nextButton.width()+this._$nextButton.horizontalMargins())}),!!this._viewport&&this._render(this._pageIndex)}};var i=window.$,x=class extends T{constructor(e){super(e);this.firstButtonEnabled=!1;this.lastButtonEnabled=!1;this.nextButtonEnabled=!1;this.prevButtonEnabled=!1;this._pageIndex=0;this._pdfDoc=null}create(){this.setConfig("pdfHeaderPanel"),super.create(),this.extensionHost.subscribe(n.PAGE_INDEX_CHANGE,e=>{this._pageIndex=e,this.render()}),this.extensionHost.subscribe(n.PDF_LOADED,e=>{this._pdfDoc=e}),this.$prevOptions=i('<div class="prevOptions"></div>'),this.$centerOptions.append(this.$prevOptions),this.$firstButton=i(` <button class="btn imageBtn first" tabindex="0" title="${this.content.first}"> <i class="uv-icon-first" aria-hidden="true"></i> <span class="sr-only">${this.content.first}</span> </button> `),this.$prevOptions.append(this.$firstButton),this.$firstButton.disable(),this.$prevButton=i(` <button class="btn imageBtn prev" tabindex="0" title="${this.content.previous}"> <i class="uv-icon-prev" aria-hidden="true"></i> <span class="sr-only">${this.content.previous}</span> </button> `),this.$prevOptions.append(this.$prevButton),this.$prevButton.disable(),this.$search=i('<div class="search"></div>'),this.$centerOptions.append(this.$search),this.$searchText=i('<input class="searchText" maxlength="50" type="text" tabindex="0" aria-label="'+this.content.pageSearchLabel+'"/>'),this.$search.append(this.$searchText),this.$total=i('<span class="total"></span>'),this.$search.append(this.$total),this.$searchButton=i('<a class="go btn btn-primary" tabindex="0">'+this.content.go+"</a>"),this.$search.append(this.$searchButton),this.$searchButton.disable(),this.$nextOptions=i('<div class="nextOptions"></div>'),this.$centerOptions.append(this.$nextOptions),this.$nextButton=i(` <button class="btn imageBtn next" tabindex="0" title="${this.content.next}"> <i class="uv-icon-next" aria-hidden="true"></i> <span class="sr-only">${this.content.next}</span> </button> `),this.$nextOptions.append(this.$nextButton),this.$nextButton.disable(),this.$lastButton=i(` <button class="btn imageBtn last" tabindex="0" title="${this.content.last}"> <i class="uv-icon-last" aria-hidden="true"></i> <span class="sr-only">${this.content.last}</span> </button> `),this.$nextOptions.append(this.$lastButton),this.$lastButton.disable(),this.$firstButton.onPressed(()=>{this.extensionHost.publish(s.FIRST)}),this.$prevButton.onPressed(()=>{this.extensionHost.publish(s.PREV)}),this.$nextButton.onPressed(()=>{this.extensionHost.publish(s.NEXT)}),this.$lastButton.onPressed(()=>{this.extensionHost.publish(s.LAST)}),this.$searchText.onEnter(()=>{this.$searchText.blur(),this.search(this.$searchText.val())}),this.$searchText.click(function(){i(this).select()}),this.$searchButton.onPressed(()=>{this.search(this.$searchText.val())})}render(){this._pdfDoc.numPages===1?this.$centerOptions.hide():this.$centerOptions.show(),this.$searchText.val(this._pageIndex);let e=this.content.of;this.$total.html(m.format(e,this._pdfDoc.numPages.toString())),this.$searchButton.enable(),this._pageIndex===1?(this.$firstButton.disable(),this.$prevButton.disable()):(this.$firstButton.enable(),this.$prevButton.enable()),this._pageIndex===this._pdfDoc.numPages?(this.$lastButton.disable(),this.$nextButton.disable()):(this.$lastButton.enable(),this.$nextButton.enable())}search(e){if(!e){this.extension.showMessage(this.content.emptyValue);return}let t=parseInt(this.$searchText.val(),10);if(isNaN(t)){this.extension.showMessage(this.extension.data.config.modules.genericDialogue.content.invalidNumber);return}this.extensionHost.publish(n.SEARCH,t)}resize(){super.resize()}};var _=class extends H{constructor(e){super(e)}create(){this.setConfig("settingsDialogue"),super.create()}};var E=class extends R{constructor(e){super(e)}create(){this.setConfig("shareDialogue"),super.create()}update(){super.update(),this.code=this.extension.getEmbedScript(this.options.embedTemplate,this.currentWidth,this.currentHeight),this.$code.val(this.code)}resize(){super.resize()}};var k=w(M());var N=w(z());var Q={allowStealFocus:!1,authAPIVersion:1,bookmarkThumbHeight:150,bookmarkThumbWidth:90,dropEnabled:!0,footerPanelEnabled:!0,headerPanelEnabled:!0,leftPanelEnabled:!0,limitLocales:!1,metrics:[{type:"sm",minWidth:0},{type:"md",minWidth:768},{type:"lg",minWidth:1024},{type:"xl",minWidth:1280}],multiSelectionMimeType:"application/zip",navigatorEnabled:!0,openTemplate:"http://universalviewer.io?manifest={0}",overrideFullScreen:!1,pagingEnabled:!0,pagingOptionEnabled:!0,pessimisticAccessControl:!1,preserveViewport:!1,rightPanelEnabled:!0,saveUserSettings:!1,clickToZoomEnabled:!0,searchWithinEnabled:!0,termsOfUseEnabled:!1,theme:"uv-en-GB-theme",tokenStorage:"session",useArrowKeysToNavigate:!1,zoomToSearchResultEnabled:!0},U={leftPanel:{options:{expandFullEnabled:!1,panelAnimationDuration:250,panelCollapsedWidth:30,panelExpandedWidth:255,panelOpen:!1},content:{collapse:"$collapse",collapseFull:"$collapseFull",expand:"$expandContents",expandFull:"$expandGallery"}},footerPanel:{options:{bookmarkEnabled:!1,downloadEnabled:!0,embedEnabled:!1,feedbackEnabled:!1,fullscreenEnabled:!0,minimiseButtons:!0,moreInfoEnabled:!0,openEnabled:!1,printEnabled:!1,shareEnabled:!0},content:{bookmark:"$add_to_bookmarks",download:"$download",embed:"$embed",exitFullScreen:"$exitFullScreen",feedback:"$feedback",fullScreen:"$fullScreen",moreInfo:"$moreInfo",open:"$open",share:"$share"}},genericDialogue:{options:{topCloseButtonEnabled:!1},content:{close:"$close",emptyValue:"$emptyValue",invalidNumber:"$invalidNumber",noMatches:"$noMatches",ok:"$ok",pageNotFound:"$pageNotFound",refresh:"$refresh"}},headerPanel:{options:{centerOptionsEnabled:!0,localeToggleEnabled:!1,settingsButtonEnabled:!0},content:{close:"$close",settings:"$settings"}},helpDialogue:{options:{topCloseButtonEnabled:!1},content:{close:"$close",text:"$placeholder_text text",title:"$help"}},moreInfoRightPanel:{options:{canvasDisplayOrder:"",canvasExclude:"",copyToClipboardEnabled:!1,expandFullEnabled:!1,limitToRange:!1,manifestDisplayOrder:"",manifestExclude:"",panelAnimationDuration:250,panelCollapsedWidth:30,panelExpandedWidth:255,panelOpen:!1,rtlLanguageCodes:"ar, ara, dv, div, he, heb, ur, urd",showAllLanguages:!1,textLimit:4,textLimitType:"lines",topCloseButtonEnabled:!1},content:{attribution:"$attribution",canvasHeader:"$aboutTheImage",close:"$close",collapse:"$collapseInformation",collapseFull:"$collapseGallery",copiedToClipboard:"$copiedToClipboard",copyToClipboard:"$copyToClipboard",description:"$description",expand:"$expandInformation",expandFull:"$expandGallery",holdingText:"$moduleGoesHere",less:"$less",license:"$license",logo:"$logo",manifestHeader:"$aboutTheItem",more:"$more",noData:"$noDataToDisplay",page:"$page",rangeHeader:"$aboutThisSection",title:"$moreInformation"}},centerPanel:{options:{titleEnabled:!0,subtitleEnabled:!0,mostSpecificRequiredStatement:!0,requiredStatementEnabled:!0},content:{attribution:"$attribution"}},pdfCenterPanel:{options:{titleEnabled:!1,subtitleEnabled:!0,mostSpecificRequiredStatement:!0,requiredStatementEnabled:!0,usePdfJs:!0},content:{attribution:"$attribution"}},resourcesLeftPanel:{options:{elideCount:40,galleryThumbHeight:320,galleryThumbWidth:200,oneColThumbHeight:320,oneColThumbWidth:200,pageModeEnabled:!0,panelAnimationDuration:250,panelCollapsedWidth:30,panelExpandedWidth:255,panelOpen:!0,thumbsEnabled:!0,thumbsExtraHeight:8,thumbsImageFadeInDuration:300,thumbsLoadRange:15,treeEnabled:!0,twoColThumbHeight:150,twoColThumbWidth:90}},dialogue:{options:{topCloseButtonEnabled:!1},content:{close:"$close"}},downloadDialogue:{options:{topCloseButtonEnabled:!1},content:{allPages:"$allPages",close:"$close",currentViewAsJpg:"$currentViewAsJpg",currentViewAsJpgExplanation:"$openNewWindow",download:"$download",downloadSelection:"$downloadSelection",downloadSelectionExplanation:"$downloadSelectionExplanation",editSettings:"$editSettings",entireDocument:"$entireDocument",entireFileAsOriginal:"$entireFile",entireFileAsOriginalWithFormat:"$entireFileWithFormat",individualPages:"$individualPages",noneAvailable:"$noDownloadOptionsAvailable",pagingNote:"$pagingNote",preview:"$preview",selection:"$selection",termsOfUse:"$termsOfUse",title:"$download",wholeImageHighRes:"$wholeImageHighRes",wholeImageHighResExplanation:"$openNewWindow",wholeImageLowResAsJpg:"$wholeImageLowResAsJpg",wholeImageLowResAsJpgExplanation:"$openNewWindow",wholeImagesHighRes:"$wholeImagesHighRes",wholeImagesHighResExplanation:"$wholeImagesHighResExplanation"}},pdfHeaderPanel:{options:{centerOptionsEnabled:!0,localeToggleEnabled:!1,settingsButtonEnabled:!0},content:{emptyValue:"$pleaseEnterValue",first:"$first",go:"$go",last:"$last",next:"$next",of:"$of",previous:"$previous",pageSearchLabel:"$searchByPageNumber",close:"$close",settings:"$settings"}},shareDialogue:{options:{embedEnabled:!0,shareEnabled:!0,embedTemplate:'<iframe src="{0}" width="{1}" height="{2}" allowfullscreen frameborder="0"></iframe>',instructionsEnabled:!1,shareFrameEnabled:!0,shareManifestsEnabled:!0,topCloseButtonEnabled:!1},content:{close:"$close",customSize:"$custom",embed:"$embed",embedInstructions:"$embedInstructions",height:"$height",iiif:"$iiifManifest",share:"$share",shareInstructions:"$shareInstructions",size:"$size",width:"$width",shareUrl:"$shareUrl"}},authDialogue:{options:{topCloseButtonEnabled:!1},content:{cancel:"$cancel",confirm:"$confirm",close:"$close"}},clickThroughDialogue:{options:{topCloseButtonEnabled:!1},content:{viewTerms:"$viewTerms",close:"$close"}},loginDialogue:{options:{topCloseButtonEnabled:!1},content:{login:"$login",logout:"$logout",cancel:"$cancel",close:"$close"}},restrictedDialogue:{options:{topCloseButtonEnabled:!1},content:{cancel:"$cancel",close:"$close"}},settingsDialogue:{options:{topCloseButtonEnabled:!1},content:{close:"$close",locale:"$locale",navigatorEnabled:"$navigatorEnabled",clickToZoomEnabled:"$clickToZoomEnabled",pagingEnabled:"$twoPageView",reducedMotion:"$reducedMotion",preserveViewport:"$preserveViewport",title:"$settings",website:"$uvWebsite"}},contentLeftPanel:{}},V={label:"English (GB)",locales:[{name:"cy-GB",label:"Cymraeg"},{name:"en-GB",label:"English (GB)"},{name:"fr-FR",label:"Fran\xE7ais (FR)"},{name:"pl-PL",label:"Polski"},{name:"sv-SE",label:"Svenska"}]},W={authCORSError:"$authCORSError",authorisationFailedMessage:"$authorisationFailedMessage",canvasIndexOutOfRange:"$canvasIndexOutOfRange",fallbackDegradedLabel:"$fallbackDegradedLabel",fallbackDegradedMessage:"$fallbackDegradedMessage",forbiddenResourceMessage:"$forbiddenResourceMessage",termsOfUse:"$termsOfUse",mediaViewer:"$mediaViewer",skipToDownload:"$skipToDownload"},L={options:Q,modules:U,localisation:V,content:W};var J=class extends C{constructor(){super(...arguments);this.defaultConfig=L}create(){super.create(),this.extensionHost.subscribe(s.CANVAS_INDEX_CHANGE,e=>{this.viewCanvas(e)}),this.extensionHost.subscribe(s.THUMB_SELECTED,e=>{this.extensionHost.publish(s.CANVAS_INDEX_CHANGE,e.index)}),this.extensionHost.subscribe(s.LEFTPANEL_EXPAND_FULL_START,()=>{this.shell.$centerPanel.hide(),this.shell.$rightPanel.hide()}),this.extensionHost.subscribe(s.LEFTPANEL_COLLAPSE_FULL_FINISH,()=>{this.shell.$centerPanel.show(),this.shell.$rightPanel.show(),this.resize()}),this.extensionHost.subscribe(p.EXIT_FULLSCREEN,()=>{setTimeout(()=>{this.resize()},10)})}render(){super.render()}isHeaderPanelEnabled(){return super.isHeaderPanelEnabled()&&r.getBool(this.data.config.modules.pdfCenterPanel.options.usePdfJs,!0)}createModules(){super.createModules(),this.isHeaderPanelEnabled()?this.headerPanel=new x(this.shell.$headerPanel):this.shell.$headerPanel.hide(),this.isLeftPanelEnabled()&&(this.leftPanel=new F(this.shell.$leftPanel)),this.centerPanel=new v(this.shell.$centerPanel),this.isRightPanelEnabled()&&(this.rightPanel=new O(this.shell.$rightPanel)),this.isFooterPanelEnabled()?this.footerPanel=new S(this.shell.$footerPanel):this.shell.$footerPanel.hide(),this.$downloadDialogue=$('<div class="overlay download" aria-hidden="true"></div>'),this.shell.$overlays.append(this.$downloadDialogue),this.downloadDialogue=new b(this.$downloadDialogue),this.$shareDialogue=$('<div class="overlay share" aria-hidden="true"></div>'),this.shell.$overlays.append(this.$shareDialogue),this.shareDialogue=new E(this.$shareDialogue),this.$settingsDialogue=$('<div class="overlay settings" aria-hidden="true"></div>'),this.shell.$overlays.append(this.$settingsDialogue),this.settingsDialogue=new _(this.$settingsDialogue),this.isLeftPanelEnabled()&&this.leftPanel.init(),this.isRightPanelEnabled()&&this.rightPanel.init()}bookmark(){super.bookmark();let e=this.helper.getCurrentCanvas(),t=new A;t.index=this.helper.canvasIndex,t.label=N.LanguageMap.getValue(e.getLabel()),t.thumb=e.getProperty("thumbnail"),t.title=this.helper.getLabel(),t.trackingLabel=window.trackingLabel,t.type=k.ExternalResourceType.DOCUMENT,this.fire(s.BOOKMARK,t)}dependencyLoaded(e,t){e===0&&(window.PDFObject=t)}getEmbedScript(e,t,o){let h=`${this.getAppUri()}#?manifest=${this.helper.manifestUri}&c=${this.helper.collectionIndex}&m=${this.helper.manifestIndex}&cv=${this.helper.canvasIndex}`;return m.format(e,h,t.toString(),o.toString())}};export{J as default};