From 7fdcd951582fc94a40e190bfad0e492934f95d36 Mon Sep 17 00:00:00 2001 From: btzr-io Date: Thu, 21 Nov 2019 18:28:01 -0700 Subject: [PATCH] add animations + minor peformance improvements fix #213 fix #220 fix #221 fix #188 some progress for #135 --- dist/villain.js | 2 +- examples/demo.css | 4 - package.json | 4 +- src/components/keyboard.js | 73 +++++ src/components/loader.js | 6 +- src/components/menu/custom.js | 61 ++-- src/components/menu/index.js | 154 +++++----- src/components/menu/item.js | 91 +++--- src/components/options.js | 19 ++ src/components/render.js | 264 ++++++++++-------- src/components/slider/handle.js | 64 ++++- src/components/slider/index.js | 42 ++- src/components/slider/sliderRail.js | 6 +- src/components/slider/tooltip.js | 16 -- src/components/toolbar/button.js | 2 +- src/components/toolbar/controls/fullscreen.js | 43 +++ src/components/toolbar/controls/layout.js | 36 +++ src/components/toolbar/controls/navigation.js | 149 ++++++++++ src/components/toolbar/controls/zoom.js | 141 ++++++++++ src/components/toolbar/index.js | 238 ++++++---------- src/components/toolbar/navigation.js | 133 --------- src/components/toolbar/settings.js | 169 ++++++----- src/components/toolbar/zoom.js | 138 --------- src/components/tooltip.js | 29 +- src/components/uncompress.js | 256 +++++++++-------- src/components/wrapp.js | 73 +++-- src/context.js | 192 ++++++------- src/css/components/menu.css | 47 ++-- src/css/components/slider.css | 3 +- src/css/components/theme.css | 2 +- src/css/components/tooltip.css | 48 ++-- src/index.js | 30 +- src/lib/utils.js | 16 ++ src/lib/zoom-parser.js | 21 ++ yarn.lock | 22 +- 35 files changed, 1463 insertions(+), 1131 deletions(-) create mode 100644 src/components/keyboard.js create mode 100644 src/components/options.js delete mode 100644 src/components/slider/tooltip.js create mode 100644 src/components/toolbar/controls/fullscreen.js create mode 100644 src/components/toolbar/controls/layout.js create mode 100644 src/components/toolbar/controls/navigation.js create mode 100644 src/components/toolbar/controls/zoom.js delete mode 100644 src/components/toolbar/navigation.js delete mode 100644 src/components/toolbar/zoom.js create mode 100644 src/lib/zoom-parser.js diff --git a/dist/villain.js b/dist/villain.js index e5d01e1d..69b6bbff 100644 --- a/dist/villain.js +++ b/dist/villain.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("reakit")):"function"==typeof define&&define.amd?define(["react","reakit"],t):(e=e||self).villain=t(e.React,e.reakit)}(this,(function(React,reakit){"use strict";var React__default="default"in React?React.default:React;function toVal(e){var t,i,n="";if(e)if("object"==typeof e)if(e.push)for(t=0;t1?t-1:0),n=1;n2?i-2:0),r=2;r1?printWarning$1("Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z])."):printWarning$1("Invalid argument supplied to oneOf, expected an array."),emptyFunctionThatReturnsNull;return l((function(t,i,n,r,o){for(var l=t[i],c=0;c{this.setState(e,t)}),_defineProperty(this,"clear",()=>{this.setState({...defaultState})}),_defineProperty(this,"toggleSetting",e=>{this.setState(t=>({[e]:!t[e]}))}),_defineProperty(this,"createPage",e=>{const t=this.state.pages.concat(e);0===e.index?this.setState({ready:!0,error:null,currentPage:0,pages:t}):this.setState({pages:t})}),_defineProperty(this,"trigger",(e,t)=>{"error"===e&&t&&(console.error(t),this.setState({ready:!1,error:t})),"loaded"===e&&t&&this.setState({...t})}),_defineProperty(this,"togglePin",()=>{this.setState(e=>({autoHideControls:!e.autoHideControls}))}),_defineProperty(this,"toggleTheme",()=>{this.setState(e=>({theme:"Light"===e.theme?"Dark":"Light"}))}),_defineProperty(this,"navigateToPage",e=>{this.setState(t=>{const{totalPages:i}=t,n=i-1;return e<0||e>n?{}:{isLastPage:e===n,isFirstPage:0===e,currentPage:e}})}),_defineProperty(this,"navigateForward",()=>{const{isLastPage:e,currentPage:t}=this.state;e||this.navigateToPage(t+1)}),_defineProperty(this,"navigateBackward",()=>{const{isFirstPage:e,currentPage:t}=this.state;e||this.navigateToPage(t-1)}),_defineProperty(this,"getPage",e=>{const{pages:t,bookMode:i,mangaMode:n,totalPages:r}=this.state,o=t[e],s=e+1;if(i&&((s>=0||s=0?e.substring(0,i):e;return t[n]?n:Object.keys(t)[0]},t.validateTranslationKeys=function(e){var t=["_interfaceLanguage","_language","_defaultLanguage","_defaultLanguageFirstLevelKeys","_props"];e.forEach((function(e){if(-1!==t.indexOf(e))throw new Error(e+" cannot be used as a key. It is a reserved word.")}))},t.randomPseudo=function(e){for(var t="",i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=0;n1?i-1:0),r=1;r2&&void 0!==arguments[2]&&arguments[2];try{for(var n=this._props[t||this._language],r=e.split("."),o=0;o1?t-1:0),o=1;o{const r=React.useContext(ReaderContext),o=React.useRef(null),{theme:s,language:a,fullscreen:l,autoHideControls:c}=r.state,u={width:t,height:i};return React.useEffect(()=>{Object.entries(n).map(([e,t])=>{r.state[e]!==t&&r.updateState({[e]:t})})},[n]),localize.setLanguage(a),React__default.createElement("div",{ref:o,className:clsx("villain",s,l&&"villain--fullscreen",!c&&"villain--static"),style:u},e(o?o.current:null))};var Wrapp$1=React__default.memo(Wrapp);class CompressedFile{constructor(e,t,i,n){this._name=e,this._size=t,this._path=i,this._archiveRef=n}get name(){return this._name}get size(){return this._size}extract(){return this._archiveRef.extractSingleFile(this._path)}}class Archive{static init(e={}){return Archive._options={workerUrl:"../dist/worker-bundle.js",...e},Archive._options}static open(e,t=null){return t=t||Archive._options||Archive.init()&&console.warn("Automatically initializing using options: ",Archive._options),new Archive(e,t).open()}constructor(e,t){this._worker=new Worker(t.workerUrl),this._worker.addEventListener("message",this._workerMsg.bind(this)),this._callbacks=[],this._content={},this._processed=0,this._file=e}async open(){return await this._postMessage({type:"HELLO"},(e,t,i)=>{"READY"===i.type&&e()}),await this._postMessage({type:"OPEN",file:this._file},(e,t,i)=>{"OPENED"===i.type&&e(this)})}hasEncryptedData(){return this._postMessage({type:"CHECK_ENCRYPTION"},(e,t,i)=>{"ENCRYPTION_STATUS"===i.type&&e(i.status)})}usePassword(e){return this._postMessage({type:"SET_PASSPHRASE",passphrase:e},(e,t,i)=>{"PASSPHRASE_STATUS"===i.type&&e(i.status)})}getFilesObject(){return this._processed>0?Promise.resolve().then(()=>this._content):this._postMessage({type:"LIST_FILES"},(e,t,i)=>{if("ENTRY"===i.type){const e=i.entry,[t,n]=this._getProp(this._content,e.path);return"FILE"===e.type&&(t[n]=new CompressedFile(e.fileName,e.size,e.path,this)),!0}"END"===i.type&&(this._processed=1,e(this._cloneContent(this._content)))})}getFilesArray(){return this.getFilesObject().then(e=>this._objectToArray(e))}extractSingleFile(e){return this._postMessage({type:"EXTRACT_SINGLE_FILE",target:e},(e,t,i)=>{if("FILE"===i.type){e(new File([i.entry.fileData],i.entry.fileName,{type:"application/octet-stream"}))}})}extractFiles(e){return this._processed>1?Promise.resolve().then(()=>this._content):this._postMessage({type:"EXTRACT_FILES"},(t,i,n)=>{if("ENTRY"===n.type){const[t,i]=this._getProp(this._content,n.entry.path);return"FILE"===n.entry.type&&(t[i]=new File([n.entry.fileData],n.entry.fileName,{type:"application/octet-stream"}),void 0!==e&&setTimeout(e.bind(null,{file:t[i],path:n.entry.path}))),!0}"END"===n.type&&(this._processed=2,this._worker.terminate(),t(this._cloneContent(this._content)))})}_cloneContent(e){if(e instanceof File||e instanceof CompressedFile||null===e)return e;const t={};for(const i of Object.keys(e))t[i]=this._cloneContent(e[i]);return t}_objectToArray(e,t=""){const i=[];for(const n of Object.keys(e))e[n]instanceof File||e[n]instanceof CompressedFile||null===e[n]?i.push({file:e[n]||n,path:t}):i.push(...this._objectToArray(e[n],`${t}${n}/`));return i}_getProp(e,t){const i=t.split("/");""===i[i.length-1]&&i.pop();let n=e,r=null;for(const e of i)n[e]=n[e]||{},r=n,n=n[e];return[r,i[i.length-1]]}_postMessage(e,t){return this._worker.postMessage(e),new Promise((e,i)=>{this._callbacks.push(this._msgHandler.bind(this,t,e,i))})}_msgHandler(e,t,i,n){if("BUSY"===n.type)i("worker is busy");else{if("ERROR"!==n.type)return e(t,i,n);i(n.error)}}_workerMsg({data:e}){(0,this._callbacks[this._callbacks.length-1])(e)||this._callbacks.pop()}}const regexImage=new RegExp(/^[a-zA-Z0-9_@()-][a-zA-Z0-9_.@()-\s]+.(jpeg|jpg|png|bpm|webp)$/),status=e=>e.status>=200&&e.status<300?Promise.resolve(e):Promise.reject(new Error(e.statusText)),isValidImageType=e=>regexImage.test(e),fetchArchive=(e,t,i)=>{fetch(e,{mode:"cors"}).then(status).then(e=>{e.headers.get("Content-Type");return e.blob()}).then(t).catch(e=>{i&&i(localize["Cant open archive"]),console.error("Request failed",e)})},asyncForEach=async(e,t)=>{for(let i=0;iObject.keys(e).find(i=>e[i]===t);var Icon=createCommonjsModule((function(e){e.exports=function(e){var t={};function i(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=2)}([function(e,t){e.exports=propTypes},function(e,t){e.exports=React__default},function(e,t,i){i.r(t);var n=i(1),r=i(0),o=function(){return(o=Object.assign||function(e){for(var t,i=1,n=arguments.length;i0&&(x.transform=C.join(" "),x.transformOrigin="center",E&&(k=n.createElement("g",{style:x},O,n.createElement("rect",{width:"24",height:"24",fill:"transparent"}))));var I,M=k,L=!0===_||"number"!=typeof _?2:_,D=!E&&(m||v);if(L<0&&(D=!D),_&&(M=n.createElement("g",{style:{animation:"spin"+(D?"-inverse":"")+" linear "+Math.abs(L)+"s infinite",transformOrigin:"center"}},k,!(m||v||0!==w)&&n.createElement("rect",{width:"24",height:"24",fill:"transparent"}))),E)return M;var H,A="icon_labelledby_"+u,z="icon_describedby_"+u;if(o)I=a?A+" "+z:A;else if(H="presentation",a)throw new Error("title attribute required when description is set");return n.createElement("svg",c({ref:t,viewBox:"0 0 24 24",style:x,role:H,"aria-labelledby":I},P),o&&n.createElement("title",{id:A},o),a&&n.createElement("desc",{id:z},a),!E&&_&&(D?n.createElement("style",null,"@keyframes spin-inverse { to { transform: rotate(-360deg) } }"):n.createElement("style",null,"@keyframes spin { to { transform: rotate(360deg) } }")),M)}));h.displayName="Icon",h.propTypes={path:r.string.isRequired,size:r.oneOfType([r.number,r.string]),color:r.string,horizontal:r.bool,vertical:r.bool,rotate:r.number,spin:r.oneOfType([r.bool,r.number]),style:r.object,inStack:r.bool,className:r.string},h.defaultProps={size:null,color:null,horizontal:!1,vertical:!1,rotate:0,spin:!1},t.default=h}])})),Icon$1=unwrapExports(Icon);const Error$1=React__default.memo(e=>{const{icon:t,message:i}=e;return React__default.createElement("div",{className:"villain-overlay villain-overlay--canvas"},React__default.createElement(Icon$1,{className:"villain-icon",path:t,size:3}),React__default.createElement("div",{className:"villain-overlay--message"},React__default.createElement("h3",null,i)))}),Loader=({id:e})=>React__default.createElement("div",{className:"villain-overlay",id:e},React__default.createElement("div",{className:"villain-loader-indicator"}));var Loader$1=React__default.memo(Loader),mdiBookOpen="M13,12H20V13.5H13M13,9.5H20V11H13M13,14.5H20V16H13M21,4H3A2,2 0 0,0 1,6V19A2,2 0 0,0 3,21H21A2,2 0 0,0 23,19V6A2,2 0 0,0 21,4M21,19H12V6H21",mdiBookOpenOutline="M21,4H3A2,2 0 0,0 1,6V19A2,2 0 0,0 3,21H21A2,2 0 0,0 23,19V6A2,2 0 0,0 21,4M3,19V6H11V19H3M21,19H13V6H21V19M14,9.5H20V11H14V9.5M14,12H20V13.5H14V12M14,14.5H20V16H14V14.5Z",mdiBrightness4="M12,18C11.11,18 10.26,17.8 9.5,17.45C11.56,16.5 13,14.42 13,12C13,9.58 11.56,7.5 9.5,6.55C10.26,6.2 11.11,6 12,6A6,6 0 0,1 18,12A6,6 0 0,1 12,18M20,8.69V4H15.31L12,0.69L8.69,4H4V8.69L0.69,12L4,15.31V20H8.69L12,23.31L15.31,20H20V15.31L23.31,12L20,8.69Z",mdiChevronLeft="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z",mdiChevronRight="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z",mdiFileAlert="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M10,18H8V16H10V18M10,14H8V9H10V14M13,9V3.5L18.5,9H13Z",mdiFullscreen="M5,5H10V7H7V10H5V5M14,5H19V10H17V7H14V5M17,14H19V19H14V17H17V14M10,17V19H5V14H7V17H10Z",mdiFullscreenExit="M14,14H19V16H16V19H14V14M5,14H10V19H8V16H5V14M8,5H10V10H5V8H8V5M19,8V10H14V5H16V8H19Z",mdiImageBrokenVariant="M21,5V11.59L18,8.58L14,12.59L10,8.59L6,12.59L3,9.58V5A2,2 0 0,1 5,3H19A2,2 0 0,1 21,5M18,11.42L21,14.43V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V12.42L6,15.41L10,11.41L14,15.41",mdiMinus="M19,13H5V11H19V13Z",mdiPagePrevious="M4,21H19A2,2 0 0,0 21,19V13H17V15L13,12L17,9V11H21V5A2,2 0 0,0 19,3H4A2,2 0 0,0 2,5V19A2,2 0 0,0 4,21M4,15H8V17H4V15M4,11H11V13H4V11M4,7H11V9H4V7M21,11H24V13H21V11Z",mdiPin="M16,12V4H17V2H7V4H8V12L6,14V16H11.2V22H12.8V16H18V14L16,12Z",mdiPinOff="M2,5.27L3.28,4L20,20.72L18.73,22L12.8,16.07V22H11.2V16H6V14L8,12V11.27L2,5.27M16,12L18,14V16H17.82L8,6.18V4H7V2H17V4H16V12Z",mdiPlus="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z",mdiRadioboxBlank="M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z",mdiRadioboxMarked="M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,7A5,5 0 0,0 7,12A5,5 0 0,0 12,17A5,5 0 0,0 17,12A5,5 0 0,0 12,7Z",mdiSettings="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z",mdiTranslate="M12.87,15.07L10.33,12.56L10.36,12.53C12.1,10.59 13.34,8.36 14.07,6H17V4H10V2H8V4H1V6H12.17C11.5,7.92 10.44,9.75 9,11.35C8.07,10.32 7.3,9.19 6.69,8H4.69C5.42,9.63 6.42,11.17 7.67,12.56L2.58,17.58L4,19L9,14L12.11,17.11L12.87,15.07M18.5,10H16.5L12,22H14L15.12,19H19.87L21,22H23L18.5,10M15.88,17L17.5,12.67L19.12,17H15.88Z",jasmineUtils=createCommonjsModule((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.equals=function(e,t,i,a){return function e(t,i,o,s,a,c){var u=!0;var h=function(e,t){var i=n(e),r=n(t);if(i&&r)return;if(i)return e.asymmetricMatch(t);if(r)return t.asymmetricMatch(e)}(t,i);if(void 0!==h)return h;for(var d=0;d"},t.isUndefined=function(e){return void 0===e},t.hasProperty=function e(t,i){if(!t)return!1;if(Object.prototype.hasOwnProperty.call(t,i))return!0;return e(function(e){if(Object.getPrototypeOf)return Object.getPrototypeOf(e);if(e.constructor.prototype==e)return null;return e.constructor.prototype}(t),i)},t.isImmutableUnorderedKeyed=function(e){return!(!e||!e[c]||e[h])},t.isImmutableUnorderedSet=function(e){return!(!e||!e[u]||e[h])};const i=Function.prototype.toString;function n(e){return!!e&&a("Function",e.asymmetricMatch)}function r(e,t,i){var n=function(e){var t=[];for(var n in e)i(e,n)&&t.push(n);return t.concat(Object.getOwnPropertySymbols(e).filter(t=>Object.getOwnPropertyDescriptor(e,t).enumerable))}(e);if(!t)return n;var r=[];if(0===n.length)return n;for(var o=0;oObject(e)!==e;var build=getType,utils$1=createCommonjsModule((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.emptyObject=function(e){return!(!e||"object"!=typeof e)&&!Object.keys(e).length},t.isOneline=t.isError=t.partition=t.sparseArrayEquality=t.typeEquality=t.subsetEquality=t.iterableEquality=t.getObjectSubset=t.getPath=t.hasOwnProperty=void 0;var i=commonjsGlobal["jest-symbol-do-not-touch"]||commonjsGlobal.Symbol;const n=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)||((e,t)=>{const i=e.constructor;if(i===Object)return!1;if("function"!=typeof i)return!1;const n=Object.getOwnPropertyDescriptor(i.prototype,t);return void 0!==n&&"function"==typeof n.get})(e,t);t.hasOwnProperty=n;const r=(e,t)=>{if(Array.isArray(t)||(t=t.split(".")),t.length){const i=1===t.length,n=t[0],o=e[n];if(!i&&null==o)return{hasEndProp:!1,lastTraversedObject:e,traversedPath:[]};const s=r(o,t.slice(1));return null===s.lastTraversedObject&&(s.lastTraversedObject=e),s.traversedPath.unshift(n),i&&(s.hasEndProp=void 0!==o||!(0,build.isPrimitive)(e)&&n in e,s.hasEndProp||s.traversedPath.shift()),s}return{lastTraversedObject:null,traversedPath:[],value:e}};t.getPath=r;const o=(e,t,i=new WeakMap)=>{if(Array.isArray(e)){if(Array.isArray(t)&&t.length===e.length)return t.map((t,i)=>o(e[i],t))}else{if(e instanceof Date)return e;if(c(e)&&c(t)){const r={};if(i.set(e,r),Object.keys(e).filter(e=>n(t,e)).forEach(n=>{r[n]=i.has(e[n])?i.get(e[n]):o(e[n],t[n],i)}),Object.keys(r).length>0)return r}}return e};t.getObjectSubset=o;const s=i.iterator,a=e=>!(null==e||!e[s]),l=(e,t,n=[],r=[])=>{if("object"!=typeof e||"object"!=typeof t||Array.isArray(e)||Array.isArray(t)||!a(e)||!a(t))return;if(e.constructor!==t.constructor)return!1;let o=n.length;for(;o--;)if(n[o]===e)return r[o]===t;n.push(e),r.push(t);const c=(e,t)=>l(e,t,[...n],[...r]);if(void 0!==e.size){if(e.size!==t.size)return!1;if((0,jasmineUtils.isA)("Set",e)||(0,jasmineUtils.isImmutableUnorderedSet)(e)){let o=!0;var u=!0,h=!1,d=void 0;try{for(var p,g=e[i.iterator]();!(u=(p=g.next()).done);u=!0){const e=p.value;if(!t.has(e)){let n=!1;var m=!0,f=!1,v=void 0;try{for(var y,w=t[i.iterator]();!(m=(y=w.next()).done);m=!0){const t=y.value;!0===(0,jasmineUtils.equals)(e,t,[c])&&(n=!0)}}catch(e){f=!0,v=e}finally{try{m||null==w.return||w.return()}finally{if(f)throw v}}if(!1===n){o=!1;break}}}}catch(e){h=!0,d=e}finally{try{u||null==g.return||g.return()}finally{if(h)throw d}}return n.pop(),r.pop(),o}if((0,jasmineUtils.isA)("Map",e)||(0,jasmineUtils.isImmutableUnorderedKeyed)(e)){let o=!0;var T=!0,_=!1,S=void 0;try{for(var x,b=e[i.iterator]();!(T=(x=b.next()).done);T=!0){const e=x.value;if(!t.has(e[0])||!(0,jasmineUtils.equals)(e[1],t.get(e[0]),[c])){let n=!1;var E=!0,P=!1,R=void 0;try{for(var C,O=t[i.iterator]();!(E=(C=O.next()).done);E=!0){const t=C.value,i=(0,jasmineUtils.equals)(e[0],t[0],[c]);let r=!1;!0===i&&(r=(0,jasmineUtils.equals)(e[1],t[1],[c])),!0===r&&(n=!0)}}catch(e){P=!0,R=e}finally{try{E||null==O.return||O.return()}finally{if(P)throw R}}if(!1===n){o=!1;break}}}}catch(e){_=!0,S=e}finally{try{T||null==b.return||b.return()}finally{if(_)throw S}}return n.pop(),r.pop(),o}}const k=t[s]();var I=!0,M=!1,L=void 0;try{for(var D,H=e[i.iterator]();!(I=(D=H.next()).done);I=!0){const e=D.value,t=k.next();if(t.done||!(0,jasmineUtils.equals)(e,t.value,[c]))return!1}}catch(e){M=!0,L=e}finally{try{I||null==H.return||H.return()}finally{if(M)throw L}}return!!k.next().done&&(n.pop(),r.pop(),!0)};t.iterableEquality=l;const c=e=>null!==e&&"object"==typeof e,u=e=>c(e)&&!(e instanceof Error)&&!(e instanceof Array)&&!(e instanceof Date);t.subsetEquality=(e,t)=>{const i=(e=new WeakMap)=>(t,r)=>{if(u(r))return Object.keys(r).every(o=>{if(u(r[o])){if(e.get(r[o]))return(0,jasmineUtils.equals)(t[o],r[o],[l]);e.set(r[o],!0)}return null!=t&&n(t,o)&&(0,jasmineUtils.equals)(t[o],r[o],[l,i(e)])})};return i()(e,t)};const h=(e,t)=>{if(null!=e&&null!=t&&e.constructor!==t.constructor)return!1};t.typeEquality=h;t.sparseArrayEquality=(e,t)=>{if(!Array.isArray(e)||!Array.isArray(t))return;const i=Object.keys(e),n=Object.keys(t);return(0,jasmineUtils.equals)(e,t,[l,h],!0)&&(0,jasmineUtils.equals)(i,n)};t.partition=(e,t)=>{const i=[[],[]];return e.forEach(e=>i[t(e)?0:1].push(e)),i};t.isError=e=>{switch(Object.prototype.toString.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return e instanceof Error}};const d=/[\r\n]/;t.isOneline=(e,t)=>!("string"!=typeof e||"string"!=typeof t||d.test(e)&&d.test(t))}));unwrapExports(utils$1);var utils_1$1=utils$1.emptyObject,utils_2$1=utils$1.isOneline,utils_3$1=utils$1.isError,utils_4$1=utils$1.partition,utils_5=utils$1.sparseArrayEquality,utils_6=utils$1.typeEquality,utils_7=utils$1.subsetEquality,utils_8=utils$1.iterableEquality,utils_9=utils$1.getObjectSubset,utils_10=utils$1.getPath,asymmetricMatchers=createCommonjsModule((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.stringNotMatching=t.stringMatching=t.stringNotContaining=t.stringContaining=t.objectNotContaining=t.objectContaining=t.arrayNotContaining=t.arrayContaining=t.anything=t.any=t.AsymmetricMatcher=void 0;var i=commonjsGlobal["jest-symbol-do-not-touch"]||commonjsGlobal.Symbol;function n(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class r{constructor(e){n(this,"sample",void 0),n(this,"$$typeof",void 0),n(this,"inverse",void 0),this.$$typeof=i.for("jest.asymmetricMatcher"),this.sample=e}}t.AsymmetricMatcher=r;class o extends r{constructor(e){if(void 0===e)throw new TypeError("any() expects to be passed a constructor function. Please pass one or use anything() to match any object.");super(e)}asymmetricMatch(e){return this.sample==String?"string"==typeof e||e instanceof String:this.sample==Number?"number"==typeof e||e instanceof Number:this.sample==Function?"function"==typeof e||e instanceof Function:this.sample==Object?"object"==typeof e:this.sample==Boolean?"boolean"==typeof e:e instanceof this.sample}toString(){return"Any"}getExpectedType(){return this.sample==String?"string":this.sample==Number?"number":this.sample==Function?"function":this.sample==Object?"object":this.sample==Boolean?"boolean":(0,jasmineUtils.fnNameFor)(this.sample)}toAsymmetricMatcher(){return"Any<"+(0,jasmineUtils.fnNameFor)(this.sample)+">"}}class s extends r{asymmetricMatch(e){return!(0,jasmineUtils.isUndefined)(e)&&null!==e}toString(){return"Anything"}toAsymmetricMatcher(){return"Anything"}}class a extends r{constructor(e,t=!1){super(e),this.inverse=t}asymmetricMatch(e){if(!Array.isArray(this.sample))throw new Error(`You must provide an array to ${this.toString()}, not '`+typeof this.sample+"'.");const t=0===this.sample.length||Array.isArray(e)&&this.sample.every(t=>e.some(e=>(0,jasmineUtils.equals)(t,e)));return this.inverse?!t:t}toString(){return`Array${this.inverse?"Not":""}Containing`}getExpectedType(){return"array"}}class l extends r{constructor(e,t=!1){super(e),this.inverse=t}asymmetricMatch(e){if("object"!=typeof this.sample)throw new Error(`You must provide an object to ${this.toString()}, not '`+typeof this.sample+"'.");if(this.inverse){for(const t in this.sample)if((0,jasmineUtils.hasProperty)(e,t)&&(0,jasmineUtils.equals)(this.sample[t],e[t])&&!(0,utils$1.emptyObject)(this.sample[t])&&!(0,utils$1.emptyObject)(e[t]))return!1;return!0}for(const t in this.sample)if(!(0,jasmineUtils.hasProperty)(e,t)||!(0,jasmineUtils.equals)(this.sample[t],e[t]))return!1;return!0}toString(){return`Object${this.inverse?"Not":""}Containing`}getExpectedType(){return"object"}}class c extends r{constructor(e,t=!1){if(!(0,jasmineUtils.isA)("String",e))throw new Error("Expected is not a string");super(e),this.inverse=t}asymmetricMatch(e){const t=(0,jasmineUtils.isA)("String",e)&&e.includes(this.sample);return this.inverse?!t:t}toString(){return`String${this.inverse?"Not":""}Containing`}getExpectedType(){return"string"}}class u extends r{constructor(e,t=!1){if(!(0,jasmineUtils.isA)("String",e)&&!(0,jasmineUtils.isA)("RegExp",e))throw new Error("Expected is not a String or a RegExp");super(new RegExp(e)),this.inverse=t}asymmetricMatch(e){const t=(0,jasmineUtils.isA)("String",e)&&this.sample.test(e);return this.inverse?!t:t}toString(){return`String${this.inverse?"Not":""}Matching`}getExpectedType(){return"string"}}t.any=e=>new o(e);t.anything=()=>new s;t.arrayContaining=e=>new a(e);t.arrayNotContaining=e=>new a(e,!0);t.objectContaining=e=>new l(e);t.objectNotContaining=e=>new l(e,!0);t.stringContaining=e=>new c(e);t.stringNotContaining=e=>new c(e,!0);t.stringMatching=e=>new u(e);t.stringNotMatching=e=>new u(e,!0)}));unwrapExports(asymmetricMatchers);var asymmetricMatchers_1=asymmetricMatchers.stringNotMatching,asymmetricMatchers_2=asymmetricMatchers.stringMatching,asymmetricMatchers_3=asymmetricMatchers.stringNotContaining,asymmetricMatchers_4=asymmetricMatchers.stringContaining,asymmetricMatchers_5=asymmetricMatchers.objectNotContaining,asymmetricMatchers_6=asymmetricMatchers.objectContaining,asymmetricMatchers_7=asymmetricMatchers.arrayNotContaining,asymmetricMatchers_8=asymmetricMatchers.arrayContaining,asymmetricMatchers_9=asymmetricMatchers.anything,asymmetricMatchers_10=asymmetricMatchers.any,asymmetricMatchers_11=asymmetricMatchers.AsymmetricMatcher,jestMatchersObject=createCommonjsModule((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.setMatchers=t.getMatchers=t.setState=t.getState=t.INTERNAL_MATCHER_FLAG=void 0;var i=commonjsGlobal["jest-symbol-do-not-touch"]||commonjsGlobal.Symbol;const n=i.for("$$jest-matchers-object"),r=i.for("$$jest-internal-matcher");t.INTERNAL_MATCHER_FLAG=r,commonjsGlobal.hasOwnProperty(n)||Object.defineProperty(commonjsGlobal,n,{value:{matchers:Object.create(null),state:{assertionCalls:0,expectedAssertionsNumber:null,isExpectingAssertions:!1,suppressedErrors:[]}}});t.getState=()=>commonjsGlobal[n].state;t.setState=e=>{Object.assign(commonjsGlobal[n].state,e)};t.getMatchers=()=>commonjsGlobal[n].matchers;t.setMatchers=(e,t,i)=>{Object.keys(e).forEach(n=>{const o=e[n];if(Object.defineProperty(o,r,{value:t}),!t){class e extends asymmetricMatchers.AsymmetricMatcher{constructor(e=!1,...t){super(t),this.inverse=e}asymmetricMatch(e){const t=o(e,...this.sample).pass;return this.inverse?!t:t}toString(){return`${this.inverse?"not.":""}${n}`}getExpectedType(){return"any"}toAsymmetricMatcher(){return`${this.toString()}<${this.sample.join(", ")}>`}}i[n]=(...t)=>new e(!1,...t),i.not||(i.not={}),i.not[n]=(...t)=>new e(!0,...t)}}),Object.assign(commonjsGlobal[n].matchers,e)}}));unwrapExports(jestMatchersObject);var jestMatchersObject_1=jestMatchersObject.setMatchers,jestMatchersObject_2=jestMatchersObject.getMatchers,jestMatchersObject_3=jestMatchersObject.setState,jestMatchersObject_4=jestMatchersObject.getState,jestMatchersObject_5=jestMatchersObject.INTERNAL_MATCHER_FLAG;const Uncompress=({file:e=null,workerUrl:t=null,children:i})=>{const n=React.useContext(ReaderContext),{ready:r,error:o,preview:s}=(React.useState({size:null,name:null,type:null}),n.state);React.useEffect(()=>(Archive.init({workerUrl:t}),()=>{c()}),[]),React.useEffect(()=>{if(!e)return void jestMatchersObject_3({name:null,size:null,type:null});const{name:t,size:i,type:r}=e;jestMatchersObject_3({name:t,size:i,type:r}),"string"==typeof e&&(n.clear(),a(e)),e instanceof Blob&&(n.clear(),l(e))},[e]);const a=e=>{fetchArchive(e,h,u)},l=e=>{h(e)},c=()=>{const{pages:e}=n.state;e&&e.length>0&&e.forEach(e=>{URL.revokeObjectURL(e.src)})},u=e=>{console.error(e),n.trigger("error",e.message||e)},h=async e=>{try{const t=await p(e);if(t&&t.length>0){const e=s?t.splice(0,s):t;await asyncForEach(e,async(e,t)=>{const i=await e.file.extract();d(i,t)})}else n.trigger("error",localize["Cant open archive"])}catch(e){console.error(e),u(e)}},d=(e,t)=>{const{size:i,name:r}=e,o={index:t,url:URL.createObjectURL(e),name:r,size:i,type:"image"};n.createPage(o)},p=async e=>{const t=await Archive.open(e),i=(await t.getFilesArray()).filter(e=>isValidImageType(e.file.name));i.length;const{type:r,size:o}=e,a={type:r,size:o,totalPages:s&&s0?i:null};return React__default.createElement(React__default.Fragment,null,o&&React__default.createElement(Error$1,{message:o.message||o,icon:mdiFileAlert})||(r?i:React__default.createElement(Loader$1,null)))};Uncompress.propTypes={file:propTypes.oneOfType([propTypes.string,propTypes.instanceOf(Blob)]),workerUrl:propTypes.string,preview:propTypes.number};var openseadragon=createCommonjsModule((function(module){function OpenSeadragon(e){return new OpenSeadragon.Viewer(e)}var root,factory,$,fullScreenApi;!function(e){e.version={versionStr:"2.4.1",major:parseInt("2",10),minor:parseInt("4",10),revision:parseInt("1",10)};var t,i={"[object Boolean]":"boolean","[object Number]":"number","[object String]":"string","[object Function]":"function","[object Array]":"array","[object Date]":"date","[object RegExp]":"regexp","[object Object]":"object"},n=Object.prototype.toString,r=Object.prototype.hasOwnProperty;e.isFunction=function(t){return"function"===e.type(t)},e.isArray=Array.isArray||function(t){return"array"===e.type(t)},e.isWindow=function(e){return e&&"object"==typeof e&&"setInterval"in e},e.type=function(e){return null==e?String(e):i[n.call(e)]||"object"},e.isPlainObject=function(t){if(!t||"object"!==OpenSeadragon.type(t)||t.nodeType||e.isWindow(t))return!1;if(t.constructor&&!r.call(t,"constructor")&&!r.call(t.constructor.prototype,"isPrototypeOf"))return!1;var i;for(var n in t)i=n;return void 0===i||r.call(t,i)},e.isEmptyObject=function(e){for(var t in e)return!1;return!0},e.freezeObject=function(t){return Object.freeze?e.freezeObject=Object.freeze:e.freezeObject=function(e){return e},e.freezeObject(t)},e.supportsCanvas=(t=document.createElement("canvas"),!(!e.isFunction(t.getContext)||!t.getContext("2d"))),e.isCanvasTainted=function(e){var t=!1;try{e.getContext("2d").getImageData(0,0,1,1)}catch(e){t=!0}return t},e.pixelDensityRatio=function(){if(e.supportsCanvas){var t=document.createElement("canvas").getContext("2d"),i=window.devicePixelRatio||1,n=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return Math.max(i,1)/n}return 1}()}(OpenSeadragon),function($){$.extend=function(){var e,t,i,n,r,o,s=arguments[0]||{},a=arguments.length,l=!1,c=1;for("boolean"==typeof s&&(l=s,s=arguments[1]||{},c=2),"object"==typeof s||OpenSeadragon.isFunction(s)||(s={}),a===c&&(s=this,--c);c=i.x&&t.x=i.y},getEvent:function(e){return $.getEvent=e?function(e){return e}:function(){return window.event},$.getEvent(e)},getMousePosition:function(e){if("number"==typeof e.pageX)$.getMousePosition=function(e){var t=new $.Point;return e=$.getEvent(e),t.x=e.pageX,t.y=e.pageY,t};else{if("number"!=typeof e.clientX)throw new Error("Unknown event mouse position, no known technique.");$.getMousePosition=function(e){var t=new $.Point;return e=$.getEvent(e),t.x=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,t.y=e.clientY+document.body.scrollTop+document.documentElement.scrollTop,t}}return $.getMousePosition(e)},getPageScroll:function(){var e=document.documentElement||{},t=document.body||{};if("number"==typeof window.pageXOffset)$.getPageScroll=function(){return new $.Point(window.pageXOffset,window.pageYOffset)};else if(t.scrollLeft||t.scrollTop)$.getPageScroll=function(){return new $.Point(document.body.scrollLeft,document.body.scrollTop)};else{if(!e.scrollLeft&&!e.scrollTop)return new $.Point(0,0);$.getPageScroll=function(){return new $.Point(document.documentElement.scrollLeft,document.documentElement.scrollTop)}}return $.getPageScroll()},setPageScroll:function(e){if(void 0!==window.scrollTo)$.setPageScroll=function(e){window.scrollTo(e.x,e.y)};else{var t=$.getPageScroll();if(t.x===e.x&&t.y===e.y)return;document.body.scrollLeft=e.x,document.body.scrollTop=e.y;var i=$.getPageScroll();if(i.x!==t.x&&i.y!==t.y)return void($.setPageScroll=function(e){document.body.scrollLeft=e.x,document.body.scrollTop=e.y});if(document.documentElement.scrollLeft=e.x,document.documentElement.scrollTop=e.y,(i=$.getPageScroll()).x!==t.x&&i.y!==t.y)return void($.setPageScroll=function(e){document.documentElement.scrollLeft=e.x,document.documentElement.scrollTop=e.y});$.setPageScroll=function(e){}}return $.setPageScroll(e)},getWindowSize:function(){var e=document.documentElement||{},t=document.body||{};if("number"==typeof window.innerWidth)$.getWindowSize=function(){return new $.Point(window.innerWidth,window.innerHeight)};else if(e.clientWidth||e.clientHeight)$.getWindowSize=function(){return new $.Point(document.documentElement.clientWidth,document.documentElement.clientHeight)};else{if(!t.clientWidth&&!t.clientHeight)throw new Error("Unknown window size, no known technique.");$.getWindowSize=function(){return new $.Point(document.body.clientWidth,document.body.clientHeight)}}return $.getWindowSize()},makeCenteredNode:function(e){e=$.getElement(e);var t=[$.makeNeutralElement("div"),$.makeNeutralElement("div"),$.makeNeutralElement("div")];return $.extend(t[0].style,{display:"table",height:"100%",width:"100%"}),$.extend(t[1].style,{display:"table-row"}),$.extend(t[2].style,{display:"table-cell",verticalAlign:"middle",textAlign:"center"}),t[0].appendChild(t[1]),t[1].appendChild(t[2]),t[2].appendChild(e),t[0]},makeNeutralElement:function(e){var t=document.createElement(e),i=t.style;return i.background="transparent none",i.border="none",i.margin="0px",i.padding="0px",i.position="static",t},now:function(){return Date.now?$.now=Date.now:$.now=function(){return(new Date).getTime()},$.now()},makeTransparentImage:function(e){return $.makeTransparentImage=function(e){var t=$.makeNeutralElement("img");return t.src=e,t},$.Browser.vendor==$.BROWSERS.IE&&$.Browser.version<7&&($.makeTransparentImage=function(e){var t=$.makeNeutralElement("img"),i=null;return(i=$.makeNeutralElement("span")).style.display="inline-block",t.onload=function(){i.style.width=i.style.width||t.width+"px",i.style.height=i.style.height||t.height+"px",t.onload=null,t=null},t.src=e,i.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+e+"', sizingMethod='scale')",i}),$.makeTransparentImage(e)},setElementOpacity:function(e,t,i){var n;e=$.getElement(e),i&&!$.Browser.alpha&&(t=Math.round(t)),$.Browser.opacity?e.style.opacity=t<1?t:"":t<1?(n="alpha(opacity="+Math.round(100*t)+")",e.style.filter=n):e.style.filter=""},setElementTouchActionNone:function(e){void 0!==(e=$.getElement(e)).style.touchAction?e.style.touchAction="none":void 0!==e.style.msTouchAction&&(e.style.msTouchAction="none")},addClass:function(e,t){(e=$.getElement(e)).className?-1===(" "+e.className+" ").indexOf(" "+t+" ")&&(e.className+=" "+t):e.className=t},indexOf:function(e,t,i){return Array.prototype.indexOf?this.indexOf=function(e,t,i){return e.indexOf(t,i)}:this.indexOf=function(e,t,i){var n,r,o=i||0;if(!e)throw new TypeError;if(0===(r=e.length)||o>=r)return-1;for(o<0&&(o=r-Math.abs(o)),n=o;n=200&&a.status<300||0===a.status&&"http:"!==s&&"https:"!==s?t(a):($.console.log("AJAX request returned %d: %s",a.status,e),$.isFunction(i)&&i(a)))};try{if(a.open("GET",e,!0),o&&(a.responseType=o),r)for(var l in r)r.hasOwnProperty(l)&&r[l]&&a.setRequestHeader(l,r[l]);n&&(a.withCredentials=!0),a.send(null)}catch(n){var c=n.message;if($.Browser.vendor==$.BROWSERS.IE&&$.Browser.version<10&&void 0!==n.number&&-2147024891==n.number&&(c+="\nSee http://msdn.microsoft.com/en-us/library/ms537505(v=vs.85).aspx#xdomain"),$.console.log("%s while making AJAX request: %s",n.name,c),a.onreadystatechange=function(){},window.XDomainRequest){var u=new XDomainRequest;if(u){u.onload=function(e){$.isFunction(t)&&t({responseText:u.responseText,status:200,statusText:"OK"})},u.onerror=function(e){$.isFunction(i)&&i({responseText:u.responseText,status:444,statusText:"An error happened. Due to an XDomainRequest deficiency we can not extract any information about this error. Upgrade your browser."})};try{u.open("GET",e),u.send()}catch(e){$.isFunction(i)&&i(a,n)}}}else $.isFunction(i)&&i(a,n)}return a},jsonp:function(e){var t,i=e.url,n=document.head||document.getElementsByTagName("head")[0]||document.documentElement,r=e.callbackName||"openseadragon"+$.now(),o=window[r],s="$1"+r+"$2",a=e.param||"callback",l=e.callback;i=i.replace(/(\=)\?(&|$)|\?\?/i,s),i+=(/\?/.test(i)?"&":"?")+a+"="+r,window[r]=function(e){if(o)window[r]=o;else try{delete window[r]}catch(e){}l&&$.isFunction(l)&&l(e)},t=document.createElement("script"),void 0===e.async&&!1===e.async||(t.async="async"),e.scriptCharset&&(t.charset=e.scriptCharset),t.src=i,t.onload=t.onreadystatechange=function(e,i){(i||!t.readyState||/loaded|complete/.test(t.readyState))&&(t.onload=t.onreadystatechange=null,n&&t.parentNode&&n.removeChild(t),t=void 0)},n.insertBefore(t,n.firstChild)},createFromDZI:function(){throw"OpenSeadragon.createFromDZI is deprecated, use Viewer.open."},parseXml:function(e){if(window.DOMParser)$.parseXml=function(e){return(new DOMParser).parseFromString(e,"text/xml")};else{if(!window.ActiveXObject)throw new Error("Browser doesn't support XML DOM.");$.parseXml=function(e){var t=null;return(t=new ActiveXObject("Microsoft.XMLDOM")).async=!1,t.loadXML(e),t}}return $.parseXml(e)},parseJSON:function(string){return window.JSON&&window.JSON.parse?$.parseJSON=window.JSON.parse:$.parseJSON=function(string){return eval("("+string+")")},$.parseJSON(string)},imageFormatSupported:function(e){return!!FILEFORMATS[(e=e||"").toLowerCase()]}}),$.Browser={vendor:$.BROWSERS.UNKNOWN,version:0,alpha:!0};var FILEFORMATS={bmp:!1,jpeg:!0,jpg:!0,png:!0,tif:!1,wdp:!1},URLPARAMS={};!function(){var e=navigator.appVersion,t=navigator.userAgent;switch(navigator.appName){case"Microsoft Internet Explorer":window.attachEvent&&window.ActiveXObject&&($.Browser.vendor=$.BROWSERS.IE,$.Browser.version=parseFloat(t.substring(t.indexOf("MSIE")+5,t.indexOf(";",t.indexOf("MSIE")))));break;case"Netscape":window.addEventListener&&(t.indexOf("Firefox")>=0?($.Browser.vendor=$.BROWSERS.FIREFOX,$.Browser.version=parseFloat(t.substring(t.indexOf("Firefox")+8))):t.indexOf("Safari")>=0?($.Browser.vendor=t.indexOf("Chrome")>=0?$.BROWSERS.CHROME:$.BROWSERS.SAFARI,$.Browser.version=parseFloat(t.substring(t.substring(0,t.indexOf("Safari")).lastIndexOf("/")+1,t.indexOf("Safari")))):null!==new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})").exec(t)&&($.Browser.vendor=$.BROWSERS.IE,$.Browser.version=parseFloat(RegExp.$1)));break;case"Opera":$.Browser.vendor=$.BROWSERS.OPERA,$.Browser.version=parseFloat(e)}var i,n,r,o=window.location.search.substring(1).split("&");for(r=0;r0&&(URLPARAMS[i.substring(0,n)]=decodeURIComponent(i.substring(n+1)));$.Browser.alpha=!($.Browser.vendor==$.BROWSERS.IE&&$.Browser.version<9||$.Browser.vendor==$.BROWSERS.CHROME&&$.Browser.version<2),$.Browser.opacity=!($.Browser.vendor==$.BROWSERS.IE&&$.Browser.version<9)}();var nullfunction=function(e){};function getOffsetParent(e,t){return t&&e!=document.body?document.body:e.offsetParent}$.console=window.console||{log:nullfunction,debug:nullfunction,info:nullfunction,warn:nullfunction,error:nullfunction,assert:nullfunction},function(e){var t=e.requestAnimationFrame||e.mozRequestAnimationFrame||e.webkitRequestAnimationFrame||e.msRequestAnimationFrame,i=e.cancelAnimationFrame||e.mozCancelAnimationFrame||e.webkitCancelAnimationFrame||e.msCancelAnimationFrame;if(t&&i)$.requestAnimationFrame=function(){return t.apply(e,arguments)},$.cancelAnimationFrame=function(){return i.apply(e,arguments)};else{var n,r=[],o=[],s=0;$.requestAnimationFrame=function(e){return r.push([++s,e]),n||(n=setInterval((function(){if(r.length){var e=$.now(),t=o;for(o=r,r=t;o.length;)o.shift()[1](e)}else clearInterval(n),n=void 0}),20)),s},$.cancelAnimationFrame=function(e){var t,i;for(t=0,i=r.length;t0&&(e.removeEvent(e.MouseTracker.captureElement,"mousemove",n.mousemovecaptured,!0),e.removeEvent(e.MouseTracker.captureElement,"mouseup",n.mouseupcaptured,!0),e.removeEvent(e.MouseTracker.captureElement,e.MouseTracker.unprefixedPointerEvents?"pointermove":"MSPointerMove",n.pointermovecaptured,!0),e.removeEvent(e.MouseTracker.captureElement,e.MouseTracker.unprefixedPointerEvents?"pointerup":"MSPointerUp",n.pointerupcaptured,!0),e.removeEvent(e.MouseTracker.captureElement,"touchmove",n.touchmovecaptured,!0),e.removeEvent(e.MouseTracker.captureElement,"touchend",n.touchendcaptured,!0),n.activePointersLists[i].captureCount=0);for(i=0;i0){for(n=0;n0&&(fe(e,t,o,0),i.captureCount=1,p(e,i.type),ge(e,t,o))}}function W(t,i){var n,r,o,s,l=i.changedTouches.length,c=[],u=t.getActivePointersListByType("touch");for(n=e.now(),u.getLength()>i.touches.length-l&&(e.console.warn("Tracked touch contact count doesn't match event.touches.length. Removing all tracked touch pointers."),U(t,i,u)),r=0;r8||"onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll",e.MouseTracker.supportsMouseCapture=(s=document.createElement("div"),e.isFunction(s.setCapture)&&e.isFunction(s.releaseCapture)),e.MouseTracker.subscribeEvents=["click","dblclick","keydown","keyup","keypress","focus","blur",e.MouseTracker.wheelEventName],"DOMMouseScroll"==e.MouseTracker.wheelEventName&&e.MouseTracker.subscribeEvents.push("MozMousePixelScroll"),window.PointerEvent&&(window.navigator.pointerEnabled||e.Browser.vendor!==e.BROWSERS.IE)?(e.MouseTracker.havePointerEvents=!0,e.MouseTracker.subscribeEvents.push("pointerover","pointerout","pointerdown","pointerup","pointermove","pointercancel"),e.MouseTracker.unprefixedPointerEvents=!0,navigator.maxTouchPoints?e.MouseTracker.maxTouchPoints=navigator.maxTouchPoints:e.MouseTracker.maxTouchPoints=0,e.MouseTracker.haveMouseEnter=!1):window.MSPointerEvent&&window.navigator.msPointerEnabled?(e.MouseTracker.havePointerEvents=!0,e.MouseTracker.subscribeEvents.push("MSPointerOver","MSPointerOut","MSPointerDown","MSPointerUp","MSPointerMove","MSPointerCancel"),e.MouseTracker.unprefixedPointerEvents=!1,navigator.msMaxTouchPoints?e.MouseTracker.maxTouchPoints=navigator.msMaxTouchPoints:e.MouseTracker.maxTouchPoints=0,e.MouseTracker.haveMouseEnter=!1):(e.MouseTracker.havePointerEvents=!1,e.Browser.vendor===e.BROWSERS.IE&&e.Browser.version<9?(e.MouseTracker.subscribeEvents.push("mouseenter","mouseleave"),e.MouseTracker.haveMouseEnter=!0):(e.MouseTracker.subscribeEvents.push("mouseover","mouseout"),e.MouseTracker.haveMouseEnter=!1),e.MouseTracker.subscribeEvents.push("mousedown","mouseup","mousemove"),"ontouchstart"in window&&e.MouseTracker.subscribeEvents.push("touchstart","touchend","touchmove","touchcancel"),"ongesturestart"in window&&e.MouseTracker.subscribeEvents.push("gesturestart","gesturechange"),e.MouseTracker.mousePointerId="legacy-mouse",e.MouseTracker.maxTouchPoints=10),e.MouseTracker.GesturePointList=function(e){this._gPoints=[],this.type=e,this.buttons=0,this.contacts=0,this.clicks=0,this.captureCount=0},e.MouseTracker.GesturePointList.prototype={getLength:function(){return this._gPoints.length},asArray:function(){return this._gPoints},add:function(e){return this._gPoints.push(e)},removeById:function(e){var t,i=this._gPoints.length;for(t=0;t1&&("mouse"===this.type||"pen"===this.type)&&(this.contacts=1)},removeContact:function(){--this.contacts,this.contacts<0&&(this.contacts=0)}};var ye=function(){try{return window.self!==window.top}catch(e){return!0}}();function we(e){try{return e.addEventListener&&e.removeEventListener}catch(e){return!1}}}(OpenSeadragon),function(e){e.ControlAnchor={NONE:0,TOP_LEFT:1,TOP_RIGHT:2,BOTTOM_RIGHT:3,BOTTOM_LEFT:4,ABSOLUTE:5},e.Control=function(t,i,n){var r=t.parentNode;"number"==typeof i&&(e.console.error("Passing an anchor directly into the OpenSeadragon.Control constructor is deprecated; please use an options object instead. Support for this deprecated variant is scheduled for removal in December 2013"),i={anchor:i}),i.attachToViewer=void 0===i.attachToViewer||i.attachToViewer,this.autoFade=void 0===i.autoFade||i.autoFade,this.element=t,this.anchor=i.anchor,this.container=n,this.anchor==e.ControlAnchor.ABSOLUTE?(this.wrapper=e.makeNeutralElement("div"),this.wrapper.style.position="absolute",this.wrapper.style.top="number"==typeof i.top?i.top+"px":i.top,this.wrapper.style.left="number"==typeof i.left?i.left+"px":i.left,this.wrapper.style.height="number"==typeof i.height?i.height+"px":i.height,this.wrapper.style.width="number"==typeof i.width?i.width+"px":i.width,this.wrapper.style.margin="0px",this.wrapper.style.padding="0px",this.element.style.position="relative",this.element.style.top="0px",this.element.style.left="0px",this.element.style.height="100%",this.element.style.width="100%"):(this.wrapper=e.makeNeutralElement("div"),this.wrapper.style.display="inline-block",this.anchor==e.ControlAnchor.NONE&&(this.wrapper.style.width=this.wrapper.style.height="100%")),this.wrapper.appendChild(this.element),i.attachToViewer?this.anchor==e.ControlAnchor.TOP_RIGHT||this.anchor==e.ControlAnchor.BOTTOM_RIGHT?this.container.insertBefore(this.wrapper,this.container.firstChild):this.container.appendChild(this.wrapper):r.appendChild(this.wrapper)},e.Control.prototype={destroy:function(){this.wrapper.removeChild(this.element),this.container.removeChild(this.wrapper)},isVisible:function(){return"none"!=this.wrapper.style.display},setVisible:function(t){this.wrapper.style.display=t?this.anchor==e.ControlAnchor.ABSOLUTE?"block":"inline-block":"none"},setOpacity:function(t){this.element[e.SIGNAL]&&e.Browser.vendor==e.BROWSERS.IE?e.setElementOpacity(this.element,t,!0):e.setElementOpacity(this.wrapper,t,!0)}}}(OpenSeadragon),function(e){function t(e,t){var i,n=e.controls;for(i=n.length-1;i>=0;i--)if(n[i].element==t)return i;return-1}e.ControlDock=function(t){var i,n,r=["topleft","topright","bottomright","bottomleft"];for(e.extend(!0,this,{id:"controldock-"+e.now()+"-"+Math.floor(1e6*Math.random()),container:e.makeNeutralElement("div"),controls:[]},t),this.container.onsubmit=function(){return!1},this.element&&(this.element=e.getElement(this.element),this.element.appendChild(this.container),this.element.style.position="relative",this.container.style.width="100%",this.container.style.height="100%"),n=0;n=0)){switch(n.anchor){case e.ControlAnchor.TOP_RIGHT:r=this.controls.topright,i.style.position="relative",i.style.paddingRight="0px",i.style.paddingTop="0px";break;case e.ControlAnchor.BOTTOM_RIGHT:r=this.controls.bottomright,i.style.position="relative",i.style.paddingRight="0px",i.style.paddingBottom="0px";break;case e.ControlAnchor.BOTTOM_LEFT:r=this.controls.bottomleft,i.style.position="relative",i.style.paddingLeft="0px",i.style.paddingBottom="0px";break;case e.ControlAnchor.TOP_LEFT:r=this.controls.topleft,i.style.position="relative",i.style.paddingLeft="0px",i.style.paddingTop="0px";break;case e.ControlAnchor.ABSOLUTE:r=this.container,i.style.margin="0px",i.style.padding="0px";break;default:case e.ControlAnchor.NONE:r=this.container,i.style.margin="0px",i.style.padding="0px"}this.controls.push(new e.Control(i,n,r)),i.style.display="inline-block"}},removeControl:function(i){var n=t(this,i=e.getElement(i));return n>=0&&(this.controls[n].destroy(),this.controls.splice(n,1)),this},clearControls:function(){for(;this.controls.length>0;)this.controls.pop().destroy();return this},areControlsEnabled:function(){var e;for(e=this.controls.length-1;e>=0;e--)if(this.controls[e].isVisible())return!0;return!1},setControlsEnabled:function(e){var t;for(t=this.controls.length-1;t>=0;t--)this.controls[t].setVisible(e);return this}}}(OpenSeadragon),function(e){e.Placement=e.freezeObject({CENTER:0,TOP_LEFT:1,TOP:2,TOP_RIGHT:3,RIGHT:4,BOTTOM_RIGHT:5,BOTTOM:6,BOTTOM_LEFT:7,LEFT:8,properties:{0:{isLeft:!1,isHorizontallyCentered:!0,isRight:!1,isTop:!1,isVerticallyCentered:!0,isBottom:!1},1:{isLeft:!0,isHorizontallyCentered:!1,isRight:!1,isTop:!0,isVerticallyCentered:!1,isBottom:!1},2:{isLeft:!1,isHorizontallyCentered:!0,isRight:!1,isTop:!0,isVerticallyCentered:!1,isBottom:!1},3:{isLeft:!1,isHorizontallyCentered:!1,isRight:!0,isTop:!0,isVerticallyCentered:!1,isBottom:!1},4:{isLeft:!1,isHorizontallyCentered:!1,isRight:!0,isTop:!1,isVerticallyCentered:!0,isBottom:!1},5:{isLeft:!1,isHorizontallyCentered:!1,isRight:!0,isTop:!1,isVerticallyCentered:!1,isBottom:!0},6:{isLeft:!1,isHorizontallyCentered:!0,isRight:!1,isTop:!1,isVerticallyCentered:!1,isBottom:!0},7:{isLeft:!0,isHorizontallyCentered:!1,isRight:!1,isTop:!1,isVerticallyCentered:!1,isBottom:!0},8:{isLeft:!0,isHorizontallyCentered:!1,isRight:!1,isTop:!1,isVerticallyCentered:!0,isBottom:!1}}})}(OpenSeadragon),function(e){var t={},i=1;function n(t){return t=e.getElement(t),new e.Point(0===t.clientWidth?1:t.clientWidth,0===t.clientHeight?1:t.clientHeight)}function r(t,i){if(i instanceof e.Overlay)return i;var n=null;if(i.element)n=e.getElement(i.element);else{var r=i.id?i.id:"openseadragon-overlay-"+Math.floor(1e7*Math.random());(n=e.getElement(i.id))||((n=document.createElement("a")).href="#/overlay/"+r),n.id=r,e.addClass(n,i.className?i.className:"openseadragon-overlay")}var o=i.location,s=i.width,a=i.height;if(!o){var l=i.x,c=i.y;if(void 0!==i.px){var u=t.viewport.imageToViewportRectangle(new e.Rect(i.px,i.py,s||0,a||0));l=u.x,c=u.y,s=void 0!==s?u.width:void 0,a=void 0!==a?u.height:void 0}o=new e.Point(l,c)}var h=i.placement;return h&&"string"===e.type(h)&&(h=e.Placement[i.placement.toUpperCase()]),new e.Overlay({element:n,location:o,placement:h,onDraw:i.onDraw,checkResize:i.checkResize,width:s,height:a,rotationMode:i.rotationMode})}function o(e,t){var i;for(i=e.length-1;i>=0;i--)if(e[i].element===t)return i;return-1}function s(t,i){return e.requestAnimationFrame((function(){i(t)}))}function a(t){e.requestAnimationFrame((function(){!function(t){var i,n,r,o;if(t.controlsShouldFade){for(i=e.now(),n=i-t.controlsFadeBeginTime,r=1-n/t.controlsFadeLength,r=Math.min(1,r),r=Math.max(0,r),o=t.controls.length-1;o>=0;o--)t.controls[o].autoFade&&t.controls[o].setOpacity(r);r>0&&a(t)}}(t)}))}function l(t){t.autoHideControls&&(t.controlsShouldFade=!0,t.controlsFadeBeginTime=e.now()+t.controlsFadeDelay,window.setTimeout((function(){a(t)}),t.controlsFadeDelay))}function c(e){var t;for(e.controlsShouldFade=!1,t=e.controls.length-1;t>=0;t--)e.controls[t].setOpacity(1)}function u(){c(this)}function h(){l(this)}function d(t){var i={originalEvent:t.originalEvent,preventDefaultAction:t.preventDefaultAction,preventVerticalPan:t.preventVerticalPan,preventHorizontalPan:t.preventHorizontalPan};if(this.raiseEvent("canvas-key",i),i.preventDefaultAction||t.ctrl||t.alt||t.meta)return!0;switch(t.keyCode){case 38:return i.preventVerticalPan||(t.shift?this.viewport.zoomBy(1.1):this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(0,-this.pixelsPerArrowPress))),this.viewport.applyConstraints()),!1;case 40:return i.preventVerticalPan||(t.shift?this.viewport.zoomBy(.9):this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(0,this.pixelsPerArrowPress))),this.viewport.applyConstraints()),!1;case 37:return i.preventHorizontalPan||(this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(-this.pixelsPerArrowPress,0))),this.viewport.applyConstraints()),!1;case 39:return i.preventHorizontalPan||(this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(this.pixelsPerArrowPress,0))),this.viewport.applyConstraints()),!1;default:return!0}}function p(t){var i={originalEvent:t.originalEvent,preventDefaultAction:t.preventDefaultAction,preventVerticalPan:t.preventVerticalPan,preventHorizontalPan:t.preventHorizontalPan};if(this.raiseEvent("canvas-key",i),i.preventDefaultAction||t.ctrl||t.alt||t.meta)return!0;switch(t.keyCode){case 43:case 61:return this.viewport.zoomBy(1.1),this.viewport.applyConstraints(),!1;case 45:return this.viewport.zoomBy(.9),this.viewport.applyConstraints(),!1;case 48:return this.viewport.goHome(),this.viewport.applyConstraints(),!1;case 119:case 87:return i.preventVerticalPan||(t.shift?this.viewport.zoomBy(1.1):this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(0,-40))),this.viewport.applyConstraints()),!1;case 115:case 83:return i.preventVerticalPan||(t.shift?this.viewport.zoomBy(.9):this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(0,40))),this.viewport.applyConstraints()),!1;case 97:return i.preventHorizontalPan||(this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(-40,0))),this.viewport.applyConstraints()),!1;case 100:return i.preventHorizontalPan||(this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(40,0))),this.viewport.applyConstraints()),!1;case 114:return this.viewport.flipped?this.viewport.setRotation(e.positiveModulo(this.viewport.degrees-this.rotationIncrement,360)):this.viewport.setRotation(e.positiveModulo(this.viewport.degrees+this.rotationIncrement,360)),this.viewport.applyConstraints(),!1;case 82:return this.viewport.flipped?this.viewport.setRotation(e.positiveModulo(this.viewport.degrees+this.rotationIncrement,360)):this.viewport.setRotation(e.positiveModulo(this.viewport.degrees-this.rotationIncrement,360)),this.viewport.applyConstraints(),!1;case 102:return this.viewport.toggleFlip(),!1;default:return!0}}function g(e){var t;document.activeElement==this.canvas||this.canvas.focus(),this.viewport.flipped&&(e.position.x=this.viewport.getContainerSize().x-e.position.x);var i={tracker:e.eventSource,position:e.position,quick:e.quick,shift:e.shift,originalEvent:e.originalEvent,preventDefaultAction:e.preventDefaultAction};this.raiseEvent("canvas-click",i),!i.preventDefaultAction&&this.viewport&&e.quick&&(t=this.gestureSettingsByDeviceType(e.pointerType)).clickToZoom&&(this.viewport.zoomBy(e.shift?1/this.zoomPerClick:this.zoomPerClick,t.zoomToRefPoint?this.viewport.pointFromPixel(e.position,!0):null),this.viewport.applyConstraints())}function m(e){var t,i={tracker:e.eventSource,position:e.position,shift:e.shift,originalEvent:e.originalEvent,preventDefaultAction:e.preventDefaultAction};this.raiseEvent("canvas-double-click",i),!i.preventDefaultAction&&this.viewport&&(t=this.gestureSettingsByDeviceType(e.pointerType)).dblClickToZoom&&(this.viewport.zoomBy(e.shift?1/this.zoomPerClick:this.zoomPerClick,t.zoomToRefPoint?this.viewport.pointFromPixel(e.position,!0):null),this.viewport.applyConstraints())}function f(e){var t,i={tracker:e.eventSource,position:e.position,delta:e.delta,speed:e.speed,direction:e.direction,shift:e.shift,originalEvent:e.originalEvent,preventDefaultAction:e.preventDefaultAction};if(this.raiseEvent("canvas-drag",i),!i.preventDefaultAction&&this.viewport){if(t=this.gestureSettingsByDeviceType(e.pointerType),this.panHorizontal||(e.delta.x=0),this.panVertical||(e.delta.y=0),this.viewport.flipped&&(e.delta.x=-e.delta.x),this.constrainDuringPan){var n=this.viewport.deltaPointsFromPixels(e.delta.negate());this.viewport.centerSpringX.target.value+=n.x,this.viewport.centerSpringY.target.value+=n.y;var r=this.viewport.getBounds(),o=this.viewport.getConstrainedBounds();this.viewport.centerSpringX.target.value-=n.x,this.viewport.centerSpringY.target.value-=n.y,r.x!=o.x&&(e.delta.x=0),r.y!=o.y&&(e.delta.y=0)}this.viewport.panBy(this.viewport.deltaPointsFromPixels(e.delta.negate()),t.flickEnabled&&!this.constrainDuringPan)}}function v(t){if(!t.preventDefaultAction&&this.viewport){var i=this.gestureSettingsByDeviceType(t.pointerType);if(i.flickEnabled&&t.speed>=i.flickMinSpeed){var n=0;this.panHorizontal&&(n=i.flickMomentum*t.speed*Math.cos(t.direction));var r=0;this.panVertical&&(r=i.flickMomentum*t.speed*Math.sin(t.direction));var o=this.viewport.pixelFromPoint(this.viewport.getCenter(!0)),s=this.viewport.pointFromPixel(new e.Point(o.x-n,o.y-r));this.viewport.panTo(s,!1)}this.viewport.applyConstraints()}this.raiseEvent("canvas-drag-end",{tracker:t.eventSource,position:t.position,speed:t.speed,direction:t.direction,shift:t.shift,originalEvent:t.originalEvent})}function y(e){this.raiseEvent("canvas-enter",{tracker:e.eventSource,pointerType:e.pointerType,position:e.position,buttons:e.buttons,pointers:e.pointers,insideElementPressed:e.insideElementPressed,buttonDownAny:e.buttonDownAny,originalEvent:e.originalEvent})}function w(t){window.location!=window.parent.location&&e.MouseTracker.resetAllMouseTrackers(),this.raiseEvent("canvas-exit",{tracker:t.eventSource,pointerType:t.pointerType,position:t.position,buttons:t.buttons,pointers:t.pointers,insideElementPressed:t.insideElementPressed,buttonDownAny:t.buttonDownAny,originalEvent:t.originalEvent})}function T(e){this.raiseEvent("canvas-press",{tracker:e.eventSource,pointerType:e.pointerType,position:e.position,insideElementPressed:e.insideElementPressed,insideElementReleased:e.insideElementReleased,originalEvent:e.originalEvent})}function _(e){this.raiseEvent("canvas-release",{tracker:e.eventSource,pointerType:e.pointerType,position:e.position,insideElementPressed:e.insideElementPressed,insideElementReleased:e.insideElementReleased,originalEvent:e.originalEvent})}function S(e){this.raiseEvent("canvas-nonprimary-press",{tracker:e.eventSource,position:e.position,pointerType:e.pointerType,button:e.button,buttons:e.buttons,originalEvent:e.originalEvent})}function x(e){this.raiseEvent("canvas-nonprimary-release",{tracker:e.eventSource,position:e.position,pointerType:e.pointerType,button:e.button,buttons:e.buttons,originalEvent:e.originalEvent})}function b(e){var t,i,n;if(!e.preventDefaultAction&&this.viewport&&((t=this.gestureSettingsByDeviceType(e.pointerType)).pinchToZoom&&(i=this.viewport.pointFromPixel(e.center,!0),n=this.viewport.pointFromPixel(e.lastCenter,!0).minus(i),this.panHorizontal||(n.x=0),this.panVertical||(n.y=0),this.viewport.zoomBy(e.distance/e.lastDistance,i,!0),t.zoomToRefPoint&&this.viewport.panBy(n,!0),this.viewport.applyConstraints()),t.pinchRotate)){var r=Math.atan2(e.gesturePoints[0].currentPos.y-e.gesturePoints[1].currentPos.y,e.gesturePoints[0].currentPos.x-e.gesturePoints[1].currentPos.x),o=Math.atan2(e.gesturePoints[0].lastPos.y-e.gesturePoints[1].lastPos.y,e.gesturePoints[0].lastPos.x-e.gesturePoints[1].lastPos.x);this.viewport.setRotation(this.viewport.getRotation()+(r-o)*(180/Math.PI))}return this.raiseEvent("canvas-pinch",{tracker:e.eventSource,gesturePoints:e.gesturePoints,lastCenter:e.lastCenter,center:e.center,lastDistance:e.lastDistance,distance:e.distance,shift:e.shift,originalEvent:e.originalEvent}),!1}function E(t){var i,n,r;if((r=e.now())-this._lastScrollTime>this.minScrollDeltaTime){if(this._lastScrollTime=r,this.viewport.flipped&&(t.position.x=this.viewport.getContainerSize().x-t.position.x),!t.preventDefaultAction&&this.viewport&&(i=this.gestureSettingsByDeviceType(t.pointerType)).scrollToZoom&&(n=Math.pow(this.zoomPerScroll,t.scroll),this.viewport.zoomBy(n,i.zoomToRefPoint?this.viewport.pointFromPixel(t.position,!0):null),this.viewport.applyConstraints()),this.raiseEvent("canvas-scroll",{tracker:t.eventSource,position:t.position,scroll:t.scroll,shift:t.shift,originalEvent:t.originalEvent}),i&&i.scrollToZoom)return!1}else if((i=this.gestureSettingsByDeviceType(t.pointerType))&&i.scrollToZoom)return!1}function P(e){t[this.hash].mouseInside=!0,c(this),this.raiseEvent("container-enter",{tracker:e.eventSource,position:e.position,buttons:e.buttons,pointers:e.pointers,insideElementPressed:e.insideElementPressed,buttonDownAny:e.buttonDownAny,originalEvent:e.originalEvent})}function R(e){e.pointers<1&&(t[this.hash].mouseInside=!1,t[this.hash].animating||l(this)),this.raiseEvent("container-exit",{tracker:e.eventSource,position:e.position,buttons:e.buttons,pointers:e.pointers,insideElementPressed:e.insideElementPressed,buttonDownAny:e.buttonDownAny,originalEvent:e.originalEvent})}function C(e){!function(e){if(e._opening)return;if(e.autoResize){var i=n(e.container),r=t[e.hash].prevContainerSize;if(!i.equals(r)){var o=e.viewport;if(e.preserveImageSizeOnResize){var s=r.x/i.x,a=o.getZoom()*s,u=o.getCenter();o.resize(i,!1),o.zoomTo(a,null,!0),o.panTo(u,!0)}else{var h=o.getBounds();o.resize(i,!0),o.fitBoundsWithConstraints(h,!0)}t[e.hash].prevContainerSize=i,t[e.hash].forceRedraw=!0}}var d=e.viewport.update(),p=e.world.update()||d;d&&e.raiseEvent("viewport-change");e.referenceStrip&&(p=e.referenceStrip.update(e.viewport)||p);!t[e.hash].animating&&p&&(e.raiseEvent("animation-start"),c(e));(p||t[e.hash].forceRedraw||e.world.needsDraw())&&(!function(e){e.imageLoader.clear(),e.drawer.clear(),e.world.draw(),e.raiseEvent("update-viewport",{})}(e),e._drawOverlays(),e.navigator&&e.navigator.update(e.viewport),t[e.hash].forceRedraw=!1,p&&e.raiseEvent("animation"));t[e.hash].animating&&!p&&(e.raiseEvent("animation-finish"),t[e.hash].mouseInside||l(e));t[e.hash].animating=p}(e),e.isOpen()?e._updateRequestId=s(e,C):e._updateRequestId=!1}function O(e,t){return e?e+t:t}function k(){t[this.hash].lastZoomTime=e.now(),t[this.hash].zoomFactor=this.zoomPerSecond,t[this.hash].zooming=!0,L(this)}function I(){t[this.hash].lastZoomTime=e.now(),t[this.hash].zoomFactor=1/this.zoomPerSecond,t[this.hash].zooming=!0,L(this)}function M(){t[this.hash].zooming=!1}function L(t){e.requestAnimationFrame(e.delegate(t,D))}function D(){var i,n,r;t[this.hash].zooming&&this.viewport&&(n=(i=e.now())-t[this.hash].lastZoomTime,r=Math.pow(t[this.hash].zoomFactor,n/1e3),this.viewport.zoomBy(r),this.viewport.applyConstraints(),t[this.hash].lastZoomTime=i,L(this))}function H(){this.viewport&&(t[this.hash].zooming=!1,this.viewport.zoomBy(this.zoomPerClick/1),this.viewport.applyConstraints())}function A(){this.viewport&&(t[this.hash].zooming=!1,this.viewport.zoomBy(1/this.zoomPerClick),this.viewport.applyConstraints())}function z(){this.buttons.emulateEnter(),this.buttons.emulateExit()}function B(){this.viewport&&this.viewport.goHome()}function F(){this.isFullPage()&&!e.isFullScreen()?this.setFullPage(!1):this.setFullScreen(!this.isFullPage()),this.buttons&&this.buttons.emulateExit(),this.fullPageButton.element.focus(),this.viewport&&this.viewport.applyConstraints()}function N(){if(this.viewport){var t=this.viewport.getRotation();t=this.viewport.flipped?e.positiveModulo(t+this.rotationIncrement,360):e.positiveModulo(t-this.rotationIncrement,360),this.viewport.setRotation(t)}}function j(){if(this.viewport){var t=this.viewport.getRotation();t=this.viewport.flipped?e.positiveModulo(t-this.rotationIncrement,360):e.positiveModulo(t+this.rotationIncrement,360),this.viewport.setRotation(t)}}function V(){this.viewport.toggleFlip()}function $(){var e=this._sequenceIndex-1;this.navPrevNextWrap&&e<0&&(e+=this.tileSources.length),this.goToPage(e)}function U(){var e=this._sequenceIndex+1;this.navPrevNextWrap&&e>=this.tileSources.length&&(e=0),this.goToPage(e)}e.Viewer=function(r){var o,a,c=arguments,u=this;if(e.isPlainObject(r)||(r={id:c[0],xmlPath:c.length>1?c[1]:void 0,prefixUrl:c.length>2?c[2]:void 0,controls:c.length>3?c[3]:void 0,overlays:c.length>4?c[4]:void 0}),r.config&&(e.extend(!0,r,r.config),delete r.config),e.extend(!0,this,{id:r.id,hash:r.hash||i++,initialPage:0,element:null,container:null,canvas:null,overlays:[],overlaysContainer:null,previousBody:[],customControls:[],source:null,drawer:null,world:null,viewport:null,navigator:null,collectionViewport:null,collectionDrawer:null,navImages:null,buttons:null,profiler:null},e.DEFAULT_SETTINGS,r),void 0===this.hash)throw new Error("A hash must be defined, either by specifying options.id or options.hash.");for(void 0!==t[this.hash]&&e.console.warn("Hash "+this.hash+" has already been used."),t[this.hash]={fsBoundsDelta:new e.Point(1,1),prevContainerSize:null,animating:!1,forceRedraw:!1,mouseInside:!1,group:null,zooming:!1,zoomFactor:null,lastZoomTime:null,fullPage:!1,onfullscreenchange:null},this._sequenceIndex=0,this._firstOpen=!0,this._updateRequestId=null,this._loadQueue=[],this.currentOverlays=[],this._lastScrollTime=e.now(),e.EventSource.call(this),this.addHandler("open-failed",(function(t){var i=e.getString("Errors.OpenFailed",t.eventSource,t.message);u._showMessage(i)})),e.ControlDock.call(this,r),this.xmlPath&&(this.tileSources=[this.xmlPath]),this.element=this.element||document.getElementById(this.id),this.canvas=e.makeNeutralElement("div"),this.canvas.className="openseadragon-canvas",(a=this.canvas.style).width="100%",a.height="100%",a.overflow="hidden",a.position="absolute",a.top="0px",a.left="0px",e.setElementTouchActionNone(this.canvas),""!==r.tabIndex&&(this.canvas.tabIndex=void 0===r.tabIndex?0:r.tabIndex),this.container.className="openseadragon-container",function(e){e.width="100%",e.height="100%",e.position="relative",e.overflow="hidden",e.left="0px",e.top="0px",e.textAlign="left"}(this.container.style),this.container.insertBefore(this.canvas,this.container.firstChild),this.element.appendChild(this.container),this.bodyWidth=document.body.style.width,this.bodyHeight=document.body.style.height,this.bodyOverflow=document.body.style.overflow,this.docOverflow=document.documentElement.style.overflow,this.innerTracker=new e.MouseTracker({element:this.canvas,startDisabled:!this.mouseNavEnabled,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,dblClickTimeThreshold:this.dblClickTimeThreshold,dblClickDistThreshold:this.dblClickDistThreshold,keyDownHandler:e.delegate(this,d),keyHandler:e.delegate(this,p),clickHandler:e.delegate(this,g),dblClickHandler:e.delegate(this,m),dragHandler:e.delegate(this,f),dragEndHandler:e.delegate(this,v),enterHandler:e.delegate(this,y),exitHandler:e.delegate(this,w),pressHandler:e.delegate(this,T),releaseHandler:e.delegate(this,_),nonPrimaryPressHandler:e.delegate(this,S),nonPrimaryReleaseHandler:e.delegate(this,x),scrollHandler:e.delegate(this,E),pinchHandler:e.delegate(this,b)}),this.outerTracker=new e.MouseTracker({element:this.container,startDisabled:!this.mouseNavEnabled,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,dblClickTimeThreshold:this.dblClickTimeThreshold,dblClickDistThreshold:this.dblClickDistThreshold,enterHandler:e.delegate(this,P),exitHandler:e.delegate(this,R)}),this.toolbar&&(this.toolbar=new e.ControlDock({element:this.toolbar})),this.bindStandardControls(),t[this.hash].prevContainerSize=n(this.container),this.world=new e.World({viewer:this}),this.world.addHandler("add-item",(function(e){u.source=u.world.getItemAt(0).source,t[u.hash].forceRedraw=!0,u._updateRequestId||(u._updateRequestId=s(u,C))})),this.world.addHandler("remove-item",(function(e){u.world.getItemCount()?u.source=u.world.getItemAt(0).source:u.source=null,t[u.hash].forceRedraw=!0})),this.world.addHandler("metrics-change",(function(e){u.viewport&&u.viewport._setContentBounds(u.world.getHomeBounds(),u.world.getContentFactor())})),this.world.addHandler("item-index-change",(function(e){u.source=u.world.getItemAt(0).source})),this.viewport=new e.Viewport({containerSize:t[this.hash].prevContainerSize,springStiffness:this.springStiffness,animationTime:this.animationTime,minZoomImageRatio:this.minZoomImageRatio,maxZoomPixelRatio:this.maxZoomPixelRatio,visibilityRatio:this.visibilityRatio,wrapHorizontal:this.wrapHorizontal,wrapVertical:this.wrapVertical,defaultZoomLevel:this.defaultZoomLevel,minZoomLevel:this.minZoomLevel,maxZoomLevel:this.maxZoomLevel,viewer:this,degrees:this.degrees,flipped:this.flipped,navigatorRotate:this.navigatorRotate,homeFillsViewer:this.homeFillsViewer,margins:this.viewportMargins}),this.viewport._setContentBounds(this.world.getHomeBounds(),this.world.getContentFactor()),this.imageLoader=new e.ImageLoader({jobLimit:this.imageLoaderLimit,timeout:r.timeout}),this.tileCache=new e.TileCache({maxImageCacheCount:this.maxImageCacheCount}),this.drawer=new e.Drawer({viewer:this,viewport:this.viewport,element:this.canvas,debugGridColor:this.debugGridColor}),this.overlaysContainer=e.makeNeutralElement("div"),this.canvas.appendChild(this.overlaysContainer),this.drawer.canRotate()||(this.rotateLeft&&(o=this.buttons.buttons.indexOf(this.rotateLeft),this.buttons.buttons.splice(o,1),this.buttons.element.removeChild(this.rotateLeft.element)),this.rotateRight&&(o=this.buttons.buttons.indexOf(this.rotateRight),this.buttons.buttons.splice(o,1),this.buttons.element.removeChild(this.rotateRight.element))),this.showNavigator&&(this.navigator=new e.Navigator({id:this.navigatorId,position:this.navigatorPosition,sizeRatio:this.navigatorSizeRatio,maintainSizeRatio:this.navigatorMaintainSizeRatio,top:this.navigatorTop,left:this.navigatorLeft,width:this.navigatorWidth,height:this.navigatorHeight,autoResize:this.navigatorAutoResize,autoFade:this.navigatorAutoFade,prefixUrl:this.prefixUrl,viewer:this,navigatorRotate:this.navigatorRotate,background:this.navigatorBackground,opacity:this.navigatorOpacity,borderColor:this.navigatorBorderColor,displayRegionColor:this.navigatorDisplayRegionColor,crossOriginPolicy:this.crossOriginPolicy})),this.sequenceMode&&this.bindSequenceControls(),this.tileSources&&this.open(this.tileSources),o=0;o-1&&t.index\s*$/))i=e.parseXml(i);else if(i.match(/^\s*[\{\[].*[\}\]]\s*$/))try{var a=e.parseJSON(i);i=a}catch(e){}function l(e,t){e.ready?r(e):(e.addHandler("ready",(function(){r(e)})),e.addHandler("open-failed",(function(e){o({message:e.message,source:t})})))}setTimeout((function(){if("string"==e.type(i))(i=new e.TileSource({url:i,crossOriginPolicy:void 0!==n.crossOriginPolicy?n.crossOriginPolicy:t.crossOriginPolicy,ajaxWithCredentials:t.ajaxWithCredentials,ajaxHeaders:t.ajaxHeaders,useCanvas:t.useCanvas,success:function(e){r(e.tileSource)}})).addHandler("open-failed",(function(e){o(e)}));else if(e.isPlainObject(i)||i.nodeType)if(void 0!==i.crossOriginPolicy||void 0===n.crossOriginPolicy&&void 0===t.crossOriginPolicy||(i.crossOriginPolicy=void 0!==n.crossOriginPolicy?n.crossOriginPolicy:t.crossOriginPolicy),void 0===i.ajaxWithCredentials&&(i.ajaxWithCredentials=t.ajaxWithCredentials),void 0===i.useCanvas&&(i.useCanvas=t.useCanvas),e.isFunction(i.getTileUrl)){var a=new e.TileSource(i);a.getTileUrl=i.getTileUrl,r(a)}else{var c=e.TileSource.determineType(s,i);if(!c)return void o({message:"Unable to load TileSource",source:i});var u=c.prototype.configure.apply(s,[i]);l(new c(u),i)}else l(i,i)}))}(this,t.tileSource,t,(function(e){n.tileSource=e,s()}),(function(e){e.options=t,r(e),s()})))},addSimpleImage:function(t){e.console.assert(t,"[Viewer.addSimpleImage] options is required"),e.console.assert(t.url,"[Viewer.addSimpleImage] options.url is required");var i=e.extend({},t,{tileSource:{type:"image",url:t.url}});delete i.url,this.addTiledImage(i)},addLayer:function(t){var i=this;e.console.error("[Viewer.addLayer] this function is deprecated; use Viewer.addTiledImage() instead.");var n=e.extend({},t,{success:function(e){i.raiseEvent("add-layer",{options:t,drawer:e.item})},error:function(e){i.raiseEvent("add-layer-failed",e)}});return this.addTiledImage(n),this},getLayerAtLevel:function(t){return e.console.error("[Viewer.getLayerAtLevel] this function is deprecated; use World.getItemAt() instead."),this.world.getItemAt(t)},getLevelOfLayer:function(t){return e.console.error("[Viewer.getLevelOfLayer] this function is deprecated; use World.getIndexOfItem() instead."),this.world.getIndexOfItem(t)},getLayersCount:function(){return e.console.error("[Viewer.getLayersCount] this function is deprecated; use World.getItemCount() instead."),this.world.getItemCount()},setLayerLevel:function(t,i){return e.console.error("[Viewer.setLayerLevel] this function is deprecated; use World.setItemIndex() instead."),this.world.setItemIndex(t,i)},removeLayer:function(t){return e.console.error("[Viewer.removeLayer] this function is deprecated; use World.removeItem() instead."),this.world.removeItem(t)},forceRedraw:function(){return t[this.hash].forceRedraw=!0,this},bindSequenceControls:function(){var t=e.delegate(this,u),i=e.delegate(this,h),n=e.delegate(this,U),r=e.delegate(this,$),o=this.navImages,s=!0;return this.showSequenceControl&&((this.previousButton||this.nextButton)&&(s=!1),this.previousButton=new e.Button({element:this.previousButton?e.getElement(this.previousButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.PreviousPage"),srcRest:O(this.prefixUrl,o.previous.REST),srcGroup:O(this.prefixUrl,o.previous.GROUP),srcHover:O(this.prefixUrl,o.previous.HOVER),srcDown:O(this.prefixUrl,o.previous.DOWN),onRelease:r,onFocus:t,onBlur:i}),this.nextButton=new e.Button({element:this.nextButton?e.getElement(this.nextButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.NextPage"),srcRest:O(this.prefixUrl,o.next.REST),srcGroup:O(this.prefixUrl,o.next.GROUP),srcHover:O(this.prefixUrl,o.next.HOVER),srcDown:O(this.prefixUrl,o.next.DOWN),onRelease:n,onFocus:t,onBlur:i}),this.navPrevNextWrap||this.previousButton.disable(),this.tileSources&&this.tileSources.length||this.nextButton.disable(),s&&(this.paging=new e.ButtonGroup({buttons:[this.previousButton,this.nextButton],clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold}),this.pagingControl=this.paging.element,this.toolbar?this.toolbar.addControl(this.pagingControl,{anchor:e.ControlAnchor.BOTTOM_RIGHT}):this.addControl(this.pagingControl,{anchor:this.sequenceControlAnchor||e.ControlAnchor.TOP_LEFT}))),this},bindStandardControls:function(){var t=e.delegate(this,k),i=e.delegate(this,M),n=e.delegate(this,H),r=e.delegate(this,I),o=e.delegate(this,A),s=e.delegate(this,B),a=e.delegate(this,F),l=e.delegate(this,N),c=e.delegate(this,j),d=e.delegate(this,V),p=e.delegate(this,u),g=e.delegate(this,h),m=this.navImages,f=[],v=!0;return this.showNavigationControl&&((this.zoomInButton||this.zoomOutButton||this.homeButton||this.fullPageButton||this.rotateLeftButton||this.rotateRightButton||this.flipButton)&&(v=!1),this.showZoomControl&&(f.push(this.zoomInButton=new e.Button({element:this.zoomInButton?e.getElement(this.zoomInButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.ZoomIn"),srcRest:O(this.prefixUrl,m.zoomIn.REST),srcGroup:O(this.prefixUrl,m.zoomIn.GROUP),srcHover:O(this.prefixUrl,m.zoomIn.HOVER),srcDown:O(this.prefixUrl,m.zoomIn.DOWN),onPress:t,onRelease:i,onClick:n,onEnter:t,onExit:i,onFocus:p,onBlur:g})),f.push(this.zoomOutButton=new e.Button({element:this.zoomOutButton?e.getElement(this.zoomOutButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.ZoomOut"),srcRest:O(this.prefixUrl,m.zoomOut.REST),srcGroup:O(this.prefixUrl,m.zoomOut.GROUP),srcHover:O(this.prefixUrl,m.zoomOut.HOVER),srcDown:O(this.prefixUrl,m.zoomOut.DOWN),onPress:r,onRelease:i,onClick:o,onEnter:r,onExit:i,onFocus:p,onBlur:g}))),this.showHomeControl&&f.push(this.homeButton=new e.Button({element:this.homeButton?e.getElement(this.homeButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.Home"),srcRest:O(this.prefixUrl,m.home.REST),srcGroup:O(this.prefixUrl,m.home.GROUP),srcHover:O(this.prefixUrl,m.home.HOVER),srcDown:O(this.prefixUrl,m.home.DOWN),onRelease:s,onFocus:p,onBlur:g})),this.showFullPageControl&&f.push(this.fullPageButton=new e.Button({element:this.fullPageButton?e.getElement(this.fullPageButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.FullPage"),srcRest:O(this.prefixUrl,m.fullpage.REST),srcGroup:O(this.prefixUrl,m.fullpage.GROUP),srcHover:O(this.prefixUrl,m.fullpage.HOVER),srcDown:O(this.prefixUrl,m.fullpage.DOWN),onRelease:a,onFocus:p,onBlur:g})),this.showRotationControl&&(f.push(this.rotateLeftButton=new e.Button({element:this.rotateLeftButton?e.getElement(this.rotateLeftButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.RotateLeft"),srcRest:O(this.prefixUrl,m.rotateleft.REST),srcGroup:O(this.prefixUrl,m.rotateleft.GROUP),srcHover:O(this.prefixUrl,m.rotateleft.HOVER),srcDown:O(this.prefixUrl,m.rotateleft.DOWN),onRelease:l,onFocus:p,onBlur:g})),f.push(this.rotateRightButton=new e.Button({element:this.rotateRightButton?e.getElement(this.rotateRightButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.RotateRight"),srcRest:O(this.prefixUrl,m.rotateright.REST),srcGroup:O(this.prefixUrl,m.rotateright.GROUP),srcHover:O(this.prefixUrl,m.rotateright.HOVER),srcDown:O(this.prefixUrl,m.rotateright.DOWN),onRelease:c,onFocus:p,onBlur:g}))),this.showFlipControl&&f.push(this.flipButton=new e.Button({element:this.flipButton?e.getElement(this.flipButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.Flip"),srcRest:O(this.prefixUrl,m.flip.REST),srcGroup:O(this.prefixUrl,m.flip.GROUP),srcHover:O(this.prefixUrl,m.flip.HOVER),srcDown:O(this.prefixUrl,m.flip.DOWN),onRelease:d,onFocus:p,onBlur:g})),v&&(this.buttons=new e.ButtonGroup({buttons:f,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold}),this.navControl=this.buttons.element,this.addHandler("open",e.delegate(this,z)),this.toolbar?this.toolbar.addControl(this.navControl,{anchor:this.navigationControlAnchor||e.ControlAnchor.TOP_LEFT}):this.addControl(this.navControl,{anchor:this.navigationControlAnchor||e.ControlAnchor.TOP_LEFT}))),this},currentPage:function(){return this._sequenceIndex},goToPage:function(e){return this.tileSources&&e>=0&&e=0)return this;var l=r(this,a);return this.currentOverlays.push(l),l.drawHTML(this.overlaysContainer,this.viewport),this.raiseEvent("add-overlay",{element:t,location:a.location,placement:a.placement}),this},updateOverlay:function(i,n,r){var s;return i=e.getElement(i),(s=o(this.currentOverlays,i))>=0&&(this.currentOverlays[s].update(n,r),t[this.hash].forceRedraw=!0,this.raiseEvent("update-overlay",{element:i,location:n,placement:r})),this},removeOverlay:function(i){var n;return i=e.getElement(i),(n=o(this.currentOverlays,i))>=0&&(this.currentOverlays[n].destroy(),this.currentOverlays.splice(n,1),t[this.hash].forceRedraw=!0,this.raiseEvent("remove-overlay",{element:i})),this},clearOverlays:function(){for(;this.currentOverlays.length>0;)this.currentOverlays.pop().destroy();return t[this.hash].forceRedraw=!0,this.raiseEvent("clear-overlay",{}),this},getOverlayById:function(t){var i;return t=e.getElement(t),(i=o(this.currentOverlays,t))>=0?this.currentOverlays[i]:null},_updateSequenceButtons:function(e){this.nextButton&&(this.tileSources&&this.tileSources.length-1!==e?this.nextButton.enable():this.navPrevNextWrap||this.nextButton.disable()),this.previousButton&&(e>0?this.previousButton.enable():this.navPrevNextWrap||this.previousButton.disable())},_showMessage:function(t){this._hideMessage();var i=e.makeNeutralElement("div");i.appendChild(document.createTextNode(t)),this.messageDiv=e.makeCenteredNode(i),e.addClass(this.messageDiv,"openseadragon-message"),this.container.appendChild(this.messageDiv)},_hideMessage:function(){var e=this.messageDiv;e&&(e.parentNode.removeChild(e),delete this.messageDiv)},gestureSettingsByDeviceType:function(e){switch(e){case"mouse":return this.gestureSettingsMouse;case"touch":return this.gestureSettingsTouch;case"pen":return this.gestureSettingsPen;default:return this.gestureSettingsUnknown}},_drawOverlays:function(){var e,t=this.currentOverlays.length;for(e=0;e1&&(this.referenceStrip=new e.ReferenceStrip({id:this.referenceStripElement,position:this.referenceStripPosition,sizeRatio:this.referenceStripSizeRatio,scroll:this.referenceStripScroll,height:this.referenceStripHeight,width:this.referenceStripWidth,tileSources:this.tileSources,prefixUrl:this.prefixUrl,viewer:this}),this.referenceStrip.setFocus(this._sequenceIndex))}else e.console.warn('Attempting to display a reference strip while "sequenceMode" is off.')}})}(OpenSeadragon),function(e){function t(e){var t={tracker:e.eventSource,position:e.position,quick:e.quick,shift:e.shift,originalEvent:e.originalEvent,preventDefaultAction:e.preventDefaultAction};if(this.viewer.raiseEvent("navigator-click",t),!t.preventDefaultAction&&e.quick&&this.viewer.viewport&&(this.panVertical||this.panHorizontal)){this.viewer.viewport.flipped&&(e.position.x=this.viewport.getContainerSize().x-e.position.x);var i=this.viewport.pointFromPixel(e.position);this.panVertical?this.panHorizontal||(i.x=this.viewer.viewport.getCenter(!0).x):i.y=this.viewer.viewport.getCenter(!0).y,this.viewer.viewport.panTo(i),this.viewer.viewport.applyConstraints()}}function i(e){var t={tracker:e.eventSource,position:e.position,delta:e.delta,speed:e.speed,direction:e.direction,shift:e.shift,originalEvent:e.originalEvent,preventDefaultAction:e.preventDefaultAction};this.viewer.raiseEvent("navigator-drag",t),!t.preventDefaultAction&&this.viewer.viewport&&(this.panHorizontal||(e.delta.x=0),this.panVertical||(e.delta.y=0),this.viewer.viewport.flipped&&(e.delta.x=-e.delta.x),this.viewer.viewport.panBy(this.viewport.deltaPointsFromPixels(e.delta)),this.viewer.constrainDuringPan&&this.viewer.viewport.applyConstraints())}function n(e){e.insideElementPressed&&this.viewer.viewport&&this.viewer.viewport.applyConstraints()}function r(e){return this.viewer.raiseEvent("navigator-scroll",{tracker:e.eventSource,position:e.position,scroll:e.scroll,shift:e.shift,originalEvent:e.originalEvent}),!1}function o(e,t){s(e,"rotate("+t+"deg)")}function s(e,t){e.style.webkitTransform=t,e.style.mozTransform=t,e.style.msTransform=t,e.style.oTransform=t,e.style.transform=t}e.Navigator=function(s){var a,l,c,u,h=s.viewer,d=this;function p(e){o(d.displayRegionContainer,e),o(d.displayRegion,-e),d.viewport.setRotation(e)}(s.id?(this.element=document.getElementById(s.id),s.controlOptions={anchor:e.ControlAnchor.NONE,attachToViewer:!1,autoFade:!1}):(s.id="navigator-"+e.now(),this.element=e.makeNeutralElement("div"),s.controlOptions={anchor:e.ControlAnchor.TOP_RIGHT,attachToViewer:!0,autoFade:s.autoFade},s.position&&("BOTTOM_RIGHT"==s.position?s.controlOptions.anchor=e.ControlAnchor.BOTTOM_RIGHT:"BOTTOM_LEFT"==s.position?s.controlOptions.anchor=e.ControlAnchor.BOTTOM_LEFT:"TOP_RIGHT"==s.position?s.controlOptions.anchor=e.ControlAnchor.TOP_RIGHT:"TOP_LEFT"==s.position?s.controlOptions.anchor=e.ControlAnchor.TOP_LEFT:"ABSOLUTE"==s.position&&(s.controlOptions.anchor=e.ControlAnchor.ABSOLUTE,s.controlOptions.top=s.top,s.controlOptions.left=s.left,s.controlOptions.height=s.height,s.controlOptions.width=s.width))),this.element.id=s.id,this.element.className+=" navigator",(s=e.extend(!0,{sizeRatio:e.DEFAULT_SETTINGS.navigatorSizeRatio},s,{element:this.element,tabIndex:-1,showNavigator:!1,mouseNavEnabled:!1,showNavigationControl:!1,showSequenceControl:!1,immediateRender:!0,blendTime:0,animationTime:0,autoResize:s.autoResize,minZoomImageRatio:1,background:s.background,opacity:s.opacity,borderColor:s.borderColor,displayRegionColor:s.displayRegionColor})).minPixelRatio=this.minPixelRatio=h.minPixelRatio,e.setElementTouchActionNone(this.element),this.borderWidth=2,this.fudge=new e.Point(1,1),this.totalBorderWidths=new e.Point(2*this.borderWidth,2*this.borderWidth).minus(this.fudge),s.controlOptions.anchor!=e.ControlAnchor.NONE&&(c=this.element.style,u=this.borderWidth,c.margin="0px",c.border=u+"px solid "+s.borderColor,c.padding="0px",c.background=s.background,c.opacity=s.opacity,c.overflow="hidden"),this.displayRegion=e.makeNeutralElement("div"),this.displayRegion.id=this.element.id+"-displayregion",this.displayRegion.className="displayregion",function(e,t){e.position="relative",e.top="0px",e.left="0px",e.fontSize="0px",e.overflow="hidden",e.border=t+"px solid "+s.displayRegionColor,e.margin="0px",e.padding="0px",e.background="transparent",e.float="left",e.cssFloat="left",e.styleFloat="left",e.zIndex=999999999,e.cursor="default"}(this.displayRegion.style,this.borderWidth),this.displayRegionContainer=e.makeNeutralElement("div"),this.displayRegionContainer.id=this.element.id+"-displayregioncontainer",this.displayRegionContainer.className="displayregioncontainer",this.displayRegionContainer.style.width="100%",this.displayRegionContainer.style.height="100%",h.addControl(this.element,s.controlOptions),this._resizeWithViewer=s.controlOptions.anchor!=e.ControlAnchor.ABSOLUTE&&s.controlOptions.anchor!=e.ControlAnchor.NONE,this._resizeWithViewer&&(s.width&&s.height?(this.element.style.height="number"==typeof s.height?s.height+"px":s.height,this.element.style.width="number"==typeof s.width?s.width+"px":s.width):(a=e.getElementSize(h.element),this.element.style.height=Math.round(a.y*s.sizeRatio)+"px",this.element.style.width=Math.round(a.x*s.sizeRatio)+"px",this.oldViewerSize=a),l=e.getElementSize(this.element),this.elementArea=l.x*l.y),this.oldContainerSize=new e.Point(0,0),e.Viewer.apply(this,[s]),this.displayRegionContainer.appendChild(this.displayRegion),this.element.getElementsByTagName("div")[0].appendChild(this.displayRegionContainer),s.navigatorRotate)&&(p(s.viewer.viewport?s.viewer.viewport.getRotation():s.viewer.degrees||0),s.viewer.addHandler("rotate",(function(e){p(e.degrees)})));this.innerTracker.destroy(),this.innerTracker=new e.MouseTracker({element:this.element,dragHandler:e.delegate(this,i),clickHandler:e.delegate(this,t),releaseHandler:e.delegate(this,n),scrollHandler:e.delegate(this,r)}),this.addHandler("reset-size",(function(){d.viewport&&d.viewport.goHome(!0)})),h.world.addHandler("item-index-change",(function(e){window.setTimeout((function(){var t=d.world.getItemAt(e.previousIndex);d.world.setItemIndex(t,e.newIndex)}),1)})),h.world.addHandler("remove-item",(function(e){var t=e.item,i=d._getMatchingItem(t);i&&d.world.removeItem(i)})),this.update(h.viewport)},e.extend(e.Navigator.prototype,e.EventSource.prototype,e.Viewer.prototype,{updateSize:function(){if(this.viewport){var t=new e.Point(0===this.container.clientWidth?1:this.container.clientWidth,0===this.container.clientHeight?1:this.container.clientHeight);t.equals(this.oldContainerSize)||(this.viewport.resize(t,!0),this.viewport.goHome(!0),this.oldContainerSize=t,this.drawer.clear(),this.world.draw())}},setFlip:function(e){return this.viewport.setFlip(e),this.setDisplayTransform(this.viewer.viewport.getFlip()?"scale(-1,1)":"scale(1,1)"),this},setDisplayTransform:function(e){s(this.displayRegion,e),s(this.canvas,e),s(this.element,e)},update:function(t){var i,n,r,o,s,a;if(i=e.getElementSize(this.viewer.element),this._resizeWithViewer&&i.x&&i.y&&!i.equals(this.oldViewerSize)&&(this.oldViewerSize=i,this.maintainSizeRatio||!this.elementArea?(n=i.x*this.sizeRatio,r=i.y*this.sizeRatio):(n=Math.sqrt(this.elementArea*(i.x/i.y)),r=this.elementArea/n),this.element.style.width=Math.round(n)+"px",this.element.style.height=Math.round(r)+"px",this.elementArea||(this.elementArea=n*r),this.updateSize()),t&&this.viewport){o=t.getBoundsNoRotate(!0),s=this.viewport.pixelFromPointNoRotate(o.getTopLeft(),!1),a=this.viewport.pixelFromPointNoRotate(o.getBottomRight(),!1).minus(this.totalBorderWidths);var l=this.displayRegion.style;l.display=this.world.getItemCount()?"block":"none",l.top=Math.round(s.y)+"px",l.left=Math.round(s.x)+"px";var c=Math.abs(s.x-a.x),u=Math.abs(s.y-a.y);l.width=Math.round(Math.max(c,0))+"px",l.height=Math.round(Math.max(u,0))+"px"}},addTiledImage:function(t){var i=this,n=t.originalTiledImage;delete t.original;var r=e.extend({},t,{success:function(e){var t=e.item;function r(){i._matchBounds(t,n)}t._originalForNavigator=n,i._matchBounds(t,n,!0),n.addHandler("bounds-change",r),n.addHandler("clip-change",r),n.addHandler("opacity-change",(function(){i._matchOpacity(t,n)})),n.addHandler("composite-operation-change",(function(){i._matchCompositeOperation(t,n)}))}});return e.Viewer.prototype.addTiledImage.apply(this,[r])},_getMatchingItem:function(e){for(var t,i=this.world.getItemCount(),n=0;n1||t.y>1);e++);return e-1},getTileAtPoint:function(t,i){var n=i.x>=0&&i.x<=1&&i.y>=0&&i.y<=1/this.aspectRatio;e.console.assert(n,"[TileSource.getTileAtPoint] must be called with a valid point.");var r=this.dimensions.x*this.getLevelScale(t),o=i.x*r,s=i.y*r,a=Math.floor(o/this.getTileWidth(t)),l=Math.floor(s/this.getTileHeight(t));i.x>=1&&(a=this.getNumTiles(t).x-1);return i.y>=1/this.aspectRatio-1e-15&&(l=this.getNumTiles(t).y-1),new e.Point(a,l)},getTileBounds:function(t,i,n,r){var o=this.dimensions.times(this.getLevelScale(t)),s=this.getTileWidth(t),a=this.getTileHeight(t),l=0===i?0:s*i-this.tileOverlap,c=0===n?0:a*n-this.tileOverlap,u=s+(0===i?1:2)*this.tileOverlap,h=a+(0===n?1:2)*this.tileOverlap,d=1/o.x;return u=Math.min(u,o.x-l),h=Math.min(h,o.y-c),r?new e.Rect(0,0,u,h):new e.Rect(l*d,c*d,u*d,h*d)},getImageInfo:function(t){var i,n,r,o,s,a,l,c=this;t&&(l=(a=(s=t.split("/"))[s.length-1]).lastIndexOf("."))>-1&&(s[s.length-1]=a.slice(0,l)),n=function(i){"string"==typeof i&&(i=e.parseXml(i));var n=e.TileSource.determineType(c,i,t);n?(void 0===(o=n.prototype.configure.apply(c,[i,t])).ajaxWithCredentials&&(o.ajaxWithCredentials=c.ajaxWithCredentials),r=new n(o),c.ready=!0,c.raiseEvent("ready",{tileSource:r})):c.raiseEvent("open-failed",{message:"Unable to load TileSource",source:t})},t.match(/\.js$/)?(i=t.split("/").pop().replace(".js",""),e.jsonp({url:t,async:!1,callbackName:i,callback:n})):e.makeAjaxRequest({url:t,withCredentials:this.ajaxWithCredentials,headers:this.ajaxHeaders,success:function(t){var i=function(t){var i,n,r=t.responseText,o=t.status;if(!t)throw new Error(e.getString("Errors.Security"));if(200!==t.status&&0!==t.status)throw o=t.status,i=404==o?"Not Found":t.statusText,new Error(e.getString("Errors.Status",o,i));if(r.match(/\s*<.*/))try{n=t.responseXML&&t.responseXML.documentElement?t.responseXML:e.parseXml(r)}catch(e){n=t.responseText}else if(r.match(/\s*[\{\[].*/))try{n=e.parseJSON(r)}catch(e){n=r}else n=r;return n}(t);n(i)},error:function(e,i){var n;try{n="HTTP "+e.status+" attempting to load TileSource"}catch(e){n=(void 0!==i&&i.toString?i.toString():"Unknown error")+" attempting to load TileSource"}c.raiseEvent("open-failed",{message:n,source:t})}})},supports:function(e,t){return!1},configure:function(e,t){throw new Error("Method not implemented.")},getTileUrl:function(e,t,i){throw new Error("Method not implemented.")},getTileAjaxHeaders:function(e,t,i){return{}},tileExists:function(e,t,i){var n=this.getNumTiles(e);return e>=this.minLevel&&e<=this.maxLevel&&t>=0&&i>=0&&t=0;u--)for(d=(h=this.displayRects[u]).minLevel;d<=h.maxLevel;d++)this._levelRects[d]||(this._levelRects[d]=[]),this._levelRects[d].push(h);e.TileSource.apply(this,[p])},e.extend(e.DziTileSource.prototype,e.TileSource.prototype,{supports:function(e,t){var i;return e.Image?i=e.Image.xmlns:e.documentElement&&("Image"!=e.documentElement.localName&&"Image"!=e.documentElement.tagName||(i=e.documentElement.namespaceURI)),-1!==(i=(i||"").toLowerCase()).indexOf("schemas.microsoft.com/deepzoom/2008")||-1!==i.indexOf("schemas.microsoft.com/deepzoom/2009")},configure:function(i,n){var r;return r=e.isPlainObject(i)?t(this,i):function(i,n){if(!n||!n.documentElement)throw new Error(e.getString("Errors.Xml"));var r,o,s,a,l,c=n.documentElement,u=c.localName||c.tagName,h=n.documentElement.namespaceURI,d=null,p=[];if("Image"==u)try{if(void 0===(a=c.getElementsByTagName("Size")[0])&&(a=c.getElementsByTagNameNS(h,"Size")[0]),d={Image:{xmlns:"http://schemas.microsoft.com/deepzoom/2008",Url:c.getAttribute("Url"),Format:c.getAttribute("Format"),DisplayRect:null,Overlap:parseInt(c.getAttribute("Overlap"),10),TileSize:parseInt(c.getAttribute("TileSize"),10),Size:{Height:parseInt(a.getAttribute("Height"),10),Width:parseInt(a.getAttribute("Width"),10)}}},!e.imageFormatSupported(d.Image.Format))throw new Error(e.getString("Errors.ImageFormat",d.Image.Format.toUpperCase()));for(void 0===(r=c.getElementsByTagName("DisplayRect"))&&(r=c.getElementsByTagNameNS(h,"DisplayRect")[0]),l=0;lthis.maxLevel)return!1;if(!u||!u.length)return!0;for(c=u.length-1;c>=0;c--)if(!(e<(n=u[c]).minLevel||e>n.maxLevel)&&(r=this.getLevelScale(e),o=n.x*r,s=n.y*r,a=o+n.width*r,l=s+n.height*r,o=Math.floor(o/this._tileWidth),s=Math.floor(s/this._tileWidth),a=Math.ceil(a/this._tileWidth),l=Math.ceil(l/this._tileWidth),o<=t&&t1&&e[1].supports&&(i=-1!==e[1].supports.indexOf("sizeByW"));return!t||i}(t.profile)){for(var o=Math.min(this.height,this.width),s=[256,512,1024],a=[],l=0;l0?t.tileSize=Math.max.apply(null,a):t.tileSize=o}else this.sizes&&this.sizes.length>0?(this.emulateLegacyImagePyramid=!0,t.levels=function(e){for(var t=[],i=0;i0&&t>=this.minLevel&&t<=this.maxLevel&&(i=this.levels[t].width/this.levels[this.maxLevel].width),i}return e.TileSource.prototype.getLevelScale.call(this,t)},getNumTiles:function(t){return this.emulateLegacyImagePyramid?this.getLevelScale(t)?new e.Point(1,1):new e.Point(0,0):e.TileSource.prototype.getNumTiles.call(this,t)},getTileAtPoint:function(t,i){return this.emulateLegacyImagePyramid?new e.Point(0,0):e.TileSource.prototype.getTileAtPoint.call(this,t,i)},getTileUrl:function(e,t,i){if(this.emulateLegacyImagePyramid){var n=null;return this.levels.length>0&&e>=this.minLevel&&e<=this.maxLevel&&(n=this.levels[e].url),n}var r,o,s,a,l,c,u,h,d,p,g,m,f,v=Math.pow(.5,this.maxLevel-e),y=Math.ceil(this.width*v),w=Math.ceil(this.height*v);return r=this.getTileWidth(e),o=this.getTileHeight(e),s=Math.ceil(r/v),a=Math.ceil(o/v),m=(f=this["@context"].indexOf("/1.0/context.json")>-1||this["@context"].indexOf("/1.1/context.json")>-1||this["@context"].indexOf("/1/context.json")>-1)?"native."+this.tileFormat:"default."+this.tileFormat,yc?l/256:c/256,s.maxLevel=Math.ceil(Math.log(a)/Math.log(2))-1,s.tileSize=256,s.width=l,s.height=c,e.TileSource.apply(this,[s])},e.extend(e.TmsTileSource.prototype,e.TileSource.prototype,{supports:function(e,t){return e.type&&"tiledmapservice"==e.type},configure:function(e,t){return e},getTileUrl:function(e,t,i){var n=this.getNumTiles(e).y-1;return this.tilesUrl+e+"/"+t+"/"+(n-i)+".png"}})}(OpenSeadragon),function(e){e.ZoomifyTileSource=function(e){e.tileSize=256;var t={x:e.width,y:e.height};for(e.imageSizes=[{x:e.width,y:e.height}],e.gridSize=[this._getGridSize(e.width,e.height,e.tileSize)];parseInt(t.x,10)>e.tileSize||parseInt(t.y,10)>e.tileSize;)t.x=Math.floor(t.x/2),t.y=Math.floor(t.y/2),e.imageSizes.push({x:t.x,y:t.y}),e.gridSize.push(this._getGridSize(t.x,t.y,e.tileSize));e.imageSizes.reverse(),e.gridSize.reverse(),e.minLevel=0,e.maxLevel=e.gridSize.length-1,OpenSeadragon.TileSource.apply(this,[e])},e.extend(e.ZoomifyTileSource.prototype,e.TileSource.prototype,{_getGridSize:function(e,t,i){return{x:Math.ceil(e/i),y:Math.ceil(t/i)}},_calculateAbsoluteTileNumber:function(e,t,i){for(var n=0,r={},o=0;o");return r.sort((function(e,t){return e.height-t.height}))}(i.levels),i.levels.length>0?(n=i.levels[i.levels.length-1].width,r=i.levels[i.levels.length-1].height):(n=0,r=0,e.console.error("No supported image formats found")),e.extend(!0,i,{width:n,height:r,tileSize:Math.max(r,n),tileOverlap:0,minLevel:0,maxLevel:i.levels.length>0?i.levels.length-1:0}),e.TileSource.apply(this,[i]),this.levels=i.levels},e.extend(e.LegacyTileSource.prototype,e.TileSource.prototype,{supports:function(e,t){return e.type&&"legacy-image-pyramid"==e.type||e.documentElement&&"legacy-image-pyramid"==e.documentElement.getAttribute("type")},configure:function(i,n){return e.isPlainObject(i)?t(this,i):function(i,n){if(!n||!n.documentElement)throw new Error(e.getString("Errors.Xml"));var r,o,s=n.documentElement,a=s.tagName,l=null,c=[];if("image"==a)try{for(l={type:s.getAttribute("type"),levels:[]},c=s.getElementsByTagName("level"),o=0;o0&&e>=this.minLevel&&e<=this.maxLevel&&(t=this.levels[e].width/this.levels[this.maxLevel].width),t},getNumTiles:function(t){return this.getLevelScale(t)?new e.Point(1,1):new e.Point(0,0)},getTileUrl:function(e,t,i){var n=null;return this.levels.length>0&&e>=this.minLevel&&e<=this.maxLevel&&(n=this.levels[e].url),n}})}(OpenSeadragon),function(e){e.ImageTileSource=function(t){t=e.extend({buildPyramid:!0,crossOriginPolicy:!1,ajaxWithCredentials:!1,useCanvas:!0},t),e.TileSource.apply(this,[t])},e.extend(e.ImageTileSource.prototype,e.TileSource.prototype,{supports:function(e,t){return e.type&&"image"===e.type},configure:function(e,t){return e},getImageInfo:function(t){var i=this._image=new Image,n=this;this.crossOriginPolicy&&(i.crossOrigin=this.crossOriginPolicy),this.ajaxWithCredentials&&(i.useCredentials=this.ajaxWithCredentials),e.addEvent(i,"load",(function(){n.width=Object.prototype.hasOwnProperty.call(i,"naturalWidth")?i.naturalWidth:i.width,n.height=Object.prototype.hasOwnProperty.call(i,"naturalHeight")?i.naturalHeight:i.height,n.aspectRatio=n.width/n.height,n.dimensions=new e.Point(n.width,n.height),n._tileWidth=n.width,n._tileHeight=n.height,n.tileOverlap=0,n.minLevel=0,n.levels=n._buildLevels(),n.maxLevel=n.levels.length-1,n.ready=!0,n.raiseEvent("ready",{tileSource:n})})),e.addEvent(i,"error",(function(){n.raiseEvent("open-failed",{message:"Error loading image at "+t,source:t})})),i.src=t},getLevelScale:function(e){var t=NaN;return e>=this.minLevel&&e<=this.maxLevel&&(t=this.levels[e].width/this.levels[this.maxLevel].width),t},getNumTiles:function(t){return this.getLevelScale(t)?new e.Point(1,1):new e.Point(0,0)},getTileUrl:function(e,t,i){var n=null;return e>=this.minLevel&&e<=this.maxLevel&&(n=this.levels[e].url),n},getContext2D:function(e,t,i){var n=null;return e>=this.minLevel&&e<=this.maxLevel&&(n=this.levels[e].context2D),n},_buildLevels:function(){var t=[{url:this._image.src,width:Object.prototype.hasOwnProperty.call(this._image,"naturalWidth")?this._image.naturalWidth:this._image.width,height:Object.prototype.hasOwnProperty.call(this._image,"naturalHeight")?this._image.naturalHeight:this._image.height}];if(!this.buildPyramid||!e.supportsCanvas||!this.useCanvas)return delete this._image,t;var i=Object.prototype.hasOwnProperty.call(this._image,"naturalWidth")?this._image.naturalWidth:this._image.width,n=Object.prototype.hasOwnProperty.call(this._image,"naturalHeight")?this._image.naturalHeight:this._image.height,r=document.createElement("canvas"),o=r.getContext("2d");if(r.width=i,r.height=n,o.drawImage(this._image,0,0,i,n),t[0].context2D=o,delete this._image,e.isCanvasTainted(r))return t;for(;i>=2&&n>=2;){i=Math.floor(i/2),n=Math.floor(n/2);var s=document.createElement("canvas"),a=s.getContext("2d");s.width=i,s.height=n,a.drawImage(r,0,0,i,n),t.splice(0,0,{context2D:a,width:i,height:n}),r=s,o=a}return t}})}(OpenSeadragon),function(e){e.TileSourceCollection=function(t,i,n,r){e.console.error("TileSourceCollection is deprecated; use World instead")}}(OpenSeadragon),function(e){function t(i){e.requestAnimationFrame((function(){!function(i){var n,r,o;i.shouldFade&&(n=e.now(),r=n-i.fadeBeginTime,o=1-r/i.fadeLength,o=Math.min(1,o),o=Math.max(0,o),i.imgGroup&&e.setElementOpacity(i.imgGroup,o,!0),o>0&&t(i))}(i)}))}function i(t,i){t.element.disabled||(i>=e.ButtonState.GROUP&&t.currentState==e.ButtonState.REST&&(!function(t){t.shouldFade=!1,t.imgGroup&&e.setElementOpacity(t.imgGroup,1,!0)}(t),t.currentState=e.ButtonState.GROUP),i>=e.ButtonState.HOVER&&t.currentState==e.ButtonState.GROUP&&(t.imgHover&&(t.imgHover.style.visibility=""),t.currentState=e.ButtonState.HOVER),i>=e.ButtonState.DOWN&&t.currentState==e.ButtonState.HOVER&&(t.imgDown&&(t.imgDown.style.visibility=""),t.currentState=e.ButtonState.DOWN))}function n(i,n){i.element.disabled||(n<=e.ButtonState.HOVER&&i.currentState==e.ButtonState.DOWN&&(i.imgDown&&(i.imgDown.style.visibility="hidden"),i.currentState=e.ButtonState.HOVER),n<=e.ButtonState.GROUP&&i.currentState==e.ButtonState.HOVER&&(i.imgHover&&(i.imgHover.style.visibility="hidden"),i.currentState=e.ButtonState.GROUP),n<=e.ButtonState.REST&&i.currentState==e.ButtonState.GROUP&&(!function(i){i.shouldFade=!0,i.fadeBeginTime=e.now()+i.fadeDelay,window.setTimeout((function(){t(i)}),i.fadeDelay)}(i),i.currentState=e.ButtonState.REST))}e.ButtonState={REST:0,GROUP:1,HOVER:2,DOWN:3},e.Button=function(t){var r=this;e.EventSource.call(this),e.extend(!0,this,{tooltip:null,srcRest:null,srcGroup:null,srcHover:null,srcDown:null,clickTimeThreshold:e.DEFAULT_SETTINGS.clickTimeThreshold,clickDistThreshold:e.DEFAULT_SETTINGS.clickDistThreshold,fadeDelay:0,fadeLength:2e3,onPress:null,onRelease:null,onClick:null,onEnter:null,onExit:null,onFocus:null,onBlur:null},t),this.element=t.element||e.makeNeutralElement("div"),t.element||(this.imgRest=e.makeTransparentImage(this.srcRest),this.imgGroup=e.makeTransparentImage(this.srcGroup),this.imgHover=e.makeTransparentImage(this.srcHover),this.imgDown=e.makeTransparentImage(this.srcDown),this.imgRest.alt=this.imgGroup.alt=this.imgHover.alt=this.imgDown.alt=this.tooltip,this.element.style.position="relative",e.setElementTouchActionNone(this.element),this.imgGroup.style.position=this.imgHover.style.position=this.imgDown.style.position="absolute",this.imgGroup.style.top=this.imgHover.style.top=this.imgDown.style.top="0px",this.imgGroup.style.left=this.imgHover.style.left=this.imgDown.style.left="0px",this.imgHover.style.visibility=this.imgDown.style.visibility="hidden",e.Browser.vendor==e.BROWSERS.FIREFOX&&e.Browser.version<3&&(this.imgGroup.style.top=this.imgHover.style.top=this.imgDown.style.top=""),this.element.appendChild(this.imgRest),this.element.appendChild(this.imgGroup),this.element.appendChild(this.imgHover),this.element.appendChild(this.imgDown)),this.addHandler("press",this.onPress),this.addHandler("release",this.onRelease),this.addHandler("click",this.onClick),this.addHandler("enter",this.onEnter),this.addHandler("exit",this.onExit),this.addHandler("focus",this.onFocus),this.addHandler("blur",this.onBlur),this.currentState=e.ButtonState.GROUP,this.fadeBeginTime=null,this.shouldFade=!1,this.element.style.display="inline-block",this.element.style.position="relative",this.element.title=this.tooltip,this.tracker=new e.MouseTracker({element:this.element,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,enterHandler:function(t){t.insideElementPressed?(i(r,e.ButtonState.DOWN),r.raiseEvent("enter",{originalEvent:t.originalEvent})):t.buttonDownAny||i(r,e.ButtonState.HOVER)},focusHandler:function(e){this.enterHandler(e),r.raiseEvent("focus",{originalEvent:e.originalEvent})},exitHandler:function(t){n(r,e.ButtonState.GROUP),t.insideElementPressed&&r.raiseEvent("exit",{originalEvent:t.originalEvent})},blurHandler:function(e){this.exitHandler(e),r.raiseEvent("blur",{originalEvent:e.originalEvent})},pressHandler:function(t){i(r,e.ButtonState.DOWN),r.raiseEvent("press",{originalEvent:t.originalEvent})},releaseHandler:function(t){t.insideElementPressed&&t.insideElementReleased?(n(r,e.ButtonState.HOVER),r.raiseEvent("release",{originalEvent:t.originalEvent})):t.insideElementPressed?n(r,e.ButtonState.GROUP):i(r,e.ButtonState.HOVER)},clickHandler:function(e){e.quick&&r.raiseEvent("click",{originalEvent:e.originalEvent})},keyHandler:function(e){return 13!==e.keyCode||(r.raiseEvent("click",{originalEvent:e.originalEvent}),r.raiseEvent("release",{originalEvent:e.originalEvent}),!1)}}),n(this,e.ButtonState.REST)},e.extend(e.Button.prototype,e.EventSource.prototype,{notifyGroupEnter:function(){i(this,e.ButtonState.GROUP)},notifyGroupExit:function(){n(this,e.ButtonState.REST)},disable:function(){this.notifyGroupExit(),this.element.disabled=!0,e.setElementOpacity(this.element,.2,!0)},enable:function(){this.element.disabled=!1,e.setElementOpacity(this.element,1,!0),this.notifyGroupEnter()}})}(OpenSeadragon),function(e){e.ButtonGroup=function(t){e.extend(!0,this,{buttons:[],clickTimeThreshold:e.DEFAULT_SETTINGS.clickTimeThreshold,clickDistThreshold:e.DEFAULT_SETTINGS.clickDistThreshold,labelText:""},t);var i,n=this.buttons.concat([]),r=this;if(this.element=t.element||e.makeNeutralElement("div"),!t.group)for(this.element.style.display="inline-block",i=0;i=270?(s=this.getTopRight(),this.x=s.x,this.y=s.y,a=this.height,this.height=this.width,this.width=a,this.degrees-=270):this.degrees>=180?(s=this.getBottomRight(),this.x=s.x,this.y=s.y,this.degrees-=180):this.degrees>=90&&(s=this.getBottomLeft(),this.x=s.x,this.y=s.y,a=this.height,this.height=this.width,this.width=a,this.degrees-=90)},e.Rect.fromSummits=function(t,i,n){var r=t.distanceTo(i),o=t.distanceTo(n),s=i.minus(t),a=Math.atan(s.y/s.x);return s.x<0?a+=Math.PI:s.y<0&&(a+=2*Math.PI),new e.Rect(t.x,t.y,r,o,a/Math.PI*180)},e.Rect.prototype={clone:function(){return new e.Rect(this.x,this.y,this.width,this.height,this.degrees)},getAspectRatio:function(){return this.width/this.height},getTopLeft:function(){return new e.Point(this.x,this.y)},getBottomRight:function(){return new e.Point(this.x+this.width,this.y+this.height).rotate(this.degrees,this.getTopLeft())},getTopRight:function(){return new e.Point(this.x+this.width,this.y).rotate(this.degrees,this.getTopLeft())},getBottomLeft:function(){return new e.Point(this.x,this.y+this.height).rotate(this.degrees,this.getTopLeft())},getCenter:function(){return new e.Point(this.x+this.width/2,this.y+this.height/2).rotate(this.degrees,this.getTopLeft())},getSize:function(){return new e.Point(this.width,this.height)},equals:function(t){return t instanceof e.Rect&&this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height&&this.degrees===t.degrees},times:function(t){return new e.Rect(this.x*t,this.y*t,this.width*t,this.height*t,this.degrees)},translate:function(t){return new e.Rect(this.x+t.x,this.y+t.y,this.width,this.height,this.degrees)},union:function(t){var i=this.getBoundingBox(),n=t.getBoundingBox(),r=Math.min(i.x,n.x),o=Math.min(i.y,n.y),s=Math.max(i.x+i.width,n.x+n.width),a=Math.max(i.y+i.height,n.y+n.height);return new e.Rect(r,o,s-r,a-o)},intersection:function(t){var i=1e-10,n=[],r=this.getTopLeft();t.containsPoint(r,i)&&n.push(r);var o=this.getTopRight();t.containsPoint(o,i)&&n.push(o);var s=this.getBottomLeft();t.containsPoint(s,i)&&n.push(s);var a=this.getBottomRight();t.containsPoint(a,i)&&n.push(a);var l=t.getTopLeft();this.containsPoint(l,i)&&n.push(l);var c=t.getTopRight();this.containsPoint(c,i)&&n.push(c);var u=t.getBottomLeft();this.containsPoint(u,i)&&n.push(u);var h=t.getBottomRight();this.containsPoint(h,i)&&n.push(h);for(var d=this._getSegments(),p=t._getSegments(),g=0;g_&&(_=E.x),E.yx&&(x=E.y)}return new e.Rect(T,S,_-T,x-S)},_getSegments:function(){var e=this.getTopLeft(),t=this.getTopRight(),i=this.getBottomLeft(),n=this.getBottomRight();return[[e,t],[t,n],[n,i],[i,e]]},rotate:function(t,i){if(0===(t=e.positiveModulo(t,360)))return this.clone();i=i||this.getCenter();var n=this.getTopLeft().rotate(t,i),r=this.getTopRight().rotate(t,i).minus(n);r=r.apply((function(e){return Math.abs(e)<1e-15?0:e}));var o=Math.atan(r.y/r.x);return r.x<0?o+=Math.PI:r.y<0&&(o+=2*Math.PI),new e.Rect(n.x,n.y,this.width,this.height,o/Math.PI*180)},getBoundingBox:function(){if(0===this.degrees)return this.clone();var t=this.getTopLeft(),i=this.getTopRight(),n=this.getBottomLeft(),r=this.getBottomRight(),o=Math.min(t.x,i.x,n.x,r.x),s=Math.max(t.x,i.x,n.x,r.x),a=Math.min(t.y,i.y,n.y,r.y),l=Math.max(t.y,i.y,n.y,r.y);return new e.Rect(o,a,s-o,l-a)},getIntegerBoundingBox:function(){var t=this.getBoundingBox(),i=Math.floor(t.x),n=Math.floor(t.y),r=Math.ceil(t.width+t.x-i),o=Math.ceil(t.height+t.y-n);return new e.Rect(i,n,r,o)},containsPoint:function(e,t){t=t||0;var i=this.getTopLeft(),n=this.getTopRight(),r=this.getBottomLeft(),o=n.minus(i),s=r.minus(i);return(e.x-i.x)*o.x+(e.y-i.y)*o.y>=-t&&(e.x-n.x)*o.x+(e.y-n.y)*o.y<=t&&(e.x-i.x)*s.x+(e.y-i.y)*s.y>=-t&&(e.x-r.x)*s.x+(e.y-r.y)*s.y<=t},toString:function(){return"["+Math.round(100*this.x)/100+", "+Math.round(100*this.y)/100+", "+Math.round(100*this.width)/100+"x"+Math.round(100*this.height)/100+", "+Math.round(100*this.degrees)/100+"deg]"}}}(OpenSeadragon),function(e){var t={};function i(t){var i=Number(this.element.style.marginLeft.replace("px","")),n=Number(this.element.style.marginTop.replace("px","")),o=Number(this.element.style.width.replace("px","")),s=Number(this.element.style.height.replace("px","")),a=e.getElementSize(this.viewer.canvas);return this.dragging=!0,this.element&&("horizontal"==this.scroll?-t.delta.x>0?i>-(o-a.x)&&(this.element.style.marginLeft=i+2*t.delta.x+"px",r(this,a.x,i+2*t.delta.x)):-t.delta.x<0&&i<0&&(this.element.style.marginLeft=i+2*t.delta.x+"px",r(this,a.x,i+2*t.delta.x)):-t.delta.y>0?n>-(s-a.y)&&(this.element.style.marginTop=n+2*t.delta.y+"px",r(this,a.y,n+2*t.delta.y)):-t.delta.y<0&&n<0&&(this.element.style.marginTop=n+2*t.delta.y+"px",r(this,a.y,n+2*t.delta.y))),!1}function n(t){var i=Number(this.element.style.marginLeft.replace("px","")),n=Number(this.element.style.marginTop.replace("px","")),o=Number(this.element.style.width.replace("px","")),s=Number(this.element.style.height.replace("px","")),a=e.getElementSize(this.viewer.canvas);return this.element&&("horizontal"==this.scroll?t.scroll>0?i>-(o-a.x)&&(this.element.style.marginLeft=i-60*t.scroll+"px",r(this,a.x,i-60*t.scroll)):t.scroll<0&&i<0&&(this.element.style.marginLeft=i-60*t.scroll+"px",r(this,a.x,i-60*t.scroll)):t.scroll<0?n>a.y-s&&(this.element.style.marginTop=n+60*t.scroll+"px",r(this,a.y,n+60*t.scroll)):t.scroll>0&&n<0&&(this.element.style.marginTop=n+60*t.scroll+"px",r(this,a.y,n+60*t.scroll))),!1}function r(t,i,n){var r,o,s,a,l,c,u;for(r="horizontal"==t.scroll?t.panelWidth:t.panelHeight,o=Math.ceil(i/r)+5,c=o=(o=(s=Math.ceil((Math.abs(n)+i)/r)+1)-o)<0?0:o;cc+s.x-this.panelWidth?(i=Math.min(i,a-s.x),this.element.style.marginLeft=-i+"px",r(this,s.x,-i)):iu+s.y-this.panelHeight?(i=Math.min(i,l-s.y),this.element.style.marginTop=-i+"px",r(this,s.y,-i)):i1?i[1].springStiffness:5,animationTime:i.length>1?i[1].animationTime:1.5}),e.console.assert("number"==typeof t.springStiffness&&0!==t.springStiffness,"[OpenSeadragon.Spring] options.springStiffness must be a non-zero number"),e.console.assert("number"==typeof t.animationTime&&t.animationTime>=0,"[OpenSeadragon.Spring] options.animationTime must be a number greater than or equal to 0"),t.exponential&&(this._exponential=!0,delete t.exponential),e.extend(!0,this,t),this.current={value:"number"==typeof this.initial?this.initial:this._exponential?0:1,time:e.now()},e.console.assert(!this._exponential||0!==this.current.value,"[OpenSeadragon.Spring] value must be non-zero for exponential springs"),this.start={value:this.current.value,time:this.current.time},this.target={value:this.current.value,time:this.current.time},this._exponential&&(this.start._logValue=Math.log(this.start.value),this.target._logValue=Math.log(this.target.value),this.current._logValue=Math.log(this.current.value))},e.Spring.prototype={resetTo:function(t){e.console.assert(!this._exponential||0!==t,"[OpenSeadragon.Spring.resetTo] target must be non-zero for exponential springs"),this.start.value=this.target.value=this.current.value=t,this.start.time=this.target.time=this.current.time=e.now(),this._exponential&&(this.start._logValue=Math.log(this.start.value),this.target._logValue=Math.log(this.target.value),this.current._logValue=Math.log(this.current.value))},springTo:function(t){e.console.assert(!this._exponential||0!==t,"[OpenSeadragon.Spring.springTo] target must be non-zero for exponential springs"),this.start.value=this.current.value,this.start.time=this.current.time,this.target.value=t,this.target.time=this.start.time+1e3*this.animationTime,this._exponential&&(this.start._logValue=Math.log(this.start.value),this.target._logValue=Math.log(this.target.value))},shiftBy:function(t){this.start.value+=t,this.target.value+=t,this._exponential&&(e.console.assert(0!==this.target.value&&0!==this.start.value,"[OpenSeadragon.Spring.shiftBy] spring value must be non-zero for exponential springs"),this.start._logValue=Math.log(this.start.value),this.target._logValue=Math.log(this.target.value))},setExponential:function(t){this._exponential=t,this._exponential&&(e.console.assert(0!==this.current.value&&0!==this.target.value&&0!==this.start.value,"[OpenSeadragon.Spring.setExponential] spring value must be non-zero for exponential springs"),this.start._logValue=Math.log(this.start.value),this.target._logValue=Math.log(this.target.value),this.current._logValue=Math.log(this.current.value))},update:function(){var t,i;this.current.time=e.now(),this._exponential?(t=this.start._logValue,i=this.target._logValue):(t=this.start.value,i=this.target.value);var n,r,o=this.current.time>=this.target.time?i:t+(i-t)*(n=this.springStiffness,r=(this.current.time-this.start.time)/(this.target.time-this.start.time),(1-Math.exp(n*-r))/(1-Math.exp(-n))),s=this.current.value;return this._exponential?this.current.value=Math.exp(o):this.current.value=o,s!=this.current.value},isAtTargetValue:function(){return this.current.value===this.target.value}}}(OpenSeadragon),function(e){function t(t){e.extend(!0,this,{timeout:e.DEFAULT_SETTINGS.timeout,jobId:null},t),this.image=null}t.prototype={errorMsg:null,start:function(){var t=this,i=this.abort;this.image=new Image,this.image.onload=function(){t.finish(!0)},this.image.onabort=this.image.onerror=function(){t.errorMsg="Image load aborted",t.finish(!1)},this.jobId=window.setTimeout((function(){t.errorMsg="Image load exceeded timeout ("+t.timeout+" ms)",t.finish(!1)}),this.timeout),this.loadWithAjax?(this.request=e.makeAjaxRequest({url:this.src,withCredentials:this.ajaxWithCredentials,headers:this.ajaxHeaders,responseType:"arraybuffer",success:function(e){var i;try{i=new window.Blob([e.response])}catch(t){var n=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder;if("TypeError"===t.name&&n){var r=new n;r.append(e.response),i=r.getBlob()}}0===i.size&&(t.errorMsg="Empty image response.",t.finish(!1));var o=(window.URL||window.webkitURL).createObjectURL(i);t.image.src=o},error:function(e){t.errorMsg="Image load aborted - XHR error",t.finish(!1)}}),this.abort=function(){t.request.abort(),"function"==typeof i&&i()}):(!1!==this.crossOriginPolicy&&(this.image.crossOrigin=this.crossOriginPolicy),this.image.src=this.src)},finish:function(e){this.image.onload=this.image.onerror=this.image.onabort=null,e||(this.image=null),this.jobId&&window.clearTimeout(this.jobId),this.callback(this)}},e.ImageLoader=function(t){e.extend(!0,this,{jobLimit:e.DEFAULT_SETTINGS.imageLoaderLimit,timeout:e.DEFAULT_SETTINGS.timeout,jobQueue:[],jobsInProgress:0},t)},e.ImageLoader.prototype={addJob:function(e){var i=this,n=new t({src:e.src,loadWithAjax:e.loadWithAjax,ajaxHeaders:e.loadWithAjax?e.ajaxHeaders:null,crossOriginPolicy:e.crossOriginPolicy,ajaxWithCredentials:e.ajaxWithCredentials,callback:function(t){!function(e,t,i){e.jobsInProgress--,(!e.jobLimit||e.jobsInProgress0&&(e.jobQueue.shift().start(),e.jobsInProgress++);i(t.image,t.errorMsg,t.request)}(i,t,e.callback)},abort:e.abort,timeout:this.timeout});!this.jobLimit||this.jobsInProgressi&&(i=r)}return i},needsUpdate:function(){return e.console.error("[Drawer.needsUpdate] this function is deprecated. Use World.needsDraw instead."),this.viewer.world.needsDraw()},numTilesLoaded:function(){return e.console.error("[Drawer.numTilesLoaded] this function is deprecated. Use TileCache.numTilesLoaded instead."),this.viewer.tileCache.numTilesLoaded()},reset:function(){return e.console.error("[Drawer.reset] this function is deprecated. Use World.resetItems instead."),this.viewer.world.resetItems(),this},update:function(){return e.console.error("[Drawer.update] this function is deprecated. Use Drawer.clear and World.draw instead."),this.clear(),this.viewer.world.draw(),this},canRotate:function(){return this.useCanvas},destroy:function(){this.canvas.width=1,this.canvas.height=1,this.sketchCanvas=null,this.sketchContext=null},clear:function(){if(this.canvas.innerHTML="",this.useCanvas){var e=this._calculateCanvasSize();if((this.canvas.width!=e.x||this.canvas.height!=e.y)&&(this.canvas.width=e.x,this.canvas.height=e.y,this._updateImageSmoothingEnabled(this.context),null!==this.sketchCanvas)){var t=this._calculateSketchCanvasSize();this.sketchCanvas.width=t.x,this.sketchCanvas.height=t.y,this._updateImageSmoothingEnabled(this.sketchContext)}this._clear()}},_clear:function(e,t){if(this.useCanvas){var i=this._getContext(e);if(t)i.clearRect(t.x,t.y,t.width,t.height);else{var n=i.canvas;i.clearRect(0,0,n.width,n.height)}}},viewportToDrawerRectangle:function(t){var i=this.viewport.pixelFromPointNoRotate(t.getTopLeft(),!0),n=this.viewport.deltaPixelsFromPointsNoRotate(t.getSize(),!0);return new e.Rect(i.x*e.pixelDensityRatio,i.y*e.pixelDensityRatio,n.x*e.pixelDensityRatio,n.y*e.pixelDensityRatio)},drawTile:function(t,i,n,r,o){if(e.console.assert(t,"[Drawer.drawTile] tile is required"),e.console.assert(i,"[Drawer.drawTile] drawingHandler is required"),this.useCanvas){var s=this._getContext(n);r=r||1,t.drawCanvas(s,i,r,o)}else t.drawHTML(this.canvas)},_getContext:function(e){var t=this.context;if(e){if(null===this.sketchCanvas){this.sketchCanvas=document.createElement("canvas");var i=this._calculateSketchCanvasSize();if(this.sketchCanvas.width=i.x,this.sketchCanvas.height=i.y,this.sketchContext=this.sketchCanvas.getContext("2d"),0===this.viewport.getRotation()){var n=this;this.viewer.addHandler("rotate",(function e(){if(0!==n.viewport.getRotation()){n.viewer.removeHandler("rotate",e);var t=n._calculateSketchCanvasSize();n.sketchCanvas.width=t.x,n.sketchCanvas.height=t.y}}))}this._updateImageSmoothingEnabled(this.sketchContext)}t=this.sketchContext}return t},saveContext:function(e){this.useCanvas&&this._getContext(e).save()},restoreContext:function(e){this.useCanvas&&this._getContext(e).restore()},setClip:function(e,t){if(this.useCanvas){var i=this._getContext(t);i.beginPath(),i.rect(e.x,e.y,e.width,e.height),i.clip()}},drawRectangle:function(e,t,i){if(this.useCanvas){var n=this._getContext(i);n.save(),n.fillStyle=t,n.fillRect(e.x,e.y,e.width,e.height),n.restore()}},blendSketch:function(t,i,n,r){var o=t;if(e.isPlainObject(o)||(o={opacity:t,scale:i,translate:n,compositeOperation:r}),this.useCanvas&&this.sketchCanvas){t=o.opacity,r=o.compositeOperation;var s=o.bounds;if(this.context.save(),this.context.globalAlpha=t,r&&(this.context.globalCompositeOperation=r),s)s.x<0&&(s.width+=s.x,s.x=0),s.x+s.width>this.canvas.width&&(s.width=this.canvas.width-s.x),s.y<0&&(s.height+=s.y,s.y=0),s.y+s.height>this.canvas.height&&(s.height=this.canvas.height-s.y),this.context.drawImage(this.sketchCanvas,s.x,s.y,s.width,s.height,s.x,s.y,s.width,s.height);else{i=o.scale||1;var a=(n=o.translate)instanceof e.Point?n:new e.Point(0,0),l=0,c=0;if(n){var u=this.sketchCanvas.width-this.canvas.width,h=this.sketchCanvas.height-this.canvas.height;l=Math.round(u/2),c=Math.round(h/2)}this.context.drawImage(this.sketchCanvas,a.x-l*i,a.y-c*i,(this.canvas.width+2*l)*i,(this.canvas.height+2*c)*i,-l,-c,this.canvas.width+2*l,this.canvas.height+2*c)}this.context.restore()}},drawDebugInfo:function(t,i,n,r){if(this.useCanvas){var o=this.viewer.world.getIndexOfItem(r)%this.debugGridColor.length,s=this.context;s.save(),s.lineWidth=2*e.pixelDensityRatio,s.font="small-caps bold "+13*e.pixelDensityRatio+"px arial",s.strokeStyle=this.debugGridColor[o],s.fillStyle=this.debugGridColor[o],0!==this.viewport.degrees&&this._offsetForRotation({degrees:this.viewport.degrees}),r.getRotation(!0)%360!=0&&this._offsetForRotation({degrees:r.getRotation(!0),point:r.viewport.pixelFromPointNoRotate(r._getRotationPoint(!0),!0)}),0===r.viewport.degrees&&r.getRotation(!0)%360==0&&r._drawer.viewer.viewport.getFlip()&&r._drawer._flip(),s.strokeRect(t.position.x*e.pixelDensityRatio,t.position.y*e.pixelDensityRatio,t.size.x*e.pixelDensityRatio,t.size.y*e.pixelDensityRatio);var a=(t.position.x+t.size.x/2)*e.pixelDensityRatio,l=(t.position.y+t.size.y/2)*e.pixelDensityRatio;s.translate(a,l),s.rotate(Math.PI/180*-this.viewport.degrees),s.translate(-a,-l),0===t.x&&0===t.y&&(s.fillText("Zoom: "+this.viewport.getZoom(),t.position.x*e.pixelDensityRatio,(t.position.y-30)*e.pixelDensityRatio),s.fillText("Pan: "+this.viewport.getBounds().toString(),t.position.x*e.pixelDensityRatio,(t.position.y-20)*e.pixelDensityRatio)),s.fillText("Level: "+t.level,(t.position.x+10)*e.pixelDensityRatio,(t.position.y+20)*e.pixelDensityRatio),s.fillText("Column: "+t.x,(t.position.x+10)*e.pixelDensityRatio,(t.position.y+30)*e.pixelDensityRatio),s.fillText("Row: "+t.y,(t.position.x+10)*e.pixelDensityRatio,(t.position.y+40)*e.pixelDensityRatio),s.fillText("Order: "+n+" of "+i,(t.position.x+10)*e.pixelDensityRatio,(t.position.y+50)*e.pixelDensityRatio),s.fillText("Size: "+t.size.toString(),(t.position.x+10)*e.pixelDensityRatio,(t.position.y+60)*e.pixelDensityRatio),s.fillText("Position: "+t.position.toString(),(t.position.x+10)*e.pixelDensityRatio,(t.position.y+70)*e.pixelDensityRatio),0!==this.viewport.degrees&&this._restoreRotationChanges(),r.getRotation(!0)%360!=0&&this._restoreRotationChanges(),0===r.viewport.degrees&&r.getRotation(!0)%360==0&&r._drawer.viewer.viewport.getFlip()&&r._drawer._flip(),s.restore()}},debugRect:function(t){if(this.useCanvas){var i=this.context;i.save(),i.lineWidth=2*e.pixelDensityRatio,i.strokeStyle=this.debugGridColor[0],i.fillStyle=this.debugGridColor[0],i.strokeRect(t.x*e.pixelDensityRatio,t.y*e.pixelDensityRatio,t.width*e.pixelDensityRatio,t.height*e.pixelDensityRatio),i.restore()}},setImageSmoothingEnabled:function(e){this.useCanvas&&(this._imageSmoothingEnabled=e,this._updateImageSmoothingEnabled(this.context),this.viewer.forceRedraw())},_updateImageSmoothingEnabled:function(e){e.mozImageSmoothingEnabled=this._imageSmoothingEnabled,e.webkitImageSmoothingEnabled=this._imageSmoothingEnabled,e.msImageSmoothingEnabled=this._imageSmoothingEnabled,e.imageSmoothingEnabled=this._imageSmoothingEnabled},getCanvasSize:function(t){var i=this._getContext(t).canvas;return new e.Point(i.width,i.height)},getCanvasCenter:function(){return new e.Point(this.canvas.width/2,this.canvas.height/2)},_offsetForRotation:function(t){var i=t.point?t.point.times(e.pixelDensityRatio):this.getCanvasCenter(),n=this._getContext(t.useSketch);n.save(),n.translate(i.x,i.y),this.viewer.viewport.flipped?(n.rotate(Math.PI/180*-t.degrees),n.scale(-1,1)):n.rotate(Math.PI/180*t.degrees),n.translate(-i.x,-i.y)},_flip:function(t){var i=(t=t||{}).point?t.point.times(e.pixelDensityRatio):this.getCanvasCenter(),n=this._getContext(t.useSketch);n.translate(i.x,0),n.scale(-1,1),n.translate(-i.x,0)},_restoreRotationChanges:function(e){this._getContext(e).restore()},_calculateCanvasSize:function(){var t=e.pixelDensityRatio,i=this.viewport.getContainerSize();return{x:Math.round(i.x*t),y:Math.round(i.y*t)}},_calculateSketchCanvasSize:function(){var e=this._calculateCanvasSize();if(0===this.viewport.getRotation())return e;var t=Math.ceil(Math.sqrt(e.x*e.x+e.y*e.y));return{x:t,y:t}}}}(OpenSeadragon),function(e){e.Viewport=function(t){var i=arguments;i.length&&i[0]instanceof e.Point&&(t={containerSize:i[0],contentSize:i[1],config:i[2]}),t.config&&(e.extend(!0,t,t.config),delete t.config),this._margins=e.extend({left:0,top:0,right:0,bottom:0},t.margins||{}),delete t.margins,e.extend(!0,this,{containerSize:null,contentSize:null,zoomPoint:null,viewer:null,springStiffness:e.DEFAULT_SETTINGS.springStiffness,animationTime:e.DEFAULT_SETTINGS.animationTime,minZoomImageRatio:e.DEFAULT_SETTINGS.minZoomImageRatio,maxZoomPixelRatio:e.DEFAULT_SETTINGS.maxZoomPixelRatio,visibilityRatio:e.DEFAULT_SETTINGS.visibilityRatio,wrapHorizontal:e.DEFAULT_SETTINGS.wrapHorizontal,wrapVertical:e.DEFAULT_SETTINGS.wrapVertical,defaultZoomLevel:e.DEFAULT_SETTINGS.defaultZoomLevel,minZoomLevel:e.DEFAULT_SETTINGS.minZoomLevel,maxZoomLevel:e.DEFAULT_SETTINGS.maxZoomLevel,degrees:e.DEFAULT_SETTINGS.degrees,flipped:e.DEFAULT_SETTINGS.flipped,homeFillsViewer:e.DEFAULT_SETTINGS.homeFillsViewer},t),this._updateContainerInnerSize(),this.centerSpringX=new e.Spring({initial:0,springStiffness:this.springStiffness,animationTime:this.animationTime}),this.centerSpringY=new e.Spring({initial:0,springStiffness:this.springStiffness,animationTime:this.animationTime}),this.zoomSpring=new e.Spring({exponential:!0,initial:1,springStiffness:this.springStiffness,animationTime:this.animationTime}),this._oldCenterX=this.centerSpringX.current.value,this._oldCenterY=this.centerSpringY.current.value,this._oldZoom=this.zoomSpring.current.value,this._setContentBounds(new e.Rect(0,0,1,1),1),this.goHome(!0),this.update()},e.Viewport.prototype={resetContentSize:function(t){return e.console.assert(t,"[Viewport.resetContentSize] contentSize is required"),e.console.assert(t instanceof e.Point,"[Viewport.resetContentSize] contentSize must be an OpenSeadragon.Point"),e.console.assert(t.x>0,"[Viewport.resetContentSize] contentSize.x must be greater than 0"),e.console.assert(t.y>0,"[Viewport.resetContentSize] contentSize.y must be greater than 0"),this._setContentBounds(new e.Rect(0,0,1,t.y/t.x),t.x),this},setHomeBounds:function(t,i){e.console.error("[Viewport.setHomeBounds] this function is deprecated; The content bounds should not be set manually."),this._setContentBounds(t,i)},_setContentBounds:function(t,i){e.console.assert(t,"[Viewport._setContentBounds] bounds is required"),e.console.assert(t instanceof e.Rect,"[Viewport._setContentBounds] bounds must be an OpenSeadragon.Rect"),e.console.assert(t.width>0,"[Viewport._setContentBounds] bounds.width must be greater than 0"),e.console.assert(t.height>0,"[Viewport._setContentBounds] bounds.height must be greater than 0"),this._contentBoundsNoRotate=t.clone(),this._contentSizeNoRotate=this._contentBoundsNoRotate.getSize().times(i),this._contentBounds=t.rotate(this.degrees).getBoundingBox(),this._contentSize=this._contentBounds.getSize().times(i),this._contentAspectRatio=this._contentSize.x/this._contentSize.y,this.viewer&&this.viewer.raiseEvent("reset-size",{contentSize:this._contentSizeNoRotate.clone(),contentFactor:i,homeBounds:this._contentBoundsNoRotate.clone(),contentBounds:this._contentBounds.clone()})},getHomeZoom:function(){if(this.defaultZoomLevel)return this.defaultZoomLevel;var e=this._contentAspectRatio/this.getAspectRatio();return(this.homeFillsViewer?e>=1?e:1:e>=1?1:e)/this._contentBounds.width},getHomeBounds:function(){return this.getHomeBoundsNoRotate().rotate(-this.getRotation())},getHomeBoundsNoRotate:function(){var t=this._contentBounds.getCenter(),i=1/this.getHomeZoom(),n=i/this.getAspectRatio();return new e.Rect(t.x-i/2,t.y-n/2,i,n)},goHome:function(e){return this.viewer&&this.viewer.raiseEvent("home",{immediately:e}),this.fitBounds(this.getHomeBounds(),e)},getMinZoom:function(){var e=this.getHomeZoom();return this.minZoomLevel?this.minZoomLevel:this.minZoomImageRatio*e},getMaxZoom:function(){var e=this.maxZoomLevel;return e||(e=this._contentSize.x*this.maxZoomPixelRatio/this._containerInnerSize.x,e/=this._contentBounds.width),Math.max(e,this.getHomeZoom())},getAspectRatio:function(){return this._containerInnerSize.x/this._containerInnerSize.y},getContainerSize:function(){return new e.Point(this.containerSize.x,this.containerSize.y)},getMargins:function(){return e.extend({},this._margins)},setMargins:function(t){e.console.assert("object"===e.type(t),"[Viewport.setMargins] margins must be an object"),this._margins=e.extend({left:0,top:0,right:0,bottom:0},t),this._updateContainerInnerSize(),this.viewer&&this.viewer.forceRedraw()},getBounds:function(e){return this.getBoundsNoRotate(e).rotate(-this.getRotation())},getBoundsNoRotate:function(t){var i=this.getCenter(t),n=1/this.getZoom(t),r=n/this.getAspectRatio();return new e.Rect(i.x-n/2,i.y-r/2,n,r)},getBoundsWithMargins:function(e){return this.getBoundsNoRotateWithMargins(e).rotate(-this.getRotation(),this.getCenter(e))},getBoundsNoRotateWithMargins:function(e){var t=this.getBoundsNoRotate(e),i=this._containerInnerSize.x*this.getZoom(e);return t.x-=this._margins.left/i,t.y-=this._margins.top/i,t.width+=(this._margins.left+this._margins.right)/i,t.height+=(this._margins.top+this._margins.bottom)/i,t},getCenter:function(t){var i,n,r,o,s,a,l=new e.Point(this.centerSpringX.current.value,this.centerSpringY.current.value),c=new e.Point(this.centerSpringX.target.value,this.centerSpringY.target.value);return t?l:this.zoomPoint?(i=this.pixelFromPoint(this.zoomPoint,!0),o=(r=1/(n=this.getZoom()))/this.getAspectRatio(),s=new e.Rect(l.x-r/2,l.y-o/2,r,o),a=this._pixelFromPoint(this.zoomPoint,s).minus(i).divide(this._containerInnerSize.x*n),c.plus(a)):c},getZoom:function(e){return e?this.zoomSpring.current.value:this.zoomSpring.target.value},_applyZoomConstraints:function(e){return Math.max(Math.min(e,this.getMaxZoom()),this.getMinZoom())},_applyBoundaryConstraints:function(t){var i=new e.Rect(t.x,t.y,t.width,t.height);if(this.wrapHorizontal);else{var n=this.visibilityRatio*i.width,r=i.x+i.width,o=this._contentBoundsNoRotate.x+this._contentBoundsNoRotate.width,s=this._contentBoundsNoRotate.x-r+n,a=o-i.x-n;n>this._contentBoundsNoRotate.width?i.x+=(s+a)/2:a<0?i.x+=a:s>0&&(i.x+=s)}if(this.wrapVertical);else{var l=this.visibilityRatio*i.height,c=i.y+i.height,u=this._contentBoundsNoRotate.y+this._contentBoundsNoRotate.height,h=this._contentBoundsNoRotate.y-c+l,d=u-i.y-l;l>this._contentBoundsNoRotate.height?i.y+=(h+d)/2:d<0?i.y+=d:h>0&&(i.y+=h)}return i},_raiseConstraintsEvent:function(e){this.viewer&&this.viewer.raiseEvent("constrain",{immediately:e})},applyConstraints:function(e){var t=this.getZoom(),i=this._applyZoomConstraints(t);t!==i&&this.zoomTo(i,this.zoomPoint,e);var n=this.getBoundsNoRotate(),r=this._applyBoundaryConstraints(n);return this._raiseConstraintsEvent(e),(n.x!==r.x||n.y!==r.y||e)&&this.fitBounds(r.rotate(-this.getRotation()),e),this},ensureVisible:function(e){return this.applyConstraints(e)},_fitBounds:function(t,i){var n=(i=i||{}).immediately||!1,r=i.constraints||!1,o=this.getAspectRatio(),s=t.getCenter(),a=new e.Rect(t.x,t.y,t.width,t.height,t.degrees+this.getRotation()).getBoundingBox();a.getAspectRatio()>=o?a.height=a.width/o:a.width=a.height*o,a.x=s.x-a.width/2,a.y=s.y-a.height/2;var l=1/a.width;if(r){var c=a.getAspectRatio(),u=this._applyZoomConstraints(l);l!==u&&(l=u,a.width=1/l,a.x=s.x-a.width/2,a.height=a.width/c,a.y=s.y-a.height/2),s=(a=this._applyBoundaryConstraints(a)).getCenter(),this._raiseConstraintsEvent(n)}if(n)return this.panTo(s,!0),this.zoomTo(l,null,!0);this.panTo(this.getCenter(!0),!0),this.zoomTo(this.getZoom(!0),null,!0);var h=this.getBounds(),d=this.getZoom();if(0===d||Math.abs(l/d-1)<1e-8)return this.zoomTo(l,!0),this.panTo(s,n);var p=(a=a.rotate(-this.getRotation())).getTopLeft().times(l).minus(h.getTopLeft().times(d)).divide(l-d);return this.zoomTo(l,p,n)},fitBounds:function(e,t){return this._fitBounds(e,{immediately:t,constraints:!1})},fitBoundsWithConstraints:function(e,t){return this._fitBounds(e,{immediately:t,constraints:!0})},fitVertically:function(t){var i=new e.Rect(this._contentBounds.x+this._contentBounds.width/2,this._contentBounds.y,0,this._contentBounds.height);return this.fitBounds(i,t)},fitHorizontally:function(t){var i=new e.Rect(this._contentBounds.x,this._contentBounds.y+this._contentBounds.height/2,this._contentBounds.width,0);return this.fitBounds(i,t)},getConstrainedBounds:function(e){var t;return t=this.getBounds(e),this._applyBoundaryConstraints(t)},panBy:function(t,i){var n=new e.Point(this.centerSpringX.target.value,this.centerSpringY.target.value);return this.panTo(n.plus(t),i)},panTo:function(e,t){return t?(this.centerSpringX.resetTo(e.x),this.centerSpringY.resetTo(e.y)):(this.centerSpringX.springTo(e.x),this.centerSpringY.springTo(e.y)),this.viewer&&this.viewer.raiseEvent("pan",{center:e,immediately:t}),this},zoomBy:function(e,t,i){return this.zoomTo(this.zoomSpring.target.value*e,t,i)},zoomTo:function(t,i,n){var r=this;return this.zoomPoint=i instanceof e.Point&&!isNaN(i.x)&&!isNaN(i.y)?i:null,n?this._adjustCenterSpringsForZoomPoint((function(){r.zoomSpring.resetTo(t)})):this.zoomSpring.springTo(t),this.viewer&&this.viewer.raiseEvent("zoom",{zoom:t,refPoint:i,immediately:n}),this},setRotation:function(t){return this.viewer&&this.viewer.drawer.canRotate()?(this.degrees=e.positiveModulo(t,360),this._setContentBounds(this.viewer.world.getHomeBounds(),this.viewer.world.getContentFactor()),this.viewer.forceRedraw(),this.viewer.raiseEvent("rotate",{degrees:t}),this):this},getRotation:function(){return this.degrees},resize:function(e,t){var i,n=this.getBoundsNoRotate(),r=n;return this.containerSize.x=e.x,this.containerSize.y=e.y,this._updateContainerInnerSize(),t&&(i=e.x/this.containerSize.x,r.width=n.width*i,r.height=r.width/this.getAspectRatio()),this.viewer&&this.viewer.raiseEvent("resize",{newContainerSize:e,maintain:t}),this.fitBounds(r,!0)},_updateContainerInnerSize:function(){this._containerInnerSize=new e.Point(Math.max(1,this.containerSize.x-(this._margins.left+this._margins.right)),Math.max(1,this.containerSize.y-(this._margins.top+this._margins.bottom)))},update:function(){var e=this;this._adjustCenterSpringsForZoomPoint((function(){e.zoomSpring.update()})),this.centerSpringX.update(),this.centerSpringY.update();var t=this.centerSpringX.current.value!==this._oldCenterX||this.centerSpringY.current.value!==this._oldCenterY||this.zoomSpring.current.value!==this._oldZoom;return this._oldCenterX=this.centerSpringX.current.value,this._oldCenterY=this.centerSpringY.current.value,this._oldZoom=this.zoomSpring.current.value,t},_adjustCenterSpringsForZoomPoint:function(e){if(this.zoomPoint){var t=this.pixelFromPoint(this.zoomPoint,!0);e();var i=this.pixelFromPoint(this.zoomPoint,!0).minus(t),n=this.deltaPointsFromPixels(i,!0);this.centerSpringX.shiftBy(n.x),this.centerSpringY.shiftBy(n.y),this.zoomSpring.isAtTargetValue()&&(this.zoomPoint=null)}else e()},deltaPixelsFromPointsNoRotate:function(e,t){return e.times(this._containerInnerSize.x*this.getZoom(t))},deltaPixelsFromPoints:function(e,t){return this.deltaPixelsFromPointsNoRotate(e.rotate(this.getRotation()),t)},deltaPointsFromPixelsNoRotate:function(e,t){return e.divide(this._containerInnerSize.x*this.getZoom(t))},deltaPointsFromPixels:function(e,t){return this.deltaPointsFromPixelsNoRotate(e,t).rotate(-this.getRotation())},pixelFromPointNoRotate:function(e,t){return this._pixelFromPointNoRotate(e,this.getBoundsNoRotate(t))},pixelFromPoint:function(e,t){return this._pixelFromPoint(e,this.getBoundsNoRotate(t))},_pixelFromPointNoRotate:function(t,i){return t.minus(i.getTopLeft()).times(this._containerInnerSize.x/i.width).plus(new e.Point(this._margins.left,this._margins.top))},_pixelFromPoint:function(e,t){return this._pixelFromPointNoRotate(e.rotate(this.getRotation(),this.getCenter(!0)),t)},pointFromPixelNoRotate:function(t,i){var n=this.getBoundsNoRotate(i);return t.minus(new e.Point(this._margins.left,this._margins.top)).divide(this._containerInnerSize.x/n.width).plus(n.getTopLeft())},pointFromPixel:function(e,t){return this.pointFromPixelNoRotate(e,t).rotate(-this.getRotation(),this.getCenter(!0))},_viewportToImageDelta:function(t,i){var n=this._contentBoundsNoRotate.width;return new e.Point(t*this._contentSizeNoRotate.x/n,i*this._contentSizeNoRotate.x/n)},viewportToImageCoordinates:function(t,i){if(t instanceof e.Point)return this.viewportToImageCoordinates(t.x,t.y);if(this.viewer){var n=this.viewer.world.getItemCount();if(n>1)e.console.error("[Viewport.viewportToImageCoordinates] is not accurate with multi-image; use TiledImage.viewportToImageCoordinates instead.");else if(1===n){return this.viewer.world.getItemAt(0).viewportToImageCoordinates(t,i,!0)}}return this._viewportToImageDelta(t-this._contentBoundsNoRotate.x,i-this._contentBoundsNoRotate.y)},_imageToViewportDelta:function(t,i){var n=this._contentBoundsNoRotate.width;return new e.Point(t/this._contentSizeNoRotate.x*n,i/this._contentSizeNoRotate.x*n)},imageToViewportCoordinates:function(t,i){if(t instanceof e.Point)return this.imageToViewportCoordinates(t.x,t.y);if(this.viewer){var n=this.viewer.world.getItemCount();if(n>1)e.console.error("[Viewport.imageToViewportCoordinates] is not accurate with multi-image; use TiledImage.imageToViewportCoordinates instead.");else if(1===n){return this.viewer.world.getItemAt(0).imageToViewportCoordinates(t,i,!0)}}var r=this._imageToViewportDelta(t,i);return r.x+=this._contentBoundsNoRotate.x,r.y+=this._contentBoundsNoRotate.y,r},imageToViewportRectangle:function(t,i,n,r){var o=t;if(o instanceof e.Rect||(o=new e.Rect(t,i,n,r)),this.viewer){var s=this.viewer.world.getItemCount();if(s>1)e.console.error("[Viewport.imageToViewportRectangle] is not accurate with multi-image; use TiledImage.imageToViewportRectangle instead.");else if(1===s){return this.viewer.world.getItemAt(0).imageToViewportRectangle(t,i,n,r,!0)}}var a=this.imageToViewportCoordinates(o.x,o.y),l=this._imageToViewportDelta(o.width,o.height);return new e.Rect(a.x,a.y,l.x,l.y,o.degrees)},viewportToImageRectangle:function(t,i,n,r){var o=t;if(o instanceof e.Rect||(o=new e.Rect(t,i,n,r)),this.viewer){var s=this.viewer.world.getItemCount();if(s>1)e.console.error("[Viewport.viewportToImageRectangle] is not accurate with multi-image; use TiledImage.viewportToImageRectangle instead.");else if(1===s){return this.viewer.world.getItemAt(0).viewportToImageRectangle(t,i,n,r,!0)}}var a=this.viewportToImageCoordinates(o.x,o.y),l=this._viewportToImageDelta(o.width,o.height);return new e.Rect(a.x,a.y,l.x,l.y,o.degrees)},viewerElementToImageCoordinates:function(e){var t=this.pointFromPixel(e,!0);return this.viewportToImageCoordinates(t)},imageToViewerElementCoordinates:function(e){var t=this.imageToViewportCoordinates(e);return this.pixelFromPoint(t,!0)},windowToImageCoordinates:function(t){e.console.assert(this.viewer,"[Viewport.windowToImageCoordinates] the viewport must have a viewer.");var i=t.minus(e.getElementPosition(this.viewer.element));return this.viewerElementToImageCoordinates(i)},imageToWindowCoordinates:function(t){return e.console.assert(this.viewer,"[Viewport.imageToWindowCoordinates] the viewport must have a viewer."),this.imageToViewerElementCoordinates(t).plus(e.getElementPosition(this.viewer.element))},viewerElementToViewportCoordinates:function(e){return this.pointFromPixel(e,!0)},viewportToViewerElementCoordinates:function(e){return this.pixelFromPoint(e,!0)},viewerElementToViewportRectangle:function(t){return e.Rect.fromSummits(this.pointFromPixel(t.getTopLeft(),!0),this.pointFromPixel(t.getTopRight(),!0),this.pointFromPixel(t.getBottomLeft(),!0))},viewportToViewerElementRectangle:function(t){return e.Rect.fromSummits(this.pixelFromPoint(t.getTopLeft(),!0),this.pixelFromPoint(t.getTopRight(),!0),this.pixelFromPoint(t.getBottomLeft(),!0))},windowToViewportCoordinates:function(t){e.console.assert(this.viewer,"[Viewport.windowToViewportCoordinates] the viewport must have a viewer.");var i=t.minus(e.getElementPosition(this.viewer.element));return this.viewerElementToViewportCoordinates(i)},viewportToWindowCoordinates:function(t){return e.console.assert(this.viewer,"[Viewport.viewportToWindowCoordinates] the viewport must have a viewer."),this.viewportToViewerElementCoordinates(t).plus(e.getElementPosition(this.viewer.element))},viewportToImageZoom:function(t){if(this.viewer){var i=this.viewer.world.getItemCount();if(i>1)e.console.error("[Viewport.viewportToImageZoom] is not accurate with multi-image.");else if(1===i){return this.viewer.world.getItemAt(0).viewportToImageZoom(t)}}var n=this._contentSizeNoRotate.x;return t*(this._containerInnerSize.x/n*this._contentBoundsNoRotate.width)},imageToViewportZoom:function(t){if(this.viewer){var i=this.viewer.world.getItemCount();if(i>1)e.console.error("[Viewport.imageToViewportZoom] is not accurate with multi-image.");else if(1===i){return this.viewer.world.getItemAt(0).imageToViewportZoom(t)}}return t*(this._contentSizeNoRotate.x/this._containerInnerSize.x/this._contentBoundsNoRotate.width)},toggleFlip:function(){return this.setFlip(!this.getFlip()),this},getFlip:function(){return this.flipped},setFlip:function(e){return this.flipped===e?this:(this.flipped=e,this.viewer.navigator&&this.viewer.navigator.setFlip(this.getFlip()),this.viewer.forceRedraw(),this.viewer.raiseEvent("flip",{flipped:e}),this)}}}(OpenSeadragon),function(e){function t(e,t,n,r,o,s,l,c,u){var h=l.getBoundingBox().getTopLeft(),d=l.getBoundingBox().getBottomRight();e.viewer&&e.viewer.raiseEvent("update-level",{tiledImage:e,havedrawn:t,level:r,opacity:o,visibility:s,drawArea:l,topleft:h,bottomright:d,currenttime:c,best:u}),a(e.coverage,r),a(e.loadingCoverage,r);for(var p=e._getCornerTiles(r,h,d),g=p.topLeft,m=p.bottomRight,f=e.source.getNumTiles(r),v=e.viewport.pixelFromPoint(e.viewport.getCenter()),y=g.x;y<=m.x;y++)for(var w=g.y;w<=m.y;w++){if(!e.wrapHorizontal&&!e.wrapVertical){var T=e.source.getTileBounds(r,y,w);if(null===l.intersection(T))continue}u=i(e,n,t,y,w,r,o,s,v,f,c,u)}return u}function i(t,i,r,a,l,c,u,h,d,p,g,m){var f=function(t,i,n,r,o,s,a,l,c,u){var h,d,p,g,m,f,v,y,w;s[n]||(s[n]={});s[n][t]||(s[n][t]={});s[n][t][i]||(h=(l.x+t%l.x)%l.x,d=(l.y+i%l.y)%l.y,p=o.getTileBounds(n,h,d),g=o.getTileBounds(n,h,d,!0),m=o.tileExists(n,h,d),f=o.getTileUrl(n,h,d),r.loadTilesWithAjax?(v=o.getTileAjaxHeaders(n,h,d),e.isPlainObject(r.ajaxHeaders)&&(v=e.extend({},r.ajaxHeaders,v))):v=null,y=o.getContext2D?o.getContext2D(n,h,d):void 0,p.x+=(t-h)/l.x,p.y+=u/c*((i-d)/l.y),w=new e.Tile(n,t,i,p,m,f,y,r.loadTilesWithAjax,v,g),h===l.x-1&&(w.isRightMost=!0),d===l.y-1&&(w.isBottomMost=!0),s[n][t][i]=w);return(w=s[n][t][i]).lastTouchTime=a,w}(a,l,c,t,t.source,t.tilesMatrix,g,p,t._worldWidthCurrent,t._worldHeightCurrent),v=r;t.viewer&&t.viewer.raiseEvent("update-tile",{tiledImage:t,tile:f}),s(t.coverage,c,a,l,!1);var y=f.loaded||f.loading||o(t.loadingCoverage,c,a,l);if(s(t.loadingCoverage,c,a,l,y),!f.exists)return m;if(i&&!v&&(o(t.coverage,c,a,l)?s(t.coverage,c,a,l,!0):v=!0),!v)return m;if(function(t,i,n,r,o,s){var a=t.bounds.getTopLeft();a.x*=s._scaleSpring.current.value,a.y*=s._scaleSpring.current.value,a.x+=s._xSpring.current.value,a.y+=s._ySpring.current.value;var l=t.bounds.getSize();l.x*=s._scaleSpring.current.value,l.y*=s._scaleSpring.current.value;var c=n.pixelFromPointNoRotate(a,!0),u=n.pixelFromPointNoRotate(a,!1),h=n.deltaPixelsFromPointsNoRotate(l,!0),d=n.deltaPixelsFromPointsNoRotate(l,!1),p=u.plus(d.divide(2)),g=r.squaredDistanceTo(p);i||(h=h.plus(new e.Point(1,1)));t.isRightMost&&s.wrapHorizontal&&(h.x+=.75);t.isBottomMost&&s.wrapVertical&&(h.y+=.75);t.position=c,t.size=h,t.squaredDistance=g,t.visibility=o}(f,t.source.tileOverlap,t.viewport,d,h,t),!f.loaded)if(f.context2D)n(t,f);else{var w=t._tileCache.getImageRecord(f.cacheKey);if(w)n(t,f,w.getImage())}f.loaded?function(e,t,i,n,r,o,a){var l,c,u=1e3*e.blendTime;t.blendStart||(t.blendStart=a);l=a-t.blendStart,c=u?Math.min(1,l/u):1,e.alwaysBlend&&(c*=o);if(t.opacity=c,e.lastDrawn.push(t),1===c)s(e.coverage,r,i,n,!0),e._hasOpaqueTile=!0;else if(le.visibility)return t;if(t.visibility==e.visibility&&t.squaredDistanceo?(s=this._clip.x/this._clip.height*t.height,a=this._clip.y/this._clip.height*t.height):(s=this._clip.x/this._clip.width*t.width,a=this._clip.y/this._clip.width*t.width)),t.getAspectRatio()>o){var u=t.height/c,h=0;r.isHorizontallyCentered?h=(t.width-t.height*o)/2:r.isRight&&(h=t.width-t.height*o),this.setPosition(new e.Point(t.x-s+h,t.y-a),n),this.setHeight(u,n)}else{var d=t.width/l,p=0;r.isVerticallyCentered?p=(t.height-t.width/o)/2:r.isBottom&&(p=t.height-t.width/o),this.setPosition(new e.Point(t.x-s,t.y-a+p),n),this.setWidth(d,n)}},getClip:function(){return this._clip?this._clip.clone():null},setClip:function(t){e.console.assert(!t||t instanceof e.Rect,"[TiledImage.setClip] newClip must be an OpenSeadragon.Rect or null"),t instanceof e.Rect?this._clip=t.clone():this._clip=null,this._needsDraw=!0,this.raiseEvent("clip-change")},getOpacity:function(){return this.opacity},setOpacity:function(e){e!==this.opacity&&(this.opacity=e,this._needsDraw=!0,this.raiseEvent("opacity-change",{opacity:this.opacity}))},getPreload:function(){return this._preload},setPreload:function(e){this._preload=!!e,this._needsDraw=!0},getRotation:function(e){return e?this._degreesSpring.current.value:this._degreesSpring.target.value},setRotation:function(e,t){this._degreesSpring.target.value===e&&this._degreesSpring.isAtTargetValue()||(t?this._degreesSpring.resetTo(e):this._degreesSpring.springTo(e),this._needsDraw=!0,this._raiseBoundsChange())},_getRotationPoint:function(e){return this.getBoundsNoRotate(e).getCenter()},getCompositeOperation:function(){return this.compositeOperation},setCompositeOperation:function(e){e!==this.compositeOperation&&(this.compositeOperation=e,this._needsDraw=!0,this.raiseEvent("composite-operation-change",{compositeOperation:this.compositeOperation}))},_setScale:function(e,t){var i=this._scaleSpring.target.value===e;if(t){if(i&&this._scaleSpring.current.value===e)return;this._scaleSpring.resetTo(e),this._updateForScale(),this._needsDraw=!0}else{if(i)return;this._scaleSpring.springTo(e),this._updateForScale(),this._needsDraw=!0}i||this._raiseBoundsChange()},_updateForScale:function(){this._worldWidthTarget=this._scaleSpring.target.value,this._worldHeightTarget=this.normHeight*this._scaleSpring.target.value,this._worldWidthCurrent=this._scaleSpring.current.value,this._worldHeightCurrent=this.normHeight*this._scaleSpring.current.value},_raiseBoundsChange:function(){this.raiseEvent("bounds-change")},_isBottomItem:function(){return this.viewer.world.getItemAt(0)===this},_getLevelsInterval:function(){var e=Math.max(this.source.minLevel,Math.floor(Math.log(this.minZoomImageRatio)/Math.log(2))),t=this.viewport.deltaPixelsFromPointsNoRotate(this.source.getPixelRatio(0),!0).x*this._scaleSpring.current.value,i=Math.min(Math.abs(this.source.maxLevel),Math.abs(Math.floor(Math.log(t/this.minPixelRatio)/Math.log(2))));return i=Math.max(i,this.source.minLevel||0),{lowestLevel:e=Math.min(e,i),highestLevel:i}},_updateViewport:function(){for(this._needsDraw=!1,this._tilesLoading=0,this.loadingCoverage={};this.lastDrawn.length>0;){this.lastDrawn.pop().beingDrawn=!1}var i=this.viewport,o=this._viewportToTiledImageRectangle(i.getBoundsWithMargins(!0));if(!this.wrapHorizontal&&!this.wrapVertical){var s=this._viewportToTiledImageRectangle(this.getClippedBounds(!0));if(null===(o=o.intersection(s)))return}for(var a=this._getLevelsInterval(),l=a.lowestLevel,c=a.highestLevel,u=null,h=!1,d=e.now(),p=c;p>=l;p--){var g=!1,m=i.deltaPixelsFromPointsNoRotate(this.source.getPixelRatio(p),!0).x*this._scaleSpring.current.value;if(p===l||!h&&m>=this.minPixelRatio)g=!0,h=!0;else if(!h)continue;var f=i.deltaPixelsFromPointsNoRotate(this.source.getPixelRatio(p),!1).x*this._scaleSpring.current.value,v=i.deltaPixelsFromPointsNoRotate(this.source.getPixelRatio(Math.max(this.source.getClosestLevel(),0)),!1).x*this._scaleSpring.current.value,y=this.immediateRender?1:v;if(u=t(this,h,g,p,Math.min(1,(m-.5)/.5),y/Math.abs(y-f),o,d,u),r(this.coverage,p))break}!function(t,i){if(0===t.opacity||0===i.length&&!t.placeholderFillStyle)return;var n,r,o,s=i[0];s&&(n=t.opacity<1||t.compositeOperation&&"source-over"!==t.compositeOperation||!t._isBottomItem()&&s._hasTransparencyChannel());var a,l=t.viewport.getZoom(!0),c=t.viewportToImageZoom(l);i.length>1&&c>t.smoothTileEdgesMinZoom&&!t.iOSDevice&&t.getRotation(!0)%360==0&&e.supportsCanvas&&(n=!0,r=s.getScaleForEdgeSmoothing(),o=s.getTranslationForEdgeSmoothing(r,t._drawer.getCanvasSize(!1),t._drawer.getCanvasSize(!0)));n&&(r||(a=t.viewport.viewportToViewerElementRectangle(t.getClippedBounds(!0)).getIntegerBoundingBox().times(e.pixelDensityRatio),t._drawer.viewer.viewport.getFlip()&&(0===t.viewport.degrees&&t.getRotation(!0)%360==0||(a.x=t._drawer.viewer.container.clientWidth-(a.x+a.width)))),t._drawer._clear(!0,a));r||(0!==t.viewport.degrees&&t._drawer._offsetForRotation({degrees:t.viewport.degrees,useSketch:n}),t.getRotation(!0)%360!=0&&t._drawer._offsetForRotation({degrees:t.getRotation(!0),point:t.viewport.pixelFromPointNoRotate(t._getRotationPoint(!0),!0),useSketch:n}),0===t.viewport.degrees&&t.getRotation(!0)%360==0&&t._drawer.viewer.viewport.getFlip()&&t._drawer._flip());var u=!1;if(t._clip){t._drawer.saveContext(n);var h=t.imageToViewportRectangle(t._clip,!0);h=h.rotate(-t.getRotation(!0),t._getRotationPoint(!0));var d=t._drawer.viewportToDrawerRectangle(h);r&&(d=d.times(r)),o&&(d=d.translate(o)),t._drawer.setClip(d,n),u=!0}if(t.placeholderFillStyle&&!1===t._hasOpaqueTile){var p=t._drawer.viewportToDrawerRectangle(t.getBounds(!0));r&&(p=p.times(r)),o&&(p=p.translate(o));var g=null;g="function"==typeof t.placeholderFillStyle?t.placeholderFillStyle(t,t._drawer.context):t.placeholderFillStyle,t._drawer.drawRectangle(p,g,n)}for(var m=i.length-1;m>=0;m--)s=i[m],t._drawer.drawTile(s,t._drawingHandler,n,r,o),s.beingDrawn=!0,t.viewer&&t.viewer.raiseEvent("tile-drawn",{tiledImage:t,tile:s});u&&t._drawer.restoreContext(n);r||(t.getRotation(!0)%360!=0&&t._drawer._restoreRotationChanges(n),0!==t.viewport.degrees&&t._drawer._restoreRotationChanges(n));n&&(r&&(0!==t.viewport.degrees&&t._drawer._offsetForRotation({degrees:t.viewport.degrees,useSketch:!1}),t.getRotation(!0)%360!=0&&t._drawer._offsetForRotation({degrees:t.getRotation(!0),point:t.viewport.pixelFromPointNoRotate(t._getRotationPoint(!0),!0),useSketch:!1})),t._drawer.blendSketch({opacity:t.opacity,scale:r,translate:o,compositeOperation:t.compositeOperation,bounds:a}),r&&(t.getRotation(!0)%360!=0&&t._drawer._restoreRotationChanges(!1),0!==t.viewport.degrees&&t._drawer._restoreRotationChanges(!1)));r||0===t.viewport.degrees&&t.getRotation(!0)%360==0&&t._drawer.viewer.viewport.getFlip()&&t._drawer._flip();!function(t,i){if(t.debugMode)for(var n=i.length-1;n>=0;n--){var r=i[n];try{t._drawer.drawDebugInfo(r,i.length,n,t)}catch(t){e.console.error(t)}}}(t,i)}(this,this.lastDrawn),u&&!u.context2D?(!function(t,i,r){i.loading=!0,t._imageLoader.addJob({src:i.url,loadWithAjax:i.loadWithAjax,ajaxHeaders:i.ajaxHeaders,crossOriginPolicy:t.crossOriginPolicy,ajaxWithCredentials:t.ajaxWithCredentials,callback:function(o,s,a){!function(t,i,r,o,s,a){if(!o)return e.console.log("Tile %s failed to load: %s - error: %s",i,i.url,s),t.viewer.raiseEvent("tile-load-failed",{tile:i,tiledImage:t,time:r,message:s,tileRequest:a}),i.loading=!1,void(i.exists=!1);if(rthis._maxImageCacheCount){for(var a,l,c,u,h,d,p=null,g=-1,m=null,f=this._tilesLoaded.length-1;f>=0;f--)(a=(d=this._tilesLoaded[f]).tile).level<=r||a.beingDrawn||(p?(u=a.lastTouchTime,l=p.lastTouchTime,h=a.level,c=p.level,(uc)&&(p=a,g=f,m=d)):(p=a,g=f,m=d));p&&g>=0&&(this._unloadTile(m),o=g)}this._tilesLoaded[o]=new t({tile:n.tile,tiledImage:n.tiledImage})},clearTilesFor:function(t){var i;e.console.assert(t,"[TileCache.clearTilesFor] tiledImage is required");for(var n=0;n=this._items.length)throw new Error("Index bigger than number of layers.");i!==n&&-1!==n&&(this._items.splice(n,1),this._items.splice(i,0,t),this._needsDraw=!0,this.raiseEvent("item-index-change",{item:t,previousIndex:n,newIndex:i}))},removeItem:function(t){e.console.assert(t,"[World.removeItem] item is required");var i=e.indexOf(this._items,t);-1!==i&&(t.removeHandler("bounds-change",this._delegatedFigureSizes),t.removeHandler("clip-change",this._delegatedFigureSizes),t.destroy(),this._items.splice(i,1),this._figureSizes(),this._needsDraw=!0,this._raiseRemoveItem(t))},removeAll:function(){var e,t;for(this.viewer._cancelPendingImages(),t=0;tu.height?a:a*(u.width/u.height))*(u.height/u.width),p=new e.Point(g+(a-h)/2,m+(a-d)/2),c.setPosition(p,n),c.setWidth(h,n),"horizontal"===r?g+=l:m+=l;this.setAutoRefigureSizes(!0)},_figureSizes:function(){var t=this._homeBounds?this._homeBounds.clone():null,i=this._contentSize?this._contentSize.clone():null,n=this._contentFactor||0;if(this._items.length){var r=this._items[0],o=r.getBounds();this._contentFactor=r.getContentSize().x/o.width;for(var s=r.getClippedBounds().getBoundingBox(),a=s.x,l=s.y,c=s.x+s.width,u=s.y+s.height,h=1;h{const s=reakit.useTooltipState({placement:n});return React.useEffect(()=>{s.place(n)},[n]),React__default.createElement(React__default.Fragment,null,React__default.createElement(reakit.TooltipReference,_extends({},s,r,{ref:o}),e=>React__default.cloneElement(React__default.Children.only(i),e)),React__default.createElement(reakit.Tooltip,_extends({},s,{style:e,unstable_portal:!1,className:"villain-tooltip"}),t))}),ToolbarButton=React__default.forwardRef(({icon:e,iconSize:t,label:i,title:n,active:r,tooltip:o,onClick:s,children:a,typeClass:l,tooltipPlacement:c,...u},h)=>{const d={ref:h,...u},p=o?{}:d;let g=React__default.createElement(reakit.Button,_extends({focusable:!0,title:n,onClick:s,"aria-label":o,className:clsx("villain-button",l&&`villain-button--${l}`,r&&"villain-button--active")},p),e&&React__default.createElement(Icon$1,{path:e,size:t||"24px",className:"villain-icon"}),i&&React__default.createElement("span",{className:"villain-button__label"},i),a);return o&&(g=React__default.createElement(Tooltip,_extends({},d,{title:o,placement:c}),g)),g}),CustomSeparator=e=>React__default.createElement(reakit.MenuSeparator,_extends({},e,{className:"villain-menu__separator"})),CustomItem=({children:e,...t})=>React__default.createElement(reakit.MenuItem,_extends({as:ToolbarButton,className:"villain-menu__item"},t),React__default.createElement("div",{className:"villain-menu__item__content"},React__default.createElement("div",{className:"villain-menu__item__label"},e))),CustomCheckbox=({children:e,...t})=>React__default.createElement(reakit.MenuItemCheckbox,_extends({as:ToolbarButton},t),React__default.createElement("div",{className:"villain-menu__item__content"},React__default.createElement("div",{className:"villain-menu__item__label"},e),React__default.createElement("div",{className:"villain-menu__item__toggler"}))),CustomRadio=({children:e,...t})=>React__default.createElement(reakit.MenuItemRadio,_extends({as:ToolbarButton,icon:t.checked?mdiRadioboxMarked:mdiRadioboxBlank,iconSize:"20px"},t),React__default.createElement("div",{className:"villain-menu__item__content"},React__default.createElement("div",{className:"villain-menu__item__label"},e))),CustomSubmenu=({children:e,...t})=>React__default.createElement(reakit.MenuItem,_extends({},t,{as:ToolbarButton}),React__default.createElement("div",{className:"villain-menu__item__content"},React__default.createElement("div",{className:"villain-menu__item__label"},e),React__default.createElement(Icon$1,{path:mdiChevronRight,size:"24px",className:"villain-icon villain-menu__item__icon"}))),MenuHeader=({title:e,closeSubmenu:t,menuProps:i,...n})=>React__default.createElement("div",_extends({},n,{className:"villain-menu__header"}),React__default.createElement(CustomItem,_extends({},i,{icon:mdiChevronLeft,onClick:t}),e),React__default.createElement(CustomSeparator,_extends({},i,{style:{margin:0}}))),CustomItems={item:CustomItem,radio:CustomRadio,submenu:CustomSubmenu,checkbox:CustomCheckbox,separator:CustomSeparator};function Item({index:e,itemType:t,content:i,children:n,openSubmenu:r,onClick:o,...s}){const a=CustomItems[t]||CustomItems.item,l=clsx("separator"!==t&&"villain-menu__item",t&&`villain-menu__${t}`);return React__default.createElement(a,_extends({onClick:i=>{o&&o(i),"submenu"===t&&r&&r(e)},className:l},s),i||n)}function ItemList({title:e,items:t,getProps:i,menuProps:n,getContent:r,closeSubmenu:o}){return React__default.createElement(reakit.MenuGroup,n,t.map((t,s)=>React__default.createElement(Item,_extends({},n,i({item:t,index:s,closeSubmenu:o,title:e}),{key:`${t}-${s}`}),r(t))))}const MenuPanel=React__default.forwardRef(({title:e,items:t,list:i,openSubmenu:n,closeSubmenu:r,menuProps:o},s)=>React__default.createElement("div",{className:"villain-menu__panel",ref:s},e&&React__default.createElement(MenuHeader,{menuProps:o,closeSubmenu:r,title:e}),i?React__default.createElement(ItemList,_extends({},i,{title:e,menuProps:o,closeSubmenu:r})):t.map(({nestedTitle:t,nestedItems:i,nestedList:r,...s},a)=>{const l=`${s.itemType||"item"}-${a}`;return React__default.createElement(Item,_extends({},o,s,{title:e,openSubmenu:n,index:a,key:l}))}))),defaultSubmenuState={show:!1,list:null,index:null,title:null,items:null},MenuWithTooltip=React__default.forwardRef(({disclosure:e,tooltip:t,items:i,placement:n,ariaLabel:r,...o},s)=>{const a=reakit.useMenuState({placement:n,gutter:20}),l=reakit.useTooltipState({placement:n}),c=React__default.useRef(null),u=React__default.useRef(null),[h,d]=React__default.useState(0),[p,g]=React__default.useState({...defaultSubmenuState}),m=e=>{return e.getBoundingClientRect().height},f=()=>{g({...defaultSubmenuState})},v=e=>{g({index:e})},y=()=>{f()};return React__default.useEffect(()=>{a.visible?(()=>{const e=u.current;e&&d(m(e)),f()})():f()},[a.visible]),React__default.useEffect(()=>{if(p.index||0===p.index){const e=i[p.index];if(e){const t=e.nestedList&&e.nestedList.items&&e.nestedList.items.length>0,i=e.nestedItems&&e.nestedItems.length>0,n=t||i;n&&g({show:n,list:t?e.nestedList:null,items:i?e.nestedItems:null,title:e.nestedTitle})}}},[p.index,i]),React__default.useEffect(()=>{const e=c.current,t=u.current;p.show?e&&d(m(e)):t&&d(m(t)),a.first()},[p.show]),React__default.useEffect(()=>{h&&a.unstable_update()},[h]),React__default.createElement(React__default.Fragment,null,React__default.createElement(reakit.TooltipReference,_extends({ref:s},l,o),t=>React__default.createElement(reakit.MenuDisclosure,_extends({},a,t),t=>React__default.cloneElement(React__default.Children.only(e),t))),React__default.createElement(reakit.Tooltip,_extends({},l,{className:"villain-tooltip",unstable_portal:!1}),t),React__default.createElement(reakit.Menu,_extends({},a,{className:"villain-menu","aria-label":r,style:{height:`${h}px`}}),React__default.createElement("div",{className:"villain-menu__animated-content"},p.show?React__default.createElement(MenuPanel,{menuProps:a,list:p.list,title:p.title,items:p.items,openSubmenu:v,closeSubmenu:y,ref:c}):React__default.createElement(MenuPanel,{menuProps:a,items:i,openSubmenu:v,closeSubmenu:y,ref:u}))))}),Languages$8={EN:"English",ES:"Español",DE:"Deutsch",FR:"Français",PT:"Português",ID:"Bahasa Indonesia",RU:"Русский",ZH:"話僮"};function getLanguageName(e){return Languages$8[e]||e}const SettingsMenu=React__default.forwardRef((e,t)=>{const i=React.useContext(ReaderContext),n=React__default.createElement(ToolbarButton,{typeClass:"icon",icon:mdiSettings}),r="Dark"===i.state.theme,o=i.state.mangaMode,s=[{icon:mdiPagePrevious,content:localize["Manga mode"],checked:o,itemType:"checkbox",onChange:()=>{i.updateState(e=>({mangaMode:!e.mangaMode}))}},{icon:mdiBrightness4,content:localize["Dark theme"],checked:r,itemType:"checkbox",onChange:()=>{i.updateState(e=>({theme:"Dark"===e.theme?"Light":"Dark"}))}},{itemType:"separator"},{icon:mdiTranslate,content:localize.Language,itemType:"submenu",nestedTitle:localize.Languages,nestedList:{items:localize.getAvailableLanguages(),getProps:({item:e,index:t,closeSubmenu:n,title:r})=>({name:r,value:e,itemType:"radio",checked:localize.getLanguage()===e,onClick:n,onChange:()=>(e=>{i.updateState({language:e})})(e)}),getContent:e=>getLanguageName(e)}}];return React__default.createElement(MenuWithTooltip,_extends({},e,{ref:t,items:s,tooltip:localize.Settings,placement:"top",disclosure:n,ariaLabel:localize.Settings}))}),useFocus=()=>{const e=React.useRef(null);return[e,()=>{e.current&&(e.current.focus(),e.current.select())}]},getNestedFocus=e=>{const t=document.activeElement;return e.contains(t)},getInteractionFocus=()=>{const e=document.activeElement;if(e){return["BUTTON","INPUT","TEXTAREA"].includes(e.tagName)}},ZoomControls=({disabled:e,onUpdate:t,toolbarItemProps:i})=>{const n=React.useContext(ReaderContext),{canZoomIn:r,canZoomOut:o,currentZoom:s}=n.state,[a,l]=React.useState({value:""}),[c,u]=React.useState(!1),[h,d]=useFocus();React.useEffect(()=>{p()},[s]);const p=()=>{s&&l({value:s})},g=()=>{a.value.length>0?t(a.value):p()};return React__default.createElement("div",{className:"villain-toolbar__group"},React__default.createElement(reakit.ToolbarItem,_extends({},i,{typeClass:"icon",tooltip:localize["Zoom in"],icon:mdiPlus,disabled:!r||e,onClick:()=>{t(s+10)},as:ToolbarButton,focusable:!0})),React__default.createElement(reakit.ToolbarItem,_extends({},i,{typeClass:"icon",icon:mdiMinus,tooltip:localize["Zoom out"],disabled:!o||e,onClick:()=>{t(s-10)},as:ToolbarButton,focusable:!0})),React__default.createElement("div",{className:"villain-wrapper-input","data-focus":c,onClick:()=>{d()}},React__default.createElement(reakit.ToolbarItem,_extends({},i,{step:1,size:3,pattern:"d+",ref:h,type:"number",role:"textbox",contentEditable:"true",title:"Zoom","aria-label":"Zoom to percentage value",onBlur:()=>{g(),u(!1)},onFocus:()=>{u(!0)},onChange:e=>{const{value:t}=e.target,i=t.replace(/\..*|^0+[\s]/gm,"");i.length<4&&l({value:t?i:s})},onKeyPress:e=>{"Enter"===e.key&&g()},className:"villain-input",disabled:e,value:a.value,as:"input",focusable:!0})),React__default.createElement("div",{className:"villain-label villain-label--center"},"%")))},Navigation=({toolbarItemProps:e})=>{const t=React.useContext(ReaderContext),{totalPages:i,isFirstPage:n,isLastPage:r,mangaMode:o,currentPage:s}=t.state,{navigateForward:a,navigateBackward:l,navigateToPage:c}=t,[u,h]=React.useState({value:s||1}),[d,p]=React.useState(!1),[g,m]=useFocus();React.useEffect(()=>{f()},[s]);const f=()=>{h({value:s+1})},v=()=>{const{value:e}=u;if(e){const t=parseInt(e,10);t<=i&&t>0?c(t-1):f()}else f()};return React__default.createElement("div",{className:"villain-toolbar__group"},React__default.createElement(reakit.ToolbarItem,_extends({},e,{typeClass:"icon",icon:mdiChevronLeft,onClick:o?a:l,disabled:o?r:n,tooltip:o?localize["Next page"]:localize["Previous page"],tooltipPlacement:"top-start",as:ToolbarButton,focusable:!0})),React__default.createElement(reakit.ToolbarItem,_extends({},e,{typeClass:"icon",icon:mdiChevronRight,onClick:o?l:a,disabled:o?n:r,tooltip:localize["Next page"],as:ToolbarButton,focusable:!0})),React__default.createElement("div",{className:"villain-wrapper-input","data-focus":d,onClick:e=>{m()}},React__default.createElement(reakit.ToolbarItem,_extends({},e,{min:1,step:1,size:3,ref:g,max:i,type:"number","aria-label":"Go to page number",role:"textbox",contentEditable:"true",title:"Page",pattern:"d+",className:"villain-input",onBlur:()=>{v(),p(!1)},onFocus:()=>{p(!0)},onChange:e=>{const{value:t}=e.target,i=t.replace(/\..*|^0+/gm,"");i.length<4&&h({value:t?i:s+1})},onKeyPress:e=>{"Enter"===e.key&&v()},value:u.value,as:"input",focusable:!0})),React__default.createElement("div",{className:"villain-label villain-label--center"},"/"),React__default.createElement("div",{className:"villain-label"},`${i}`)))};function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArrayLimit(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var i=[],n=!0,r=!1,o=void 0;try{for(var s,a=e[Symbol.iterator]();!(n=(s=a.next()).done)&&(i.push(s.value),!t||i.length!==t);n=!0);}catch(e){r=!0,o=e}finally{try{n||null==a.return||a.return()}finally{if(r)throw o}}return i}}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_nonIterableRest()}function _extends$1(){return(_extends$1=Object.assign||function(e){for(var t=1;t2?n-2:0);for(var r=2;r0&&void 0!==arguments[0]?arguments[0]:{},t=i.props,n=t.emitMouse,r=t.emitTouch;return _objectSpread({},e,{onMouseDown:callAll(e.onMouseDown,n),onTouchStart:callAll(e.onTouchStart,r)})})),i}return _inherits(t,e),_createClass(t,[{key:"render",value:function(){var e=this.getRailProps,t=this.props,i=t.getEventData,n=t.activeHandleID,r=(0,t.children)({getEventData:i,activeHandleID:n,getRailProps:e});return r&&React__default.Children.only(r)}}]),t}(React.Component);Rail.propTypes={getEventData:propTypes.func,activeHandleID:propTypes.string,emitMouse:propTypes.func,emitTouch:propTypes.func,children:propTypes.func.isRequired};var Ticks=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"render",value:function(){var e=this.props,t=e.children,i=e.values,n=e.scale,r=e.count,o=t({getEventData:e.getEventData,activeHandleID:e.activeHandleID,ticks:(i||n.getTicks(r)).map((function(e){return{id:"$$-".concat(e),value:e,percent:n.getValue(e)}}))});return o&&React__default.Children.only(o)}}]),t}(React.Component);function ownKeys$1(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function _objectSpread$1(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:{},t=i.props,n=t.emitMouse,r=t.emitTouch;return _objectSpread$1({},e,{onMouseDown:callAll(e.onMouseDown,n),onTouchStart:callAll(e.onTouchStart,r)})})),i}return _inherits(t,e),_createClass(t,[{key:"render",value:function(){for(var e=this.getTrackProps,t=this.props,i=t.children,n=t.left,r=t.right,o=t.scale,s=t.handles,a=t.getEventData,l=t.activeHandleID,c=o.getDomain(),u=[],h=0;h1&&void 0!==arguments[1]?arguments[1]:{},n=i.props,r=n.emitKeyboard,o=n.emitMouse,s=n.emitTouch;return _objectSpread$2({},t,{onKeyDown:callAll(t.onKeyDown,(function(t){return r(t,e)})),onMouseDown:callAll(t.onMouseDown,i.autofocus,(function(t){return o(t,e)})),onTouchStart:callAll(t.onTouchStart,(function(t){return s(t,e)}))})})),i}return _inherits(t,e),_createClass(t,[{key:"render",value:function(){var e=this.getHandleProps,t=this.props,i=t.activeHandleID,n=(0,t.children)({handles:t.handles,activeHandleID:i,getHandleProps:e});return n&&React__default.Children.only(n)}}]),t}(React.Component);function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,i=new Array(e.length);ti.val?e?-1:1:i.val>t.val?e?1:-1:0}}function getUpdatedHandles(e,t,i,n){var r=e.findIndex((function(e){return e.key===t}));if(-1!==r){var o=e[r],s=o.key;return o.val===i?e:[].concat(_toConsumableArray(e.slice(0,r)),[{key:s,val:i}],_toConsumableArray(e.slice(r+1))).sort(getSortByVal(n))}return e}function getSliderDomain(e,t){if(!e)return[0,0];var i=e.getBoundingClientRect();return[t?i.top:i.left,t?i.bottom:i.right]}function isNotValidTouch(e){var t=e.type,i=void 0===t?"":t,n=e.touches;return!n||n.length>1||"touchend"===i.toLowerCase()&&n.length>0}function getTouchPosition(e,t){return e?t.touches[0].clientY:t.touches[0].pageX}function getHandles(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1?arguments[1]:void 0,i=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0,r=0;return{handles:e.map((function(e){var t=i.getValue(e);return e!==t&&(r+=1,warning_1(!n,"".concat(prfx," Invalid value encountered. Changing ").concat(e," to ").concat(t,"."))),t})).map((function(e,t){return{key:"$$-".concat(t),val:e}})).sort(getSortByVal(t)),changes:r}}function mode1(e,t){return t}function mode2(e,t){for(var i=0;i0)}if(-1===o)return e;for(var u=s?i:-i,h=0;ht?1:e>=t?0:NaN}function bisector(e){return 1===e.length&&(e=ascendingComparator(e)),{left:function(t,i,n,r){for(null==n&&(n=0),null==r&&(r=t.length);n>>1;e(t[o],i)<0?n=o+1:r=o}return n},right:function(t,i,n,r){for(null==n&&(n=0),null==r&&(r=t.length);n>>1;e(t[o],i)>0?r=o:n=o+1}return n}}}function ascendingComparator(e){return function(t,i){return ascending(e(t),i)}}var ascendingBisect=bisector(ascending),e10=Math.sqrt(50),e5=Math.sqrt(10),e2=Math.sqrt(2);function ticks(e,t,i){var n,r,o,s,a=-1;if(i=+i,(e=+e)===(t=+t)&&i>0)return[e];if((n=t0)for(e=Math.ceil(e/s),t=Math.floor(t/s),o=new Array(r=Math.ceil(t-e+1));++a=0?(o>=e10?10:o>=e5?5:o>=e2?2:1)*Math.pow(10,r):-Math.pow(10,-r)/(o>=e10?10:o>=e5?5:o>=e2?2:1)}var LinearScale=function(){function e(){_classCallCheck(this,e),this.domain=[0,1],this.range=[0,1],this.interpolator=null}return _createClass(e,[{key:"createInterpolator",value:function(e,t){var i=e[0],n=e[1],r=t[0],o=t[1];return ns?a:s)})),this.step=1,this.domain=[0,1],this.range=[0,1]},isBrowser="undefined"!=typeof window&&"undefined"!=typeof document,noop=function(){},compare=function(e){return function(t,i,n){return t&&e[n]===i}},equal=function(e,t){return e===t||e.length===t.length&&e.reduce(compare(t),!0)},getNextValue=function(e,t,i,n){var r=n?e-t:e+t;return n?Math.max(i[0],r):Math.min(i[1],r)},getPrevValue=function(e,t,i,n){var r=n?e+t:e-t;return n?Math.min(i[1],r):Math.max(i[0],r)},Slider=function(e){function t(){var e,i;_classCallCheck(this,t);for(var n=arguments.length,r=new Array(n),o=0;og,"".concat(prfx," Max must be greater than min (even if reversed). Max is ").concat(m,". Min is ").concat(g,"."));var f=getHandles(n||t.values,o,u,l),v=f.handles;(f.changes||void 0===n||n===t.values)&&(s(v.map((function(e){return e.val}))),a(v.map((function(e){return e.val})))),d.step=i,d.values=n,d.domain=r,d.handles=v,d.reversed=o}else if(!equal(n,t.values)){var y=getHandles(n,o,u,l),w=y.handles;y.changes&&(s(w.map((function(e){return e.val}))),a(w.map((function(e){return e.val})))),d.values=n,d.handles=w}return Object.keys(d).length?d:null}}]),t}(React.PureComponent);Slider.propTypes={component:propTypes.string,rootStyle:propTypes.object,rootProps:propTypes.object,className:propTypes.string,domain:propTypes.array,values:propTypes.array,step:propTypes.number,mode:propTypes.oneOfType([propTypes.number,propTypes.func]),vertical:propTypes.bool,reversed:propTypes.bool,onChange:propTypes.func,onUpdate:propTypes.func,onSlideStart:propTypes.func,onSlideEnd:propTypes.func,disabled:propTypes.bool,flatten:propTypes.bool,warnOnChanges:propTypes.bool,children:propTypes.any},Slider.defaultProps={mode:1,step:.1,domain:[0,100],component:"div",rootProps:{},rootStyle:{},vertical:!1,reversed:!1,onChange:noop,onUpdate:noop,onSlideStart:noop,onSlideEnd:noop,disabled:!1,flatten:!1,warnOnChanges:!1},Slider.Rail=Rail,Slider.Ticks=Ticks,Slider.Tracks=Tracks,Slider.Handles=Handles;const Tooltip$1=({value:e=null})=>React__default.createElement("div",{className:"villain-tooltip--slider"},React__default.createElement("div",{className:"villain-tooltip--slider__container"},React__default.createElement("div",{className:"villain-tooltip--slider__text"},e)));Tooltip$1.propTypes={value:propTypes.number};const Handle=({domain:[e,t],handle:{id:i,value:n,percent:r},isActive:o,disabled:s,getHandleProps:a,toolbarItemProps:l})=>{const[c,u]=React.useState(!1);return React__default.createElement(reakit.ToolbarItem,_extends({},l,{role:"slider","aria-valuemin":e,"aria-valuemax":t,"aria-valuenow":n,style:{height:14,width:14,left:`${r}%`,position:"absolute",transform:"translate(-50%, -50%)",WebkitTapHighlightColor:"rgba(0,0,0,0)",border:0,borderRadius:"50%",backgroundColor:s?"transparent":"var(--slider-track-bg)",zIndex:1,margin:0,padding:0}},a(i,{onMouseEnter:()=>{u(!0)},onMouseLeave:()=>{u(!1)}}),{as:"button"}),!c&&!o||s?null:React__default.createElement(Tooltip$1,{value:n}))};Handle.propTypes={domain:propTypes.array.isRequired,handle:propTypes.shape({id:propTypes.string.isRequired,value:propTypes.number.isRequired,percent:propTypes.number.isRequired}).isRequired,getHandleProps:propTypes.func.isRequired,isActive:propTypes.bool.isRequired,disabled:propTypes.bool};var Handle$1=React__default.memo(Handle);const railStyle={position:"absolute",margin:0,width:"100%",height:"100%",cursor:"pointer",borderRadius:"4px",backgroundColor:"var(--slider-bg)",zIndex:-1},SliderRail=({activeHandleID:e,getEventData:t,getRailProps:i})=>{const[n,r]=React.useState(null),[o,s]=React.useState(null),a=i=>{e?(r(null),s(null)):(r(t(i).value),s(t(i).percent))};return React__default.createElement("div",_extends({style:railStyle},i({onMouseEnter:()=>{document.addEventListener("mousemove",a)},onMouseLeave:()=>{r(null),s(null),document.removeEventListener("mousemove",a)}})))};SliderRail.propTypes={activeHandleID:propTypes.string,getEventData:propTypes.func.isRequired,getRailProps:propTypes.func.isRequired};const sliderStyle={position:"absolute",width:"100%",height:4,display:"flex",alignItems:"center",borderRadius:"4px",justifyContent:"center",zIndex:99},Track=({source:e,target:t,getTrackProps:i})=>React__default.createElement("div",_extends({className:"villain-slider__track",style:{zIndex:0,left:`${e.percent}%`,width:`${t.percent-e.percent}%`}},i())),defaultValues=[1],SliderUI=({max:e=1,bufferProgress:t=0,reversed:i,onChange:n,value:r,toolbarItemProps:o})=>{const[s,a]=React.useState(!1),[l,c]=React.useState(defaultValues.slice()),u=[1,e];if(1==e)return null;return React.useEffect(()=>{s||c([r+1])},[r]),React__default.createElement("div",{className:"villain-slider",style:{height:sliderStyle.height}},React__default.createElement(Slider,{rootStyle:sliderStyle,domain:u,step:1,mode:2,values:l,onUpdate:()=>a(!0),onChange:e=>{a(!1),n(e[0]-1)},reversed:i},React__default.createElement(Rail,null,({activeHandleID:e,getEventData:t,getRailProps:i})=>React__default.createElement(SliderRail,{activeHandleID:e,getEventData:t,getRailProps:i})),React__default.createElement(Handles,null,({handles:e,activeHandleID:t,getHandleProps:i})=>React__default.createElement("div",{className:"villain-slider__handles"},e.map(e=>React__default.createElement(Handle$1,{key:e.id,handle:e,domain:u,isActive:e.id===t,getHandleProps:i,toolbarItemProps:o})))),React__default.createElement(Tracks,{right:i,left:!i},({tracks:e,getTrackProps:t})=>React__default.createElement("div",{className:"villain-slider__tracks"},e.map(({id:e,source:i,target:n})=>React__default.createElement(Track,{key:e,source:i,target:n,getTrackProps:t}))))),React__default.createElement("div",{className:"villain-slider__buffer",style:{width:`${t}%`,borderRadius:"4px",right:i?0:"initial"}}))};var Slider$1=React__default.memo(SliderUI);const Toolbar=({container:e,updateZoom:t,renderError:i,showControls:n,toggleFullscreen:r})=>{const{state:o,toggleSetting:s,navigateForward:a,navigateBackward:l,navigateToPage:c,togglePin:u,toggleTheme:h}=React.useContext(ReaderContext),{pages:d,bookMode:p,mangaMode:g,totalPages:m,fullscreen:f,currentPage:v,currentZoom:y,allowFullScreen:w,autoHideControls:T,allowGlobalShortcuts:_}=o,S=React.useCallback(t=>{if(getInteractionFocus())return;if(!_&&!getNestedFocus(e))return;const i=g?l:a,n=g?a:l;switch(t.key){case"f":t.preventDefault(),r();break;case"ArrowRight":i();break;case"ArrowLeft":n()}},[_,g,l,a,r]);React.useEffect(()=>(document.addEventListener("keydown",S),()=>{document.removeEventListener("keydown",S)}),[S]);const x=f?mdiFullscreenExit:mdiFullscreen,b=d.length/m*100,E=reakit.useToolbarState();return React__default.createElement(reakit.Toolbar,_extends({},E,{"aria-label":"Toolbar",className:clsx("villain-toolbar",!n&&"villain-toolbar--hide")}),React__default.createElement(Navigation,{currentPage:v,totalPages:m,toolbarItemProps:E}),React__default.createElement("div",{className:"villain-toolbar__group villain-toolbar__group--expand"},React__default.createElement(Slider$1,{max:m,value:v,bufferProgress:b,onChange:c,reversed:g,toolbarItemProps:E})),React__default.createElement("div",{className:"villain-toolbar__group",disabled:i},React__default.createElement(ZoomControls,{onUpdate:t,currentZoom:y,disabled:i,toolbarItemProps:E}),React__default.createElement(reakit.ToolbarSeparator,{className:"villain-toolbar__divider"}),React__default.createElement(reakit.ToolbarItem,_extends({},E,{as:SettingsMenu})),React__default.createElement(reakit.ToolbarItem,_extends({},E,{typeClass:"icon",icon:T?mdiPin:mdiPinOff,onClick:u,disabled:i,tooltip:T?localize["Pin toolbar"]:localize["Unpin toolbar"],as:ToolbarButton,focusable:!0})),React__default.createElement(reakit.ToolbarItem,_extends({},E,{typeClass:"icon",icon:p?mdiBookOpen:mdiBookOpenOutline,onClick:()=>s("bookMode"),disabled:i,tooltip:p?localize["Page view"]:localize["Book view"],tooltipPlacement:w?"top":"top-end",as:ToolbarButton,focusable:!0})),w&&React__default.createElement(reakit.ToolbarItem,_extends({},E,{typeClass:"icon",icon:x,onClick:r,disabled:i,tooltip:f?localize["Exit fullscreen"]:localize["Enter fullscreen"],tooltipPlacement:"top-end",as:ToolbarButton,focusable:!0}))))},prefixes={exitFullscreen:["exitFullscreen","msExitFullscreen","mozCancelFullScreen","webkitExitFullscreen"],fullscreenChange:["fullscreenchange","MSFullscreenChange","mozfullscreenchange","webkitfullscreenchange"],fullscreenEnabled:["fullscreenEnabled","msFullscreenEnabled","mozFullScreenEnabled","webkitFullscreenEnabled"],fullscreenElement:["fullscreenElement","msFullscreenElement","mozFullScreenElement","webkitFullscreenElement"],requestFullscreen:["requestFullscreen","msRequestFullscreen","mozRequestFullScreen","webkitRequestFullscreen"]},getPrefix=()=>{let e=0;return prefixes.fullscreenEnabled.some((t,i)=>{if(document[t]||!1===document[t])return e=i,!0}),e},fullscreenElement=()=>{const e=getPrefix(),t=prefixes.fullscreenElement[e];return document[t]},requestFullscreen=e=>{const t=getPrefix(),i=prefixes.requestFullscreen[t];e[i]&&e[i]()},exitFullscreen=()=>{const e=getPrefix(),t=prefixes.exitFullscreen[e];document[t]&&document[t]()},toggleFullscreen=e=>{fullscreenElement()?exitFullscreen():requestFullscreen(e)},onFullscreenChange=(e,t,i)=>{const n=getPrefix(),r=prefixes.fullscreenChange[n];e[`${t}EventListener`](r,i,!1)};class CanvasRender extends React.Component{constructor(e){super(e),_defineProperty(this,"getTargetZoom",(e=1)=>{const{viewport:t,world:i}=this.viewer,n=i.getItemCount();if(n>1){return i.getItemAt(0).imageToViewportZoom(e)}if(n&&1===n)return t.imageToViewportZoom(e)}),_defineProperty(this,"updateZoomLimits",()=>{const{viewport:e}=this.viewer,t=this.getTargetZoom(),i=this.viewer.world.getItemAt(0).getBounds(),n=e.getBounds(),r=i.width/i.height/(n.width/n.height),o=.9*(r>=1?1:r)/i.width,s=t<=o?t:o;e.defaultZoomLevel=s,e.minZoomLevel=s,e.maxZoomLevel=t}),_defineProperty(this,"updateZoom",(e=1)=>{const{viewport:t}=this.viewer,i=this.getTargetZoom(),n=t.getMinZoom();let r=e;"string"==typeof r&&(r=parseInt(r)),r&&(r>100&&(r=100),(r=r/100*this.getTargetZoom())>i&&(r=i),r{const e=this.getTargetZoom();this.viewer.viewport.zoomTo(e,null,!0)}),_defineProperty(this,"handleFocus",()=>{const{container:e}=this.props;this.context.updateState({focus:getNestedFocus(e)})}),_defineProperty(this,"handleBlur",()=>{this.context.updateState({focus:!1})}),_defineProperty(this,"handleEnter",()=>{const{autoHideControls:e}=this.context.state;e&&this.context.updateState({hover:!0})}),_defineProperty(this,"handleExit",()=>{const{autoHideControls:e}=this.context.state;e&&this.context.updateState({hover:!1})}),_defineProperty(this,"handleError",e=>{this.viewer.close(),this.context.updateState({renderError:!0}),console.error(e)}),_defineProperty(this,"handleFullscreenChange",()=>{const e=null!==fullscreenElement();this.context.updateState({fullscreen:e}),this.updateZoomLimits()}),_defineProperty(this,"handleZoom",({zoom:e})=>{const{viewport:t}=this.viewer,i=t.getMinZoom(),n=t.getMaxZoom(),r=parseInt(e/n*100),o=ei;this.context.updateState({currentZoom:r,canZoomIn:o,canZoomOut:s})}),_defineProperty(this,"handleZoomOptimized",e=>{this.isScrolling||this.handleZoom(e)}),_defineProperty(this,"handleScrollOptimized",()=>{this.isScrolling=!0,window.clearTimeout(this.clearScrollingDelay),this.clearScrollingDelay=setTimeout(()=>{this.isScrolling=!1,this.handleZoomOptimized({zoom:this.viewer.viewport.getZoom()})},750)}),_defineProperty(this,"toggleFullscreen",()=>{const{container:e}=this.props,{allowFullScreen:t}=this.context.state;t&&toggleFullscreen(e)}),this.viewer=null,this.browser=null,this.isScrolling=!1,this.clearScrollingDelay=null}initOpenSeaDragon(){const{id:e,container:t}=this.props,{pages:i}=this.context.state;this.browser=getKeyByValue(openseadragon.BROWSERS,openseadragon.Browser.vendor),this.viewer=openseadragon({id:e,tileSources:i[0],...config}),this.viewer.addHandler("open",()=>{this.renderLayout(),this.updateZoomLimits(),this.viewer.viewport.zoomTo(this.viewer.viewport.getMinZoom(),null,!0),this.context.updateState({renderError:!1})}),this.viewer.addHandler("resize",()=>{this.updateZoomLimits()}),"FIREFOX"===this.browser?(this.viewer.addHandler("zoom",this.handleZoomOptimized),this.viewer.addHandler("canvas-scroll",this.handleScrollOptimized)):this.viewer.addHandler("zoom",this.handleZoom),this.viewer.addHandler("canvas-exit",this.handleExit),this.viewer.addHandler("canvas-enter",this.handleEnter),this.viewer.addHandler("open-failed",this.handleError),document.addEventListener("blur",this.handleBlur,!0),document.addEventListener("focus",this.handleFocus,!0),onFullscreenChange(t,"add",this.handleFullscreenChange)}renderPage(e){const t=this.context.getPage(e);t&&this.viewer.open(t)}renderCover(){this.renderPage(0)}renderLayout(){const{viewport:e,world:t}=this.viewer,{currentPage:i}=this.context.state,n=new openseadragon.Point(0,0),r=t.getItemCount();let o=null,s=null,a=null;for(let e=0;e=0&&rReact__default.createElement(ReaderProvider,{externalOptions:n},React__default.createElement(Wrapp$1,{width:t,height:i,externalOptions:n},t=>React__default.createElement(Uncompress,{file:e,workerUrl:r},React__default.createElement(ReaderContext.Consumer,null,e=>React__default.createElement(CanvasRender,{id:"osd-canvas-render",container:t,contextState:e.state})))));return Villain.propTypes={file:propTypes.oneOfType([propTypes.string,propTypes.instanceOf(Blob)]),width:propTypes.string,height:propTypes.string,options:propTypes.shape({theme:propTypes.string,workerUrl:propTypes.string,preview:propTypes.number})},Villain})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("reakit")):"function"==typeof define&&define.amd?define(["react","reakit"],t):(e=e||self).villain=t(e.React,e.reakit)}(this,(function(React,reakit){"use strict";var React__default="default"in React?React.default:React;function toVal(e){var t,i,n="";if(e)if("object"==typeof e)if(e.push)for(t=0;t1?t-1:0),n=1;n2?i-2:0),r=2;r1?printWarning$1("Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z])."):printWarning$1("Invalid argument supplied to oneOf, expected an array."),emptyFunctionThatReturnsNull;return l((function(t,i,n,r,o){for(var l=t[i],c=0;c{this.setState(e,t)}),_defineProperty(this,"clear",()=>{this.setState({...defaultState})}),_defineProperty(this,"toggleSetting",e=>{this.setState(t=>({[e]:!t[e]}))}),_defineProperty(this,"createPage",e=>{const t=this.state.pages.concat(e);0===e.index?this.setState({ready:!0,error:null,currentPage:0,pages:t}):this.setState({pages:t})}),_defineProperty(this,"trigger",(e,t)=>{"error"===e&&t&&(console.error(t),this.setState({ready:!1,error:t})),"loaded"===e&&t&&this.setState({...t})}),_defineProperty(this,"togglePin",()=>{this.setState(e=>({autoHideControls:!e.autoHideControls}))}),_defineProperty(this,"toggleTheme",()=>{this.setState(e=>({theme:"Light"===e.theme?"Dark":"Light"}))}),_defineProperty(this,"navigateToPage",e=>{this.setState(t=>{const{totalPages:i}=t,n=i-1;return e<0||e>n?{}:{isLastPage:e===n,isFirstPage:0===e,currentPage:e}})}),_defineProperty(this,"navigateForward",()=>{const{isLastPage:e,currentPage:t}=this.state;e||this.navigateToPage(t+1)}),_defineProperty(this,"navigateBackward",()=>{const{isFirstPage:e,currentPage:t}=this.state;e||this.navigateToPage(t-1)}),_defineProperty(this,"getPage",e=>{const{pages:t,bookMode:i,mangaMode:n,totalPages:r}=this.state,o=t[e],s=e+1;if(i&&((s>=0||s=0?e.substring(0,i):e;return t[n]?n:Object.keys(t)[0]},t.validateTranslationKeys=function(e){var t=["_interfaceLanguage","_language","_defaultLanguage","_defaultLanguageFirstLevelKeys","_props"];e.forEach((function(e){if(-1!==t.indexOf(e))throw new Error(e+" cannot be used as a key. It is a reserved word.")}))},t.randomPseudo=function(e){for(var t="",i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=0;n1?i-1:0),r=1;r2&&void 0!==arguments[2]&&arguments[2];try{for(var n=this._props[t||this._language],r=e.split("."),o=0;o1?t-1:0),o=1;o{const r=React.useContext(ReaderContext),o=React.useRef(null),{theme:s,language:a,fullscreen:l,autoHideControls:c}=r.state,u={width:t,height:i};return React.useEffect(()=>{Object.entries(n).map(([e,t])=>{r.state[e]!==t&&r.updateState({[e]:t})})},[n]),localize.setLanguage(a),React__default.createElement("div",{ref:o,className:clsx("villain",s,l&&"villain--fullscreen",!c&&"villain--static"),style:u},e(o?o.current:null))};var Wrapp$1=React__default.memo(Wrapp);class CompressedFile{constructor(e,t,i,n){this._name=e,this._size=t,this._path=i,this._archiveRef=n}get name(){return this._name}get size(){return this._size}extract(){return this._archiveRef.extractSingleFile(this._path)}}class Archive{static init(e={}){return Archive._options={workerUrl:"../dist/worker-bundle.js",...e},Archive._options}static open(e,t=null){return t=t||Archive._options||Archive.init()&&console.warn("Automatically initializing using options: ",Archive._options),new Archive(e,t).open()}constructor(e,t){this._worker=new Worker(t.workerUrl),this._worker.addEventListener("message",this._workerMsg.bind(this)),this._callbacks=[],this._content={},this._processed=0,this._file=e}async open(){return await this._postMessage({type:"HELLO"},(e,t,i)=>{"READY"===i.type&&e()}),await this._postMessage({type:"OPEN",file:this._file},(e,t,i)=>{"OPENED"===i.type&&e(this)})}hasEncryptedData(){return this._postMessage({type:"CHECK_ENCRYPTION"},(e,t,i)=>{"ENCRYPTION_STATUS"===i.type&&e(i.status)})}usePassword(e){return this._postMessage({type:"SET_PASSPHRASE",passphrase:e},(e,t,i)=>{"PASSPHRASE_STATUS"===i.type&&e(i.status)})}getFilesObject(){return this._processed>0?Promise.resolve().then(()=>this._content):this._postMessage({type:"LIST_FILES"},(e,t,i)=>{if("ENTRY"===i.type){const e=i.entry,[t,n]=this._getProp(this._content,e.path);return"FILE"===e.type&&(t[n]=new CompressedFile(e.fileName,e.size,e.path,this)),!0}"END"===i.type&&(this._processed=1,e(this._cloneContent(this._content)))})}getFilesArray(){return this.getFilesObject().then(e=>this._objectToArray(e))}extractSingleFile(e){return this._postMessage({type:"EXTRACT_SINGLE_FILE",target:e},(e,t,i)=>{if("FILE"===i.type){e(new File([i.entry.fileData],i.entry.fileName,{type:"application/octet-stream"}))}})}extractFiles(e){return this._processed>1?Promise.resolve().then(()=>this._content):this._postMessage({type:"EXTRACT_FILES"},(t,i,n)=>{if("ENTRY"===n.type){const[t,i]=this._getProp(this._content,n.entry.path);return"FILE"===n.entry.type&&(t[i]=new File([n.entry.fileData],n.entry.fileName,{type:"application/octet-stream"}),void 0!==e&&setTimeout(e.bind(null,{file:t[i],path:n.entry.path}))),!0}"END"===n.type&&(this._processed=2,this._worker.terminate(),t(this._cloneContent(this._content)))})}_cloneContent(e){if(e instanceof File||e instanceof CompressedFile||null===e)return e;const t={};for(const i of Object.keys(e))t[i]=this._cloneContent(e[i]);return t}_objectToArray(e,t=""){const i=[];for(const n of Object.keys(e))e[n]instanceof File||e[n]instanceof CompressedFile||null===e[n]?i.push({file:e[n]||n,path:t}):i.push(...this._objectToArray(e[n],`${t}${n}/`));return i}_getProp(e,t){const i=t.split("/");""===i[i.length-1]&&i.pop();let n=e,r=null;for(const e of i)n[e]=n[e]||{},r=n,n=n[e];return[r,i[i.length-1]]}_postMessage(e,t){return this._worker.postMessage(e),new Promise((e,i)=>{this._callbacks.push(this._msgHandler.bind(this,t,e,i))})}_msgHandler(e,t,i,n){if("BUSY"===n.type)i("worker is busy");else{if("ERROR"!==n.type)return e(t,i,n);i(n.error)}}_workerMsg({data:e}){(0,this._callbacks[this._callbacks.length-1])(e)||this._callbacks.pop()}}const regexImage=new RegExp(/^[a-zA-Z0-9_@()-][a-zA-Z0-9_.@()-\s]+.(jpeg|jpg|png|bpm|webp)$/),status=e=>e.status>=200&&e.status<300?Promise.resolve(e):Promise.reject(new Error(e.statusText)),isValidImageType=e=>regexImage.test(e),fetchArchive=(e,t,i)=>{fetch(e,{mode:"cors"}).then(status).then(e=>{e.headers.get("Content-Type");return e.blob()}).then(t).catch(e=>{i&&i(localize["Cant open archive"]),console.error("Request failed",e)})},asyncForEach=async(e,t)=>{for(let i=0;iObject.keys(e).find(i=>e[i]===t);var Icon=createCommonjsModule((function(e){e.exports=function(e){var t={};function i(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=2)}([function(e,t){e.exports=propTypes},function(e,t){e.exports=React__default},function(e,t,i){i.r(t);var n=i(1),r=i(0),o=function(){return(o=Object.assign||function(e){for(var t,i=1,n=arguments.length;i0&&(x.transform=C.join(" "),x.transformOrigin="center",E&&(k=n.createElement("g",{style:x},O,n.createElement("rect",{width:"24",height:"24",fill:"transparent"}))));var I,M=k,L=!0===_||"number"!=typeof _?2:_,D=!E&&(m||v);if(L<0&&(D=!D),_&&(M=n.createElement("g",{style:{animation:"spin"+(D?"-inverse":"")+" linear "+Math.abs(L)+"s infinite",transformOrigin:"center"}},k,!(m||v||0!==w)&&n.createElement("rect",{width:"24",height:"24",fill:"transparent"}))),E)return M;var H,A="icon_labelledby_"+u,z="icon_describedby_"+u;if(o)I=a?A+" "+z:A;else if(H="presentation",a)throw new Error("title attribute required when description is set");return n.createElement("svg",c({ref:t,viewBox:"0 0 24 24",style:x,role:H,"aria-labelledby":I},P),o&&n.createElement("title",{id:A},o),a&&n.createElement("desc",{id:z},a),!E&&_&&(D?n.createElement("style",null,"@keyframes spin-inverse { to { transform: rotate(-360deg) } }"):n.createElement("style",null,"@keyframes spin { to { transform: rotate(360deg) } }")),M)}));h.displayName="Icon",h.propTypes={path:r.string.isRequired,size:r.oneOfType([r.number,r.string]),color:r.string,horizontal:r.bool,vertical:r.bool,rotate:r.number,spin:r.oneOfType([r.bool,r.number]),style:r.object,inStack:r.bool,className:r.string},h.defaultProps={size:null,color:null,horizontal:!1,vertical:!1,rotate:0,spin:!1},t.default=h}])})),Icon$1=unwrapExports(Icon);const Error$1=React__default.memo(e=>{const{icon:t,message:i}=e;return React__default.createElement("div",{className:"villain-overlay villain-overlay--canvas"},React__default.createElement(Icon$1,{className:"villain-icon",path:t,size:3}),React__default.createElement("div",{className:"villain-overlay--message"},React__default.createElement("h3",null,i)))}),Loader=({id:e})=>React__default.createElement("div",{className:"villain-overlay",id:e},React__default.createElement("div",{className:"villain-loader-indicator"}));var Loader$1=React__default.memo(Loader),mdiBookOpen="M13,12H20V13.5H13M13,9.5H20V11H13M13,14.5H20V16H13M21,4H3A2,2 0 0,0 1,6V19A2,2 0 0,0 3,21H21A2,2 0 0,0 23,19V6A2,2 0 0,0 21,4M21,19H12V6H21",mdiBookOpenOutline="M21,4H3A2,2 0 0,0 1,6V19A2,2 0 0,0 3,21H21A2,2 0 0,0 23,19V6A2,2 0 0,0 21,4M3,19V6H11V19H3M21,19H13V6H21V19M14,9.5H20V11H14V9.5M14,12H20V13.5H14V12M14,14.5H20V16H14V14.5Z",mdiBrightness4="M12,18C11.11,18 10.26,17.8 9.5,17.45C11.56,16.5 13,14.42 13,12C13,9.58 11.56,7.5 9.5,6.55C10.26,6.2 11.11,6 12,6A6,6 0 0,1 18,12A6,6 0 0,1 12,18M20,8.69V4H15.31L12,0.69L8.69,4H4V8.69L0.69,12L4,15.31V20H8.69L12,23.31L15.31,20H20V15.31L23.31,12L20,8.69Z",mdiChevronLeft="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z",mdiChevronRight="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z",mdiFileAlert="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M10,18H8V16H10V18M10,14H8V9H10V14M13,9V3.5L18.5,9H13Z",mdiFullscreen="M5,5H10V7H7V10H5V5M14,5H19V10H17V7H14V5M17,14H19V19H14V17H17V14M10,17V19H5V14H7V17H10Z",mdiFullscreenExit="M14,14H19V16H16V19H14V14M5,14H10V19H8V16H5V14M8,5H10V10H5V8H8V5M19,8V10H14V5H16V8H19Z",mdiImageBrokenVariant="M21,5V11.59L18,8.58L14,12.59L10,8.59L6,12.59L3,9.58V5A2,2 0 0,1 5,3H19A2,2 0 0,1 21,5M18,11.42L21,14.43V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V12.42L6,15.41L10,11.41L14,15.41",mdiMinus="M19,13H5V11H19V13Z",mdiPagePrevious="M4,21H19A2,2 0 0,0 21,19V13H17V15L13,12L17,9V11H21V5A2,2 0 0,0 19,3H4A2,2 0 0,0 2,5V19A2,2 0 0,0 4,21M4,15H8V17H4V15M4,11H11V13H4V11M4,7H11V9H4V7M21,11H24V13H21V11Z",mdiPin="M16,12V4H17V2H7V4H8V12L6,14V16H11.2V22H12.8V16H18V14L16,12Z",mdiPinOff="M2,5.27L3.28,4L20,20.72L18.73,22L12.8,16.07V22H11.2V16H6V14L8,12V11.27L2,5.27M16,12L18,14V16H17.82L8,6.18V4H7V2H17V4H16V12Z",mdiPlus="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z",mdiRadioboxBlank="M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z",mdiRadioboxMarked="M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,7A5,5 0 0,0 7,12A5,5 0 0,0 12,17A5,5 0 0,0 17,12A5,5 0 0,0 12,7Z",mdiSettings="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z",mdiTranslate="M12.87,15.07L10.33,12.56L10.36,12.53C12.1,10.59 13.34,8.36 14.07,6H17V4H10V2H8V4H1V6H12.17C11.5,7.92 10.44,9.75 9,11.35C8.07,10.32 7.3,9.19 6.69,8H4.69C5.42,9.63 6.42,11.17 7.67,12.56L2.58,17.58L4,19L9,14L12.11,17.11L12.87,15.07M18.5,10H16.5L12,22H14L15.12,19H19.87L21,22H23L18.5,10M15.88,17L17.5,12.67L19.12,17H15.88Z",jasmineUtils=createCommonjsModule((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.equals=function(e,t,i,a){return function e(t,i,o,s,a,c){var u=!0;var h=function(e,t){var i=n(e),r=n(t);if(i&&r)return;if(i)return e.asymmetricMatch(t);if(r)return t.asymmetricMatch(e)}(t,i);if(void 0!==h)return h;for(var d=0;d"},t.isUndefined=function(e){return void 0===e},t.hasProperty=function e(t,i){if(!t)return!1;if(Object.prototype.hasOwnProperty.call(t,i))return!0;return e(function(e){if(Object.getPrototypeOf)return Object.getPrototypeOf(e);if(e.constructor.prototype==e)return null;return e.constructor.prototype}(t),i)},t.isImmutableUnorderedKeyed=function(e){return!(!e||!e[c]||e[h])},t.isImmutableUnorderedSet=function(e){return!(!e||!e[u]||e[h])};const i=Function.prototype.toString;function n(e){return!!e&&a("Function",e.asymmetricMatch)}function r(e,t,i){var n=function(e){var t=[];for(var n in e)i(e,n)&&t.push(n);return t.concat(Object.getOwnPropertySymbols(e).filter(t=>Object.getOwnPropertyDescriptor(e,t).enumerable))}(e);if(!t)return n;var r=[];if(0===n.length)return n;for(var o=0;oObject(e)!==e;var build=getType,utils$1=createCommonjsModule((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.emptyObject=function(e){return!(!e||"object"!=typeof e)&&!Object.keys(e).length},t.isOneline=t.isError=t.partition=t.sparseArrayEquality=t.typeEquality=t.subsetEquality=t.iterableEquality=t.getObjectSubset=t.getPath=t.hasOwnProperty=void 0;var i=commonjsGlobal["jest-symbol-do-not-touch"]||commonjsGlobal.Symbol;const n=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)||((e,t)=>{const i=e.constructor;if(i===Object)return!1;if("function"!=typeof i)return!1;const n=Object.getOwnPropertyDescriptor(i.prototype,t);return void 0!==n&&"function"==typeof n.get})(e,t);t.hasOwnProperty=n;const r=(e,t)=>{if(Array.isArray(t)||(t=t.split(".")),t.length){const i=1===t.length,n=t[0],o=e[n];if(!i&&null==o)return{hasEndProp:!1,lastTraversedObject:e,traversedPath:[]};const s=r(o,t.slice(1));return null===s.lastTraversedObject&&(s.lastTraversedObject=e),s.traversedPath.unshift(n),i&&(s.hasEndProp=void 0!==o||!(0,build.isPrimitive)(e)&&n in e,s.hasEndProp||s.traversedPath.shift()),s}return{lastTraversedObject:null,traversedPath:[],value:e}};t.getPath=r;const o=(e,t,i=new WeakMap)=>{if(Array.isArray(e)){if(Array.isArray(t)&&t.length===e.length)return t.map((t,i)=>o(e[i],t))}else{if(e instanceof Date)return e;if(c(e)&&c(t)){const r={};if(i.set(e,r),Object.keys(e).filter(e=>n(t,e)).forEach(n=>{r[n]=i.has(e[n])?i.get(e[n]):o(e[n],t[n],i)}),Object.keys(r).length>0)return r}}return e};t.getObjectSubset=o;const s=i.iterator,a=e=>!(null==e||!e[s]),l=(e,t,n=[],r=[])=>{if("object"!=typeof e||"object"!=typeof t||Array.isArray(e)||Array.isArray(t)||!a(e)||!a(t))return;if(e.constructor!==t.constructor)return!1;let o=n.length;for(;o--;)if(n[o]===e)return r[o]===t;n.push(e),r.push(t);const c=(e,t)=>l(e,t,[...n],[...r]);if(void 0!==e.size){if(e.size!==t.size)return!1;if((0,jasmineUtils.isA)("Set",e)||(0,jasmineUtils.isImmutableUnorderedSet)(e)){let o=!0;var u=!0,h=!1,d=void 0;try{for(var p,g=e[i.iterator]();!(u=(p=g.next()).done);u=!0){const e=p.value;if(!t.has(e)){let n=!1;var m=!0,f=!1,v=void 0;try{for(var y,w=t[i.iterator]();!(m=(y=w.next()).done);m=!0){const t=y.value;!0===(0,jasmineUtils.equals)(e,t,[c])&&(n=!0)}}catch(e){f=!0,v=e}finally{try{m||null==w.return||w.return()}finally{if(f)throw v}}if(!1===n){o=!1;break}}}}catch(e){h=!0,d=e}finally{try{u||null==g.return||g.return()}finally{if(h)throw d}}return n.pop(),r.pop(),o}if((0,jasmineUtils.isA)("Map",e)||(0,jasmineUtils.isImmutableUnorderedKeyed)(e)){let o=!0;var T=!0,_=!1,S=void 0;try{for(var x,b=e[i.iterator]();!(T=(x=b.next()).done);T=!0){const e=x.value;if(!t.has(e[0])||!(0,jasmineUtils.equals)(e[1],t.get(e[0]),[c])){let n=!1;var E=!0,P=!1,R=void 0;try{for(var C,O=t[i.iterator]();!(E=(C=O.next()).done);E=!0){const t=C.value,i=(0,jasmineUtils.equals)(e[0],t[0],[c]);let r=!1;!0===i&&(r=(0,jasmineUtils.equals)(e[1],t[1],[c])),!0===r&&(n=!0)}}catch(e){P=!0,R=e}finally{try{E||null==O.return||O.return()}finally{if(P)throw R}}if(!1===n){o=!1;break}}}}catch(e){_=!0,S=e}finally{try{T||null==b.return||b.return()}finally{if(_)throw S}}return n.pop(),r.pop(),o}}const k=t[s]();var I=!0,M=!1,L=void 0;try{for(var D,H=e[i.iterator]();!(I=(D=H.next()).done);I=!0){const e=D.value,t=k.next();if(t.done||!(0,jasmineUtils.equals)(e,t.value,[c]))return!1}}catch(e){M=!0,L=e}finally{try{I||null==H.return||H.return()}finally{if(M)throw L}}return!!k.next().done&&(n.pop(),r.pop(),!0)};t.iterableEquality=l;const c=e=>null!==e&&"object"==typeof e,u=e=>c(e)&&!(e instanceof Error)&&!(e instanceof Array)&&!(e instanceof Date);t.subsetEquality=(e,t)=>{const i=(e=new WeakMap)=>(t,r)=>{if(u(r))return Object.keys(r).every(o=>{if(u(r[o])){if(e.get(r[o]))return(0,jasmineUtils.equals)(t[o],r[o],[l]);e.set(r[o],!0)}return null!=t&&n(t,o)&&(0,jasmineUtils.equals)(t[o],r[o],[l,i(e)])})};return i()(e,t)};const h=(e,t)=>{if(null!=e&&null!=t&&e.constructor!==t.constructor)return!1};t.typeEquality=h;t.sparseArrayEquality=(e,t)=>{if(!Array.isArray(e)||!Array.isArray(t))return;const i=Object.keys(e),n=Object.keys(t);return(0,jasmineUtils.equals)(e,t,[l,h],!0)&&(0,jasmineUtils.equals)(i,n)};t.partition=(e,t)=>{const i=[[],[]];return e.forEach(e=>i[t(e)?0:1].push(e)),i};t.isError=e=>{switch(Object.prototype.toString.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return e instanceof Error}};const d=/[\r\n]/;t.isOneline=(e,t)=>!("string"!=typeof e||"string"!=typeof t||d.test(e)&&d.test(t))}));unwrapExports(utils$1);var utils_1$1=utils$1.emptyObject,utils_2$1=utils$1.isOneline,utils_3$1=utils$1.isError,utils_4$1=utils$1.partition,utils_5=utils$1.sparseArrayEquality,utils_6=utils$1.typeEquality,utils_7=utils$1.subsetEquality,utils_8=utils$1.iterableEquality,utils_9=utils$1.getObjectSubset,utils_10=utils$1.getPath,asymmetricMatchers=createCommonjsModule((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.stringNotMatching=t.stringMatching=t.stringNotContaining=t.stringContaining=t.objectNotContaining=t.objectContaining=t.arrayNotContaining=t.arrayContaining=t.anything=t.any=t.AsymmetricMatcher=void 0;var i=commonjsGlobal["jest-symbol-do-not-touch"]||commonjsGlobal.Symbol;function n(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class r{constructor(e){n(this,"sample",void 0),n(this,"$$typeof",void 0),n(this,"inverse",void 0),this.$$typeof=i.for("jest.asymmetricMatcher"),this.sample=e}}t.AsymmetricMatcher=r;class o extends r{constructor(e){if(void 0===e)throw new TypeError("any() expects to be passed a constructor function. Please pass one or use anything() to match any object.");super(e)}asymmetricMatch(e){return this.sample==String?"string"==typeof e||e instanceof String:this.sample==Number?"number"==typeof e||e instanceof Number:this.sample==Function?"function"==typeof e||e instanceof Function:this.sample==Object?"object"==typeof e:this.sample==Boolean?"boolean"==typeof e:e instanceof this.sample}toString(){return"Any"}getExpectedType(){return this.sample==String?"string":this.sample==Number?"number":this.sample==Function?"function":this.sample==Object?"object":this.sample==Boolean?"boolean":(0,jasmineUtils.fnNameFor)(this.sample)}toAsymmetricMatcher(){return"Any<"+(0,jasmineUtils.fnNameFor)(this.sample)+">"}}class s extends r{asymmetricMatch(e){return!(0,jasmineUtils.isUndefined)(e)&&null!==e}toString(){return"Anything"}toAsymmetricMatcher(){return"Anything"}}class a extends r{constructor(e,t=!1){super(e),this.inverse=t}asymmetricMatch(e){if(!Array.isArray(this.sample))throw new Error(`You must provide an array to ${this.toString()}, not '`+typeof this.sample+"'.");const t=0===this.sample.length||Array.isArray(e)&&this.sample.every(t=>e.some(e=>(0,jasmineUtils.equals)(t,e)));return this.inverse?!t:t}toString(){return`Array${this.inverse?"Not":""}Containing`}getExpectedType(){return"array"}}class l extends r{constructor(e,t=!1){super(e),this.inverse=t}asymmetricMatch(e){if("object"!=typeof this.sample)throw new Error(`You must provide an object to ${this.toString()}, not '`+typeof this.sample+"'.");if(this.inverse){for(const t in this.sample)if((0,jasmineUtils.hasProperty)(e,t)&&(0,jasmineUtils.equals)(this.sample[t],e[t])&&!(0,utils$1.emptyObject)(this.sample[t])&&!(0,utils$1.emptyObject)(e[t]))return!1;return!0}for(const t in this.sample)if(!(0,jasmineUtils.hasProperty)(e,t)||!(0,jasmineUtils.equals)(this.sample[t],e[t]))return!1;return!0}toString(){return`Object${this.inverse?"Not":""}Containing`}getExpectedType(){return"object"}}class c extends r{constructor(e,t=!1){if(!(0,jasmineUtils.isA)("String",e))throw new Error("Expected is not a string");super(e),this.inverse=t}asymmetricMatch(e){const t=(0,jasmineUtils.isA)("String",e)&&e.includes(this.sample);return this.inverse?!t:t}toString(){return`String${this.inverse?"Not":""}Containing`}getExpectedType(){return"string"}}class u extends r{constructor(e,t=!1){if(!(0,jasmineUtils.isA)("String",e)&&!(0,jasmineUtils.isA)("RegExp",e))throw new Error("Expected is not a String or a RegExp");super(new RegExp(e)),this.inverse=t}asymmetricMatch(e){const t=(0,jasmineUtils.isA)("String",e)&&this.sample.test(e);return this.inverse?!t:t}toString(){return`String${this.inverse?"Not":""}Matching`}getExpectedType(){return"string"}}t.any=e=>new o(e);t.anything=()=>new s;t.arrayContaining=e=>new a(e);t.arrayNotContaining=e=>new a(e,!0);t.objectContaining=e=>new l(e);t.objectNotContaining=e=>new l(e,!0);t.stringContaining=e=>new c(e);t.stringNotContaining=e=>new c(e,!0);t.stringMatching=e=>new u(e);t.stringNotMatching=e=>new u(e,!0)}));unwrapExports(asymmetricMatchers);var asymmetricMatchers_1=asymmetricMatchers.stringNotMatching,asymmetricMatchers_2=asymmetricMatchers.stringMatching,asymmetricMatchers_3=asymmetricMatchers.stringNotContaining,asymmetricMatchers_4=asymmetricMatchers.stringContaining,asymmetricMatchers_5=asymmetricMatchers.objectNotContaining,asymmetricMatchers_6=asymmetricMatchers.objectContaining,asymmetricMatchers_7=asymmetricMatchers.arrayNotContaining,asymmetricMatchers_8=asymmetricMatchers.arrayContaining,asymmetricMatchers_9=asymmetricMatchers.anything,asymmetricMatchers_10=asymmetricMatchers.any,asymmetricMatchers_11=asymmetricMatchers.AsymmetricMatcher,jestMatchersObject=createCommonjsModule((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.setMatchers=t.getMatchers=t.setState=t.getState=t.INTERNAL_MATCHER_FLAG=void 0;var i=commonjsGlobal["jest-symbol-do-not-touch"]||commonjsGlobal.Symbol;const n=i.for("$$jest-matchers-object"),r=i.for("$$jest-internal-matcher");t.INTERNAL_MATCHER_FLAG=r,commonjsGlobal.hasOwnProperty(n)||Object.defineProperty(commonjsGlobal,n,{value:{matchers:Object.create(null),state:{assertionCalls:0,expectedAssertionsNumber:null,isExpectingAssertions:!1,suppressedErrors:[]}}});t.getState=()=>commonjsGlobal[n].state;t.setState=e=>{Object.assign(commonjsGlobal[n].state,e)};t.getMatchers=()=>commonjsGlobal[n].matchers;t.setMatchers=(e,t,i)=>{Object.keys(e).forEach(n=>{const o=e[n];if(Object.defineProperty(o,r,{value:t}),!t){class e extends asymmetricMatchers.AsymmetricMatcher{constructor(e=!1,...t){super(t),this.inverse=e}asymmetricMatch(e){const t=o(e,...this.sample).pass;return this.inverse?!t:t}toString(){return`${this.inverse?"not.":""}${n}`}getExpectedType(){return"any"}toAsymmetricMatcher(){return`${this.toString()}<${this.sample.join(", ")}>`}}i[n]=(...t)=>new e(!1,...t),i.not||(i.not={}),i.not[n]=(...t)=>new e(!0,...t)}}),Object.assign(commonjsGlobal[n].matchers,e)}}));unwrapExports(jestMatchersObject);var jestMatchersObject_1=jestMatchersObject.setMatchers,jestMatchersObject_2=jestMatchersObject.getMatchers,jestMatchersObject_3=jestMatchersObject.setState,jestMatchersObject_4=jestMatchersObject.getState,jestMatchersObject_5=jestMatchersObject.INTERNAL_MATCHER_FLAG;const Uncompress=({file:e=null,workerUrl:t=null,children:i})=>{const n=React.useContext(ReaderContext),{ready:r,error:o,preview:s}=(React.useState({size:null,name:null,type:null}),n.state);React.useEffect(()=>(Archive.init({workerUrl:t}),()=>{c()}),[]),React.useEffect(()=>{if(!e)return void jestMatchersObject_3({name:null,size:null,type:null});const{name:t,size:i,type:r}=e;jestMatchersObject_3({name:t,size:i,type:r}),"string"==typeof e&&(n.clear(),a(e)),e instanceof Blob&&(n.clear(),l(e))},[e]);const a=e=>{fetchArchive(e,h,u)},l=e=>{h(e)},c=()=>{const{pages:e}=n.state;e&&e.length>0&&e.forEach(e=>{URL.revokeObjectURL(e.src)})},u=e=>{console.error(e),n.trigger("error",e.message||e)},h=async e=>{try{const t=await p(e);if(t&&t.length>0){const e=s?t.splice(0,s):t;await asyncForEach(e,async(e,t)=>{const i=await e.file.extract();d(i,t)})}else n.trigger("error",localize["Cant open archive"])}catch(e){console.error(e),u(e)}},d=(e,t)=>{const{size:i,name:r}=e,o={index:t,url:URL.createObjectURL(e),name:r,size:i,type:"image"};n.createPage(o)},p=async e=>{const t=await Archive.open(e),i=(await t.getFilesArray()).filter(e=>isValidImageType(e.file.name));i.length;const{type:r,size:o}=e,a={type:r,size:o,totalPages:s&&s0?i:null};return React__default.createElement(React__default.Fragment,null,o&&React__default.createElement(Error$1,{message:o.message||o,icon:mdiFileAlert})||(r?i:React__default.createElement(Loader$1,null)))};Uncompress.propTypes={file:propTypes.oneOfType([propTypes.string,propTypes.instanceOf(Blob)]),workerUrl:propTypes.string,preview:propTypes.number};var openseadragon=createCommonjsModule((function(module){function OpenSeadragon(e){return new OpenSeadragon.Viewer(e)}var root,factory,$,fullScreenApi;!function(e){e.version={versionStr:"2.4.1",major:parseInt("2",10),minor:parseInt("4",10),revision:parseInt("1",10)};var t,i={"[object Boolean]":"boolean","[object Number]":"number","[object String]":"string","[object Function]":"function","[object Array]":"array","[object Date]":"date","[object RegExp]":"regexp","[object Object]":"object"},n=Object.prototype.toString,r=Object.prototype.hasOwnProperty;e.isFunction=function(t){return"function"===e.type(t)},e.isArray=Array.isArray||function(t){return"array"===e.type(t)},e.isWindow=function(e){return e&&"object"==typeof e&&"setInterval"in e},e.type=function(e){return null==e?String(e):i[n.call(e)]||"object"},e.isPlainObject=function(t){if(!t||"object"!==OpenSeadragon.type(t)||t.nodeType||e.isWindow(t))return!1;if(t.constructor&&!r.call(t,"constructor")&&!r.call(t.constructor.prototype,"isPrototypeOf"))return!1;var i;for(var n in t)i=n;return void 0===i||r.call(t,i)},e.isEmptyObject=function(e){for(var t in e)return!1;return!0},e.freezeObject=function(t){return Object.freeze?e.freezeObject=Object.freeze:e.freezeObject=function(e){return e},e.freezeObject(t)},e.supportsCanvas=(t=document.createElement("canvas"),!(!e.isFunction(t.getContext)||!t.getContext("2d"))),e.isCanvasTainted=function(e){var t=!1;try{e.getContext("2d").getImageData(0,0,1,1)}catch(e){t=!0}return t},e.pixelDensityRatio=function(){if(e.supportsCanvas){var t=document.createElement("canvas").getContext("2d"),i=window.devicePixelRatio||1,n=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return Math.max(i,1)/n}return 1}()}(OpenSeadragon),function($){$.extend=function(){var e,t,i,n,r,o,s=arguments[0]||{},a=arguments.length,l=!1,c=1;for("boolean"==typeof s&&(l=s,s=arguments[1]||{},c=2),"object"==typeof s||OpenSeadragon.isFunction(s)||(s={}),a===c&&(s=this,--c);c=i.x&&t.x=i.y},getEvent:function(e){return $.getEvent=e?function(e){return e}:function(){return window.event},$.getEvent(e)},getMousePosition:function(e){if("number"==typeof e.pageX)$.getMousePosition=function(e){var t=new $.Point;return e=$.getEvent(e),t.x=e.pageX,t.y=e.pageY,t};else{if("number"!=typeof e.clientX)throw new Error("Unknown event mouse position, no known technique.");$.getMousePosition=function(e){var t=new $.Point;return e=$.getEvent(e),t.x=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,t.y=e.clientY+document.body.scrollTop+document.documentElement.scrollTop,t}}return $.getMousePosition(e)},getPageScroll:function(){var e=document.documentElement||{},t=document.body||{};if("number"==typeof window.pageXOffset)$.getPageScroll=function(){return new $.Point(window.pageXOffset,window.pageYOffset)};else if(t.scrollLeft||t.scrollTop)$.getPageScroll=function(){return new $.Point(document.body.scrollLeft,document.body.scrollTop)};else{if(!e.scrollLeft&&!e.scrollTop)return new $.Point(0,0);$.getPageScroll=function(){return new $.Point(document.documentElement.scrollLeft,document.documentElement.scrollTop)}}return $.getPageScroll()},setPageScroll:function(e){if(void 0!==window.scrollTo)$.setPageScroll=function(e){window.scrollTo(e.x,e.y)};else{var t=$.getPageScroll();if(t.x===e.x&&t.y===e.y)return;document.body.scrollLeft=e.x,document.body.scrollTop=e.y;var i=$.getPageScroll();if(i.x!==t.x&&i.y!==t.y)return void($.setPageScroll=function(e){document.body.scrollLeft=e.x,document.body.scrollTop=e.y});if(document.documentElement.scrollLeft=e.x,document.documentElement.scrollTop=e.y,(i=$.getPageScroll()).x!==t.x&&i.y!==t.y)return void($.setPageScroll=function(e){document.documentElement.scrollLeft=e.x,document.documentElement.scrollTop=e.y});$.setPageScroll=function(e){}}return $.setPageScroll(e)},getWindowSize:function(){var e=document.documentElement||{},t=document.body||{};if("number"==typeof window.innerWidth)$.getWindowSize=function(){return new $.Point(window.innerWidth,window.innerHeight)};else if(e.clientWidth||e.clientHeight)$.getWindowSize=function(){return new $.Point(document.documentElement.clientWidth,document.documentElement.clientHeight)};else{if(!t.clientWidth&&!t.clientHeight)throw new Error("Unknown window size, no known technique.");$.getWindowSize=function(){return new $.Point(document.body.clientWidth,document.body.clientHeight)}}return $.getWindowSize()},makeCenteredNode:function(e){e=$.getElement(e);var t=[$.makeNeutralElement("div"),$.makeNeutralElement("div"),$.makeNeutralElement("div")];return $.extend(t[0].style,{display:"table",height:"100%",width:"100%"}),$.extend(t[1].style,{display:"table-row"}),$.extend(t[2].style,{display:"table-cell",verticalAlign:"middle",textAlign:"center"}),t[0].appendChild(t[1]),t[1].appendChild(t[2]),t[2].appendChild(e),t[0]},makeNeutralElement:function(e){var t=document.createElement(e),i=t.style;return i.background="transparent none",i.border="none",i.margin="0px",i.padding="0px",i.position="static",t},now:function(){return Date.now?$.now=Date.now:$.now=function(){return(new Date).getTime()},$.now()},makeTransparentImage:function(e){return $.makeTransparentImage=function(e){var t=$.makeNeutralElement("img");return t.src=e,t},$.Browser.vendor==$.BROWSERS.IE&&$.Browser.version<7&&($.makeTransparentImage=function(e){var t=$.makeNeutralElement("img"),i=null;return(i=$.makeNeutralElement("span")).style.display="inline-block",t.onload=function(){i.style.width=i.style.width||t.width+"px",i.style.height=i.style.height||t.height+"px",t.onload=null,t=null},t.src=e,i.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+e+"', sizingMethod='scale')",i}),$.makeTransparentImage(e)},setElementOpacity:function(e,t,i){var n;e=$.getElement(e),i&&!$.Browser.alpha&&(t=Math.round(t)),$.Browser.opacity?e.style.opacity=t<1?t:"":t<1?(n="alpha(opacity="+Math.round(100*t)+")",e.style.filter=n):e.style.filter=""},setElementTouchActionNone:function(e){void 0!==(e=$.getElement(e)).style.touchAction?e.style.touchAction="none":void 0!==e.style.msTouchAction&&(e.style.msTouchAction="none")},addClass:function(e,t){(e=$.getElement(e)).className?-1===(" "+e.className+" ").indexOf(" "+t+" ")&&(e.className+=" "+t):e.className=t},indexOf:function(e,t,i){return Array.prototype.indexOf?this.indexOf=function(e,t,i){return e.indexOf(t,i)}:this.indexOf=function(e,t,i){var n,r,o=i||0;if(!e)throw new TypeError;if(0===(r=e.length)||o>=r)return-1;for(o<0&&(o=r-Math.abs(o)),n=o;n=200&&a.status<300||0===a.status&&"http:"!==s&&"https:"!==s?t(a):($.console.log("AJAX request returned %d: %s",a.status,e),$.isFunction(i)&&i(a)))};try{if(a.open("GET",e,!0),o&&(a.responseType=o),r)for(var l in r)r.hasOwnProperty(l)&&r[l]&&a.setRequestHeader(l,r[l]);n&&(a.withCredentials=!0),a.send(null)}catch(n){var c=n.message;if($.Browser.vendor==$.BROWSERS.IE&&$.Browser.version<10&&void 0!==n.number&&-2147024891==n.number&&(c+="\nSee http://msdn.microsoft.com/en-us/library/ms537505(v=vs.85).aspx#xdomain"),$.console.log("%s while making AJAX request: %s",n.name,c),a.onreadystatechange=function(){},window.XDomainRequest){var u=new XDomainRequest;if(u){u.onload=function(e){$.isFunction(t)&&t({responseText:u.responseText,status:200,statusText:"OK"})},u.onerror=function(e){$.isFunction(i)&&i({responseText:u.responseText,status:444,statusText:"An error happened. Due to an XDomainRequest deficiency we can not extract any information about this error. Upgrade your browser."})};try{u.open("GET",e),u.send()}catch(e){$.isFunction(i)&&i(a,n)}}}else $.isFunction(i)&&i(a,n)}return a},jsonp:function(e){var t,i=e.url,n=document.head||document.getElementsByTagName("head")[0]||document.documentElement,r=e.callbackName||"openseadragon"+$.now(),o=window[r],s="$1"+r+"$2",a=e.param||"callback",l=e.callback;i=i.replace(/(\=)\?(&|$)|\?\?/i,s),i+=(/\?/.test(i)?"&":"?")+a+"="+r,window[r]=function(e){if(o)window[r]=o;else try{delete window[r]}catch(e){}l&&$.isFunction(l)&&l(e)},t=document.createElement("script"),void 0===e.async&&!1===e.async||(t.async="async"),e.scriptCharset&&(t.charset=e.scriptCharset),t.src=i,t.onload=t.onreadystatechange=function(e,i){(i||!t.readyState||/loaded|complete/.test(t.readyState))&&(t.onload=t.onreadystatechange=null,n&&t.parentNode&&n.removeChild(t),t=void 0)},n.insertBefore(t,n.firstChild)},createFromDZI:function(){throw"OpenSeadragon.createFromDZI is deprecated, use Viewer.open."},parseXml:function(e){if(window.DOMParser)$.parseXml=function(e){return(new DOMParser).parseFromString(e,"text/xml")};else{if(!window.ActiveXObject)throw new Error("Browser doesn't support XML DOM.");$.parseXml=function(e){var t=null;return(t=new ActiveXObject("Microsoft.XMLDOM")).async=!1,t.loadXML(e),t}}return $.parseXml(e)},parseJSON:function(string){return window.JSON&&window.JSON.parse?$.parseJSON=window.JSON.parse:$.parseJSON=function(string){return eval("("+string+")")},$.parseJSON(string)},imageFormatSupported:function(e){return!!FILEFORMATS[(e=e||"").toLowerCase()]}}),$.Browser={vendor:$.BROWSERS.UNKNOWN,version:0,alpha:!0};var FILEFORMATS={bmp:!1,jpeg:!0,jpg:!0,png:!0,tif:!1,wdp:!1},URLPARAMS={};!function(){var e=navigator.appVersion,t=navigator.userAgent;switch(navigator.appName){case"Microsoft Internet Explorer":window.attachEvent&&window.ActiveXObject&&($.Browser.vendor=$.BROWSERS.IE,$.Browser.version=parseFloat(t.substring(t.indexOf("MSIE")+5,t.indexOf(";",t.indexOf("MSIE")))));break;case"Netscape":window.addEventListener&&(t.indexOf("Firefox")>=0?($.Browser.vendor=$.BROWSERS.FIREFOX,$.Browser.version=parseFloat(t.substring(t.indexOf("Firefox")+8))):t.indexOf("Safari")>=0?($.Browser.vendor=t.indexOf("Chrome")>=0?$.BROWSERS.CHROME:$.BROWSERS.SAFARI,$.Browser.version=parseFloat(t.substring(t.substring(0,t.indexOf("Safari")).lastIndexOf("/")+1,t.indexOf("Safari")))):null!==new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})").exec(t)&&($.Browser.vendor=$.BROWSERS.IE,$.Browser.version=parseFloat(RegExp.$1)));break;case"Opera":$.Browser.vendor=$.BROWSERS.OPERA,$.Browser.version=parseFloat(e)}var i,n,r,o=window.location.search.substring(1).split("&");for(r=0;r0&&(URLPARAMS[i.substring(0,n)]=decodeURIComponent(i.substring(n+1)));$.Browser.alpha=!($.Browser.vendor==$.BROWSERS.IE&&$.Browser.version<9||$.Browser.vendor==$.BROWSERS.CHROME&&$.Browser.version<2),$.Browser.opacity=!($.Browser.vendor==$.BROWSERS.IE&&$.Browser.version<9)}();var nullfunction=function(e){};function getOffsetParent(e,t){return t&&e!=document.body?document.body:e.offsetParent}$.console=window.console||{log:nullfunction,debug:nullfunction,info:nullfunction,warn:nullfunction,error:nullfunction,assert:nullfunction},function(e){var t=e.requestAnimationFrame||e.mozRequestAnimationFrame||e.webkitRequestAnimationFrame||e.msRequestAnimationFrame,i=e.cancelAnimationFrame||e.mozCancelAnimationFrame||e.webkitCancelAnimationFrame||e.msCancelAnimationFrame;if(t&&i)$.requestAnimationFrame=function(){return t.apply(e,arguments)},$.cancelAnimationFrame=function(){return i.apply(e,arguments)};else{var n,r=[],o=[],s=0;$.requestAnimationFrame=function(e){return r.push([++s,e]),n||(n=setInterval((function(){if(r.length){var e=$.now(),t=o;for(o=r,r=t;o.length;)o.shift()[1](e)}else clearInterval(n),n=void 0}),20)),s},$.cancelAnimationFrame=function(e){var t,i;for(t=0,i=r.length;t0&&(e.removeEvent(e.MouseTracker.captureElement,"mousemove",n.mousemovecaptured,!0),e.removeEvent(e.MouseTracker.captureElement,"mouseup",n.mouseupcaptured,!0),e.removeEvent(e.MouseTracker.captureElement,e.MouseTracker.unprefixedPointerEvents?"pointermove":"MSPointerMove",n.pointermovecaptured,!0),e.removeEvent(e.MouseTracker.captureElement,e.MouseTracker.unprefixedPointerEvents?"pointerup":"MSPointerUp",n.pointerupcaptured,!0),e.removeEvent(e.MouseTracker.captureElement,"touchmove",n.touchmovecaptured,!0),e.removeEvent(e.MouseTracker.captureElement,"touchend",n.touchendcaptured,!0),n.activePointersLists[i].captureCount=0);for(i=0;i0){for(n=0;n0&&(fe(e,t,o,0),i.captureCount=1,p(e,i.type),ge(e,t,o))}}function W(t,i){var n,r,o,s,l=i.changedTouches.length,c=[],u=t.getActivePointersListByType("touch");for(n=e.now(),u.getLength()>i.touches.length-l&&(e.console.warn("Tracked touch contact count doesn't match event.touches.length. Removing all tracked touch pointers."),U(t,i,u)),r=0;r8||"onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll",e.MouseTracker.supportsMouseCapture=(s=document.createElement("div"),e.isFunction(s.setCapture)&&e.isFunction(s.releaseCapture)),e.MouseTracker.subscribeEvents=["click","dblclick","keydown","keyup","keypress","focus","blur",e.MouseTracker.wheelEventName],"DOMMouseScroll"==e.MouseTracker.wheelEventName&&e.MouseTracker.subscribeEvents.push("MozMousePixelScroll"),window.PointerEvent&&(window.navigator.pointerEnabled||e.Browser.vendor!==e.BROWSERS.IE)?(e.MouseTracker.havePointerEvents=!0,e.MouseTracker.subscribeEvents.push("pointerover","pointerout","pointerdown","pointerup","pointermove","pointercancel"),e.MouseTracker.unprefixedPointerEvents=!0,navigator.maxTouchPoints?e.MouseTracker.maxTouchPoints=navigator.maxTouchPoints:e.MouseTracker.maxTouchPoints=0,e.MouseTracker.haveMouseEnter=!1):window.MSPointerEvent&&window.navigator.msPointerEnabled?(e.MouseTracker.havePointerEvents=!0,e.MouseTracker.subscribeEvents.push("MSPointerOver","MSPointerOut","MSPointerDown","MSPointerUp","MSPointerMove","MSPointerCancel"),e.MouseTracker.unprefixedPointerEvents=!1,navigator.msMaxTouchPoints?e.MouseTracker.maxTouchPoints=navigator.msMaxTouchPoints:e.MouseTracker.maxTouchPoints=0,e.MouseTracker.haveMouseEnter=!1):(e.MouseTracker.havePointerEvents=!1,e.Browser.vendor===e.BROWSERS.IE&&e.Browser.version<9?(e.MouseTracker.subscribeEvents.push("mouseenter","mouseleave"),e.MouseTracker.haveMouseEnter=!0):(e.MouseTracker.subscribeEvents.push("mouseover","mouseout"),e.MouseTracker.haveMouseEnter=!1),e.MouseTracker.subscribeEvents.push("mousedown","mouseup","mousemove"),"ontouchstart"in window&&e.MouseTracker.subscribeEvents.push("touchstart","touchend","touchmove","touchcancel"),"ongesturestart"in window&&e.MouseTracker.subscribeEvents.push("gesturestart","gesturechange"),e.MouseTracker.mousePointerId="legacy-mouse",e.MouseTracker.maxTouchPoints=10),e.MouseTracker.GesturePointList=function(e){this._gPoints=[],this.type=e,this.buttons=0,this.contacts=0,this.clicks=0,this.captureCount=0},e.MouseTracker.GesturePointList.prototype={getLength:function(){return this._gPoints.length},asArray:function(){return this._gPoints},add:function(e){return this._gPoints.push(e)},removeById:function(e){var t,i=this._gPoints.length;for(t=0;t1&&("mouse"===this.type||"pen"===this.type)&&(this.contacts=1)},removeContact:function(){--this.contacts,this.contacts<0&&(this.contacts=0)}};var ye=function(){try{return window.self!==window.top}catch(e){return!0}}();function we(e){try{return e.addEventListener&&e.removeEventListener}catch(e){return!1}}}(OpenSeadragon),function(e){e.ControlAnchor={NONE:0,TOP_LEFT:1,TOP_RIGHT:2,BOTTOM_RIGHT:3,BOTTOM_LEFT:4,ABSOLUTE:5},e.Control=function(t,i,n){var r=t.parentNode;"number"==typeof i&&(e.console.error("Passing an anchor directly into the OpenSeadragon.Control constructor is deprecated; please use an options object instead. Support for this deprecated variant is scheduled for removal in December 2013"),i={anchor:i}),i.attachToViewer=void 0===i.attachToViewer||i.attachToViewer,this.autoFade=void 0===i.autoFade||i.autoFade,this.element=t,this.anchor=i.anchor,this.container=n,this.anchor==e.ControlAnchor.ABSOLUTE?(this.wrapper=e.makeNeutralElement("div"),this.wrapper.style.position="absolute",this.wrapper.style.top="number"==typeof i.top?i.top+"px":i.top,this.wrapper.style.left="number"==typeof i.left?i.left+"px":i.left,this.wrapper.style.height="number"==typeof i.height?i.height+"px":i.height,this.wrapper.style.width="number"==typeof i.width?i.width+"px":i.width,this.wrapper.style.margin="0px",this.wrapper.style.padding="0px",this.element.style.position="relative",this.element.style.top="0px",this.element.style.left="0px",this.element.style.height="100%",this.element.style.width="100%"):(this.wrapper=e.makeNeutralElement("div"),this.wrapper.style.display="inline-block",this.anchor==e.ControlAnchor.NONE&&(this.wrapper.style.width=this.wrapper.style.height="100%")),this.wrapper.appendChild(this.element),i.attachToViewer?this.anchor==e.ControlAnchor.TOP_RIGHT||this.anchor==e.ControlAnchor.BOTTOM_RIGHT?this.container.insertBefore(this.wrapper,this.container.firstChild):this.container.appendChild(this.wrapper):r.appendChild(this.wrapper)},e.Control.prototype={destroy:function(){this.wrapper.removeChild(this.element),this.container.removeChild(this.wrapper)},isVisible:function(){return"none"!=this.wrapper.style.display},setVisible:function(t){this.wrapper.style.display=t?this.anchor==e.ControlAnchor.ABSOLUTE?"block":"inline-block":"none"},setOpacity:function(t){this.element[e.SIGNAL]&&e.Browser.vendor==e.BROWSERS.IE?e.setElementOpacity(this.element,t,!0):e.setElementOpacity(this.wrapper,t,!0)}}}(OpenSeadragon),function(e){function t(e,t){var i,n=e.controls;for(i=n.length-1;i>=0;i--)if(n[i].element==t)return i;return-1}e.ControlDock=function(t){var i,n,r=["topleft","topright","bottomright","bottomleft"];for(e.extend(!0,this,{id:"controldock-"+e.now()+"-"+Math.floor(1e6*Math.random()),container:e.makeNeutralElement("div"),controls:[]},t),this.container.onsubmit=function(){return!1},this.element&&(this.element=e.getElement(this.element),this.element.appendChild(this.container),this.element.style.position="relative",this.container.style.width="100%",this.container.style.height="100%"),n=0;n=0)){switch(n.anchor){case e.ControlAnchor.TOP_RIGHT:r=this.controls.topright,i.style.position="relative",i.style.paddingRight="0px",i.style.paddingTop="0px";break;case e.ControlAnchor.BOTTOM_RIGHT:r=this.controls.bottomright,i.style.position="relative",i.style.paddingRight="0px",i.style.paddingBottom="0px";break;case e.ControlAnchor.BOTTOM_LEFT:r=this.controls.bottomleft,i.style.position="relative",i.style.paddingLeft="0px",i.style.paddingBottom="0px";break;case e.ControlAnchor.TOP_LEFT:r=this.controls.topleft,i.style.position="relative",i.style.paddingLeft="0px",i.style.paddingTop="0px";break;case e.ControlAnchor.ABSOLUTE:r=this.container,i.style.margin="0px",i.style.padding="0px";break;default:case e.ControlAnchor.NONE:r=this.container,i.style.margin="0px",i.style.padding="0px"}this.controls.push(new e.Control(i,n,r)),i.style.display="inline-block"}},removeControl:function(i){var n=t(this,i=e.getElement(i));return n>=0&&(this.controls[n].destroy(),this.controls.splice(n,1)),this},clearControls:function(){for(;this.controls.length>0;)this.controls.pop().destroy();return this},areControlsEnabled:function(){var e;for(e=this.controls.length-1;e>=0;e--)if(this.controls[e].isVisible())return!0;return!1},setControlsEnabled:function(e){var t;for(t=this.controls.length-1;t>=0;t--)this.controls[t].setVisible(e);return this}}}(OpenSeadragon),function(e){e.Placement=e.freezeObject({CENTER:0,TOP_LEFT:1,TOP:2,TOP_RIGHT:3,RIGHT:4,BOTTOM_RIGHT:5,BOTTOM:6,BOTTOM_LEFT:7,LEFT:8,properties:{0:{isLeft:!1,isHorizontallyCentered:!0,isRight:!1,isTop:!1,isVerticallyCentered:!0,isBottom:!1},1:{isLeft:!0,isHorizontallyCentered:!1,isRight:!1,isTop:!0,isVerticallyCentered:!1,isBottom:!1},2:{isLeft:!1,isHorizontallyCentered:!0,isRight:!1,isTop:!0,isVerticallyCentered:!1,isBottom:!1},3:{isLeft:!1,isHorizontallyCentered:!1,isRight:!0,isTop:!0,isVerticallyCentered:!1,isBottom:!1},4:{isLeft:!1,isHorizontallyCentered:!1,isRight:!0,isTop:!1,isVerticallyCentered:!0,isBottom:!1},5:{isLeft:!1,isHorizontallyCentered:!1,isRight:!0,isTop:!1,isVerticallyCentered:!1,isBottom:!0},6:{isLeft:!1,isHorizontallyCentered:!0,isRight:!1,isTop:!1,isVerticallyCentered:!1,isBottom:!0},7:{isLeft:!0,isHorizontallyCentered:!1,isRight:!1,isTop:!1,isVerticallyCentered:!1,isBottom:!0},8:{isLeft:!0,isHorizontallyCentered:!1,isRight:!1,isTop:!1,isVerticallyCentered:!0,isBottom:!1}}})}(OpenSeadragon),function(e){var t={},i=1;function n(t){return t=e.getElement(t),new e.Point(0===t.clientWidth?1:t.clientWidth,0===t.clientHeight?1:t.clientHeight)}function r(t,i){if(i instanceof e.Overlay)return i;var n=null;if(i.element)n=e.getElement(i.element);else{var r=i.id?i.id:"openseadragon-overlay-"+Math.floor(1e7*Math.random());(n=e.getElement(i.id))||((n=document.createElement("a")).href="#/overlay/"+r),n.id=r,e.addClass(n,i.className?i.className:"openseadragon-overlay")}var o=i.location,s=i.width,a=i.height;if(!o){var l=i.x,c=i.y;if(void 0!==i.px){var u=t.viewport.imageToViewportRectangle(new e.Rect(i.px,i.py,s||0,a||0));l=u.x,c=u.y,s=void 0!==s?u.width:void 0,a=void 0!==a?u.height:void 0}o=new e.Point(l,c)}var h=i.placement;return h&&"string"===e.type(h)&&(h=e.Placement[i.placement.toUpperCase()]),new e.Overlay({element:n,location:o,placement:h,onDraw:i.onDraw,checkResize:i.checkResize,width:s,height:a,rotationMode:i.rotationMode})}function o(e,t){var i;for(i=e.length-1;i>=0;i--)if(e[i].element===t)return i;return-1}function s(t,i){return e.requestAnimationFrame((function(){i(t)}))}function a(t){e.requestAnimationFrame((function(){!function(t){var i,n,r,o;if(t.controlsShouldFade){for(i=e.now(),n=i-t.controlsFadeBeginTime,r=1-n/t.controlsFadeLength,r=Math.min(1,r),r=Math.max(0,r),o=t.controls.length-1;o>=0;o--)t.controls[o].autoFade&&t.controls[o].setOpacity(r);r>0&&a(t)}}(t)}))}function l(t){t.autoHideControls&&(t.controlsShouldFade=!0,t.controlsFadeBeginTime=e.now()+t.controlsFadeDelay,window.setTimeout((function(){a(t)}),t.controlsFadeDelay))}function c(e){var t;for(e.controlsShouldFade=!1,t=e.controls.length-1;t>=0;t--)e.controls[t].setOpacity(1)}function u(){c(this)}function h(){l(this)}function d(t){var i={originalEvent:t.originalEvent,preventDefaultAction:t.preventDefaultAction,preventVerticalPan:t.preventVerticalPan,preventHorizontalPan:t.preventHorizontalPan};if(this.raiseEvent("canvas-key",i),i.preventDefaultAction||t.ctrl||t.alt||t.meta)return!0;switch(t.keyCode){case 38:return i.preventVerticalPan||(t.shift?this.viewport.zoomBy(1.1):this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(0,-this.pixelsPerArrowPress))),this.viewport.applyConstraints()),!1;case 40:return i.preventVerticalPan||(t.shift?this.viewport.zoomBy(.9):this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(0,this.pixelsPerArrowPress))),this.viewport.applyConstraints()),!1;case 37:return i.preventHorizontalPan||(this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(-this.pixelsPerArrowPress,0))),this.viewport.applyConstraints()),!1;case 39:return i.preventHorizontalPan||(this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(this.pixelsPerArrowPress,0))),this.viewport.applyConstraints()),!1;default:return!0}}function p(t){var i={originalEvent:t.originalEvent,preventDefaultAction:t.preventDefaultAction,preventVerticalPan:t.preventVerticalPan,preventHorizontalPan:t.preventHorizontalPan};if(this.raiseEvent("canvas-key",i),i.preventDefaultAction||t.ctrl||t.alt||t.meta)return!0;switch(t.keyCode){case 43:case 61:return this.viewport.zoomBy(1.1),this.viewport.applyConstraints(),!1;case 45:return this.viewport.zoomBy(.9),this.viewport.applyConstraints(),!1;case 48:return this.viewport.goHome(),this.viewport.applyConstraints(),!1;case 119:case 87:return i.preventVerticalPan||(t.shift?this.viewport.zoomBy(1.1):this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(0,-40))),this.viewport.applyConstraints()),!1;case 115:case 83:return i.preventVerticalPan||(t.shift?this.viewport.zoomBy(.9):this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(0,40))),this.viewport.applyConstraints()),!1;case 97:return i.preventHorizontalPan||(this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(-40,0))),this.viewport.applyConstraints()),!1;case 100:return i.preventHorizontalPan||(this.viewport.panBy(this.viewport.deltaPointsFromPixels(new e.Point(40,0))),this.viewport.applyConstraints()),!1;case 114:return this.viewport.flipped?this.viewport.setRotation(e.positiveModulo(this.viewport.degrees-this.rotationIncrement,360)):this.viewport.setRotation(e.positiveModulo(this.viewport.degrees+this.rotationIncrement,360)),this.viewport.applyConstraints(),!1;case 82:return this.viewport.flipped?this.viewport.setRotation(e.positiveModulo(this.viewport.degrees+this.rotationIncrement,360)):this.viewport.setRotation(e.positiveModulo(this.viewport.degrees-this.rotationIncrement,360)),this.viewport.applyConstraints(),!1;case 102:return this.viewport.toggleFlip(),!1;default:return!0}}function g(e){var t;document.activeElement==this.canvas||this.canvas.focus(),this.viewport.flipped&&(e.position.x=this.viewport.getContainerSize().x-e.position.x);var i={tracker:e.eventSource,position:e.position,quick:e.quick,shift:e.shift,originalEvent:e.originalEvent,preventDefaultAction:e.preventDefaultAction};this.raiseEvent("canvas-click",i),!i.preventDefaultAction&&this.viewport&&e.quick&&(t=this.gestureSettingsByDeviceType(e.pointerType)).clickToZoom&&(this.viewport.zoomBy(e.shift?1/this.zoomPerClick:this.zoomPerClick,t.zoomToRefPoint?this.viewport.pointFromPixel(e.position,!0):null),this.viewport.applyConstraints())}function m(e){var t,i={tracker:e.eventSource,position:e.position,shift:e.shift,originalEvent:e.originalEvent,preventDefaultAction:e.preventDefaultAction};this.raiseEvent("canvas-double-click",i),!i.preventDefaultAction&&this.viewport&&(t=this.gestureSettingsByDeviceType(e.pointerType)).dblClickToZoom&&(this.viewport.zoomBy(e.shift?1/this.zoomPerClick:this.zoomPerClick,t.zoomToRefPoint?this.viewport.pointFromPixel(e.position,!0):null),this.viewport.applyConstraints())}function f(e){var t,i={tracker:e.eventSource,position:e.position,delta:e.delta,speed:e.speed,direction:e.direction,shift:e.shift,originalEvent:e.originalEvent,preventDefaultAction:e.preventDefaultAction};if(this.raiseEvent("canvas-drag",i),!i.preventDefaultAction&&this.viewport){if(t=this.gestureSettingsByDeviceType(e.pointerType),this.panHorizontal||(e.delta.x=0),this.panVertical||(e.delta.y=0),this.viewport.flipped&&(e.delta.x=-e.delta.x),this.constrainDuringPan){var n=this.viewport.deltaPointsFromPixels(e.delta.negate());this.viewport.centerSpringX.target.value+=n.x,this.viewport.centerSpringY.target.value+=n.y;var r=this.viewport.getBounds(),o=this.viewport.getConstrainedBounds();this.viewport.centerSpringX.target.value-=n.x,this.viewport.centerSpringY.target.value-=n.y,r.x!=o.x&&(e.delta.x=0),r.y!=o.y&&(e.delta.y=0)}this.viewport.panBy(this.viewport.deltaPointsFromPixels(e.delta.negate()),t.flickEnabled&&!this.constrainDuringPan)}}function v(t){if(!t.preventDefaultAction&&this.viewport){var i=this.gestureSettingsByDeviceType(t.pointerType);if(i.flickEnabled&&t.speed>=i.flickMinSpeed){var n=0;this.panHorizontal&&(n=i.flickMomentum*t.speed*Math.cos(t.direction));var r=0;this.panVertical&&(r=i.flickMomentum*t.speed*Math.sin(t.direction));var o=this.viewport.pixelFromPoint(this.viewport.getCenter(!0)),s=this.viewport.pointFromPixel(new e.Point(o.x-n,o.y-r));this.viewport.panTo(s,!1)}this.viewport.applyConstraints()}this.raiseEvent("canvas-drag-end",{tracker:t.eventSource,position:t.position,speed:t.speed,direction:t.direction,shift:t.shift,originalEvent:t.originalEvent})}function y(e){this.raiseEvent("canvas-enter",{tracker:e.eventSource,pointerType:e.pointerType,position:e.position,buttons:e.buttons,pointers:e.pointers,insideElementPressed:e.insideElementPressed,buttonDownAny:e.buttonDownAny,originalEvent:e.originalEvent})}function w(t){window.location!=window.parent.location&&e.MouseTracker.resetAllMouseTrackers(),this.raiseEvent("canvas-exit",{tracker:t.eventSource,pointerType:t.pointerType,position:t.position,buttons:t.buttons,pointers:t.pointers,insideElementPressed:t.insideElementPressed,buttonDownAny:t.buttonDownAny,originalEvent:t.originalEvent})}function T(e){this.raiseEvent("canvas-press",{tracker:e.eventSource,pointerType:e.pointerType,position:e.position,insideElementPressed:e.insideElementPressed,insideElementReleased:e.insideElementReleased,originalEvent:e.originalEvent})}function _(e){this.raiseEvent("canvas-release",{tracker:e.eventSource,pointerType:e.pointerType,position:e.position,insideElementPressed:e.insideElementPressed,insideElementReleased:e.insideElementReleased,originalEvent:e.originalEvent})}function S(e){this.raiseEvent("canvas-nonprimary-press",{tracker:e.eventSource,position:e.position,pointerType:e.pointerType,button:e.button,buttons:e.buttons,originalEvent:e.originalEvent})}function x(e){this.raiseEvent("canvas-nonprimary-release",{tracker:e.eventSource,position:e.position,pointerType:e.pointerType,button:e.button,buttons:e.buttons,originalEvent:e.originalEvent})}function b(e){var t,i,n;if(!e.preventDefaultAction&&this.viewport&&((t=this.gestureSettingsByDeviceType(e.pointerType)).pinchToZoom&&(i=this.viewport.pointFromPixel(e.center,!0),n=this.viewport.pointFromPixel(e.lastCenter,!0).minus(i),this.panHorizontal||(n.x=0),this.panVertical||(n.y=0),this.viewport.zoomBy(e.distance/e.lastDistance,i,!0),t.zoomToRefPoint&&this.viewport.panBy(n,!0),this.viewport.applyConstraints()),t.pinchRotate)){var r=Math.atan2(e.gesturePoints[0].currentPos.y-e.gesturePoints[1].currentPos.y,e.gesturePoints[0].currentPos.x-e.gesturePoints[1].currentPos.x),o=Math.atan2(e.gesturePoints[0].lastPos.y-e.gesturePoints[1].lastPos.y,e.gesturePoints[0].lastPos.x-e.gesturePoints[1].lastPos.x);this.viewport.setRotation(this.viewport.getRotation()+(r-o)*(180/Math.PI))}return this.raiseEvent("canvas-pinch",{tracker:e.eventSource,gesturePoints:e.gesturePoints,lastCenter:e.lastCenter,center:e.center,lastDistance:e.lastDistance,distance:e.distance,shift:e.shift,originalEvent:e.originalEvent}),!1}function E(t){var i,n,r;if((r=e.now())-this._lastScrollTime>this.minScrollDeltaTime){if(this._lastScrollTime=r,this.viewport.flipped&&(t.position.x=this.viewport.getContainerSize().x-t.position.x),!t.preventDefaultAction&&this.viewport&&(i=this.gestureSettingsByDeviceType(t.pointerType)).scrollToZoom&&(n=Math.pow(this.zoomPerScroll,t.scroll),this.viewport.zoomBy(n,i.zoomToRefPoint?this.viewport.pointFromPixel(t.position,!0):null),this.viewport.applyConstraints()),this.raiseEvent("canvas-scroll",{tracker:t.eventSource,position:t.position,scroll:t.scroll,shift:t.shift,originalEvent:t.originalEvent}),i&&i.scrollToZoom)return!1}else if((i=this.gestureSettingsByDeviceType(t.pointerType))&&i.scrollToZoom)return!1}function P(e){t[this.hash].mouseInside=!0,c(this),this.raiseEvent("container-enter",{tracker:e.eventSource,position:e.position,buttons:e.buttons,pointers:e.pointers,insideElementPressed:e.insideElementPressed,buttonDownAny:e.buttonDownAny,originalEvent:e.originalEvent})}function R(e){e.pointers<1&&(t[this.hash].mouseInside=!1,t[this.hash].animating||l(this)),this.raiseEvent("container-exit",{tracker:e.eventSource,position:e.position,buttons:e.buttons,pointers:e.pointers,insideElementPressed:e.insideElementPressed,buttonDownAny:e.buttonDownAny,originalEvent:e.originalEvent})}function C(e){!function(e){if(e._opening)return;if(e.autoResize){var i=n(e.container),r=t[e.hash].prevContainerSize;if(!i.equals(r)){var o=e.viewport;if(e.preserveImageSizeOnResize){var s=r.x/i.x,a=o.getZoom()*s,u=o.getCenter();o.resize(i,!1),o.zoomTo(a,null,!0),o.panTo(u,!0)}else{var h=o.getBounds();o.resize(i,!0),o.fitBoundsWithConstraints(h,!0)}t[e.hash].prevContainerSize=i,t[e.hash].forceRedraw=!0}}var d=e.viewport.update(),p=e.world.update()||d;d&&e.raiseEvent("viewport-change");e.referenceStrip&&(p=e.referenceStrip.update(e.viewport)||p);!t[e.hash].animating&&p&&(e.raiseEvent("animation-start"),c(e));(p||t[e.hash].forceRedraw||e.world.needsDraw())&&(!function(e){e.imageLoader.clear(),e.drawer.clear(),e.world.draw(),e.raiseEvent("update-viewport",{})}(e),e._drawOverlays(),e.navigator&&e.navigator.update(e.viewport),t[e.hash].forceRedraw=!1,p&&e.raiseEvent("animation"));t[e.hash].animating&&!p&&(e.raiseEvent("animation-finish"),t[e.hash].mouseInside||l(e));t[e.hash].animating=p}(e),e.isOpen()?e._updateRequestId=s(e,C):e._updateRequestId=!1}function O(e,t){return e?e+t:t}function k(){t[this.hash].lastZoomTime=e.now(),t[this.hash].zoomFactor=this.zoomPerSecond,t[this.hash].zooming=!0,L(this)}function I(){t[this.hash].lastZoomTime=e.now(),t[this.hash].zoomFactor=1/this.zoomPerSecond,t[this.hash].zooming=!0,L(this)}function M(){t[this.hash].zooming=!1}function L(t){e.requestAnimationFrame(e.delegate(t,D))}function D(){var i,n,r;t[this.hash].zooming&&this.viewport&&(n=(i=e.now())-t[this.hash].lastZoomTime,r=Math.pow(t[this.hash].zoomFactor,n/1e3),this.viewport.zoomBy(r),this.viewport.applyConstraints(),t[this.hash].lastZoomTime=i,L(this))}function H(){this.viewport&&(t[this.hash].zooming=!1,this.viewport.zoomBy(this.zoomPerClick/1),this.viewport.applyConstraints())}function A(){this.viewport&&(t[this.hash].zooming=!1,this.viewport.zoomBy(1/this.zoomPerClick),this.viewport.applyConstraints())}function z(){this.buttons.emulateEnter(),this.buttons.emulateExit()}function B(){this.viewport&&this.viewport.goHome()}function F(){this.isFullPage()&&!e.isFullScreen()?this.setFullPage(!1):this.setFullScreen(!this.isFullPage()),this.buttons&&this.buttons.emulateExit(),this.fullPageButton.element.focus(),this.viewport&&this.viewport.applyConstraints()}function N(){if(this.viewport){var t=this.viewport.getRotation();t=this.viewport.flipped?e.positiveModulo(t+this.rotationIncrement,360):e.positiveModulo(t-this.rotationIncrement,360),this.viewport.setRotation(t)}}function j(){if(this.viewport){var t=this.viewport.getRotation();t=this.viewport.flipped?e.positiveModulo(t-this.rotationIncrement,360):e.positiveModulo(t+this.rotationIncrement,360),this.viewport.setRotation(t)}}function V(){this.viewport.toggleFlip()}function $(){var e=this._sequenceIndex-1;this.navPrevNextWrap&&e<0&&(e+=this.tileSources.length),this.goToPage(e)}function U(){var e=this._sequenceIndex+1;this.navPrevNextWrap&&e>=this.tileSources.length&&(e=0),this.goToPage(e)}e.Viewer=function(r){var o,a,c=arguments,u=this;if(e.isPlainObject(r)||(r={id:c[0],xmlPath:c.length>1?c[1]:void 0,prefixUrl:c.length>2?c[2]:void 0,controls:c.length>3?c[3]:void 0,overlays:c.length>4?c[4]:void 0}),r.config&&(e.extend(!0,r,r.config),delete r.config),e.extend(!0,this,{id:r.id,hash:r.hash||i++,initialPage:0,element:null,container:null,canvas:null,overlays:[],overlaysContainer:null,previousBody:[],customControls:[],source:null,drawer:null,world:null,viewport:null,navigator:null,collectionViewport:null,collectionDrawer:null,navImages:null,buttons:null,profiler:null},e.DEFAULT_SETTINGS,r),void 0===this.hash)throw new Error("A hash must be defined, either by specifying options.id or options.hash.");for(void 0!==t[this.hash]&&e.console.warn("Hash "+this.hash+" has already been used."),t[this.hash]={fsBoundsDelta:new e.Point(1,1),prevContainerSize:null,animating:!1,forceRedraw:!1,mouseInside:!1,group:null,zooming:!1,zoomFactor:null,lastZoomTime:null,fullPage:!1,onfullscreenchange:null},this._sequenceIndex=0,this._firstOpen=!0,this._updateRequestId=null,this._loadQueue=[],this.currentOverlays=[],this._lastScrollTime=e.now(),e.EventSource.call(this),this.addHandler("open-failed",(function(t){var i=e.getString("Errors.OpenFailed",t.eventSource,t.message);u._showMessage(i)})),e.ControlDock.call(this,r),this.xmlPath&&(this.tileSources=[this.xmlPath]),this.element=this.element||document.getElementById(this.id),this.canvas=e.makeNeutralElement("div"),this.canvas.className="openseadragon-canvas",(a=this.canvas.style).width="100%",a.height="100%",a.overflow="hidden",a.position="absolute",a.top="0px",a.left="0px",e.setElementTouchActionNone(this.canvas),""!==r.tabIndex&&(this.canvas.tabIndex=void 0===r.tabIndex?0:r.tabIndex),this.container.className="openseadragon-container",function(e){e.width="100%",e.height="100%",e.position="relative",e.overflow="hidden",e.left="0px",e.top="0px",e.textAlign="left"}(this.container.style),this.container.insertBefore(this.canvas,this.container.firstChild),this.element.appendChild(this.container),this.bodyWidth=document.body.style.width,this.bodyHeight=document.body.style.height,this.bodyOverflow=document.body.style.overflow,this.docOverflow=document.documentElement.style.overflow,this.innerTracker=new e.MouseTracker({element:this.canvas,startDisabled:!this.mouseNavEnabled,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,dblClickTimeThreshold:this.dblClickTimeThreshold,dblClickDistThreshold:this.dblClickDistThreshold,keyDownHandler:e.delegate(this,d),keyHandler:e.delegate(this,p),clickHandler:e.delegate(this,g),dblClickHandler:e.delegate(this,m),dragHandler:e.delegate(this,f),dragEndHandler:e.delegate(this,v),enterHandler:e.delegate(this,y),exitHandler:e.delegate(this,w),pressHandler:e.delegate(this,T),releaseHandler:e.delegate(this,_),nonPrimaryPressHandler:e.delegate(this,S),nonPrimaryReleaseHandler:e.delegate(this,x),scrollHandler:e.delegate(this,E),pinchHandler:e.delegate(this,b)}),this.outerTracker=new e.MouseTracker({element:this.container,startDisabled:!this.mouseNavEnabled,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,dblClickTimeThreshold:this.dblClickTimeThreshold,dblClickDistThreshold:this.dblClickDistThreshold,enterHandler:e.delegate(this,P),exitHandler:e.delegate(this,R)}),this.toolbar&&(this.toolbar=new e.ControlDock({element:this.toolbar})),this.bindStandardControls(),t[this.hash].prevContainerSize=n(this.container),this.world=new e.World({viewer:this}),this.world.addHandler("add-item",(function(e){u.source=u.world.getItemAt(0).source,t[u.hash].forceRedraw=!0,u._updateRequestId||(u._updateRequestId=s(u,C))})),this.world.addHandler("remove-item",(function(e){u.world.getItemCount()?u.source=u.world.getItemAt(0).source:u.source=null,t[u.hash].forceRedraw=!0})),this.world.addHandler("metrics-change",(function(e){u.viewport&&u.viewport._setContentBounds(u.world.getHomeBounds(),u.world.getContentFactor())})),this.world.addHandler("item-index-change",(function(e){u.source=u.world.getItemAt(0).source})),this.viewport=new e.Viewport({containerSize:t[this.hash].prevContainerSize,springStiffness:this.springStiffness,animationTime:this.animationTime,minZoomImageRatio:this.minZoomImageRatio,maxZoomPixelRatio:this.maxZoomPixelRatio,visibilityRatio:this.visibilityRatio,wrapHorizontal:this.wrapHorizontal,wrapVertical:this.wrapVertical,defaultZoomLevel:this.defaultZoomLevel,minZoomLevel:this.minZoomLevel,maxZoomLevel:this.maxZoomLevel,viewer:this,degrees:this.degrees,flipped:this.flipped,navigatorRotate:this.navigatorRotate,homeFillsViewer:this.homeFillsViewer,margins:this.viewportMargins}),this.viewport._setContentBounds(this.world.getHomeBounds(),this.world.getContentFactor()),this.imageLoader=new e.ImageLoader({jobLimit:this.imageLoaderLimit,timeout:r.timeout}),this.tileCache=new e.TileCache({maxImageCacheCount:this.maxImageCacheCount}),this.drawer=new e.Drawer({viewer:this,viewport:this.viewport,element:this.canvas,debugGridColor:this.debugGridColor}),this.overlaysContainer=e.makeNeutralElement("div"),this.canvas.appendChild(this.overlaysContainer),this.drawer.canRotate()||(this.rotateLeft&&(o=this.buttons.buttons.indexOf(this.rotateLeft),this.buttons.buttons.splice(o,1),this.buttons.element.removeChild(this.rotateLeft.element)),this.rotateRight&&(o=this.buttons.buttons.indexOf(this.rotateRight),this.buttons.buttons.splice(o,1),this.buttons.element.removeChild(this.rotateRight.element))),this.showNavigator&&(this.navigator=new e.Navigator({id:this.navigatorId,position:this.navigatorPosition,sizeRatio:this.navigatorSizeRatio,maintainSizeRatio:this.navigatorMaintainSizeRatio,top:this.navigatorTop,left:this.navigatorLeft,width:this.navigatorWidth,height:this.navigatorHeight,autoResize:this.navigatorAutoResize,autoFade:this.navigatorAutoFade,prefixUrl:this.prefixUrl,viewer:this,navigatorRotate:this.navigatorRotate,background:this.navigatorBackground,opacity:this.navigatorOpacity,borderColor:this.navigatorBorderColor,displayRegionColor:this.navigatorDisplayRegionColor,crossOriginPolicy:this.crossOriginPolicy})),this.sequenceMode&&this.bindSequenceControls(),this.tileSources&&this.open(this.tileSources),o=0;o-1&&t.index\s*$/))i=e.parseXml(i);else if(i.match(/^\s*[\{\[].*[\}\]]\s*$/))try{var a=e.parseJSON(i);i=a}catch(e){}function l(e,t){e.ready?r(e):(e.addHandler("ready",(function(){r(e)})),e.addHandler("open-failed",(function(e){o({message:e.message,source:t})})))}setTimeout((function(){if("string"==e.type(i))(i=new e.TileSource({url:i,crossOriginPolicy:void 0!==n.crossOriginPolicy?n.crossOriginPolicy:t.crossOriginPolicy,ajaxWithCredentials:t.ajaxWithCredentials,ajaxHeaders:t.ajaxHeaders,useCanvas:t.useCanvas,success:function(e){r(e.tileSource)}})).addHandler("open-failed",(function(e){o(e)}));else if(e.isPlainObject(i)||i.nodeType)if(void 0!==i.crossOriginPolicy||void 0===n.crossOriginPolicy&&void 0===t.crossOriginPolicy||(i.crossOriginPolicy=void 0!==n.crossOriginPolicy?n.crossOriginPolicy:t.crossOriginPolicy),void 0===i.ajaxWithCredentials&&(i.ajaxWithCredentials=t.ajaxWithCredentials),void 0===i.useCanvas&&(i.useCanvas=t.useCanvas),e.isFunction(i.getTileUrl)){var a=new e.TileSource(i);a.getTileUrl=i.getTileUrl,r(a)}else{var c=e.TileSource.determineType(s,i);if(!c)return void o({message:"Unable to load TileSource",source:i});var u=c.prototype.configure.apply(s,[i]);l(new c(u),i)}else l(i,i)}))}(this,t.tileSource,t,(function(e){n.tileSource=e,s()}),(function(e){e.options=t,r(e),s()})))},addSimpleImage:function(t){e.console.assert(t,"[Viewer.addSimpleImage] options is required"),e.console.assert(t.url,"[Viewer.addSimpleImage] options.url is required");var i=e.extend({},t,{tileSource:{type:"image",url:t.url}});delete i.url,this.addTiledImage(i)},addLayer:function(t){var i=this;e.console.error("[Viewer.addLayer] this function is deprecated; use Viewer.addTiledImage() instead.");var n=e.extend({},t,{success:function(e){i.raiseEvent("add-layer",{options:t,drawer:e.item})},error:function(e){i.raiseEvent("add-layer-failed",e)}});return this.addTiledImage(n),this},getLayerAtLevel:function(t){return e.console.error("[Viewer.getLayerAtLevel] this function is deprecated; use World.getItemAt() instead."),this.world.getItemAt(t)},getLevelOfLayer:function(t){return e.console.error("[Viewer.getLevelOfLayer] this function is deprecated; use World.getIndexOfItem() instead."),this.world.getIndexOfItem(t)},getLayersCount:function(){return e.console.error("[Viewer.getLayersCount] this function is deprecated; use World.getItemCount() instead."),this.world.getItemCount()},setLayerLevel:function(t,i){return e.console.error("[Viewer.setLayerLevel] this function is deprecated; use World.setItemIndex() instead."),this.world.setItemIndex(t,i)},removeLayer:function(t){return e.console.error("[Viewer.removeLayer] this function is deprecated; use World.removeItem() instead."),this.world.removeItem(t)},forceRedraw:function(){return t[this.hash].forceRedraw=!0,this},bindSequenceControls:function(){var t=e.delegate(this,u),i=e.delegate(this,h),n=e.delegate(this,U),r=e.delegate(this,$),o=this.navImages,s=!0;return this.showSequenceControl&&((this.previousButton||this.nextButton)&&(s=!1),this.previousButton=new e.Button({element:this.previousButton?e.getElement(this.previousButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.PreviousPage"),srcRest:O(this.prefixUrl,o.previous.REST),srcGroup:O(this.prefixUrl,o.previous.GROUP),srcHover:O(this.prefixUrl,o.previous.HOVER),srcDown:O(this.prefixUrl,o.previous.DOWN),onRelease:r,onFocus:t,onBlur:i}),this.nextButton=new e.Button({element:this.nextButton?e.getElement(this.nextButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.NextPage"),srcRest:O(this.prefixUrl,o.next.REST),srcGroup:O(this.prefixUrl,o.next.GROUP),srcHover:O(this.prefixUrl,o.next.HOVER),srcDown:O(this.prefixUrl,o.next.DOWN),onRelease:n,onFocus:t,onBlur:i}),this.navPrevNextWrap||this.previousButton.disable(),this.tileSources&&this.tileSources.length||this.nextButton.disable(),s&&(this.paging=new e.ButtonGroup({buttons:[this.previousButton,this.nextButton],clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold}),this.pagingControl=this.paging.element,this.toolbar?this.toolbar.addControl(this.pagingControl,{anchor:e.ControlAnchor.BOTTOM_RIGHT}):this.addControl(this.pagingControl,{anchor:this.sequenceControlAnchor||e.ControlAnchor.TOP_LEFT}))),this},bindStandardControls:function(){var t=e.delegate(this,k),i=e.delegate(this,M),n=e.delegate(this,H),r=e.delegate(this,I),o=e.delegate(this,A),s=e.delegate(this,B),a=e.delegate(this,F),l=e.delegate(this,N),c=e.delegate(this,j),d=e.delegate(this,V),p=e.delegate(this,u),g=e.delegate(this,h),m=this.navImages,f=[],v=!0;return this.showNavigationControl&&((this.zoomInButton||this.zoomOutButton||this.homeButton||this.fullPageButton||this.rotateLeftButton||this.rotateRightButton||this.flipButton)&&(v=!1),this.showZoomControl&&(f.push(this.zoomInButton=new e.Button({element:this.zoomInButton?e.getElement(this.zoomInButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.ZoomIn"),srcRest:O(this.prefixUrl,m.zoomIn.REST),srcGroup:O(this.prefixUrl,m.zoomIn.GROUP),srcHover:O(this.prefixUrl,m.zoomIn.HOVER),srcDown:O(this.prefixUrl,m.zoomIn.DOWN),onPress:t,onRelease:i,onClick:n,onEnter:t,onExit:i,onFocus:p,onBlur:g})),f.push(this.zoomOutButton=new e.Button({element:this.zoomOutButton?e.getElement(this.zoomOutButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.ZoomOut"),srcRest:O(this.prefixUrl,m.zoomOut.REST),srcGroup:O(this.prefixUrl,m.zoomOut.GROUP),srcHover:O(this.prefixUrl,m.zoomOut.HOVER),srcDown:O(this.prefixUrl,m.zoomOut.DOWN),onPress:r,onRelease:i,onClick:o,onEnter:r,onExit:i,onFocus:p,onBlur:g}))),this.showHomeControl&&f.push(this.homeButton=new e.Button({element:this.homeButton?e.getElement(this.homeButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.Home"),srcRest:O(this.prefixUrl,m.home.REST),srcGroup:O(this.prefixUrl,m.home.GROUP),srcHover:O(this.prefixUrl,m.home.HOVER),srcDown:O(this.prefixUrl,m.home.DOWN),onRelease:s,onFocus:p,onBlur:g})),this.showFullPageControl&&f.push(this.fullPageButton=new e.Button({element:this.fullPageButton?e.getElement(this.fullPageButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.FullPage"),srcRest:O(this.prefixUrl,m.fullpage.REST),srcGroup:O(this.prefixUrl,m.fullpage.GROUP),srcHover:O(this.prefixUrl,m.fullpage.HOVER),srcDown:O(this.prefixUrl,m.fullpage.DOWN),onRelease:a,onFocus:p,onBlur:g})),this.showRotationControl&&(f.push(this.rotateLeftButton=new e.Button({element:this.rotateLeftButton?e.getElement(this.rotateLeftButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.RotateLeft"),srcRest:O(this.prefixUrl,m.rotateleft.REST),srcGroup:O(this.prefixUrl,m.rotateleft.GROUP),srcHover:O(this.prefixUrl,m.rotateleft.HOVER),srcDown:O(this.prefixUrl,m.rotateleft.DOWN),onRelease:l,onFocus:p,onBlur:g})),f.push(this.rotateRightButton=new e.Button({element:this.rotateRightButton?e.getElement(this.rotateRightButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.RotateRight"),srcRest:O(this.prefixUrl,m.rotateright.REST),srcGroup:O(this.prefixUrl,m.rotateright.GROUP),srcHover:O(this.prefixUrl,m.rotateright.HOVER),srcDown:O(this.prefixUrl,m.rotateright.DOWN),onRelease:c,onFocus:p,onBlur:g}))),this.showFlipControl&&f.push(this.flipButton=new e.Button({element:this.flipButton?e.getElement(this.flipButton):null,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,tooltip:e.getString("Tooltips.Flip"),srcRest:O(this.prefixUrl,m.flip.REST),srcGroup:O(this.prefixUrl,m.flip.GROUP),srcHover:O(this.prefixUrl,m.flip.HOVER),srcDown:O(this.prefixUrl,m.flip.DOWN),onRelease:d,onFocus:p,onBlur:g})),v&&(this.buttons=new e.ButtonGroup({buttons:f,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold}),this.navControl=this.buttons.element,this.addHandler("open",e.delegate(this,z)),this.toolbar?this.toolbar.addControl(this.navControl,{anchor:this.navigationControlAnchor||e.ControlAnchor.TOP_LEFT}):this.addControl(this.navControl,{anchor:this.navigationControlAnchor||e.ControlAnchor.TOP_LEFT}))),this},currentPage:function(){return this._sequenceIndex},goToPage:function(e){return this.tileSources&&e>=0&&e=0)return this;var l=r(this,a);return this.currentOverlays.push(l),l.drawHTML(this.overlaysContainer,this.viewport),this.raiseEvent("add-overlay",{element:t,location:a.location,placement:a.placement}),this},updateOverlay:function(i,n,r){var s;return i=e.getElement(i),(s=o(this.currentOverlays,i))>=0&&(this.currentOverlays[s].update(n,r),t[this.hash].forceRedraw=!0,this.raiseEvent("update-overlay",{element:i,location:n,placement:r})),this},removeOverlay:function(i){var n;return i=e.getElement(i),(n=o(this.currentOverlays,i))>=0&&(this.currentOverlays[n].destroy(),this.currentOverlays.splice(n,1),t[this.hash].forceRedraw=!0,this.raiseEvent("remove-overlay",{element:i})),this},clearOverlays:function(){for(;this.currentOverlays.length>0;)this.currentOverlays.pop().destroy();return t[this.hash].forceRedraw=!0,this.raiseEvent("clear-overlay",{}),this},getOverlayById:function(t){var i;return t=e.getElement(t),(i=o(this.currentOverlays,t))>=0?this.currentOverlays[i]:null},_updateSequenceButtons:function(e){this.nextButton&&(this.tileSources&&this.tileSources.length-1!==e?this.nextButton.enable():this.navPrevNextWrap||this.nextButton.disable()),this.previousButton&&(e>0?this.previousButton.enable():this.navPrevNextWrap||this.previousButton.disable())},_showMessage:function(t){this._hideMessage();var i=e.makeNeutralElement("div");i.appendChild(document.createTextNode(t)),this.messageDiv=e.makeCenteredNode(i),e.addClass(this.messageDiv,"openseadragon-message"),this.container.appendChild(this.messageDiv)},_hideMessage:function(){var e=this.messageDiv;e&&(e.parentNode.removeChild(e),delete this.messageDiv)},gestureSettingsByDeviceType:function(e){switch(e){case"mouse":return this.gestureSettingsMouse;case"touch":return this.gestureSettingsTouch;case"pen":return this.gestureSettingsPen;default:return this.gestureSettingsUnknown}},_drawOverlays:function(){var e,t=this.currentOverlays.length;for(e=0;e1&&(this.referenceStrip=new e.ReferenceStrip({id:this.referenceStripElement,position:this.referenceStripPosition,sizeRatio:this.referenceStripSizeRatio,scroll:this.referenceStripScroll,height:this.referenceStripHeight,width:this.referenceStripWidth,tileSources:this.tileSources,prefixUrl:this.prefixUrl,viewer:this}),this.referenceStrip.setFocus(this._sequenceIndex))}else e.console.warn('Attempting to display a reference strip while "sequenceMode" is off.')}})}(OpenSeadragon),function(e){function t(e){var t={tracker:e.eventSource,position:e.position,quick:e.quick,shift:e.shift,originalEvent:e.originalEvent,preventDefaultAction:e.preventDefaultAction};if(this.viewer.raiseEvent("navigator-click",t),!t.preventDefaultAction&&e.quick&&this.viewer.viewport&&(this.panVertical||this.panHorizontal)){this.viewer.viewport.flipped&&(e.position.x=this.viewport.getContainerSize().x-e.position.x);var i=this.viewport.pointFromPixel(e.position);this.panVertical?this.panHorizontal||(i.x=this.viewer.viewport.getCenter(!0).x):i.y=this.viewer.viewport.getCenter(!0).y,this.viewer.viewport.panTo(i),this.viewer.viewport.applyConstraints()}}function i(e){var t={tracker:e.eventSource,position:e.position,delta:e.delta,speed:e.speed,direction:e.direction,shift:e.shift,originalEvent:e.originalEvent,preventDefaultAction:e.preventDefaultAction};this.viewer.raiseEvent("navigator-drag",t),!t.preventDefaultAction&&this.viewer.viewport&&(this.panHorizontal||(e.delta.x=0),this.panVertical||(e.delta.y=0),this.viewer.viewport.flipped&&(e.delta.x=-e.delta.x),this.viewer.viewport.panBy(this.viewport.deltaPointsFromPixels(e.delta)),this.viewer.constrainDuringPan&&this.viewer.viewport.applyConstraints())}function n(e){e.insideElementPressed&&this.viewer.viewport&&this.viewer.viewport.applyConstraints()}function r(e){return this.viewer.raiseEvent("navigator-scroll",{tracker:e.eventSource,position:e.position,scroll:e.scroll,shift:e.shift,originalEvent:e.originalEvent}),!1}function o(e,t){s(e,"rotate("+t+"deg)")}function s(e,t){e.style.webkitTransform=t,e.style.mozTransform=t,e.style.msTransform=t,e.style.oTransform=t,e.style.transform=t}e.Navigator=function(s){var a,l,c,u,h=s.viewer,d=this;function p(e){o(d.displayRegionContainer,e),o(d.displayRegion,-e),d.viewport.setRotation(e)}(s.id?(this.element=document.getElementById(s.id),s.controlOptions={anchor:e.ControlAnchor.NONE,attachToViewer:!1,autoFade:!1}):(s.id="navigator-"+e.now(),this.element=e.makeNeutralElement("div"),s.controlOptions={anchor:e.ControlAnchor.TOP_RIGHT,attachToViewer:!0,autoFade:s.autoFade},s.position&&("BOTTOM_RIGHT"==s.position?s.controlOptions.anchor=e.ControlAnchor.BOTTOM_RIGHT:"BOTTOM_LEFT"==s.position?s.controlOptions.anchor=e.ControlAnchor.BOTTOM_LEFT:"TOP_RIGHT"==s.position?s.controlOptions.anchor=e.ControlAnchor.TOP_RIGHT:"TOP_LEFT"==s.position?s.controlOptions.anchor=e.ControlAnchor.TOP_LEFT:"ABSOLUTE"==s.position&&(s.controlOptions.anchor=e.ControlAnchor.ABSOLUTE,s.controlOptions.top=s.top,s.controlOptions.left=s.left,s.controlOptions.height=s.height,s.controlOptions.width=s.width))),this.element.id=s.id,this.element.className+=" navigator",(s=e.extend(!0,{sizeRatio:e.DEFAULT_SETTINGS.navigatorSizeRatio},s,{element:this.element,tabIndex:-1,showNavigator:!1,mouseNavEnabled:!1,showNavigationControl:!1,showSequenceControl:!1,immediateRender:!0,blendTime:0,animationTime:0,autoResize:s.autoResize,minZoomImageRatio:1,background:s.background,opacity:s.opacity,borderColor:s.borderColor,displayRegionColor:s.displayRegionColor})).minPixelRatio=this.minPixelRatio=h.minPixelRatio,e.setElementTouchActionNone(this.element),this.borderWidth=2,this.fudge=new e.Point(1,1),this.totalBorderWidths=new e.Point(2*this.borderWidth,2*this.borderWidth).minus(this.fudge),s.controlOptions.anchor!=e.ControlAnchor.NONE&&(c=this.element.style,u=this.borderWidth,c.margin="0px",c.border=u+"px solid "+s.borderColor,c.padding="0px",c.background=s.background,c.opacity=s.opacity,c.overflow="hidden"),this.displayRegion=e.makeNeutralElement("div"),this.displayRegion.id=this.element.id+"-displayregion",this.displayRegion.className="displayregion",function(e,t){e.position="relative",e.top="0px",e.left="0px",e.fontSize="0px",e.overflow="hidden",e.border=t+"px solid "+s.displayRegionColor,e.margin="0px",e.padding="0px",e.background="transparent",e.float="left",e.cssFloat="left",e.styleFloat="left",e.zIndex=999999999,e.cursor="default"}(this.displayRegion.style,this.borderWidth),this.displayRegionContainer=e.makeNeutralElement("div"),this.displayRegionContainer.id=this.element.id+"-displayregioncontainer",this.displayRegionContainer.className="displayregioncontainer",this.displayRegionContainer.style.width="100%",this.displayRegionContainer.style.height="100%",h.addControl(this.element,s.controlOptions),this._resizeWithViewer=s.controlOptions.anchor!=e.ControlAnchor.ABSOLUTE&&s.controlOptions.anchor!=e.ControlAnchor.NONE,this._resizeWithViewer&&(s.width&&s.height?(this.element.style.height="number"==typeof s.height?s.height+"px":s.height,this.element.style.width="number"==typeof s.width?s.width+"px":s.width):(a=e.getElementSize(h.element),this.element.style.height=Math.round(a.y*s.sizeRatio)+"px",this.element.style.width=Math.round(a.x*s.sizeRatio)+"px",this.oldViewerSize=a),l=e.getElementSize(this.element),this.elementArea=l.x*l.y),this.oldContainerSize=new e.Point(0,0),e.Viewer.apply(this,[s]),this.displayRegionContainer.appendChild(this.displayRegion),this.element.getElementsByTagName("div")[0].appendChild(this.displayRegionContainer),s.navigatorRotate)&&(p(s.viewer.viewport?s.viewer.viewport.getRotation():s.viewer.degrees||0),s.viewer.addHandler("rotate",(function(e){p(e.degrees)})));this.innerTracker.destroy(),this.innerTracker=new e.MouseTracker({element:this.element,dragHandler:e.delegate(this,i),clickHandler:e.delegate(this,t),releaseHandler:e.delegate(this,n),scrollHandler:e.delegate(this,r)}),this.addHandler("reset-size",(function(){d.viewport&&d.viewport.goHome(!0)})),h.world.addHandler("item-index-change",(function(e){window.setTimeout((function(){var t=d.world.getItemAt(e.previousIndex);d.world.setItemIndex(t,e.newIndex)}),1)})),h.world.addHandler("remove-item",(function(e){var t=e.item,i=d._getMatchingItem(t);i&&d.world.removeItem(i)})),this.update(h.viewport)},e.extend(e.Navigator.prototype,e.EventSource.prototype,e.Viewer.prototype,{updateSize:function(){if(this.viewport){var t=new e.Point(0===this.container.clientWidth?1:this.container.clientWidth,0===this.container.clientHeight?1:this.container.clientHeight);t.equals(this.oldContainerSize)||(this.viewport.resize(t,!0),this.viewport.goHome(!0),this.oldContainerSize=t,this.drawer.clear(),this.world.draw())}},setFlip:function(e){return this.viewport.setFlip(e),this.setDisplayTransform(this.viewer.viewport.getFlip()?"scale(-1,1)":"scale(1,1)"),this},setDisplayTransform:function(e){s(this.displayRegion,e),s(this.canvas,e),s(this.element,e)},update:function(t){var i,n,r,o,s,a;if(i=e.getElementSize(this.viewer.element),this._resizeWithViewer&&i.x&&i.y&&!i.equals(this.oldViewerSize)&&(this.oldViewerSize=i,this.maintainSizeRatio||!this.elementArea?(n=i.x*this.sizeRatio,r=i.y*this.sizeRatio):(n=Math.sqrt(this.elementArea*(i.x/i.y)),r=this.elementArea/n),this.element.style.width=Math.round(n)+"px",this.element.style.height=Math.round(r)+"px",this.elementArea||(this.elementArea=n*r),this.updateSize()),t&&this.viewport){o=t.getBoundsNoRotate(!0),s=this.viewport.pixelFromPointNoRotate(o.getTopLeft(),!1),a=this.viewport.pixelFromPointNoRotate(o.getBottomRight(),!1).minus(this.totalBorderWidths);var l=this.displayRegion.style;l.display=this.world.getItemCount()?"block":"none",l.top=Math.round(s.y)+"px",l.left=Math.round(s.x)+"px";var c=Math.abs(s.x-a.x),u=Math.abs(s.y-a.y);l.width=Math.round(Math.max(c,0))+"px",l.height=Math.round(Math.max(u,0))+"px"}},addTiledImage:function(t){var i=this,n=t.originalTiledImage;delete t.original;var r=e.extend({},t,{success:function(e){var t=e.item;function r(){i._matchBounds(t,n)}t._originalForNavigator=n,i._matchBounds(t,n,!0),n.addHandler("bounds-change",r),n.addHandler("clip-change",r),n.addHandler("opacity-change",(function(){i._matchOpacity(t,n)})),n.addHandler("composite-operation-change",(function(){i._matchCompositeOperation(t,n)}))}});return e.Viewer.prototype.addTiledImage.apply(this,[r])},_getMatchingItem:function(e){for(var t,i=this.world.getItemCount(),n=0;n1||t.y>1);e++);return e-1},getTileAtPoint:function(t,i){var n=i.x>=0&&i.x<=1&&i.y>=0&&i.y<=1/this.aspectRatio;e.console.assert(n,"[TileSource.getTileAtPoint] must be called with a valid point.");var r=this.dimensions.x*this.getLevelScale(t),o=i.x*r,s=i.y*r,a=Math.floor(o/this.getTileWidth(t)),l=Math.floor(s/this.getTileHeight(t));i.x>=1&&(a=this.getNumTiles(t).x-1);return i.y>=1/this.aspectRatio-1e-15&&(l=this.getNumTiles(t).y-1),new e.Point(a,l)},getTileBounds:function(t,i,n,r){var o=this.dimensions.times(this.getLevelScale(t)),s=this.getTileWidth(t),a=this.getTileHeight(t),l=0===i?0:s*i-this.tileOverlap,c=0===n?0:a*n-this.tileOverlap,u=s+(0===i?1:2)*this.tileOverlap,h=a+(0===n?1:2)*this.tileOverlap,d=1/o.x;return u=Math.min(u,o.x-l),h=Math.min(h,o.y-c),r?new e.Rect(0,0,u,h):new e.Rect(l*d,c*d,u*d,h*d)},getImageInfo:function(t){var i,n,r,o,s,a,l,c=this;t&&(l=(a=(s=t.split("/"))[s.length-1]).lastIndexOf("."))>-1&&(s[s.length-1]=a.slice(0,l)),n=function(i){"string"==typeof i&&(i=e.parseXml(i));var n=e.TileSource.determineType(c,i,t);n?(void 0===(o=n.prototype.configure.apply(c,[i,t])).ajaxWithCredentials&&(o.ajaxWithCredentials=c.ajaxWithCredentials),r=new n(o),c.ready=!0,c.raiseEvent("ready",{tileSource:r})):c.raiseEvent("open-failed",{message:"Unable to load TileSource",source:t})},t.match(/\.js$/)?(i=t.split("/").pop().replace(".js",""),e.jsonp({url:t,async:!1,callbackName:i,callback:n})):e.makeAjaxRequest({url:t,withCredentials:this.ajaxWithCredentials,headers:this.ajaxHeaders,success:function(t){var i=function(t){var i,n,r=t.responseText,o=t.status;if(!t)throw new Error(e.getString("Errors.Security"));if(200!==t.status&&0!==t.status)throw o=t.status,i=404==o?"Not Found":t.statusText,new Error(e.getString("Errors.Status",o,i));if(r.match(/\s*<.*/))try{n=t.responseXML&&t.responseXML.documentElement?t.responseXML:e.parseXml(r)}catch(e){n=t.responseText}else if(r.match(/\s*[\{\[].*/))try{n=e.parseJSON(r)}catch(e){n=r}else n=r;return n}(t);n(i)},error:function(e,i){var n;try{n="HTTP "+e.status+" attempting to load TileSource"}catch(e){n=(void 0!==i&&i.toString?i.toString():"Unknown error")+" attempting to load TileSource"}c.raiseEvent("open-failed",{message:n,source:t})}})},supports:function(e,t){return!1},configure:function(e,t){throw new Error("Method not implemented.")},getTileUrl:function(e,t,i){throw new Error("Method not implemented.")},getTileAjaxHeaders:function(e,t,i){return{}},tileExists:function(e,t,i){var n=this.getNumTiles(e);return e>=this.minLevel&&e<=this.maxLevel&&t>=0&&i>=0&&t=0;u--)for(d=(h=this.displayRects[u]).minLevel;d<=h.maxLevel;d++)this._levelRects[d]||(this._levelRects[d]=[]),this._levelRects[d].push(h);e.TileSource.apply(this,[p])},e.extend(e.DziTileSource.prototype,e.TileSource.prototype,{supports:function(e,t){var i;return e.Image?i=e.Image.xmlns:e.documentElement&&("Image"!=e.documentElement.localName&&"Image"!=e.documentElement.tagName||(i=e.documentElement.namespaceURI)),-1!==(i=(i||"").toLowerCase()).indexOf("schemas.microsoft.com/deepzoom/2008")||-1!==i.indexOf("schemas.microsoft.com/deepzoom/2009")},configure:function(i,n){var r;return r=e.isPlainObject(i)?t(this,i):function(i,n){if(!n||!n.documentElement)throw new Error(e.getString("Errors.Xml"));var r,o,s,a,l,c=n.documentElement,u=c.localName||c.tagName,h=n.documentElement.namespaceURI,d=null,p=[];if("Image"==u)try{if(void 0===(a=c.getElementsByTagName("Size")[0])&&(a=c.getElementsByTagNameNS(h,"Size")[0]),d={Image:{xmlns:"http://schemas.microsoft.com/deepzoom/2008",Url:c.getAttribute("Url"),Format:c.getAttribute("Format"),DisplayRect:null,Overlap:parseInt(c.getAttribute("Overlap"),10),TileSize:parseInt(c.getAttribute("TileSize"),10),Size:{Height:parseInt(a.getAttribute("Height"),10),Width:parseInt(a.getAttribute("Width"),10)}}},!e.imageFormatSupported(d.Image.Format))throw new Error(e.getString("Errors.ImageFormat",d.Image.Format.toUpperCase()));for(void 0===(r=c.getElementsByTagName("DisplayRect"))&&(r=c.getElementsByTagNameNS(h,"DisplayRect")[0]),l=0;lthis.maxLevel)return!1;if(!u||!u.length)return!0;for(c=u.length-1;c>=0;c--)if(!(e<(n=u[c]).minLevel||e>n.maxLevel)&&(r=this.getLevelScale(e),o=n.x*r,s=n.y*r,a=o+n.width*r,l=s+n.height*r,o=Math.floor(o/this._tileWidth),s=Math.floor(s/this._tileWidth),a=Math.ceil(a/this._tileWidth),l=Math.ceil(l/this._tileWidth),o<=t&&t1&&e[1].supports&&(i=-1!==e[1].supports.indexOf("sizeByW"));return!t||i}(t.profile)){for(var o=Math.min(this.height,this.width),s=[256,512,1024],a=[],l=0;l0?t.tileSize=Math.max.apply(null,a):t.tileSize=o}else this.sizes&&this.sizes.length>0?(this.emulateLegacyImagePyramid=!0,t.levels=function(e){for(var t=[],i=0;i0&&t>=this.minLevel&&t<=this.maxLevel&&(i=this.levels[t].width/this.levels[this.maxLevel].width),i}return e.TileSource.prototype.getLevelScale.call(this,t)},getNumTiles:function(t){return this.emulateLegacyImagePyramid?this.getLevelScale(t)?new e.Point(1,1):new e.Point(0,0):e.TileSource.prototype.getNumTiles.call(this,t)},getTileAtPoint:function(t,i){return this.emulateLegacyImagePyramid?new e.Point(0,0):e.TileSource.prototype.getTileAtPoint.call(this,t,i)},getTileUrl:function(e,t,i){if(this.emulateLegacyImagePyramid){var n=null;return this.levels.length>0&&e>=this.minLevel&&e<=this.maxLevel&&(n=this.levels[e].url),n}var r,o,s,a,l,c,u,h,d,p,g,m,f,v=Math.pow(.5,this.maxLevel-e),y=Math.ceil(this.width*v),w=Math.ceil(this.height*v);return r=this.getTileWidth(e),o=this.getTileHeight(e),s=Math.ceil(r/v),a=Math.ceil(o/v),m=(f=this["@context"].indexOf("/1.0/context.json")>-1||this["@context"].indexOf("/1.1/context.json")>-1||this["@context"].indexOf("/1/context.json")>-1)?"native."+this.tileFormat:"default."+this.tileFormat,yc?l/256:c/256,s.maxLevel=Math.ceil(Math.log(a)/Math.log(2))-1,s.tileSize=256,s.width=l,s.height=c,e.TileSource.apply(this,[s])},e.extend(e.TmsTileSource.prototype,e.TileSource.prototype,{supports:function(e,t){return e.type&&"tiledmapservice"==e.type},configure:function(e,t){return e},getTileUrl:function(e,t,i){var n=this.getNumTiles(e).y-1;return this.tilesUrl+e+"/"+t+"/"+(n-i)+".png"}})}(OpenSeadragon),function(e){e.ZoomifyTileSource=function(e){e.tileSize=256;var t={x:e.width,y:e.height};for(e.imageSizes=[{x:e.width,y:e.height}],e.gridSize=[this._getGridSize(e.width,e.height,e.tileSize)];parseInt(t.x,10)>e.tileSize||parseInt(t.y,10)>e.tileSize;)t.x=Math.floor(t.x/2),t.y=Math.floor(t.y/2),e.imageSizes.push({x:t.x,y:t.y}),e.gridSize.push(this._getGridSize(t.x,t.y,e.tileSize));e.imageSizes.reverse(),e.gridSize.reverse(),e.minLevel=0,e.maxLevel=e.gridSize.length-1,OpenSeadragon.TileSource.apply(this,[e])},e.extend(e.ZoomifyTileSource.prototype,e.TileSource.prototype,{_getGridSize:function(e,t,i){return{x:Math.ceil(e/i),y:Math.ceil(t/i)}},_calculateAbsoluteTileNumber:function(e,t,i){for(var n=0,r={},o=0;o");return r.sort((function(e,t){return e.height-t.height}))}(i.levels),i.levels.length>0?(n=i.levels[i.levels.length-1].width,r=i.levels[i.levels.length-1].height):(n=0,r=0,e.console.error("No supported image formats found")),e.extend(!0,i,{width:n,height:r,tileSize:Math.max(r,n),tileOverlap:0,minLevel:0,maxLevel:i.levels.length>0?i.levels.length-1:0}),e.TileSource.apply(this,[i]),this.levels=i.levels},e.extend(e.LegacyTileSource.prototype,e.TileSource.prototype,{supports:function(e,t){return e.type&&"legacy-image-pyramid"==e.type||e.documentElement&&"legacy-image-pyramid"==e.documentElement.getAttribute("type")},configure:function(i,n){return e.isPlainObject(i)?t(this,i):function(i,n){if(!n||!n.documentElement)throw new Error(e.getString("Errors.Xml"));var r,o,s=n.documentElement,a=s.tagName,l=null,c=[];if("image"==a)try{for(l={type:s.getAttribute("type"),levels:[]},c=s.getElementsByTagName("level"),o=0;o0&&e>=this.minLevel&&e<=this.maxLevel&&(t=this.levels[e].width/this.levels[this.maxLevel].width),t},getNumTiles:function(t){return this.getLevelScale(t)?new e.Point(1,1):new e.Point(0,0)},getTileUrl:function(e,t,i){var n=null;return this.levels.length>0&&e>=this.minLevel&&e<=this.maxLevel&&(n=this.levels[e].url),n}})}(OpenSeadragon),function(e){e.ImageTileSource=function(t){t=e.extend({buildPyramid:!0,crossOriginPolicy:!1,ajaxWithCredentials:!1,useCanvas:!0},t),e.TileSource.apply(this,[t])},e.extend(e.ImageTileSource.prototype,e.TileSource.prototype,{supports:function(e,t){return e.type&&"image"===e.type},configure:function(e,t){return e},getImageInfo:function(t){var i=this._image=new Image,n=this;this.crossOriginPolicy&&(i.crossOrigin=this.crossOriginPolicy),this.ajaxWithCredentials&&(i.useCredentials=this.ajaxWithCredentials),e.addEvent(i,"load",(function(){n.width=Object.prototype.hasOwnProperty.call(i,"naturalWidth")?i.naturalWidth:i.width,n.height=Object.prototype.hasOwnProperty.call(i,"naturalHeight")?i.naturalHeight:i.height,n.aspectRatio=n.width/n.height,n.dimensions=new e.Point(n.width,n.height),n._tileWidth=n.width,n._tileHeight=n.height,n.tileOverlap=0,n.minLevel=0,n.levels=n._buildLevels(),n.maxLevel=n.levels.length-1,n.ready=!0,n.raiseEvent("ready",{tileSource:n})})),e.addEvent(i,"error",(function(){n.raiseEvent("open-failed",{message:"Error loading image at "+t,source:t})})),i.src=t},getLevelScale:function(e){var t=NaN;return e>=this.minLevel&&e<=this.maxLevel&&(t=this.levels[e].width/this.levels[this.maxLevel].width),t},getNumTiles:function(t){return this.getLevelScale(t)?new e.Point(1,1):new e.Point(0,0)},getTileUrl:function(e,t,i){var n=null;return e>=this.minLevel&&e<=this.maxLevel&&(n=this.levels[e].url),n},getContext2D:function(e,t,i){var n=null;return e>=this.minLevel&&e<=this.maxLevel&&(n=this.levels[e].context2D),n},_buildLevels:function(){var t=[{url:this._image.src,width:Object.prototype.hasOwnProperty.call(this._image,"naturalWidth")?this._image.naturalWidth:this._image.width,height:Object.prototype.hasOwnProperty.call(this._image,"naturalHeight")?this._image.naturalHeight:this._image.height}];if(!this.buildPyramid||!e.supportsCanvas||!this.useCanvas)return delete this._image,t;var i=Object.prototype.hasOwnProperty.call(this._image,"naturalWidth")?this._image.naturalWidth:this._image.width,n=Object.prototype.hasOwnProperty.call(this._image,"naturalHeight")?this._image.naturalHeight:this._image.height,r=document.createElement("canvas"),o=r.getContext("2d");if(r.width=i,r.height=n,o.drawImage(this._image,0,0,i,n),t[0].context2D=o,delete this._image,e.isCanvasTainted(r))return t;for(;i>=2&&n>=2;){i=Math.floor(i/2),n=Math.floor(n/2);var s=document.createElement("canvas"),a=s.getContext("2d");s.width=i,s.height=n,a.drawImage(r,0,0,i,n),t.splice(0,0,{context2D:a,width:i,height:n}),r=s,o=a}return t}})}(OpenSeadragon),function(e){e.TileSourceCollection=function(t,i,n,r){e.console.error("TileSourceCollection is deprecated; use World instead")}}(OpenSeadragon),function(e){function t(i){e.requestAnimationFrame((function(){!function(i){var n,r,o;i.shouldFade&&(n=e.now(),r=n-i.fadeBeginTime,o=1-r/i.fadeLength,o=Math.min(1,o),o=Math.max(0,o),i.imgGroup&&e.setElementOpacity(i.imgGroup,o,!0),o>0&&t(i))}(i)}))}function i(t,i){t.element.disabled||(i>=e.ButtonState.GROUP&&t.currentState==e.ButtonState.REST&&(!function(t){t.shouldFade=!1,t.imgGroup&&e.setElementOpacity(t.imgGroup,1,!0)}(t),t.currentState=e.ButtonState.GROUP),i>=e.ButtonState.HOVER&&t.currentState==e.ButtonState.GROUP&&(t.imgHover&&(t.imgHover.style.visibility=""),t.currentState=e.ButtonState.HOVER),i>=e.ButtonState.DOWN&&t.currentState==e.ButtonState.HOVER&&(t.imgDown&&(t.imgDown.style.visibility=""),t.currentState=e.ButtonState.DOWN))}function n(i,n){i.element.disabled||(n<=e.ButtonState.HOVER&&i.currentState==e.ButtonState.DOWN&&(i.imgDown&&(i.imgDown.style.visibility="hidden"),i.currentState=e.ButtonState.HOVER),n<=e.ButtonState.GROUP&&i.currentState==e.ButtonState.HOVER&&(i.imgHover&&(i.imgHover.style.visibility="hidden"),i.currentState=e.ButtonState.GROUP),n<=e.ButtonState.REST&&i.currentState==e.ButtonState.GROUP&&(!function(i){i.shouldFade=!0,i.fadeBeginTime=e.now()+i.fadeDelay,window.setTimeout((function(){t(i)}),i.fadeDelay)}(i),i.currentState=e.ButtonState.REST))}e.ButtonState={REST:0,GROUP:1,HOVER:2,DOWN:3},e.Button=function(t){var r=this;e.EventSource.call(this),e.extend(!0,this,{tooltip:null,srcRest:null,srcGroup:null,srcHover:null,srcDown:null,clickTimeThreshold:e.DEFAULT_SETTINGS.clickTimeThreshold,clickDistThreshold:e.DEFAULT_SETTINGS.clickDistThreshold,fadeDelay:0,fadeLength:2e3,onPress:null,onRelease:null,onClick:null,onEnter:null,onExit:null,onFocus:null,onBlur:null},t),this.element=t.element||e.makeNeutralElement("div"),t.element||(this.imgRest=e.makeTransparentImage(this.srcRest),this.imgGroup=e.makeTransparentImage(this.srcGroup),this.imgHover=e.makeTransparentImage(this.srcHover),this.imgDown=e.makeTransparentImage(this.srcDown),this.imgRest.alt=this.imgGroup.alt=this.imgHover.alt=this.imgDown.alt=this.tooltip,this.element.style.position="relative",e.setElementTouchActionNone(this.element),this.imgGroup.style.position=this.imgHover.style.position=this.imgDown.style.position="absolute",this.imgGroup.style.top=this.imgHover.style.top=this.imgDown.style.top="0px",this.imgGroup.style.left=this.imgHover.style.left=this.imgDown.style.left="0px",this.imgHover.style.visibility=this.imgDown.style.visibility="hidden",e.Browser.vendor==e.BROWSERS.FIREFOX&&e.Browser.version<3&&(this.imgGroup.style.top=this.imgHover.style.top=this.imgDown.style.top=""),this.element.appendChild(this.imgRest),this.element.appendChild(this.imgGroup),this.element.appendChild(this.imgHover),this.element.appendChild(this.imgDown)),this.addHandler("press",this.onPress),this.addHandler("release",this.onRelease),this.addHandler("click",this.onClick),this.addHandler("enter",this.onEnter),this.addHandler("exit",this.onExit),this.addHandler("focus",this.onFocus),this.addHandler("blur",this.onBlur),this.currentState=e.ButtonState.GROUP,this.fadeBeginTime=null,this.shouldFade=!1,this.element.style.display="inline-block",this.element.style.position="relative",this.element.title=this.tooltip,this.tracker=new e.MouseTracker({element:this.element,clickTimeThreshold:this.clickTimeThreshold,clickDistThreshold:this.clickDistThreshold,enterHandler:function(t){t.insideElementPressed?(i(r,e.ButtonState.DOWN),r.raiseEvent("enter",{originalEvent:t.originalEvent})):t.buttonDownAny||i(r,e.ButtonState.HOVER)},focusHandler:function(e){this.enterHandler(e),r.raiseEvent("focus",{originalEvent:e.originalEvent})},exitHandler:function(t){n(r,e.ButtonState.GROUP),t.insideElementPressed&&r.raiseEvent("exit",{originalEvent:t.originalEvent})},blurHandler:function(e){this.exitHandler(e),r.raiseEvent("blur",{originalEvent:e.originalEvent})},pressHandler:function(t){i(r,e.ButtonState.DOWN),r.raiseEvent("press",{originalEvent:t.originalEvent})},releaseHandler:function(t){t.insideElementPressed&&t.insideElementReleased?(n(r,e.ButtonState.HOVER),r.raiseEvent("release",{originalEvent:t.originalEvent})):t.insideElementPressed?n(r,e.ButtonState.GROUP):i(r,e.ButtonState.HOVER)},clickHandler:function(e){e.quick&&r.raiseEvent("click",{originalEvent:e.originalEvent})},keyHandler:function(e){return 13!==e.keyCode||(r.raiseEvent("click",{originalEvent:e.originalEvent}),r.raiseEvent("release",{originalEvent:e.originalEvent}),!1)}}),n(this,e.ButtonState.REST)},e.extend(e.Button.prototype,e.EventSource.prototype,{notifyGroupEnter:function(){i(this,e.ButtonState.GROUP)},notifyGroupExit:function(){n(this,e.ButtonState.REST)},disable:function(){this.notifyGroupExit(),this.element.disabled=!0,e.setElementOpacity(this.element,.2,!0)},enable:function(){this.element.disabled=!1,e.setElementOpacity(this.element,1,!0),this.notifyGroupEnter()}})}(OpenSeadragon),function(e){e.ButtonGroup=function(t){e.extend(!0,this,{buttons:[],clickTimeThreshold:e.DEFAULT_SETTINGS.clickTimeThreshold,clickDistThreshold:e.DEFAULT_SETTINGS.clickDistThreshold,labelText:""},t);var i,n=this.buttons.concat([]),r=this;if(this.element=t.element||e.makeNeutralElement("div"),!t.group)for(this.element.style.display="inline-block",i=0;i=270?(s=this.getTopRight(),this.x=s.x,this.y=s.y,a=this.height,this.height=this.width,this.width=a,this.degrees-=270):this.degrees>=180?(s=this.getBottomRight(),this.x=s.x,this.y=s.y,this.degrees-=180):this.degrees>=90&&(s=this.getBottomLeft(),this.x=s.x,this.y=s.y,a=this.height,this.height=this.width,this.width=a,this.degrees-=90)},e.Rect.fromSummits=function(t,i,n){var r=t.distanceTo(i),o=t.distanceTo(n),s=i.minus(t),a=Math.atan(s.y/s.x);return s.x<0?a+=Math.PI:s.y<0&&(a+=2*Math.PI),new e.Rect(t.x,t.y,r,o,a/Math.PI*180)},e.Rect.prototype={clone:function(){return new e.Rect(this.x,this.y,this.width,this.height,this.degrees)},getAspectRatio:function(){return this.width/this.height},getTopLeft:function(){return new e.Point(this.x,this.y)},getBottomRight:function(){return new e.Point(this.x+this.width,this.y+this.height).rotate(this.degrees,this.getTopLeft())},getTopRight:function(){return new e.Point(this.x+this.width,this.y).rotate(this.degrees,this.getTopLeft())},getBottomLeft:function(){return new e.Point(this.x,this.y+this.height).rotate(this.degrees,this.getTopLeft())},getCenter:function(){return new e.Point(this.x+this.width/2,this.y+this.height/2).rotate(this.degrees,this.getTopLeft())},getSize:function(){return new e.Point(this.width,this.height)},equals:function(t){return t instanceof e.Rect&&this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height&&this.degrees===t.degrees},times:function(t){return new e.Rect(this.x*t,this.y*t,this.width*t,this.height*t,this.degrees)},translate:function(t){return new e.Rect(this.x+t.x,this.y+t.y,this.width,this.height,this.degrees)},union:function(t){var i=this.getBoundingBox(),n=t.getBoundingBox(),r=Math.min(i.x,n.x),o=Math.min(i.y,n.y),s=Math.max(i.x+i.width,n.x+n.width),a=Math.max(i.y+i.height,n.y+n.height);return new e.Rect(r,o,s-r,a-o)},intersection:function(t){var i=1e-10,n=[],r=this.getTopLeft();t.containsPoint(r,i)&&n.push(r);var o=this.getTopRight();t.containsPoint(o,i)&&n.push(o);var s=this.getBottomLeft();t.containsPoint(s,i)&&n.push(s);var a=this.getBottomRight();t.containsPoint(a,i)&&n.push(a);var l=t.getTopLeft();this.containsPoint(l,i)&&n.push(l);var c=t.getTopRight();this.containsPoint(c,i)&&n.push(c);var u=t.getBottomLeft();this.containsPoint(u,i)&&n.push(u);var h=t.getBottomRight();this.containsPoint(h,i)&&n.push(h);for(var d=this._getSegments(),p=t._getSegments(),g=0;g_&&(_=E.x),E.yx&&(x=E.y)}return new e.Rect(T,S,_-T,x-S)},_getSegments:function(){var e=this.getTopLeft(),t=this.getTopRight(),i=this.getBottomLeft(),n=this.getBottomRight();return[[e,t],[t,n],[n,i],[i,e]]},rotate:function(t,i){if(0===(t=e.positiveModulo(t,360)))return this.clone();i=i||this.getCenter();var n=this.getTopLeft().rotate(t,i),r=this.getTopRight().rotate(t,i).minus(n);r=r.apply((function(e){return Math.abs(e)<1e-15?0:e}));var o=Math.atan(r.y/r.x);return r.x<0?o+=Math.PI:r.y<0&&(o+=2*Math.PI),new e.Rect(n.x,n.y,this.width,this.height,o/Math.PI*180)},getBoundingBox:function(){if(0===this.degrees)return this.clone();var t=this.getTopLeft(),i=this.getTopRight(),n=this.getBottomLeft(),r=this.getBottomRight(),o=Math.min(t.x,i.x,n.x,r.x),s=Math.max(t.x,i.x,n.x,r.x),a=Math.min(t.y,i.y,n.y,r.y),l=Math.max(t.y,i.y,n.y,r.y);return new e.Rect(o,a,s-o,l-a)},getIntegerBoundingBox:function(){var t=this.getBoundingBox(),i=Math.floor(t.x),n=Math.floor(t.y),r=Math.ceil(t.width+t.x-i),o=Math.ceil(t.height+t.y-n);return new e.Rect(i,n,r,o)},containsPoint:function(e,t){t=t||0;var i=this.getTopLeft(),n=this.getTopRight(),r=this.getBottomLeft(),o=n.minus(i),s=r.minus(i);return(e.x-i.x)*o.x+(e.y-i.y)*o.y>=-t&&(e.x-n.x)*o.x+(e.y-n.y)*o.y<=t&&(e.x-i.x)*s.x+(e.y-i.y)*s.y>=-t&&(e.x-r.x)*s.x+(e.y-r.y)*s.y<=t},toString:function(){return"["+Math.round(100*this.x)/100+", "+Math.round(100*this.y)/100+", "+Math.round(100*this.width)/100+"x"+Math.round(100*this.height)/100+", "+Math.round(100*this.degrees)/100+"deg]"}}}(OpenSeadragon),function(e){var t={};function i(t){var i=Number(this.element.style.marginLeft.replace("px","")),n=Number(this.element.style.marginTop.replace("px","")),o=Number(this.element.style.width.replace("px","")),s=Number(this.element.style.height.replace("px","")),a=e.getElementSize(this.viewer.canvas);return this.dragging=!0,this.element&&("horizontal"==this.scroll?-t.delta.x>0?i>-(o-a.x)&&(this.element.style.marginLeft=i+2*t.delta.x+"px",r(this,a.x,i+2*t.delta.x)):-t.delta.x<0&&i<0&&(this.element.style.marginLeft=i+2*t.delta.x+"px",r(this,a.x,i+2*t.delta.x)):-t.delta.y>0?n>-(s-a.y)&&(this.element.style.marginTop=n+2*t.delta.y+"px",r(this,a.y,n+2*t.delta.y)):-t.delta.y<0&&n<0&&(this.element.style.marginTop=n+2*t.delta.y+"px",r(this,a.y,n+2*t.delta.y))),!1}function n(t){var i=Number(this.element.style.marginLeft.replace("px","")),n=Number(this.element.style.marginTop.replace("px","")),o=Number(this.element.style.width.replace("px","")),s=Number(this.element.style.height.replace("px","")),a=e.getElementSize(this.viewer.canvas);return this.element&&("horizontal"==this.scroll?t.scroll>0?i>-(o-a.x)&&(this.element.style.marginLeft=i-60*t.scroll+"px",r(this,a.x,i-60*t.scroll)):t.scroll<0&&i<0&&(this.element.style.marginLeft=i-60*t.scroll+"px",r(this,a.x,i-60*t.scroll)):t.scroll<0?n>a.y-s&&(this.element.style.marginTop=n+60*t.scroll+"px",r(this,a.y,n+60*t.scroll)):t.scroll>0&&n<0&&(this.element.style.marginTop=n+60*t.scroll+"px",r(this,a.y,n+60*t.scroll))),!1}function r(t,i,n){var r,o,s,a,l,c,u;for(r="horizontal"==t.scroll?t.panelWidth:t.panelHeight,o=Math.ceil(i/r)+5,c=o=(o=(s=Math.ceil((Math.abs(n)+i)/r)+1)-o)<0?0:o;cc+s.x-this.panelWidth?(i=Math.min(i,a-s.x),this.element.style.marginLeft=-i+"px",r(this,s.x,-i)):iu+s.y-this.panelHeight?(i=Math.min(i,l-s.y),this.element.style.marginTop=-i+"px",r(this,s.y,-i)):i1?i[1].springStiffness:5,animationTime:i.length>1?i[1].animationTime:1.5}),e.console.assert("number"==typeof t.springStiffness&&0!==t.springStiffness,"[OpenSeadragon.Spring] options.springStiffness must be a non-zero number"),e.console.assert("number"==typeof t.animationTime&&t.animationTime>=0,"[OpenSeadragon.Spring] options.animationTime must be a number greater than or equal to 0"),t.exponential&&(this._exponential=!0,delete t.exponential),e.extend(!0,this,t),this.current={value:"number"==typeof this.initial?this.initial:this._exponential?0:1,time:e.now()},e.console.assert(!this._exponential||0!==this.current.value,"[OpenSeadragon.Spring] value must be non-zero for exponential springs"),this.start={value:this.current.value,time:this.current.time},this.target={value:this.current.value,time:this.current.time},this._exponential&&(this.start._logValue=Math.log(this.start.value),this.target._logValue=Math.log(this.target.value),this.current._logValue=Math.log(this.current.value))},e.Spring.prototype={resetTo:function(t){e.console.assert(!this._exponential||0!==t,"[OpenSeadragon.Spring.resetTo] target must be non-zero for exponential springs"),this.start.value=this.target.value=this.current.value=t,this.start.time=this.target.time=this.current.time=e.now(),this._exponential&&(this.start._logValue=Math.log(this.start.value),this.target._logValue=Math.log(this.target.value),this.current._logValue=Math.log(this.current.value))},springTo:function(t){e.console.assert(!this._exponential||0!==t,"[OpenSeadragon.Spring.springTo] target must be non-zero for exponential springs"),this.start.value=this.current.value,this.start.time=this.current.time,this.target.value=t,this.target.time=this.start.time+1e3*this.animationTime,this._exponential&&(this.start._logValue=Math.log(this.start.value),this.target._logValue=Math.log(this.target.value))},shiftBy:function(t){this.start.value+=t,this.target.value+=t,this._exponential&&(e.console.assert(0!==this.target.value&&0!==this.start.value,"[OpenSeadragon.Spring.shiftBy] spring value must be non-zero for exponential springs"),this.start._logValue=Math.log(this.start.value),this.target._logValue=Math.log(this.target.value))},setExponential:function(t){this._exponential=t,this._exponential&&(e.console.assert(0!==this.current.value&&0!==this.target.value&&0!==this.start.value,"[OpenSeadragon.Spring.setExponential] spring value must be non-zero for exponential springs"),this.start._logValue=Math.log(this.start.value),this.target._logValue=Math.log(this.target.value),this.current._logValue=Math.log(this.current.value))},update:function(){var t,i;this.current.time=e.now(),this._exponential?(t=this.start._logValue,i=this.target._logValue):(t=this.start.value,i=this.target.value);var n,r,o=this.current.time>=this.target.time?i:t+(i-t)*(n=this.springStiffness,r=(this.current.time-this.start.time)/(this.target.time-this.start.time),(1-Math.exp(n*-r))/(1-Math.exp(-n))),s=this.current.value;return this._exponential?this.current.value=Math.exp(o):this.current.value=o,s!=this.current.value},isAtTargetValue:function(){return this.current.value===this.target.value}}}(OpenSeadragon),function(e){function t(t){e.extend(!0,this,{timeout:e.DEFAULT_SETTINGS.timeout,jobId:null},t),this.image=null}t.prototype={errorMsg:null,start:function(){var t=this,i=this.abort;this.image=new Image,this.image.onload=function(){t.finish(!0)},this.image.onabort=this.image.onerror=function(){t.errorMsg="Image load aborted",t.finish(!1)},this.jobId=window.setTimeout((function(){t.errorMsg="Image load exceeded timeout ("+t.timeout+" ms)",t.finish(!1)}),this.timeout),this.loadWithAjax?(this.request=e.makeAjaxRequest({url:this.src,withCredentials:this.ajaxWithCredentials,headers:this.ajaxHeaders,responseType:"arraybuffer",success:function(e){var i;try{i=new window.Blob([e.response])}catch(t){var n=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder;if("TypeError"===t.name&&n){var r=new n;r.append(e.response),i=r.getBlob()}}0===i.size&&(t.errorMsg="Empty image response.",t.finish(!1));var o=(window.URL||window.webkitURL).createObjectURL(i);t.image.src=o},error:function(e){t.errorMsg="Image load aborted - XHR error",t.finish(!1)}}),this.abort=function(){t.request.abort(),"function"==typeof i&&i()}):(!1!==this.crossOriginPolicy&&(this.image.crossOrigin=this.crossOriginPolicy),this.image.src=this.src)},finish:function(e){this.image.onload=this.image.onerror=this.image.onabort=null,e||(this.image=null),this.jobId&&window.clearTimeout(this.jobId),this.callback(this)}},e.ImageLoader=function(t){e.extend(!0,this,{jobLimit:e.DEFAULT_SETTINGS.imageLoaderLimit,timeout:e.DEFAULT_SETTINGS.timeout,jobQueue:[],jobsInProgress:0},t)},e.ImageLoader.prototype={addJob:function(e){var i=this,n=new t({src:e.src,loadWithAjax:e.loadWithAjax,ajaxHeaders:e.loadWithAjax?e.ajaxHeaders:null,crossOriginPolicy:e.crossOriginPolicy,ajaxWithCredentials:e.ajaxWithCredentials,callback:function(t){!function(e,t,i){e.jobsInProgress--,(!e.jobLimit||e.jobsInProgress0&&(e.jobQueue.shift().start(),e.jobsInProgress++);i(t.image,t.errorMsg,t.request)}(i,t,e.callback)},abort:e.abort,timeout:this.timeout});!this.jobLimit||this.jobsInProgressi&&(i=r)}return i},needsUpdate:function(){return e.console.error("[Drawer.needsUpdate] this function is deprecated. Use World.needsDraw instead."),this.viewer.world.needsDraw()},numTilesLoaded:function(){return e.console.error("[Drawer.numTilesLoaded] this function is deprecated. Use TileCache.numTilesLoaded instead."),this.viewer.tileCache.numTilesLoaded()},reset:function(){return e.console.error("[Drawer.reset] this function is deprecated. Use World.resetItems instead."),this.viewer.world.resetItems(),this},update:function(){return e.console.error("[Drawer.update] this function is deprecated. Use Drawer.clear and World.draw instead."),this.clear(),this.viewer.world.draw(),this},canRotate:function(){return this.useCanvas},destroy:function(){this.canvas.width=1,this.canvas.height=1,this.sketchCanvas=null,this.sketchContext=null},clear:function(){if(this.canvas.innerHTML="",this.useCanvas){var e=this._calculateCanvasSize();if((this.canvas.width!=e.x||this.canvas.height!=e.y)&&(this.canvas.width=e.x,this.canvas.height=e.y,this._updateImageSmoothingEnabled(this.context),null!==this.sketchCanvas)){var t=this._calculateSketchCanvasSize();this.sketchCanvas.width=t.x,this.sketchCanvas.height=t.y,this._updateImageSmoothingEnabled(this.sketchContext)}this._clear()}},_clear:function(e,t){if(this.useCanvas){var i=this._getContext(e);if(t)i.clearRect(t.x,t.y,t.width,t.height);else{var n=i.canvas;i.clearRect(0,0,n.width,n.height)}}},viewportToDrawerRectangle:function(t){var i=this.viewport.pixelFromPointNoRotate(t.getTopLeft(),!0),n=this.viewport.deltaPixelsFromPointsNoRotate(t.getSize(),!0);return new e.Rect(i.x*e.pixelDensityRatio,i.y*e.pixelDensityRatio,n.x*e.pixelDensityRatio,n.y*e.pixelDensityRatio)},drawTile:function(t,i,n,r,o){if(e.console.assert(t,"[Drawer.drawTile] tile is required"),e.console.assert(i,"[Drawer.drawTile] drawingHandler is required"),this.useCanvas){var s=this._getContext(n);r=r||1,t.drawCanvas(s,i,r,o)}else t.drawHTML(this.canvas)},_getContext:function(e){var t=this.context;if(e){if(null===this.sketchCanvas){this.sketchCanvas=document.createElement("canvas");var i=this._calculateSketchCanvasSize();if(this.sketchCanvas.width=i.x,this.sketchCanvas.height=i.y,this.sketchContext=this.sketchCanvas.getContext("2d"),0===this.viewport.getRotation()){var n=this;this.viewer.addHandler("rotate",(function e(){if(0!==n.viewport.getRotation()){n.viewer.removeHandler("rotate",e);var t=n._calculateSketchCanvasSize();n.sketchCanvas.width=t.x,n.sketchCanvas.height=t.y}}))}this._updateImageSmoothingEnabled(this.sketchContext)}t=this.sketchContext}return t},saveContext:function(e){this.useCanvas&&this._getContext(e).save()},restoreContext:function(e){this.useCanvas&&this._getContext(e).restore()},setClip:function(e,t){if(this.useCanvas){var i=this._getContext(t);i.beginPath(),i.rect(e.x,e.y,e.width,e.height),i.clip()}},drawRectangle:function(e,t,i){if(this.useCanvas){var n=this._getContext(i);n.save(),n.fillStyle=t,n.fillRect(e.x,e.y,e.width,e.height),n.restore()}},blendSketch:function(t,i,n,r){var o=t;if(e.isPlainObject(o)||(o={opacity:t,scale:i,translate:n,compositeOperation:r}),this.useCanvas&&this.sketchCanvas){t=o.opacity,r=o.compositeOperation;var s=o.bounds;if(this.context.save(),this.context.globalAlpha=t,r&&(this.context.globalCompositeOperation=r),s)s.x<0&&(s.width+=s.x,s.x=0),s.x+s.width>this.canvas.width&&(s.width=this.canvas.width-s.x),s.y<0&&(s.height+=s.y,s.y=0),s.y+s.height>this.canvas.height&&(s.height=this.canvas.height-s.y),this.context.drawImage(this.sketchCanvas,s.x,s.y,s.width,s.height,s.x,s.y,s.width,s.height);else{i=o.scale||1;var a=(n=o.translate)instanceof e.Point?n:new e.Point(0,0),l=0,c=0;if(n){var u=this.sketchCanvas.width-this.canvas.width,h=this.sketchCanvas.height-this.canvas.height;l=Math.round(u/2),c=Math.round(h/2)}this.context.drawImage(this.sketchCanvas,a.x-l*i,a.y-c*i,(this.canvas.width+2*l)*i,(this.canvas.height+2*c)*i,-l,-c,this.canvas.width+2*l,this.canvas.height+2*c)}this.context.restore()}},drawDebugInfo:function(t,i,n,r){if(this.useCanvas){var o=this.viewer.world.getIndexOfItem(r)%this.debugGridColor.length,s=this.context;s.save(),s.lineWidth=2*e.pixelDensityRatio,s.font="small-caps bold "+13*e.pixelDensityRatio+"px arial",s.strokeStyle=this.debugGridColor[o],s.fillStyle=this.debugGridColor[o],0!==this.viewport.degrees&&this._offsetForRotation({degrees:this.viewport.degrees}),r.getRotation(!0)%360!=0&&this._offsetForRotation({degrees:r.getRotation(!0),point:r.viewport.pixelFromPointNoRotate(r._getRotationPoint(!0),!0)}),0===r.viewport.degrees&&r.getRotation(!0)%360==0&&r._drawer.viewer.viewport.getFlip()&&r._drawer._flip(),s.strokeRect(t.position.x*e.pixelDensityRatio,t.position.y*e.pixelDensityRatio,t.size.x*e.pixelDensityRatio,t.size.y*e.pixelDensityRatio);var a=(t.position.x+t.size.x/2)*e.pixelDensityRatio,l=(t.position.y+t.size.y/2)*e.pixelDensityRatio;s.translate(a,l),s.rotate(Math.PI/180*-this.viewport.degrees),s.translate(-a,-l),0===t.x&&0===t.y&&(s.fillText("Zoom: "+this.viewport.getZoom(),t.position.x*e.pixelDensityRatio,(t.position.y-30)*e.pixelDensityRatio),s.fillText("Pan: "+this.viewport.getBounds().toString(),t.position.x*e.pixelDensityRatio,(t.position.y-20)*e.pixelDensityRatio)),s.fillText("Level: "+t.level,(t.position.x+10)*e.pixelDensityRatio,(t.position.y+20)*e.pixelDensityRatio),s.fillText("Column: "+t.x,(t.position.x+10)*e.pixelDensityRatio,(t.position.y+30)*e.pixelDensityRatio),s.fillText("Row: "+t.y,(t.position.x+10)*e.pixelDensityRatio,(t.position.y+40)*e.pixelDensityRatio),s.fillText("Order: "+n+" of "+i,(t.position.x+10)*e.pixelDensityRatio,(t.position.y+50)*e.pixelDensityRatio),s.fillText("Size: "+t.size.toString(),(t.position.x+10)*e.pixelDensityRatio,(t.position.y+60)*e.pixelDensityRatio),s.fillText("Position: "+t.position.toString(),(t.position.x+10)*e.pixelDensityRatio,(t.position.y+70)*e.pixelDensityRatio),0!==this.viewport.degrees&&this._restoreRotationChanges(),r.getRotation(!0)%360!=0&&this._restoreRotationChanges(),0===r.viewport.degrees&&r.getRotation(!0)%360==0&&r._drawer.viewer.viewport.getFlip()&&r._drawer._flip(),s.restore()}},debugRect:function(t){if(this.useCanvas){var i=this.context;i.save(),i.lineWidth=2*e.pixelDensityRatio,i.strokeStyle=this.debugGridColor[0],i.fillStyle=this.debugGridColor[0],i.strokeRect(t.x*e.pixelDensityRatio,t.y*e.pixelDensityRatio,t.width*e.pixelDensityRatio,t.height*e.pixelDensityRatio),i.restore()}},setImageSmoothingEnabled:function(e){this.useCanvas&&(this._imageSmoothingEnabled=e,this._updateImageSmoothingEnabled(this.context),this.viewer.forceRedraw())},_updateImageSmoothingEnabled:function(e){e.mozImageSmoothingEnabled=this._imageSmoothingEnabled,e.webkitImageSmoothingEnabled=this._imageSmoothingEnabled,e.msImageSmoothingEnabled=this._imageSmoothingEnabled,e.imageSmoothingEnabled=this._imageSmoothingEnabled},getCanvasSize:function(t){var i=this._getContext(t).canvas;return new e.Point(i.width,i.height)},getCanvasCenter:function(){return new e.Point(this.canvas.width/2,this.canvas.height/2)},_offsetForRotation:function(t){var i=t.point?t.point.times(e.pixelDensityRatio):this.getCanvasCenter(),n=this._getContext(t.useSketch);n.save(),n.translate(i.x,i.y),this.viewer.viewport.flipped?(n.rotate(Math.PI/180*-t.degrees),n.scale(-1,1)):n.rotate(Math.PI/180*t.degrees),n.translate(-i.x,-i.y)},_flip:function(t){var i=(t=t||{}).point?t.point.times(e.pixelDensityRatio):this.getCanvasCenter(),n=this._getContext(t.useSketch);n.translate(i.x,0),n.scale(-1,1),n.translate(-i.x,0)},_restoreRotationChanges:function(e){this._getContext(e).restore()},_calculateCanvasSize:function(){var t=e.pixelDensityRatio,i=this.viewport.getContainerSize();return{x:Math.round(i.x*t),y:Math.round(i.y*t)}},_calculateSketchCanvasSize:function(){var e=this._calculateCanvasSize();if(0===this.viewport.getRotation())return e;var t=Math.ceil(Math.sqrt(e.x*e.x+e.y*e.y));return{x:t,y:t}}}}(OpenSeadragon),function(e){e.Viewport=function(t){var i=arguments;i.length&&i[0]instanceof e.Point&&(t={containerSize:i[0],contentSize:i[1],config:i[2]}),t.config&&(e.extend(!0,t,t.config),delete t.config),this._margins=e.extend({left:0,top:0,right:0,bottom:0},t.margins||{}),delete t.margins,e.extend(!0,this,{containerSize:null,contentSize:null,zoomPoint:null,viewer:null,springStiffness:e.DEFAULT_SETTINGS.springStiffness,animationTime:e.DEFAULT_SETTINGS.animationTime,minZoomImageRatio:e.DEFAULT_SETTINGS.minZoomImageRatio,maxZoomPixelRatio:e.DEFAULT_SETTINGS.maxZoomPixelRatio,visibilityRatio:e.DEFAULT_SETTINGS.visibilityRatio,wrapHorizontal:e.DEFAULT_SETTINGS.wrapHorizontal,wrapVertical:e.DEFAULT_SETTINGS.wrapVertical,defaultZoomLevel:e.DEFAULT_SETTINGS.defaultZoomLevel,minZoomLevel:e.DEFAULT_SETTINGS.minZoomLevel,maxZoomLevel:e.DEFAULT_SETTINGS.maxZoomLevel,degrees:e.DEFAULT_SETTINGS.degrees,flipped:e.DEFAULT_SETTINGS.flipped,homeFillsViewer:e.DEFAULT_SETTINGS.homeFillsViewer},t),this._updateContainerInnerSize(),this.centerSpringX=new e.Spring({initial:0,springStiffness:this.springStiffness,animationTime:this.animationTime}),this.centerSpringY=new e.Spring({initial:0,springStiffness:this.springStiffness,animationTime:this.animationTime}),this.zoomSpring=new e.Spring({exponential:!0,initial:1,springStiffness:this.springStiffness,animationTime:this.animationTime}),this._oldCenterX=this.centerSpringX.current.value,this._oldCenterY=this.centerSpringY.current.value,this._oldZoom=this.zoomSpring.current.value,this._setContentBounds(new e.Rect(0,0,1,1),1),this.goHome(!0),this.update()},e.Viewport.prototype={resetContentSize:function(t){return e.console.assert(t,"[Viewport.resetContentSize] contentSize is required"),e.console.assert(t instanceof e.Point,"[Viewport.resetContentSize] contentSize must be an OpenSeadragon.Point"),e.console.assert(t.x>0,"[Viewport.resetContentSize] contentSize.x must be greater than 0"),e.console.assert(t.y>0,"[Viewport.resetContentSize] contentSize.y must be greater than 0"),this._setContentBounds(new e.Rect(0,0,1,t.y/t.x),t.x),this},setHomeBounds:function(t,i){e.console.error("[Viewport.setHomeBounds] this function is deprecated; The content bounds should not be set manually."),this._setContentBounds(t,i)},_setContentBounds:function(t,i){e.console.assert(t,"[Viewport._setContentBounds] bounds is required"),e.console.assert(t instanceof e.Rect,"[Viewport._setContentBounds] bounds must be an OpenSeadragon.Rect"),e.console.assert(t.width>0,"[Viewport._setContentBounds] bounds.width must be greater than 0"),e.console.assert(t.height>0,"[Viewport._setContentBounds] bounds.height must be greater than 0"),this._contentBoundsNoRotate=t.clone(),this._contentSizeNoRotate=this._contentBoundsNoRotate.getSize().times(i),this._contentBounds=t.rotate(this.degrees).getBoundingBox(),this._contentSize=this._contentBounds.getSize().times(i),this._contentAspectRatio=this._contentSize.x/this._contentSize.y,this.viewer&&this.viewer.raiseEvent("reset-size",{contentSize:this._contentSizeNoRotate.clone(),contentFactor:i,homeBounds:this._contentBoundsNoRotate.clone(),contentBounds:this._contentBounds.clone()})},getHomeZoom:function(){if(this.defaultZoomLevel)return this.defaultZoomLevel;var e=this._contentAspectRatio/this.getAspectRatio();return(this.homeFillsViewer?e>=1?e:1:e>=1?1:e)/this._contentBounds.width},getHomeBounds:function(){return this.getHomeBoundsNoRotate().rotate(-this.getRotation())},getHomeBoundsNoRotate:function(){var t=this._contentBounds.getCenter(),i=1/this.getHomeZoom(),n=i/this.getAspectRatio();return new e.Rect(t.x-i/2,t.y-n/2,i,n)},goHome:function(e){return this.viewer&&this.viewer.raiseEvent("home",{immediately:e}),this.fitBounds(this.getHomeBounds(),e)},getMinZoom:function(){var e=this.getHomeZoom();return this.minZoomLevel?this.minZoomLevel:this.minZoomImageRatio*e},getMaxZoom:function(){var e=this.maxZoomLevel;return e||(e=this._contentSize.x*this.maxZoomPixelRatio/this._containerInnerSize.x,e/=this._contentBounds.width),Math.max(e,this.getHomeZoom())},getAspectRatio:function(){return this._containerInnerSize.x/this._containerInnerSize.y},getContainerSize:function(){return new e.Point(this.containerSize.x,this.containerSize.y)},getMargins:function(){return e.extend({},this._margins)},setMargins:function(t){e.console.assert("object"===e.type(t),"[Viewport.setMargins] margins must be an object"),this._margins=e.extend({left:0,top:0,right:0,bottom:0},t),this._updateContainerInnerSize(),this.viewer&&this.viewer.forceRedraw()},getBounds:function(e){return this.getBoundsNoRotate(e).rotate(-this.getRotation())},getBoundsNoRotate:function(t){var i=this.getCenter(t),n=1/this.getZoom(t),r=n/this.getAspectRatio();return new e.Rect(i.x-n/2,i.y-r/2,n,r)},getBoundsWithMargins:function(e){return this.getBoundsNoRotateWithMargins(e).rotate(-this.getRotation(),this.getCenter(e))},getBoundsNoRotateWithMargins:function(e){var t=this.getBoundsNoRotate(e),i=this._containerInnerSize.x*this.getZoom(e);return t.x-=this._margins.left/i,t.y-=this._margins.top/i,t.width+=(this._margins.left+this._margins.right)/i,t.height+=(this._margins.top+this._margins.bottom)/i,t},getCenter:function(t){var i,n,r,o,s,a,l=new e.Point(this.centerSpringX.current.value,this.centerSpringY.current.value),c=new e.Point(this.centerSpringX.target.value,this.centerSpringY.target.value);return t?l:this.zoomPoint?(i=this.pixelFromPoint(this.zoomPoint,!0),o=(r=1/(n=this.getZoom()))/this.getAspectRatio(),s=new e.Rect(l.x-r/2,l.y-o/2,r,o),a=this._pixelFromPoint(this.zoomPoint,s).minus(i).divide(this._containerInnerSize.x*n),c.plus(a)):c},getZoom:function(e){return e?this.zoomSpring.current.value:this.zoomSpring.target.value},_applyZoomConstraints:function(e){return Math.max(Math.min(e,this.getMaxZoom()),this.getMinZoom())},_applyBoundaryConstraints:function(t){var i=new e.Rect(t.x,t.y,t.width,t.height);if(this.wrapHorizontal);else{var n=this.visibilityRatio*i.width,r=i.x+i.width,o=this._contentBoundsNoRotate.x+this._contentBoundsNoRotate.width,s=this._contentBoundsNoRotate.x-r+n,a=o-i.x-n;n>this._contentBoundsNoRotate.width?i.x+=(s+a)/2:a<0?i.x+=a:s>0&&(i.x+=s)}if(this.wrapVertical);else{var l=this.visibilityRatio*i.height,c=i.y+i.height,u=this._contentBoundsNoRotate.y+this._contentBoundsNoRotate.height,h=this._contentBoundsNoRotate.y-c+l,d=u-i.y-l;l>this._contentBoundsNoRotate.height?i.y+=(h+d)/2:d<0?i.y+=d:h>0&&(i.y+=h)}return i},_raiseConstraintsEvent:function(e){this.viewer&&this.viewer.raiseEvent("constrain",{immediately:e})},applyConstraints:function(e){var t=this.getZoom(),i=this._applyZoomConstraints(t);t!==i&&this.zoomTo(i,this.zoomPoint,e);var n=this.getBoundsNoRotate(),r=this._applyBoundaryConstraints(n);return this._raiseConstraintsEvent(e),(n.x!==r.x||n.y!==r.y||e)&&this.fitBounds(r.rotate(-this.getRotation()),e),this},ensureVisible:function(e){return this.applyConstraints(e)},_fitBounds:function(t,i){var n=(i=i||{}).immediately||!1,r=i.constraints||!1,o=this.getAspectRatio(),s=t.getCenter(),a=new e.Rect(t.x,t.y,t.width,t.height,t.degrees+this.getRotation()).getBoundingBox();a.getAspectRatio()>=o?a.height=a.width/o:a.width=a.height*o,a.x=s.x-a.width/2,a.y=s.y-a.height/2;var l=1/a.width;if(r){var c=a.getAspectRatio(),u=this._applyZoomConstraints(l);l!==u&&(l=u,a.width=1/l,a.x=s.x-a.width/2,a.height=a.width/c,a.y=s.y-a.height/2),s=(a=this._applyBoundaryConstraints(a)).getCenter(),this._raiseConstraintsEvent(n)}if(n)return this.panTo(s,!0),this.zoomTo(l,null,!0);this.panTo(this.getCenter(!0),!0),this.zoomTo(this.getZoom(!0),null,!0);var h=this.getBounds(),d=this.getZoom();if(0===d||Math.abs(l/d-1)<1e-8)return this.zoomTo(l,!0),this.panTo(s,n);var p=(a=a.rotate(-this.getRotation())).getTopLeft().times(l).minus(h.getTopLeft().times(d)).divide(l-d);return this.zoomTo(l,p,n)},fitBounds:function(e,t){return this._fitBounds(e,{immediately:t,constraints:!1})},fitBoundsWithConstraints:function(e,t){return this._fitBounds(e,{immediately:t,constraints:!0})},fitVertically:function(t){var i=new e.Rect(this._contentBounds.x+this._contentBounds.width/2,this._contentBounds.y,0,this._contentBounds.height);return this.fitBounds(i,t)},fitHorizontally:function(t){var i=new e.Rect(this._contentBounds.x,this._contentBounds.y+this._contentBounds.height/2,this._contentBounds.width,0);return this.fitBounds(i,t)},getConstrainedBounds:function(e){var t;return t=this.getBounds(e),this._applyBoundaryConstraints(t)},panBy:function(t,i){var n=new e.Point(this.centerSpringX.target.value,this.centerSpringY.target.value);return this.panTo(n.plus(t),i)},panTo:function(e,t){return t?(this.centerSpringX.resetTo(e.x),this.centerSpringY.resetTo(e.y)):(this.centerSpringX.springTo(e.x),this.centerSpringY.springTo(e.y)),this.viewer&&this.viewer.raiseEvent("pan",{center:e,immediately:t}),this},zoomBy:function(e,t,i){return this.zoomTo(this.zoomSpring.target.value*e,t,i)},zoomTo:function(t,i,n){var r=this;return this.zoomPoint=i instanceof e.Point&&!isNaN(i.x)&&!isNaN(i.y)?i:null,n?this._adjustCenterSpringsForZoomPoint((function(){r.zoomSpring.resetTo(t)})):this.zoomSpring.springTo(t),this.viewer&&this.viewer.raiseEvent("zoom",{zoom:t,refPoint:i,immediately:n}),this},setRotation:function(t){return this.viewer&&this.viewer.drawer.canRotate()?(this.degrees=e.positiveModulo(t,360),this._setContentBounds(this.viewer.world.getHomeBounds(),this.viewer.world.getContentFactor()),this.viewer.forceRedraw(),this.viewer.raiseEvent("rotate",{degrees:t}),this):this},getRotation:function(){return this.degrees},resize:function(e,t){var i,n=this.getBoundsNoRotate(),r=n;return this.containerSize.x=e.x,this.containerSize.y=e.y,this._updateContainerInnerSize(),t&&(i=e.x/this.containerSize.x,r.width=n.width*i,r.height=r.width/this.getAspectRatio()),this.viewer&&this.viewer.raiseEvent("resize",{newContainerSize:e,maintain:t}),this.fitBounds(r,!0)},_updateContainerInnerSize:function(){this._containerInnerSize=new e.Point(Math.max(1,this.containerSize.x-(this._margins.left+this._margins.right)),Math.max(1,this.containerSize.y-(this._margins.top+this._margins.bottom)))},update:function(){var e=this;this._adjustCenterSpringsForZoomPoint((function(){e.zoomSpring.update()})),this.centerSpringX.update(),this.centerSpringY.update();var t=this.centerSpringX.current.value!==this._oldCenterX||this.centerSpringY.current.value!==this._oldCenterY||this.zoomSpring.current.value!==this._oldZoom;return this._oldCenterX=this.centerSpringX.current.value,this._oldCenterY=this.centerSpringY.current.value,this._oldZoom=this.zoomSpring.current.value,t},_adjustCenterSpringsForZoomPoint:function(e){if(this.zoomPoint){var t=this.pixelFromPoint(this.zoomPoint,!0);e();var i=this.pixelFromPoint(this.zoomPoint,!0).minus(t),n=this.deltaPointsFromPixels(i,!0);this.centerSpringX.shiftBy(n.x),this.centerSpringY.shiftBy(n.y),this.zoomSpring.isAtTargetValue()&&(this.zoomPoint=null)}else e()},deltaPixelsFromPointsNoRotate:function(e,t){return e.times(this._containerInnerSize.x*this.getZoom(t))},deltaPixelsFromPoints:function(e,t){return this.deltaPixelsFromPointsNoRotate(e.rotate(this.getRotation()),t)},deltaPointsFromPixelsNoRotate:function(e,t){return e.divide(this._containerInnerSize.x*this.getZoom(t))},deltaPointsFromPixels:function(e,t){return this.deltaPointsFromPixelsNoRotate(e,t).rotate(-this.getRotation())},pixelFromPointNoRotate:function(e,t){return this._pixelFromPointNoRotate(e,this.getBoundsNoRotate(t))},pixelFromPoint:function(e,t){return this._pixelFromPoint(e,this.getBoundsNoRotate(t))},_pixelFromPointNoRotate:function(t,i){return t.minus(i.getTopLeft()).times(this._containerInnerSize.x/i.width).plus(new e.Point(this._margins.left,this._margins.top))},_pixelFromPoint:function(e,t){return this._pixelFromPointNoRotate(e.rotate(this.getRotation(),this.getCenter(!0)),t)},pointFromPixelNoRotate:function(t,i){var n=this.getBoundsNoRotate(i);return t.minus(new e.Point(this._margins.left,this._margins.top)).divide(this._containerInnerSize.x/n.width).plus(n.getTopLeft())},pointFromPixel:function(e,t){return this.pointFromPixelNoRotate(e,t).rotate(-this.getRotation(),this.getCenter(!0))},_viewportToImageDelta:function(t,i){var n=this._contentBoundsNoRotate.width;return new e.Point(t*this._contentSizeNoRotate.x/n,i*this._contentSizeNoRotate.x/n)},viewportToImageCoordinates:function(t,i){if(t instanceof e.Point)return this.viewportToImageCoordinates(t.x,t.y);if(this.viewer){var n=this.viewer.world.getItemCount();if(n>1)e.console.error("[Viewport.viewportToImageCoordinates] is not accurate with multi-image; use TiledImage.viewportToImageCoordinates instead.");else if(1===n){return this.viewer.world.getItemAt(0).viewportToImageCoordinates(t,i,!0)}}return this._viewportToImageDelta(t-this._contentBoundsNoRotate.x,i-this._contentBoundsNoRotate.y)},_imageToViewportDelta:function(t,i){var n=this._contentBoundsNoRotate.width;return new e.Point(t/this._contentSizeNoRotate.x*n,i/this._contentSizeNoRotate.x*n)},imageToViewportCoordinates:function(t,i){if(t instanceof e.Point)return this.imageToViewportCoordinates(t.x,t.y);if(this.viewer){var n=this.viewer.world.getItemCount();if(n>1)e.console.error("[Viewport.imageToViewportCoordinates] is not accurate with multi-image; use TiledImage.imageToViewportCoordinates instead.");else if(1===n){return this.viewer.world.getItemAt(0).imageToViewportCoordinates(t,i,!0)}}var r=this._imageToViewportDelta(t,i);return r.x+=this._contentBoundsNoRotate.x,r.y+=this._contentBoundsNoRotate.y,r},imageToViewportRectangle:function(t,i,n,r){var o=t;if(o instanceof e.Rect||(o=new e.Rect(t,i,n,r)),this.viewer){var s=this.viewer.world.getItemCount();if(s>1)e.console.error("[Viewport.imageToViewportRectangle] is not accurate with multi-image; use TiledImage.imageToViewportRectangle instead.");else if(1===s){return this.viewer.world.getItemAt(0).imageToViewportRectangle(t,i,n,r,!0)}}var a=this.imageToViewportCoordinates(o.x,o.y),l=this._imageToViewportDelta(o.width,o.height);return new e.Rect(a.x,a.y,l.x,l.y,o.degrees)},viewportToImageRectangle:function(t,i,n,r){var o=t;if(o instanceof e.Rect||(o=new e.Rect(t,i,n,r)),this.viewer){var s=this.viewer.world.getItemCount();if(s>1)e.console.error("[Viewport.viewportToImageRectangle] is not accurate with multi-image; use TiledImage.viewportToImageRectangle instead.");else if(1===s){return this.viewer.world.getItemAt(0).viewportToImageRectangle(t,i,n,r,!0)}}var a=this.viewportToImageCoordinates(o.x,o.y),l=this._viewportToImageDelta(o.width,o.height);return new e.Rect(a.x,a.y,l.x,l.y,o.degrees)},viewerElementToImageCoordinates:function(e){var t=this.pointFromPixel(e,!0);return this.viewportToImageCoordinates(t)},imageToViewerElementCoordinates:function(e){var t=this.imageToViewportCoordinates(e);return this.pixelFromPoint(t,!0)},windowToImageCoordinates:function(t){e.console.assert(this.viewer,"[Viewport.windowToImageCoordinates] the viewport must have a viewer.");var i=t.minus(e.getElementPosition(this.viewer.element));return this.viewerElementToImageCoordinates(i)},imageToWindowCoordinates:function(t){return e.console.assert(this.viewer,"[Viewport.imageToWindowCoordinates] the viewport must have a viewer."),this.imageToViewerElementCoordinates(t).plus(e.getElementPosition(this.viewer.element))},viewerElementToViewportCoordinates:function(e){return this.pointFromPixel(e,!0)},viewportToViewerElementCoordinates:function(e){return this.pixelFromPoint(e,!0)},viewerElementToViewportRectangle:function(t){return e.Rect.fromSummits(this.pointFromPixel(t.getTopLeft(),!0),this.pointFromPixel(t.getTopRight(),!0),this.pointFromPixel(t.getBottomLeft(),!0))},viewportToViewerElementRectangle:function(t){return e.Rect.fromSummits(this.pixelFromPoint(t.getTopLeft(),!0),this.pixelFromPoint(t.getTopRight(),!0),this.pixelFromPoint(t.getBottomLeft(),!0))},windowToViewportCoordinates:function(t){e.console.assert(this.viewer,"[Viewport.windowToViewportCoordinates] the viewport must have a viewer.");var i=t.minus(e.getElementPosition(this.viewer.element));return this.viewerElementToViewportCoordinates(i)},viewportToWindowCoordinates:function(t){return e.console.assert(this.viewer,"[Viewport.viewportToWindowCoordinates] the viewport must have a viewer."),this.viewportToViewerElementCoordinates(t).plus(e.getElementPosition(this.viewer.element))},viewportToImageZoom:function(t){if(this.viewer){var i=this.viewer.world.getItemCount();if(i>1)e.console.error("[Viewport.viewportToImageZoom] is not accurate with multi-image.");else if(1===i){return this.viewer.world.getItemAt(0).viewportToImageZoom(t)}}var n=this._contentSizeNoRotate.x;return t*(this._containerInnerSize.x/n*this._contentBoundsNoRotate.width)},imageToViewportZoom:function(t){if(this.viewer){var i=this.viewer.world.getItemCount();if(i>1)e.console.error("[Viewport.imageToViewportZoom] is not accurate with multi-image.");else if(1===i){return this.viewer.world.getItemAt(0).imageToViewportZoom(t)}}return t*(this._contentSizeNoRotate.x/this._containerInnerSize.x/this._contentBoundsNoRotate.width)},toggleFlip:function(){return this.setFlip(!this.getFlip()),this},getFlip:function(){return this.flipped},setFlip:function(e){return this.flipped===e?this:(this.flipped=e,this.viewer.navigator&&this.viewer.navigator.setFlip(this.getFlip()),this.viewer.forceRedraw(),this.viewer.raiseEvent("flip",{flipped:e}),this)}}}(OpenSeadragon),function(e){function t(e,t,n,r,o,s,l,c,u){var h=l.getBoundingBox().getTopLeft(),d=l.getBoundingBox().getBottomRight();e.viewer&&e.viewer.raiseEvent("update-level",{tiledImage:e,havedrawn:t,level:r,opacity:o,visibility:s,drawArea:l,topleft:h,bottomright:d,currenttime:c,best:u}),a(e.coverage,r),a(e.loadingCoverage,r);for(var p=e._getCornerTiles(r,h,d),g=p.topLeft,m=p.bottomRight,f=e.source.getNumTiles(r),v=e.viewport.pixelFromPoint(e.viewport.getCenter()),y=g.x;y<=m.x;y++)for(var w=g.y;w<=m.y;w++){if(!e.wrapHorizontal&&!e.wrapVertical){var T=e.source.getTileBounds(r,y,w);if(null===l.intersection(T))continue}u=i(e,n,t,y,w,r,o,s,v,f,c,u)}return u}function i(t,i,r,a,l,c,u,h,d,p,g,m){var f=function(t,i,n,r,o,s,a,l,c,u){var h,d,p,g,m,f,v,y,w;s[n]||(s[n]={});s[n][t]||(s[n][t]={});s[n][t][i]||(h=(l.x+t%l.x)%l.x,d=(l.y+i%l.y)%l.y,p=o.getTileBounds(n,h,d),g=o.getTileBounds(n,h,d,!0),m=o.tileExists(n,h,d),f=o.getTileUrl(n,h,d),r.loadTilesWithAjax?(v=o.getTileAjaxHeaders(n,h,d),e.isPlainObject(r.ajaxHeaders)&&(v=e.extend({},r.ajaxHeaders,v))):v=null,y=o.getContext2D?o.getContext2D(n,h,d):void 0,p.x+=(t-h)/l.x,p.y+=u/c*((i-d)/l.y),w=new e.Tile(n,t,i,p,m,f,y,r.loadTilesWithAjax,v,g),h===l.x-1&&(w.isRightMost=!0),d===l.y-1&&(w.isBottomMost=!0),s[n][t][i]=w);return(w=s[n][t][i]).lastTouchTime=a,w}(a,l,c,t,t.source,t.tilesMatrix,g,p,t._worldWidthCurrent,t._worldHeightCurrent),v=r;t.viewer&&t.viewer.raiseEvent("update-tile",{tiledImage:t,tile:f}),s(t.coverage,c,a,l,!1);var y=f.loaded||f.loading||o(t.loadingCoverage,c,a,l);if(s(t.loadingCoverage,c,a,l,y),!f.exists)return m;if(i&&!v&&(o(t.coverage,c,a,l)?s(t.coverage,c,a,l,!0):v=!0),!v)return m;if(function(t,i,n,r,o,s){var a=t.bounds.getTopLeft();a.x*=s._scaleSpring.current.value,a.y*=s._scaleSpring.current.value,a.x+=s._xSpring.current.value,a.y+=s._ySpring.current.value;var l=t.bounds.getSize();l.x*=s._scaleSpring.current.value,l.y*=s._scaleSpring.current.value;var c=n.pixelFromPointNoRotate(a,!0),u=n.pixelFromPointNoRotate(a,!1),h=n.deltaPixelsFromPointsNoRotate(l,!0),d=n.deltaPixelsFromPointsNoRotate(l,!1),p=u.plus(d.divide(2)),g=r.squaredDistanceTo(p);i||(h=h.plus(new e.Point(1,1)));t.isRightMost&&s.wrapHorizontal&&(h.x+=.75);t.isBottomMost&&s.wrapVertical&&(h.y+=.75);t.position=c,t.size=h,t.squaredDistance=g,t.visibility=o}(f,t.source.tileOverlap,t.viewport,d,h,t),!f.loaded)if(f.context2D)n(t,f);else{var w=t._tileCache.getImageRecord(f.cacheKey);if(w)n(t,f,w.getImage())}f.loaded?function(e,t,i,n,r,o,a){var l,c,u=1e3*e.blendTime;t.blendStart||(t.blendStart=a);l=a-t.blendStart,c=u?Math.min(1,l/u):1,e.alwaysBlend&&(c*=o);if(t.opacity=c,e.lastDrawn.push(t),1===c)s(e.coverage,r,i,n,!0),e._hasOpaqueTile=!0;else if(le.visibility)return t;if(t.visibility==e.visibility&&t.squaredDistanceo?(s=this._clip.x/this._clip.height*t.height,a=this._clip.y/this._clip.height*t.height):(s=this._clip.x/this._clip.width*t.width,a=this._clip.y/this._clip.width*t.width)),t.getAspectRatio()>o){var u=t.height/c,h=0;r.isHorizontallyCentered?h=(t.width-t.height*o)/2:r.isRight&&(h=t.width-t.height*o),this.setPosition(new e.Point(t.x-s+h,t.y-a),n),this.setHeight(u,n)}else{var d=t.width/l,p=0;r.isVerticallyCentered?p=(t.height-t.width/o)/2:r.isBottom&&(p=t.height-t.width/o),this.setPosition(new e.Point(t.x-s,t.y-a+p),n),this.setWidth(d,n)}},getClip:function(){return this._clip?this._clip.clone():null},setClip:function(t){e.console.assert(!t||t instanceof e.Rect,"[TiledImage.setClip] newClip must be an OpenSeadragon.Rect or null"),t instanceof e.Rect?this._clip=t.clone():this._clip=null,this._needsDraw=!0,this.raiseEvent("clip-change")},getOpacity:function(){return this.opacity},setOpacity:function(e){e!==this.opacity&&(this.opacity=e,this._needsDraw=!0,this.raiseEvent("opacity-change",{opacity:this.opacity}))},getPreload:function(){return this._preload},setPreload:function(e){this._preload=!!e,this._needsDraw=!0},getRotation:function(e){return e?this._degreesSpring.current.value:this._degreesSpring.target.value},setRotation:function(e,t){this._degreesSpring.target.value===e&&this._degreesSpring.isAtTargetValue()||(t?this._degreesSpring.resetTo(e):this._degreesSpring.springTo(e),this._needsDraw=!0,this._raiseBoundsChange())},_getRotationPoint:function(e){return this.getBoundsNoRotate(e).getCenter()},getCompositeOperation:function(){return this.compositeOperation},setCompositeOperation:function(e){e!==this.compositeOperation&&(this.compositeOperation=e,this._needsDraw=!0,this.raiseEvent("composite-operation-change",{compositeOperation:this.compositeOperation}))},_setScale:function(e,t){var i=this._scaleSpring.target.value===e;if(t){if(i&&this._scaleSpring.current.value===e)return;this._scaleSpring.resetTo(e),this._updateForScale(),this._needsDraw=!0}else{if(i)return;this._scaleSpring.springTo(e),this._updateForScale(),this._needsDraw=!0}i||this._raiseBoundsChange()},_updateForScale:function(){this._worldWidthTarget=this._scaleSpring.target.value,this._worldHeightTarget=this.normHeight*this._scaleSpring.target.value,this._worldWidthCurrent=this._scaleSpring.current.value,this._worldHeightCurrent=this.normHeight*this._scaleSpring.current.value},_raiseBoundsChange:function(){this.raiseEvent("bounds-change")},_isBottomItem:function(){return this.viewer.world.getItemAt(0)===this},_getLevelsInterval:function(){var e=Math.max(this.source.minLevel,Math.floor(Math.log(this.minZoomImageRatio)/Math.log(2))),t=this.viewport.deltaPixelsFromPointsNoRotate(this.source.getPixelRatio(0),!0).x*this._scaleSpring.current.value,i=Math.min(Math.abs(this.source.maxLevel),Math.abs(Math.floor(Math.log(t/this.minPixelRatio)/Math.log(2))));return i=Math.max(i,this.source.minLevel||0),{lowestLevel:e=Math.min(e,i),highestLevel:i}},_updateViewport:function(){for(this._needsDraw=!1,this._tilesLoading=0,this.loadingCoverage={};this.lastDrawn.length>0;){this.lastDrawn.pop().beingDrawn=!1}var i=this.viewport,o=this._viewportToTiledImageRectangle(i.getBoundsWithMargins(!0));if(!this.wrapHorizontal&&!this.wrapVertical){var s=this._viewportToTiledImageRectangle(this.getClippedBounds(!0));if(null===(o=o.intersection(s)))return}for(var a=this._getLevelsInterval(),l=a.lowestLevel,c=a.highestLevel,u=null,h=!1,d=e.now(),p=c;p>=l;p--){var g=!1,m=i.deltaPixelsFromPointsNoRotate(this.source.getPixelRatio(p),!0).x*this._scaleSpring.current.value;if(p===l||!h&&m>=this.minPixelRatio)g=!0,h=!0;else if(!h)continue;var f=i.deltaPixelsFromPointsNoRotate(this.source.getPixelRatio(p),!1).x*this._scaleSpring.current.value,v=i.deltaPixelsFromPointsNoRotate(this.source.getPixelRatio(Math.max(this.source.getClosestLevel(),0)),!1).x*this._scaleSpring.current.value,y=this.immediateRender?1:v;if(u=t(this,h,g,p,Math.min(1,(m-.5)/.5),y/Math.abs(y-f),o,d,u),r(this.coverage,p))break}!function(t,i){if(0===t.opacity||0===i.length&&!t.placeholderFillStyle)return;var n,r,o,s=i[0];s&&(n=t.opacity<1||t.compositeOperation&&"source-over"!==t.compositeOperation||!t._isBottomItem()&&s._hasTransparencyChannel());var a,l=t.viewport.getZoom(!0),c=t.viewportToImageZoom(l);i.length>1&&c>t.smoothTileEdgesMinZoom&&!t.iOSDevice&&t.getRotation(!0)%360==0&&e.supportsCanvas&&(n=!0,r=s.getScaleForEdgeSmoothing(),o=s.getTranslationForEdgeSmoothing(r,t._drawer.getCanvasSize(!1),t._drawer.getCanvasSize(!0)));n&&(r||(a=t.viewport.viewportToViewerElementRectangle(t.getClippedBounds(!0)).getIntegerBoundingBox().times(e.pixelDensityRatio),t._drawer.viewer.viewport.getFlip()&&(0===t.viewport.degrees&&t.getRotation(!0)%360==0||(a.x=t._drawer.viewer.container.clientWidth-(a.x+a.width)))),t._drawer._clear(!0,a));r||(0!==t.viewport.degrees&&t._drawer._offsetForRotation({degrees:t.viewport.degrees,useSketch:n}),t.getRotation(!0)%360!=0&&t._drawer._offsetForRotation({degrees:t.getRotation(!0),point:t.viewport.pixelFromPointNoRotate(t._getRotationPoint(!0),!0),useSketch:n}),0===t.viewport.degrees&&t.getRotation(!0)%360==0&&t._drawer.viewer.viewport.getFlip()&&t._drawer._flip());var u=!1;if(t._clip){t._drawer.saveContext(n);var h=t.imageToViewportRectangle(t._clip,!0);h=h.rotate(-t.getRotation(!0),t._getRotationPoint(!0));var d=t._drawer.viewportToDrawerRectangle(h);r&&(d=d.times(r)),o&&(d=d.translate(o)),t._drawer.setClip(d,n),u=!0}if(t.placeholderFillStyle&&!1===t._hasOpaqueTile){var p=t._drawer.viewportToDrawerRectangle(t.getBounds(!0));r&&(p=p.times(r)),o&&(p=p.translate(o));var g=null;g="function"==typeof t.placeholderFillStyle?t.placeholderFillStyle(t,t._drawer.context):t.placeholderFillStyle,t._drawer.drawRectangle(p,g,n)}for(var m=i.length-1;m>=0;m--)s=i[m],t._drawer.drawTile(s,t._drawingHandler,n,r,o),s.beingDrawn=!0,t.viewer&&t.viewer.raiseEvent("tile-drawn",{tiledImage:t,tile:s});u&&t._drawer.restoreContext(n);r||(t.getRotation(!0)%360!=0&&t._drawer._restoreRotationChanges(n),0!==t.viewport.degrees&&t._drawer._restoreRotationChanges(n));n&&(r&&(0!==t.viewport.degrees&&t._drawer._offsetForRotation({degrees:t.viewport.degrees,useSketch:!1}),t.getRotation(!0)%360!=0&&t._drawer._offsetForRotation({degrees:t.getRotation(!0),point:t.viewport.pixelFromPointNoRotate(t._getRotationPoint(!0),!0),useSketch:!1})),t._drawer.blendSketch({opacity:t.opacity,scale:r,translate:o,compositeOperation:t.compositeOperation,bounds:a}),r&&(t.getRotation(!0)%360!=0&&t._drawer._restoreRotationChanges(!1),0!==t.viewport.degrees&&t._drawer._restoreRotationChanges(!1)));r||0===t.viewport.degrees&&t.getRotation(!0)%360==0&&t._drawer.viewer.viewport.getFlip()&&t._drawer._flip();!function(t,i){if(t.debugMode)for(var n=i.length-1;n>=0;n--){var r=i[n];try{t._drawer.drawDebugInfo(r,i.length,n,t)}catch(t){e.console.error(t)}}}(t,i)}(this,this.lastDrawn),u&&!u.context2D?(!function(t,i,r){i.loading=!0,t._imageLoader.addJob({src:i.url,loadWithAjax:i.loadWithAjax,ajaxHeaders:i.ajaxHeaders,crossOriginPolicy:t.crossOriginPolicy,ajaxWithCredentials:t.ajaxWithCredentials,callback:function(o,s,a){!function(t,i,r,o,s,a){if(!o)return e.console.log("Tile %s failed to load: %s - error: %s",i,i.url,s),t.viewer.raiseEvent("tile-load-failed",{tile:i,tiledImage:t,time:r,message:s,tileRequest:a}),i.loading=!1,void(i.exists=!1);if(rthis._maxImageCacheCount){for(var a,l,c,u,h,d,p=null,g=-1,m=null,f=this._tilesLoaded.length-1;f>=0;f--)(a=(d=this._tilesLoaded[f]).tile).level<=r||a.beingDrawn||(p?(u=a.lastTouchTime,l=p.lastTouchTime,h=a.level,c=p.level,(uc)&&(p=a,g=f,m=d)):(p=a,g=f,m=d));p&&g>=0&&(this._unloadTile(m),o=g)}this._tilesLoaded[o]=new t({tile:n.tile,tiledImage:n.tiledImage})},clearTilesFor:function(t){var i;e.console.assert(t,"[TileCache.clearTilesFor] tiledImage is required");for(var n=0;n=this._items.length)throw new Error("Index bigger than number of layers.");i!==n&&-1!==n&&(this._items.splice(n,1),this._items.splice(i,0,t),this._needsDraw=!0,this.raiseEvent("item-index-change",{item:t,previousIndex:n,newIndex:i}))},removeItem:function(t){e.console.assert(t,"[World.removeItem] item is required");var i=e.indexOf(this._items,t);-1!==i&&(t.removeHandler("bounds-change",this._delegatedFigureSizes),t.removeHandler("clip-change",this._delegatedFigureSizes),t.destroy(),this._items.splice(i,1),this._figureSizes(),this._needsDraw=!0,this._raiseRemoveItem(t))},removeAll:function(){var e,t;for(this.viewer._cancelPendingImages(),t=0;tu.height?a:a*(u.width/u.height))*(u.height/u.width),p=new e.Point(g+(a-h)/2,m+(a-d)/2),c.setPosition(p,n),c.setWidth(h,n),"horizontal"===r?g+=l:m+=l;this.setAutoRefigureSizes(!0)},_figureSizes:function(){var t=this._homeBounds?this._homeBounds.clone():null,i=this._contentSize?this._contentSize.clone():null,n=this._contentFactor||0;if(this._items.length){var r=this._items[0],o=r.getBounds();this._contentFactor=r.getContentSize().x/o.width;for(var s=r.getClippedBounds().getBoundingBox(),a=s.x,l=s.y,c=s.x+s.width,u=s.y+s.height,h=1;h{const s=reakit.useTooltipState({placement:n});return React.useEffect(()=>{s.place(n)},[n]),React__default.createElement(React__default.Fragment,null,React__default.createElement(reakit.TooltipReference,_extends({},s,r,{ref:o}),e=>React__default.cloneElement(React__default.Children.only(i),e)),React__default.createElement(reakit.Tooltip,_extends({},s,{style:e,unstable_portal:!1,className:"villain-tooltip"}),t))}),ToolbarButton=React__default.forwardRef(({icon:e,iconSize:t,label:i,title:n,active:r,tooltip:o,onClick:s,children:a,typeClass:l,tooltipPlacement:c,...u},h)=>{const d={ref:h,...u},p=o?{}:d;let g=React__default.createElement(reakit.Button,_extends({focusable:!0,title:n,onClick:s,"aria-label":o,className:clsx("villain-button",l&&`villain-button--${l}`,r&&"villain-button--active")},p),e&&React__default.createElement(Icon$1,{path:e,size:t||"24px",className:"villain-icon"}),i&&React__default.createElement("span",{className:"villain-button__label"},i),a);return o&&(g=React__default.createElement(Tooltip,_extends({},d,{title:o,placement:c}),g)),g}),CustomSeparator=e=>React__default.createElement(reakit.MenuSeparator,_extends({},e,{className:"villain-menu__separator"})),CustomItem=({children:e,...t})=>React__default.createElement(reakit.MenuItem,_extends({as:ToolbarButton,className:"villain-menu__item"},t),React__default.createElement("div",{className:"villain-menu__item__content"},React__default.createElement("div",{className:"villain-menu__item__label"},e))),CustomCheckbox=({children:e,...t})=>React__default.createElement(reakit.MenuItemCheckbox,_extends({as:ToolbarButton},t),React__default.createElement("div",{className:"villain-menu__item__content"},React__default.createElement("div",{className:"villain-menu__item__label"},e),React__default.createElement("div",{className:"villain-menu__item__toggler"}))),CustomRadio=({children:e,...t})=>React__default.createElement(reakit.MenuItemRadio,_extends({as:ToolbarButton,icon:t.checked?mdiRadioboxMarked:mdiRadioboxBlank,iconSize:"20px"},t),React__default.createElement("div",{className:"villain-menu__item__content"},React__default.createElement("div",{className:"villain-menu__item__label"},e))),CustomSubmenu=({children:e,...t})=>React__default.createElement(reakit.MenuItem,_extends({},t,{as:ToolbarButton}),React__default.createElement("div",{className:"villain-menu__item__content"},React__default.createElement("div",{className:"villain-menu__item__label"},e),React__default.createElement(Icon$1,{path:mdiChevronRight,size:"24px",className:"villain-icon villain-menu__item__icon"}))),MenuHeader=({title:e,closeSubmenu:t,menuProps:i,...n})=>React__default.createElement("div",_extends({},n,{className:"villain-menu__header"}),React__default.createElement(CustomItem,_extends({},i,{icon:mdiChevronLeft,onClick:t}),e),React__default.createElement(CustomSeparator,_extends({},i,{style:{margin:0}}))),CustomItems={item:CustomItem,radio:CustomRadio,submenu:CustomSubmenu,checkbox:CustomCheckbox,separator:CustomSeparator};function Item({index:e,itemType:t,content:i,children:n,openSubmenu:r,onClick:o,...s}){const a=CustomItems[t]||CustomItems.item,l=clsx("separator"!==t&&"villain-menu__item",t&&`villain-menu__${t}`);return React__default.createElement(a,_extends({onClick:i=>{o&&o(i),"submenu"===t&&r&&r(e)},className:l},s),i||n)}function ItemList({title:e,items:t,getProps:i,menuProps:n,getContent:r,closeSubmenu:o}){return React__default.createElement(reakit.MenuGroup,n,t.map((t,s)=>React__default.createElement(Item,_extends({},n,i({item:t,index:s,closeSubmenu:o,title:e}),{key:`${t}-${s}`}),r(t))))}const MenuPanel=React__default.forwardRef(({title:e,items:t,list:i,openSubmenu:n,closeSubmenu:r,menuProps:o},s)=>React__default.createElement("div",{className:"villain-menu__panel",ref:s},e&&React__default.createElement(MenuHeader,{menuProps:o,closeSubmenu:r,title:e}),i?React__default.createElement(ItemList,_extends({},i,{title:e,menuProps:o,closeSubmenu:r})):t.map(({nestedTitle:t,nestedItems:i,nestedList:r,...s},a)=>{const l=`${s.itemType||"item"}-${a}`;return React__default.createElement(Item,_extends({},o,s,{title:e,openSubmenu:n,index:a,key:l}))}))),defaultSubmenuState={show:!1,list:null,index:null,title:null,items:null},MenuWithTooltip=React__default.forwardRef(({disclosure:e,tooltip:t,items:i,placement:n,ariaLabel:r,...o},s)=>{const a=reakit.useMenuState({placement:n,gutter:20}),l=reakit.useTooltipState({placement:n}),c=React__default.useRef(null),u=React__default.useRef(null),[h,d]=React__default.useState(0),[p,g]=React__default.useState({...defaultSubmenuState}),m=e=>{return e.getBoundingClientRect().height},f=()=>{g({...defaultSubmenuState})},v=e=>{g({index:e})},y=()=>{f()};return React__default.useEffect(()=>{a.visible?(()=>{const e=u.current;e&&d(m(e)),f()})():f()},[a.visible]),React__default.useEffect(()=>{if(p.index||0===p.index){const e=i[p.index];if(e){const t=e.nestedList&&e.nestedList.items&&e.nestedList.items.length>0,i=e.nestedItems&&e.nestedItems.length>0,n=t||i;n&&g({show:n,list:t?e.nestedList:null,items:i?e.nestedItems:null,title:e.nestedTitle})}}},[p.index,i]),React__default.useEffect(()=>{const e=c.current,t=u.current;p.show?e&&d(m(e)):t&&d(m(t)),a.first()},[p.show]),React__default.useEffect(()=>{h&&a.unstable_update()},[h]),React__default.createElement(React__default.Fragment,null,React__default.createElement(reakit.TooltipReference,_extends({ref:s},l,o),t=>React__default.createElement(reakit.MenuDisclosure,_extends({},a,t),t=>React__default.cloneElement(React__default.Children.only(e),t))),React__default.createElement(reakit.Tooltip,_extends({},l,{className:"villain-tooltip",unstable_portal:!1}),t),React__default.createElement(reakit.Menu,_extends({},a,{className:"villain-menu","aria-label":r,style:{height:`${h}px`}}),React__default.createElement("div",{className:"villain-menu__animated-content"},p.show?React__default.createElement(MenuPanel,{menuProps:a,list:p.list,title:p.title,items:p.items,openSubmenu:v,closeSubmenu:y,ref:c}):React__default.createElement(MenuPanel,{menuProps:a,items:i,openSubmenu:v,closeSubmenu:y,ref:u}))))}),Languages$8={EN:"English",ES:"Español",DE:"Deutsch",FR:"Français",PT:"Português",ID:"Bahasa Indonesia",RU:"Русский",ZH:"話僮"};function getLanguageName(e){return Languages$8[e]||e}const SettingsMenu=React__default.forwardRef((e,t)=>{const i=React.useContext(ReaderContext),n=React__default.createElement(ToolbarButton,{typeClass:"icon",icon:mdiSettings}),r="Dark"===i.state.theme,o=i.state.mangaMode,s=[{icon:mdiPagePrevious,content:localize["Manga mode"],checked:o,itemType:"checkbox",onChange:()=>{i.updateState(e=>({mangaMode:!e.mangaMode}))}},{icon:mdiBrightness4,content:localize["Dark theme"],checked:r,itemType:"checkbox",onChange:()=>{i.updateState(e=>({theme:"Dark"===e.theme?"Light":"Dark"}))}},{itemType:"separator"},{icon:mdiTranslate,content:localize.Language,itemType:"submenu",nestedTitle:localize.Languages,nestedList:{items:localize.getAvailableLanguages(),getProps:({item:e,index:t,closeSubmenu:n,title:r})=>({name:r,value:e,itemType:"radio",checked:localize.getLanguage()===e,onClick:n,onChange:()=>(e=>{i.updateState({language:e})})(e)}),getContent:e=>getLanguageName(e)}}];return React__default.createElement(MenuWithTooltip,_extends({},e,{ref:t,items:s,tooltip:localize.Settings,placement:"top",disclosure:n,ariaLabel:localize.Settings}))}),useFocus=()=>{const e=React.useRef(null);return[e,()=>{e.current&&(e.current.focus(),e.current.select())}]},getNestedFocus=e=>{const t=document.activeElement;return e.contains(t)},getInteractionFocus=()=>{const e=document.activeElement;if(e){return["BUTTON","INPUT","TEXTAREA"].includes(e.tagName)}},ZoomControls=({disabled:e,onUpdate:t,toolbarItemProps:i})=>{const n=React.useContext(ReaderContext),{canZoomIn:r,canZoomOut:o,currentZoom:s}=n.state,[a,l]=React.useState({value:""}),[c,u]=React.useState(!1),[h,d]=useFocus();React.useEffect(()=>{p()},[s]);const p=()=>{s&&l({value:s})},g=()=>{a.value.length>0?t(a.value):p()};return React__default.createElement("div",{className:"villain-toolbar__group"},React__default.createElement(reakit.ToolbarItem,_extends({},i,{typeClass:"icon",tooltip:localize["Zoom in"],icon:mdiPlus,disabled:!r||e,onClick:()=>{t(s+10)},as:ToolbarButton,focusable:!0})),React__default.createElement(reakit.ToolbarItem,_extends({},i,{typeClass:"icon",icon:mdiMinus,tooltip:localize["Zoom out"],disabled:!o||e,onClick:()=>{t(s-10)},as:ToolbarButton,focusable:!0})),React__default.createElement("div",{className:"villain-wrapper-input","data-focus":c,onClick:()=>{d()}},React__default.createElement(reakit.ToolbarItem,_extends({},i,{step:1,size:3,pattern:"d+",ref:h,type:"number",role:"textbox",contentEditable:"true",title:"Zoom","aria-label":"Zoom to percentage value",onBlur:()=>{g(),u(!1)},onFocus:()=>{u(!0)},onChange:e=>{const{value:t}=e.target,i=t.replace(/\..*|^0+[\s]/gm,"");i.length<4&&l({value:t?i:s})},onKeyPress:e=>{"Enter"===e.key&&g()},className:"villain-input",disabled:e,value:a.value,as:"input",focusable:!0})),React__default.createElement("div",{className:"villain-label villain-label--center"},"%")))},Navigation=({toolbarItemProps:e})=>{const t=React.useContext(ReaderContext),{totalPages:i,isFirstPage:n,isLastPage:r,mangaMode:o,currentPage:s}=t.state,{navigateForward:a,navigateBackward:l,navigateToPage:c}=t,[u,h]=React.useState({value:s||1}),[d,p]=React.useState(!1),[g,m]=useFocus();React.useEffect(()=>{f()},[s]);const f=()=>{h({value:s+1})},v=()=>{const{value:e}=u;if(e){const t=parseInt(e,10);t<=i&&t>0?c(t-1):f()}else f()};return React__default.createElement("div",{className:"villain-toolbar__group"},React__default.createElement(reakit.ToolbarItem,_extends({},e,{typeClass:"icon",icon:mdiChevronLeft,onClick:o?a:l,disabled:o?r:n,tooltip:o?localize["Next page"]:localize["Previous page"],tooltipPlacement:"top-start",as:ToolbarButton,focusable:!0})),React__default.createElement(reakit.ToolbarItem,_extends({},e,{typeClass:"icon",icon:mdiChevronRight,onClick:o?l:a,disabled:o?n:r,tooltip:localize["Next page"],as:ToolbarButton,focusable:!0})),React__default.createElement("div",{className:"villain-wrapper-input","data-focus":d,onClick:e=>{m()}},React__default.createElement(reakit.ToolbarItem,_extends({},e,{min:1,step:1,size:3,ref:g,max:i,type:"number","aria-label":"Go to page number",role:"textbox",contentEditable:"true",title:"Page",pattern:"d+",className:"villain-input",onBlur:()=>{v(),p(!1)},onFocus:()=>{p(!0)},onChange:e=>{const{value:t}=e.target,i=t.replace(/\..*|^0+/gm,"");i.length<4&&h({value:t?i:s+1})},onKeyPress:e=>{"Enter"===e.key&&v()},value:u.value,as:"input",focusable:!0})),React__default.createElement("div",{className:"villain-label villain-label--center"},"/"),React__default.createElement("div",{className:"villain-label"},`${i}`)))};function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArrayLimit(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var i=[],n=!0,r=!1,o=void 0;try{for(var s,a=e[Symbol.iterator]();!(n=(s=a.next()).done)&&(i.push(s.value),!t||i.length!==t);n=!0);}catch(e){r=!0,o=e}finally{try{n||null==a.return||a.return()}finally{if(r)throw o}}return i}}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_nonIterableRest()}function _extends$1(){return(_extends$1=Object.assign||function(e){for(var t=1;t2?n-2:0);for(var r=2;r0&&void 0!==arguments[0]?arguments[0]:{},t=i.props,n=t.emitMouse,r=t.emitTouch;return _objectSpread({},e,{onMouseDown:callAll(e.onMouseDown,n),onTouchStart:callAll(e.onTouchStart,r)})})),i}return _inherits(t,e),_createClass(t,[{key:"render",value:function(){var e=this.getRailProps,t=this.props,i=t.getEventData,n=t.activeHandleID,r=(0,t.children)({getEventData:i,activeHandleID:n,getRailProps:e});return r&&React__default.Children.only(r)}}]),t}(React.Component);Rail.propTypes={getEventData:propTypes.func,activeHandleID:propTypes.string,emitMouse:propTypes.func,emitTouch:propTypes.func,children:propTypes.func.isRequired};var Ticks=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"render",value:function(){var e=this.props,t=e.children,i=e.values,n=e.scale,r=e.count,o=t({getEventData:e.getEventData,activeHandleID:e.activeHandleID,ticks:(i||n.getTicks(r)).map((function(e){return{id:"$$-".concat(e),value:e,percent:n.getValue(e)}}))});return o&&React__default.Children.only(o)}}]),t}(React.Component);function ownKeys$1(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function _objectSpread$1(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:{},t=i.props,n=t.emitMouse,r=t.emitTouch;return _objectSpread$1({},e,{onMouseDown:callAll(e.onMouseDown,n),onTouchStart:callAll(e.onTouchStart,r)})})),i}return _inherits(t,e),_createClass(t,[{key:"render",value:function(){for(var e=this.getTrackProps,t=this.props,i=t.children,n=t.left,r=t.right,o=t.scale,s=t.handles,a=t.getEventData,l=t.activeHandleID,c=o.getDomain(),u=[],h=0;h1&&void 0!==arguments[1]?arguments[1]:{},n=i.props,r=n.emitKeyboard,o=n.emitMouse,s=n.emitTouch;return _objectSpread$2({},t,{onKeyDown:callAll(t.onKeyDown,(function(t){return r(t,e)})),onMouseDown:callAll(t.onMouseDown,i.autofocus,(function(t){return o(t,e)})),onTouchStart:callAll(t.onTouchStart,(function(t){return s(t,e)}))})})),i}return _inherits(t,e),_createClass(t,[{key:"render",value:function(){var e=this.getHandleProps,t=this.props,i=t.activeHandleID,n=(0,t.children)({handles:t.handles,activeHandleID:i,getHandleProps:e});return n&&React__default.Children.only(n)}}]),t}(React.Component);function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,i=new Array(e.length);ti.val?e?-1:1:i.val>t.val?e?1:-1:0}}function getUpdatedHandles(e,t,i,n){var r=e.findIndex((function(e){return e.key===t}));if(-1!==r){var o=e[r],s=o.key;return o.val===i?e:[].concat(_toConsumableArray(e.slice(0,r)),[{key:s,val:i}],_toConsumableArray(e.slice(r+1))).sort(getSortByVal(n))}return e}function getSliderDomain(e,t){if(!e)return[0,0];var i=e.getBoundingClientRect();return[t?i.top:i.left,t?i.bottom:i.right]}function isNotValidTouch(e){var t=e.type,i=void 0===t?"":t,n=e.touches;return!n||n.length>1||"touchend"===i.toLowerCase()&&n.length>0}function getTouchPosition(e,t){return e?t.touches[0].clientY:t.touches[0].pageX}function getHandles(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1?arguments[1]:void 0,i=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0,r=0;return{handles:e.map((function(e){var t=i.getValue(e);return e!==t&&(r+=1,warning_1(!n,"".concat(prfx," Invalid value encountered. Changing ").concat(e," to ").concat(t,"."))),t})).map((function(e,t){return{key:"$$-".concat(t),val:e}})).sort(getSortByVal(t)),changes:r}}function mode1(e,t){return t}function mode2(e,t){for(var i=0;i0)}if(-1===o)return e;for(var u=s?i:-i,h=0;ht?1:e>=t?0:NaN}function bisector(e){return 1===e.length&&(e=ascendingComparator(e)),{left:function(t,i,n,r){for(null==n&&(n=0),null==r&&(r=t.length);n>>1;e(t[o],i)<0?n=o+1:r=o}return n},right:function(t,i,n,r){for(null==n&&(n=0),null==r&&(r=t.length);n>>1;e(t[o],i)>0?r=o:n=o+1}return n}}}function ascendingComparator(e){return function(t,i){return ascending(e(t),i)}}var ascendingBisect=bisector(ascending),e10=Math.sqrt(50),e5=Math.sqrt(10),e2=Math.sqrt(2);function ticks(e,t,i){var n,r,o,s,a=-1;if(i=+i,(e=+e)===(t=+t)&&i>0)return[e];if((n=t0)for(e=Math.ceil(e/s),t=Math.floor(t/s),o=new Array(r=Math.ceil(t-e+1));++a=0?(o>=e10?10:o>=e5?5:o>=e2?2:1)*Math.pow(10,r):-Math.pow(10,-r)/(o>=e10?10:o>=e5?5:o>=e2?2:1)}var LinearScale=function(){function e(){_classCallCheck(this,e),this.domain=[0,1],this.range=[0,1],this.interpolator=null}return _createClass(e,[{key:"createInterpolator",value:function(e,t){var i=e[0],n=e[1],r=t[0],o=t[1];return ns?a:s)})),this.step=1,this.domain=[0,1],this.range=[0,1]},isBrowser="undefined"!=typeof window&&"undefined"!=typeof document,noop=function(){},compare=function(e){return function(t,i,n){return t&&e[n]===i}},equal=function(e,t){return e===t||e.length===t.length&&e.reduce(compare(t),!0)},getNextValue=function(e,t,i,n){var r=n?e-t:e+t;return n?Math.max(i[0],r):Math.min(i[1],r)},getPrevValue=function(e,t,i,n){var r=n?e+t:e-t;return n?Math.min(i[1],r):Math.max(i[0],r)},Slider=function(e){function t(){var e,i;_classCallCheck(this,t);for(var n=arguments.length,r=new Array(n),o=0;og,"".concat(prfx," Max must be greater than min (even if reversed). Max is ").concat(m,". Min is ").concat(g,"."));var f=getHandles(n||t.values,o,u,l),v=f.handles;(f.changes||void 0===n||n===t.values)&&(s(v.map((function(e){return e.val}))),a(v.map((function(e){return e.val})))),d.step=i,d.values=n,d.domain=r,d.handles=v,d.reversed=o}else if(!equal(n,t.values)){var y=getHandles(n,o,u,l),w=y.handles;y.changes&&(s(w.map((function(e){return e.val}))),a(w.map((function(e){return e.val})))),d.values=n,d.handles=w}return Object.keys(d).length?d:null}}]),t}(React.PureComponent);Slider.propTypes={component:propTypes.string,rootStyle:propTypes.object,rootProps:propTypes.object,className:propTypes.string,domain:propTypes.array,values:propTypes.array,step:propTypes.number,mode:propTypes.oneOfType([propTypes.number,propTypes.func]),vertical:propTypes.bool,reversed:propTypes.bool,onChange:propTypes.func,onUpdate:propTypes.func,onSlideStart:propTypes.func,onSlideEnd:propTypes.func,disabled:propTypes.bool,flatten:propTypes.bool,warnOnChanges:propTypes.bool,children:propTypes.any},Slider.defaultProps={mode:1,step:.1,domain:[0,100],component:"div",rootProps:{},rootStyle:{},vertical:!1,reversed:!1,onChange:noop,onUpdate:noop,onSlideStart:noop,onSlideEnd:noop,disabled:!1,flatten:!1,warnOnChanges:!1},Slider.Rail=Rail,Slider.Ticks=Ticks,Slider.Tracks=Tracks,Slider.Handles=Handles;const Tooltip$1=({value:e=null})=>React__default.createElement("div",{className:"villain-tooltip--slider"},React__default.createElement("div",{className:"villain-tooltip--slider__container"},React__default.createElement("div",{className:"villain-tooltip--slider__text"},e)));Tooltip$1.propTypes={value:propTypes.number};const Handle=({domain:[e,t],handle:{id:i,value:n,percent:r},isActive:o,disabled:s,getHandleProps:a,toolbarItemProps:l})=>{const[c,u]=React.useState(!1);return React__default.createElement(reakit.ToolbarItem,_extends({},l,{role:"slider","aria-valuemin":e,"aria-valuemax":t,"aria-valuenow":n,style:{height:14,width:14,left:`${r}%`,position:"absolute",transform:"translate(-50%, -50%)",WebkitTapHighlightColor:"rgba(0,0,0,0)",border:0,borderRadius:"50%",backgroundColor:s?"transparent":"var(--slider-track-bg)",zIndex:1,margin:0,padding:0}},a(i,{onMouseEnter:()=>{u(!0)},onMouseLeave:()=>{u(!1)}}),{as:"button"}),!c&&!o||s?null:React__default.createElement(Tooltip$1,{value:n}))};Handle.propTypes={domain:propTypes.array.isRequired,handle:propTypes.shape({id:propTypes.string.isRequired,value:propTypes.number.isRequired,percent:propTypes.number.isRequired}).isRequired,getHandleProps:propTypes.func.isRequired,isActive:propTypes.bool.isRequired,disabled:propTypes.bool};var Handle$1=React__default.memo(Handle);const railStyle={position:"absolute",margin:0,width:"100%",height:"100%",cursor:"pointer",borderRadius:"4px",backgroundColor:"var(--slider-bg)",zIndex:-1},SliderRail=({activeHandleID:e,getEventData:t,getRailProps:i})=>{const[n,r]=React.useState(null),[o,s]=React.useState(null),a=i=>{e?(r(null),s(null)):(r(t(i).value),s(t(i).percent))};return React__default.createElement("div",_extends({style:railStyle},i({onMouseEnter:()=>{document.addEventListener("mousemove",a)},onMouseLeave:()=>{r(null),s(null),document.removeEventListener("mousemove",a)}})))};SliderRail.propTypes={activeHandleID:propTypes.string,getEventData:propTypes.func.isRequired,getRailProps:propTypes.func.isRequired};const sliderStyle={position:"absolute",width:"100%",height:4,display:"flex",alignItems:"center",borderRadius:"4px",justifyContent:"center",zIndex:99},Track=({source:e,target:t,getTrackProps:i})=>React__default.createElement("div",_extends({className:"villain-slider__track",style:{zIndex:0,left:`${e.percent}%`,width:`${t.percent-e.percent}%`}},i())),defaultValues=[1],SliderUI=({max:e=1,bufferProgress:t=0,reversed:i,onChange:n,value:r,toolbarItemProps:o})=>{const[s,a]=React.useState(!1),[l,c]=React.useState(defaultValues.slice()),u=[1,e];if(1==e)return null;return React.useEffect(()=>{s||c([r+1])},[r]),React__default.createElement("div",{className:"villain-slider",style:{height:sliderStyle.height}},React__default.createElement(Slider,{rootStyle:sliderStyle,domain:u,step:1,mode:2,values:l,onUpdate:()=>a(!0),onChange:e=>{a(!1),n(e[0]-1)},reversed:i},React__default.createElement(Rail,null,({activeHandleID:e,getEventData:t,getRailProps:i})=>React__default.createElement(SliderRail,{activeHandleID:e,getEventData:t,getRailProps:i})),React__default.createElement(Handles,null,({handles:e,activeHandleID:t,getHandleProps:i})=>React__default.createElement("div",{className:"villain-slider__handles"},e.map(e=>React__default.createElement(Handle$1,{key:e.id,handle:e,domain:u,isActive:e.id===t,getHandleProps:i,toolbarItemProps:o})))),React__default.createElement(Tracks,{right:i,left:!i},({tracks:e,getTrackProps:t})=>React__default.createElement("div",{className:"villain-slider__tracks"},e.map(({id:e,source:i,target:n})=>React__default.createElement(Track,{key:e,source:i,target:n,getTrackProps:t}))))),React__default.createElement("div",{className:"villain-slider__buffer",style:{width:`${t}%`,borderRadius:"4px",right:i?0:"initial"}}))};var Slider$1=React__default.memo(SliderUI);const Toolbar=({container:e,updateZoom:t,renderError:i,showControls:n,toggleFullscreen:r})=>{const{state:o,toggleSetting:s,navigateForward:a,navigateBackward:l,navigateToPage:c,togglePin:u,toggleTheme:h}=React.useContext(ReaderContext),{pages:d,bookMode:p,mangaMode:g,totalPages:m,fullscreen:f,currentPage:v,currentZoom:y,allowFullScreen:w,autoHideControls:T,allowGlobalShortcuts:_}=o,S=React.useCallback(t=>{if(getInteractionFocus())return;if(!_&&!getNestedFocus(e))return;const i=g?l:a,n=g?a:l;switch(t.key){case"f":t.preventDefault(),r();break;case"ArrowRight":i();break;case"ArrowLeft":n()}},[_,g,l,a,r]);React.useEffect(()=>(document.addEventListener("keydown",S),()=>{document.removeEventListener("keydown",S)}),[S]);const x=f?mdiFullscreenExit:mdiFullscreen,b=d.length/m*100,E=reakit.useToolbarState();return React__default.createElement(reakit.Toolbar,_extends({},E,{"aria-label":"Toolbar",className:clsx("villain-toolbar",!n&&"villain-toolbar--hide")}),React__default.createElement(Navigation,{currentPage:v,totalPages:m,toolbarItemProps:E}),React__default.createElement("div",{className:"villain-toolbar__group villain-toolbar__group--expand"},React__default.createElement(Slider$1,{max:m,value:v,bufferProgress:b,onChange:c,reversed:g,toolbarItemProps:E})),React__default.createElement("div",{className:"villain-toolbar__group",disabled:i},React__default.createElement(ZoomControls,{onUpdate:t,currentZoom:y,disabled:i,toolbarItemProps:E}),React__default.createElement(reakit.ToolbarSeparator,{className:"villain-toolbar__divider"}),React__default.createElement(reakit.ToolbarItem,_extends({},E,{as:SettingsMenu})),React__default.createElement(reakit.ToolbarItem,_extends({},E,{typeClass:"icon",icon:T?mdiPin:mdiPinOff,onClick:u,disabled:i,tooltip:T?localize["Pin toolbar"]:localize["Unpin toolbar"],as:ToolbarButton,focusable:!0})),React__default.createElement(reakit.ToolbarItem,_extends({},E,{typeClass:"icon",icon:p?mdiBookOpen:mdiBookOpenOutline,onClick:()=>s("bookMode"),disabled:i,tooltip:p?localize["Page view"]:localize["Book view"],tooltipPlacement:w?"top":"top-end",as:ToolbarButton,focusable:!0})),w&&React__default.createElement(reakit.ToolbarItem,_extends({},E,{typeClass:"icon",icon:x,onClick:r,disabled:i,tooltip:f?localize["Exit fullscreen"]:localize["Enter fullscreen"],tooltipPlacement:"top-end",as:ToolbarButton,focusable:!0}))))},prefixes={exitFullscreen:["exitFullscreen","msExitFullscreen","mozCancelFullScreen","webkitExitFullscreen"],fullscreenChange:["fullscreenchange","MSFullscreenChange","mozfullscreenchange","webkitfullscreenchange"],fullscreenEnabled:["fullscreenEnabled","msFullscreenEnabled","mozFullScreenEnabled","webkitFullscreenEnabled"],fullscreenElement:["fullscreenElement","msFullscreenElement","mozFullScreenElement","webkitFullscreenElement"],requestFullscreen:["requestFullscreen","msRequestFullscreen","mozRequestFullScreen","webkitRequestFullscreen"]},getPrefix=()=>{let e=0;return prefixes.fullscreenEnabled.some((t,i)=>{if(document[t]||!1===document[t])return e=i,!0}),e},fullscreenElement=()=>{const e=getPrefix(),t=prefixes.fullscreenElement[e];return document[t]},requestFullscreen=e=>{const t=getPrefix(),i=prefixes.requestFullscreen[t];e[i]&&e[i]()},exitFullscreen=()=>{const e=getPrefix(),t=prefixes.exitFullscreen[e];document[t]&&document[t]()},toggleFullscreen=e=>{fullscreenElement()?exitFullscreen():requestFullscreen(e)},onFullscreenChange=(e,t,i)=>{const n=getPrefix(),r=prefixes.fullscreenChange[n];e[`${t}EventListener`](r,i,!1)};class CanvasRender extends React.Component{constructor(e){super(e),_defineProperty(this,"getTargetZoom",(e=1)=>{const{viewport:t,world:i}=this.viewer,n=i.getItemCount();if(n>1){return i.getItemAt(0).imageToViewportZoom(e)}if(n&&1===n)return t.imageToViewportZoom(e)}),_defineProperty(this,"updateZoomLimits",()=>{const{viewport:e}=this.viewer,t=this.getTargetZoom(),i=this.viewer.world.getItemAt(0).getBounds(),n=e.getBounds(),r=i.width/i.height/(n.width/n.height),o=.9*(r>=1?1:r)/i.width,s=t<=o?t:o;e.defaultZoomLevel=s,e.minZoomLevel=s,e.maxZoomLevel=t}),_defineProperty(this,"updateZoom",(e=1)=>{const{viewport:t}=this.viewer,i=this.getTargetZoom(),n=t.getMinZoom();let r=e;"string"==typeof r&&(r=parseInt(r)),r&&(r>100&&(r=100),(r=r/100*this.getTargetZoom())>i&&(r=i),r{const e=this.getTargetZoom();this.viewer.viewport.zoomTo(e,null,!0)}),_defineProperty(this,"handleFocus",()=>{const{container:e}=this.props;this.context.updateState({focus:getNestedFocus(e)})}),_defineProperty(this,"handleBlur",()=>{this.context.updateState({focus:!1})}),_defineProperty(this,"handleEnter",()=>{const{autoHideControls:e}=this.context;e&&this.context.updateState({hover:!0})}),_defineProperty(this,"handleExit",()=>{const{autoHideControls:e}=this.context;e&&this.context.updateState({hover:!1})}),_defineProperty(this,"handleError",e=>{this.viewer.close(),this.context.updateState({renderError:!0}),console.error(e)}),_defineProperty(this,"handleFullscreenChange",()=>{const e=null!==fullscreenElement();this.context.updateState({fullscreen:e}),this.updateZoomLimits()}),_defineProperty(this,"handleZoom",({zoom:e})=>{const{viewport:t}=this.viewer,i=t.getMinZoom(),n=t.getMaxZoom(),r=parseInt(e/n*100),o=ei;this.context.updateState({currentZoom:r,canZoomIn:o,canZoomOut:s})}),_defineProperty(this,"handleZoomOptimized",e=>{this.isScrolling||this.handleZoom(e)}),_defineProperty(this,"handleScrollOptimized",()=>{this.isScrolling=!0,window.clearTimeout(this.clearScrollingDelay),this.clearScrollingDelay=setTimeout(()=>{this.isScrolling=!1,this.handleZoomOptimized({zoom:this.viewer.viewport.getZoom()})},750)}),_defineProperty(this,"toggleFullscreen",()=>{const{container:e}=this.props,{allowFullScreen:t}=this.context;t&&toggleFullscreen(e)}),this.viewer=null,this.browser=null,this.isScrolling=!1,this.clearScrollingDelay=null}initOpenSeaDragon(){const{id:e,container:t}=this.props,{pages:i}=this.context;this.browser=getKeyByValue(openseadragon.BROWSERS,openseadragon.Browser.vendor),this.viewer=openseadragon({id:e,tileSources:i[0],...config}),this.viewer.addHandler("open",()=>{this.renderLayout(),this.updateZoomLimits(),this.viewer.viewport.zoomTo(this.viewer.viewport.getMinZoom(),null,!0),this.context.updateState({renderError:!1})}),this.viewer.addHandler("resize",()=>{this.updateZoomLimits()}),"FIREFOX"===this.browser?(this.viewer.addHandler("zoom",this.handleZoomOptimized),this.viewer.addHandler("canvas-scroll",this.handleScrollOptimized)):this.viewer.addHandler("zoom",this.handleZoom),this.viewer.addHandler("canvas-exit",this.handleExit),this.viewer.addHandler("canvas-enter",this.handleEnter),this.viewer.addHandler("open-failed",this.handleError),document.addEventListener("blur",this.handleBlur,!0),document.addEventListener("focus",this.handleFocus,!0),onFullscreenChange(t,"add",this.handleFullscreenChange)}renderPage(e){const t=this.context.getPage(e);t&&this.viewer.open(t)}renderCover(){this.renderPage(0)}renderLayout(){const{viewport:e,world:t}=this.viewer,{currentPage:i}=this.context,n=new openseadragon.Point(0,0),r=t.getItemCount();let o=null,s=null,a=null;for(let e=0;e=0&&rReact__default.createElement(ReaderProvider,{externalOptions:n},React__default.createElement(Wrapp$1,{width:t,height:i,externalOptions:n},t=>React__default.createElement(Uncompress,{file:e,workerUrl:r},React__default.createElement(ReaderContext.Consumer,null,e=>React__default.createElement(CanvasRender,{id:"osd-canvas-render",container:t,contextState:e.state})))));return Villain.propTypes={file:propTypes.oneOfType([propTypes.string,propTypes.instanceOf(Blob)]),width:propTypes.string,height:propTypes.string,options:propTypes.shape({theme:propTypes.string,workerUrl:propTypes.string,preview:propTypes.number})},Villain})); diff --git a/examples/demo.css b/examples/demo.css index 9a2b155e..981f1691 100644 --- a/examples/demo.css +++ b/examples/demo.css @@ -91,10 +91,6 @@ body, display: inline-block; } -.villain-demo .field select::-ms-expand { - display: none; -} - .villain-demo .instance { align-self: center; margin: 0 auto; diff --git a/package.json b/package.json index a84993b4..bc1af33d 100644 --- a/package.json +++ b/package.json @@ -40,10 +40,12 @@ "dependencies": { "clsx": "^1.0.4", "libarchive.js": "^1.3.0", + "memoize-one": "^5.1.1", "openseadragon": "^2.4.1", "prop-types": "^15.7.2", "react-compound-slider": "^2.3.0", - "react-localization": "^1.0.15" + "react-localization": "^1.0.15", + "react-spring": "^8.0.27" }, "devDependencies": { "@babel/core": "^7.4.4", diff --git a/src/components/keyboard.js b/src/components/keyboard.js new file mode 100644 index 00000000..7726fa93 --- /dev/null +++ b/src/components/keyboard.js @@ -0,0 +1,73 @@ +import React from 'react' +import { ReaderContext } from '@/context' +import { getNestedFocus, getInteractionFocus } from '@/lib/use-focus' +import { toggleFullscreen } from '@/lib/full-screen' + +const KeyboardConsumer = React.memo(({ container }) => { + const context = React.useContext(ReaderContext) + + const { + error, + mangaMode, + navigateBackward, + navigateForward, + allowGlobalShortcuts, + allowFullScreen, + } = context + + // Note: We should provide an api to add, define, overwrite key shortcuts + const handleShortcuts = React.useCallback( + event => { + // Check if it should restrict listening for key shortcuts on player focus + if (error || getInteractionFocus()) { + return + } + + if (!allowGlobalShortcuts && !getNestedFocus(container)) { + return + } + + const navigateRight = mangaMode ? navigateBackward : navigateForward + const navigateLeft = mangaMode ? navigateForward : navigateBackward + + switch (event.key) { + // Toggle fullscreen of viewer. + // Note: PreventDefault is used to remove flp shortcut. + case 'f': + event.preventDefault() + toggleFullscreen(container) + break + + // Navigation to next page (previous when in mangaMode) + case 'ArrowRight': + navigateRight() + break + + // Navigation to previous page (next when in mangaMode) + case 'ArrowLeft': + navigateLeft() + break + } + }, + [ + allowFullScreen, + allowGlobalShortcuts, + mangaMode, + navigateBackward, + navigateForward, + container, + ] + ) + + React.useEffect(() => { + document.addEventListener('keydown', handleShortcuts) + + return () => { + document.removeEventListener('keydown', handleShortcuts) + } + }, [handleShortcuts]) + + return null +}) + +export default KeyboardConsumer diff --git a/src/components/loader.js b/src/components/loader.js index fbf78152..7bf4cc74 100644 --- a/src/components/loader.js +++ b/src/components/loader.js @@ -1,9 +1,9 @@ import React from 'react' -const Loader = ({ id }) => ( +const Loader = React.memo(({ id }) => (
-) +)) -export default React.memo(Loader) +export default Loader diff --git a/src/components/menu/custom.js b/src/components/menu/custom.js index 60e20739..2a56ab3f 100644 --- a/src/components/menu/custom.js +++ b/src/components/menu/custom.js @@ -17,42 +17,43 @@ import { mdiRadioboxMarked, } from '@mdi/js' -export const CustomSeparator = props => ( - -) +export const CustomSeparator = React.forwardRef((props, ref) => ( + +)) -export const CustomItem = ({ children, ...props }) => ( - +export const CustomItem = React.forwardRef(({ children, ...props }, ref) => ( +
{children}
-) +)) -export const CustomCheckbox = ({ children, ...props }) => ( - +export const CustomCheckbox = React.forwardRef(({ children, ...props }, ref) => ( +
{children}
-) +)) -export const CustomRadio = ({ children, ...props }) => ( +export const CustomRadio = React.forwardRef(({ children, ...props }, ref) => (
{children}
-) +)) -export const CustomSubmenu = ({ children, ...props }) => ( - +export const CustomSubmenu = React.forwardRef(({ children, ...props }, ref) => ( +
{children}
( />
-) +)) -export const MenuHeader = ({ title, closeSubmenu, menuProps, ...props }) => { - return ( -
- - {title} - - -
- ) -} +export const MenuHeader = React.forwardRef( + ({ title, closeSubmenu, menuProps, ...props }, ref) => { + return ( +
+ + {title} + + +
+ ) + } +) export const CustomItems = { - item: CustomItem, - radio: CustomRadio, - submenu: CustomSubmenu, - checkbox: CustomCheckbox, - separator: CustomSeparator, + item: React.memo(CustomItem), + radio: React.memo(CustomRadio), + submenu: React.memo(CustomSubmenu), + checkbox: React.memo(CustomCheckbox), + separator: React.memo(CustomSeparator), } diff --git a/src/components/menu/index.js b/src/components/menu/index.js index ca63d24c..545203cd 100644 --- a/src/components/menu/index.js +++ b/src/components/menu/index.js @@ -1,15 +1,9 @@ import React from 'react' import { MenuHeader } from '@/components/menu/custom' import { Item, ItemList } from '@/components/menu/item' +import { animated, useSpring } from 'react-spring' -import { - Menu, - MenuDisclosure, - Tooltip, - TooltipReference, - useTooltipState, - useMenuState, -} from 'reakit' +import { Menu, MenuDisclosure, useMenuState } from 'reakit' const MenuPanel = React.forwardRef( ({ title, items, list, openSubmenu, closeSubmenu, menuProps }, ref) => { @@ -26,16 +20,15 @@ const MenuPanel = React.forwardRef( closeSubmenu={closeSubmenu} /> ) : ( - items.map(({ nestedTitle, nestedItems, nestedList, ...itemProps }, index) => { - const itemKey = `${itemProps.itemType || 'item'}-${index}` + items && + items.map(({ nestedTitle, nestedItems, nestedList, ...itemProps }) => { return ( ) }) @@ -45,36 +38,39 @@ const MenuPanel = React.forwardRef( } ) +const PureMenuPanel = React.memo(MenuPanel) + const defaultSubmenuState = { - show: false, + id: null, list: null, - index: null, title: null, items: null, + visible: false, } -const MenuWithTooltip = React.forwardRef( +const BaseMenu = React.forwardRef( ({ disclosure, tooltip, items, placement, ariaLabel, ...props }, ref) => { - const menu = useMenuState({ placement, gutter: 20 }) - const tooltipState = useTooltipState({ placement }) - + const menu = useMenuState({ placement, gutter: 20, unstable_animated: true }) const subRef = React.useRef(null) const mainRef = React.useRef(null) const [menuHeight, setMenuHeight] = React.useState(0) - const [submenuState, setSubmenuState] = React.useState({ ...defaultSubmenuState }) + const [submenuState, setSubmenuState] = React.useState(defaultSubmenuState) + const [animationState, setAnimationState] = React.useState(false) + + const maxHeight = 240 const getHeight = element => { const bounds = element.getBoundingClientRect() - return bounds.height + return bounds.height > maxHeight ? maxHeight : bounds.height } const reset = () => { setSubmenuState({ ...defaultSubmenuState }) } - const handleSubmenuOpen = index => { - setSubmenuState({ index }) + const handleSubmenuOpen = id => { + setSubmenuState({ ...submenuState, id }) } const handleSubmenuClose = () => { @@ -84,30 +80,56 @@ const MenuWithTooltip = React.forwardRef( const handleMenuOpen = () => { const mainElement = mainRef.current mainElement && setMenuHeight(getHeight(mainElement)) - reset() } const handleMenuClose = () => { reset() } + const handleAnimationStart = () => { + setAnimationState(true) + } + + const handleAnimationRest = () => { + setAnimationState(false) + menu.unstable_stopAnimation() + } + + const [menuAnimatedProps, updateMenuSpring, stopMenuSpring] = useSpring(() => ({ + height: `${menuHeight}px`, + opacity: 0, + onRest: handleAnimationRest, + onStart: handleAnimationStart, + config: { clamp: true, velocity: 5, friction: 20 }, + })) + // Handle menu React.useEffect(() => { - // On menu open if (menu.visible) { handleMenuOpen() - } else { - // On menu close - handleMenuClose() } + // Animated opacity + updateMenuSpring({ opacity: menu.visible ? 1 : 0 }) }, [menu.visible]) + React.useEffect(() => { + if (!animationState && !menu.visible) { + handleMenuClose() + } + }, [animationState]) + + React.useEffect(() => { + // Animated height + updateMenuSpring({ height: `${menuHeight}px` }) + }, [menuHeight]) + // Handle submenu React.useEffect(() => { // Update submenu content - if (submenuState.index || submenuState.index === 0) { + if (submenuState.id) { // Check if selected iteam exist - const selected = items[submenuState.index] + const selected = + items && items.length > 0 && items.find(item => item.id === submenuState.id) if (selected) { // Contains a list of similar items @@ -120,12 +142,13 @@ const MenuWithTooltip = React.forwardRef( const hasNestedItems = selected.nestedItems && selected.nestedItems.length > 0 // Validate state update - const show = hasNestedList || hasNestedItems + const visible = hasNestedList || hasNestedItems // Update submenu state and show it - if (show) { + if (visible) { setSubmenuState({ - show, + ...submenuState, + visible: true, list: hasNestedList ? selected.nestedList : null, items: hasNestedItems ? selected.nestedItems : null, title: selected.nestedTitle, @@ -133,65 +156,60 @@ const MenuWithTooltip = React.forwardRef( } } } - }, [submenuState.index, items]) + }, [submenuState.id]) // Submenu transition React.useEffect(() => { const subElement = subRef.current const mainElement = mainRef.current // Submenu open - if (submenuState.show) { + if (submenuState.visible) { subElement && setMenuHeight(getHeight(subElement)) } else { mainElement && setMenuHeight(getHeight(mainElement)) } - menu.first() + menu.unstable_update() - }, [submenuState.show]) + }, [submenuState.visible]) return ( - - {referenceProps => ( - - {disclosureProps => - React.cloneElement(React.Children.only(disclosure), disclosureProps) - } - - )} - - - {tooltip} - + - {!submenuState.show ? ( - - ) : ( - - )} + + {!submenuState.visible ? ( + + ) : ( + + )} + ) } ) -export default MenuWithTooltip +export default React.memo(BaseMenu) diff --git a/src/components/menu/item.js b/src/components/menu/item.js index 07094239..97b03630 100644 --- a/src/components/menu/item.js +++ b/src/components/menu/item.js @@ -4,56 +4,51 @@ import Icon from '@mdi/react' import { MenuGroup } from 'reakit' import { CustomItems } from '@/components/menu/custom' -export function Item({ - index, - itemType, - content, - children, - openSubmenu, - onClick, - ...props -}) { - const ContainerType = CustomItems[itemType] || CustomItems.item +export const Item = React.memo( + React.forwardRef( + ({ id, itemType, content, children, openSubmenu, onClick, ...props }, ref) => { + const ContainerType = CustomItems[itemType] || CustomItems.item - const handleClick = e => { - onClick && onClick(e) - // Close submenu - if (itemType === 'submenu') { - openSubmenu && openSubmenu(index) - } - } + const handleClick = e => { + onClick && onClick(e) + // Close submenu + if (itemType === 'submenu') { + openSubmenu && openSubmenu(id) + } + } - const itemClass = clsx( - itemType !== 'separator' && 'villain-menu__item', - itemType && `villain-menu__${itemType}` - ) + const itemClass = clsx( + itemType !== 'separator' && 'villain-menu__item', + itemType && `villain-menu__${itemType}` + ) - return ( - - {content || children} - + return ( + + {content || children} + + ) + } ) -} +) -export function ItemList({ - title, - items, - getProps, - menuProps, - getContent, - closeSubmenu, -}) { - return ( - - {items.map((item, index) => ( - - {getContent(item)} - - ))} - - ) -} +export const ItemList = React.memo( + ({ title, items, getProps, menuProps, getContent, closeSubmenu }) => { + return ( + + {items.map((item, index) => ( + getProps({ item, closeSubmenu, title }), [ + item, + title, + closeSubmenu, + ])} + key={item} + > + {React.useMemo(() => getContent(item), [item])} + + ))} + + ) + } +) diff --git a/src/components/options.js b/src/components/options.js new file mode 100644 index 00000000..5da12d8b --- /dev/null +++ b/src/components/options.js @@ -0,0 +1,19 @@ +import React from 'react' +import { ReaderContext } from '@/context' + +// Renderless component to sync props with context state +const OptionsConsumer = React.memo(({ options }) => { + const context = React.useContext(ReaderContext) + // Update context state on props change + React.useEffect(() => { + Object.entries(options).map(([key, value]) => { + if (context[key] !== value) { + context.updateState({ [key]: value }) + } + }) + }, [options]) + // Nothing to render + return null +}) + +export default OptionsConsumer diff --git a/src/components/render.js b/src/components/render.js index 7a9275bb..e4d1551f 100644 --- a/src/components/render.js +++ b/src/components/render.js @@ -1,30 +1,24 @@ import clsx from 'clsx' import React, { Component } from 'react' import OpenSeaDragon from 'openseadragon' +import Localize from '@/localize' import OSDConfig from '@/osd.config' -import Toolbar from '@/components/toolbar' import RenderError from '@/components/renderError' -import Localize from '@/localize' +import ToolbarConsumer from '@/components/toolbar' import { ReaderContext } from '../context' -import { getKeyByValue } from '@/lib/utils' +import { getKeyByValue, debounce } from '@/lib/utils' import { getNestedFocus } from '@/lib/use-focus' - -import { - onFullscreenChange, - fullscreenElement, - toggleFullscreen, -} from '@/lib/full-screen' +import { memoizeZoomClamp, memoizeZoomPercent } from '@/lib/zoom-parser' +import { fullscreenElement, onFullscreenChange } from '@/lib/full-screen' // Icons import { mdiImageBrokenVariant } from '@mdi/js' -class CanvasRender extends Component { +class CanvasRender extends React.PureComponent { static defaultProps = { initialPage: 0, } - static contextType = ReaderContext - constructor(props) { super(props) this.viewer = null @@ -33,7 +27,7 @@ class CanvasRender extends Component { this.clearScrollingDelay = null } -// Get the max target zoom + // Get the max target zoom getTargetZoom = (scale = 1) => { let zooms = [] const { viewport, world } = this.viewer @@ -65,97 +59,93 @@ class CanvasRender extends Component { updateZoom = (scale = 1) => { const { viewport } = this.viewer - const max = this.getTargetZoom() + const max = viewport.getMaxZoom() const min = viewport.getMinZoom() - let zoom = scale - - // Convert to int - if (typeof zoom === 'string') { - zoom = parseInt(zoom) - } - - if (zoom) { - // Prevent maz zoom - if (zoom > 100) { - zoom = 100 - } - // Calculate zoom from user input - zoom = (zoom / 100) * this.getTargetZoom() - // Fix max - if (zoom > max) { - zoom = max - } - // Fix min - if (zoom < min) { - zoom = min - } + if (scale) { + // Clamp zoom value + let zoom = memoizeZoomClamp(scale, max, min) // Update - viewport.zoomTo(zoom, null, true) + viewport.zoomTo(zoom, true) + viewport.ensureVisible(true) } } + zoomIn = () => { + const { viewport } = this.viewer + const max = viewport.getMaxZoom() + const zoom = viewport.getZoom() + const currentZoom = memoizeZoomPercent(zoom, max) + this.updateZoom(currentZoom + 10) + } + + zoomOut = () => { + const { viewport } = this.viewer + const max = viewport.getMaxZoom() + const zoom = viewport.getZoom() + const currentZoom = memoizeZoomPercent(zoom, max) + this.updateZoom(currentZoom - 10) + } + zoomToOriginalSize = () => { const targetZoom = this.getTargetZoom() this.viewer.viewport.zoomTo(targetZoom, null, true) } handleFocus = () => { - const { container } = this.props - this.context.updateState({ focus: getNestedFocus(container) }) + const { updateContextState } = this.props + updateContextState({ focus: true }) } handleBlur = () => { - this.context.updateState({ focus: false }) + const { updateContextState } = this.props + updateContextState({ focus: false }) } handleEnter = () => { - const { autoHideControls } = this.context.state - - if (autoHideControls) { - this.context.updateState({ hover: true }) - } + const { updateContextState } = this.props + updateContextState({ hover: true }) } handleExit = () => { - const { autoHideControls } = this.context.state - - if (autoHideControls) { - this.context.updateState({ hover: false }) - } + const { updateContextState } = this.props + updateContextState({ hover: false }) } handleError = error => { + const { updateCotextState } = this.props this.viewer.close() - this.context.updateState({ renderError: true }) + updateContextState({ renderError: true }) // Debug error console.error(error) } handleFullscreenChange = () => { + const { updateContextState } = this.props const fullscreen = fullscreenElement() !== null - this.context.updateState({ fullscreen }) + updateContextState({ fullscreen }) this.updateZoomLimits() } handleZoom = ({ zoom }) => { const { viewport } = this.viewer + const { updateContextState } = this.props const min = viewport.getMinZoom() - const targetZoom = viewport.getMaxZoom() - const currentZoom = parseInt((zoom / targetZoom) * 100) - const canZoomIn = zoom < targetZoom && currentZoom < 100 + const max = viewport.getMaxZoom() + const currentZoom = memoizeZoomPercent(zoom, max) + const canZoomIn = zoom < max && currentZoom < 100 const canZoomOut = zoom > min - this.context.updateState({ currentZoom, canZoomIn, canZoomOut }) + updateContextState({ currentZoom, canZoomIn, canZoomOut }) } - handleZoomOptimized = event => { + handleZoomOptimized = debounce(event => { // Unable to update zoom on scroll inside this event handler: // - Bad peformance from multiple context update state calls // - Small delay for text updating noticeable. if (!this.isScrolling) { this.handleZoom(event) } - } + }, 200) handleScrollOptimized = () => { // Reset scrolling flag @@ -166,18 +156,11 @@ class CanvasRender extends Component { this.clearScrollingDelay = setTimeout(() => { this.isScrolling = false this.handleZoomOptimized({ zoom: this.viewer.viewport.getZoom() }) - }, 750) + }, 400) } - toggleFullscreen = () => { - const { container } = this.props - const { allowFullScreen } = this.context.state - if (allowFullScreen) toggleFullscreen(container) - } - - initOpenSeaDragon() { - const { id, container } = this.props - const { pages } = this.context.state + initOpenSeaDragon = () => { + const { id, container, pages, renderError, updateContextState } = this.props // Detect browser vendor this.browser = getKeyByValue(OpenSeaDragon.BROWSERS, OpenSeaDragon.Browser.vendor) @@ -188,9 +171,12 @@ class CanvasRender extends Component { // Events handler this.viewer.addHandler('open', () => { this.renderLayout() - this.updateZoomLimits() - this.viewer.viewport.zoomTo(this.viewer.viewport.getMinZoom(), null, true) - this.context.updateState({ renderError: false }) + this.fitBounds() + + // Prevent unessesart context updates + if (renderError) { + updateContextState({ renderError: false }) + } }) // Events handler @@ -198,18 +184,12 @@ class CanvasRender extends Component { this.updateZoomLimits() }) - // Fallback to improve peformance on firefox browser. - // We should look into what other browsers should use this: - if (this.browser === 'FIREFOX') { - // Fix issue with animations and peformance, see: - // https://github.com/btzr-io/Villain/issues/66 - this.viewer.addHandler('zoom', this.handleZoomOptimized) - this.viewer.addHandler('canvas-scroll', this.handleScrollOptimized) - } else { - // This can run smooth on chromium based browsers (chrome, brave, electon) - // But still needs more optimizations! - this.viewer.addHandler('zoom', this.handleZoom) - } + // Fallback to improve peformance on zoom upodates" + // Fix issue with animations and peformance, see: + // https://github.com/btzr-io/Villain/issues/66 + this.viewer.addHandler('zoom', this.handleZoomOptimized) + // Optimized scroll event + this.viewer.addHandler('canvas-scroll', this.handleScrollOptimized) this.viewer.addHandler('canvas-exit', this.handleExit) @@ -217,15 +197,15 @@ class CanvasRender extends Component { this.viewer.addHandler('open-failed', this.handleError) - document.addEventListener('blur', this.handleBlur, true) + this.viewer.canvas.addEventListener('blur', this.handleBlur) - document.addEventListener('focus', this.handleFocus, true) + this.viewer.canvas.addEventListener('focus', this.handleFocus) onFullscreenChange(container, 'add', this.handleFullscreenChange) } renderPage(index) { - const page = this.context.getPage(index) + const page = this.props.getPage(index) page && this.viewer.open(page) } @@ -233,26 +213,38 @@ class CanvasRender extends Component { this.renderPage(0) } + fitBounds() { + const { viewport } = this.viewer + this.fitPages() + this.updateZoomLimits() + viewport.zoomTo(viewport.getMinZoom(), null, true) + } + renderLayout() { const { world } = this.viewer + const { mangaMode, bookMode } = this.props const pos = new OpenSeaDragon.Point(0, 0) const count = world.getItemCount() // Cache tile data let bounds = null - let nextPage = null + // first page let firstPage = null - let nextPageBounds = null + let firstPageIndex = bookMode && mangaMode && count > 1 ? 1 : 0 let firstPageBounds = null + // Next page + let nextPage = null + let nextPageBounds = null + let nextPageIndex = bookMode && mangaMode ? 0 : 1 if (count > 0) { // Page view (single page) - firstPage = world.getItemAt(0) + firstPage = world.getItemAt(firstPageIndex) firstPageBounds = firstPage.getBounds() // Book view ( two pages ) if (count > 1) { - nextPage = world.getItemAt(1) + nextPage = world.getItemAt(nextPageIndex) nextPageBounds = nextPage.getBounds() // Auto resize page to fit first page height @@ -282,9 +274,6 @@ class CanvasRender extends Component { pos.x += nextPageBounds.width } } - - // Fit pages on viewer and apply bounds - this.fitPages() } fitPagesLegacy() { @@ -312,14 +301,14 @@ class CanvasRender extends Component { componentDidMount() { const { initialPage } = this.props this.initOpenSeaDragon() + this.renderPage(initialPage) } componentWillUnmount() { - this.renderPage(initialPage) const { container } = this.props // Remove event listeners - document.removeEventListener('blur', this.handleBlur, true) - document.removeEventListener('focus', this.handleFocus, true) + // document.removeEventListener('blur', this.handleBlur, true) + // document.removeEventListener('focus', this.handleFocus, true) onFullscreenChange(container, 'remove', this.handleFullscreenChange) // Destroy OpenSeaDragon viewer this.viewer.destroy() @@ -327,21 +316,10 @@ class CanvasRender extends Component { } componentDidUpdate(prevProps) { - const { - bookMode, - mangaMode, - totalPages, - currentPage, - autoHideControls, - } = this.props.contextState - - const prevContextState = prevProps.contextState + const { bookMode, mangaMode, totalPages, currentPage } = this.props // Page changed - if ( - currentPage !== prevContextState.currentPage || - bookMode !== prevContextState.bookMode - ) { + if (currentPage !== prevProps.currentPage || bookMode !== prevProps.bookMode) { // Render new valid page if (currentPage >= 0 && currentPage < totalPages) { this.renderPage(currentPage) @@ -349,32 +327,30 @@ class CanvasRender extends Component { } // Page changed - if (bookMode !== prevContextState.bookMode) { + if (bookMode !== prevProps.bookMode) { if (bookMode) { // Trigger re-render layout this.renderLayout() + this.fitBounds() } } - // re-render page when mangaMode is changed - if (mangaMode !== prevContextState.mangaMode) { - this.renderPage(currentPage) + // Re-render layout when mangaMode and there and book mode is active + if (mangaMode !== prevProps.mangaMode && bookMode) { + this.renderLayout() } } render() { - const { id, container, renderError, contextState } = this.props - const { focus, hover, autoHideControls } = contextState - const showControls = !autoHideControls || hover || focus + const { id, container, renderError } = this.props return ( -
{renderError && ( @@ -385,4 +361,50 @@ class CanvasRender extends Component { } } -export default CanvasRender +const CanvasRenderConsumer = React.memo(({ container }) => { + return ( + + {({ + // State + ready, + error, + hover, + pages, + bookMode, + mangaMode, + totalPages, + currentPage, + renderError, + allowFullScreen, + allowGlobalShortcuts, + // Actions + getPage, + updateState, + }) => { + const shouldRender = ready && !error + + return ( + shouldRender && ( + + ) + ) + }} + + ) +}) + +export default CanvasRenderConsumer diff --git a/src/components/slider/handle.js b/src/components/slider/handle.js index 800a67a8..38890659 100644 --- a/src/components/slider/handle.js +++ b/src/components/slider/handle.js @@ -1,7 +1,50 @@ -import React, { useState } from 'react' +import React, { memo, useState, useEffect } from 'react' import PropTypes from 'prop-types' -import Tooltip from './tooltip' -import { ToolbarItem } from 'reakit' +import Button from '@/components/toolbar/button' +import { animated, useSpring } from 'react-spring' + +const HandlerTooltip = memo(({ value, visible }) => { + const [shouldRender, setShouldRender] = useState(false) + + const [tooltipAnimatedProps, updateTooltipSpring, stopTooltipSpring] = useSpring( + () => ({ + delay: 0, + opacity: 1, + transform: 'scale(1)', + config: { clamp: true, velocity: 14, friction: 20 }, + }) + ) + + useEffect(() => { + updateTooltipSpring({ + delay: visible ? 200 : 800, + opacity: visible ? 1 : 0, + onRest: () => { + if (!visible) { + setShouldRender(false) + } + }, + onStart: () => { + if (visible) { + setShouldRender(true) + } + }, + transform: `scale(${visible ? 1 : 0})`, + }) + }, [visible]) + + return ( + shouldRender && ( + + {value} + + ) + ) +}) + +HandlerTooltip.propTypes = { + value: PropTypes.number, +} const Handle = ({ domain: [min, max], @@ -9,7 +52,6 @@ const Handle = ({ isActive, disabled, getHandleProps, - toolbarItemProps, }) => { const [mouseOver, setMouseOver] = useState(false) @@ -21,9 +63,10 @@ const Handle = ({ setMouseOver(false) } + const showTooltip = (mouseOver || isActive) && !disabled + return ( - - {(mouseOver || isActive) && !disabled ? : null} - + + ) } @@ -65,4 +109,4 @@ Handle.propTypes = { disabled: PropTypes.bool, } -export default React.memo(Handle) +export default memo(Handle) diff --git a/src/components/slider/index.js b/src/components/slider/index.js index faba1f46..f8bd9619 100644 --- a/src/components/slider/index.js +++ b/src/components/slider/index.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, memo } from 'react' import { Slider, Rail, Handles, Tracks } from 'react-compound-slider' import Handle from './handle' import SliderRail from './sliderRail' @@ -16,7 +16,7 @@ const sliderStyle = { zIndex: 99, } -const Track = ({ source, target, getTrackProps }) => { +const Track = memo(({ source, target, getTrackProps }) => { return (
{ {...getTrackProps()} /> ) -} +}) + +const BufferLoader = memo(({ bufferProgress, reversed }) => { + return ( +
+ ) +}) const defaultValues = [1] -const SliderUI = ({ - max = 1, - bufferProgress = 0, - reversed, - onChange, - value, - toolbarItemProps, -}) => { +const SliderUI = memo(({ max = 1, bufferProgress = 0, reversed, onChange, value }) => { const [seeking, setSeeking] = useState(false) const [values, setValue] = useState(defaultValues.slice()) @@ -88,7 +93,6 @@ const SliderUI = ({ domain={domain} isActive={handle.id === activeHandleID} getHandleProps={getHandleProps} - toolbarItemProps={toolbarItemProps} /> ))}
@@ -110,17 +114,9 @@ const SliderUI = ({ )} - -
+
) -} +}) -export default React.memo(SliderUI) +export default SliderUI diff --git a/src/components/slider/sliderRail.js b/src/components/slider/sliderRail.js index 9e88fae8..2840a5e6 100644 --- a/src/components/slider/sliderRail.js +++ b/src/components/slider/sliderRail.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { memo } from 'react' import PropTypes from 'prop-types' const railStyle = { @@ -12,9 +12,9 @@ const railStyle = { zIndex: -1, } -const SliderRail = ({ activeHandleID, getEventData, getRailProps }) => { +const SliderRail = memo(({ activeHandleID, getEventData, getRailProps }) => { return
-} +}) SliderRail.propTypes = { activeHandleID: PropTypes.string, diff --git a/src/components/slider/tooltip.js b/src/components/slider/tooltip.js deleted file mode 100644 index ae0c401d..00000000 --- a/src/components/slider/tooltip.js +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' - -const Tooltip = ({ value = null }) => ( -
-
-
{value}
-
-
-) - -Tooltip.propTypes = { - value: PropTypes.number, -} - -export default Tooltip diff --git a/src/components/toolbar/button.js b/src/components/toolbar/button.js index af6d9519..edc8ff48 100644 --- a/src/components/toolbar/button.js +++ b/src/components/toolbar/button.js @@ -57,4 +57,4 @@ const ToolbarButton = React.forwardRef( } ) -export default ToolbarButton +export default React.memo(ToolbarButton) diff --git a/src/components/toolbar/controls/fullscreen.js b/src/components/toolbar/controls/fullscreen.js new file mode 100644 index 00000000..9faba8e9 --- /dev/null +++ b/src/components/toolbar/controls/fullscreen.js @@ -0,0 +1,43 @@ +import React from 'react' +import Button from '@/components/toolbar/button' +import Localize from '@/localize' +import { ReaderContext } from '@/context' +import { mdiFullscreen, mdiFullscreenExit } from '@mdi/js' +import { toggleFullscreen } from '@/lib/full-screen' + +const FullscreenButton = React.memo( + ({ fullscreen, allowFullScreen, container, disabled }) => { + const handleToggleFullscreen = () => { + if (allowFullScreen) { + toggleFullscreen(container) + } + } + + return ( +