UNPKG

@tindtechnologies/universalviewer

Version:

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

1 lines 20.4 kB
"use strict";(self.webpackChunkUV=self.webpackChunkUV||[]).push([[4830],{8307:(e,t,i)=>{i.d(t,{K:()=>n});var n=function(){function e(e){this.value=e}return e.prototype.toString=function(){return this.value},e.image=new e("image"),e.page=new e("page"),e}()},8051:(e,t,i)=>{i.d(t,{H:()=>R});var n=i(6540),s=i(5338),o=i(5903),r=i(5692),a=i(2485),h=i.n(a),l=function(e){var t=e.first,i=e.onClick,s=e.paged,a=e.selected,l=e.thumb,p=e.viewingDirection,u=(0,r.Wx)({threshold:0,rootMargin:"0px 0px 0px 0px",triggerOnce:!0}),c=u[0],d=u[1];return n.createElement("div",{onClick:function(){return i(l)},className:h()("thumb",{first:t,placeholder:!l.uri,twoCol:s&&(p===o.T5.LEFT_TO_RIGHT||p===o.T5.RIGHT_TO_LEFT),oneCol:!s,selected:a}),tabIndex:0},n.createElement("div",{ref:c,className:"wrap",style:{height:l.height+8+"px"}},d&&n.createElement("img",{src:l.uri,alt:l.label})),n.createElement("div",{className:"info"},n.createElement("span",{className:"label",title:l.label},l.label," "),l.data.searchResults&&n.createElement("span",{className:"searchResults"},l.data.searchResults)))};const p=function(e){var t=e.onClick,i=e.paged,s=e.selected,r=e.thumbs,a=e.viewingDirection,p=(0,n.useRef)(null);(0,n.useEffect)((function(){var e,t,i=null===(e=p.current)||void 0===e?void 0:e.querySelector("#thumb-".concat(s[0])),n=null==i?void 0:i.offsetTop;null===(t=p.current)||void 0===t||t.parentElement.scrollTo({top:n,left:0,behavior:"smooth"})}),[s]);var u=r.findIndex((function(e){return e.viewingHint!==o.LX.NON_PAGED}));return n.createElement("div",{ref:p,className:h()("thumbs",{"left-to-right":a===o.T5.LEFT_TO_RIGHT,"right-to-left":a===o.T5.RIGHT_TO_LEFT,paged:i})},r.map((function(e,r){return n.createElement("span",{key:"thumb-".concat(r),id:"thumb-".concat(r)},n.createElement(l,{first:r===u,onClick:t,paged:i,selected:s.includes(r),thumb:e,viewingDirection:a}),function(e,t,i){return!(t!==o.LX.NON_PAGED&&e&&(i-1)%2==0)}(i,e.viewingHint,r)&&n.createElement("div",{className:"separator"}))})))};var u,c=i(4342),d=i(3957),g=i(4194),b=i(4598),f=i(8210),T=(u=function(e,t){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},u(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function i(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}),y=window.$,w=function(e){function t(t){var i=e.call(this,t,!0,!0)||this;return i.isOpen=!1,i}return T(t,e),t.prototype.create=function(){this.setConfig("contentLeftPanel"),e.prototype.create.call(this),this.$gallery=y('<div class="iiif-gallery-component"></div>'),this.$element.append(this.$gallery)},t.prototype.setup=function(){var e=this;this.galleryComponent=new f.A({target:this.$gallery[0]}),this.galleryComponent.on("thumbSelected",(function(t){e.extensionHost.publish(g.b.GALLERY_THUMB_SELECTED,t),e.extensionHost.publish(g.b.THUMB_SELECTED,t)}),!1),this.galleryComponent.on("decreaseSize",(function(){e.extensionHost.publish(g.b.GALLERY_DECREASE_SIZE)}),!1),this.galleryComponent.on("increaseSize",(function(){e.extensionHost.publish(g.b.GALLERY_INCREASE_SIZE)}),!1)},t.prototype.databind=function(){this.galleryComponent.options.data=this.galleryData,this.galleryComponent.set(this.galleryData),this.resize()},t.prototype.show=function(){var e=this;this.isOpen=!0,this.$element.show(),setTimeout((function(){e.galleryComponent.selectIndex(e.extension.helper.canvasIndex)}),10)},t.prototype.hide=function(){this.isOpen=!1,this.$element.hide()},t.prototype.resize=function(){e.prototype.resize.call(this);var t=this.$gallery.find(".main"),i=this.$gallery.find(".header");t.height(this.$element.height()-i.height())},t}(b.P),m=i(2668),E=i(8307),v=i(4427),$=function(){var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},e(t,i)};return function(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}(),N=window.$,C=function(e){function t(t){var i=e.call(this,t,!0,!0)||this;return i.isOpen=!1,i}return $(t,e),t.prototype.create=function(){this.setConfig("contentLeftPanel"),e.prototype.create.call(this),this.$tree=N('<div class="iiif-tree-component"></div>'),this.$element.append(this.$tree)},t.prototype.setup=function(){var e=this;this.treeComponent=new v.TreeComponent({target:this.$tree[0],data:this.treeData}),this.treeComponent.on("treeNodeSelected",(function(t){e.extensionHost.publish(g.b.TREE_NODE_SELECTED,t)}),!1),this.treeComponent.on("treeNodeMultiSelected",(function(t){e.extensionHost.publish(g.b.TREE_NODE_MULTISELECTED,t)}),!1)},t.prototype.databind=function(){this.treeComponent.set(this.treeData),this.resize()},t.prototype.show=function(){this.isOpen=!0,this.$element.show()},t.prototype.hide=function(){this.isOpen=!1,this.$element.hide()},t.prototype.selectNode=function(e){var t=this;this.treeComponent.selectedNode||(this.treeComponent.expandParents(e,!0),this.$tree.find("#tree-link-"+e.id)[0]),setTimeout((function(){t.treeComponent.selectNode(e)}),0)},t.prototype.expandNode=function(e,t){this.treeComponent.expandNode(e,t)},t.prototype.getAllNodes=function(){return this.treeComponent.getAllNodes()},t.prototype.deselectCurrentNode=function(){this.treeComponent.deselectCurrentNode()},t.prototype.getNodeById=function(e){return this.treeComponent.getNodeById(e)},t.prototype.resize=function(){e.prototype.resize.call(this)},t}(b.P),V=i(6346),x=i(1539),_=i(41),O=function(){var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},e(t,i)};return function(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}(),B=window.$,S=i(3957).T5,R=function(e){function t(t){var i=e.call(this,t)||this;return i.expandFullEnabled=!1,i.isThumbsViewOpen=!1,i.isTreeViewOpen=!1,i.treeSortType=x.BG.NONE,i}return O(t,e),t.prototype.create=function(){var t=this;this.setConfig("contentLeftPanel"),e.prototype.create.call(this),this.extensionHost.subscribe(g.b.SETTINGS_CHANGE,(function(){t.render()})),this.extensionHost.subscribe(g.b.CANVAS_INDEX_CHANGE,(function(){t.render()})),this.extensionHost.subscribe(g.b.GALLERY_THUMB_SELECTED,(function(){t.collapseFull()})),this.extensionHost.subscribe(g.b.METRIC_CHANGE,(function(){t.extension.isDesktopMetric()||t.isFullyExpanded&&t.collapseFull()})),this.extensionHost.subscribe(g.b.ANNOTATIONS,(function(){t.renderThumbs(),t.renderGallery()})),this.extensionHost.subscribe(g.b.ANNOTATIONS_CLEARED,(function(){t.renderThumbs(),t.renderGallery()})),this.extensionHost.subscribe(g.b.ANNOTATIONS_EMPTY,(function(){t.renderThumbs(),t.renderGallery()})),this.extensionHost.subscribe(g.b.CANVAS_INDEX_CHANGE,(function(){t.isFullyExpanded&&t.collapseFull(),t.selectCurrentTreeNode(),t.updateTreeTabBySelection()})),this.extensionHost.subscribe(g.b.RANGE_CHANGE,(function(){t.isFullyExpanded&&t.collapseFull(),t.selectCurrentTreeNode(),t.updateTreeTabBySelection()})),this.$tabs=B('<div class="tabs"></div>'),this.$main.append(this.$tabs),this.$treeButton=B('<a class="index tab" tabindex="0">'+this.content.index+"</a>"),this.$tabs.append(this.$treeButton),this.$thumbsButton=B('<a class="thumbs tab" tabindex="0">'+this.content.thumbnails+"</a>"),this.$tabs.append(this.$thumbsButton),this.$tabsContent=B('<div class="tabsContent"></div>'),this.$main.append(this.$tabsContent),this.$options=B('<div class="options"></div>'),this.$tabsContent.append(this.$options),this.$topOptions=B('<div class="top"></div>'),this.$options.append(this.$topOptions),this.$treeSelect=B('<select aria-label="'+this.content.manifestRanges+'"></select>'),this.$topOptions.append(this.$treeSelect),this.$bottomOptions=B('<div class="bottom"></div>'),this.$options.append(this.$bottomOptions),this.$leftOptions=B('<div class="left"></div>'),this.$bottomOptions.append(this.$leftOptions),this.$rightOptions=B('<div class="right"></div>'),this.$bottomOptions.append(this.$rightOptions),this.$treeViewOptions=B('<div class="treeView"></div>'),this.$leftOptions.append(this.$treeViewOptions),this.$sortByLabel=B('<span class="sort">'+this.content.sortBy+"</span>"),this.$treeViewOptions.append(this.$sortByLabel),this.$sortButtonGroup=B('<div class="btn-group"></div>'),this.$treeViewOptions.append(this.$sortButtonGroup),this.$sortByDateButton=B('<button class="btn" tabindex="0">'+this.content.date+"</button>"),this.$sortButtonGroup.append(this.$sortByDateButton),this.$sortByVolumeButton=B('<button class="btn" tabindex="0">'+this.content.volume+"</button>"),this.$sortButtonGroup.append(this.$sortByVolumeButton),this.$views=B('<div class="views"></div>'),this.$tabsContent.append(this.$views),this.$treeView=B('<div class="treeView"></div>'),this.$views.append(this.$treeView),this.$thumbsView=B('<div class="thumbsView" tabindex="-1"></div>'),this.$views.append(this.$thumbsView),this.$galleryView=B('<div class="galleryView"></div>'),this.$views.append(this.$galleryView),this.$treeSelect.hide(),this.$treeSelect.change((function(){t.renderTree(),t.selectCurrentTreeNode(),t.updateTreeTabBySelection()})),this.$sortByDateButton.on("click",(function(){t.sortByDate()})),this.$sortByVolumeButton.on("click",(function(){t.sortByVolume()})),this.$treeViewOptions.hide(),this.onAccessibleClick(this.$treeButton,(function(){t.openTreeView()})),this.onAccessibleClick(this.$thumbsButton,(function(){t.openThumbsView()})),this.setTitle(this.content.title),this.$sortByVolumeButton.addClass("on");var i=this.options.tabOrder;i&&("thumbs"===(i=(i=i.toLowerCase()).replace(/ /g,"")).split(",")[0]?(this.$treeButton.before(this.$thumbsButton),this.$thumbsButton.addClass("first")):this.$treeButton.addClass("first"))},t.prototype.createTreeView=function(){this.treeView=new C(this.$treeView),this.treeView.treeData=this.getTreeData(),this.treeView.setup(),this.renderTree();var e=this.extension.helper.getTopRanges();if(e.length>1)for(var t=0;t<e.length;t++){var i=e[t];this.$treeSelect.append('<option value="'+i.id+'">'+V.LanguageMap.getValue(i.getLabel())+"</option>")}this.updateTreeViewOptions()},t.prototype.render=function(){this.renderThumbs(),this.renderTree(),this.renderGallery()},t.prototype.updateTreeViewOptions=function(){var e=this.getTree();e&&(this.isCollection()&&this.extension.helper.treeHasNavDates(e)?this.$treeViewOptions.show():this.$treeViewOptions.hide(),this.$treeSelect.find("option").length?this.$treeSelect.show():this.$treeSelect.hide())},t.prototype.sortByDate=function(){this.treeSortType=x.BG.DATE,this.treeView.treeData=this.getTreeData(),this.treeView.databind(),this.selectCurrentTreeNode(),this.$sortByDateButton.addClass("on"),this.$sortByVolumeButton.removeClass("on"),this.resize()},t.prototype.sortByVolume=function(){this.treeSortType=x.BG.NONE,this.treeView.treeData=this.getTreeData(),this.treeView.databind(),this.selectCurrentTreeNode(),this.$sortByDateButton.removeClass("on"),this.$sortByVolumeButton.addClass("on"),this.resize()},t.prototype.isCollection=function(){var e=this.getTree();if(e)return e.data.type===V.TreeNodeType.COLLECTION;throw new Error("Tree not available")},t.prototype.renderTree=function(){this.treeView&&(this.treeView.treeData=this.getTreeData(),this.treeView.databind(),this.selectCurrentTreeNode())},t.prototype.getTreeData=function(){return{autoExpand:this._isTreeAutoExpanded(),branchNodesExpandOnClick:c.YA.getBool(this.config.options.branchNodesExpandOnClick,!0),branchNodesSelectable:c.YA.getBool(this.config.options.branchNodesSelectable,!1),helper:this.extension.helper,topRangeIndex:this.getSelectedTopRangeIndex(),treeSortType:this.treeSortType}},t.prototype._isTreeAutoExpanded=function(){var e=c.YA.getBool(this.config.options.autoExpandTreeEnabled,!1),t=this.config.options.autoExpandTreeIfFewerThan||0;if(e){var i=this.extension.helper.getFlattenedTree();if(i&&i.length<t)return!0}return!1},t.prototype.updateTreeTabByCanvasIndex=function(){var e=this.extension.helper.getTopRanges();if(e.length>1){var t=this.getCurrentCanvasTopRangeIndex();if(-1===t)return;var i=e[t];this.setTreeTabTitle(V.LanguageMap.getValue(i.getLabel()))}else this.setTreeTabTitle(this.content.index)},t.prototype.setTreeTabTitle=function(e){this.$treeButton.text(e)},t.prototype.updateTreeTabBySelection=function(){var e=null,t=this.extension.helper.getTopRanges();t.length>1&&(e=this.treeView?this.getSelectedTree().text():V.LanguageMap.getValue(t[0].getLabel())),e?this.setTreeTabTitle(e):this.setTreeTabTitle(this.content.index)},t.prototype.getViewingHint=function(){return this.extension.helper.getViewingHint()},t.prototype.getViewingDirection=function(){return this.extension.helper.getViewingDirection()},t.prototype.createThumbsRoot=function(){this.thumbsRoot||(this.thumbsRoot=(0,s.H)(this.$thumbsView[0])),this.renderThumbs()},t.prototype.renderThumbs=function(){var e=this;if(this.thumbsRoot){var t=this.getViewingDirection(),i=this.extension.helper.getThumbs(90);t&&t===S.BOTTOM_TO_TOP&&i.reverse();var s=this.extension.annotations;if(s&&s.length)for(var o=function(e){var t=s[e],n=i.filter((function(e){return e.index===t.canvasIndex}))[0];if(n){var o=Object.assign({},n.data);o.searchResults=t.rects.length,n.data=o}},r=0;r<s.length;r++)o(r);var a=!!this.extension.getSettings().pagingEnabled&&this.extension.helper.isPaged(),h=this.extension.getPagedIndices(this.extension.helper.canvasIndex);this.thumbsRoot.render((0,n.createElement)(p,{thumbs:i,paged:a,viewingDirection:t||d.T5.LEFT_TO_RIGHT,selected:h,onClick:function(t){e.extensionHost.publish(g.b.THUMB_SELECTED,t)}}))}},t.prototype.createGalleryView=function(){this.galleryView=new w(this.$galleryView),this.galleryView.galleryData=this.getGalleryData(),this.galleryView.setup(),this.renderGallery()},t.prototype.renderGallery=function(){this.galleryView&&(this.galleryView.galleryData=this.getGalleryData(),this.galleryView.databind())},t.prototype.getGalleryData=function(){return{helper:this.extension.helper,chunkedResizingThreshold:this.config.options.galleryThumbChunkedResizingThreshold,content:this.config.content,debug:!1,imageFadeInDuration:300,initialZoom:6,minLabelWidth:20,pageModeEnabled:this.isPageModeEnabled(),scrollStopDuration:100,searchResults:this.extension.annotations,sizingEnabled:!0,thumbHeight:this.config.options.galleryThumbHeight,thumbLoadPadding:this.config.options.galleryThumbLoadPadding,thumbWidth:this.config.options.galleryThumbWidth,viewingDirection:this.getViewingDirection()}},t.prototype.isPageModeEnabled=function(){return"function"==typeof this.extension.getMode?c.YA.getBool(this.config.options.pageModeEnabled,!0)&&this.extension.getMode().toString()===E.K.page.toString():c.YA.getBool(this.config.options.pageModeEnabled,!0)},t.prototype.getSelectedTree=function(){return this.$treeSelect.find(":selected")},t.prototype.getSelectedTopRangeIndex=function(){var e=this.getSelectedTree().index();return-1===e&&(e=0),e},t.prototype.getTree=function(){var e=this.getSelectedTopRangeIndex();return this.extension.helper.getTree(e,x.BG.NONE)},t.prototype.toggleFinish=function(){if(e.prototype.toggleFinish.call(this),this.isUnopened){var t=c.YA.getBool(this.config.options.treeEnabled,!0),i=c.YA.getBool(this.config.options.thumbsEnabled,!0),n=this.getTree();n&&n.nodes.length||(t=!1),t&&i||this.$tabs.hide(),i&&this.defaultToThumbsView()?this.openThumbsView():t&&this.openTreeView()}},t.prototype.defaultToThumbsView=function(){var e=c.YA.getBool(this.config.options.defaultToTreeEnabled,!1),t=this.config.options.defaultToTreeIfGreaterThan||0,i=this.getTree();return!(e&&i&&i.nodes.length>t)},t.prototype.expandFullStart=function(){e.prototype.expandFullStart.call(this),this.extensionHost.publish(g.b.LEFTPANEL_EXPAND_FULL_START)},t.prototype.expandFullFinish=function(){e.prototype.expandFullFinish.call(this),this.$treeButton.hasClass("on")?this.openTreeView():this.$thumbsButton.hasClass("on")&&this.openThumbsView(),this.extensionHost.publish(g.b.LEFTPANEL_EXPAND_FULL_FINISH)},t.prototype.collapseFullStart=function(){e.prototype.collapseFullStart.call(this),this.extensionHost.publish(g.b.LEFTPANEL_COLLAPSE_FULL_START)},t.prototype.collapseFullFinish=function(){e.prototype.collapseFullFinish.call(this),this.$thumbsButton.hasClass("on")&&this.openThumbsView(),this.extensionHost.publish(g.b.LEFTPANEL_COLLAPSE_FULL_FINISH)},t.prototype.openTreeView=function(){this.isTreeViewOpen=!0,this.isThumbsViewOpen=!1,this.treeView||this.createTreeView(),this.$treeButton.addClass("on"),this.$thumbsButton.removeClass("on"),this.treeView.show(),this.$thumbsView&&this.$thumbsView.hide(),this.galleryView&&this.galleryView.hide(),this.updateTreeViewOptions(),this.selectCurrentTreeNode(),this.resize(),this.treeView.resize(),this.extensionHost.publish(g.b.OPEN_TREE_VIEW)},t.prototype.openThumbsView=function(){this.isTreeViewOpen=!1,this.isThumbsViewOpen=!0,this.createThumbsRoot(),this.isFullyExpanded&&!this.galleryView&&this.createGalleryView(),this.$treeButton.removeClass("on"),this.$thumbsButton.addClass("on"),this.treeView&&this.treeView.hide(),this.$treeSelect.hide(),this.$treeViewOptions.hide(),this.resize(),this.isFullyExpanded?(this.$thumbsView.hide(),this.galleryView&&this.galleryView.show(),this.galleryView&&this.galleryView.resize()):(this.galleryView&&this.galleryView.hide(),this.$thumbsView.show(),this.$thumbsView.resize()),this.extensionHost.publish(g.b.OPEN_THUMBS_VIEW)},t.prototype.selectTopRangeIndex=function(e){this.$treeSelect.prop("selectedIndex",e)},t.prototype.getCurrentCanvasTopRangeIndex=function(){var e=-1,t=this.extension.getCurrentCanvasRange();return t&&(e=Number(t.path.split("/")[0])),e},t.prototype.selectCurrentTreeNode=function(){var e;"uv-openseadragon-extension"===(null===(e=this.extension.type)||void 0===e?void 0:e.name)?this.selectCurrentTreeNodeByCanvas():this.selectCurrentTreeNodeByRange()},t.prototype.selectCurrentTreeNodeByRange=function(){if(this.treeView){var e=this.extension.helper.getCurrentRange(),t=null;e&&e.treeNode&&(t=this.treeView.getNodeById(e.treeNode.id)),t?this.treeView.selectNode(t):this.selectTreeNodeByManifest()}},t.prototype.selectCurrentTreeNodeByCanvas=function(){if(this.treeView){var e=null,t=this.getCurrentCanvasTopRangeIndex(),i=t===this.getSelectedTopRangeIndex(),n=null;-1!==t&&(n=this.extension.getCurrentCanvasRange())&&n.treeNode&&(e=this.treeView.getNodeById(n.treeNode.id)),e&&i?this.treeView.selectNode(e):((n=this.extension.helper.getCurrentRange())&&n.treeNode&&(e=this.treeView.getNodeById(n.treeNode.id)),e?this.treeView.selectNode(e):this.selectTreeNodeByManifest())}},t.prototype.selectTreeNodeByManifest=function(){var e=this,t=this.extension.helper.collectionIndex,i=this.extension.helper.manifestIndex,n=this.treeView.getAllNodes(),s=!1;n.map((function(n){n.isCollection()&&n.data.index===t&&(e.treeView.selectNode(n),e.treeView.expandNode(n,!0),s=!0),n.isManifest()&&n.data.index===i&&(e.treeView.selectNode(n),s=!0)})),s||this.treeView.deselectCurrentNode()},t.prototype.resize=function(){e.prototype.resize.call(this),this.$tabsContent.height(this.$main.height()-((0,_.zN)(this.$tabs)?this.$tabs.height():0)-this.$tabsContent.verticalPadding()),this.$views.height(this.$tabsContent.height()-this.$options.outerHeight())},t}(m.W)},9340:(e,t,i)=>{var n;i.d(t,{C:()=>n}),function(e){e.CANVAS_RENDERINGS="canvasRenderings",e.CURRENT_VIEW="currentView",e.ENTIRE_DOCUMENT_AS_PDF="entireDocumentAsPdf",e.ENTIRE_DOCUMENT_AS_TEXT="entireDocumentAsText",e.ENTIRE_FILE_AS_ORIGINAL="entireFileAsOriginal",e.IMAGE_RENDERINGS="imageRenderings",e.MANIFEST_RENDERINGS="manifestRenderings",e.RANGE_RENDERINGS="rangeRenderings",e.SELECTION="selection",e.UNKNOWN="unknown",e.WHOLE_IMAGE_HIGH_RES="wholeImageHighRes",e.WHOLE_IMAGE_LOW_RES="wholeImageLowRes",e.WHOLE_IMAGES_HIGH_RES="wholeImagesHighRes"}(n||(n={}))}}]);