class RefnotePopup{t(e){const t=e;t.style.left="",t.style.top="",t.style.width="",t.style.height="",t.style.position=""}o(e,t){const o=e;o.style.left=t.left+"px",o.style.top=t.top+"px",o.style.width=t.width+"px",o.style.height=t.height+"px",o.style.position="fixed"}s(e,t){this.t(e);const o=document.getElementById("refnote-popup-container"),n=200;o.style.minHeight="200px";const s=getComputedStyle(document.body),i=parseInt(s.width,10),p=parseInt(s.height,10),r=Math.ceil(i*t[0]),u=Math.ceil(p*t[1]);o.style.maxWidth=r+"px",o.style.maxHeight=u+"px";const d=getComputedStyle(o),c=undefined,a=undefined;return[parseInt(d.width,10),parseInt(d.height,10)]}i(e){const t=getComputedStyle(document.body),o=parseInt(t.width,10),n=parseInt(t.height,10),s=e[0],i=e[1],p=Math.max((n-i)/2,0),r=Math.max((o-s)/2,0);return{left:Math.ceil(r),top:Math.ceil(p),width:Math.ceil(s),height:Math.ceil(i)}}p(e,t){const o=t[0],n=t[1],s=o/2,i=n/2,p=e.top+(e.bottom-e.top)/2,r=e.left+(e.right-e.left)/2,u=getComputedStyle(document.body),d=parseInt(u.width,10),c=parseInt(u.height,10),a=r%d,h=a>s&&d-a>s;let f=0,m=0;const l=5;e.top>n+10&&h?(f=r-s,m=e.top-n-5):c-e.bottom>n+10&&h?(f=r-s,m=e.bottom+5):e.left>d-e.left?(f=e.left-o-5,m=Math.max(p-i,5)):(f=e.right+5,m=Math.max(p-i,5));const g=m+n+5;if(g>c){const e=undefined;m-=g-c}return{left:Math.ceil(f),top:Math.ceil(m),width:Math.ceil(o),height:Math.ceil(n)}}u(e){const t=undefined,o=undefined,n=`radial-gradient(circle at ${e.left+e.width/2}px ${e.top+e.height/2}px, rgba(0,0,0,0) 0%, rgba(0,0,0,.1) 5%, rgba(0,0,0,0) 100%)`;document.body.style.background="rgba(0,0,0,0.07)",document.body.style.background=n}setRefnoteCueRect(e,t,o,n){const s={top:t,bottom:t+n,left:e,right:e+o};return window.clickedRefnoteCueRect=s,s}h(){const e=document.getElementById("refnote-popup-container");if(!e)return;document.body.classList.add("refnote-popover","ipad");const t=[.55,.55],o=this.s(e,t),n=this.p(window.clickedRefnoteCueRect,o);this.o(e,n),this.u(n),this.m()}l(){const e=document.getElementById("refnote-popup-container");if(!e)return;document.body.classList.add("refnote-popover","clara");const t=[.65,.9],o=this.s(e,t),n=this.i(o);this.o(e,n),this.m()}g(e,t,o){const n=document.getElementById("refnote-popup-container"),s=document.getElementById("refnote-popup-header"),i=document.getElementsByClassName("refnote-popup-content")[0],p=document.getElementsByClassName("refnote")[0],r=document.getElementById("refnote-popup-footer");if(!(n&&s&&i&&p&&r))return;document.body.classList.add("refnote-sheet",e,t),i.style.height="",document.body.style.marginTop="";const u=getComputedStyle(n),d=parseInt(u.height,10),c=getComputedStyle(s),a=getComputedStyle(i),h=getComputedStyle(p),f=getComputedStyle(r),m=parseInt(c.height,10),l=parseInt(h.height,10),g=parseInt(f.height,10),w=parseInt(a.marginTop,10),v=undefined,M=Math.min(m+w+l+g,d)/d;let P=o[o.length-1];for(let e=0;e<o.length-1;e+=1){const t=o[e];if(M<=t){P=t;break}}const _=undefined,C=Math.ceil(d*P)-(m+w+g);i.style.height=C+"px",P<1&&this.m(),this.v(P)}v(e){let t=.2;1===e&&(t=.4,document.body.classList.add("full-size-sheet")),document.body.style.transition=t+"s",document.body.style.marginTop=100-100*e+"vh"}M(){document.body.style.marginTop="100vh";const e=parseFloat(document.body.style.transition);window.setTimeout(()=>{this.P()},1e3*e)}m(){const e=undefined;document.getElementById("refnote-popup-container").addEventListener("mouseup",this._.bind(this)),window.addEventListener("mouseup",this.C.bind(this))}I(){const e=undefined;document.getElementById("refnote-popup-container").removeEventListener("mouseup",this._.bind(this)),window.removeEventListener("mouseup",this.C.bind(this))}_(e){e.stopPropagation()}C(e){this.closeRefnotePopup()}configureRefnotePopup(e){const t="overflow-scrolling",o="overflow-paged";if("fire"===e||"paperwhite"===e){const t=[.3,.5,1];this.g("overflow-paged",e,t)}else if("ipad"===e)this.h();else if("iphone-5"===e||"iphone"===e){const t=[1];this.g("overflow-scrolling",e,t)}else if("clara"===e)this.l();else if("android-tablet"===e){const t=[.3];this.g("overflow-scrolling",e,t)}}closeRefnotePopup(){document.body.style.background="",this.I();const e=undefined;return document.body.classList.contains("refnote-sheet")?this.M():this.P(),!1}postMessageToShowRefnotePopup(e,t){const o=document.getElementById(t),n=o.classList.contains("footnote-cue")?"footnote":"endnote",s=o.getBoundingClientRect(),i=undefined,p={command:"show",info:{identifier:t,number:e,type:n,"rect-x":s.x,"rect-y":s.y,"rect-width":s.width,"rect-height":s.height}};window.webkit.messageHandlers.refnotePopup.postMessage(p)}P(){const e={command:"close"};window.webkit&&window.webkit.messageHandlers.refnotePopup.postMessage(e)}}refnotePopup=new RefnotePopup;